mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
feat(smartCamCarData): 添加车辆数据对比功能
- 新增 compare 接口用于对比智能摄像头和地磅设备的车辆数据- 实现 CompareRequest 和 CompareResult 数据传输对象 - 在 SmartCamCarDataService 中添加 compare 方法实现数据对比逻辑 - 优化代码结构,引入 Specification 用于构建查询条件
This commit is contained in:
@@ -4,9 +4,7 @@ import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.CreateSmartCamCarDataDto;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.SmartCamCarDataDto;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.UpdateSmartCamCarDataDto;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.*;
|
||||
import cn.lihongjie.coal.smartCamCarData.service.SmartCamCarDataService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -51,4 +49,11 @@ public class SmartCamCarDataController {
|
||||
public Page<SmartCamCarDataDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/compare")
|
||||
public CompareResult compare(@RequestBody CompareRequest request) {
|
||||
return this.service.compare(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.lihongjie.coal.smartCamCarData.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
public class CompareRequest {
|
||||
|
||||
private LocalDateTime start;
|
||||
|
||||
private LocalDateTime end;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.lihongjie.coal.smartCamCarData.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
public class CompareResult {
|
||||
|
||||
|
||||
private List<CarInfo> carInfos;
|
||||
|
||||
|
||||
@Data
|
||||
public static class CarInfo {
|
||||
|
||||
private String number;
|
||||
|
||||
|
||||
private Integer camEntryCnt;
|
||||
|
||||
private Integer camExitCnt;
|
||||
|
||||
|
||||
private Integer weightEntryCnt;
|
||||
|
||||
private Integer weightExitCnt;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,14 +3,20 @@ package cn.lihongjie.coal.smartCamCarData.service;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.CreateSmartCamCarDataDto;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.SmartCamCarDataDto;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.UpdateSmartCamCarDataDto;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.*;
|
||||
import cn.lihongjie.coal.smartCamCarData.entity.SmartCamCarDataEntity;
|
||||
import cn.lihongjie.coal.smartCamCarData.mapper.SmartCamCarDataMapper;
|
||||
import cn.lihongjie.coal.smartCamCarData.repository.SmartCamCarDataRepository;
|
||||
import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity;
|
||||
import cn.lihongjie.coal.weightDeviceData.repository.WeightDeviceDataRepository;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -19,9 +25,14 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
@@ -35,6 +46,105 @@ public class SmartCamCarDataService
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
@Autowired WeightDeviceDataRepository weightDeviceDataRepository;
|
||||
|
||||
public CompareResult compare(CompareRequest request) {
|
||||
|
||||
List<SmartCamCarDataEntity> camData =
|
||||
this.repository.findAll(
|
||||
new Specification<SmartCamCarDataEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<SmartCamCarDataEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(
|
||||
root.get("organizationId"),
|
||||
Ctx.activeOrganizationId()),
|
||||
criteriaBuilder.between(
|
||||
root.get("entryTime"),
|
||||
request.getStart(),
|
||||
request.getEnd()));
|
||||
}
|
||||
});
|
||||
|
||||
List<WeightDeviceDataEntity> weightData =
|
||||
weightDeviceDataRepository.findAll(
|
||||
new Specification<WeightDeviceDataEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<WeightDeviceDataEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(
|
||||
root.get("organizationId"),
|
||||
Ctx.activeOrganizationId()),
|
||||
criteriaBuilder.between(
|
||||
root.get("ycgbTIme"),
|
||||
request.getStart(),
|
||||
request.getEnd()));
|
||||
}
|
||||
});
|
||||
|
||||
Map<String, CompareResult.CarInfo> carInfoMap = new HashMap<>();
|
||||
|
||||
for (SmartCamCarDataEntity camDatum : camData) {
|
||||
|
||||
if (carInfoMap.containsKey(camDatum.getNumber())) {
|
||||
CompareResult.CarInfo carInfo = carInfoMap.get(camDatum.getNumber());
|
||||
|
||||
if (camDatum.getEntry() != null) {
|
||||
|
||||
carInfo.setCamEntryCnt(carInfo.getCamEntryCnt() + 1);
|
||||
}
|
||||
|
||||
if (camDatum.getExit() != null) {
|
||||
carInfo.setCamExitCnt(carInfo.getCamExitCnt() + 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
CompareResult.CarInfo value = new CompareResult.CarInfo();
|
||||
value.setNumber(camDatum.getNumber());
|
||||
value.setCamEntryCnt(camDatum.getEntry() != null ? 1 : 0);
|
||||
value.setCamExitCnt(camDatum.getExit() != null ? 1 : 0);
|
||||
carInfoMap.put(camDatum.getNumber(), value);
|
||||
}
|
||||
}
|
||||
|
||||
for (WeightDeviceDataEntity weightDatum : weightData) {
|
||||
|
||||
if (carInfoMap.containsKey(weightDatum.getPlanNumber())) {
|
||||
|
||||
CompareResult.CarInfo carInfo = carInfoMap.get(weightDatum.getPlanNumber());
|
||||
|
||||
if (weightDatum.getYcgbTIme() != null) {
|
||||
carInfo.setWeightEntryCnt(carInfo.getWeightEntryCnt() + 1);
|
||||
}
|
||||
if (weightDatum.getEcgbTime() != null) {
|
||||
carInfo.setWeightExitCnt(carInfo.getWeightExitCnt() + 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
CompareResult.CarInfo value = new CompareResult.CarInfo();
|
||||
value.setNumber(weightDatum.getPlanNumber());
|
||||
value.setWeightEntryCnt(weightDatum.getYcgbTIme() != null ? 1 : 0);
|
||||
value.setWeightExitCnt(weightDatum.getEcgbTime() != null ? 1 : 0);
|
||||
carInfoMap.put(weightDatum.getPlanNumber(), value);
|
||||
}
|
||||
}
|
||||
|
||||
CompareResult compareResult = new CompareResult();
|
||||
|
||||
compareResult.setCarInfos(carInfoMap.values().stream().toList());
|
||||
return compareResult;
|
||||
}
|
||||
|
||||
public SmartCamCarDataDto create(CreateSmartCamCarDataDto request) {
|
||||
SmartCamCarDataEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user