Commit 23eee501 authored by huangcb's avatar huangcb

新增接口:货主帐号审核

parent cee6bbc3
...@@ -35,4 +35,9 @@ public class ErrorMessageComponent { ...@@ -35,4 +35,9 @@ public class ErrorMessageComponent {
@Value("${error-message.goodsowner.account.unblock.1002}") @Value("${error-message.goodsowner.account.unblock.1002}")
private String goodsOwnerAccountUnblock1002; private String goodsOwnerAccountUnblock1002;
@Value("${error-message.goodsowner.account.audit.1001}")
private String goodsOwnerAccountAudit1001;
@Value("${error-message.goodsowner.account.audit.1002}")
private String goodsOwnerAccountAudit1002;
} }
...@@ -12,6 +12,9 @@ import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants; ...@@ -12,6 +12,9 @@ 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.AccountForm;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm; import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
import com.esv.freight.customer.module.goodsowner.service.AccountService; import com.esv.freight.customer.module.goodsowner.service.AccountService;
import com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorAudit;
import com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorBlock;
import com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorUnblock;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -101,7 +104,7 @@ public class GoodsOwnerController { ...@@ -101,7 +104,7 @@ public class GoodsOwnerController {
* createTime 2020/04/18 15:11 * createTime 2020/04/18 15:11
**/ **/
@PostMapping("/block") @PostMapping("/block")
public EResponse blockAccount(@RequestBody @Validated AccountForm form) throws EException { public EResponse blockAccount(@RequestBody @Validated(ValidatorBlock.class) AccountForm form) throws EException {
accountService.blockAccount(form.getId()); accountService.blockAccount(form.getId());
return EResponse.ok(); return EResponse.ok();
} }
...@@ -114,8 +117,28 @@ public class GoodsOwnerController { ...@@ -114,8 +117,28 @@ public class GoodsOwnerController {
* createTime 2020/04/18 15:11 * createTime 2020/04/18 15:11
**/ **/
@PostMapping("/unblock") @PostMapping("/unblock")
public EResponse unblockAccount(@RequestBody @Validated AccountForm form) throws EException { public EResponse unblockAccount(@RequestBody @Validated(ValidatorUnblock.class) AccountForm form) throws EException {
accountService.unblockAccount(form.getId()); accountService.unblockAccount(form.getId());
return EResponse.ok(); return EResponse.ok();
} }
/**
* description 审核帐号
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/18 16:08
**/
@PostMapping("/audit")
public EResponse auditAccount(@RequestBody @Validated(ValidatorAudit.class) AccountForm form) throws EException {
/****************************** 参数校验 ******************************/
// 校验备注
if (GoodsOwnerConstants.OWNER_AUDIT_STATUS_FAILURE.equals(form.getAuditStatus()) && StringUtils.isBlank(form.getRemark())) {
throw new EException(ECode.PARAM_ERROR.code(), "参数remark不能为空");
}
/****************************** 参数校验 ******************************/
accountService.auditAccount(form);
return EResponse.ok();
}
} }
package com.esv.freight.customer.module.goodsowner.form; package com.esv.freight.customer.module.goodsowner.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.goodsowner.validator.groups.ValidatorAudit;
import com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorBlock;
import com.esv.freight.customer.module.goodsowner.validator.groups.ValidatorUnblock;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder; 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 javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
...@@ -18,9 +24,15 @@ import javax.validation.constraints.NotNull; ...@@ -18,9 +24,15 @@ import javax.validation.constraints.NotNull;
@Data @Data
public class AccountForm { public class AccountForm {
@NotNull(message = "参数id不能为空") @NotNull(message = "参数id不能为空", groups = {ValidatorBlock.class, ValidatorUnblock.class, ValidatorAudit.class})
private Long id; private Long id;
@NotNull(message = "参数auditStatus不能为空", groups = {ValidatorAudit.class})
private Integer auditStatus;
@Length(max = 100, message = "参数remark长度不合法", groups = {ValidatorAudit.class})
private String remark;
@Override @Override
public String toString() { public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
......
...@@ -2,6 +2,7 @@ package com.esv.freight.customer.module.goodsowner.service; ...@@ -2,6 +2,7 @@ package com.esv.freight.customer.module.goodsowner.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.goodsowner.entity.AccountEntity; import com.esv.freight.customer.module.goodsowner.entity.AccountEntity;
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.form.AccountInfoForm;
import java.util.List; import java.util.List;
...@@ -69,5 +70,14 @@ public interface AccountService extends IService<AccountEntity> { ...@@ -69,5 +70,14 @@ public interface AccountService extends IService<AccountEntity> {
**/ **/
void unblockAccount(Long id); void unblockAccount(Long id);
/**
* description 审核帐号
* param [form]
* return void
* author Administrator
* createTime 2020/04/18 15:41
**/
void auditAccount(AccountForm form);
} }
...@@ -15,6 +15,7 @@ import com.esv.freight.customer.module.goodsowner.dao.AccountDao; ...@@ -15,6 +15,7 @@ import com.esv.freight.customer.module.goodsowner.dao.AccountDao;
import com.esv.freight.customer.module.goodsowner.entity.AccountEntity; import com.esv.freight.customer.module.goodsowner.entity.AccountEntity;
import com.esv.freight.customer.module.goodsowner.entity.AuditHistoryEntity; import com.esv.freight.customer.module.goodsowner.entity.AuditHistoryEntity;
import com.esv.freight.customer.module.goodsowner.entity.InfoEntity; import com.esv.freight.customer.module.goodsowner.entity.InfoEntity;
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.form.AccountInfoForm;
import com.esv.freight.customer.module.goodsowner.service.AccountService; import com.esv.freight.customer.module.goodsowner.service.AccountService;
import com.esv.freight.customer.module.goodsowner.service.AuditHistoryService; import com.esv.freight.customer.module.goodsowner.service.AuditHistoryService;
...@@ -206,4 +207,31 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i ...@@ -206,4 +207,31 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
accountEntityUpdate.setAccountStatus(GoodsOwnerConstants.OWNER_ACCOUNT_STATUS_UNBLOCK); accountEntityUpdate.setAccountStatus(GoodsOwnerConstants.OWNER_ACCOUNT_STATUS_UNBLOCK);
this.baseMapper.updateById(accountEntityUpdate); this.baseMapper.updateById(accountEntityUpdate);
} }
@Override
public void auditAccount(AccountForm form) {
// 1.判断帐号是否存在
Long accountId = form.getId();
AccountEntity accountEntity = this.getAccountRecordById(accountId);
if (null == accountEntity) {
throw new EException(1001, errorMessageComponent.getGoodsOwnerAccountAudit1001());
} else {
if (GoodsOwnerConstants.OWNER_AUDIT_STATUS_SUCCESS.equals(accountEntity.getAuditStatus())) {
throw new EException(1002, errorMessageComponent.getGoodsOwnerAccountAudit1002());
}
}
// 2.更新帐号审核状态
AccountEntity accountEntityUpdate = new AccountEntity();
accountEntityUpdate.setId(accountId);
accountEntityUpdate.setAuditStatus(form.getAuditStatus());
this.baseMapper.updateById(accountEntityUpdate);
// 3.更新帐号审核历史
AuditHistoryEntity auditHistoryEntity = new AuditHistoryEntity();
auditHistoryEntity.setAccountId(accountId);
auditHistoryEntity.setAuditStatus(form.getAuditStatus());
auditHistoryEntity.setOperateUser(ReqUtils.getRequestHeader(GatewayHeaders.USER_ACCOUNT));
auditHistoryService.getBaseMapper().insert(auditHistoryEntity);
}
} }
\ 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.ValidatorAudit
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorAudit extends Default {
}
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.ValidatorBlock
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorBlock extends Default {
}
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.ValidatorUnblock
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorUnblock extends Default {
}
...@@ -58,3 +58,6 @@ error-message: ...@@ -58,3 +58,6 @@ error-message:
unblock: unblock:
1001: 无效的帐号ID 1001: 无效的帐号ID
1002: 帐号已启用 1002: 帐号已启用
audit:
1001: 无效的帐号ID
1002: 帐号已审核通过
\ No newline at end of file
...@@ -285,4 +285,90 @@ public class GoodsOwnerControllerTest extends BaseTestController { ...@@ -285,4 +285,90 @@ 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
public void e1_auditAccount_failure_test() throws Exception {
String url = "/goodsowner/account/audit";
// 构造数据
AccountForm form = new AccountForm();
form.setId(1L);
form.setAuditStatus(GoodsOwnerConstants.OWNER_AUDIT_STATUS_FAILURE);
form.setRemark(null);
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
public void e2_auditAccount_success_test() throws Exception {
String url = "/goodsowner/account/audit";
// 构造数据
AccountForm form = new AccountForm();
form.setId(1L);
form.setAuditStatus(GoodsOwnerConstants.OWNER_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 e3_auditAccount_success_test() throws Exception {
String url = "/goodsowner/account/audit";
// 构造数据
AccountForm form = new AccountForm();
form.setId(1L);
form.setAuditStatus(GoodsOwnerConstants.OWNER_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"));
}
} }
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