Commit cee6bbc3 authored by huangcb's avatar huangcb

新增接口:货主帐号启用/停用

parent 6e2d9172
......@@ -25,4 +25,14 @@ public class ErrorMessageComponent {
@Value("${error-message.goodsowner.account.edit.1001}")
private String goodsOwnerAccountEdit1001;
@Value("${error-message.goodsowner.account.block.1001}")
private String goodsOwnerAccountBlock1001;
@Value("${error-message.goodsowner.account.block.1002}")
private String goodsOwnerAccountBlock1002;
@Value("${error-message.goodsowner.account.unblock.1001}")
private String goodsOwnerAccountUnblock1001;
@Value("${error-message.goodsowner.account.unblock.1002}")
private String goodsOwnerAccountUnblock1002;
}
......@@ -23,11 +23,17 @@ public class GoodsOwnerConstants {
public static final String OWNER_SOURCE_TYPE_PLATFORM = "1";
public static final String OWNER_SOURCE_TYPE_REGISTER = "2";
/**
* 货主帐号审核状态:0-待审核、1-审核成功,2-审核失败,APP自行注册需要平台审核
**/
public static final Integer OWNER_AUDIT_STATUS_UNAUDITED = 0;
public static final Integer OWNER_AUDIT_STATUS_SUCCESS = 1;
public static final Integer OWNER_AUDIT_STATUS_FAILURE = 2;
/**
* 货主帐号状态:1-正常、2-停用
**/
public static final String OWNER_ACCOUNT_STATUS_UNBLOCK = "1";
public static final String OWNER_ACCOUNT_STATUS_BLOCK = "2";
}
......@@ -9,6 +9,7 @@ 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.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.form.AccountForm;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
import com.esv.freight.customer.module.goodsowner.service.AccountService;
import lombok.extern.slf4j.Slf4j;
......@@ -91,4 +92,30 @@ public class GoodsOwnerController {
accountService.updateAccountInfo(form);
return EResponse.ok();
}
/**
* description 停用帐号
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/18 15:11
**/
@PostMapping("/block")
public EResponse blockAccount(@RequestBody @Validated AccountForm form) throws EException {
accountService.blockAccount(form.getId());
return EResponse.ok();
}
/**
* description 启用帐号
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/18 15:11
**/
@PostMapping("/unblock")
public EResponse unblockAccount(@RequestBody @Validated AccountForm form) throws EException {
accountService.unblockAccount(form.getId());
return EResponse.ok();
}
}
package com.esv.freight.customer.module.goodsowner.form;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotNull;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.goodsowner.form.AccountForm
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/17 16:11
* @version:1.0
*/
@Data
public class AccountForm {
@NotNull(message = "参数id不能为空")
private Long id;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
......@@ -51,5 +51,23 @@ public interface AccountService extends IService<AccountEntity> {
**/
void updateAccountInfo(AccountInfoForm form);
/**
* description 停用帐号
* param [id]
* return void
* author Administrator
* createTime 2020/04/18 14:59
**/
void blockAccount(Long id);
/**
* description 启用帐号
* param [id]
* return void
* author Administrator
* createTime 2020/04/18 14:59
**/
void unblockAccount(Long id);
}
......@@ -168,4 +168,42 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
Wrapper<InfoEntity> InfoUpdateWrapper = new UpdateWrapper<>(infoEntityWrapper);
infoService.getBaseMapper().update(infoEntity, InfoUpdateWrapper);
}
@Override
public void blockAccount(Long id) {
// 判断帐号是否存在
AccountEntity accountEntity = this.getAccountRecordById(id);
if (null == accountEntity) {
throw new EException(1001, errorMessageComponent.getGoodsOwnerAccountBlock1001());
} else {
if (GoodsOwnerConstants.OWNER_ACCOUNT_STATUS_BLOCK.equals(accountEntity.getAccountStatus())) {
throw new EException(1002, errorMessageComponent.getGoodsOwnerAccountBlock1002());
}
}
// 停用帐号
AccountEntity accountEntityUpdate = new AccountEntity();
accountEntityUpdate.setId(id);
accountEntityUpdate.setAccountStatus(GoodsOwnerConstants.OWNER_ACCOUNT_STATUS_BLOCK);
this.baseMapper.updateById(accountEntityUpdate);
}
@Override
public void unblockAccount(Long id) {
// 判断帐号是否存在
AccountEntity accountEntity = this.getAccountRecordById(id);
if (null == accountEntity) {
throw new EException(1001, errorMessageComponent.getGoodsOwnerAccountUnblock1001());
} else {
if (GoodsOwnerConstants.OWNER_ACCOUNT_STATUS_UNBLOCK.equals(accountEntity.getAccountStatus())) {
throw new EException(1002, errorMessageComponent.getGoodsOwnerAccountUnblock1002());
}
}
// 启用帐号
AccountEntity accountEntityUpdate = new AccountEntity();
accountEntityUpdate.setId(id);
accountEntityUpdate.setAccountStatus(GoodsOwnerConstants.OWNER_ACCOUNT_STATUS_UNBLOCK);
this.baseMapper.updateById(accountEntityUpdate);
}
}
\ No newline at end of file
......@@ -51,4 +51,10 @@ error-message:
add:
1001: 帐号已存在
edit:
1001: 无效的帐号ID
\ No newline at end of file
1001: 无效的帐号ID
block:
1001: 无效的帐号ID
1002: 帐号已停用
unblock:
1001: 无效的帐号ID
1002: 帐号已启用
\ No newline at end of file
......@@ -31,6 +31,11 @@ public class ErrorMessageComponentTest extends BaseTestController {
@Test
public void test() {
log.info(errorMessageComponent.getGoodsOwnerAccountAdd1001());
log.info(errorMessageComponent.getGoodsOwnerAccountEdit1001());
log.info(errorMessageComponent.getGoodsOwnerAccountBlock1001());
log.info(errorMessageComponent.getGoodsOwnerAccountBlock1002());
log.info(errorMessageComponent.getGoodsOwnerAccountUnblock1001());
log.info(errorMessageComponent.getGoodsOwnerAccountUnblock1002());
}
}
......@@ -4,6 +4,7 @@ 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.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.form.AccountForm;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
......@@ -41,7 +42,6 @@ public class GoodsOwnerControllerTest extends BaseTestController {
String url = "/goodsowner/account/add";
// 构造数据
JSONObject reqJson = new JSONObject();
AccountInfoForm form = new AccountInfoForm();
form.setAccount("18524431581");
form.setPassword("e28bec3e2feb42598b8cf1a1d3b11f4a");
......@@ -55,7 +55,7 @@ public class GoodsOwnerControllerTest extends BaseTestController {
form.setDetailAddress("双园路");
form.setIdCardFrontUrl("http://127.0.0.1/001.jpg");
form.setIdCardBackUrl("http://127.0.0.1/002.jpg");
reqJson = JSONObject.parseObject(form.toString());
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
......@@ -77,7 +77,6 @@ public class GoodsOwnerControllerTest extends BaseTestController {
String url = "/goodsowner/account/add";
// 构造数据
JSONObject reqJson = new JSONObject();
AccountInfoForm form = new AccountInfoForm();
form.setAccount("18524431582");
form.setPassword("e28bec3e2feb42598b8cf1a1d3b11f4a");
......@@ -95,7 +94,7 @@ public class GoodsOwnerControllerTest extends BaseTestController {
form.setUniCreditCode("123456789");
form.setCreditCopyUrl("http://127.0.0.1/003.jpg");
form.setLegalPerson("黄卓越");
reqJson = JSONObject.parseObject(form.toString());
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
......@@ -117,7 +116,6 @@ public class GoodsOwnerControllerTest extends BaseTestController {
String url = "/goodsowner/account/edit";
// 构造数据
JSONObject reqJson = new JSONObject();
AccountInfoForm form = new AccountInfoForm();
form.setId(1L);
form.setPassword(UUID.randomUUID().toString().replaceAll("-", ""));
......@@ -135,7 +133,7 @@ public class GoodsOwnerControllerTest extends BaseTestController {
form.setUniCreditCode("123456789");
form.setCreditCopyUrl("http://127.0.0.1/003.jpg");
form.setLegalPerson("黄卓越");
reqJson = JSONObject.parseObject(form.toString());
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
......@@ -157,7 +155,6 @@ public class GoodsOwnerControllerTest extends BaseTestController {
String url = "/goodsowner/account/edit";
// 构造数据
JSONObject reqJson = new JSONObject();
AccountInfoForm form = new AccountInfoForm();
form.setId(4L);
form.setPassword(UUID.randomUUID().toString().replaceAll("-", ""));
......@@ -176,7 +173,7 @@ public class GoodsOwnerControllerTest extends BaseTestController {
form.setUniCreditCode("1234567890");
form.setCreditCopyUrl("http://127.0.0.1/003.jpg");
form.setLegalPerson("黄卓越");
reqJson = JSONObject.parseObject(form.toString());
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
......@@ -192,4 +189,100 @@ public class GoodsOwnerControllerTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(ECode.SUCCESS.code(), result.getIntValue("code"));
}
@Test
public void c1_blockAccount_success_test() throws Exception {
String url = "/goodsowner/account/block";
// 构造数据
AccountForm form = new AccountForm();
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"));
}
@Test
public void c2_blockAccount_failure_test() throws Exception {
String url = "/goodsowner/account/block";
// 构造数据
AccountForm form = new AccountForm();
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
public void d1_unblockAccount_success_test() throws Exception {
String url = "/goodsowner/account/unblock";
// 构造数据
AccountForm form = new AccountForm();
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"));
}
@Test
public void d2_unblockAccount_failure_test() throws Exception {
String url = "/goodsowner/account/unblock";
// 构造数据
AccountForm form = new AccountForm();
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