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 | 61 ++++++++++++++++++++++-------- 1 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/boying/controller/BarrierController.java b/src/main/java/com/boying/controller/BarrierController.java index 478572e..8fb48d4 100644 --- a/src/main/java/com/boying/controller/BarrierController.java +++ b/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("璇锋眰鎴愬姛"); -- Gitblit v1.9.1