Browse Source

fix: 解决车辆年度里程统计数据异常的问题

zhongwei
liwen 5 months ago
parent
commit
81ee0f3a73
  1. 4
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/CarMilesYearVO.java
  2. 5
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml
  3. 11
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java

4
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/CarMilesYearVO.java

@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
/** /**
* @author liwen * @author liwen
@ -78,4 +79,7 @@ public class CarMilesYearVO {
@ExcelProperty(value = "合计里程/km", order = 15) @ExcelProperty(value = "合计里程/km", order = 15)
@ApiModelProperty("合计里程数") @ApiModelProperty("合计里程数")
private BigDecimal sumMiles; private BigDecimal sumMiles;
@ApiModelProperty("创建时间")
private Date createTime;
} }

5
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml

@ -4,7 +4,7 @@
<select id="selectCarByYear" resultType="com.hnac.hzims.safeproduct.vo.CarMilesYearVO"> <select id="selectCarByYear" resultType="com.hnac.hzims.safeproduct.vo.CarMilesYearVO">
SELECT SELECT
DISTINCT t1.unit, t1.car_brand, t1.plate_number, t1.create_user, t1.create_dept DISTINCT t1.unit, t1.car_brand, t1.plate_number, t1.create_time
FROM FROM
hzims_car t1 hzims_car t1
LEFT JOIN hzims_car_used_record t2 ON t1.id = t2.car_id LEFT JOIN hzims_car_used_record t2 ON t1.id = t2.car_id
@ -22,8 +22,7 @@
<select id="selectMilesByCar" resultType="com.hnac.hzims.safeproduct.dto.CarMilesYearDTO"> <select id="selectMilesByCar" resultType="com.hnac.hzims.safeproduct.dto.CarMilesYearDTO">
SELECT SELECT
t1.unit, t1.car_brand, t1.plate_number, DATE_FORMAT(t2.end_time, '%m') as dateTime, sum(t2.miles) as miles, t1.unit, t1.car_brand, t1.plate_number, DATE_FORMAT(t2.end_time, '%m') as dateTime, sum(t2.miles) as miles
t1.create_user, t1.create_dept
FROM FROM
hzims_car t1 hzims_car t1
LEFT JOIN hzims_car_used_record t2 ON t1.id = t2.car_id LEFT JOIN hzims_car_used_record t2 ON t1.id = t2.car_id

11
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java

@ -15,6 +15,7 @@ import com.hnac.hzims.safeproduct.entity.CarEntity;
import com.hnac.hzims.safeproduct.mapper.CarMapper; import com.hnac.hzims.safeproduct.mapper.CarMapper;
import com.hnac.hzims.safeproduct.service.*; import com.hnac.hzims.safeproduct.service.*;
import com.hnac.hzims.safeproduct.vo.CarMilesYearVO; import com.hnac.hzims.safeproduct.vo.CarMilesYearVO;
import org.apache.commons.collections4.map.HashedMap;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
@ -29,6 +30,7 @@ import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -71,7 +73,7 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
} }
List<String> carList = records.stream().map(CarMilesYearVO::getPlateNumber).collect(Collectors.toList()); List<String> carList = records.stream().map(CarMilesYearVO::getPlateNumber).collect(Collectors.toList());
List<CarMilesYearDTO> milesList = baseMapper.selectMilesByCar(carList, year); List<CarMilesYearDTO> milesList = baseMapper.selectMilesByCar(carList, year);
List<CarMilesYearVO> res = new ArrayList<>(); HashedMap<String, CarMilesYearVO> map = new HashedMap<>();
milesList.forEach(data -> { milesList.forEach(data -> {
CarMilesYearVO carMilesYearVO = records.stream().filter(x -> x.getPlateNumber().equals(data.getPlateNumber())) CarMilesYearVO carMilesYearVO = records.stream().filter(x -> x.getPlateNumber().equals(data.getPlateNumber()))
.collect(Collectors.toList()).get(0); .collect(Collectors.toList()).get(0);
@ -127,11 +129,14 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
carMilesYearVO.setSumMiles(sum.add(data.getMiles())); carMilesYearVO.setSumMiles(sum.add(data.getMiles()));
} }
if (!carMilesYearVO.getSumMiles().equals(new BigDecimal(0))) { if (!carMilesYearVO.getSumMiles().equals(new BigDecimal(0))) {
res.add(carMilesYearVO); map.put(carMilesYearVO.getPlateNumber(), carMilesYearVO);
} }
}); });
List<CarMilesYearVO> list = new ArrayList<>(map.values());
List<CarMilesYearVO> res = list.stream().sorted(Comparator.comparing(CarMilesYearVO::getCreateTime).reversed())
.collect(Collectors.toList());
page.setRecords(res); page.setRecords(res);
page.setTotal(res.size()); page.setTotal(carPage.getTotal());
return page; return page;
} }

Loading…
Cancel
Save