Commit 0c42c276 authored by huangcb's avatar huangcb

承运商接口:审核司机信息

parent 8c3ae625
......@@ -188,4 +188,9 @@ public class ErrorMessageComponent {
@Value("${error-message.carrier.driver.detail.1001}")
private String carrierDriverDetail1001;
@Value("${error-message.carrier.driver.audit.1001}")
private String carrierDriverAudit1001;
@Value("${error-message.carrier.driver.audit.1002}")
private String carrierDriverAudit1002;
}
......@@ -12,6 +12,7 @@ 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.dto.DriverDetailDto;
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;
......@@ -116,13 +117,31 @@ public class DriverController {
if (null == dto) {
throw new EException(1001, errorMessageComponent.getCarrierDriverDetail1001());
}
// 数据转换
DriverDetailVO vo = new DriverDetailVO();
BeanUtils.copyProperties(dto, vo);
vo.setCreateTime(dto.getCreateTime().getTime());
return EResponse.ok(vo);
}
/**
* description 审核司机信息
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/29 9:38
**/
@PostMapping("/audit")
public EResponse audit(@RequestBody @Validated DriverAuditForm form) throws EException {
if (DriverConstants.ACCOUNT_AUDIT_STATUS_FAILURE.equals(form.getAuditStatus())) {
String[] notBlankParams = new String[] {"remark"};
ReqUtils.checkParamsNotBlank(JSONObject.parseObject(form.toString()), notBlankParams);
}
driverAccountService.auditDriver(form);
return EResponse.ok();
}
}
package com.esv.freight.customer.module.driver.form;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotNull;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.driver.form.DriverAuditForm
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/29 9:27
* @version:1.0
*/
@Data
public class DriverAuditForm {
/**
*
*/
@NotNull(message = "参数id不能为空")
private Long id;
/**
* 审核状态:1-审核通过,2-审核不通过
*/
@Range(min = 1, max = 2, message = "参数auditStatus不合法")
@NotNull(message = "参数auditStatus不能为空")
private Integer auditStatus;
/**
* 备注
*/
@Length(max = 100, message = "参数remark长度不合法")
private String remark;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
......@@ -3,6 +3,7 @@ package com.esv.freight.customer.module.driver.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.driver.dto.DriverDetailDto;
import com.esv.freight.customer.module.driver.entity.DriverAccountEntity;
import com.esv.freight.customer.module.driver.form.DriverAuditForm;
import com.esv.freight.customer.module.driver.form.DriverInfoForm;
/**
......@@ -40,6 +41,15 @@ public interface DriverAccountService extends IService<DriverAccountEntity> {
* createTime 2020/04/28 20:22
**/
DriverDetailDto getDriverDetail(Long id);
/**
* description 审核司机信息
* param [form]
* return java.lang.Integer
* author Administrator
* createTime 2020/04/29 9:29
**/
Integer auditDriver(DriverAuditForm form);
}
......@@ -13,6 +13,7 @@ import com.esv.freight.customer.module.driver.dto.DriverDetailDto;
import com.esv.freight.customer.module.driver.entity.DriverAccountEntity;
import com.esv.freight.customer.module.driver.entity.DriverAuditHistoryEntity;
import com.esv.freight.customer.module.driver.entity.DriverInfoEntity;
import com.esv.freight.customer.module.driver.form.DriverAuditForm;
import com.esv.freight.customer.module.driver.service.DriverAccountService;
import com.esv.freight.customer.module.driver.service.DriverAuditHistoryService;
import com.esv.freight.customer.module.driver.service.DriverInfoService;
......@@ -160,4 +161,33 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
public DriverDetailDto getDriverDetail(Long id) {
return this.baseMapper.selectDriverDetail(id);
}
@Override
public Integer auditDriver(DriverAuditForm form) {
// 1:校验帐号ID是否有效
DriverAccountEntity accountEntity = this.baseMapper.selectById(form.getId());
if (null == accountEntity) {
throw new EException(1001, errorMessageComponent.getCarrierDriverAudit1001());
}
// 2:校验帐号是否审核通过
if (DriverConstants.ACCOUNT_AUDIT_STATUS_SUCCESS.equals(accountEntity.getAuditStatus())) {
throw new EException(1002, errorMessageComponent.getCarrierDriverAudit1002());
}
// 3:审核帐号
DriverAccountEntity driverAccountEntity = new DriverAccountEntity();
BeanUtils.copyProperties(form, driverAccountEntity);
int flag = this.baseMapper.updateById(driverAccountEntity);
// 4:增加审核记录
DriverAuditHistoryEntity driverAuditHistoryEntity = new DriverAuditHistoryEntity();
driverAuditHistoryEntity.setCarrierId(accountEntity.getCarrierId());
driverAuditHistoryEntity.setDriverId(form.getId());
driverAuditHistoryEntity.setAuditStatus(form.getAuditStatus());
driverAuditHistoryEntity.setOperateUser(ReqUtils.getRequestUserAccount());
driverAuditHistoryEntity.setRemark(form.getRemark());
flag += this.driverAuditHistoryService.getBaseMapper().insert(driverAuditHistoryEntity);
return flag;
}
}
\ No newline at end of file
......@@ -156,4 +156,7 @@ error-message:
1003: 驾驶证号码已存在
1004: 从业资格证号已存在
detail:
1001: 无效的账号ID
\ No newline at end of file
1001: 无效的账号ID
audit:
1001: 无效的账号ID
1002: 帐号已审核通过
\ No newline at end of file
......@@ -3,6 +3,8 @@ package com.esv.freight.customer.module.driver.controller;
import com.alibaba.fastjson.JSONObject;
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.DriverQueryForm;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
......@@ -35,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback(false)
public class DriverTest extends BaseTestController {
public class DriverAccountTest extends BaseTestController {
/**
* 查询司机详情
......@@ -93,4 +95,121 @@ public class DriverTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1001, result.getIntValue("code"));
}
/**
* 审核司机信息:审核不通过
**/
@Test
public void b1_audit_not_passed_success_test() throws Exception {
String url = "/carrier/driver/audit";
// 构造数据
DriverAuditForm form = new DriverAuditForm();
form.setId(1L);
form.setAuditStatus(DriverConstants.ACCOUNT_AUDIT_STATUS_FAILURE);
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(ECode.SUCCESS.code(), result.getIntValue("code"));
}
/**
* 审核司机信息:审核通过
**/
@Test
public void b2_audit_passed_success_test() throws Exception {
String url = "/carrier/driver/audit";
// 构造数据
DriverAuditForm form = new DriverAuditForm();
form.setId(1L);
form.setAuditStatus(DriverConstants.ACCOUNT_AUDIT_STATUS_SUCCESS);
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"));
}
/**
* 审核司机信息:无效的帐号ID
**/
@Test
public void b3_audit_wrong_id_failure_test() throws Exception {
String url = "/carrier/driver/audit";
// 构造数据
DriverAuditForm form = new DriverAuditForm();
form.setId(99999L);
form.setAuditStatus(DriverConstants.ACCOUNT_AUDIT_STATUS_SUCCESS);
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"));
}
/**
* 审核司机信息:无帐号已审核通过
**/
@Test
public void b4_audit_has_passed_failure_test() throws Exception {
String url = "/carrier/driver/audit";
// 构造数据
DriverAuditForm form = new DriverAuditForm();
form.setId(1L);
form.setAuditStatus(DriverConstants.ACCOUNT_AUDIT_STATUS_SUCCESS);
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