kongdeqiang
2024-03-25 d6aa1029a1c538cd2227f0026ad5adbaa1739726
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;
@@ -19,6 +20,7 @@
import ledshow.LedBean;
import ledshow.ResultData;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
@@ -32,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;
@@ -59,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";
    /**
@@ -138,9 +143,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){
                //待开闸
@@ -169,35 +178,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);
                }
                if(barrier.getType() == 1){
                    boolean in = barrierService.getDateDifIn(barrier.getId());
                    boolean in = barrierService.getDateDifIn(park.getId());
                    if(in){
                        inLedShowDefault(park.getId(),request,response);
                    }
@@ -359,6 +387,8 @@
                        if(tickets.size()>0){
                            enterPark.setStatus(1);//发现有违章
                        }
                        enterPark.setIsPay(0);
                        enterPark.setPrice(0);
                        enterParkService.deleteByCarNo(enterPark.getCarNo(),enterPark.getParkId());
                        enterParkService.save(enterPark);
                        barrier.setType2(1);
@@ -409,6 +439,15 @@
                outPark.setTime(l/(1000*60));
                toDayHrMinSec = DateUtilOther.millisToDayHrMinSec(l/(1000*60));
                money = costRuleService.getMoney(one.getParkId(), outPark.getEnterTime(), outPark.getCreateTime(), 1);
                //入场记录保存一下
                if(one.getIsPay()==1){
                    money = money - one.getPrice();
                }else {
                    one.setPrice(money);
                    one.setIsPay(0);
                    enterParkService.updateById(one);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
@@ -486,6 +525,8 @@
        }else {
            enterParkService.deleteByCarNo(carNo,parkId);
            EnterPark enterPark = new EnterPark();
            enterPark.setIsPay(0);
            enterPark.setPrice(0);
            enterPark.setCarNo(carNo);
            enterPark.setBarrierId(barrierId);
            enterPark.setParkId(parkId);
@@ -502,6 +543,9 @@
                enterPark.setImgId(fileInfo.getId());
            }
            enterParkService.saveOrUpdate(enterPark);
            String jsonValue = JSON.toJSONString(enterPark);
            redisTemplate.opsForValue().set("enterPark_dif_"+ parkId, jsonValue);
        }
    }
@@ -528,6 +572,15 @@
                outPark.setTime(l/(1000*60));
                toDayHrMinSec = DateUtilOther.millisToDayHrMinSec(l/(1000*60));
                money = costRuleService.getMoney(parkId, outPark.getEnterTime(), outPark.getCreateTime(), 1);
                //入场记录保存一下
                if(enterPark.getIsPay() != null && enterPark.getIsPay()==1){
                    money = money - enterPark.getPrice();
                }else {
                    enterPark.setPrice(money);
                    enterPark.setIsPay(0);
                    enterParkService.updateById(enterPark);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
@@ -544,7 +597,7 @@
        barrier.setCarNo(carNo);
        //led展示
        if(toDayHrMinSec == null){
            toDayHrMinSec = "不足两小时";
            toDayHrMinSec = "入场记录异常,请联系管理员";
        }
        //判断是否在白名单
        QueryWrapper<WhiteList> wrapper = new QueryWrapper<>();
@@ -556,9 +609,14 @@
                if(w.getType()==0){
                    outLedShowYueZu(barrier.getCarNo(),"月租车",parkId,request,response,0);
                    OutPark byCarNoAndBarrierId = outParkService.findByCarNoAndBarrierId(carNo, barrierId);
                    byCarNoAndBarrierId.setStatus(1);
                    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())){
@@ -570,9 +628,14 @@
                                if(pid == outPark.getParkId() && System.currentTimeMillis()<w.getEndTime().getTime()){
                                    outLedShowYueZu(barrier.getCarNo(),"月租车",parkId,request,response,0);
                                    OutPark byCarNoAndBarrierId = outParkService.findByCarNoAndBarrierId(carNo, barrierId);
                                    byCarNoAndBarrierId.setStatus(1);
                                    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;
                                }
                            }
@@ -581,19 +644,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);
            String jsonValue = JSON.toJSONString(outPark);
            redisTemplate.opsForValue().set("outPark_dif_"+ barrierId, jsonValue);
            outLedShow(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);
            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(barrier.getCode(),barrier.getCarNo(),outPark.getPrice(),toDayHrMinSec,barrier.getParkId(),request,response,1);
        }
        barrierService.saveOrUpdate(barrier);
        return money;
    }
@@ -771,22 +844,49 @@
            if(carNo.equals("无车牌")){
                noOpen(request,response,data1);
            }else {
                //开闸
                open(request,response,data1);
                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);
                if(timeStamp.contains("记录异常")){
                    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 {
                    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);
                    //开闸
                    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);
@@ -818,6 +918,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--;