|
|
@@ -1,19 +1,33 @@
|
|
|
package com.sckw.fleet.service;
|
|
|
|
|
|
+import com.sckw.core.exception.SystemException;
|
|
|
+import com.sckw.core.model.constant.Global;
|
|
|
+import com.sckw.core.utils.BeanUtils;
|
|
|
+import com.sckw.core.utils.CollectionUtils;
|
|
|
+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.fleet.dao.KwfTransportLicenseMapper;
|
|
|
import com.sckw.fleet.dao.KwfTruckEntMapper;
|
|
|
import com.sckw.fleet.dao.KwfTruckLicenseMapper;
|
|
|
import com.sckw.fleet.dao.KwfTruckMapper;
|
|
|
-import com.sckw.fleet.model.KwfTruck;
|
|
|
+import com.sckw.fleet.model.*;
|
|
|
+import com.sckw.fleet.model.dto.*;
|
|
|
+import com.sckw.fleet.model.vo.KwfTableTopCount;
|
|
|
import com.sckw.fleet.model.vo.KwfTruckVo;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
+import com.sckw.system.api.model.dto.res.UserCacheResDto;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
-import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author zk
|
|
|
@@ -34,10 +48,8 @@ public class KwfTruckService {
|
|
|
@DubboReference(version = "2.0.0", group = "design", check = false)
|
|
|
private RemoteSystemService remoteSystemService;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
- * @param key 主键id
|
|
|
+ * @param key 逐渐id
|
|
|
* @desc 根据主键查询
|
|
|
* @author zk
|
|
|
* @date 2023/7/6
|
|
|
@@ -46,6 +58,33 @@ public class KwfTruckService {
|
|
|
return truckDao.selectById(key);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 统计
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/11
|
|
|
+ **/
|
|
|
+ public Map statistics(Map<String, Object> params) {
|
|
|
+ /**统计数据**/
|
|
|
+ List<KwfTableTopCount> counts = truckDao.statistics(params);
|
|
|
+ long tatol = 0;
|
|
|
+ for (KwfTableTopCount topCount:counts) {
|
|
|
+ tatol += topCount.getTotal();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**全部数据-处理**/
|
|
|
+ KwfTableTopCount allCount = new KwfTableTopCount();
|
|
|
+ allCount.setValue(String.valueOf(Global.NUMERICAL_ZERO));
|
|
|
+ allCount.setTotal(tatol);
|
|
|
+ counts.add(allCount);
|
|
|
+
|
|
|
+ /**数据组装**/
|
|
|
+ Map tableCount = new HashMap();
|
|
|
+ tableCount.put("tableTop", counts);
|
|
|
+ tableCount.put("tableBottom", tatol);
|
|
|
+ return tableCount;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param params 分页参数
|
|
|
* @desc 分页查询
|
|
|
@@ -53,38 +92,329 @@ public class KwfTruckService {
|
|
|
* @date 2023/7/6
|
|
|
**/
|
|
|
public List<KwfTruckVo> findPage(Map<String, Object> params) {
|
|
|
- return truckDao.selectPage(null, null);
|
|
|
+ /**查询分页数据**/
|
|
|
+ List<KwfTruckVo> trucks = truckDao.findPage(params);
|
|
|
+ if (CollectionUtils.isEmpty(trucks)) {
|
|
|
+ return trucks;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**获取查询数据**/
|
|
|
+ List<Long> createBys = new ArrayList<>();
|
|
|
+ List<Long> entIds = new ArrayList<>();
|
|
|
+ for (KwfTruckVo truck:trucks) {
|
|
|
+ createBys.add(Long.parseLong(truck.getCreateBy()));
|
|
|
+ entIds.add(Long.parseLong(truck.getEntId()));
|
|
|
+ }
|
|
|
+ //用户数据集
|
|
|
+ createBys = createBys.stream().distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, UserCacheResDto> users = remoteSystemService.queryUserCacheMapByIds(createBys);
|
|
|
+ //企业数据集
|
|
|
+ entIds = entIds.stream().distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, EntCacheResDto> ents = remoteSystemService.queryEntCacheMapByIds(entIds);
|
|
|
+
|
|
|
+ /**数据组装**/
|
|
|
+ for (KwfTruckVo truck:trucks) {
|
|
|
+ UserCacheResDto user = users == null ? null : users.get(Long.parseLong(truck.getCreateBy()));
|
|
|
+ EntCacheResDto ent = ents == null ? null : ents.get(Long.parseLong(truck.getEntId()));
|
|
|
+ truck.setCreateByName(user != null ? user.getName() : null);
|
|
|
+ truck.setFirmName(ent != null ? ent.getFirmName() : null);
|
|
|
+ }
|
|
|
+ return trucks;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param params 分页参数
|
|
|
+ * @param params 查询参数
|
|
|
* @desc 查询
|
|
|
* @author zk
|
|
|
* @date 2023/7/6
|
|
|
**/
|
|
|
- public List<KwfTruckVo> findList(Map<String, Object> params) {
|
|
|
- return truckDao.selectPage(null, null);
|
|
|
+ public List<Map<String, Object>> findList(Map<String, Object> params) {
|
|
|
+ return truckDao.findList(params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param params 分页参数
|
|
|
- * @desc 新增司机
|
|
|
+ * @param {}
|
|
|
+ * @description 导出
|
|
|
* @author zk
|
|
|
- * @date 2023/7/6
|
|
|
+ * @date 2023/07/11
|
|
|
**/
|
|
|
- public HttpResult add(KwfTruck params) {
|
|
|
- truckDao.insert(params);
|
|
|
+ public HttpResult importExcel(MultipartFile file) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param params 分页参数
|
|
|
- * @desc 修改司机
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 新增车辆
|
|
|
* @author zk
|
|
|
* @date 2023/7/6
|
|
|
**/
|
|
|
- public HttpResult update(KwfTruck params) {
|
|
|
- truckDao.updateById(params);
|
|
|
- return null;
|
|
|
+ public HttpResult add(KwfTruckDto params) {
|
|
|
+ /**车辆信息**/
|
|
|
+ KwfTruck truck = new KwfTruck();
|
|
|
+ BeanUtils.copyProperties(params, truck);
|
|
|
+ //证件都有数据则为已认证(前端校验认证数据必填)
|
|
|
+ boolean bool = checkLicense(params);
|
|
|
+ if (bool) {
|
|
|
+ truck.setStatus(Global.NUMERICAL_ONE);
|
|
|
+ } else {
|
|
|
+ truck.setStatus(Global.NUMERICAL_TWO);
|
|
|
+ }
|
|
|
+ HttpResult result = truckEdit(truck);
|
|
|
+ if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**车辆行驶证信息**/
|
|
|
+ KwfTruckLicenseDto truckLicenseDto = params.getTruckLicense();
|
|
|
+ if (truckLicenseDto != null) {
|
|
|
+ truckLicenseDto.setTruckId(truck.getId());
|
|
|
+ truckLicenseEdit(truckLicenseDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**车辆行驶证信息**/
|
|
|
+ KwfTransportLicenseDto transportLicenseDto = params.getTransportLicense();
|
|
|
+ if (transportLicenseDto != null) {
|
|
|
+ truckLicenseDto.setTruckId(truck.getId());
|
|
|
+ transportLicenseEdit(transportLicenseDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**车辆信息与企业关联信息**/
|
|
|
+ truckEntEdit(truck);
|
|
|
+ return HttpResult.ok("车辆信息新增成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 修改车辆
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/6
|
|
|
+ **/
|
|
|
+ public HttpResult update(KwfTruckDto params) {
|
|
|
+ /**数据校验**/
|
|
|
+ if (StringUtils.isBlank(params.getId())) {
|
|
|
+ return HttpResult.error(HttpStatus.PARAMETERS_PATTERN_ERROR_CODE,"车辆信息ID不能为空!");
|
|
|
+ }
|
|
|
+ KwfTruck truck = truckDao.selectById(params.getId());
|
|
|
+ if (truck == null) {
|
|
|
+ return HttpResult.error("车辆信息不存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**车辆信息**/
|
|
|
+ BeanUtils.copyProperties(params, truck);
|
|
|
+ //证件都有数据则为已认证(前端校验认证数据必填)
|
|
|
+ boolean bool = checkLicense(params);
|
|
|
+ if (bool) {
|
|
|
+ truck.setStatus(Global.NUMERICAL_ONE);
|
|
|
+ }
|
|
|
+ HttpResult result = truckEdit(truck);
|
|
|
+ if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**车辆行驶证信息**/
|
|
|
+ KwfTruckLicenseDto truckLicenseDto = params.getTruckLicense();
|
|
|
+ if (truckLicenseDto != null) {
|
|
|
+ truckLicenseDto.setTruckId(truck.getId());
|
|
|
+ truckLicenseEdit(truckLicenseDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**车辆行驶证信息**/
|
|
|
+ KwfTransportLicenseDto transportLicenseDto = params.getTransportLicense();
|
|
|
+ if (transportLicenseDto != null) {
|
|
|
+ truckLicenseDto.setTruckId(truck.getId());
|
|
|
+ transportLicenseEdit(transportLicenseDto);
|
|
|
+ }
|
|
|
+ return HttpResult.ok("车辆信息修改成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param {ids:主键ID(多个以逗号隔开)}
|
|
|
+ * @description 删除
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/6
|
|
|
+ **/
|
|
|
+ public HttpResult del(String ids) {
|
|
|
+ /**数据校验**/
|
|
|
+ if (StringUtils.isBlank(ids)) {
|
|
|
+ return HttpResult.error("请选择要删除的数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**数据组装**/
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
+ KwfTruckEnt truckEntQuery = new KwfTruckEnt();
|
|
|
+ truckEntQuery.setEntId(LoginUserHolder.getEntId());
|
|
|
+ for (String id : idArray) {
|
|
|
+ truckEntQuery.setTruckId(Long.parseLong(id));
|
|
|
+ KwfTruckEnt truckEnt = truckEntDao.findByTruckEnt(truckEntQuery);
|
|
|
+ if (truckEnt != null) {
|
|
|
+ truckEnt.setDelFlag(Global.YES);
|
|
|
+ if (truckEntDao.updateById(truckEnt) <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.DELETE_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return HttpResult.ok("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 更新车辆信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public HttpResult truckEdit(KwfTruck params) {
|
|
|
+ if (StringUtils.isBlank(params.getId())) {
|
|
|
+ /**唯一性交易**/
|
|
|
+ List<Map<String, Object>> drivers = truckDao.findList(new HashMap(){{ put("truckNo", params.getTruckNo()); }});
|
|
|
+ if (!CollectionUtils.isEmpty(drivers)) {
|
|
|
+ return HttpResult.error("车牌号已存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**新增**/
|
|
|
+ params.setEntId(LoginUserHolder.getEntId());
|
|
|
+ params.setEntId(params.getEntId() == null ? 1 : params.getEntId());// 暂时处理---------------zk
|
|
|
+ int count = truckDao.insert(params);
|
|
|
+ return count > 0 ? HttpResult.ok() : HttpResult.error("车辆信息新增失败!");
|
|
|
+ } else {
|
|
|
+ /**唯一性交易**/
|
|
|
+ List<Map<String, Object>> drivers = truckDao.findList(new HashMap(){{ put("truckNo", params.getTruckNo()); }});
|
|
|
+ //校验list中对象key值是否存在与value不一致的情况
|
|
|
+ boolean bool = CollectionUtils.listByKeyValueV1(drivers, "id", String.valueOf(params.getId()));
|
|
|
+ if (bool) {
|
|
|
+ return HttpResult.error("车辆信息已存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**更新**/
|
|
|
+ int count = truckDao.updateById(params);
|
|
|
+ return count > 0 ? HttpResult.ok() : HttpResult.error("车辆信息修改失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 更新车辆行驶证信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public HttpResult truckLicenseEdit(KwfTruckLicenseDto params) {
|
|
|
+ /**数据copy**/
|
|
|
+ KwfTruckLicense truckLicense = new KwfTruckLicense();
|
|
|
+ BeanUtils.copyProperties(params, truckLicense);
|
|
|
+
|
|
|
+ /**数据更新**/
|
|
|
+ int count = 0;
|
|
|
+ KwfTruckLicense license = truckLicenseDao.findByTruckId(params.getTruckId());
|
|
|
+ if (license == null) {
|
|
|
+ count = truckLicenseDao.insert(truckLicense);
|
|
|
+ } else {
|
|
|
+ truckLicense.setId(license.getId());
|
|
|
+ count = truckLicenseDao.updateById(truckLicense);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**校验车辆是否有证书并更新状态**/
|
|
|
+ checkLicense(truckLicense.getId());
|
|
|
+ return count > 0 ? HttpResult.ok("车辆行驶证信息修改成功!") : HttpResult.error("车辆行驶证信息修改失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param key 参数
|
|
|
+ * @desc 查询车辆行驶证信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public KwfTruckLicense findTruckLicenseByKey(Long key) {
|
|
|
+ return truckLicenseDao.findByTruckId(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 更新车辆道路运输许可证
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public HttpResult transportLicenseEdit(KwfTransportLicenseDto params) {
|
|
|
+ /**数据copy**/
|
|
|
+ KwfTransportLicense transportLicense = new KwfTransportLicense();
|
|
|
+ BeanUtils.copyProperties(params, transportLicense);
|
|
|
+
|
|
|
+ /**数据更新**/
|
|
|
+ int count = 0;
|
|
|
+ KwfTransportLicense license = transportLicenseDao.findByTruckId(params.getTruckId());
|
|
|
+ if (license == null) {
|
|
|
+ count = transportLicenseDao.insert(transportLicense);
|
|
|
+ return count > 0 ? HttpResult.ok("车辆驾驶证信息更新成功!") : HttpResult.error("车辆驾驶证信息更新失败!");
|
|
|
+ } else {
|
|
|
+ transportLicense.setId(license.getId());
|
|
|
+ count = transportLicenseDao.updateById(transportLicense);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**校验车辆是否有证书并更新状态**/
|
|
|
+ checkLicense(transportLicense.getTruckId());
|
|
|
+ return count > 0 ? HttpResult.ok("车辆驾驶证信息修改成功!") : HttpResult.error("车辆驾驶证信息修改失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param key 参数
|
|
|
+ * @desc 查询车辆道路运输许可证
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public KwfTransportLicense findTransportLicenseByKey(Long key) {
|
|
|
+ return transportLicenseDao.findByTruckId(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 新增车辆信息与企业关联信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public void truckEntEdit(KwfTruck params) {
|
|
|
+ KwfTruckEnt truckEnt = new KwfTruckEnt();
|
|
|
+ truckEnt.setTruckId(params.getId());
|
|
|
+ truckEnt.setEntId(params.getEntId());
|
|
|
+ truckEntDao.insert(truckEnt);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 校验车辆是否有证书
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/11
|
|
|
+ **/
|
|
|
+ public boolean checkLicense(KwfTruckDto params) {
|
|
|
+ //车辆行驶证信息
|
|
|
+ if (params.getTruckLicense() == null || StringUtils.isBlank(params.getTruckLicense().getDrivingNo())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //车辆道路运输许可证
|
|
|
+ if (params.getTransportLicense() == null || StringUtils.isBlank(params.getTransportLicense().getRoadTranNo())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param truckId 车辆主键id
|
|
|
+ * @desc 校验车辆是否有证书并更新状态
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/11
|
|
|
+ **/
|
|
|
+ public void checkLicense(Long truckId) {
|
|
|
+ //车辆行驶证信息
|
|
|
+ KwfTruckLicense license = this.findTruckLicenseByKey(truckId);
|
|
|
+ if (license == null || StringUtils.isBlank(license.getDrivingNo())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //车辆道路运输许可证
|
|
|
+ KwfTransportLicense transportLicense = this.findTransportLicenseByKey(truckId);
|
|
|
+ if (transportLicense == null || StringUtils.isBlank(transportLicense.getRoadTranNo())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //更新数据
|
|
|
+ KwfTruck truck = new KwfTruck();
|
|
|
+ truck.setId(truckId);
|
|
|
+ truck.setStatus(Global.NUMERICAL_ONE);
|
|
|
+ truckDao.updateById(truck);
|
|
|
}
|
|
|
}
|