kongdeqiang
2024-10-11 bac87061c69aaca6c23a84e08f76f3dfd0c77c4a
src/main/java/com/boying/controller/car/PlateServlet3.java
@@ -12,6 +12,7 @@
import com.boying.service.*;
import com.boying.util.DateUtilOther;
import com.boying.util.FileUtil;
import com.boying.util.RedisJsonUtil;
import com.boying.util.StringUtil;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -33,6 +34,7 @@
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Base64;
@@ -60,6 +62,8 @@
    private final WhiteListService whiteListService;
    private final FileInfoService fileInfoService;
    private final TicketBlackService ticketBlackService;
    private final OutParkLogService outParkLogService;
   // private final RedisJsonUtil redisJsonUtil;
    private final String LEDURL = "http://192.168.31.212:9988/LedShow/IGetResultDataAllLine";
    /**
@@ -128,6 +132,14 @@
        out.close();
    }
    protected void easyOpen2(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/json");
        PrintWriter out = response.getWriter();
        out.println("{\"Response_AlarmInfoPlate\":{\"ivs_ioctrl\":{\"delay\":1000,\"io\":0,\"value\":2}}}");
        out.flush();
        out.close();
    }
    protected void easyNoOpen(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/json");
        PrintWriter out = response.getWriter();
@@ -139,9 +151,13 @@
    @PostMapping("/status")
    public void heart(String serialno,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        Barrier barrier = barrierService.findByCode(serialno);
        Park park = parkService.getById(barrier.getParkId());
        String redis = redisTemplate.opsForValue().get("park_up_" + park.getId());
        Park park = parkService.getOneById(barrier.getParkId());
       // Park park = parkService.getById(barrier.getParkId());
       // String redis = redisTemplate.opsForValue().get("park_up_" + park.getId());
        String redisnum = redisTemplate.opsForValue().get("car_park_" + park.getId());
        if(StringUtils.isBlank(redisnum)){
            redisnum = "0";
        }
        if(barrier!=null){
            if(barrier.getType2()==1){
                //待开闸
@@ -170,36 +186,54 @@
                barrier.setStatus(0);
                barrier.setUpdateTime(LocalDateTime.now());
                barrierService.saveOrUpdate(barrier);
                String jsonValue = JSON.toJSONString(barrier);
                redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue);
                easyOpen(request,response);
            }else {
                //不需开闸
                barrier.setStatus(0);
                barrier.setUpdateTime(LocalDateTime.now());
                barrierService.saveOrUpdate(barrier);
                OutPark outPark = outParkService.count4(barrier.getId());
                if(outPark!=null){
                    if(barrier.getType() == 0){
                        int i = Integer.parseInt(redisnum);
                        i--;
                        if(i<0){
                            String s= "2."+outPark.getCarNo()+"缴费完成,场内停车数为"+i+"\n";
                            writeTxt2(s);
                            redisTemplate.opsForValue().set("car_park_" + park.getId(),"0",30, TimeUnit.DAYS);
                            redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS);
                        }else {
                            String s= "2."+outPark.getCarNo()+"缴费完成,场内停车数为"+i+"\n";
                            writeTxt2(s);
                            redisTemplate.opsForValue().set("car_park_" + park.getId(),Integer.toString(i),30, TimeUnit.DAYS);
                            redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS);
                LocalDateTime now = LocalDateTime.now();
                LocalDateTime updateTime = barrier.getUpdateTime();
                Duration duration = Duration.between(updateTime,now);
                long minutes = duration.toMinutes();
                if(minutes>=2){
                    barrier.setStatus(0);
                    barrier.setUpdateTime(LocalDateTime.now());
                    barrierService.saveOrUpdate(barrier);
                }
                String jsonValue = JSON.toJSONString(barrier);
                redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue);
                if(barrier.getType() == 0){
                    OutPark outPark = outParkService.count4(barrier.getId());
                    if(outPark!=null){
                        if(barrier.getType() == 0){
                            int i = Integer.parseInt(redisnum);
                            i--;
                            if(i<0){
                                String s= "2."+outPark.getCarNo()+"缴费完成,场内停车数为"+i+"\n";
                                writeTxt2(s);
                                redisTemplate.opsForValue().set("car_park_" + park.getId(),"0",30, TimeUnit.DAYS);
                                redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS);
                            }else {
                                String s= "2."+outPark.getCarNo()+"缴费完成,场内停车数为"+i+"\n";
                                writeTxt2(s);
                                redisTemplate.opsForValue().set("car_park_" + park.getId(),Integer.toString(i),30, TimeUnit.DAYS);
                                redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS);
                            }
                        }
                        outPark.setStatus2(1);
                        outParkService.saveOrUpdate(outPark);
                        easyOpen(request,response);
                        OutParkLog byOutPark = outParkLogService.getByOutPark(outPark.getCarNo(), outPark.getId());
                        byOutPark.setOpenTime(LocalDateTime.now());
                        outParkLogService.saveOrUpdate(byOutPark);
                        enterParkService.deleteByCarNo(outPark.getCarNo(), barrier.getParkId());
                        redisTemplate.delete("outPark-"+outPark.getBarrierId());
                    }
                    outPark.setStatus2(1);
                    outParkService.saveOrUpdate(outPark);
                    easyOpen(request,response);
                    enterParkService.deleteByCarNo(outPark.getCarNo(), barrier.getParkId());
                }
                if(barrier.getType() == 1){
                    boolean in = barrierService.getDateDifIn(barrier.getId());
                    boolean in = barrierService.getDateDifIn(park.getId());
                    if(in){
                        inLedShowDefault(park.getId(),request,response);
                    }
@@ -305,8 +339,8 @@
                            inLedFullShow(code, license,barrier.getParkId(),request,response);
                        }else {
                            //led显示
                            inLedShow(code, license,barrier.getParkId(),request,response);
                            enterPark(license,barrier.getId(),barrier.getParkId(),fileInfo);
                            inLedShow(code, license,barrier.getParkId(),request,response);
                            s+=license+"-保存入场记录\n";
                        }
                    }
@@ -351,7 +385,7 @@
                if(one == null){
                    return R.failed("未查询到车辆存在");
                }else {
                    if(one.getCarNo().equals("无牌车")){
                    if(one.getCarNo().equals("_无_") || one.getCarNo().equals("无牌车")){
                        enterPark.setCreateTime(LocalDateTime.now());
                        QueryWrapper<Ticket> wrapper = new QueryWrapper<>();
                        wrapper.lambda()
@@ -517,6 +551,9 @@
                enterPark.setImgId(fileInfo.getId());
            }
            enterParkService.saveOrUpdate(enterPark);
            String jsonValue = JSON.toJSONString(enterPark);
            redisTemplate.opsForValue().set("enterPark_dif_"+ parkId, jsonValue);
        }
    }
@@ -583,6 +620,11 @@
                    byCarNoAndBarrierId.setStatus(2);
                    byCarNoAndBarrierId.setStatus2(1);
                    outParkService.saveOrUpdate(byCarNoAndBarrierId);
                    barrierService.saveOrUpdate(barrier);
                    String jsonValue2 = JSON.toJSONString(barrier);
                    redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue2);
                    String jsonValue = JSON.toJSONString(byCarNoAndBarrierId);
                    redisTemplate.opsForValue().set("outPark_dif_"+ barrierId, jsonValue);
                    return 0.0;
                }else{
                    if(StringUtils.isNotBlank(w.getParkIds())){
@@ -597,6 +639,11 @@
                                    byCarNoAndBarrierId.setStatus(2);
                                    byCarNoAndBarrierId.setStatus2(1);
                                    outParkService.saveOrUpdate(byCarNoAndBarrierId);
                                    barrierService.saveOrUpdate(barrier);
                                    String jsonValue2 = JSON.toJSONString(barrier);
                                    redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue2);
                                    String jsonValue = JSON.toJSONString(byCarNoAndBarrierId);
                                    redisTemplate.opsForValue().set("outPark_dif_"+ barrierId, jsonValue);
                                    return 0.0;
                                }
                            }
@@ -605,19 +652,29 @@
                }
            }
        }
        barrierService.saveOrUpdate(barrier);
        String jsonValue2 = JSON.toJSONString(barrier);
        redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue2);
        if(outPark.getPrice()==0&&outPark.getStatus3()==0){
            System.out.println(outPark.getCarNo()+"该车不需要缴费");
            String s= "1."+barrier.getCarNo()+"该车不需要缴费\n";
            writeTxt2(s);
            outLedShow(barrier.getCode(),barrier.getCarNo(),outPark.getPrice(),toDayHrMinSec,barrier.getParkId(),request,response,0);
            String jsonValue = JSON.toJSONString(outPark);
            redisTemplate.opsForValue().set("outPark_dif_"+ barrierId, jsonValue);
            outLedShow(outPark,barrier.getCode(),barrier.getCarNo(),outPark.getPrice(),toDayHrMinSec,barrier.getParkId(),request,response,0);
        }else {
            //需要缴费或者有违章
            System.out.println(outPark.getCarNo()+"该车需要缴费"+outPark.getPrice());
            String s= "1."+barrier.getCarNo()+"该车需要缴费\n";
            writeTxt2(s);
            outLedShow(barrier.getCode(),barrier.getCarNo(),outPark.getPrice(),toDayHrMinSec,barrier.getParkId(),request,response,1);
            OutParkLog byOutPark = outParkLogService.getByOutPark(outPark.getCarNo(), outPark.getId());
            byOutPark.setOutTime(outPark.getCreateTime());
            byOutPark.setParkId(outPark.getParkId());
            outParkLogService.saveOrUpdate(byOutPark);
            String jsonValue = JSON.toJSONString(outPark);
            redisTemplate.opsForValue().set("outPark_dif_"+ barrierId, jsonValue);
            outLedShow(outPark,barrier.getCode(),barrier.getCarNo(),outPark.getPrice(),toDayHrMinSec,barrier.getParkId(),request,response,1);
        }
        barrierService.saveOrUpdate(barrier);
        return money;
    }
@@ -691,9 +748,9 @@
                    }
                }
            }
            if(StringUtils.isBlank(carDay) && !carNo.equals("无车牌")){
            if(StringUtils.isBlank(carDay) && !carNo.equals("_无_") && !carNo.equals("无牌车")){
                carDay = "欢迎光临";
            }else if(StringUtils.isBlank(carDay) && carNo.equals("无车牌")){
            }else if(StringUtils.isBlank(carDay) || carNo.equals("_无_") || carNo.equals("无牌车")){
                carDay = "拒绝驶入";
            }
@@ -717,7 +774,7 @@
            String data1 = Base64.getMimeEncoder().encodeToString(dataX) + "=";
            data1 = data1.replaceAll("\r\n", "");
            if(!carNo.equals("无车牌")){
            if(!carNo.equals("_无_") && !carNo.equals("无牌车")){
                open(request,response,data1);//入场开闸
            }else {
                noOpen(request,response,data1);
@@ -769,7 +826,7 @@
        noOpen(request,response,data1);//入场开闸
    }
    public void outLedShow(String ledId,String carNo,Double price,String timeStamp,Integer parkId,HttpServletRequest request, HttpServletResponse response,int type) throws ServletException, IOException {
    public void outLedShow(OutPark outPark,String ledId,String carNo,Double price,String timeStamp,Integer parkId,HttpServletRequest request, HttpServletResponse response,int type) throws ServletException, IOException {
        String redisnum = redisTemplate.opsForValue().get("car_park_" + parkId);
        Park park = parkService.getById(parkId);
        LedBean ledBean = new LedBean();
@@ -792,28 +849,55 @@
        String data1 = Base64.getMimeEncoder().encodeToString(dataX) + "=";
        data1 = data1.replaceAll("\r\n", "");
        if(type == 0){
            if(carNo.equals("无车牌")){
            if(carNo.equals("_无_") || carNo.equals("无牌车")){
                noOpen(request,response,data1);
            }else {
                if(timeStamp.contains("记录异常")){
                    noOpen(request,response,data1);
                    OutPark by5min = outParkService.findBy5min(carNo, parkId, LocalDateTime.now());
                    if(by5min != null){
                        //开闸
                        open(request,response,data1);
                        enterParkService.deleteByCarNo(carNo, parkId);
                        redisTemplate.opsForValue().set("park_change_in_"+parkId,"true",1, TimeUnit.DAYS);
                        int i = Integer.parseInt(redisnum);
                        i--;
                        if(i<0){
                            String s= "2."+carNo+",场内停车数为0\n";
                            writeTxt2(s);
                            redisTemplate.opsForValue().set("car_park_" + parkId,"0",30, TimeUnit.DAYS);
                            redisTemplate.opsForValue().set("park_up_" + parkId,"true",30, TimeUnit.DAYS);
                        }else {
                            String s= "2."+carNo+",场内停车数为"+i+"\n";
                            writeTxt2(s);
                            redisTemplate.opsForValue().set("car_park_" + parkId,Integer.toString(i),30, TimeUnit.DAYS);
                            redisTemplate.opsForValue().set("park_up_" + parkId,"true",30, TimeUnit.DAYS);
                        }
                    }else {
                        noOpen(request,response,data1);
                    }
                }else {
                    //开闸
                    open(request,response,data1);
                    //缓存在redis里,心跳接口去抬杆
                    String jsonValue = JSON.toJSONString(outPark);
                    redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue);
                    //enterParkService.deleteByCarNo(carNo, parkId);
                    redisTemplate.opsForValue().set("park_change_in_"+parkId,"true",1, TimeUnit.DAYS);
                    int i = Integer.parseInt(redisnum);
                    i--;
                    if(i<0){
                        String s= "2."+carNo+",场内停车数为0\n";
                        writeTxt2(s);
                        redisTemplate.opsForValue().set("car_park_" + parkId,"0",30, TimeUnit.DAYS);
                        redisTemplate.opsForValue().set("park_up_" + parkId,"true",30, TimeUnit.DAYS);
                    }else {
                        String s= "2."+carNo+",场内停车数为"+i+"\n";
                        writeTxt2(s);
                        redisTemplate.opsForValue().set("car_park_" + parkId,Integer.toString(i),30, TimeUnit.DAYS);
                        redisTemplate.opsForValue().set("park_up_" + parkId,"true",30, TimeUnit.DAYS);
                    }
//                    int i = Integer.parseInt(redisnum);
//                    i--;
//                    if(i<0){
//                        String s= "2."+carNo+",场内停车数为0\n";
//                        writeTxt2(s);
//                        redisTemplate.opsForValue().set("car_park_" + parkId,"0",30, TimeUnit.DAYS);
//                        redisTemplate.opsForValue().set("park_up_" + parkId,"true",30, TimeUnit.DAYS);
//                    }else {
//                        String s= "2."+carNo+",场内停车数为"+i+"\n";
//                        writeTxt2(s);
//                        redisTemplate.opsForValue().set("car_park_" + parkId,Integer.toString(i),30, TimeUnit.DAYS);
//                        redisTemplate.opsForValue().set("park_up_" + parkId,"true",30, TimeUnit.DAYS);
//                    }
                }
            }
@@ -847,6 +931,7 @@
        if(type == 0){
            //开闸
            open(request,response,data1);
            enterParkService.deleteByCarNo(carNo,parkId);
            redisTemplate.opsForValue().set("park_change_in_"+parkId,"true",1, TimeUnit.DAYS);
            int i = Integer.parseInt(redisnum);
            i--;