Commit 2eda488d authored by huangcb's avatar huangcb

承运商接口:编辑司机信息

parent 6812bc24
......@@ -176,4 +176,13 @@ public class ErrorMessageComponent {
private String carrierDriverAdd1003;
@Value("${error-message.carrier.driver.add.1004}")
private String carrierDriverAdd1004;
@Value("${error-message.carrier.driver.edit.1001}")
private String carrierDriverEdit1001;
@Value("${error-message.carrier.driver.edit.1002}")
private String carrierDriverEdit1002;
@Value("${error-message.carrier.driver.edit.1003}")
private String carrierDriverEdit1003;
@Value("${error-message.carrier.driver.edit.1004}")
private String carrierDriverEdit1004;
}
......@@ -8,6 +8,7 @@ import com.esv.freight.customer.common.response.EResponse;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.freight.customer.common.util.VerifyUtils;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.driver.DriverConstants;
import com.esv.freight.customer.module.driver.form.DriverInfoForm;
import com.esv.freight.customer.module.driver.service.DriverAccountService;
......@@ -71,4 +72,29 @@ public class DriverController {
data.put("id", id);
return EResponse.ok(data);
}
/**
* description 编辑司机信息
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/28 19:26
**/
@PostMapping("/edit")
public EResponse edit(@RequestBody @Validated(ValidatorUpdate.class) DriverInfoForm form) throws EException {
/****************************** 参数校验 ******************************/
// 所驾驶车辆4.5吨以上必填道路运输从业资格证信息
if (DriverConstants.ACCOUNT_DRIVING_VEHICLE_TYPE_2.equals(form.getCertificateVehicle())) {
String[] notBlankParams = new String[] {"certificateEndDate", "certificateNumber", "certificateUrl"};
ReqUtils.checkParamsNotBlank(JSONObject.parseObject(form.toString()), notBlankParams);
}
// 校验身份证号码
if (StringUtils.isNotBlank(form.getIdCard()) && !VerifyUtils.isValidIdCard18(form.getIdCard())) {
throw new EException(ECode.PARAM_ERROR.code(), "无效的身份证号码");
}
/****************************** 参数校验 ******************************/
driverAccountService.updateDriver(form);
return EResponse.ok();
}
}
......@@ -22,5 +22,14 @@ public interface DriverAccountService extends IService<DriverAccountEntity> {
**/
Long insertDriver(DriverInfoForm form);
/**
* description 更新司机信息
* param [form]
* return java.lang.Integer
* author Administrator
* createTime 2020/04/28 19:13
**/
Integer updateDriver(DriverInfoForm form);
}
package com.esv.freight.customer.module.driver.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.component.PasswordComponent;
......@@ -103,4 +104,54 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
return driverId;
}
@Override
public Integer updateDriver(DriverInfoForm form) {
// 1:校验
// 1.1:校验账号ID是否有效
DriverAccountEntity driverAccountEntity = this.baseMapper.selectById(form.getId());
if (null == driverAccountEntity) {
throw new EException(1001, errorMessageComponent.getCarrierDriverEdit1001());
}
// 1.2:校验身份证号码是否已存在
Integer count = this.driverInfoService.getBaseMapper().selectCount(new QueryWrapper<DriverInfoEntity>().lambda()
.ne(DriverInfoEntity::getDriverId, form.getId())
.eq(DriverInfoEntity::getIdCard, form.getIdCard()));
if (0 < count) {
throw new EException(1002, errorMessageComponent.getCarrierDriverEdit1002());
}
// 1.3:校验驾驶证号码是否已存在
count = this.driverInfoService.getBaseMapper().selectCount(new QueryWrapper<DriverInfoEntity>().lambda()
.ne(DriverInfoEntity::getDriverId, form.getId())
.eq(DriverInfoEntity::getDrivingLicense, form.getDrivingLicense()));
if (0 < count) {
throw new EException(1003, errorMessageComponent.getCarrierDriverEdit1003());
}
// 1.4:校验从业资格证号是否已存在
if (StringUtils.isNotBlank(form.getCertificateNumber())) {
count = this.driverInfoService.getBaseMapper().selectCount(new QueryWrapper<DriverInfoEntity>().lambda()
.ne(DriverInfoEntity::getDriverId, form.getId())
.eq(DriverInfoEntity::getCertificateNumber, form.getCertificateNumber()));
if (0 < count) {
throw new EException(1004, errorMessageComponent.getCarrierDriverEdit1004());
}
}
// 2:更新密码
int flag = 0;
if (StringUtils.isNotBlank(form.getPassword())) {
DriverAccountEntity accountEntity = new DriverAccountEntity();
accountEntity.setId(form.getId());
accountEntity.setPassword(passwordComponent.generatePwd4Salt(form.getPassword(), driverAccountEntity.getSalt()));
flag += this.baseMapper.updateById(accountEntity);
}
// 3:更新帐号信息
DriverInfoEntity driverInfoEntity = new DriverInfoEntity();
BeanUtils.copyProperties(form, driverInfoEntity);
flag += this.driverInfoService.getBaseMapper().update(driverInfoEntity, new UpdateWrapper<DriverInfoEntity>().lambda()
.eq(DriverInfoEntity::getDriverId, form.getId()));
return flag;
}
}
\ No newline at end of file
......@@ -149,4 +149,9 @@ error-message:
1001: 账号已存在
1002: 身份证号码已存在
1003: 驾驶证号码已存在
1004: 从业资格证号已存在
edit:
1001: 无效的账号ID
1002: 身份证号码已存在
1003: 驾驶证号码已存在
1004: 从业资格证号已存在
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment