kongdeqiang
2024-04-11 f9a85d68b1a08b03753d297f76bd4e87bb4d2b3e
src/main/java/com/boying/controller/BarrierController.java
@@ -1,15 +1,19 @@
package com.boying.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boying.common.R;
import com.boying.entity.Barrier;
import com.boying.entity.BarrierOpenLog;
import com.boying.entity.OutPark;
import com.boying.service.BarrierOpenLogService;
import com.boying.service.BarrierService;
import com.boying.service.OutParkService;
import com.boying.service.ParkService;
import com.boying.util.RedisJsonUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -17,6 +21,7 @@
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.List;
@RestController
@@ -25,9 +30,11 @@
public class BarrierController {
    private final BarrierService barrierService;
    private final BarrierOpenLogService barrierOpenLogService;
    private final OutParkService outParkService;
    private final ParkService parkService;
    private final RedisJsonUtil redisJsonUtil;
    private final StringRedisTemplate redisTemplate;
    @PostMapping("findPage")
    public Object findPage(Page page, String parkId) {
@@ -37,9 +44,8 @@
        Page page1 = barrierService.page(page, wrapper);
        List<Barrier> records = page1.getRecords();
        for(Barrier barrier:records){
            long l = System.currentTimeMillis() - barrier.getUpdateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
            System.out.println(l);
            if(l>10000){
            long between = ChronoUnit.SECONDS.between(barrier.getUpdateTime(), LocalDateTime.now());
            if(between>121){
                barrier.setStatus(1);
            }
        }
@@ -52,8 +58,9 @@
        barrier.setUpdateTime(LocalDateTime.now());
        barrierService.saveOrUpdate(barrier);
        try {
            redisJsonUtil.set("barrier-"+barrier.getCode(),barrier);
        } catch (IOException e) {
            String jsonValue = JSON.toJSONString(barrier);
            redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok("保存成功");
@@ -63,7 +70,7 @@
    public Object delete(Integer id) {
        Barrier byId = barrierService.getById(id);
        barrierService.removeById(id);
        redisJsonUtil.del("barrier-"+byId.getCode());
        redisTemplate.delete("barrier-"+byId.getCode());
        return R.ok("删除成功");
    }
@@ -88,8 +95,9 @@
        b.setUpdateTime(LocalDateTime.now());
        barrierService.saveOrUpdate(b);
        try {
            redisJsonUtil.set("barrier-"+b.getCode(),b);
        } catch (IOException e) {
            String jsonValue = JSON.toJSONString(b);
            redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok("请求成功");
@@ -108,7 +116,7 @@
    @PostMapping("openBarrier")
    public Object openBarrier(Long barrierId,Integer type) {
    public Object openBarrier(Long barrierId,Integer type,String carNo,String remark) {
        Barrier b=  barrierService.getById(barrierId);
        if (b==null) {
            return R.failed("未找到该道闸");
@@ -120,8 +128,15 @@
               b.setUpdateTime(LocalDateTime.now());
               barrierService.saveOrUpdate(b);
               try {
                   redisJsonUtil.set("barrier-"+b.getCode(),b);
               } catch (IOException e) {
                   String jsonValue = JSON.toJSONString(b);
                   redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue);
                   BarrierOpenLog barrierOpenLog = new BarrierOpenLog();
                   barrierOpenLog.setCarNo(carNo);
                   barrierOpenLog.setRemark(remark);
                   barrierOpenLog.setParkId(b.getParkId());
                   barrierOpenLog.setType(b.getType());
                   barrierOpenLogService.save(barrierOpenLog);
               } catch (Exception e) {
                   e.printStackTrace();
               }
               return R.ok("请求成功");
@@ -140,8 +155,15 @@
                   b.setUpdateTime(LocalDateTime.now());
                   barrierService.saveOrUpdate(b);
                   try {
                       redisJsonUtil.set("barrier-"+b.getCode(),b);
                   } catch (IOException e) {
                       String jsonValue = JSON.toJSONString(b);
                       redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue);
                       BarrierOpenLog barrierOpenLog = new BarrierOpenLog();
                       barrierOpenLog.setCarNo(carNo);
                       barrierOpenLog.setRemark(remark);
                       barrierOpenLog.setParkId(b.getParkId());
                       barrierOpenLog.setType(b.getType());
                       barrierOpenLogService.save(barrierOpenLog);
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
                   return R.ok("请求成功");
@@ -151,8 +173,15 @@
                   b.setUpdateTime(LocalDateTime.now());
                   barrierService.saveOrUpdate(b);
                   try {
                       redisJsonUtil.set("barrier-"+b.getCode(),b);
                   } catch (IOException e) {
                       String jsonValue = JSON.toJSONString(b);
                       redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue);
                       BarrierOpenLog barrierOpenLog = new BarrierOpenLog();
                       barrierOpenLog.setCarNo(carNo);
                       barrierOpenLog.setRemark(remark);
                       barrierOpenLog.setParkId(b.getParkId());
                       barrierOpenLog.setType(b.getType());
                       barrierOpenLogService.save(barrierOpenLog);
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
                   return R.ok("请求成功");