AppCarController.java 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.sqx.modules.car.controller.app;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.sqx.common.utils.Result;
  4. import com.sqx.modules.app.annotation.Login;
  5. import com.sqx.modules.car.entity.Car;
  6. import com.sqx.modules.car.service.CarService;
  7. import com.sqx.modules.driver.entity.Driver;
  8. import com.sqx.modules.driver.service.DriverService;
  9. import com.sqx.modules.emergencyContact.entity.EmergencyContact;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.*;
  14. import javax.annotation.Resource;
  15. import java.util.List;
  16. @RestController
  17. @Api(value = "车辆管理", tags = {"车辆管理"})
  18. @RequestMapping("/app/car")
  19. public class AppCarController {
  20. @Autowired
  21. private CarService carService;
  22. @Resource
  23. private DriverService driverService;
  24. @Login
  25. @GetMapping("/selectCarList")
  26. @ApiOperation("查询用户车辆")
  27. public Result selectCarList(@RequestAttribute("userId")Long userId){
  28. return Result.success().put("data",carService.list(new QueryWrapper<Car>().eq("user_id",userId)));
  29. }
  30. @Login
  31. @PostMapping("/insertCar")
  32. @ApiOperation("新增车辆")
  33. public Result insertCar(@RequestAttribute("userId")Long userId, Car car){
  34. car.setUserId(userId);
  35. car.setStatus(1);
  36. carService.insert(car);
  37. return Result.success();
  38. }
  39. @GetMapping("/selectCarById")
  40. @ApiOperation("根据ID查询车辆")
  41. public Result selectCarById(Long carId){
  42. return Result.success().put("data",carService.getOne(new QueryWrapper<Car>().eq("car_id",carId)));
  43. }
  44. @PostMapping("/updateCar")
  45. @ApiOperation("修改车辆信息")
  46. public Result updateEmergency(Car car){
  47. return carService.updateCar(car);
  48. }
  49. @PostMapping("/deleteCar")
  50. @ApiOperation("删除车辆信息")
  51. public Result deleteCar(Long carId){
  52. return carService.deleteCar(carId);
  53. }
  54. @Login
  55. @PostMapping("/updateChecked")
  56. @ApiOperation("修改车辆选中")
  57. public Result updateChecked(@RequestAttribute("userId")Long userId, Car car){
  58. if (car.getStatus() != 2){
  59. return Result.error(999,"未审核通过车辆禁止切换");
  60. }
  61. carService.updateCar(car);
  62. Driver driver = driverService.selectDriverByUserId(userId);
  63. driver.setDriverColor(car.getCarColor());
  64. driver.setDriverPlate(car.getCarPlate());
  65. driver.setDriverBrand(car.getCarBrand());
  66. driver.setStatus(car.getStatus());
  67. driverService.updateDriver(driver);
  68. List<Car> carList = carService.list(new QueryWrapper<Car>().eq("user_id", userId));
  69. if (carList.size() == 1){
  70. return Result.success();
  71. }else if (carList.size() > 1){
  72. for (Car c : carList){
  73. if (c.getCarId() != car.getCarId()){
  74. c.setChecked(0);
  75. carService.updateCar(c);
  76. }
  77. }
  78. }
  79. return Result.success();
  80. }
  81. }