2 Incheckningar 352b01e59f ... 020bb78b89

Upphovsman SHA1 Meddelande Datum
  hjp 020bb78b89 Merge remote-tracking branch 'origin/master' 2 veckor sedan
  hjp c209b3ffe0 新增车辆管理选择逻辑 2 veckor sedan

+ 36 - 1
src/main/java/com/sqx/modules/car/controller/app/AppCarController.java

@@ -5,12 +5,17 @@ import com.sqx.common.utils.Result;
 import com.sqx.modules.app.annotation.Login;
 import com.sqx.modules.car.entity.Car;
 import com.sqx.modules.car.service.CarService;
+import com.sqx.modules.driver.entity.Driver;
+import com.sqx.modules.driver.service.DriverService;
 import com.sqx.modules.emergencyContact.entity.EmergencyContact;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
+import java.util.List;
+
 @RestController
 @Api(value = "车辆管理", tags = {"车辆管理"})
 @RequestMapping("/app/car")
@@ -18,6 +23,8 @@ public class AppCarController {
 
     @Autowired
     private CarService carService;
+    @Resource
+    private DriverService driverService;
 
     @Login
     @GetMapping("/selectCarList")
@@ -31,7 +38,7 @@ public class AppCarController {
     @ApiOperation("新增车辆")
     public Result insertCar(@RequestAttribute("userId")Long userId, Car car){
         car.setUserId(userId);
-        car.setStatus(1L);
+        car.setStatus(1);
         carService.insert(car);
         return Result.success();
     }
@@ -54,4 +61,32 @@ public class AppCarController {
         return carService.deleteCar(carId);
     }
 
+    @Login
+    @PostMapping("/updateChecked")
+    @ApiOperation("修改车辆选中")
+    public Result updateChecked(@RequestAttribute("userId")Long userId, Car car){
+        if (car.getStatus() != 2){
+            return Result.error(999,"未审核通过车辆禁止切换");
+        }
+        carService.updateCar(car);
+        Driver driver = driverService.selectDriverByUserId(userId);
+        driver.setDriverColor(car.getCarColor());
+        driver.setDriverPlate(car.getCarPlate());
+        driver.setDriverBrand(car.getCarBrand());
+        driver.setStatus(car.getStatus());
+        driverService.updateDriver(driver);
+        List<Car> carList = carService.list(new QueryWrapper<Car>().eq("user_id", userId));
+        if (carList.size() == 1){
+            return Result.success();
+        }else if (carList.size() > 1){
+            for (Car c : carList){
+                if (c.getCarId() != car.getCarId()){
+                    c.setChecked(0);
+                    carService.updateCar(c);
+                }
+            }
+        }
+        return Result.success();
+    }
+
 }

+ 6 - 1
src/main/java/com/sqx/modules/car/entity/Car.java

@@ -57,6 +57,11 @@ public class Car implements Serializable {
     /**
      * 状态 1审核中 2使用中 3未通过
      */
-    private Long status;
+    private Integer status;
+
+    /**
+     * 0-未选择 1-选中
+     */
+    private Integer checked;
 
 }