kongdeqiang
2023-06-05 bb344d8e73bf3a6825f21584609649cb5d5042f5
src/main/java/com/boying/controller/car/PlateServlet3.java
@@ -9,6 +9,7 @@
import com.boying.entity.*;
import com.boying.service.*;
import com.boying.util.DateUtilOther;
import com.boying.util.FileUtil;
import com.boying.util.StringUtil;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -35,11 +36,12 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
 * Servlet implementation class PlateServlet
 */
@Controller
@RequestMapping("/car")
@RequestMapping("/ffzf/car")
@RequiredArgsConstructor
public class PlateServlet3 extends HttpServlet {
    private static final long serialVersionUID = 1L;
@@ -52,6 +54,7 @@
    private final TicketService ticketService;
    private final CostRuleService costRuleService;
    private final WhiteListService whiteListService;
    private final FileInfoService fileInfoService;
    private final String LEDURL = "http://192.168.31.212:9988/LedShow/IGetResultDataAllLine";
    /**
@@ -145,9 +148,13 @@
                    int i = Integer.parseInt(redisnum);
                    i--;
                    if(i<0){
                        String s= "2."+barrier.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."+barrier.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);
                    }
@@ -170,9 +177,13 @@
                        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);
                        }
@@ -208,6 +219,7 @@
        BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));
        String str = "";
        String lineStr = "";
        FileInfo fileInfo = null;
        while((str = reader.readLine()) != null){
            lineStr += str;
        }
@@ -218,6 +230,7 @@
        JSONObject result = alarmInfoPlate.getJSONObject("result");
        JSONObject plateResult = result.getJSONObject("PlateResult");
        String carNo = plateResult.get("license").toString();
      //  String image = plateResult.get("imageFile").toString();
        String code = alarmInfoPlate.get("serialno").toString();
        try {
@@ -253,7 +266,14 @@
                    break;
                }
                System.out.println("编号:"+serialno+"设备识别到了:"+license);
//                if(StringUtils.isNotBlank(image)){
//                    fileInfo = FileUtil.generateBase64StringToFile(image, 1,1);
//                    fileInfoService.save(fileInfo);
//                }
                System.out.println("编号:"+serialno+"  设备识别到了:"+license);
                String format = sdf.format(new Date());
                s+= format+",车牌号为:"+license+",serialno为:"+code+"  ";
@@ -264,7 +284,7 @@
                    easyNoOpen(request,response);
                }else{
                    if(barrier.getType()==0){
                        outPark(license, barrier.getId(), barrier.getParkId(),request,response);
                        outPark(license, barrier.getId(), barrier.getParkId(),request,response,fileInfo);
                        s+=license+"-保存出场记录\n";
                    }else{
                        String num = redisTemplate.opsForValue().get("car_park_" +  barrier.getParkId());
@@ -280,7 +300,7 @@
                        }else {
                            //led显示
                            inLedShow(code, license,barrier.getParkId(),request,response);
                            enterPark(license,barrier.getId(),barrier.getParkId());
                            enterPark(license,barrier.getId(),barrier.getParkId(),fileInfo);
                            s+=license+"-保存入场记录\n";
                        }
                    }
@@ -314,10 +334,27 @@
        }
    }
    private void writeTxt2( String txt)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        try
        {
            FileWriter f = new FileWriter(systemConfigProperties.getLogPath()+sdf.format(new Date())+"LED.txt",true);
            BufferedWriter bw=new BufferedWriter(f);
            bw.write(txt);
            bw.newLine();
            bw.close();
        }
        catch(Exception e)
        {
            System.out.println("打印错误");
        }
    }
    public void enterPark(String carNo,Integer barrierId,Integer parkId) {
    public void enterPark(String carNo,Integer barrierId,Integer parkId,FileInfo fileInfo) {
        Park park = parkService.getById(parkId);
//        int num = 0;
//        String s = redisTemplate.opsForValue().get("car_park_" + parkId);
@@ -348,6 +385,9 @@
        if(tickets.size()>0){
            enterPark.setStatus(1);//发现有违章
        }
        if(fileInfo != null){
            enterPark.setImgId(fileInfo.getId());
        }
        enterParkService.saveOrUpdate(enterPark);
//        Barrier barrier = barrierService.getById(barrierId);
@@ -355,7 +395,7 @@
//        barrierService.saveOrUpdate(barrier);
    }
    public double outPark(String carNo,Integer barrierId,Integer parkId,HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    public double outPark(String carNo,Integer barrierId,Integer parkId,HttpServletRequest request, HttpServletResponse response,FileInfo fileInfo) throws ServletException, IOException {
        double money = 0.0;
        EnterPark enterPark = null;
        String toDayHrMinSec = null;
@@ -386,6 +426,9 @@
        //outPark.setPrice(Double.valueOf(String.format("%.1f", money)));
        outPark.setPrice(money);
        outPark.setStatus3(findTicket(carNo));
        if(fileInfo != null){
            outPark.setImgId(fileInfo.getId());
        }
        outParkService.saveOrUpdate(outPark);
        Barrier barrier =barrierService.getById(barrierId);
        barrier.setCarNo(carNo);
@@ -408,7 +451,7 @@
                    outParkService.saveOrUpdate(byCarNoAndBarrierId);
                    return 0.0;
                }else{
                    if(w.getParkIds()!=null){
                    if(StringUtils.isNotBlank(w.getParkIds())){
                        if(w.getEndTime()!=null){
                            String parkIds = w.getParkIds();
                            String[] split = parkIds.split(",");
@@ -430,10 +473,14 @@
        }
        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);
        }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);
        }
        barrierService.saveOrUpdate(barrier);
@@ -478,10 +525,12 @@
                carType = "月租车";
            }else {
                //白名单固定停车场车辆
                if(byCarNo.getParkId().equals(barrier.getParkId())){
                if(StringUtils.isNotBlank(byCarNo.getParkIds()) && byCarNo.getParkIds().contains(barrier.getParkId()+"")){
                    carType = "月租车";
                    long l = (byCarNo.getEndTime().getTime() - byCarNo.getStartTime().getTime()) / (24 * 3600 * 1000);
                    carDay = "有效期还有"+l+"天";
                }else {
                    carType = "临时车";
                }
            }
        }
@@ -525,10 +574,10 @@
                carType = "月租车";
            }else {
                //白名单固定停车场车辆
                if(byCarNo.getParkId().equals(barrier.getParkId())){
                if(StringUtils.isNotBlank(byCarNo.getParkIds()) && byCarNo.getParkIds().contains(barrier.getParkId()+"")){
                    carType = "月租车";
                    long l = (byCarNo.getEndTime().getTime() - byCarNo.getStartTime().getTime()) / (24 * 3600 * 1000);
                    carDay = "有效期还有"+l+"天";
                }else {
                    carType = "临时车";
                }
            }
        }
@@ -585,9 +634,13 @@
            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);
            }
@@ -625,9 +678,13 @@
            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);
            }
@@ -698,4 +755,5 @@
        noOpen(request,response,data1);
    }
}