mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-07-26 07:28:58 +08:00
feat(smartCamCarData):增加车辆数据关联功能- 新增 BindRequest 类用于车辆数据关联请求
- 在 SmartCamCarDataController 中添加关联和解关联车辆数据的接口 - 在 SmartCamCarDataService 中实现车辆数据关联和解关联的逻辑 - 新增 FindSimilarRequest 类用于查找相似车牌号码的请求 - 在 SmartCamCarLicenseSnapshotDataRepository 中添加查找相似车牌号码的方法 - 在 SmartCamCarLicenseSnapshotDataService 中实现查找相似车牌号码的逻辑- 更新 SmartCamCarLicenseSnapshotDataEntity 类,添加车牌号码处理相关方法 - 在 MyPostgreSQLDialect 中注册 similarity 函数
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package cn.lihongjie.coal.smartCamCarData.controller;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BindRequest {
|
||||
|
||||
|
||||
private String id;
|
||||
|
||||
|
||||
/**
|
||||
* 入场记录id
|
||||
*/
|
||||
private String entryId;
|
||||
|
||||
|
||||
/**
|
||||
* 出场记录id
|
||||
*/
|
||||
|
||||
private String exitId;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.smartCamCarData.dto.*;
|
||||
import cn.lihongjie.coal.smartCamCarData.service.SmartCamCarDataService;
|
||||
import cn.lihongjie.coal.smartCamCarLicenseSnapshotData.dto.SmartCamCarLicenseSnapshotDataDto;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -56,4 +57,24 @@ public class SmartCamCarDataController {
|
||||
public CompareResult compare(@RequestBody CompareRequest request) {
|
||||
return this.service.compare(request);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/bind")
|
||||
public SmartCamCarDataDto bind(@RequestBody BindRequest request) {
|
||||
return this.service.bind(request);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/unbind")
|
||||
public SmartCamCarDataDto unbind(@RequestBody BindRequest request) {
|
||||
return this.service.unbind(request);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/findSimilar")
|
||||
public Page<SmartCamCarLicenseSnapshotDataDto> findSimilar(@RequestBody FindSimilarRequest request) {
|
||||
|
||||
return this.service.findSimilar(request);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.smartCamCarData.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
|
||||
public class FindSimilarRequest {
|
||||
|
||||
private Integer pageNo = 0;
|
||||
private Integer pageSize = Integer.MAX_VALUE;
|
||||
|
||||
private String number;
|
||||
}
|
||||
@@ -6,10 +6,14 @@ 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.controller.BindRequest;
|
||||
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.smartCamCarLicenseSnapshotData.dto.SmartCamCarLicenseSnapshotDataDto;
|
||||
import cn.lihongjie.coal.smartCamCarLicenseSnapshotData.entity.SmartCamCarLicenseSnapshotDataEntity;
|
||||
import cn.lihongjie.coal.smartCamCarLicenseSnapshotData.service.SmartCamCarLicenseSnapshotDataService;
|
||||
import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity;
|
||||
import cn.lihongjie.coal.weightDeviceData.repository.WeightDeviceDataRepository;
|
||||
|
||||
@@ -20,6 +24,7 @@ import jakarta.persistence.criteria.Root;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -48,6 +53,8 @@ public class SmartCamCarDataService
|
||||
|
||||
@Autowired WeightDeviceDataRepository weightDeviceDataRepository;
|
||||
|
||||
@Autowired SmartCamCarLicenseSnapshotDataService smartCamCarLicenseSnapshotDataService;
|
||||
|
||||
public CompareResult compare(CompareRequest request) {
|
||||
|
||||
List<SmartCamCarDataEntity> camData =
|
||||
@@ -188,4 +195,93 @@ public class SmartCamCarDataService
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public SmartCamCarDataDto bind(BindRequest request) {
|
||||
|
||||
SmartCamCarDataEntity entity = this.repository.get(request.getId());
|
||||
|
||||
|
||||
if (entity.getEntry() != null && entity.getExit() != null) {
|
||||
throw new BizException("进出记录都被关联了");
|
||||
}
|
||||
|
||||
if (entity.getEntry() == null) {
|
||||
|
||||
if (StringUtils.isNotBlank(request.getEntryId())){
|
||||
|
||||
SmartCamCarLicenseSnapshotDataEntity entry =
|
||||
smartCamCarLicenseSnapshotDataService.get(request.getEntryId());
|
||||
|
||||
entity.setEntry(entry);
|
||||
|
||||
entity.setEntryTime(entry.getInfoTimeObj());
|
||||
|
||||
}else {
|
||||
|
||||
throw new BizException("请选择关联的进记录");
|
||||
}
|
||||
|
||||
}else if (entity.getExit() == null) {
|
||||
|
||||
if (StringUtils.isNotBlank(request.getExitId())){
|
||||
|
||||
SmartCamCarLicenseSnapshotDataEntity exit =
|
||||
smartCamCarLicenseSnapshotDataService.get(request.getExitId());
|
||||
|
||||
entity.setExit(exit);
|
||||
|
||||
entity.setExitTime(exit.getInfoTimeObj());
|
||||
|
||||
entity.setFinished(true);
|
||||
|
||||
}else {
|
||||
|
||||
throw new BizException("请选择关联的出记录");
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
throw new BizException("进出记录都已经关联了");
|
||||
}
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public Page<SmartCamCarLicenseSnapshotDataDto> findSimilar(FindSimilarRequest request) {
|
||||
|
||||
|
||||
Page<SmartCamCarLicenseSnapshotDataDto> similar = smartCamCarLicenseSnapshotDataService.findSimilar(request.getNumber(), PageRequest.of(request.getPageNo(), request.getPageSize()));
|
||||
|
||||
|
||||
return similar;
|
||||
|
||||
}
|
||||
|
||||
public SmartCamCarDataDto unbind(BindRequest request) {
|
||||
|
||||
|
||||
|
||||
SmartCamCarDataEntity entity = this.repository.get(request.getId());
|
||||
|
||||
|
||||
if (StringUtils.isNotBlank(request.getEntryId()) && StringUtils.equals(entity.getEntry().getId(), request.getEntryId())){
|
||||
|
||||
entity.setEntry(null);
|
||||
entity.setEntryTime(null);
|
||||
}else if (StringUtils.isNotBlank(request.getExitId()) && StringUtils.equals(entity.getExit().getId(), request.getExitId())){
|
||||
|
||||
entity.setExit(null);
|
||||
entity.setExitTime(null);
|
||||
entity.setFinished(false);
|
||||
}else {
|
||||
throw new BizException("关联的记录不匹配");
|
||||
}
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -151,10 +152,30 @@ public class SmartCamCarLicenseSnapshotDataEntity extends OrgCommonEntity {
|
||||
@Comment("车牌背景图片信息 原始图片MD5值")
|
||||
private String backgroundImagePictureMd5;
|
||||
|
||||
@ManyToOne private FileEntity captureImage;
|
||||
|
||||
@ManyToOne
|
||||
private FileEntity captureImage;
|
||||
@ManyToOne private FileEntity backgroundImage;
|
||||
|
||||
@ManyToOne
|
||||
private FileEntity backgroundImage;
|
||||
@Comment("车牌号码 只有数字和字母")
|
||||
private String numberPart;
|
||||
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
|
||||
if (StringUtils.isNotBlank(this.numberPart)) {
|
||||
|
||||
this.numberPart = this.number.replaceAll("[^0-9a-zA-Z]", "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preUpdate() {
|
||||
super.preUpdate();
|
||||
|
||||
if (StringUtils.isNotBlank(this.numberPart)) {
|
||||
|
||||
this.numberPart = this.number.replaceAll("[^0-9a-zA-Z]", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ package cn.lihongjie.coal.smartCamCarLicenseSnapshotData.repository;
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.smartCamCarLicenseSnapshotData.entity.SmartCamCarLicenseSnapshotDataEntity;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
@@ -13,4 +16,17 @@ public interface SmartCamCarLicenseSnapshotDataRepository
|
||||
extends BaseRepository<SmartCamCarLicenseSnapshotDataEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
|
||||
@Query("""
|
||||
select e from SmartCamCarLicenseSnapshotDataEntity e
|
||||
left join SmartCamCarDataEntity c1 on c1.entry = e
|
||||
left join SmartCamCarDataEntity c2 on c2.exit = e
|
||||
|
||||
where c1 is null and c2 is null
|
||||
|
||||
order by similarity(e.numberPart, :number) desc
|
||||
|
||||
|
||||
""")
|
||||
Page<SmartCamCarLicenseSnapshotDataEntity> findSimilar(@Param("number") String number, PageRequest of);
|
||||
}
|
||||
|
||||
@@ -645,4 +645,10 @@ public class SmartCamCarLicenseSnapshotDataService
|
||||
return "无效";
|
||||
}
|
||||
}
|
||||
|
||||
public Page<SmartCamCarLicenseSnapshotDataDto> findSimilar(String number, PageRequest of) {
|
||||
|
||||
|
||||
return repository.findSimilar(number.replaceAll("[^0-9a-zA-Z]", ""), of).map(mapper::toDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,10 @@ public class MyPostgreSQLDialect extends PostgreSQLDialect {
|
||||
.getBasicTypeRegistry().resolve(StandardBasicTypes.INTEGER));
|
||||
|
||||
|
||||
|
||||
functionContributions.getFunctionRegistry().registerPattern("similarity", "similarity(?1, ?2)", functionContributions.getTypeConfiguration()
|
||||
.getBasicTypeRegistry().resolve(StandardBasicTypes.DOUBLE));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user