Commit 0a48f425 authored by huangcb's avatar huangcb

承运商接口:注册司机

parent d4857259
......@@ -176,6 +176,8 @@ public class ErrorMessageComponent {
private String carrierDriverAdd1003;
@Value("${error-message.carrier.driver.add.1004}")
private String carrierDriverAdd1004;
@Value("${error-message.carrier.driver.add.1005}")
private String carrierDriverAdd1005;
@Value("${error-message.carrier.driver.edit.1001}")
private String carrierDriverEdit1001;
......@@ -203,4 +205,9 @@ public class ErrorMessageComponent {
private String carrierDriverUnblock1001;
@Value("${error-message.carrier.driver.unblock.1002}")
private String carrierDriverUnblock1002;
@Value("${error-message.carrier.driver.register.1001}")
private String carrierDriverRegister1001;
@Value("${error-message.carrier.driver.register.1002}")
private String carrierDriverRegister1002;
}
......@@ -73,5 +73,14 @@ public interface CarrierAccountService extends IService<CarrierAccountEntity> {
**/
PageResultVO getCarrier4Page(CarrierQueryForm queryObj);
/**
* description 通过ID查询承运商帐号
* param [id]
* return com.esv.freight.customer.module.carrier.entity.CarrierAccountEntity
* author Administrator
* createTime 2020/04/29 10:52
**/
CarrierAccountEntity getCarrierById(Long id);
}
......@@ -219,4 +219,9 @@ public class CarrierAccountServiceImpl extends ServiceImpl<CarrierAccountDao, Ca
return new PageResultVO(page, targetRecordList);
}
@Override
public CarrierAccountEntity getCarrierById(Long id) {
return this.baseMapper.selectById(id);
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import com.esv.freight.customer.module.driver.form.DriverAuditForm;
import com.esv.freight.customer.module.driver.form.DriverInfoForm;
import com.esv.freight.customer.module.driver.form.DriverQueryForm;
import com.esv.freight.customer.module.driver.service.DriverAccountService;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorRegister;
import com.esv.freight.customer.module.driver.vo.DriverDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -171,4 +172,20 @@ public class DriverController {
return EResponse.ok();
}
/**
* description 注册司机
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/29 11:03
**/
@PostMapping("/register")
public EResponse register(@RequestBody @Validated(ValidatorRegister.class) DriverInfoForm form) throws EException {
Long id = driverAccountService.registerDriver(form);
JSONObject data = new JSONObject();
data.put("id", id);
return EResponse.ok(data);
}
}
......@@ -2,6 +2,7 @@ package com.esv.freight.customer.module.driver.form;
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.validator.groups.ValidatorRegister;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
......@@ -31,12 +32,12 @@ public class DriverInfoForm {
/**
* 承运商帐号ID
*/
@NotNull(message = "参数carrierId不能为空", groups = {ValidatorInsert.class})
@NotNull(message = "参数carrierId不能为空", groups = {ValidatorInsert.class, ValidatorRegister.class})
private Long carrierId;
/**
* 登录帐号,司机手机号
*/
@Length(min = 11, max = 11, message = "参数account长度不合法", groups = {ValidatorInsert.class})
@Length(min = 11, max = 11, message = "参数account长度不合法", groups = {ValidatorInsert.class, ValidatorRegister.class})
@NotBlank(message = "参数account不能为空", groups = {ValidatorInsert.class})
private String account;
/**
......
......@@ -69,5 +69,14 @@ public interface DriverAccountService extends IService<DriverAccountEntity> {
**/
Integer unblockDriver(Long id);
/**
* description 注册司机
* param [form]
* return java.lang.Long
* author Administrator
* createTime 2020/04/29 10:43
**/
Long registerDriver(DriverInfoForm form);
}
......@@ -7,6 +7,8 @@ import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.component.PasswordComponent;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.freight.customer.module.carrier.entity.CarrierAccountEntity;
import com.esv.freight.customer.module.carrier.service.CarrierAccountService;
import com.esv.freight.customer.module.driver.DriverConstants;
import com.esv.freight.customer.module.driver.dao.DriverAccountDao;
import com.esv.freight.customer.module.driver.dto.DriverDetailDto;
......@@ -36,13 +38,17 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
private DriverAuditHistoryService driverAuditHistoryService;
private CarrierAccountService carrierAccountService;
@Autowired
public DriverAccountServiceImpl(ErrorMessageComponent errorMessageComponent, PasswordComponent passwordComponent,
DriverInfoService driverInfoService, DriverAuditHistoryService driverAuditHistoryService) {
DriverInfoService driverInfoService, DriverAuditHistoryService driverAuditHistoryService,
CarrierAccountService carrierAccountService) {
this.errorMessageComponent = errorMessageComponent;
this.passwordComponent = passwordComponent;
this.driverInfoService = driverInfoService;
this.driverAuditHistoryService = driverAuditHistoryService;
this.carrierAccountService = carrierAccountService;
}
@Override
......@@ -75,6 +81,11 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
throw new EException(1004, errorMessageComponent.getCarrierDriverAdd1004());
}
}
// 1.5:校验承运商帐号ID是否有效
CarrierAccountEntity carrierAccountEntity = this.carrierAccountService.getCarrierById(form.getCarrierId());
if (null == carrierAccountEntity) {
throw new EException(1005, errorMessageComponent.getCarrierDriverAdd1005());
}
// 2:新增司机帐号
DriverAccountEntity driverAccountEntity = new DriverAccountEntity();
......@@ -229,4 +240,50 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
driverAccountEntity.setAccountStatus(DriverConstants.ACCOUNT_STATUS_UNBLOCK);
return this.baseMapper.updateById(driverAccountEntity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Long registerDriver(DriverInfoForm form) {
// 1:校验账号是否已存在
Integer count = this.baseMapper.selectCount(new QueryWrapper<DriverAccountEntity>().lambda()
.eq(DriverAccountEntity::getAccount, form.getAccount()));
if (0 < count) {
throw new EException(1001, errorMessageComponent.getCarrierDriverRegister1001());
}
// 2:校验承运商帐号ID是否有效
CarrierAccountEntity carrierAccountEntity = this.carrierAccountService.getCarrierById(form.getCarrierId());
if (null == carrierAccountEntity) {
throw new EException(1002, errorMessageComponent.getCarrierDriverRegister1002());
}
// 3:新增司机帐号
DriverAccountEntity driverAccountEntity = new DriverAccountEntity();
driverAccountEntity.setAccount(form.getAccount());
driverAccountEntity.setCarrierId(form.getCarrierId());
driverAccountEntity.setSalt(passwordComponent.generateAccountPwdSalt());
driverAccountEntity.setAccountStatus(DriverConstants.ACCOUNT_STATUS_BLOCK);
driverAccountEntity.setSourceType(DriverConstants.ACCOUNT_SOURCE_TYPE_REGISTER);
driverAccountEntity.setAuthenticateStatus(DriverConstants.ACCOUNT_AUTHENTICATE_STATUS_NO);
driverAccountEntity.setAuditStatus(DriverConstants.ACCOUNT_AUDIT_STATUS_UNAUDITED);
this.baseMapper.insert(driverAccountEntity);
Long driverId = driverAccountEntity.getId();
// 4:新增司机信息
DriverInfoEntity driverInfoEntity = new DriverInfoEntity();
driverInfoEntity.setDriverId(driverId);
driverInfoEntity.setCarrierId(form.getCarrierId());
this.driverInfoService.getBaseMapper().insert(driverInfoEntity);
// 5:新增审核记录
DriverAuditHistoryEntity driverAuditHistoryEntity = new DriverAuditHistoryEntity();
driverAuditHistoryEntity.setCarrierId(form.getCarrierId());
driverAuditHistoryEntity.setDriverId(driverId);
driverAuditHistoryEntity.setAuditStatus(DriverConstants.ACCOUNT_AUDIT_STATUS_UNAUDITED);
driverAuditHistoryEntity.setRemark("用户通过终端APP注册帐号");
driverAuditHistoryEntity.setOperateUser(ReqUtils.getRequestUserAccount());
this.driverAuditHistoryService.getBaseMapper().insert(driverAuditHistoryEntity);
return driverId;
}
}
\ No newline at end of file
package com.esv.freight.customer.module.driver.validator.groups;
import javax.validation.groups.Default;
/**
* @description: 参数校验分组:注册
* @project: SpringCloudTemplate
* @name: com.esv.freight.customer.module.driver.validator.groups.ValidatorRegister
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorRegister extends Default {
}
......@@ -150,6 +150,7 @@ error-message:
1002: 身份证号码已存在
1003: 驾驶证号码已存在
1004: 从业资格证号已存在
1005: 无效的承运商ID
edit:
1001: 无效的账号ID
1002: 身份证号码已存在
......@@ -165,4 +166,7 @@ error-message:
1002: 帐号已停用
unblock:
1001: 无效的账号ID
1002: 帐号已启用
\ No newline at end of file
1002: 帐号已启用
register:
1001: 帐号已存在
1002: 无效的承运商ID​
\ No newline at end of file
......@@ -430,4 +430,58 @@ public class DriverAccountAddTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(ECode.PARAM_ERROR.code(), result.getIntValue("code"));
}
/**
* 新增司机:无效的承运商ID
**/
@Test
@Rollback
public void a8_add_vehicle_wrong_carrierId_failure_test() throws Exception {
String url = "/carrier/driver/add";
// 构造数据
DriverInfoForm form = new DriverInfoForm();
form.setCarrierId(99999L);
form.setAccount("18512340013");
form.setPassword("e10adc3949ba59abbe56e057f20f883e");
form.setName("路上跳");
form.setIdCard("210104198106036252");
form.setIdCardExpireDate("2030/10/31");
form.setIdCardFrontUrl("http://127.0.0.1/id_card_front_url_18512340012.jpg");
form.setIdCardBackUrl("http://127.0.0.1/id_card_back_url_18512340012.jpg");
form.setSettlementType(1); // 结算对象(字典表):1-个人、2-所属承运商
form.setSex(1); // 性别(字典表):1-男、2-女、3-未知
form.setBirthDate("1981/6/3");
form.setNation("满族");
form.setNativePlace("辽宁沈阳");
form.setProvinceCode("210000");
form.setCityCode("210100");
form.setDistrictCode("210103");
form.setDetailAddress("青年大街245号河畔花园1-1");
form.setDrivingLicense("210104198106036252");
form.setDrivingLicenseType(7); // 驾驶证类型(字典表):1-A1、2-A2、3-A3、4-A1A2、5-A2E、6-A2D、7-B1、8-B2、9-C1、0-其他
form.setDrivingLicenseStartDate("2015/8/1");
form.setDrivingLicenseEndDate("2021/7/30");
form.setDrivingLicenseIssueDepartment("沈阳市公安局交通警察支队大东分局");
form.setDrivingLicenseInitDate("2015/8/1");
form.setDrivingLicenseUrl("http://127.0.0.1/driving_license_url_18512340013.jpg");
form.setCertificateVehicle(DriverConstants.ACCOUNT_DRIVING_VEHICLE_TYPE_1); // 道路运输从业资格证-所驾驶车辆(字典表):1-4.5吨及以下、2-4.5吨以上
form.setRemark("测试数据");
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String responseStr = mvcResult.getResponse().getContentAsString();
log.info(responseStr);
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1005, result.getIntValue("code"));
}
}
......@@ -5,6 +5,7 @@ import com.esv.freight.customer.BaseTestController;
import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.module.driver.DriverConstants;
import com.esv.freight.customer.module.driver.form.DriverAuditForm;
import com.esv.freight.customer.module.driver.form.DriverInfoForm;
import com.esv.freight.customer.module.driver.form.DriverQueryForm;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
......@@ -388,4 +389,96 @@ public class DriverAccountTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1002, result.getIntValue("code"));
}
/**
* 注册司机
**/
@Test
// @Rollback
public void d1_register_success_test() throws Exception {
String url = "/carrier/driver/register";
// 构造数据
DriverInfoForm form = new DriverInfoForm();
form.setAccount("18512341001");
form.setCarrierId(1L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String responseStr = mvcResult.getResponse().getContentAsString();
log.info(responseStr);
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(ECode.SUCCESS.code(), result.getIntValue("code"));
Assert.assertTrue(result.getJSONObject("data").containsKey("id"));
}
/**
* 注册司机:帐号已存在
**/
@Test
@Rollback
public void d2_register_wrong_account_failure_test() throws Exception {
String url = "/carrier/driver/register";
// 构造数据
DriverInfoForm form = new DriverInfoForm();
form.setAccount("18512341001");
form.setCarrierId(1L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String responseStr = mvcResult.getResponse().getContentAsString();
log.info(responseStr);
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1001, result.getIntValue("code"));
}
/**
* 注册司机:无效的承运商ID
**/
@Test
@Rollback
public void d3_register_wrong_CarrierId_failure_test() throws Exception {
String url = "/carrier/driver/register";
// 构造数据
DriverInfoForm form = new DriverInfoForm();
form.setAccount("18512341002");
form.setCarrierId(99999L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String responseStr = mvcResult.getResponse().getContentAsString();
log.info(responseStr);
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1002, result.getIntValue("code"));
}
}
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