From 80cacfd0dcee0174f2a8d9ae322a2fcf857cef63 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期三, 04 十二月 2024 15:31:35 +0800
Subject: [PATCH] fix : 新增修改出场接口

---
 src/main/java/com/boying/controller/OutParkController.java |  123 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 123 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/boying/controller/OutParkController.java b/src/main/java/com/boying/controller/OutParkController.java
index fdaea6f..be0c09f 100644
--- a/src/main/java/com/boying/controller/OutParkController.java
+++ b/src/main/java/com/boying/controller/OutParkController.java
@@ -1,8 +1,10 @@
 package com.boying.controller;
 
 import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.boying.common.R;
 import com.boying.common.SystemConfigProperties;
@@ -29,6 +31,7 @@
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
@@ -80,6 +83,9 @@
     //閬撻椄code
     @PostMapping("/findByBarrierCode")
     public Object findById(String code) {
+        if(StringUtils.isBlank(code)){
+            return R.failed(null,"鍙傛暟閿欒");
+        }
        QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(Barrier::getCode2,code);
@@ -109,6 +115,9 @@
     //閬撻椄code
     @PostMapping("/findByBarrierCode2")
     public Object findById2(String code2) {
+        if(StringUtils.isBlank(code2)){
+            return R.failed(null,"鍙傛暟閿欒");
+        }
         System.out.println("code2     :"+code2);
         QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
         wrapper.lambda()
@@ -292,6 +301,120 @@
         }
     }
 
+    @GetMapping("/getByCarAndPark")
+    public Object getByCarAndPark(String carNo ,Integer parkId) {
+        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
+        wrapper.lambda()
+                .eq(OutPark::getCarNo,carNo)
+                .eq(OutPark::getParkId,parkId)
+                .orderByDesc(OutPark::getCreateTime);
+        List<OutPark> list = outParkService.list(wrapper);
+        if(list.size() > 0){
+            OutPark outPark = list.get(0);
+            if(outPark.getTime() > 0){
+                outPark.setTimeStr(DateUtilOther.millisToDayHrMinSec(new Double(outPark.getTime()).longValue()));
+            }else {
+                outPark.setTimeStr("涓嶈冻涓�鍒嗛挓");
+            }
+            return R.ok(outPark,"鎵惧埌鏁版嵁");
+        }else {
+            return R.failed(null,"鏈壘鍒版暟鎹�");
+        }
+    }
+
+    //鎵爜淇敼鍑哄満锛堟ā绯婅溅鐗岋級
+    @GetMapping("/getLikeCar")
+    public Object getLikeCar(Integer outParkId) {
+        OutPark byId = outParkService.getById(outParkId);
+        List<Map<String, Object>> likeCar = outParkService.getLikeCar(byId.getCarNo(), byId.getParkId(), byId.getCreateTime());
+        if (CollectionUtils.isNotEmpty(likeCar)) {
+            Collections.sort(likeCar, (m1, m2)-> String.valueOf(m2.get("createTime")).compareTo(String.valueOf(m1.get("createTime"))));
+        }
+        return R.ok(likeCar);
+    }
+
+    //鎵爜淇敼鍑哄満锛堟ā绯婅溅鐗岋級
+    @GetMapping("/editOutPark")
+    public Object editOutPark(Integer outParkId,Integer enterParkId,Integer type) {
+        double money = 0.0;
+        OutPark outPark = outParkService.getById(outParkId);
+        EnterPark enterPark = enterParkService.getById(enterParkId);
+        Barrier barrier =barrierService.getById(outPark.getBarrierId());
+        if(type == 0){ //鍏ュ満姝g‘锛屾浛鎹㈠嚭鍦猴紝鏇存柊鍑哄満璁板綍
+            outPark.setCarNo(enterPark.getCarNo());
+            barrier.setCarNo(enterPark.getCarNo());
+            barrierService.saveOrUpdate(barrier);
+            String jsonValue = JSON.toJSONString(barrier);
+            redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue);
+        }else { //鍑哄満姝g‘锛屾浛鎹㈠叆鍦猴紝鏇存柊鍑哄満璁板綍
+            enterPark.setCarNo(outPark.getCarNo());
+        }
+        outPark.setEnterTime(enterPark.getCreateTime());
+        try {
+            long l = outPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - enterPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
+            outPark.setTime(l/(1000*60));
+            if(outPark.getTime() > 0){
+                outPark.setTimeStr(DateUtilOther.millisToDayHrMinSec(new Double(outPark.getTime()).longValue()));
+            }else {
+                outPark.setTimeStr("涓嶈冻涓�鍒嗛挓");
+            }
+            money = costRuleService.getMoney(outPark.getParkId(), outPark.getEnterTime(), outPark.getCreateTime(), 1);
+            //鍏ュ満璁板綍淇濆瓨涓�涓�
+            enterPark.setPrice(money);
+            enterPark.setIsPay(0);
+            enterParkService.updateById(enterPark);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        outPark.setPrice(money);
+        outParkService.saveOrUpdate(outPark);
+        outPark.setParkName(barrier.getName());
+        return R.ok(outPark,"鏇存柊鎴愬姛");
+    }
+
+    @GetMapping("/editEnterPark")
+    public Object editEnterPark(String carNo ,Integer parkId,String time) {
+        QueryWrapper<Barrier> wrapper = new QueryWrapper<>();
+        wrapper.lambda()
+                .eq(Barrier::getParkId,parkId)
+                .eq(Barrier::getType,1);
+        List<Barrier> list = barrierService.list(wrapper);
+        EnterPark enterPark = new EnterPark();
+        enterPark.setCreateTime(LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+        enterPark.setCarNo(carNo);
+        enterPark.setParkId(parkId);
+        enterPark.setBarrierId(list.get(0).getId());
+        enterPark.setStatus(0);
+        enterPark.setIsAdd(1);
+        enterPark.setIsPay(0);
+        enterParkService.saveOrUpdate(enterPark);
+
+        OutPark outPark = null;
+        QueryWrapper<OutPark> wrapper1 = new QueryWrapper<>();
+        wrapper1.lambda()
+                .eq(OutPark::getParkId,parkId)
+                .eq(OutPark::getCarNo,carNo)
+                .ge(OutPark::getCreateTime,enterPark.getCreateTime())
+                .ne(OutPark::getStatus,1);
+        List<OutPark> list1 = outParkService.list(wrapper1);
+        if(list1 !=null&&list1.size()>0){
+            outPark  = list1.get(0);
+            outPark.setEnterTime(enterPark.getCreateTime());
+            long l = outPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - enterPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
+            outPark.setTime(l/(1000*60));
+            try {
+                outPark.setPrice(costRuleService.getMoney(parkId, outPark.getEnterTime(), outPark.getCreateTime(), 1));
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+            outParkService.saveOrUpdate(outPark);
+            return R.ok(null,"淇敼鍑哄満璁板綍鎴愬姛");
+        }else {
+            return R.ok(null,"鏂板鍏ュ満璁板綍鎴愬姛");
+        }
+
+    }
+
 
     public Barrier findBarrier(String code2) {
         QueryWrapper<Barrier> wrapper = new QueryWrapper<>();

--
Gitblit v1.9.1