Bläddra i källkod

车辆管理和司机管理业更改

donglang 2 månader sedan
förälder
incheckning
504cab1dba

+ 14 - 2
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/controller/KwfDriverController.java

@@ -11,7 +11,6 @@ import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.response.HttpResult;
-import com.sckw.core.web.response.ResponseUtil;
 import com.sckw.excel.utils.ExcelUtil;
 import com.sckw.fleet.model.dto.*;
 import com.sckw.fleet.model.vo.KwfDriverDetailVo;
@@ -24,7 +23,7 @@ import org.springframework.http.MediaType;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
-import java.io.IOException;
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -263,4 +262,17 @@ public class KwfDriverController {
         return HttpResult.ok(driverService.driverStatistics());
     }
 
+
+    /**
+     * @param params 新增参数
+     * @return HttpResult
+     * @desc 绑定车辆
+     * @author czh
+     * @date 2023/6/14
+     */
+    @PostMapping("/bindTruck")
+    public HttpResult bindTruck(@Valid @RequestBody KwfBindTruckDto params) throws SystemException{
+        return driverService.bindTruck(params);
+    }
+
 }

+ 3 - 3
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/controller/KwfTruckController.java

@@ -57,9 +57,9 @@ public class KwfTruckController {
      * @date 2023/7/6
      **/
     @GetMapping("/detail")
-    public HttpResult selectByKey(Long id) throws SystemException {
+    public HttpResult selectByKey(Long id, Long entId) throws SystemException {
         //车辆信息
-        KwfTruckDetailVo truckDetailVo = truckService.detail(id);
+        KwfTruckDetailVo truckDetailVo = truckService.detail(id, entId);
         return HttpResult.ok(truckDetailVo);
     }
 
@@ -88,7 +88,7 @@ public class KwfTruckController {
         }
 
         //车辆信息
-        KwfTruckDetailVo truckDetailVo = truckService.detail(id);
+        KwfTruckDetailVo truckDetailVo = truckService.detail(id, null);
         return HttpResult.ok(truckDetailVo);
     }
 

+ 12 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/KwfTruck.java

@@ -136,4 +136,16 @@ public class KwfTruck extends BaseModel {
      */
     @TableField("drive_mode")
     private Integer driveMode;
+
+    /**
+     * 车牌
+     */
+    @TableField("brand")
+    private String brand;
+
+    /**
+     * 车辆唯一识别码
+     */
+    @TableField("vin")
+    private String vin;
 }

+ 28 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/dto/KwfBindTruckDto.java

@@ -0,0 +1,28 @@
+package com.sckw.fleet.model.dto;
+
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
+
+/**
+ * @author zk
+ * @desc 车辆信息
+ * @date 2023/7/12 0012
+ */
+@Data
+public class KwfBindTruckDto {
+
+    /**
+     * 司机主键id
+     */
+    @NotBlank(message = "司机主键id不能为空!")
+    private Long id;
+
+    /**
+     * 车牌号
+     */
+    @NotBlank(message = "车牌号不能为空!")
+    private Long truckId;
+
+
+
+}

+ 10 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/dto/KwfTruckDto.java

@@ -96,6 +96,16 @@ public class KwfTruckDto {
     @Size(max=200, message = "remark长度不能大于200个字符!")
     private String remark;
 
+    /**
+     * 车牌
+     */
+    private String brand;
+
+    /**
+     * 车辆唯一识别码
+     */
+    private String vin;
+
     /**
      * 车辆行驶证信息
      */

+ 15 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/vo/KwfTruckDetailVo.java

@@ -117,6 +117,21 @@ public class KwfTruckDetailVo implements Serializable {
      */
     private String fleetName;
 
+    /**
+     * 司机名称
+     */
+    private String driverName;
+
+    /**
+     * 车牌
+     */
+    private String brand;
+
+    /**
+     * 车辆唯一识别码
+     */
+    private String vin;
+
     /**
      * 车辆行驶证信息
      */

+ 82 - 6
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/service/KwfDriverService.java

@@ -4,10 +4,12 @@ import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.ExcelReader;
 import com.alibaba.excel.read.metadata.ReadSheet;
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.sckw.core.common.enums.enums.DictEnum;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
 import com.sckw.core.common.enums.enums.FileEnum;
 import com.sckw.core.exception.SystemException;
+import com.sckw.core.model.base.BaseModel;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.enums.SystemTypeEnum;
 import com.sckw.core.model.file.FileInfo;
@@ -22,6 +24,8 @@ import com.sckw.fleet.dao.*;
 import com.sckw.fleet.model.*;
 import com.sckw.fleet.model.dto.*;
 import com.sckw.fleet.model.vo.*;
+import com.sckw.fleet.repository.KwfTruckReportRepository;
+import com.sckw.fleet.repository.KwfTruckRepository;
 import com.sckw.redis.constant.RedisConstant;
 import com.sckw.redis.utils.RedissonUtils;
 import com.sckw.system.api.RemoteSystemService;
@@ -71,6 +75,12 @@ public class KwfDriverService {
     private FileApiDubboService remoteFileService;
     @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 8000)
     private RemoteUserService remoteUserService;
+    @Autowired
+    KwfTruckReportRepository truckReportRepository;
+    @Autowired
+    KwfTruckRepository truckRepository;
+
+
     /**
      * @param key 逐渐id
      * @desc 根据主键查询
@@ -117,10 +127,10 @@ public class KwfDriverService {
             qualificationVo.setTypeName(value);
             driverDetailVo.setDriverQualification(qualificationVo);
 
-            //车队班组
-            KwfFleet fleet = this.findByFleetDriver(driverId, LoginUserHolder.getEntId());
-            driverDetailVo.setFleetId(fleet != null ? fleet.getId() : null);
-            driverDetailVo.setFleetName(fleet != null ? fleet.getName() : null);
+//            //车队班组
+//            KwfFleet fleet = this.findByFleetDriver(driverId, LoginUserHolder.getEntId());
+//            driverDetailVo.setFleetId(fleet != null ? fleet.getId() : null);
+//            driverDetailVo.setFleetName(fleet != null ? fleet.getName() : null);
 
             //司机关联车辆(车辆上报)
             if (LoginUserHolder.getSystemType() == SystemTypeEnum.DRIVER.getCode()) {
@@ -255,6 +265,11 @@ public class KwfDriverService {
             driver.setCreateByName(user != null ? user.getName() : null);
             driver.setFirmName(ent != null ? ent.getFirmName() : null);
             driver.setLicenseTypeName(licenseType != null ? licenseType.getLabel() : null);
+
+            //获取车辆信息
+            KwfTruck truckInfo = getTruckInfo(driver.getId(), driver.getEntId());
+            driver.setTruckNo(truckInfo.getTruckNo());
+
         }
         return drivers;
     }
@@ -287,6 +302,33 @@ public class KwfDriverService {
         }
     }
 
+    /**
+     * 根据司机id和企业id查询车辆信息
+     *
+     * @param truck
+     * @param ents
+     * @return
+     */
+    private KwfTruck getTruckInfo(String driverId, String entId) {
+        //查询司机关联车辆信息
+        KwfTruckReport truckReport = truckReportRepository.getOne(Wrappers.<KwfTruckReport>lambdaQuery()
+                .eq(BaseModel::getDelFlag, 0)
+                .eq(KwfTruckReport::getDriverId, driverId)
+                .eq(KwfTruckReport::getEntId, entId));
+        if (truckReport == null) {
+            return new KwfTruck();
+        }
+        //查询车辆信息
+        KwfTruck truck = truckRepository.getOne(Wrappers.<KwfTruck>lambdaQuery()
+                .eq(BaseModel::getDelFlag, 0)
+                .eq(KwfTruck::getId, truckReport.getTruckId())
+                .eq(KwfTruck::getEntId, entId));
+        if (truck == null) {
+            return new KwfTruck();
+        }
+        return truck;
+    }
+
     /**
      * @param params 查询参数
      * @desc 查询
@@ -432,7 +474,7 @@ public class KwfDriverService {
         }
 
         /**车队班组绑定**/
-        driverFleetEdit(driver.getId(), params.getFleetId());
+//        driverFleetEdit(driver.getId(), params.getFleetId());
 
         return HttpResult.ok(result.getMsg());
     }
@@ -1022,7 +1064,6 @@ public class KwfDriverService {
         driver.setAuthStatus(Global.NUMERICAL_ONE);
         driverDao.updateById(driver);
     }
-
     /**
      * 校验list中对象key值是否存在与value不一致的情况
      * @param list 数据集
@@ -1040,4 +1081,39 @@ public class KwfDriverService {
         }
         return false;
     }
+
+    /**
+     * @param params 参数
+     * @desc 修改司机
+     * @author zk
+     * @date 2023/7/6
+     **/
+    public HttpResult bindTruck(KwfBindTruckDto params) {
+        /**数据校验**/
+        if (params.getId() == null) {
+            return HttpResult.error(HttpStatus.PARAMETERS_PATTERN_ERROR_CODE,"司机主键id不能为空!");
+        }
+        if (StringUtils.isBlank(params.getTruckId())) {
+            return HttpResult.ok("未选择需要绑定的车辆!");
+        }
+        //查询是否存在已有车辆司机关系数据
+        KwfTruckReport truckReport = truckReportRepository.getOne(Wrappers.<KwfTruckReport>lambdaQuery()
+                .eq(KwfTruckReport::getEntId, LoginUserHolder.getEntId())
+                .eq(KwfTruckReport::getDriverId, params.getId())
+                .eq(KwfTruckReport::getDelFlag, Global.NO));
+        if(truckReport == null) {
+            truckReport.setTruckId(params.getTruckId());
+            boolean saveResult = truckReportRepository.save(truckReport);
+            return saveResult ? HttpResult.ok("车辆绑定成功!") : HttpResult.error("车辆绑定失败!");
+        } else {
+            if (truckReport.getTruckId().equals(params.getTruckId())) {
+                return HttpResult.error("此车辆已与此司机绑定,请重选选择车辆");
+            }
+            truckReport.setTruckId(params.getTruckId());
+            boolean updateResult = truckReportRepository.updateById(truckReport);
+            return updateResult ? HttpResult.ok("车辆绑定成功!") : HttpResult.error("车辆绑定失败!");
+        }
+    }
+
+
 }

+ 24 - 14
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/service/KwfTruckService.java

@@ -10,7 +10,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.google.common.collect.Lists;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
 import com.sckw.core.common.enums.enums.FileEnum;
-import com.sckw.core.exception.BusinessException;
 import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.base.BaseModel;
 import com.sckw.core.model.constant.Global;
@@ -35,10 +34,7 @@ import com.sckw.fleet.model.dto.*;
 import com.sckw.fleet.model.request.CapacityStatusReq;
 import com.sckw.fleet.model.request.TruckInfoReq;
 import com.sckw.fleet.model.vo.*;
-import com.sckw.fleet.repository.KwfFleetRepository;
-import com.sckw.fleet.repository.KwfFleetTruckRepository;
-import com.sckw.fleet.repository.KwfTruckReportRepository;
-import com.sckw.fleet.repository.KwfTruckRepository;
+import com.sckw.fleet.repository.*;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.RemoteUserService;
 import com.sckw.system.api.model.dto.res.EntCacheResDto;
@@ -88,7 +84,7 @@ public class KwfTruckService {
     KwfTruckImportMapper kwfTruckImportDao;
     @Autowired
     KwfFleetTruckMapper fleetTruckDao;
-
+    private final KwfDriverRepository kwfDriverRepository;
     private final KwfTruckReportRepository kwfTruckReportRepository;
     private final KwfTruckRepository kwfTruckRepository;
     private final KwfFleetRepository kwfFleetRepository;
@@ -118,7 +114,7 @@ public class KwfTruckService {
      * @author zk
      * @date 2023/7/11
      **/
-    public KwfTruckDetailVo detail(Long truckId) {
+    public KwfTruckDetailVo detail(Long truckId, Long entId) {
         //车辆信息
         KwfTruck truck = this.selectByKey(truckId);
         KwfTruckDetailVo truckDetailVo = new KwfTruckDetailVo();
@@ -153,6 +149,11 @@ public class KwfTruckService {
             truckDetailVo.setFleetId(fleet != null ? fleet.getId() : null);
             truckDetailVo.setFleetName(fleet != null ? fleet.getName() : null);
             truckDetailVo.setColorName(color != null ? color.getLabel() : null);
+
+            //关联司机
+            KwfDriver driver = getDriverInfo(truckId, entId);
+            truckDetailVo.setDriverName(driver.getName());
+
             return truckDetailVo;
         }
         return null;
@@ -306,28 +307,37 @@ public class KwfTruckService {
             truck.setEnergyTypeName(energyType != null ? energyType.getLabel() : null);
 
             //查询司机信息
-            KwfTruckReport truckReport = getKwfTruckReport(truck, ents);
-            truck.setDriverName(truckReport.getRemark());
+            KwfDriver driver = getDriverInfo(Long.parseLong(truck.getId()), ent.getId());
+            truck.setDriverName(driver.getName());
         }
         return trucks;
     }
 
     /**
      * 根据企业id和车辆id查询司机信息
+     *
      * @param truck
      * @param ents
      * @return
      */
-    private KwfTruckReport getKwfTruckReport(KwfTruckVo truck, Map<Long, EntCacheResDto> ents) {
+    private KwfDriver getDriverInfo(Long truckId, Long entId) {
         //查询车辆关联司机信息
         KwfTruckReport truckReport = kwfTruckReportRepository.getOne(Wrappers.<KwfTruckReport>lambdaQuery()
                 .eq(BaseModel::getDelFlag, 0)
-                .eq(KwfTruckReport::getTruckId, truck.getId())
-                .eq(KwfTruckReport::getEntId, ents.get(Long.parseLong(truck.getEntId()))));
+                .eq(KwfTruckReport::getTruckId, truckId)
+                .eq(KwfTruckReport::getEntId, entId));
         if (truckReport == null) {
-            return new KwfTruckReport();
+            return new KwfDriver();
+        }
+        //查询司机信息
+        KwfDriver driver = kwfDriverRepository.getOne(Wrappers.<KwfDriver>lambdaQuery()
+                .eq(BaseModel::getDelFlag, 0)
+                .eq(KwfDriver::getId, truckReport.getDriverId())
+                .eq(KwfDriver::getEntId, entId));
+        if (driver == null) {
+            return new KwfDriver();
         }
-        return truckReport;
+        return driver;
     }
 
     /**