Browse Source

车辆管理

donglang 2 months ago
parent
commit
4313c4d9e0

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

@@ -19,6 +19,10 @@ import com.sckw.fleet.model.dto.GpsByTruckNoDto;
 import com.sckw.fleet.model.dto.KwfTransportLicenseDto;
 import com.sckw.fleet.model.dto.KwfTransportLicenseDto;
 import com.sckw.fleet.model.dto.KwfTruckDto;
 import com.sckw.fleet.model.dto.KwfTruckDto;
 import com.sckw.fleet.model.dto.KwfTruckLicenseDto;
 import com.sckw.fleet.model.dto.KwfTruckLicenseDto;
+import com.sckw.fleet.model.reponse.TruckBlacklistParam;
+import com.sckw.fleet.model.reponse.TruckQueryParam;
+import com.sckw.fleet.model.reponse.TruckResp;
+import com.sckw.fleet.model.reponse.TruckUpdateStatusParam;
 import com.sckw.fleet.model.request.*;
 import com.sckw.fleet.model.request.*;
 import com.sckw.fleet.model.vo.*;
 import com.sckw.fleet.model.vo.*;
 import com.sckw.fleet.service.KwfTruckService;
 import com.sckw.fleet.service.KwfTruckService;
@@ -380,4 +384,43 @@ public class KwfTruckController {
     }
     }
 
 
 
 
+    /**
+     * 分页查询车辆列表
+     *
+     * @param param
+     * @return
+     */
+    @Operation(summary = "分页查询车辆列表", description = "分页查询车辆列表")
+    @PostMapping("/selectTruck")
+    public BaseResult<PageDataResult<TruckResp>> pageQueryTruck(@RequestBody @Valid TruckQueryParam param){
+        PageDataResult<TruckResp> truckRespList = truckService.pageQueryTruck(param);
+        return BaseResult.success(truckRespList);
+    }
+
+
+    /**
+     *
+     * 批量启用/停用
+     * @param param
+     * @return
+     */
+    @PostMapping("/batchUpdateStatus")
+    public BaseResult batchUpdateStatus(@RequestBody @Valid TruckUpdateStatusParam param) {
+        truckService.batchUpdateStatus(param);
+        return BaseResult.success();
+    }
+
+    /**
+     *
+     * 批量启用/停用
+     * @param param
+     * @return
+     */
+    @PostMapping("/toggleBlacklist")
+    public BaseResult toggleBlacklist(@RequestBody @Valid TruckBlacklistParam param) {
+        truckService.toggleBlacklist(param);
+        return BaseResult.success();
+    }
+
+
 }
 }

+ 54 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/enums/TruckStatusEnum.java

@@ -0,0 +1,54 @@
+package com.sckw.fleet.model.enums;
+
+import lombok.Getter;
+
+/**
+ * @author zk
+ * @desc 车辆状态
+ * @date 2024/3/8 0008
+ */
+@Getter
+public enum TruckStatusEnum {
+    /**
+     * 正常
+     */
+    NORMAL(0, "正常"),
+
+    /**
+     * 停用
+     */
+    DISABLED(1, "停用"),
+
+    /**
+     * 待审核
+     */
+    PENDING_REVIEW(2, "待审核"),
+
+    /**
+     * 审核驳回
+     */
+    REVIEW_REJECTED(3, "审核驳回"),
+
+    /**
+     * 黑名单
+     */
+    BLACKLIST(4, "黑名单");
+
+
+    private final Integer code;
+    private final String name;
+
+    TruckStatusEnum(Integer code, String name) {
+        this.code = code;
+        this.name = name;
+    }
+
+    public static String getName(Integer code) {
+        for (TruckStatusEnum entity : TruckStatusEnum.values()) {
+            if (entity.getCode().equals(code)) {
+                return entity.getName();
+            }
+        }
+        return null;
+    }
+}

+ 30 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/reponse/TruckBlacklistParam.java

@@ -0,0 +1,30 @@
+package com.sckw.fleet.model.reponse;
+
+import com.sckw.core.web.request.PageReq;
+import com.sckw.excel.annotation.ExcelContext;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * @author zk
+ * @desc 车辆信息
+ * @date 2023/7/11 0011
+ */
+@Data
+@ExcelContext(fileName = "车辆黑名单那模型", sheetName = "车辆黑名单那模型")
+public class TruckBlacklistParam extends PageReq implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -1021090755043784996L;
+
+    @Schema(description = "车辆ID列表")
+    private Long id;
+
+
+    @Schema(description = "目标状态: 0-正常、4-黑名单")
+    private Integer status;
+
+}

+ 66 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/reponse/TruckQueryParam.java

@@ -0,0 +1,66 @@
+package com.sckw.fleet.model.reponse;
+
+import com.sckw.core.web.request.PageReq;
+import com.sckw.excel.annotation.ExcelContext;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * @author zk
+ * @desc 车辆信息
+ * @date 2023/7/11 0011
+ */
+@Data
+@ExcelContext(fileName = "车辆信息查询模型", sheetName = "车辆信息查询模型")
+public class TruckQueryParam extends PageReq implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -1021090755043784996L;
+
+    /**
+     * 车牌号
+     */
+    @Schema(description = "车牌号")
+    private String truckNo;
+
+    /**
+     * 车辆类型(牵引车、货车)
+     */
+    @Schema(description = "车辆类型(牵引车、货车)")
+    private Integer type;
+
+
+    /**
+     * 轴数(1-二轴、2-三轴、3-四轴、5-六轴)
+     */
+    @Schema(description = "轴数(1-二轴、2-三轴、3-四轴、5-六轴)")
+    private String carAxis;
+
+    /**
+     * 能源类型(1-传统能源车辆、2-新能源车辆)
+     */
+    @Schema(description = "能源类型(1-传统能源车辆、2-新能源车辆)")
+    private int energyTyp;
+
+    /**
+     * 排放标准(1-国四、2-国五、3-国六)
+     */
+    @Schema(description = "排放标准(1-国四、2-国五、3-国六)")
+    private int eev;
+
+    /**
+     * 状态(0-正常、1-停用、2-待审核、3-审核驳回、4-黑名单)
+     */
+    @Schema(description = "状态(0-正常、1-停用、2-待审核、3-审核驳回、4-黑名单)")
+    private int status;
+
+    /**
+     * 关联司机
+     */
+    @Schema(description = "关联司机")
+    private String driverName;
+
+}

+ 94 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/reponse/TruckResp.java

@@ -0,0 +1,94 @@
+package com.sckw.fleet.model.reponse;
+
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.sckw.excel.annotation.ExcelContext;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author zk
+ * @desc 车辆信息
+ * @date 2023/7/11 0011
+ */
+@Data
+@ExcelContext(fileName = "车辆信息", sheetName = "车辆信息")
+public class TruckResp implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1964578088223686164L;
+
+    /**
+     * 车辆主键id
+     */
+    @Schema(description = "车辆主键id")
+    private Long id;
+
+    /**
+     * 车牌号
+     */
+    @Schema(description = "车牌号")
+    private String truckNo;
+
+    /**
+     * 车辆类别(牵引车、货车)
+     */
+    @Schema(description = "车辆类别(牵引车、货车)")
+    private Integer type;
+
+    /**
+     * 车辆类别描述
+     */
+    @Schema(description = "车辆类别描述")
+    private String typeDesc;
+
+    /**
+     * 轴数(1-二轴、2-三轴、3-四轴、5-六轴)
+     */
+    @Schema(description = "轴数(1-二轴、2-三轴、3-四轴、5-六轴)")
+    private String carAxis;
+
+    /**
+     * 轴数名称
+     */
+    @Schema(description = "轴数名称")
+    private String carAxisName;
+
+    /**
+     * 品牌
+     */
+    @Schema(description = "品牌")
+    private String brand;
+
+    /**
+     * 状态(0-正常、1-停用、2-待审核、3-审核驳回、4-黑名单)
+     */
+    @Schema(description = "状态(0-正常、1-停用、2-待审核、3-审核驳回、4-黑名单)")
+    private int status;
+
+    /**
+     * 状态描述
+     */
+    @Schema(description = "状态描述")
+    private String statusDesc;
+
+    /**
+     * 关联司机
+     */
+    @Schema(description = "关联司机")
+    private String driverName;
+
+    /**
+     * 创建时间
+     */
+    @Schema(description = "创建时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createTime;
+
+}

+ 31 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/model/reponse/TruckUpdateStatusParam.java

@@ -0,0 +1,31 @@
+package com.sckw.fleet.model.reponse;
+
+import com.sckw.core.web.request.PageReq;
+import com.sckw.excel.annotation.ExcelContext;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author zk
+ * @desc 车辆信息
+ * @date 2023/7/11 0011
+ */
+@Data
+@ExcelContext(fileName = "车辆状态修改模型", sheetName = "车辆状态修改模型")
+public class TruckUpdateStatusParam extends PageReq implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -1021090755043784996L;
+
+    @Schema(description = "车辆ID列表")
+    private List<Long> ids;
+
+
+    @Schema(description = "目标状态: 0-正常、1-停用")
+    private Integer status;
+
+}

+ 161 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/service/KwfTruckService.java

@@ -6,17 +6,23 @@ import com.alibaba.excel.read.metadata.ReadSheet;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Maps;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
+import com.sckw.core.common.enums.enums.ErrorCodeEnum;
 import com.sckw.core.common.enums.enums.FileEnum;
 import com.sckw.core.common.enums.enums.FileEnum;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.exception.BusinessException;
+import com.sckw.core.exception.BusinessPlatfromException;
 import com.sckw.core.exception.SystemException;
 import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.base.BaseModel;
 import com.sckw.core.model.base.BaseModel;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.enums.EntTypeEnum;
 import com.sckw.core.model.enums.EntTypeEnum;
+import com.sckw.core.model.enums.ForkliftStatusEnum;
 import com.sckw.core.model.enums.SystemTypeEnum;
 import com.sckw.core.model.enums.SystemTypeEnum;
 import com.sckw.core.model.file.FileInfo;
 import com.sckw.core.model.file.FileInfo;
 import com.sckw.core.utils.*;
 import com.sckw.core.utils.*;
@@ -25,6 +31,7 @@ import com.sckw.core.web.context.LoginEntHolder;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.request.HttpClientUtil;
 import com.sckw.core.web.request.HttpClientUtil;
 import com.sckw.core.web.response.BaseIotResult;
 import com.sckw.core.web.response.BaseIotResult;
+import com.sckw.core.web.response.BaseResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.result.PageDataResult;
 import com.sckw.core.web.response.result.PageDataResult;
 import com.sckw.excel.easyexcel.ExcelImportListener;
 import com.sckw.excel.easyexcel.ExcelImportListener;
@@ -33,6 +40,11 @@ import com.sckw.fleet.config.UrlConfigProperties;
 import com.sckw.fleet.dao.*;
 import com.sckw.fleet.dao.*;
 import com.sckw.fleet.model.*;
 import com.sckw.fleet.model.*;
 import com.sckw.fleet.model.dto.*;
 import com.sckw.fleet.model.dto.*;
+import com.sckw.fleet.model.enums.TruckStatusEnum;
+import com.sckw.fleet.model.reponse.TruckBlacklistParam;
+import com.sckw.fleet.model.reponse.TruckQueryParam;
+import com.sckw.fleet.model.reponse.TruckResp;
+import com.sckw.fleet.model.reponse.TruckUpdateStatusParam;
 import com.sckw.fleet.model.request.BatchTruckValidateReq;
 import com.sckw.fleet.model.request.BatchTruckValidateReq;
 import com.sckw.fleet.model.request.CapacityStatusReq;
 import com.sckw.fleet.model.request.CapacityStatusReq;
 import com.sckw.fleet.model.request.TruckInfoReq;
 import com.sckw.fleet.model.request.TruckInfoReq;
@@ -2026,4 +2038,153 @@ public class KwfTruckService {
 
 
         return builder.build();
         return builder.build();
     }
     }
+
+
+    /**
+     * 分页查询铲车订单
+     * @param param
+     * @return
+     */
+    public PageDataResult<TruckResp> pageQueryTruck(TruckQueryParam param) {
+        log.info("查询司机信息列表:{}", JSON.toJSONString(param));
+        List<Long> validTruckIds = new ArrayList<>();
+        if (StringUtils.isNotBlank(param.getDriverName())) {
+            //1.1 先根据司机名字模糊查询司机ID
+            List<KwfDriver> drivers = kwfDriverRepository.list(Wrappers.<KwfDriver>lambdaQuery()
+                            .like(KwfDriver::getName, param.getDriverName())
+                            .eq(BaseModel::getDelFlag, 0)
+            );
+
+            if (CollectionUtils.isNotEmpty(drivers)) {
+                List<Long> driverIds = drivers.stream().map(KwfDriver::getId).collect(Collectors.toList());
+                // 1.2 拿着司机ID去关联表(kwf_truck_report)查车辆ID
+                List<KwfTruckReport> reports = kwfTruckReportRepository.list(
+                        Wrappers.<KwfTruckReport>lambdaQuery()
+                                .in(KwfTruckReport::getDriverId, driverIds)
+                                .eq(KwfTruckReport::getEntId, LoginUserHolder.getEntId())
+                                .eq(BaseModel::getDelFlag, 0)
+                );
+                if (CollectionUtils.isNotEmpty(reports)) {
+                    //1.3 提取出车辆ID列表
+                    validTruckIds = reports.stream()
+                            .map(KwfTruckReport::getTruckId)
+                            .distinct() // 去重
+                            .collect(Collectors.toList());
+                } else {
+                    return PageDataResult.empty(param.getPageNum(), param.getPageSize());
+                }
+
+            } else {
+                return PageDataResult.empty(param.getPageNum(), param.getPageSize());
+            }
+        }
+
+        LambdaQueryWrapper<KwfTruck> wrapper = Wrappers.<KwfTruck>lambdaQuery()
+                .like(StringUtils.isNotBlank(param.getTruckNo()), KwfTruck::getTruckNo, param.getTruckNo())
+                .eq(KwfTruck::getType, param.getType())
+                .eq(KwfTruck::getCarAxis, param.getCarAxis())
+                .eq(KwfTruck::getEnergyType, param.getEnergyTyp())
+                .eq(KwfTruck::getEev, param.getEev())
+                .eq(KwfTruck::getStatus, param.getStatus());
+        // 查询该你了司机
+        if (CollectionUtils.isNotEmpty(validTruckIds)) {
+            wrapper.in(KwfTruck::getId, validTruckIds);
+        }
+        wrapper.orderByDesc(KwfTruck::getCreateTime)
+                .orderByDesc(KwfTruck::getId);
+
+        //查询铲车订单
+        Page<KwfTruck> pageByStatus = kwfTruckRepository.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
+        List<KwfTruck> records = pageByStatus.getRecords();
+        if (CollectionUtils.isEmpty(records)) {
+            log.info("无车辆信息,param:{}", param);
+            return PageDataResult.empty(param.getPageNum(), param.getPageSize());
+        }
+        List<TruckResp> truckPageResult = getTruckResp(records);
+        return PageDataResult.success(param.getPageNum(), param.getPageSize(), pageByStatus.getTotal(), truckPageResult);
+    }
+
+    /**
+     *
+     * @param records
+     * @return
+     */
+    public List<TruckResp> getTruckResp(List<KwfTruck> trucks) {
+        List<TruckResp> truckResps = new ArrayList<>();
+        Map<String, Map<String, String>> dict = remoteSystemService.queryDictByType(List.of(DictTypeEnum.TRUCK_TYPE.getType()));
+        Map<String, String> truckTypeMap = new HashMap<>(Global.NUMERICAL_SIXTEEN);
+        if (CollectionUtils.isNotEmpty(dict)) {
+            truckTypeMap = dict.get(DictTypeEnum.TRUCK_TYPE.getType());
+        }
+        for (KwfTruck truck : trucks) {
+            TruckResp truckResp = new TruckResp();
+            truckResp.setId(truck.getId());
+            truckResp.setTruckNo(truck.getTruckNo());
+            truckResp.setType(truck.getType());
+            truckResp.setTypeDesc(CollectionUtils.isNotEmpty(truckTypeMap) ? truckTypeMap.get(String.valueOf(truck.getType())) : null);
+            truckResp.setBrand(truck.getBrand());
+            truckResp.setStatus(truck.getStatus());
+            truckResp.setStatusDesc(TruckStatusEnum.getName(truck.getStatus()));
+            truckResp.setCreateTime(truck.getCreateTime());
+
+            //查询车辆轴数
+            TmsTruckAxleNum axleNum = getCarAxisInfo(truck.getCarAxis());
+            truckResp.setCarAxis(truck.getCarAxis());
+            truckResp.setCarAxisName(axleNum.getName());
+
+            //查询司机信息
+            KwfDriver driver = getDriverInfo(truck.getId(), LoginUserHolder.getEntId());
+            truckResp.setDriverName(driver.getName());
+
+            truckResps.add(truckResp);
+        }
+        return truckResps;
+    }
+
+    /**
+     * 分页查询铲车订单
+     * @param param
+     * @return
+     */
+    public void batchUpdateStatus(TruckUpdateStatusParam param) {
+        log.info("车辆停用/启用,param:{}", JSON.toJSONString(param));
+        // 1. 校验状态合法性
+        if (param.getStatus() != 0 && param.getStatus() != 1) {
+            throw new BusinessPlatfromException(ErrorCodeEnum.TRUCK_STATUS_ERROR, "仅支持修改为正常(0)或停用(1)状态");
+        }
+        if (param.getStatus() == null) {
+            throw new BusinessPlatfromException(ErrorCodeEnum.TRUCK_STATUS_ERROR, "状态参数不能为空");
+        }
+
+        LambdaUpdateWrapper<KwfTruck> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.in(KwfTruck::getId, param.getIds());
+        updateWrapper.set(KwfTruck::getStatus, param.getStatus());
+        kwfTruckRepository.update(updateWrapper);
+
+    }
+
+    /**
+     * 黑名单
+     * @param param
+     * @return
+     */
+    public void toggleBlacklist(TruckBlacklistParam param) {
+        log.info("黑名单业务:{}", JSON.toJSONString(param));
+        if (param.getId() == null) {
+            throw new BusinessPlatfromException(ErrorCodeEnum.DRIVER_NOT_FOUND, "车辆不存在");
+        }
+        int targetStatus;
+        if (param.getStatus() == 4) {
+            // 如果当前已经是黑名单,则操作为“移出”,目标状态设为正常(0)
+            targetStatus = 0;
+        } else {
+            // 如果当前不是黑名单,则操作为“加入”,目标状态设为黑名单(4)
+            targetStatus = 4;
+        }
+        kwfTruckRepository.update(Wrappers.<KwfTruck>lambdaUpdate()
+                .eq(KwfTruck::getId, param.getId())
+                .set(KwfTruck::getStatus, targetStatus));
+    }
+
+
 }
 }