Commit d4857259 authored by huangcb's avatar huangcb

承运商接口:停用/启用司机帐号

parent 0c42c276
......@@ -193,4 +193,14 @@ public class ErrorMessageComponent {
private String carrierDriverAudit1001;
@Value("${error-message.carrier.driver.audit.1002}")
private String carrierDriverAudit1002;
@Value("${error-message.carrier.driver.block.1001}")
private String carrierDriverBlock1001;
@Value("${error-message.carrier.driver.block.1002}")
private String carrierDriverBlock1002;
@Value("${error-message.carrier.driver.unblock.1001}")
private String carrierDriverUnblock1001;
@Value("${error-message.carrier.driver.unblock.1002}")
private String carrierDriverUnblock1002;
}
......@@ -144,4 +144,31 @@ public class DriverController {
return EResponse.ok();
}
/**
* description 停用帐号
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/29 10:10
**/
@PostMapping("/block")
public EResponse block(@RequestBody @Validated(ValidatorDetail.class) DriverQueryForm form) throws EException {
driverAccountService.blockDriver(form.getId());
return EResponse.ok();
}
/**
* description 停用帐号
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/29 10:10
**/
@PostMapping("/unblock")
public EResponse unblock(@RequestBody @Validated(ValidatorDetail.class) DriverQueryForm form) throws EException {
driverAccountService.unblockDriver(form.getId());
return EResponse.ok();
}
}
......@@ -51,5 +51,23 @@ public interface DriverAccountService extends IService<DriverAccountEntity> {
**/
Integer auditDriver(DriverAuditForm form);
/**
* description 停用司机帐号
* param [id]
* return java.lang.Integer
* author Administrator
* createTime 2020/04/29 10:03
**/
Integer blockDriver(Long id);
/**
* description 启用司机帐号
* param [id]
* return java.lang.Integer
* author Administrator
* createTime 2020/04/29 10:08
**/
Integer unblockDriver(Long id);
}
......@@ -163,6 +163,7 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
}
@Override
@Transactional(rollbackFor = Exception.class)
public Integer auditDriver(DriverAuditForm form) {
// 1:校验帐号ID是否有效
DriverAccountEntity accountEntity = this.baseMapper.selectById(form.getId());
......@@ -190,4 +191,42 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
return flag;
}
@Override
public Integer blockDriver(Long id) {
// 1:校验帐号ID是否有效
DriverAccountEntity accountEntity = this.baseMapper.selectById(id);
if (null == accountEntity) {
throw new EException(1001, errorMessageComponent.getCarrierDriverBlock1001());
}
// 2:校验帐号是否已停用
if (DriverConstants.ACCOUNT_STATUS_BLOCK.equals(accountEntity.getAccountStatus())) {
throw new EException(1002, errorMessageComponent.getCarrierDriverBlock1002());
}
// 3:停用帐号
DriverAccountEntity driverAccountEntity = new DriverAccountEntity();
driverAccountEntity.setId(id);
driverAccountEntity.setAccountStatus(DriverConstants.ACCOUNT_STATUS_BLOCK);
return this.baseMapper.updateById(driverAccountEntity);
}
@Override
public Integer unblockDriver(Long id) {
// 1:校验帐号ID是否有效
DriverAccountEntity accountEntity = this.baseMapper.selectById(id);
if (null == accountEntity) {
throw new EException(1001, errorMessageComponent.getCarrierDriverUnblock1001());
}
// 2:校验帐号是否已启用
if (DriverConstants.ACCOUNT_STATUS_UNBLOCK.equals(accountEntity.getAccountStatus())) {
throw new EException(1002, errorMessageComponent.getCarrierDriverUnblock1002());
}
// 3:启用帐号
DriverAccountEntity driverAccountEntity = new DriverAccountEntity();
driverAccountEntity.setId(id);
driverAccountEntity.setAccountStatus(DriverConstants.ACCOUNT_STATUS_UNBLOCK);
return this.baseMapper.updateById(driverAccountEntity);
}
}
\ No newline at end of file
......@@ -160,3 +160,9 @@ error-message:
audit:
1001: 无效的账号ID
1002: 帐号已审核通过
block:
1001: 无效的账号ID
1002: 帐号已停用
unblock:
1001: 无效的账号ID
1002: 帐号已启用
\ No newline at end of file
......@@ -159,6 +159,7 @@ public class DriverAccountTest extends BaseTestController {
* 审核司机信息:无效的帐号ID
**/
@Test
@Rollback
public void b3_audit_wrong_id_failure_test() throws Exception {
String url = "/carrier/driver/audit";
......@@ -188,6 +189,7 @@ public class DriverAccountTest extends BaseTestController {
* 审核司机信息:无帐号已审核通过
**/
@Test
@Rollback
public void b4_audit_has_passed_failure_test() throws Exception {
String url = "/carrier/driver/audit";
......@@ -212,4 +214,178 @@ public class DriverAccountTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1002, result.getIntValue("code"));
}
/**
* 停用司机帐号
**/
@Test
@Rollback
public void c1_block_success_test() throws Exception {
String url = "/carrier/driver/block";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(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"));
}
/**
* 停用司机帐号:无效的帐号ID
**/
@Test
@Rollback
public void c2_block_wrong_id_failure_test() throws Exception {
String url = "/carrier/driver/block";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(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(1001, result.getIntValue("code"));
}
/**
* 停用司机帐号:帐号已停用
**/
@Test
@Rollback
public void c3_block_has_block_failure_test() throws Exception {
String url = "/carrier/driver/block";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(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(1002, result.getIntValue("code"));
}
/**
* 启用司机帐号
**/
@Test
@Rollback
public void d1_unblock_success_test() throws Exception {
String url = "/carrier/driver/unblock";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(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"));
}
/**
* 启用司机帐号:无效的帐号ID
**/
@Test
@Rollback
public void d2_unblock_wrong_id_failure_test() throws Exception {
String url = "/carrier/driver/unblock";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(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(1001, result.getIntValue("code"));
}
/**
* 启用司机帐号:帐号已启用
**/
@Test
@Rollback
public void d3_unblock_has_unblock_failure_test() throws Exception {
String url = "/carrier/driver/unblock";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(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(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