From 0e3fcad8cc16e71c2f66cabfcf77b9d730de6bd1 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Mon, 5 May 2025 14:08:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(smartCamWhiteList):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E6=91=84=E5=83=8F=E5=A4=B4=E7=99=BD=E5=90=8D?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 SmartCamWhiteList 相关的控制器、DTO、实体类、映射器、仓库和服务 - 在比较逻辑中增加白名单过滤,忽略白名单中的车牌号- 新增白名单数据字典脚本 --- .../service/SmartCamCarDataService.java | 20 +++++ .../SmartCamWhiteListController.java | 54 +++++++++++ .../dto/CreateSmartCamWhiteListDto.java | 11 +++ .../dto/SmartCamWhiteListDto.java | 11 +++ .../dto/UpdateSmartCamWhiteListDto.java | 10 +++ .../entity/SmartCamWhiteListEntity.java | 21 +++++ .../mapper/SmartCamWhiteListMapper.java | 23 +++++ .../SmartCamWhiteListRepository.java | 19 ++++ .../service/SmartCamWhiteListService.java | 89 +++++++++++++++++++ .../dict/enum/smartCamWhiteListDict.groovy | 19 ++++ 10 files changed, 277 insertions(+) create mode 100644 src/main/java/cn/lihongjie/coal/smartCamWhiteList/controller/SmartCamWhiteListController.java create mode 100644 src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/CreateSmartCamWhiteListDto.java create mode 100644 src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/SmartCamWhiteListDto.java create mode 100644 src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/UpdateSmartCamWhiteListDto.java create mode 100644 src/main/java/cn/lihongjie/coal/smartCamWhiteList/entity/SmartCamWhiteListEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/smartCamWhiteList/mapper/SmartCamWhiteListMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/smartCamWhiteList/repository/SmartCamWhiteListRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/smartCamWhiteList/service/SmartCamWhiteListService.java create mode 100644 src/main/resources/scripts/dict/enum/smartCamWhiteListDict.groovy diff --git a/src/main/java/cn/lihongjie/coal/smartCamCarData/service/SmartCamCarDataService.java b/src/main/java/cn/lihongjie/coal/smartCamCarData/service/SmartCamCarDataService.java index 31655d1e..21f07ec7 100644 --- a/src/main/java/cn/lihongjie/coal/smartCamCarData/service/SmartCamCarDataService.java +++ b/src/main/java/cn/lihongjie/coal/smartCamCarData/service/SmartCamCarDataService.java @@ -15,6 +15,8 @@ import cn.lihongjie.coal.smartCamCarLicenseSnapshotData.dto.HumanModifyRequest; import cn.lihongjie.coal.smartCamCarLicenseSnapshotData.dto.SmartCamCarLicenseSnapshotDataDto; import cn.lihongjie.coal.smartCamCarLicenseSnapshotData.entity.SmartCamCarLicenseSnapshotDataEntity; import cn.lihongjie.coal.smartCamCarLicenseSnapshotData.service.SmartCamCarLicenseSnapshotDataService; +import cn.lihongjie.coal.smartCamWhiteList.repository.SmartCamWhiteListRepository; +import cn.lihongjie.coal.smartCamWhiteList.service.SmartCamWhiteListService; import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity; import cn.lihongjie.coal.weightDeviceData.repository.WeightDeviceDataRepository; @@ -39,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; @Service @Slf4j @@ -56,6 +60,10 @@ public class SmartCamCarDataService @Autowired WeightDeviceDataRepository weightDeviceDataRepository; @Autowired SmartCamCarLicenseSnapshotDataService smartCamCarLicenseSnapshotDataService; + @Autowired + SmartCamWhiteListRepository smartCamWhiteListRepository; + @Autowired + private SmartCamWhiteListService smartCamWhiteListService; public CompareResult compare(CompareRequest request) { @@ -99,10 +107,18 @@ public class SmartCamCarDataService } }); + Set whiteList = smartCamWhiteListRepository.searchAllByOrganizationId(Ctx.activeOrganizationId()).stream() + .map(x -> x.getCarNumber()) + .collect(Collectors.toSet()); + Map carInfoMap = new HashMap<>(); for (SmartCamCarDataEntity camDatum : camData) { + if (whiteList.contains(camDatum.getNumber())) { + continue; + } + if (carInfoMap.containsKey(camDatum.getNumber())) { CompareResult.CarInfo carInfo = carInfoMap.get(camDatum.getNumber()); @@ -127,6 +143,10 @@ public class SmartCamCarDataService for (WeightDeviceDataEntity weightDatum : weightData) { + if (whiteList.contains(weightDatum.getPlateNo())) { + continue; + } + if (carInfoMap.containsKey(weightDatum.getPlateNo())) { CompareResult.CarInfo carInfo = carInfoMap.get(weightDatum.getPlateNo()); diff --git a/src/main/java/cn/lihongjie/coal/smartCamWhiteList/controller/SmartCamWhiteListController.java b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/controller/SmartCamWhiteListController.java new file mode 100644 index 00000000..6d6affdc --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/controller/SmartCamWhiteListController.java @@ -0,0 +1,54 @@ +package cn.lihongjie.coal.smartCamWhiteList.controller; + +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.smartCamWhiteList.dto.CreateSmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.dto.SmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.dto.UpdateSmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.service.SmartCamWhiteListService; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/smartCamWhiteList") +@SysLog(module = "") +@Slf4j +@OrgScope +public class SmartCamWhiteListController { + @Autowired private SmartCamWhiteListService service; + + @PostMapping("/create") + public SmartCamWhiteListDto create(@RequestBody CreateSmartCamWhiteListDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public SmartCamWhiteListDto update(@RequestBody UpdateSmartCamWhiteListDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public SmartCamWhiteListDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery request) { + return this.service.list(request); + } +} diff --git a/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/CreateSmartCamWhiteListDto.java b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/CreateSmartCamWhiteListDto.java new file mode 100644 index 00000000..2e2f05af --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/CreateSmartCamWhiteListDto.java @@ -0,0 +1,11 @@ +package cn.lihongjie.coal.smartCamWhiteList.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class CreateSmartCamWhiteListDto extends OrgCommonDto { + + private String carNumber; +} diff --git a/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/SmartCamWhiteListDto.java b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/SmartCamWhiteListDto.java new file mode 100644 index 00000000..5720bba3 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/SmartCamWhiteListDto.java @@ -0,0 +1,11 @@ +package cn.lihongjie.coal.smartCamWhiteList.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class SmartCamWhiteListDto extends OrgCommonDto { + + private String carNumber; +} diff --git a/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/UpdateSmartCamWhiteListDto.java b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/UpdateSmartCamWhiteListDto.java new file mode 100644 index 00000000..f2200596 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/dto/UpdateSmartCamWhiteListDto.java @@ -0,0 +1,10 @@ +package cn.lihongjie.coal.smartCamWhiteList.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class UpdateSmartCamWhiteListDto extends OrgCommonDto { + private String carNumber; +} diff --git a/src/main/java/cn/lihongjie/coal/smartCamWhiteList/entity/SmartCamWhiteListEntity.java b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/entity/SmartCamWhiteListEntity.java new file mode 100644 index 00000000..4ddf7ae4 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/entity/SmartCamWhiteListEntity.java @@ -0,0 +1,21 @@ +package cn.lihongjie.coal.smartCamWhiteList.entity; + +import cn.lihongjie.coal.base.entity.OrgCommonEntity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +import lombok.Data; + +@Data +@Entity +@Table( + indexes = + @jakarta.persistence.Index( + name = "idx_smartCamWhiteList_org_id", + columnList = "organization_id")) +public class SmartCamWhiteListEntity extends OrgCommonEntity { + + private String carNumber; + +} diff --git a/src/main/java/cn/lihongjie/coal/smartCamWhiteList/mapper/SmartCamWhiteListMapper.java b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/mapper/SmartCamWhiteListMapper.java new file mode 100644 index 00000000..aa999fdd --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/mapper/SmartCamWhiteListMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.smartCamWhiteList.mapper; + +import cn.lihongjie.coal.base.mapper.BaseMapper; +import cn.lihongjie.coal.base.mapper.CommonEntityMapper; +import cn.lihongjie.coal.base.mapper.CommonMapper; +import cn.lihongjie.coal.smartCamWhiteList.dto.CreateSmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.dto.SmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.dto.UpdateSmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.entity.SmartCamWhiteListEntity; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; + +@Mapper( + componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING, + uses = {CommonMapper.class, CommonEntityMapper.class}, + mappingControl = DeepClone.class) +public interface SmartCamWhiteListMapper + extends BaseMapper< + SmartCamWhiteListEntity, + SmartCamWhiteListDto, + CreateSmartCamWhiteListDto, + UpdateSmartCamWhiteListDto> {} diff --git a/src/main/java/cn/lihongjie/coal/smartCamWhiteList/repository/SmartCamWhiteListRepository.java b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/repository/SmartCamWhiteListRepository.java new file mode 100644 index 00000000..d62edb3b --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/repository/SmartCamWhiteListRepository.java @@ -0,0 +1,19 @@ +package cn.lihongjie.coal.smartCamWhiteList.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.smartCamWhiteList.entity.SmartCamWhiteListEntity; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface SmartCamWhiteListRepository extends BaseRepository { + @Query("select false") + boolean isLinked(List ids); + + long countByCarNumberAndOrganizationId(String carNumber, String organizationId); + + List searchAllByOrganizationId(String s); +} diff --git a/src/main/java/cn/lihongjie/coal/smartCamWhiteList/service/SmartCamWhiteListService.java b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/service/SmartCamWhiteListService.java new file mode 100644 index 00000000..092ab652 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/smartCamWhiteList/service/SmartCamWhiteListService.java @@ -0,0 +1,89 @@ +package cn.lihongjie.coal.smartCamWhiteList.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.dbFunctions.DbFunctionService; +import cn.lihongjie.coal.exception.BizException; +import cn.lihongjie.coal.smartCamWhiteList.dto.CreateSmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.dto.SmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.dto.UpdateSmartCamWhiteListDto; +import cn.lihongjie.coal.smartCamWhiteList.entity.SmartCamWhiteListEntity; +import cn.lihongjie.coal.smartCamWhiteList.mapper.SmartCamWhiteListMapper; +import cn.lihongjie.coal.smartCamWhiteList.repository.SmartCamWhiteListRepository; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +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.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Slf4j +@Transactional +public class SmartCamWhiteListService + extends BaseService { + @Autowired private SmartCamWhiteListRepository repository; + + @Autowired private SmartCamWhiteListMapper mapper; + + @Autowired private ConversionService conversionService; + + @Autowired private DbFunctionService dbFunctionService; + + public SmartCamWhiteListDto create(CreateSmartCamWhiteListDto request) { + SmartCamWhiteListEntity entity = mapper.toEntity(request); + + long cnt = this.repository.countByCarNumberAndOrganizationId( + request.getCarNumber(), request.getOrganizationId()); + + if (cnt > 0) { + + return null; + } + + this.repository.save(entity); + return getById(entity.getId()); + } + + public SmartCamWhiteListDto update(UpdateSmartCamWhiteListDto request) { + SmartCamWhiteListEntity entity = this.repository.get(request.getId()); + this.mapper.updateEntity(entity, request); + + this.repository.save(entity); + + return getById(entity.getId()); + } + + public void delete(IdRequest request) { + boolean linked = this.repository.isLinked(request.getIds()); + + if (linked) { + throw new BizException("数据已被关联,无法删除"); + } + + this.repository.deleteAllById(request.getIds()); + } + + public SmartCamWhiteListDto getById(String id) { + SmartCamWhiteListEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + public Page list(CommonQuery query) { + Page page = + repository.findAll( + query.specification(conversionService), + PageRequest.of( + query.getPageNo(), + query.getPageSize(), + Sort.by(query.getOrders()))); + + return page.map(this.mapper::toDto); + } +} diff --git a/src/main/resources/scripts/dict/enum/smartCamWhiteListDict.groovy b/src/main/resources/scripts/dict/enum/smartCamWhiteListDict.groovy new file mode 100644 index 00000000..fce20f3f --- /dev/null +++ b/src/main/resources/scripts/dict/enum/smartCamWhiteListDict.groovy @@ -0,0 +1,19 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.smartCamWhiteList.controller.SmartCamWhiteListController +import com.fasterxml.jackson.databind.ObjectMapper +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(SmartCamWhiteListController.class) +def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper + + + + +return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery()) + +