Commit d2b5abe6 authored by jiaorz's avatar jiaorz

车辆信息统计

parent feddd783
...@@ -7,7 +7,6 @@ import org.springframework.format.annotation.DateTimeFormat; ...@@ -7,7 +7,6 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date; import java.util.Date;
/** /**
...@@ -22,8 +21,8 @@ public class BranchCompanyVehicleCount { ...@@ -22,8 +21,8 @@ public class BranchCompanyVehicleCount {
/** /**
* 公司名称 * 公司名称
*/ */
@Column(name = "company_name") @Column(name = "company_id")
private String companyName; private String companyId;
/** /**
* 当前停靠车辆数量 * 当前停靠车辆数量
...@@ -41,17 +40,21 @@ public class BranchCompanyVehicleCount { ...@@ -41,17 +40,21 @@ public class BranchCompanyVehicleCount {
) )
private Date countDate; private Date countDate;
@DateTimeFormat(pattern="yyyy-MM-dd") /**
@JsonFormat( * 统计年
pattern = "yyyy-MM-dd" */
) @Column(name = "count_year")
@Transient private Integer countYear;
private Date weekStartDate;
/**
* 统计月
*/
@Column(name = "count_month")
private Integer countMonth;
/**
* 统计周
*/
@Column(name = "count_week")
private Integer countWeek;
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(
pattern = "yyyy-MM-dd"
)
@Transient
private Date weekEndDate;
} }
\ No newline at end of file
package com.xxfc.platform.vehicle.pojo; package com.xxfc.platform.vehicle.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data @Data
public class BranchCompanyVehicleCountVo { public class BranchCompanyVehicleCountVo {
private String parkBranchCompanyName; //分公司ID
private Integer count;
private Integer companyId; private Integer companyId;
//统计年
private Integer countYear;
//统计月
private Integer countMonth;
//统计周
private Integer countWeek;
//统计日期
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(
pattern = "yyyy-MM-dd"
)
private Date countDate;
//统计数量
private Integer vehicleNum;
//公司名称
private String companyName;
//周开始时间
private String weekStartDate;
//周结束时间
private String weekEndDate;
} }
...@@ -11,9 +11,8 @@ public class BranchCompanyVehicleCountDTO extends PageParam { ...@@ -11,9 +11,8 @@ public class BranchCompanyVehicleCountDTO extends PageParam {
//结束时间 //结束时间
private String endTime; private String endTime;
private String companyName; private Integer companyId;
//统计类型,日月年, 1、日,2、月,3、年 //统计类型,日月年, 1、日,2、月,3、年
private Integer type; private Integer type;
//需要除去的天数
private Integer dayNum;
} }
package com.xxfc.platform.vehicle.biz; package com.xxfc.platform.vehicle.biz;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.Query; import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xxfc.platform.order.Utils.OrderDateUtils; import com.xxfc.platform.order.Utils.OrderDateUtils;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount; import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper; import com.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper;
import com.xxfc.platform.vehicle.pojo.VehicleWeekCountVo; import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO; import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired;
import org.joda.time.DateTime; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
@Slf4j @Slf4j
public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCountMapper, BranchCompanyVehicleCount> { public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCountMapper, BranchCompanyVehicleCount> {
@Autowired
VehicleBiz vehicleBiz;
public ObjectRestResponse add(BranchCompanyVehicleCount branchCompanyVehicleCount) { public ObjectRestResponse add(BranchCompanyVehicleCount branchCompanyVehicleCount) {
if (branchCompanyVehicleCount == null) { if (branchCompanyVehicleCount == null) {
return ObjectRestResponse.paramIsEmpty(); return ObjectRestResponse.paramIsEmpty();
...@@ -36,129 +36,78 @@ public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCo ...@@ -36,129 +36,78 @@ public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCo
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
public ObjectRestResponse<PageDataVO<BranchCompanyVehicleCount>> findAll(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) { public ObjectRestResponse addAll(List<BranchCompanyVehicleCountVo> list) {
Integer pageNo = branchCompanyVehicleCountDTO.getPage() == null ? 1 : branchCompanyVehicleCountDTO.getPage(); if (list != null && list.size() > 0) {
Integer pageSize = branchCompanyVehicleCountDTO.getLimit() == null ? 10 : branchCompanyVehicleCountDTO.getLimit(); list.parallelStream().forEach(result -> {
Integer type = branchCompanyVehicleCountDTO.getType() == null ? 1 : branchCompanyVehicleCountDTO.getType(); BranchCompanyVehicleCount branchCompanyVehicleCount = new BranchCompanyVehicleCount();
branchCompanyVehicleCountDTO.setPage(pageNo); BeanUtil.copyProperties(result, branchCompanyVehicleCount, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
branchCompanyVehicleCountDTO.setLimit(pageSize); add(branchCompanyVehicleCount);
branchCompanyVehicleCountDTO.setType(type); });
if (type == 1) { return ObjectRestResponse.succ();
branchCompanyVehicleCountDTO.setDayNum(1); } else {
} else if (type == 2) { return ObjectRestResponse.paramIsEmpty();
branchCompanyVehicleCountDTO.setDayNum(7);
} else if (type == 3) {
branchCompanyVehicleCountDTO.setDayNum(getCurrentMonthLastDay());
} }
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<BranchCompanyVehicleCount> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.getAllByParam(query.getSuper()));
return ObjectRestResponse.succ(pageDataVO);
} }
@Scheduled(cron = "0 0 2 * * *")
public int getCurrentMonthLastDay() { public void addAll() {
Calendar a = Calendar.getInstance(); addAll(vehicleBiz.getAllVehicleInfo());
a.set(Calendar.DATE, 1);//把日期设置为当月第一天
a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
int maxDate = a.get(Calendar.DATE);
return maxDate;
} }
/** /**
* 获取所有公司名称 * 按天统计
* * @param query
* @return * @return
*/ */
public List<BranchCompanyVehicleCount> getAllBranchCompanyName() { public PageDataVO<BranchCompanyVehicleCountVo> countByDay(Query query) {
return mapper.getAllCompanyName(); return PageDataVO.pageInfo(query, () -> mapper.getAllCountInfo(query.getSuper()));
} }
/** /**
* 按月统计 * 按月统计
* * @param query
* @param param
* @return * @return
*/ */
public List<BranchCompanyVehicleCount> countByMonth(Map<String, Object> param) { public PageDataVO<BranchCompanyVehicleCountVo> countByMonth(Query query) {
return mapper.countByMonth(param); return PageDataVO.pageInfo(query, () -> mapper.countByMonth(query.getSuper()));
} }
/** /**
* 按周统计 * 按周统计
* * @param query
* @param param
* @return * @return
*/ */
public List<VehicleWeekCountVo> countByWeek(Map<String, Object> param) { public PageDataVO<BranchCompanyVehicleCountVo> countByWeek(Query query) {
return mapper.countByWeek(param); return PageDataVO.pageInfo(query, () -> mapper.countByWeek(query.getSuper()));
} }
/** public ObjectRestResponse<PageDataVO<BranchCompanyVehicleCountVo>> getAllCountInfo(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
* 后台查询统计信息 if (branchCompanyVehicleCountDTO == null) {
* return ObjectRestResponse.paramIsEmpty();
* @param branchCompanyVehicleCountDTO
* @return
*/
public PageDataVO<BranchCompanyVehicleCount> countAllByMonth(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
if (StringUtils.isNotBlank(branchCompanyVehicleCountDTO.getCompanyName())) {
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<BranchCompanyVehicleCount> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.countByMonth(query.getSuper()));
return pageDataVO;
}
List<BranchCompanyVehicleCount> resultList = Lists.newArrayList();
List<BranchCompanyVehicleCount> branCompanyNames = getAllBranchCompanyName();
if (branCompanyNames != null && branCompanyNames.size() > 0) {
for (BranchCompanyVehicleCount branchCompanyVehicleCount : branCompanyNames) {
branchCompanyVehicleCountDTO.setCompanyName(branchCompanyVehicleCount.getCompanyName());
Map<String, Object> map = Maps.newHashMap();
map.put("startTime", branchCompanyVehicleCountDTO.getStartTime());
map.put("endTime", branchCompanyVehicleCountDTO.getEndTime());
map.put("companyName", branchCompanyVehicleCountDTO.getCompanyName());
List<BranchCompanyVehicleCount> branchCompanyVehicleCounts = countByMonth(map);
if (branchCompanyVehicleCounts != null && branchCompanyVehicleCounts.size() > 0) {
branchCompanyVehicleCounts.forEach((a) -> a.setCompanyName(branchCompanyVehicleCountDTO.getCompanyName()));
resultList.addAll(branchCompanyVehicleCounts);
}
}
} }
PageDataVO<BranchCompanyVehicleCount> pageDataVO = new PageDataVO<>(); Integer page = branchCompanyVehicleCountDTO.getPage() == null ? 1 : branchCompanyVehicleCountDTO.getPage();
if (resultList.size() > 0) { Integer limit = branchCompanyVehicleCountDTO.getLimit() == null ? 10 : branchCompanyVehicleCountDTO.getLimit();
List<BranchCompanyVehicleCount> dataList = resultList.subList((branchCompanyVehicleCountDTO.getPage() - 1) * branchCompanyVehicleCountDTO.getLimit(), branchCompanyVehicleCountDTO.getPage() * branchCompanyVehicleCountDTO.getLimit()); Integer type = branchCompanyVehicleCountDTO.getType() == null ? 1 : branchCompanyVehicleCountDTO.getType();
pageDataVO.setData(dataList); branchCompanyVehicleCountDTO.setPage(page);
} else { branchCompanyVehicleCountDTO.setLimit(limit);
pageDataVO.setData(resultList); Query query = new Query(branchCompanyVehicleCountDTO);
if (type == 1) {//按天
return ObjectRestResponse.succ(countByDay(query));
} }
pageDataVO.setTotalCount(Long.parseLong(resultList.size() + "")); if (type == 2) {//按周
pageDataVO.setTotalPage(resultList.size() % branchCompanyVehicleCountDTO.getLimit() == 0 ? resultList.size() / branchCompanyVehicleCountDTO.getLimit() : resultList.size() / branchCompanyVehicleCountDTO.getLimit() + 1); PageDataVO<BranchCompanyVehicleCountVo> pageDataVO = countByWeek(query);
pageDataVO.setPageNum(branchCompanyVehicleCountDTO.getLimit()); if (pageDataVO != null && pageDataVO.getData() != null && pageDataVO.getData().size() > 0) {
pageDataVO.setPageSize(branchCompanyVehicleCountDTO.getPage()); pageDataVO.getData().parallelStream().forEach(result -> {
return pageDataVO; String weekStartDate = OrderDateUtils.getStartDayOfWeekNo(result.getCountYear(), result.getCountWeek());
} String weekEndDate = OrderDateUtils.getEndDayOfWeekNo(result.getCountYear(), result.getCountWeek());
result.setWeekStartDate(weekStartDate);
/** result.setWeekEndDate(weekEndDate);
* 按周统计
*
* @param branchCompanyVehicleCountDTO
* @return
*/
public PageDataVO<BranchCompanyVehicleCount> countAllByWeek(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
if (StringUtils.isNotBlank(branchCompanyVehicleCountDTO.getCompanyName())) {
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<VehicleWeekCountVo> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.countByWeek(query.getSuper()));
if (pageDataVO.getData() != null && pageDataVO.getData().size() > 0) {
List<BranchCompanyVehicleCount> list = Lists.newArrayList();
pageDataVO.getData().forEach(result -> {
BranchCompanyVehicleCount branchCompanyVehicleCount = new BranchCompanyVehicleCount();
branchCompanyVehicleCount.setCompanyName(branchCompanyVehicleCountDTO.getCompanyName());
branchCompanyVehicleCount.setCountDate(result.getDateTime());
branchCompanyVehicleCount.setVehicleNum(result.getCount());
Date weekStartDate = OrderDateUtils.getStartDayOfWeekNo(result.getDateTime().getYear(), result.getWeek());
branchCompanyVehicleCount.setWeekStartDate();
list.add(branchCompanyVehicleCount);
}); });
} }
return pageDataVO; return ObjectRestResponse.succ(pageDataVO);
}
if (type == 3) {//按月
return ObjectRestResponse.succ(countByMonth(query));
} }
return null; return ObjectRestResponse.succ(new PageDataVO<>());
} }
} }
...@@ -1514,8 +1514,8 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR ...@@ -1514,8 +1514,8 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
return vehicles.stream().map(Vehicle::getId).collect(Collectors.toList()); return vehicles.stream().map(Vehicle::getId).collect(Collectors.toList());
} }
public List<BranchCompanyVehicleCountVo> getAllVehicleInfo(Map<String, Object> param) { public List<BranchCompanyVehicleCountVo> getAllVehicleInfo() {
return mapper.getAllVehicleInfo(param); return mapper.getAllVehicleInfo();
} }
} }
...@@ -4,25 +4,24 @@ import com.alibaba.fastjson.JSON; ...@@ -4,25 +4,24 @@ import com.alibaba.fastjson.JSON;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO; import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.entity.Vehicle; import com.xxfc.platform.vehicle.entity.Vehicle;
import com.xxfc.platform.vehicle.mapper.VehicleMapper; import com.xxfc.platform.vehicle.mapper.VehicleMapper;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo;
import com.xxfc.platform.vehicle.pojo.ResultVehicleVo; import com.xxfc.platform.vehicle.pojo.ResultVehicleVo;
import com.xxfc.platform.vehicle.pojo.VehicleExcelVo; import com.xxfc.platform.vehicle.pojo.VehicleExcelVo;
import com.xxfc.platform.vehicle.pojo.VehiclePageQueryVo; import com.xxfc.platform.vehicle.pojo.VehiclePageQueryVo;
import com.xxfc.platform.vehicle.util.DateUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Service @Service
@Slf4j @Slf4j
...@@ -100,41 +99,4 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl ...@@ -100,41 +99,4 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
} }
public void getAllVehicleInfo() {
Map<String, Object> map = new HashMap<>();
map.put("startTime", DateTime.now().withMillis(DateUtils.getStartOfDay()).toString(DEFAULT_DATE_TIME_FORMATTER));
map.put("endTime", DateTime.now().withMillis(DateUtils.getEndOfDay()).toString(DEFAULT_DATE_TIME_FORMATTER));
add(map);
}
public void addAll() {
DateTime dateTime = DateTime.parse("2019-10-01 00:00:00", DEFAULT_DATE_TIME_FORMATTER);
DateTime dateTime1 = DateTime.parse("2019-10-01 23:59:59", DEFAULT_DATE_TIME_FORMATTER);
for (int i = 0; i < 52; i++) {
Map<String, Object> map = new HashMap<>();
map.put("startTime", dateTime.plusDays(i).toString(DEFAULT_DATE_TIME_FORMATTER));
map.put("endTime", dateTime1.plusDays(i).toString(DEFAULT_DATE_TIME_FORMATTER));
add(map);
}
}
public void add(Map<String, Object> param) {
List<BranchCompanyVehicleCountVo> branchCompanyVehicleCountVos = vehicleBiz.getAllVehicleInfo(param);
branchCompanyVehicleCountVos.forEach(result->{
try {
if (result != null) {
BranchCompanyVehicleCount branchCompanyVehicleCount = new BranchCompanyVehicleCount();
branchCompanyVehicleCount.setCompanyName(result.getParkBranchCompanyName());
branchCompanyVehicleCount.setVehicleNum(result.getCount());
branchCompanyVehicleCount.setCountDate(DateTime.parse(param.get("startTime").toString().split(" ")[0]).toDate());
branchCompanyVehicleCountBiz.add(branchCompanyVehicleCount);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
} }
package com.xxfc.platform.vehicle.mapper; package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount; import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.pojo.VehicleWeekCountVo; import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
import java.util.List; import java.util.List;
...@@ -9,8 +9,10 @@ import java.util.Map; ...@@ -9,8 +9,10 @@ import java.util.Map;
public interface BranchCompanyVehicleCountMapper extends Mapper<BranchCompanyVehicleCount> { public interface BranchCompanyVehicleCountMapper extends Mapper<BranchCompanyVehicleCount> {
List<BranchCompanyVehicleCount> getAllByParam(Map<String, Object> param); List<BranchCompanyVehicleCountVo> getAllCountInfo(Map<String, Object> param);
List<BranchCompanyVehicleCount> getAllCompanyName();
List<BranchCompanyVehicleCount> countByMonth(Map<String, Object> param); List<BranchCompanyVehicleCountVo> countByMonth(Map<String, Object> param);
List<VehicleWeekCountVo> countByWeek(Map<String, Object> param);
List<BranchCompanyVehicleCountVo> countByWeek(Map<String, Object> param);
} }
\ No newline at end of file
...@@ -54,5 +54,5 @@ public interface VehicleMapper extends Mapper<Vehicle> { ...@@ -54,5 +54,5 @@ public interface VehicleMapper extends Mapper<Vehicle> {
@Select("select `id` from `vehicle` where `is_del`=0") @Select("select `id` from `vehicle` where `is_del`=0")
List<String> findExistVehicleIds(); List<String> findExistVehicleIds();
List<BranchCompanyVehicleCountVo> getAllVehicleInfo(Map<String, Object> params); List<BranchCompanyVehicleCountVo> getAllVehicleInfo();
} }
\ No newline at end of file
package com.xxfc.platform.vehicle.rest.admin; package com.xxfc.platform.vehicle.rest.admin;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.biz.BranchCompanyVehicleCountBiz; import com.xxfc.platform.vehicle.biz.BranchCompanyVehicleCountBiz;
import com.xxfc.platform.vehicle.common.BaseController; import com.xxfc.platform.vehicle.common.BaseController;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO; import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
@Controller @Controller
@RequestMapping(value = "/bg-vehicle/count") @RequestMapping(value = "/bg-vehicle/count")
public class BranchCompanyVehicleCountController extends BaseController<BranchCompanyVehicleCountBiz> { public class BranchCompanyVehicleCountController extends BaseController<BranchCompanyVehicleCountBiz> {
@Autowired
private HttpServletResponse response;
@GetMapping(value = "/getAll") @GetMapping(value = "/getAll")
@ResponseBody @ResponseBody
public ObjectRestResponse getAll(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) { public ObjectRestResponse getAll(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
return baseBiz.findAll(branchCompanyVehicleCountDTO); return baseBiz.getAllCountInfo(branchCompanyVehicleCountDTO);
}
@GetMapping("/app/unauth/export")
public void exportVehicleInfo(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) throws Exception {
PageDataVO<BranchCompanyVehicleCountVo> pageDataVO = baseBiz.getAllCountInfo(branchCompanyVehicleCountDTO).getData();
if (pageDataVO != null && pageDataVO.getData() != null) {
ExcelWriter writer = ExcelUtil.getWriter(true);
writer.addHeaderAlias("companyId", "公司ID");
writer.addHeaderAlias("companyName", "公司名");
writer.addHeaderAlias("countYear", "年");
writer.addHeaderAlias("countMonth", "月");
writer.addHeaderAlias("countWeek", "周");
writer.addHeaderAlias("weekStartDate", "开始日期");
writer.addHeaderAlias("weekEndDate", "结束日期");
writer.addHeaderAlias("countDate", "日期");
writer.addHeaderAlias("vehicleNum", "数量");
writer.autoSizeColumnAll();
// 一次性写出内容,使用默认样式,强制输出标题
writer.write(pageDataVO.getData(), true);
//response为HttpServletResponse对象
response.setContentType("application/vnd.ms-excel;charset=utf-8");
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
response.setHeader("Content-Disposition", "attachment;filename=clxx.xlsx");
//out为OutputStream,需要写出到的目标流
ServletOutputStream out = response.getOutputStream();
writer.flush(out, true);
// 关闭writer,释放内存
writer.close();
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
} }
} }
...@@ -7,15 +7,11 @@ import com.github.wxiaoqi.security.admin.feign.UserFeign; ...@@ -7,15 +7,11 @@ import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO; import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig; import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.common.exception.BaseException; import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.biz.BranchCompanyVehicleCountBiz; import com.xxfc.platform.vehicle.biz.BranchCompanyVehicleCountBiz;
import com.xxfc.platform.vehicle.biz.VehicleBiz; import com.xxfc.platform.vehicle.biz.VehicleBiz;
import com.xxfc.platform.vehicle.biz.VehicleInformationDownloadBiz; import com.xxfc.platform.vehicle.biz.VehicleInformationDownloadBiz;
import com.xxfc.platform.vehicle.common.BaseController; import com.xxfc.platform.vehicle.common.BaseController;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.pojo.VehicleExcelVo; import com.xxfc.platform.vehicle.pojo.VehicleExcelVo;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -76,36 +72,9 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle ...@@ -76,36 +72,9 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
IoUtil.close(out); IoUtil.close(out);
} }
@GetMapping("/app/unauth/export")
public void exportVehicleInfo(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) throws Exception {
PageDataVO<BranchCompanyVehicleCount> pageDataVO = branchCompanyVehicleCountBiz.findAll(branchCompanyVehicleCountDTO).getData();
if (pageDataVO == null || pageDataVO.getData() == null) {
throw new BaseException(ResultCode.getMsg(ResultCode.NOTEXIST_CODE), ResultCode.NOTEXIST_CODE);
}
List<BranchCompanyVehicleCount> rows = pageDataVO.getData();
ExcelWriter writer = ExcelUtil.getWriter(true);
writer.addHeaderAlias("id", "ID");
writer.addHeaderAlias("countDate", "日期");
writer.addHeaderAlias("companyName", "停靠分公司");
writer.addHeaderAlias("vehicleNum", "车辆数量");
// 一次性写出内容,使用默认样式,强制输出标题
writer.write(rows, true);
//response为HttpServletResponse对象
response.setContentType("application/vnd.ms-excel;charset=utf-8");
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
response.setHeader("Content-Disposition", "attachment;filename=vehicleInfo.xlsx");
//out为OutputStream,需要写出到的目标流
ServletOutputStream out = response.getOutputStream();
writer.flush(out, true);
// 关闭writer,释放内存
writer.close();
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
@GetMapping("/app/unauth/addAll") @GetMapping("/app/unauth/addAll")
public void addAll() { public void addAll() {
baseBiz.addAll(); branchCompanyVehicleCountBiz.addAll(vehicleBiz.getAllVehicleInfo());
} }
} }
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper" > <mapper namespace="com.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper" >
<resultMap id="BaseResultMap" type="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="BIGINT" />
<result column="company_name" property="companyName" jdbcType="VARCHAR" />
<result column="vehicle_num" property="vehicleNum" jdbcType="INTEGER" />
<result column="count_date" property="countDate" jdbcType="TIMESTAMP" />
<result column="company_id" property="companyId" jdbcType="INTEGER" />
</resultMap>
<select id="getAllByParam" parameterType="Map" resultType="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount"> <select id="getAllCountInfo" parameterType="Map" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo">
SELECT company_name, CEILING(( SELECT c.*, b.`name` as companyName from branch_company_vehicle_count c
CASE LEFT JOIN branch_company b on b.id = c.company_id
WHEN #{type} = 1 THEN <where>
sum(vehicle_num) / #{dayNum} <if test = "companyId != null">
WHEN #{type} = 2 THEN and c.company_id = #{companyId}
sum(vehicle_num) / #{dayNum} </if>
WHEN #{type} = 3 THEN <if test="startTime != null and startTime != ''">
sum(vehicle_num) / #{dayNum} and c.count_date &gt;= #{startTime}
END </if>
)) <if test="endTime != null and endTime != ''">
AS vehicleNum from branch_company_vehicle_count and c.count_date &lt;= #{endTime}
<where> </if>
<if test="companyName != null and companyName != ''"> </where>
and company_name like concat('%', #{companyName}, '%') order by c.count_date
</if>
<if test="startTime != null and startTime != ''">
and count_date &gt; #{startTime} and count_date &lt; #{endTime}
</if>
</where>
GROUP BY company_name
</select>
<select id="getAllCompanyName" resultType="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount">
select distinct(company_name) from branch_company_vehicle_count group by company_name
</select> </select>
<select id="countByMonth" parameterType="Map" resultType="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount"> <select id="countByMonth" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo" parameterType="Map">
SELECT SELECT c.company_id, c.count_year, c.count_month, b.`name` as companyName, sum(c.vehicle_num) as vehicle_num from branch_company_vehicle_count c
DATE_FORMAT(b2.count_date, "%Y年%m月") AS countDate, LEFT JOIN branch_company b on b.id = c.company_id
sum(b2.vehicle_num) as vehicleNum <where>
FROM <if test = "companyId != null">
( and c.company_id = #{companyId}
select tmp.* </if>
FROM <if test="startTime != null and startTime != ''">
( and c.count_date &gt;= #{startTime}
SELECT </if>
b.* <if test="endTime != null and endTime != ''">
FROM and c.count_date &lt;= #{endTime}
branch_company_vehicle_count b </if>
WHERE </where>
b.company_name like concat('%', #{companyName}, '%') GROUP BY c.company_id,c.count_year,c.count_month
<if test="startTime != null and startTime != ''">
and count_date &gt;= #{startTime} and count_date &lt;= #{endTime}
</if>
)tmp
) b2
GROUP BY
DATE_FORMAT(b2.count_date, "%Y年%m月")
ORDER BY
DATE_FORMAT(b2.count_date, "%Y年%m月") DESC;
</select> </select>
<select id="countByWeek" resultType="com.xxfc.platform.vehicle.pojo.VehicleWeekCountVo" parameterType="Map"> <select id="countByWeek" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo" parameterType="Map">
SELECT DATE_FORMAT(count_date,'%u') as week,min(count_date) as dateTime,sum(b2.vehicle_num) as count SELECT c.company_id, c.count_year, c.count_week, b.`name` as companyName, sum(c.vehicle_num) as vehicle_num from branch_company_vehicle_count c
FROM ( LEFT JOIN branch_company b on b.id = c.company_id
select tmp.* <where>
FROM <if test = "companyId != null">
( and c.company_id = #{companyId}
SELECT </if>
b.* <if test="startTime != null and startTime != ''">
FROM and c.count_date &gt;= #{startTime}
branch_company_vehicle_count b </if>
WHERE <if test="endTime != null and endTime != ''">
b.company_name like concat('%', #{companyName}, '%') and c.count_date &lt;= #{endTime}
<if test="startTime != null and startTime != ''"> </if>
and count_date &gt;= #{startTime} and count_date &lt;= #{endTime} </where>
</if> GROUP BY c.company_id,c.count_year,c.count_week
)tmp
) b2
GROUP BY week
ORDER BY week asc;
</select> </select>
</mapper> </mapper>
\ No newline at end of file
...@@ -591,8 +591,8 @@ ...@@ -591,8 +591,8 @@
</select> </select>
<!--导出分公司停靠所有车辆--> <!--导出分公司停靠所有车辆-->
<select id="getAllVehicleInfo" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo" parameterType="Map"> <select id="getAllVehicleInfo" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo">
select b.id as companyId, b.name as companyName, DATE_FORMAT(now(),'%Y') as countYear, DATE_FORMAT(now(),'%m') as countMonth,DATE_FORMAT(now(),'%u') as countWeek,DATE_FORMAT(now(),'%Y-%m-%d') as countDate,count(*) from vehicle v select b.id as companyId, DATE_FORMAT(now(),'%Y') as countYear, DATE_FORMAT(now(),'%m') as countMonth,DATE_FORMAT(now(),'%u') as countWeek,DATE_FORMAT(now(),'%Y-%m-%d') as countDate,count(*) as vehicleNum from vehicle v
LEFT JOIN branch_company b on b.id = v.park_branch_company_id LEFT JOIN branch_company b on b.id = v.park_branch_company_id
GROUP BY b.id GROUP BY b.id
</select> </select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment