From f9a85d68b1a08b03753d297f76bd4e87bb4d2b3e Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期四, 11 四月 2024 14:42:26 +0800
Subject: [PATCH] fix:手动抬杆接口更新

---
 src/main/java/com/boying/controller/BarrierController.java |   83 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/boying/controller/BarrierController.java b/src/main/java/com/boying/controller/BarrierController.java
index bc1e5ea..8fb48d4 100644
--- a/src/main/java/com/boying/controller/BarrierController.java
+++ b/src/main/java/com/boying/controller/BarrierController.java
@@ -1,28 +1,40 @@
 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;
 
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
+import java.time.temporal.ChronoUnit;
 import java.util.List;
 
 @RestController
-@RequestMapping("barrier")
+@RequestMapping("ffzf/barrier")
 @RequiredArgsConstructor
 public class BarrierController {
 
     private final BarrierService barrierService;
+    private final BarrierOpenLogService barrierOpenLogService;
     private final OutParkService outParkService;
+    private final ParkService parkService;
+    private final StringRedisTemplate redisTemplate;
+
 
     @PostMapping("findPage")
     public Object findPage(Page page, String parkId) {
@@ -32,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);
             }
         }
@@ -46,12 +57,20 @@
     public Object save(Barrier barrier) {
         barrier.setUpdateTime(LocalDateTime.now());
         barrierService.saveOrUpdate(barrier);
+        try {
+            String jsonValue = JSON.toJSONString(barrier);
+            redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return R.ok("淇濆瓨鎴愬姛");
     }
 
     @PostMapping("delete")
     public Object delete(Integer id) {
+        Barrier byId = barrierService.getById(id);
         barrierService.removeById(id);
+        redisTemplate.delete("barrier-"+byId.getCode());
         return R.ok("鍒犻櫎鎴愬姛");
     }
 
@@ -75,11 +94,29 @@
         b.setType2(1);
         b.setUpdateTime(LocalDateTime.now());
         barrierService.saveOrUpdate(b);
+        try {
+            String jsonValue = JSON.toJSONString(b);
+            redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return R.ok("璇锋眰鎴愬姛");
     }
 
+    @PostMapping("getByCode")
+    public Object getByCode(String code) {
+        Barrier b=  barrierService.findByCode2(code);
+        if (b==null) {
+            return R.failed("鏈壘鍒拌閬撻椄");
+        }
+        b.setParkName(parkService.getById(b.getParkId()).getName());
+        return R.ok(b,"璇锋眰鎴愬姛");
+    }
+
+
+
     @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("鏈壘鍒拌閬撻椄");
@@ -90,6 +127,18 @@
                b.setType2(1);
                b.setUpdateTime(LocalDateTime.now());
                barrierService.saveOrUpdate(b);
+               try {
+                   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("璇锋眰鎴愬姛");
            }else {
                System.out.println("鎵嬪姩寮�鍑哄彛闂�");
@@ -105,12 +154,36 @@
                    b.setType2(1);
                    b.setUpdateTime(LocalDateTime.now());
                    barrierService.saveOrUpdate(b);
+                   try {
+                       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("璇锋眰鎴愬姛");
                }else {
                    //璁¤垂
                    b.setType2(1);
                    b.setUpdateTime(LocalDateTime.now());
                    barrierService.saveOrUpdate(b);
+                   try {
+                       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("璇锋眰鎴愬姛");
                }
            }

--
Gitblit v1.9.1