From f180808a445a3cc135727c692c2efdb20998ac0e Mon Sep 17 00:00:00 2001
From: kongdeqiang <kongdeqiang960204@163.com>
Date: 星期二, 23 四月 2024 16:17:07 +0800
Subject: [PATCH] fix:新增模糊车牌接口
---
src/main/java/com/boying/service/OutParkService.java | 3 +
src/main/java/com/boying/util/PlateComparator.java | 77 +++++++++++++++++++++++++
src/main/java/com/boying/service/impl/OutParkServiceImpl.java | 24 ++++++-
src/main/java/com/boying/controller/OutParkController.java | 53 +++++++++++++++++
src/main/java/com/boying/controller/ParkController.java | 2
5 files changed, 154 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/boying/controller/OutParkController.java b/src/main/java/com/boying/controller/OutParkController.java
index 3d0a6e5..be0c09f 100644
--- a/src/main/java/com/boying/controller/OutParkController.java
+++ b/src/main/java/com/boying/controller/OutParkController.java
@@ -1,8 +1,10 @@
package com.boying.controller;
import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.boying.common.R;
import com.boying.common.SystemConfigProperties;
@@ -319,6 +321,57 @@
return R.failed(null,"鏈壘鍒版暟鎹�");
}
}
+
+ //鎵爜淇敼鍑哄満锛堟ā绯婅溅鐗岋級
+ @GetMapping("/getLikeCar")
+ public Object getLikeCar(Integer outParkId) {
+ OutPark byId = outParkService.getById(outParkId);
+ List<Map<String, Object>> likeCar = outParkService.getLikeCar(byId.getCarNo(), byId.getParkId(), byId.getCreateTime());
+ if (CollectionUtils.isNotEmpty(likeCar)) {
+ Collections.sort(likeCar, (m1, m2)-> String.valueOf(m2.get("createTime")).compareTo(String.valueOf(m1.get("createTime"))));
+ }
+ return R.ok(likeCar);
+ }
+
+ //鎵爜淇敼鍑哄満锛堟ā绯婅溅鐗岋級
+ @GetMapping("/editOutPark")
+ public Object editOutPark(Integer outParkId,Integer enterParkId,Integer type) {
+ double money = 0.0;
+ OutPark outPark = outParkService.getById(outParkId);
+ EnterPark enterPark = enterParkService.getById(enterParkId);
+ Barrier barrier =barrierService.getById(outPark.getBarrierId());
+ if(type == 0){ //鍏ュ満姝g‘锛屾浛鎹㈠嚭鍦猴紝鏇存柊鍑哄満璁板綍
+ outPark.setCarNo(enterPark.getCarNo());
+ barrier.setCarNo(enterPark.getCarNo());
+ barrierService.saveOrUpdate(barrier);
+ String jsonValue = JSON.toJSONString(barrier);
+ redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue);
+ }else { //鍑哄満姝g‘锛屾浛鎹㈠叆鍦猴紝鏇存柊鍑哄満璁板綍
+ enterPark.setCarNo(outPark.getCarNo());
+ }
+ outPark.setEnterTime(enterPark.getCreateTime());
+ try {
+ long l = outPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - enterPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
+ outPark.setTime(l/(1000*60));
+ if(outPark.getTime() > 0){
+ outPark.setTimeStr(DateUtilOther.millisToDayHrMinSec(new Double(outPark.getTime()).longValue()));
+ }else {
+ outPark.setTimeStr("涓嶈冻涓�鍒嗛挓");
+ }
+ money = costRuleService.getMoney(outPark.getParkId(), outPark.getEnterTime(), outPark.getCreateTime(), 1);
+ //鍏ュ満璁板綍淇濆瓨涓�涓�
+ enterPark.setPrice(money);
+ enterPark.setIsPay(0);
+ enterParkService.updateById(enterPark);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ outPark.setPrice(money);
+ outParkService.saveOrUpdate(outPark);
+ outPark.setParkName(barrier.getName());
+ return R.ok(outPark,"鏇存柊鎴愬姛");
+ }
+
@GetMapping("/editEnterPark")
public Object editEnterPark(String carNo ,Integer parkId,String time) {
QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
diff --git a/src/main/java/com/boying/controller/ParkController.java b/src/main/java/com/boying/controller/ParkController.java
index ce2968f..0a9ec02 100644
--- a/src/main/java/com/boying/controller/ParkController.java
+++ b/src/main/java/com/boying/controller/ParkController.java
@@ -158,6 +158,7 @@
}
}
+
@PostMapping("/getParkCar")
public Object getParkCar(Page page, Integer parkId,String carNo) {
QueryWrapper<EnterPark> enterParkQueryWrapper = new QueryWrapper<>();
@@ -174,6 +175,5 @@
}
return R.ok(page1);
}
-
}
diff --git a/src/main/java/com/boying/service/OutParkService.java b/src/main/java/com/boying/service/OutParkService.java
index 4081de4..4cad1cb 100644
--- a/src/main/java/com/boying/service/OutParkService.java
+++ b/src/main/java/com/boying/service/OutParkService.java
@@ -7,6 +7,7 @@
import java.time.LocalDateTime;
import java.util.List;
+import java.util.Map;
/**
* @author kdq
@@ -48,4 +49,6 @@
OutPark findBy10min(String carNo, Integer parkId, LocalDateTime dateTime, Integer outParkId);
+ List<Map<String, Object>> getLikeCar(String carNo, Integer parkId, LocalDateTime dateTime);
+
}
diff --git a/src/main/java/com/boying/service/impl/OutParkServiceImpl.java b/src/main/java/com/boying/service/impl/OutParkServiceImpl.java
index c6ace3d..e5c929e 100644
--- a/src/main/java/com/boying/service/impl/OutParkServiceImpl.java
+++ b/src/main/java/com/boying/service/impl/OutParkServiceImpl.java
@@ -4,14 +4,13 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.boying.entity.Barrier;
-import com.boying.entity.OutPark;
-import com.boying.entity.Park;
-import com.boying.entity.Statistic;
+import com.boying.entity.*;
+import com.boying.mapper.EnterParkMapper;
import com.boying.mapper.OutParkMapper;
import com.boying.mapper.StatisticMapper;
import com.boying.service.OutParkService;
import com.boying.service.StatisticService;
+import com.boying.util.PlateComparator;
import com.boying.util.RedisJsonUtil;
import com.boying.util.StringUtil;
import lombok.AllArgsConstructor;
@@ -35,6 +34,7 @@
@AllArgsConstructor
public class OutParkServiceImpl extends ServiceImpl<OutParkMapper, OutPark> implements OutParkService {
private final OutParkMapper outParkMapper;
+ private final EnterParkMapper enterParkMapper;
private StringRedisTemplate redisTemplate;
@@ -232,6 +232,22 @@
}
@Override
+ public List<Map<String, Object>> getLikeCar(String carNo, Integer parkId, LocalDateTime dateTime) {
+ QueryWrapper<EnterPark> wrapper = new QueryWrapper<>();
+ wrapper.select(" id,car_no,park_id,create_time ");
+ wrapper.lambda()
+ .eq(EnterPark::getParkId,parkId)
+ .lt(EnterPark::getCreateTime,dateTime);
+ List<EnterPark> enterParks = enterParkMapper.selectList(wrapper);
+ if(enterParks !=null && enterParks.size()>0){
+ List<Map<String, Object>> list = PlateComparator.getList(carNo, enterParks);
+ return list;
+ }else {
+ return null;
+ }
+ }
+
+ @Override
public OutPark findBy5min2(String carNo, Integer parkId,LocalDateTime dateTime) {
LocalDateTime localDateTime = dateTime.minusMinutes(7);
QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
diff --git a/src/main/java/com/boying/util/PlateComparator.java b/src/main/java/com/boying/util/PlateComparator.java
new file mode 100644
index 0000000..5ac353a
--- /dev/null
+++ b/src/main/java/com/boying/util/PlateComparator.java
@@ -0,0 +1,77 @@
+package com.boying.util;
+
+import org.springframework.beans.BeanUtils;
+import com.boying.entity.EnterPark;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author kdq
+ * @version 1.0.0
+ * @ClassName PlateComparator.java
+ * @Description TODO
+ * @createTime 2024骞�04鏈�19鏃� 15:57:00
+ */
+public class PlateComparator {
+
+ public static List<Map<String,Object>> getList(String carNo, List<EnterPark> enterParkList) {
+ List<Map<String,Object>> list = new ArrayList<>();
+ for (EnterPark enterPark : enterParkList) {
+ int i = compareLicensePlates(carNo, enterPark.getCarNo());
+ if (i<2){
+ Map<String, Object> returnMap = new HashMap<String, Object>();
+ BeanInfo beanInfo = null;
+ try {
+ beanInfo = Introspector.getBeanInfo(enterPark.getClass());
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ for (PropertyDescriptor pd : propertyDescriptors) {
+ String propertyName = pd.getName();
+ if (!"class".equals(propertyName)) {
+ Method readMethod = pd.getReadMethod();
+ Object result = readMethod.invoke(enterPark);
+ if (result != null) {
+ returnMap.put(propertyName, result);
+ } else {
+ returnMap.put(propertyName, "");
+ }
+ }
+ }
+ } catch (IntrospectionException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ returnMap.put("count",i); // 鏂板娆℃暟
+ list.add(returnMap);
+ }
+ }
+ return list;
+
+ }
+
+ public static int compareLicensePlates(String oldLicensePlate, String newLicensePlate) {
+ int length = Math.min(oldLicensePlate.length(), newLicensePlate.length());
+ int count = 0;
+ for (int i = 0; i < length; i++) {
+ if (oldLicensePlate.charAt(i) != newLicensePlate.charAt(i)) {
+ count ++;
+ }
+ }
+ // 濡傛灉鏂拌溅鐗屾瘮鏃ц溅鐗岄暱锛屽垯杩藉姞鏂拌溅鐗屽鍑虹殑瀛楃
+ if (newLicensePlate.length() > oldLicensePlate.length()) {
+ count++;
+ }
+ return count;
+ }
+}
--
Gitblit v1.9.1