|
|
@@ -1,10 +1,25 @@
|
|
|
package com.sckw.fleet.service;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+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.PasswordUtils;
|
|
|
+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.KwfDriverMapper;
|
|
|
-import com.sckw.fleet.model.KwfDriver;
|
|
|
+import com.sckw.fleet.dao.*;
|
|
|
+import com.sckw.fleet.model.*;
|
|
|
+import com.sckw.fleet.model.dto.KwfDriverCardDto;
|
|
|
+import com.sckw.fleet.model.dto.KwfDriverDto;
|
|
|
+import com.sckw.fleet.model.dto.KwfDriverLicenseDto;
|
|
|
+import com.sckw.fleet.model.dto.KwfDriverQualificationDto;
|
|
|
+import com.sckw.fleet.model.vo.KwfDriverVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -18,6 +33,14 @@ public class KwfDriverService {
|
|
|
|
|
|
@Autowired
|
|
|
KwfDriverMapper driverDao;
|
|
|
+ @Autowired
|
|
|
+ KwfDriverEntMapper driverEntDao;
|
|
|
+ @Autowired
|
|
|
+ KwfDriverCardMapper KwfDriverCardDao;
|
|
|
+ @Autowired
|
|
|
+ KwfDriverLicenseMapper KwfDriverLicenseDao;
|
|
|
+ @Autowired
|
|
|
+ KwfDriverQualificationMapper KwfDriverQualificationDao;
|
|
|
|
|
|
/**
|
|
|
* @param key 逐渐id
|
|
|
@@ -35,8 +58,8 @@ public class KwfDriverService {
|
|
|
* @author zk
|
|
|
* @date 2023/7/6
|
|
|
**/
|
|
|
- public List<KwfDriver> findPage(Map<String, Object> params) {
|
|
|
- return driverDao.selectPage(null, null);
|
|
|
+ public List<KwfDriverVo> findPage(Map<String, Object> params) {
|
|
|
+ return driverDao.findPage(params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -50,24 +73,249 @@ public class KwfDriverService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param params 分页参数
|
|
|
+ * @param params 参数
|
|
|
* @desc 新增司机
|
|
|
* @author zk
|
|
|
* @date 2023/7/6
|
|
|
**/
|
|
|
- public HttpResult add(KwfDriver params) {
|
|
|
- driverDao.insert(params);
|
|
|
- return null;
|
|
|
+ public HttpResult add(KwfDriverDto params) {
|
|
|
+ /**司机信息**/
|
|
|
+ KwfDriver driver = new KwfDriver();
|
|
|
+ BeanUtils.copyProperties(params, driver);
|
|
|
+ HttpResult result = driverEdit(driver);
|
|
|
+ if (result != null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**身份证信息**/
|
|
|
+ params.getDriverCard().setDriverId(params.getId());
|
|
|
+ driverCardEdit(params.getDriverCard());
|
|
|
+
|
|
|
+ /**司机驾驶证信息**/
|
|
|
+ params.getDriverLicense().setDriverId(params.getId());
|
|
|
+ driverLicenseEdit(params.getDriverLicense());
|
|
|
+
|
|
|
+ /**司机从业资格证**/
|
|
|
+ params.getDriverQualification().setDriverId(params.getId());
|
|
|
+ driverQualificationEdit(params.getDriverQualification());
|
|
|
+
|
|
|
+ /**司机信息与企业关联信息**/
|
|
|
+ driverEntEdit(driver);
|
|
|
+ return HttpResult.ok("司机信息新增成功!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param params 分页参数
|
|
|
+ * @param params 参数
|
|
|
* @desc 修改司机
|
|
|
* @author zk
|
|
|
* @date 2023/7/6
|
|
|
**/
|
|
|
- public HttpResult update(KwfDriver params) {
|
|
|
- driverDao.updateById(params);
|
|
|
+ public HttpResult update(KwfDriverDto params) {
|
|
|
+ /**数据校验**/
|
|
|
+ if (StringUtils.isBlank(params.getId())) {
|
|
|
+ return HttpResult.error(HttpStatus.PARAMETERS_PATTERN_ERROR_CODE,"司机信息ID不能为空!");
|
|
|
+ }
|
|
|
+ KwfDriver driver = driverDao.selectById(params.getId());
|
|
|
+ if (driver == null) {
|
|
|
+ return HttpResult.error("司机信息不存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**司机信息**/
|
|
|
+ BeanUtils.copyProperties(params, driver);
|
|
|
+ HttpResult result = driverEdit(driver);
|
|
|
+ if (result != null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**身份证信息**/
|
|
|
+ params.getDriverCard().setDriverId(params.getId());
|
|
|
+ driverCardEdit(params.getDriverCard());
|
|
|
+
|
|
|
+ /**司机驾驶证信息**/
|
|
|
+ params.getDriverLicense().setDriverId(params.getId());
|
|
|
+ driverLicenseEdit(params.getDriverLicense());
|
|
|
+
|
|
|
+ /**司机从业资格证**/
|
|
|
+ params.getDriverQualification().setDriverId(params.getId());
|
|
|
+ driverQualificationEdit(params.getDriverQualification());
|
|
|
+ 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(",");
|
|
|
+ KwfDriver driverQuery = new KwfDriver();
|
|
|
+ driverQuery.setEntId(LoginUserHolder.getEntId());
|
|
|
+ for (String id : idArray) {
|
|
|
+ driverQuery.setId(Long.parseLong(id));
|
|
|
+ KwfDriver driver = driverDao.findEntDriver(driverQuery);
|
|
|
+ if (driver != null) {
|
|
|
+ driver.setDelFlag(Global.YES);
|
|
|
+ if (driverDao.updateById(driver) <= 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 driverEdit(KwfDriver params) {
|
|
|
+ if (StringUtils.isBlank(params.getId())) {
|
|
|
+ /**唯一性交易**/
|
|
|
+ List<Map<String, Object>> drivers = driverDao.findList(new HashMap(){{ put("phone", params.getPhone()); }});
|
|
|
+ if (!CollectionUtils.isEmpty(drivers)) {
|
|
|
+ return HttpResult.error("电话号码已存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**新增**/
|
|
|
+ String md5 = PasswordUtils.md5(params.getPhone());
|
|
|
+ String password = PasswordUtils.entryptPassword(md5);
|
|
|
+ params.setSalt(PasswordUtils.getSaltSubPwd(password));
|
|
|
+ params.setPassword(password);
|
|
|
+ params.setEntId(LoginUserHolder.getEntId());
|
|
|
+ int count = driverDao.insert(params);
|
|
|
+ return count > 0 ? null : HttpResult.error("司机信息新增失败!");
|
|
|
+ } else {
|
|
|
+ /**唯一性交易**/
|
|
|
+ List<Map<String, Object>> drivers = driverDao.findList(new HashMap(){{ put("phone", params.getPhone()); }});
|
|
|
+ //校验list中对象key值是否存在与value不一致的情况
|
|
|
+ boolean bool = CollectionUtils.listByKeyValueV1(drivers, "id", String.valueOf(params.getId()));
|
|
|
+ if (bool) {
|
|
|
+ return HttpResult.error("司机信息电话号码已存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**更新**/
|
|
|
+ int count = driverDao.updateById(params);
|
|
|
+ return count > 0 ? null : HttpResult.error("司机信息修改失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 新增身份证信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public HttpResult driverCardEdit(KwfDriverCardDto params) {
|
|
|
+ /**数据copy**/
|
|
|
+ KwfDriverCard driverCard = new KwfDriverCard();
|
|
|
+ BeanUtils.copyProperties(params, driverCard);
|
|
|
+
|
|
|
+ /**数据更新**/
|
|
|
+ KwfDriverCard card = KwfDriverCardDao.findByDriverId(params.getDriverId());
|
|
|
+ if (card == null) {
|
|
|
+ int count = KwfDriverCardDao.insert(driverCard);
|
|
|
+ } else {
|
|
|
+ driverCard.setId(card.getId());
|
|
|
+ int count = KwfDriverCardDao.updateById(driverCard);
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param key 参数
|
|
|
+ * @desc 查询身份证信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public KwfDriverCard findCarByKey(Long key) {
|
|
|
+ return KwfDriverCardDao.findByDriverId(String.valueOf(key));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 新增司机驾驶证信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public HttpResult driverLicenseEdit(KwfDriverLicenseDto params) {
|
|
|
+ /**数据copy**/
|
|
|
+ KwfDriverLicense driverLicense = new KwfDriverLicense();
|
|
|
+ BeanUtils.copyProperties(params, driverLicense);
|
|
|
+
|
|
|
+ /**数据更新**/
|
|
|
+ KwfDriverLicense license = KwfDriverLicenseDao.findByDriverId(params.getDriverId());
|
|
|
+ if (license == null) {
|
|
|
+ int count = KwfDriverLicenseDao.insert(driverLicense);
|
|
|
+ } else {
|
|
|
+ driverLicense.setId(license.getId());
|
|
|
+ int count = KwfDriverLicenseDao.updateById(driverLicense);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param key 参数
|
|
|
+ * @desc 查询司机驾驶证信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public KwfDriverLicense findLicenseByKey(Long key) {
|
|
|
+ return KwfDriverLicenseDao.findByDriverId(String.valueOf(key));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 新增司机从业资格证
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public HttpResult driverQualificationEdit(KwfDriverQualificationDto params) {
|
|
|
+ /**数据copy**/
|
|
|
+ KwfDriverQualification driverQual = new KwfDriverQualification();
|
|
|
+ BeanUtils.copyProperties(params, driverQual);
|
|
|
+
|
|
|
+ /**数据更新**/
|
|
|
+ KwfDriverQualification qualification = KwfDriverQualificationDao.findByDriverId(params.getDriverId());
|
|
|
+ if (qualification == null) {
|
|
|
+ int count = KwfDriverQualificationDao.insert(driverQual);
|
|
|
+ } else {
|
|
|
+ driverQual.setId(qualification.getId());
|
|
|
+ int count = KwfDriverQualificationDao.updateById(driverQual);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param key 参数
|
|
|
+ * @desc 查询司机从业资格证
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public KwfDriverQualification findQualificationByKey(Long key) {
|
|
|
+ return KwfDriverQualificationDao.findByDriverId(String.valueOf(key));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 新增司机信息与企业关联信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/7
|
|
|
+ **/
|
|
|
+ public void driverEntEdit(KwfDriver params) {
|
|
|
+ if (StringUtils.isBlank(params.getId())) {
|
|
|
+ KwfDriverEnt driverEnt = new KwfDriverEnt();
|
|
|
+ driverEnt.setDriverId(params.getId());
|
|
|
+ driverEnt.setEntId(params.getEntId());
|
|
|
+ driverEntDao.insert(driverEnt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|