Commit db7c7d6c authored by hanfeng's avatar hanfeng

添加车辆信息下载

parent 8c61cc63
...@@ -5,7 +5,7 @@ import lombok.Data; ...@@ -5,7 +5,7 @@ import lombok.Data;
import java.util.Date; import java.util.Date;
@Data @Data
public class ResultVehicleVo extends VehicleExcelVo { public class ResultVehicleVo {
/** /**
* 主键(uuid) * 主键(uuid)
*/ */
......
...@@ -2,9 +2,13 @@ package com.xxfc.platform.vehicle.pojo; ...@@ -2,9 +2,13 @@ package com.xxfc.platform.vehicle.pojo;
import lombok.Data; import lombok.Data;
import java.util.HashMap;
import java.util.Map;
@Data @Data
public class VehicleExcelVo { public class VehicleExcelVo {
/** /**
* 车牌号,空字符串-没有 * 车牌号,空字符串-没有
*/ */
...@@ -23,15 +27,15 @@ public class VehicleExcelVo { ...@@ -23,15 +27,15 @@ public class VehicleExcelVo {
/** /**
* 用途类型:租赁房车(1)、展车等,对应关系见车辆常量表 *
*/ */
private Integer useType; private String useType;
/** /**
* 停靠分支机构(id * 停靠分支机构(
*/ */
private Integer parkBranchCompanyId; private String parkBranchCompanyName;
} }
...@@ -5,15 +5,19 @@ import com.github.pagehelper.PageHelper; ...@@ -5,15 +5,19 @@ import com.github.pagehelper.PageHelper;
import com.github.wxiaoqi.security.admin.feign.UserFeign; 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.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Lists;
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.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 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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -28,7 +32,7 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl ...@@ -28,7 +32,7 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
public List getByPageNotAllData(VehiclePageQueryVo vehiclePageQueryVo, List<Integer> companyList) throws Exception { public List<VehicleExcelVo> getByPageNotAllData(VehiclePageQueryVo vehiclePageQueryVo, List<Integer> companyList) throws Exception {
Map<String, Object> params = PropertyUtils.describe(vehiclePageQueryVo); Map<String, Object> params = PropertyUtils.describe(vehiclePageQueryVo);
//处理预定日期相关参数 //处理预定日期相关参数
vehicleBiz.adjustBookedInfoParam(params, vehiclePageQueryVo); vehicleBiz.adjustBookedInfoParam(params, vehiclePageQueryVo);
...@@ -38,10 +42,10 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl ...@@ -38,10 +42,10 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
params.put("companyList", Arrays.asList(-1)); params.put("companyList", Arrays.asList(-1));
} }
return mapper.getByPageNotAllData(params); return mapper.getVehicleExcelVoNotAllData(params);
} }
public List getByPage(VehiclePageQueryVo vehiclePageQueryVo) throws Exception { public List<VehicleExcelVo> getByPage(VehiclePageQueryVo vehiclePageQueryVo) throws Exception {
Map<String, Object> params = PropertyUtils.describe(vehiclePageQueryVo); Map<String, Object> params = PropertyUtils.describe(vehiclePageQueryVo);
//处理预定日期相关参数 //处理预定日期相关参数
...@@ -50,7 +54,7 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl ...@@ -50,7 +54,7 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
if (vehiclePageQueryVo.getModelId() == null) { if (vehiclePageQueryVo.getModelId() == null) {
params.remove("modelId"); params.remove("modelId");
} }
return mapper.getByPage(params); return mapper.getVehicleExcelVo(params);
} }
public List<VehicleExcelVo> getList(String vehiclePageQueryVoJson, UserDTO userDTO) { public List<VehicleExcelVo> getList(String vehiclePageQueryVoJson, UserDTO userDTO) {
...@@ -59,17 +63,16 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl ...@@ -59,17 +63,16 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
if (StringUtils.isNotBlank(vehiclePageQueryVoJson)){ if (StringUtils.isNotBlank(vehiclePageQueryVoJson)){
vehiclePageQueryVo = JSON.parseObject(vehiclePageQueryVoJson, VehiclePageQueryVo.class); vehiclePageQueryVo = JSON.parseObject(vehiclePageQueryVoJson, VehiclePageQueryVo.class);
} }
if (userDTO != null) {
if (userDTO.getDataAll() == 2) { if (userDTO.getDataAll() == 2) {
List<Integer> companyList = vehicleBiz.dataCompany(userDTO.getDataZone(), userDTO.getDataCompany()); List<Integer> companyList = vehicleBiz.dataCompany(userDTO.getDataZone(), userDTO.getDataCompany());
return getByPageNotAllData(vehiclePageQueryVo, companyList); return getByPageNotAllData(vehiclePageQueryVo, companyList);
} }
}
return getByPage(vehiclePageQueryVo); return getByPage(vehiclePageQueryVo);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return new ArrayList(); return new ArrayList();
} }
} }
...@@ -16,6 +16,10 @@ public interface VehicleMapper extends Mapper<Vehicle> { ...@@ -16,6 +16,10 @@ public interface VehicleMapper extends Mapper<Vehicle> {
public List<ResultVehicleVo> getByPageNotAllData(Map<String, Object> params); public List<ResultVehicleVo> getByPageNotAllData(Map<String, Object> params);
List<VehicleExcelVo> getVehicleExcelVo(Map<String, Object> params);
List<VehicleExcelVo> getVehicleExcelVoNotAllData(Map<String, Object> params);
public int updateStatusById(Map<String, Object> params); public int updateStatusById(Map<String, Object> params);
/** /**
......
...@@ -3,24 +3,15 @@ package com.xxfc.platform.vehicle.rest.admin; ...@@ -3,24 +3,15 @@ package com.xxfc.platform.vehicle.rest.admin;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter; import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.github.wxiaoqi.security.admin.feign.UserFeign; 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.google.common.collect.Lists; import com.github.wxiaoqi.security.common.exception.BaseException;
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.common.CustomIllegalParamException;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.constant.ResCode.ResCode;
import com.xxfc.platform.vehicle.entity.Vehicle;
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 lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtilsBean;
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;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -29,9 +20,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -29,9 +20,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -53,15 +41,18 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle ...@@ -53,15 +41,18 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
HttpServletResponse response; HttpServletResponse response;
@GetMapping("/excel") @GetMapping("/excel")
public void downloadExcel(@RequestParam(value = "vehiclePageQueryVoJson",required = false) String vehiclePageQueryVoJson) throws IOException, InvocationTargetException, IllegalAccessException { public void downloadExcel(@RequestParam(value = "vehiclePageQueryVoJson",required = false) String vehiclePageQueryVoJson) throws Exception {
UserDTO userDTO = userFeign.userinfoByToken(userAuthConfig.getToken(request)).getData(); UserDTO userDTO = userFeign.userinfoByToken(userAuthConfig.getToken(request)).getData();
if (userDTO==null) {
throw new BaseException("token已失效");
}
List<VehicleExcelVo> rows = baseBiz.getList(vehiclePageQueryVoJson, userDTO); List<VehicleExcelVo> rows = baseBiz.getList(vehiclePageQueryVoJson, userDTO);
ExcelWriter writer = ExcelUtil.getWriter(true); ExcelWriter writer = ExcelUtil.getWriter(true);
writer.addHeaderAlias("numberPlate", "车牌号"); writer.addHeaderAlias("numberPlate", "车牌号");
writer.addHeaderAlias("code", "车辆编码"); writer.addHeaderAlias("code", "车辆编码");
writer.addHeaderAlias("vehicleType", "车型"); writer.addHeaderAlias("vehicleType", "车型");
writer.addHeaderAlias("useType", "用途"); writer.addHeaderAlias("useType", "用途");
writer.addHeaderAlias("parkBranchCompanyId", "停靠分公司"); writer.addHeaderAlias("parkBranchCompanyName", "停靠分公司");
// 一次性写出内容,使用默认样式,强制输出标题 // 一次性写出内容,使用默认样式,强制输出标题
writer.write(rows, true); writer.write(rows, true);
//response为HttpServletResponse对象 //response为HttpServletResponse对象
......
...@@ -180,6 +180,7 @@ ...@@ -180,6 +180,7 @@
) r ORDER BY r.parkBranchCompanyName ) r ORDER BY r.parkBranchCompanyName
</select> </select>
<select id="getByPageNotAllData" parameterType="java.util.Map" <select id="getByPageNotAllData" parameterType="java.util.Map"
resultType="com.xxfc.platform.vehicle.pojo.ResultVehicleVo"> resultType="com.xxfc.platform.vehicle.pojo.ResultVehicleVo">
SELECT r.* FROM ( SELECT r.* FROM (
...@@ -337,6 +338,248 @@ ...@@ -337,6 +338,248 @@
) r ORDER BY r.parkBranchCompanyName ) r ORDER BY r.parkBranchCompanyName
</select> </select>
<select id="getVehicleExcelVo" parameterType="java.util.Map"
resultType="com.xxfc.platform.vehicle.pojo.VehicleExcelVo">
SELECT r.* FROM (
select
v.`code`,
v.number_plate,
bc.name as parkBranchCompanyName,
c.val as useType,
vm.name as vehicleType
from vehicle v
<if test=" yearMonthAndParam != null ">
left join
vehicle_book_info vbi on v.`id` = vbi.vehicle
</if>
-- LEFT JOIN branch_company bc ON v.park_branch_company_id = bc.id
-- LEFT JOIN branch_company bc1 ON v.expect_destination_branch_company_id = bc1.id
-- 停车分公司
LEFT JOIN branch_company bc ON v.park_branch_company_id = bc.id
-- 目的地分公司
LEFT JOIN branch_company bc1 ON v.expect_destination_branch_company_id = bc1.id
-- 所属分公司
LEFT JOIN branch_company bc2 ON v.subordinate_branch = bc2.id
LEFT JOIN vehicle_book_record v2 on v2.vehicle_id = v.id
LEFT JOIN vehicle_departure_log v3 on v2.id = v3.book_record_id
LEFT JOIN vehicle_model vm ON v.model_id = vm.id
LEFT JOIN (select * from constant where type = 2) c ON v.use_type = c.code
where
v.is_del=0
<if test="mRangeDateEnd !=null">
and v.maintenance_date &lt;= #{mRangeDateEnd}
</if>
<if test="modelId != null and modelId != ''">
and v.model_id = #{modelId}
</if>
<if test="mRangeDateStart !=null">
and v.maintenance_date &gt;= #{mRangeDateStart}
</if>
<if test="aVRangeDateStart !=null">
and v.annual_verification_date &lt;= #{aVRangeDateEnd}
</if>
<if test="aVRangeDateEnd !=null">
and v.annual_verification_date &gt;= #{aVRangeDateStart}
</if>
<if test="insuranceDateRangeStart !=null">
and v.insurance_end_date &lt;= #{insuranceDateRangeEnd}
</if>
<if test="insuranceDateRangeEnd !=null">
and v.insurance_end_date &gt;= #{insuranceDateRangeStart}
</if>
<if test="insuranceCompany !=null">
and v.insurance_company = #{insuranceCompany}
</if>
<if test="belongToName !=null">
and v.belong_to_name = #{belongToName}
</if>
<if test="vin !=null and vin != ''">
and v.vin = #{vin}
</if>
<!-- <if test="subordinateBranch !=null">-->
<!-- and v.subordinate_branch = #{subordinateBranch}-->
<!-- </if>-->
<if test="code !=null">
and v.code = #{code}
</if>
<if test="status !=null and status != 6 and status != 7">
and v.status = #{status}
</if>
<if test="status !=null and status == 6">
and v3.id is not NULL and v2.book_type = 3 and v3.state = 0
</if>
<if test="status !=null and status == 7">
and v3.id is not NULL and v2.book_type = 6 and v3.state = 0
</if>
<if test="numberPlate !=null and numberPlate != ''">
and v.number_plate like concat('%',#{numberPlate},'%')
</if>
<if test="brand !=null">
and v.brand = #{brand}
</if>
<if test="useType !=null">
and v.use_type = #{useType}
</if>
-- 添加所属大区搜索条件
<if test="zoneId !=null">
and bc.zone_id=#{zoneId}
</if>
<!-- 若需根据预定日期条件查询,针对换为位操作 -->
<if test=" yearMonthAndParam !=null ">
<foreach collection="yearMonthAndParam" index="yearMonth" item="andOperation">
and
( (vbi.`year_month` = #{yearMonth} or vbi.`year_month` is null) and
ifnull(vbi.`booked_date`,0) &amp; #{andOperation.andOperationFactor} = #{andOperation.andOperationRs}
)
</foreach>
</if>
<if test="subordinateBranch !=null ">
and ( v.park_branch_company_id = #{subordinateBranch})
</if>
<if test=" addrProvince !=null or addrCity !=null or zoneId !=null ">
<if test="addrProvince !=null">
and bc.addr_province=#{addrProvince}
</if>
<if test="addrCity !=null">
and bc.addr_city=#{addrCity}
</if>
<if test="zoneId !=null">
and bc.zone_id=#{zoneId}
</if>
</if>
order by v.code
) r ORDER BY r.parkBranchCompanyName
</select>
<select id="getVehicleExcelVoNotAllData" parameterType="java.util.Map"
resultType="com.xxfc.platform.vehicle.pojo.VehicleExcelVo">
SELECT r.* FROM (
select
v.`code`,
v.number_plate,
bc.name as parkBranchCompanyName,
c.val as useType,
vm.name as vehicleType
from vehicle v
<if test=" yearMonthAndParam !=null ">
left join
vehicle_book_info vbi on v.`id` = vbi.vehicle
</if>
-- 停车分公司
LEFT JOIN branch_company bc ON v.park_branch_company_id = bc.id
-- 目的地分公司
LEFT JOIN branch_company bc1 ON v.expect_destination_branch_company_id = bc1.id
-- 所属分公司
LEFT JOIN branch_company bc2 ON v.subordinate_branch = bc2.id
LEFT JOIN vehicle_model vm ON v.model_id = vm.id
LEFT JOIN (select * from constant where type = 2) c ON v.use_type = c.code
where
v.is_del=0
<if test="companyList != null">
and ( v.park_branch_company_id in (
<trim suffixOverrides=",">
<foreach collection="companyList" item="companyId">
#{companyId},
</foreach>
</trim>
)
<!--or v.expect_destination_branch_company_id in (
<trim suffixOverrides=",">
<foreach collection="companyList" item="companyId">
#{companyId},
</foreach>
</trim>
)-->
<!-- or v.subordinate_branch in (-->
<!-- <trim suffixOverrides=",">-->
<!-- <foreach collection="companyList" item="companyId">-->
<!-- #{companyId},-->
<!-- </foreach>-->
<!-- </trim>-->
)
</if>
<if test="mRangeDateEnd !=null">
and v.maintenance_date &lt;= #{mRangeDateEnd}
</if>
<if test="modelId != null and modelId != ''">
and v.model_id = #{modelId}
</if>
<if test="mRangeDateStart !=null">
and v.maintenance_date &gt;= #{mRangeDateStart}
</if>
<if test="aVRangeDateStart !=null">
and v.annual_verification_date &lt;= #{aVRangeDateEnd}
</if>
<if test="aVRangeDateEnd !=null">
and v.annual_verification_date &gt;= #{aVRangeDateStart}
</if>
<if test="insuranceDateRangeStart !=null">
and v.insurance_end_date &lt;= #{insuranceDateRangeEnd}
</if>
<if test="insuranceDateRangeEnd !=null">
and v.insurance_end_date &gt;= #{insuranceDateRangeStart}
</if>
<if test="insuranceCompany !=null">
and v.insurance_company = #{insuranceCompany}
</if>
<if test="belongToName !=null">
and v.belong_to_name = #{belongToName}
</if>
<if test="vin !=null and vin != ''">
and v.vin = #{vin}
</if>
<!-- <if test="subordinateBranch !=null">-->
<!-- and v.subordinate_branch = #{subordinateBranch}-->
<!-- </if>-->
<if test="code !=null">
and v.code = #{code}
</if>
<if test="status !=null">
and v.status = #{status}
</if>
<if test="numberPlate !=null and numberPlate != ''">
and v.number_plate like concat('%',#{numberPlate},'%')
</if>
<if test="brand !=null">
and v.brand = #{brand}
</if>
<if test="useType !=null">
and v.use_type = #{useType}
</if>
-- 添加所属大区搜索条件
<if test="zoneId !=null">
and bc.zone_id=#{zoneId}
</if>
<!-- 若需根据预定日期条件查询,针对换为位操作 -->
<if test=" yearMonthAndParam !=null ">
<foreach collection="yearMonthAndParam" index="yearMonth" item="andOperation">
and
( (vbi.`year_month` = #{yearMonth} or vbi.`year_month` is null) and
ifnull(vbi.`booked_date`,0) &amp; #{andOperation.andOperationFactor} = #{andOperation.andOperationRs}
)
</foreach>
</if>
<if test="subordinateBranch !=null ">
and ( v.park_branch_company_id = #{subordinateBranch} or
v.expect_destination_branch_company_id=#{subordinateBranch} )
</if>
<if test=" addrProvince !=null or addrCity !=null or zoneId !=null ">
<if test="addrProvince !=null">
and bc.addr_province=#{addrProvince}
</if>
<if test="addrCity !=null">
and bc.addr_city=#{addrCity}
</if>
<if test="zoneId !=null">
and bc.zone_id=#{zoneId}
</if>
</if>
order by v.code
) r ORDER BY r.parkBranchCompanyName
</select>
<select id="lockByCode" resultType="com.xxfc.platform.vehicle.entity.Vehicle" <select id="lockByCode" resultType="com.xxfc.platform.vehicle.entity.Vehicle"
parameterType="com.xxfc.platform.vehicle.pojo.AddOrUpdateVehicleVo"> parameterType="com.xxfc.platform.vehicle.pojo.AddOrUpdateVehicleVo">
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