kongdeqiang
2024-12-04 80cacfd0dcee0174f2a8d9ae322a2fcf857cef63
src/main/java/com/boying/controller/BarrierController.java
@@ -2,6 +2,7 @@
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;
@@ -12,6 +13,7 @@
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;
@@ -22,7 +24,8 @@
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping("ffzf/barrier")
@@ -33,10 +36,11 @@
    private final BarrierOpenLogService barrierOpenLogService;
    private final OutParkService outParkService;
    private final ParkService parkService;
    private StringRedisTemplate redisTemplate;
    private final StringRedisTemplate redisTemplate;
    @PostMapping("findPage")
   // @Operation(summary = "根据停车场分页查询道闸" , description = "根据停车场分页查询道闸" )
    public Object findPage(Page page, String parkId) {
        QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
        wrapper.lambda()
@@ -54,6 +58,7 @@
    }
    @PostMapping("save")
   // @Operation(summary = "新增道闸" , description = "新增道闸" )
    public Object save(Barrier barrier) {
        barrier.setUpdateTime(LocalDateTime.now());
        barrierService.saveOrUpdate(barrier);
@@ -67,6 +72,7 @@
    }
    @PostMapping("delete")
    //@Operation(summary = "删除道闸" , description = "删除道闸" )
    public Object delete(Integer id) {
        Barrier byId = barrierService.getById(id);
        barrierService.removeById(id);
@@ -75,6 +81,7 @@
    }
    @PostMapping("findAll")
    //@Operation(summary = "查询所有道闸(APP)" , description = "查询所有道闸(APP)" )
    public Object findAll(Long parkId) {
        if (parkId==null) {
            return R.failed("未发现该停车场");
@@ -86,6 +93,7 @@
    }
    @PostMapping("open")
   // @Operation(summary = "手动开闸(废弃)" , description = "手动开闸(废弃)" )
    public Object open(Long barrierId) {
        Barrier b=  barrierService.getById(barrierId);
        if (b==null) {
@@ -104,6 +112,7 @@
    }
    @PostMapping("getByCode")
   // @Operation(summary = "根据code查询道闸" , description = "根据code查询道闸" )
    public Object getByCode(String code) {
        Barrier b=  barrierService.findByCode2(code);
        if (b==null) {
@@ -116,6 +125,7 @@
    @PostMapping("openBarrier")
   // @Operation(summary = "手持手动开闸" , description = "手持手动开闸" )
    public Object openBarrier(Long barrierId,Integer type,String carNo,String remark) {
        Barrier b=  barrierService.getById(barrierId);
        if (b==null) {
@@ -189,4 +199,33 @@
           }
        }
    }
    @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);
    }
}