kongdeqiang
2024-04-23 f180808a445a3cc135727c692c2efdb20998ac0e
fix:新增模糊车牌接口
4个文件已修改
1个文件已添加
159 ■■■■■ 已修改文件
src/main/java/com/boying/controller/OutParkController.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/controller/ParkController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/service/OutParkService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/service/impl/OutParkServiceImpl.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/util/PlateComparator.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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){ //入场正确,替换出场,更新出场记录
            outPark.setCarNo(enterPark.getCarNo());
            barrier.setCarNo(enterPark.getCarNo());
            barrierService.saveOrUpdate(barrier);
            String jsonValue = JSON.toJSONString(barrier);
            redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue);
        }else { //出场正确,替换入场,更新出场记录
            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<>();
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);
    }
}
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);
}
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<>();
src/main/java/com/boying/util/PlateComparator.java
New file
@@ -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;
    }
}