kongdeqiang
2024-03-19 bccd25039a08f8833b72ff906d156da63018db98
src/main/java/com/boying/controller/BarrierController.java
@@ -1,5 +1,6 @@
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;
@@ -10,6 +11,7 @@
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;
@@ -27,7 +29,8 @@
    private final BarrierService barrierService;
    private final OutParkService outParkService;
    private final ParkService parkService;
    private final RedisJsonUtil redisJsonUtil;
    private StringRedisTemplate redisTemplate;
    @PostMapping("findPage")
    public Object findPage(Page page, String parkId) {
@@ -39,7 +42,7 @@
        for(Barrier barrier:records){
            long l = System.currentTimeMillis() - barrier.getUpdateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
            System.out.println(l);
            if(l>10000){
            if(l>20000){
                barrier.setStatus(1);
            }
        }
@@ -52,8 +55,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 +67,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 +92,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("请求成功");
@@ -120,8 +125,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("请求成功");
@@ -140,8 +146,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("请求成功");
@@ -151,8 +158,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("请求成功");