Commit 42f72662 authored by huangcb's avatar huangcb

新增接口:帐号注册

parent 8ef7f262
...@@ -53,4 +53,7 @@ public class ErrorMessageComponent { ...@@ -53,4 +53,7 @@ public class ErrorMessageComponent {
@Value("${error-message.goodsowner.account.password-check.1002}") @Value("${error-message.goodsowner.account.password-check.1002}")
private String goodsOwnerAccountPasswordCheck1002; private String goodsOwnerAccountPasswordCheck1002;
@Value("${error-message.goodsowner.account.register.1001}")
private String goodsOwnerAccountRegister1001;
} }
...@@ -238,4 +238,19 @@ public class GoodsOwnerController { ...@@ -238,4 +238,19 @@ public class GoodsOwnerController {
BeanUtils.copyProperties(accountInfoDto, accountInfoVO); BeanUtils.copyProperties(accountInfoDto, accountInfoVO);
return EResponse.ok(accountInfoVO); return EResponse.ok(accountInfoVO);
} }
/**
* description 帐号注册
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/20 14:56
**/
@PostMapping("/register")
public EResponse accountRegister(@RequestBody @Validated(ValidatorRegister.class) AccountForm form) throws EException {
Long id = accountService.registerAccount(form.getAccount());
JSONObject data = new JSONObject();
data.put("id", id);
return EResponse.ok(data);
}
} }
...@@ -7,6 +7,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder; ...@@ -7,6 +7,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
/** /**
...@@ -30,10 +31,11 @@ public class AccountForm { ...@@ -30,10 +31,11 @@ public class AccountForm {
@Length(max = 100, message = "参数remark长度不合法", groups = {ValidatorAudit.class}) @Length(max = 100, message = "参数remark长度不合法", groups = {ValidatorAudit.class})
private String remark; private String remark;
@Length(max = 11, message = "参数account长度不合法", groups = {ValidatorDetail.class, ValidatorPassword.class}) @Length(min = 11, max = 11, message = "参数account长度不合法", groups = {ValidatorDetail.class, ValidatorPassword.class, ValidatorRegister.class})
@NotBlank(message = "参数account不能为空", groups = {ValidatorRegister.class})
private String account; private String account;
@Length(max = 32, message = "参数password长度不合法", groups = {ValidatorPassword.class}) @Length(min = 32, max = 32, message = "参数password长度不合法", groups = {ValidatorPassword.class})
private String password; private String password;
@Override @Override
......
...@@ -99,5 +99,14 @@ public interface AccountService extends IService<AccountEntity> { ...@@ -99,5 +99,14 @@ public interface AccountService extends IService<AccountEntity> {
**/ **/
AccountInfoDto getAccountInfo(AccountForm form); AccountInfoDto getAccountInfo(AccountForm form);
/**
* description 注册帐号
* param [account]
* return java.lang.Long
* author Administrator
* createTime 2020/04/20 13:23
**/
Long registerAccount(String account);
} }
...@@ -270,4 +270,25 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i ...@@ -270,4 +270,25 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
return dto; return dto;
} }
@Override
public Long registerAccount(String account) {
// 判断帐号是否存在
AccountEntity accountEntity = this.getAccountRecordByAccount(account);
if (null != accountEntity) {
throw new EException(1001, errorMessageComponent.getGoodsOwnerAccountRegister1001());
} else {
accountEntity = new AccountEntity();
}
// 新增注册帐号
accountEntity.setAccount(account);
accountEntity.setSalt(passwordComponent.generateAccountPwdSalt());
accountEntity.setSourceType(GoodsOwnerConstants.OWNER_SOURCE_TYPE_REGISTER);
accountEntity.setAuditStatus(GoodsOwnerConstants.OWNER_AUDIT_STATUS_UNAUDITED);
this.baseMapper.insert(accountEntity);
Long accountId = accountEntity.getId();
return accountId;
}
} }
\ No newline at end of file
package com.esv.freight.customer.module.goodsowner.validator.groups;
import javax.validation.groups.Default;
/**
* @description: 参数校验分组:注册
* @project: SpringCloudTemplate
* @name: com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorRegister
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorRegister extends Default {
}
...@@ -69,3 +69,5 @@ error-message: ...@@ -69,3 +69,5 @@ error-message:
password-check: password-check:
1001: 无效的手机号 1001: 无效的手机号
1002: 密码错误 1002: 密码错误
register:
1001: 帐号已存在
\ No newline at end of file
...@@ -14,11 +14,13 @@ import org.junit.runner.RunWith; ...@@ -14,11 +14,13 @@ import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID; import java.util.UUID;
...@@ -35,6 +37,7 @@ import java.util.UUID; ...@@ -35,6 +37,7 @@ import java.util.UUID;
@SpringBootTest @SpringBootTest
@Slf4j @Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
public class GoodsOwnerControllerTest extends BaseTestController { public class GoodsOwnerControllerTest extends BaseTestController {
@Test @Test
...@@ -616,4 +619,89 @@ public class GoodsOwnerControllerTest extends BaseTestController { ...@@ -616,4 +619,89 @@ public class GoodsOwnerControllerTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr); JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1002, result.getIntValue("code")); Assert.assertEquals(1002, result.getIntValue("code"));
} }
/**
* 帐号注册
**/
@Test
@Rollback
public void i1_accountRegister_success_test() throws Exception {
String url = "/goodsowner/account/register";
// 构造数据
AccountForm form = new AccountForm();
form.setAccount("18524431583");
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 i2_accountRegister_wrong_param_account_failure_test() throws Exception {
String url = "/goodsowner/account/register";
// 构造数据
AccountForm form = new AccountForm();
form.setAccount("123456789");
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.PARAM_ERROR.code(), result.getIntValue("code"));
}
/**
* 帐号注册:帐号已存在
**/
@Test
@Rollback
public void i3_accountRegister_account_existed_failure_test() throws Exception {
String url = "/goodsowner/account/register";
// 构造数据
AccountForm form = new AccountForm();
form.setAccount("18524431581");
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"));
}
} }
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