kongdeqiang
2024-03-18 ffa5f49a2bcb6311486d00777b3629538eb3e6f0
src/main/java/com/boying/controller/BarrierController.java
@@ -8,11 +8,13 @@
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.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;
@@ -25,6 +27,7 @@
    private final BarrierService barrierService;
    private final OutParkService outParkService;
    private final ParkService parkService;
    private final RedisJsonUtil redisJsonUtil;
    @PostMapping("findPage")
    public Object findPage(Page page, String parkId) {
@@ -48,12 +51,19 @@
    public Object save(Barrier barrier) {
        barrier.setUpdateTime(LocalDateTime.now());
        barrierService.saveOrUpdate(barrier);
        try {
            redisJsonUtil.set("barrier-"+barrier.getCode(),barrier);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.ok("保存成功");
    }
    @PostMapping("delete")
    public Object delete(Integer id) {
        Barrier byId = barrierService.getById(id);
        barrierService.removeById(id);
        redisJsonUtil.del("barrier-"+byId.getCode());
        return R.ok("删除成功");
    }
@@ -77,6 +87,11 @@
        b.setType2(1);
        b.setUpdateTime(LocalDateTime.now());
        barrierService.saveOrUpdate(b);
        try {
            redisJsonUtil.set("barrier-"+b.getCode(),b);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.ok("请求成功");
    }
@@ -104,6 +119,11 @@
               b.setType2(1);
               b.setUpdateTime(LocalDateTime.now());
               barrierService.saveOrUpdate(b);
               try {
                   redisJsonUtil.set("barrier-"+b.getCode(),b);
               } catch (IOException e) {
                   e.printStackTrace();
               }
               return R.ok("请求成功");
           }else {
               System.out.println("手动开出口闸");
@@ -119,12 +139,22 @@
                   b.setType2(1);
                   b.setUpdateTime(LocalDateTime.now());
                   barrierService.saveOrUpdate(b);
                   try {
                       redisJsonUtil.set("barrier-"+b.getCode(),b);
                   } catch (IOException e) {
                       e.printStackTrace();
                   }
                   return R.ok("请求成功");
               }else {
                   //计费
                   b.setType2(1);
                   b.setUpdateTime(LocalDateTime.now());
                   barrierService.saveOrUpdate(b);
                   try {
                       redisJsonUtil.set("barrier-"+b.getCode(),b);
                   } catch (IOException e) {
                       e.printStackTrace();
                   }
                   return R.ok("请求成功");
               }
           }