From acf352921487e857810a943b008121e33404e9ae Mon Sep 17 00:00:00 2001
From: kongdeqiang <kongdeqiang960204@163.com>
Date: 星期二, 15 四月 2025 16:56:50 +0800
Subject: [PATCH] fix:白名单新增bug
---
src/main/java/com/boying/controller/BarrierController.java | 124 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 118 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/boying/controller/BarrierController.java b/src/main/java/com/boying/controller/BarrierController.java
index bc1e5ea..54144bd 100644
--- a/src/main/java/com/boying/controller/BarrierController.java
+++ b/src/main/java/com/boying/controller/BarrierController.java
@@ -1,30 +1,46 @@
package com.boying.controller;
+import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
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 io.swagger.annotations.Tag;
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.util.List;
+import java.time.temporal.ChronoUnit;
+import java.util.*;
+import java.util.stream.Collectors;
@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")
+ // @Operation(summary = "鏍规嵁鍋滆溅鍦哄垎椤垫煡璇㈤亾闂�" , description = "鏍规嵁鍋滆溅鍦哄垎椤垫煡璇㈤亾闂�" )
public Object findPage(Page page, String parkId) {
QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
wrapper.lambda()
@@ -32,9 +48,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);
}
}
@@ -43,19 +58,30 @@
}
@PostMapping("save")
+ // @Operation(summary = "鏂板閬撻椄" , description = "鏂板閬撻椄" )
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")
+ //@Operation(summary = "鍒犻櫎閬撻椄" , description = "鍒犻櫎閬撻椄" )
public Object delete(Integer id) {
+ Barrier byId = barrierService.getById(id);
barrierService.removeById(id);
+ redisTemplate.delete("barrier-"+byId.getCode());
return R.ok("鍒犻櫎鎴愬姛");
}
@PostMapping("findAll")
+ //@Operation(summary = "鏌ヨ鎵�鏈夐亾闂革紙APP锛�" , description = "鏌ヨ鎵�鏈夐亾闂革紙APP锛�" )
public Object findAll(Long parkId) {
if (parkId==null) {
return R.failed("鏈彂鐜拌鍋滆溅鍦�");
@@ -67,6 +93,7 @@
}
@PostMapping("open")
+ // @Operation(summary = "鎵嬪姩寮�闂革紙搴熷純锛�" , description = "鎵嬪姩寮�闂革紙搴熷純锛�" )
public Object open(Long barrierId) {
Barrier b= barrierService.getById(barrierId);
if (b==null) {
@@ -75,11 +102,31 @@
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")
+ // @Operation(summary = "鏍规嵁code鏌ヨ閬撻椄" , description = "鏍规嵁code鏌ヨ閬撻椄" )
+ 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) {
+ // @Operation(summary = "鎵嬫寔鎵嬪姩寮�闂�" , description = "鎵嬫寔鎵嬪姩寮�闂�" )
+ public Object openBarrier(Long barrierId,Integer type,String carNo,String remark) {
Barrier b= barrierService.getById(barrierId);
if (b==null) {
return R.failed("鏈壘鍒拌閬撻椄");
@@ -90,6 +137,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,15 +164,68 @@
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("璇锋眰鎴愬姛");
}
}
}
}
+
+ @PostMapping("getDisConnect")
+ //@Operation(summary = "璁惧鎺夌嚎閫氱煡" , description = "璁惧鎺夌嚎閫氱煡" )
+ public Object getDisConnect() {
+ List<Map<String,Object>> resultlist = new ArrayList<>();
+ String barrierCodeAll = redisTemplate.opsForValue().get("barrierCode_all");
+ if(StringUtils.isBlank(barrierCodeAll)){
+ QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
+ wrapper.select(" code ");
+ List<Barrier> list = barrierService.list(wrapper);
+ String collect = list.stream().map(Barrier::getCode).collect(Collectors.joining(","));
+ redisTemplate.opsForValue().set("barrierCode_all",collect);
+ barrierCodeAll = collect;
+ }
+ for (String s : barrierCodeAll.split(",")) {
+ Barrier barrier = barrierService.findByCode(s);
+ long between = ChronoUnit.SECONDS.between(barrier.getUpdateTime(), LocalDateTime.now());
+ if(between>121){
+ Map<String,Object> map = new HashMap<>();
+ map.put("parkName",parkService.getOneById(barrier.getParkId()).getName());
+ map.put("type",barrier.getType()==0?"鍑哄彛":"鍏ュ彛");
+ map.put("downTime",barrier.getUpdateTime());
+ resultlist.add(map);
+ }
+ }
+ Collections.sort(resultlist, (m1, m2)-> String.valueOf(m2.get("downTime")).compareTo(String.valueOf(m1.get("downTime")))); // lamuda鎺掑簭
+ return R.ok(resultlist);
+ }
+
}
--
Gitblit v1.9.1