Commit 5deb634e authored by jiaorz's avatar jiaorz

后台导出车辆信息

parent 1c46624e
package com.xxfc.platform.vehicle.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
/**
* 分公司停靠车辆统计
*/
@Table(name = "branch_company_vehicle_count")
@Data
public class BranchCompanyVehicleCount {
@Id
private Long id;
/**
* 公司名称
*/
@Column(name = "company_name")
private String companyName;
/**
* 当前停靠车辆数量
*/
@Column(name = "vehicle_num")
private Integer vehicleNum;
/**
* 统计日期
*/
@Column(name = "count_date")
private Date countDate;
/**
* 公司ID
*/
@Column(name = "company_id")
private Integer companyId;
}
\ No newline at end of file
......@@ -3,7 +3,8 @@ package com.xxfc.platform.vehicle.pojo;
import lombok.Data;
@Data
public class BranchCompanyVehicleCount {
public class BranchCompanyVehicleCountVo {
private String parkBranchCompanyName;
private Integer count;
private Integer companyId;
}
package com.xxfc.platform.vehicle.pojo.dto;
import com.github.wxiaoqi.security.common.vo.PageParam;
import lombok.Data;
@Data
public class BranchCompanyVehicleCountDTO extends PageParam {
//开始时间 yyyy-MM-dd
private String startTime;
//结束时间
private String endTime;
private String companyName;
}
package com.xxfc.platform.vehicle.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Iterator;
import java.util.List;
@Service
@Slf4j
public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCountMapper, BranchCompanyVehicleCount> {
public ObjectRestResponse add(List<BranchCompanyVehicleCount> branchCompanyVehicleCounts) {
if (branchCompanyVehicleCounts == null) {
return ObjectRestResponse.paramIsEmpty();
}
Iterator<BranchCompanyVehicleCount> iterator = branchCompanyVehicleCounts.iterator();
while (iterator.hasNext()) {
BranchCompanyVehicleCount newValue = iterator.next();
BranchCompanyVehicleCount oldValue = selectOne(newValue);
if (oldValue != null) {
iterator.remove();
}
}
insertMultiSelective(branchCompanyVehicleCounts);
return ObjectRestResponse.succ();
}
public ObjectRestResponse<PageDataVO<BranchCompanyVehicleCount>> findAll(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
Integer pageNo = branchCompanyVehicleCountDTO.getPage() == null ? 1 : branchCompanyVehicleCountDTO.getPage();
Integer pageSize = branchCompanyVehicleCountDTO.getLimit() == null ? 10 : branchCompanyVehicleCountDTO.getLimit();
branchCompanyVehicleCountDTO.setPage(pageNo);
branchCompanyVehicleCountDTO.setLimit(pageSize);
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<BranchCompanyVehicleCount> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.getAllByParam(query.getSuper()));
return ObjectRestResponse.succ(pageDataVO);
}
}
......@@ -1514,7 +1514,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
return vehicles.stream().map(Vehicle::getId).collect(Collectors.toList());
}
public List<BranchCompanyVehicleCount> getAllVehicleInfo() {
public List<BranchCompanyVehicleCountVo> getAllVehicleInfo() {
return mapper.getAllVehicleInfo();
}
......
......@@ -4,9 +4,10 @@ import com.alibaba.fastjson.JSON;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
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.mapper.VehicleMapper;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo;
import com.xxfc.platform.vehicle.pojo.ResultVehicleVo;
import com.xxfc.platform.vehicle.pojo.VehicleExcelVo;
import com.xxfc.platform.vehicle.pojo.VehiclePageQueryVo;
......@@ -14,7 +15,11 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
......@@ -29,7 +34,10 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
@Autowired
private VehicleBiz vehicleBiz;
@Autowired
private BranchCompanyVehicleCountBiz branchCompanyVehicleCountBiz;
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
public List getByPageNotAllData(VehiclePageQueryVo vehiclePageQueryVo, List<Integer> companyList) throws Exception {
......@@ -94,8 +102,30 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
}
public List<BranchCompanyVehicleCount> getAllVehicleInfo() {
public List<BranchCompanyVehicleCountVo> getAllVehicleInfo() {
return vehicleBiz.getAllVehicleInfo();
}
@Scheduled(cron = "0 0 */2 * * *")
public void add() {
ArrayList<BranchCompanyVehicleCount> arrayList = Lists.newArrayList();
List<BranchCompanyVehicleCountVo> branchCompanyVehicleCountVos = vehicleBiz.getAllVehicleInfo();
branchCompanyVehicleCountVos.parallelStream().forEach(result->{
try {
BranchCompanyVehicleCount branchCompanyVehicleCount = new BranchCompanyVehicleCount();
branchCompanyVehicleCount.setCompanyId(result.getCompanyId());
branchCompanyVehicleCount.setCompanyName(result.getParkBranchCompanyName());
branchCompanyVehicleCount.setVehicleNum(result.getCount());
DateTime dateTime = DateTime.now();
String dateStr = dateTime.toString(DATE_TIME_FORMATTER);
branchCompanyVehicleCount.setCountDate(DateTime.parse(dateStr).toDate());
arrayList.add(branchCompanyVehicleCount);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
branchCompanyVehicleCountBiz.add(arrayList);
}
}
package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
import java.util.Map;
public interface BranchCompanyVehicleCountMapper extends Mapper<BranchCompanyVehicleCount> {
List<BranchCompanyVehicleCount> getAllByParam(Map<String, Object> param);
}
\ No newline at end of file
......@@ -54,5 +54,5 @@ public interface VehicleMapper extends Mapper<Vehicle> {
@Select("select `id` from `vehicle` where `is_del`=0")
List<String> findExistVehicleIds();
List<BranchCompanyVehicleCount> getAllVehicleInfo();
List<BranchCompanyVehicleCountVo> getAllVehicleInfo();
}
\ No newline at end of file
package com.xxfc.platform.vehicle.rest.admin;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.vehicle.biz.BranchCompanyVehicleCountBiz;
import com.xxfc.platform.vehicle.common.BaseController;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value = "/bg-vehicle/count")
public class BranchCompanyVehicleCountController extends BaseController<BranchCompanyVehicleCountBiz> {
@GetMapping(value = "/getAll")
@ResponseBody
public ObjectRestResponse getAll(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
return baseBiz.findAll(branchCompanyVehicleCountDTO);
}
}
......@@ -7,11 +7,15 @@ import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
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.VehicleBiz;
import com.xxfc.platform.vehicle.biz.VehicleInformationDownloadBiz;
import com.xxfc.platform.vehicle.common.BaseController;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.pojo.VehicleExcelVo;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -30,7 +34,7 @@ import java.util.List;
public class VehicleInformationDownloadController extends BaseController<VehicleInformationDownloadBiz> {
@Autowired
UserFeign userFeign;
private UserFeign userFeign;
@Autowired
private UserAuthConfig userAuthConfig;
......@@ -39,7 +43,10 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
private VehicleBiz vehicleBiz;
@Autowired
HttpServletResponse response;
private BranchCompanyVehicleCountBiz branchCompanyVehicleCountBiz;
@Autowired
private HttpServletResponse response;
@GetMapping("/excel")
public void downloadExcel(@RequestParam(value = "vehiclePageQueryVoJson", required = false) String vehiclePageQueryVoJson) throws Exception {
......@@ -70,11 +77,17 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
}
@GetMapping("/app/unauth/export")
public void exportVehicleInfo() throws Exception {
List<BranchCompanyVehicleCount> rows = baseBiz.getAllVehicleInfo();
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("parkBranchCompanyName", "停靠分公司");
writer.addHeaderAlias("count", "车辆数量");
writer.merge(2,"导出车辆数据");
writer.addHeaderAlias("countDate", "日期");
writer.addHeaderAlias("companyName", "停靠分公司");
writer.addHeaderAlias("vehicleNum", "车辆数量");
// 一次性写出内容,使用默认样式,强制输出标题
writer.write(rows, true);
//response为HttpServletResponse对象
......@@ -89,4 +102,5 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
}
<?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" >
<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 * from branch_company_vehicle_count
<where>
<if test="companyName != null and companyName != ''">
and company_name like concat('%', #{companyName}, '%')
</if>
<if test="startTime != null and startTime != ''">
and count_date &gt; #{startTime} and count_date &lt; #{endTime}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -591,10 +591,11 @@
</select>
<!--导出分公司停靠所有车辆-->
<select id="getAllVehicleInfo" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCount">
<select id="getAllVehicleInfo" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo">
SELECT
b1. NAME AS parkBranchCompanyName,
count(v1.id) as count
count(v1.id) as count,
b1.id as companyId
FROM
branch_company b1
LEFT JOIN vehicle v1 ON v1.park_branch_company_id = b1.id
......
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