From 81af4cff627b7ec1e125b90f4fd57392c6d70588 Mon Sep 17 00:00:00 2001
From: wjli <591616088@qq.com>
Date: 星期三, 10 四月 2024 11:28:03 +0800
Subject: [PATCH] 修改签收出错bug

---
 xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java |  154 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 137 insertions(+), 17 deletions(-)

diff --git a/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java b/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java
index e261f9d..e5a0da8 100644
--- a/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java
+++ b/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java
@@ -2,15 +2,12 @@
 
 import cn.exrick.xboot.core.common.utils.PageUtil;
 import cn.exrick.xboot.core.common.utils.ResultUtil;
+import cn.exrick.xboot.core.common.utils.SecurityUtil;
 import cn.exrick.xboot.core.common.vo.PageVo;
 import cn.exrick.xboot.core.common.vo.Result;
-import cn.exrick.xboot.your.entity.AddOil;
-import cn.exrick.xboot.your.entity.Car;
-import cn.exrick.xboot.your.entity.DrivingRecord;
-import cn.exrick.xboot.your.entity.Suggest;
-import cn.exrick.xboot.your.service.IAddOilService;
-import cn.exrick.xboot.your.service.ICarService;
-import cn.exrick.xboot.your.service.IDrivingRecordService;
+import cn.exrick.xboot.core.entity.User;
+import cn.exrick.xboot.your.entity.*;
+import cn.exrick.xboot.your.service.*;
 import cn.exrick.xboot.your.vo.CarVo;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
@@ -24,8 +21,11 @@
 import org.springframework.web.bind.annotation.*;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author zhangzeli
@@ -43,6 +43,9 @@
     private IAddOilService iAddOilService;
     @Autowired
     private IDrivingRecordService iDrivingRecordService;
+    @Autowired
+    private SecurityUtil securityUtil;
+
 
     @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
     @ApiOperation(value = "閫氳繃id鑾峰彇")
@@ -60,12 +63,23 @@
         return new ResultUtil<List<Car>>().setData(list);
     }
 
+    @RequestMapping(value = "/getBindCar", method = RequestMethod.GET)
+    @ApiOperation(value = "鑾峰彇缁戝畾鐨勮溅杈�")
+    public Result<Car> getBindCar() {
+        String userId =  securityUtil.getCurrUser().getId();
+        QueryWrapper<Car> carQueryWrapper = new QueryWrapper<Car>();
+        carQueryWrapper.eq("user_id",userId).or().eq("follow_user_id",userId);
+        Car car = iCarService.getOne(carQueryWrapper);
+        return new ResultUtil<Car>().setData(car);
+    }
+
     @RequestMapping(value = "/getAll", method = RequestMethod.GET)
     @ApiOperation(value = "鑾峰彇鍏ㄩ儴鏁版嵁")
-    public Result<List<CarVo>> getAll(String beginTime,String endTime) {
+    public Result<List<CarVo>> getAll(String beginTime,String endTime,PageVo page) {
         List<CarVo> carVos = new ArrayList<>();
-        List<Car> list = iCarService.getAll2();
-        for (Car car:list){
+        java.text.DecimalFormat   df   =new   java.text.DecimalFormat("#.##");
+        IPage<Car> list = iCarService.getAll2(PageUtil.initMpPage(page));
+        for (Car car:list.getRecords()){
             CarVo carVo = new CarVo();
             //鍔犳补淇℃伅
             QueryWrapper<AddOil> queryWrapper = new QueryWrapper<>();
@@ -80,15 +94,23 @@
             queryWrapper.ge(beginTime!=null && beginTime!="","add_date",beginTime);
 
             wrapper.le(endTime!=null && endTime!="","in_time",endTime);
-            queryWrapper.le(endTime!=null && endTime!="","add_date",beginTime);
+            queryWrapper.le(endTime!=null && endTime!="","add_date",endTime);
+
+            QueryWrapper<OrderTask> wrapper1 = new QueryWrapper<>();
+
+
+            wrapper1.eq("car_id",car.getId());
+            wrapper1.ge(beginTime!=null && beginTime!="","send_date",beginTime);
+            wrapper1.le(endTime!=null && endTime!="","send_date",endTime);
+
 
             DrivingRecord drivingRecord = iDrivingRecordService.getOne(wrapper);
 
             AddOil addOil = iAddOilService.getOne(queryWrapper);
 
             if (addOil!=null){
-                carVo.setMoney(addOil.getMoney());
-                carVo.setOilWear(addOil.getAmount());
+                carVo.setMoney(Double.parseDouble(df.format(addOil.getMoney())));
+                carVo.setOilWear(Double.parseDouble(df.format(addOil.getAmount())));
             }
 
             if (drivingRecord!=null) {
@@ -98,8 +120,50 @@
 
             carVo.setCar(car);
             carVos.add(carVo);
+            carVo.setTotal(list.getTotal());
         }
         return new ResultUtil<List<CarVo>>().setData(carVos);
+    }
+    @RequestMapping(value = "/getInfo", method = RequestMethod.GET)
+    @ApiOperation(value = "閫氳繃杞﹁締id鑾峰彇")
+    public Result<List<Car>> getInfo(String beginTime,String endTime) {
+        java.text.DecimalFormat   df   =new   java.text.DecimalFormat("#.##");
+
+        QueryWrapper<AddOil> wrapper = new QueryWrapper<>();
+        wrapper.ge(beginTime!=null && beginTime!="","add_date",beginTime);
+        wrapper.le(endTime!=null && endTime!="","add_date",endTime);
+//        wrapper.groupBy("car_id");
+        List<AddOil> addOilList = iAddOilService.list(wrapper);
+        List<Car> list = new ArrayList<>();
+        Map<String, List<AddOil>> collect = addOilList.stream().collect(Collectors.groupingBy(AddOil::getCarId));
+        for (Map.Entry<String, List<AddOil>> stringListEntry : collect.entrySet()) {
+            String key = stringListEntry.getKey();
+            Car car = iCarService.getById(key);
+            Car carInfoByCarId = iCarService.getCarInfoByCarId(key);
+            car.setAmount(Double.parseDouble(df.format(carInfoByCarId.getAmount())));
+            car.setMileage(Double.parseDouble(df.format(carInfoByCarId.getMileage())));
+            car.setMoney(Double.parseDouble(df.format(carInfoByCarId.getMoney())));
+            car.setAllAmount(Double.parseDouble(df.format(carInfoByCarId.getAllAmount())));
+            car.setAllMileage(Double.parseDouble(df.format(carInfoByCarId.getAllMileage())));
+            car.setAllMoney(Double.parseDouble(df.format(carInfoByCarId.getAllMoney())));
+            list.add(car);
+        }
+//        List<Car> list2 = iCarService.getCarInfo2(wrapper);
+//        List<Car> list = iCarService.getCarInfo();
+//        for (Car car:list2){
+//            for (Car car1:list){
+//                if (car.getId().equals(car1.getId())){
+//                    car1.setAmount(Double.parseDouble(df.format(car.getAmount())));
+//                    car1.setMileage(Double.parseDouble(df.format(car.getMileage())));
+//                    car1.setMoney(Double.parseDouble(df.format(car.getMoney())));
+//                    car1.setAllAmount(Double.parseDouble(df.format(car1.getAllAmount())));
+//                    car1.setAllMileage(Double.parseDouble(df.format(car1.getAllMileage())));
+//                    car1.setAllMoney(Double.parseDouble(df.format(car1.getAllMoney())));
+//                    continue;
+//                }
+//            }
+//        }
+        return new ResultUtil<List<Car>>().setData(list);
     }
 
     @RequestMapping(value = "/getByPage", method = RequestMethod.GET)
@@ -117,18 +181,74 @@
     @ApiOperation(value = "缂栬緫鎴栨洿鏂版暟鎹�")
     public Result<Car> saveOrUpdate(Car car) {
 
+        QueryWrapper<Car> wrapper = new QueryWrapper<>();
+        QueryWrapper<Car> wrapper1 = new QueryWrapper<>();
+        if (!car.getUserId().equals("")){
+            wrapper.eq("user_id",car.getUserId());
+            Car car1 = iCarService.getOne(wrapper);
+            if (car1!=null && !car1.getId().equals(car.getId())){
+                return new ResultUtil<Car>().setErrorMsg("璇ラ┚椹跺憳宸茶鍏朵粬杞﹁締缁戝畾,璇峰厛瑙g粦");
+            }
+        }
+
+        if (!car.getFollowUserId().equals("")){
+            wrapper1.eq("follow_user_id",car.getFollowUserId());
+            Car car1 = iCarService.getOne(wrapper1);
+            if (car1!=null && !car1.getId().equals(car.getId())){
+                return new ResultUtil<Car>().setErrorMsg("璇ラ厤閫佸憳宸茶鍏朵粬杞﹁締缁戝畾,璇峰厛瑙g粦");
+            }
+        }
+
         if (iCarService.saveOrUpdate(car)) {
             return new ResultUtil<Car>().setData(car);
         }
+
         return new ResultUtil<Car>().setErrorMsg("鎿嶄綔澶辫触");
     }
 
     @RequestMapping(value = "/bindCar", method = RequestMethod.POST)
     @ApiOperation(value = "缁戝畾杞﹁締浜哄憳")
-    public Result<Car> bindCar(String carId,String userId) {
-        Car car = iCarService.getById(carId);
-        car.setUserId(userId);
-        iCarService.saveOrUpdate(car);
+    public Result<Car> bindCar(String carId,String userId) {//A杞﹀紶涓� 鏉庡洓   B杞︾帇浜旓紝璧靛叚
+        User user = securityUtil.getCurrUser();
+        QueryWrapper<Car> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("user_id",user.getId()).or().eq("follow_user_id",user.getId());
+        Car one = iCarService.getOne(queryWrapper);//鍘熸潵鐨勮溅
+
+        if(one!=null){
+            //濡傛灉杩樻槸閫変簡鍘熸潵鐨勮溅鍒欎笉鐢ㄥ彉
+            if(one.getId().equals(carId)){
+
+            }else{
+                //濡傛灉閫変簡鍙︿竴杈嗚溅锛屽厛鎶婂師鏉ョ殑杞︾殑浜哄憳娓呯┖
+                if(user.getType2()==0){
+                    one.setUserId("");
+                }else{
+                    one.setFollowUserId("");
+                }
+                iCarService.saveOrUpdate(one);
+
+                //缁戝畾涓婃柊閫夌殑杞�
+                Car car = iCarService.getById(carId);
+                if(car!=null){
+                    if(user.getType2()==0){
+                        car.setUserId(user.getId());
+                    }else{
+                        car.setFollowUserId(user.getId());
+                    }
+                    iCarService.saveOrUpdate(car);
+                }
+            }
+        }else{
+            Car car = iCarService.getById(carId);
+            if(car!=null){
+                if(user.getType2()==0){
+                    car.setUserId(user.getId());
+                }else{
+                    car.setFollowUserId(user.getId());
+                }
+                iCarService.saveOrUpdate(car);
+            }
+        }
         return ResultUtil.success("缁戝畾鎴愬姛");
     }
 

--
Gitblit v1.9.1