Commit efca6869535143e67350ce2440373248a4787b5f

Authored by miaoguoxin
1 parent 9a830fa9

优化

src/main/java/com/diligrp/xtrade/product/domain/emuns/ResponseCode.java deleted 100644 → 0
1   -package com.diligrp.xtrade.product.domain.emuns;
2   -
3   -import com.diligrp.xtrade.shared.type.IEnumType;
4   -
5   -/**
6   - * @Auther: miaoguoxin
7   - * @Date: 2020/4/22 08:48
8   - * @Description: 响应code枚举
9   - */
10   -public enum ResponseCode implements IEnumType {
11   - ACCOUNT_EXIST(200001,"账号已存在"),
12   - CARD_MERCHANT_CREATED(200002,"该卡已创建商户,请使用用户名密码登录"),
13   - ;
14   -
15   -
16   - private int code;
17   - private String name;
18   -
19   - ResponseCode(int code,String name)
20   - {
21   - this.name = name;
22   - this.code = code;
23   - }
24   -
25   - @Override
26   - public int getCode() {
27   - return this.code;
28   - }
29   -
30   - @Override
31   - public String getName() {
32   - return this.name;
33   - }
34   -}
src/main/java/com/diligrp/xtrade/product/exception/ExceptionEnum.java
1   -package com.diligrp.xtrade.product.exception;
2   -
3   -import java.util.Arrays;
4   -
5   -import com.diligrp.xtrade.shared.type.IEnumType;
6   -
7   -/**
8   - * @ClassName: ExceptionEnum
9   - * @Description TODO(用一句话描述该文件做什么)
10   - * @author yangfan
11   - * @date 2020年4月22日
12   - */
13   -public enum ExceptionEnum implements IEnumType {
14   - SHOP_NOT_EXISTENCE(20001, "SHOP_NOT_EXISTENCE");
15   -
16   - private int code;
17   - private String name;
18   -
19   - ExceptionEnum(int code, String name) {
20   - this.code = code;
21   - this.name = name;
22   - }
23   -
24   - public static ExceptionEnum getByType(int code) {
25   - return Arrays.stream(values())
26   - .filter(exceptionEnum -> exceptionEnum.getCode() == code)
27   - .findFirst()
28   - .orElse(null);
29   - }
30   -
31   - public static String getName(int index) {
32   - return Arrays.stream(ExceptionEnum.values())
33   - .filter(c -> c.getCode() == index)
34   - .findFirst().map(c -> c.name)
35   - .orElse(null);
36   - }
37   -
38   -
39   - public int getCode() {
40   - // TODO Auto-generated method stub
41   - return 0;
42   - }
43   -
44   - @Override
45   - public String getName() {
46   - // TODO Auto-generated method stub
47   - return null;
48   - }
49   -
50   -}
  1 +package com.diligrp.xtrade.product.exception;
  2 +
  3 +import java.util.Arrays;
  4 +
  5 +import com.diligrp.xtrade.shared.type.IEnumType;
  6 +
  7 +/**
  8 + * @ClassName: ExceptionEnum
  9 + * @Description 异常响应
  10 + * @author yangfan
  11 + * @date 2020年4月22日
  12 + */
  13 +public enum ExceptionEnum implements IEnumType {
  14 + SHOP_NOT_EXISTENCE(200001, "SHOP_NOT_EXISTENCE"),
  15 + MERCHANT_ACCOUNT_EXIST(200002,"商户账号已存在"),
  16 + CARD_MERCHANT_CREATED(200003,"该卡已创建商户,请使用用户名密码登录"),
  17 + ;
  18 +
  19 + private int code;
  20 + private String name;
  21 +
  22 + ExceptionEnum(int code, String name) {
  23 + this.code = code;
  24 + this.name = name;
  25 + }
  26 +
  27 + public static ExceptionEnum getByType(int code) {
  28 + return Arrays.stream(values())
  29 + .filter(exceptionEnum -> exceptionEnum.getCode() == code)
  30 + .findFirst()
  31 + .orElse(null);
  32 + }
  33 +
  34 + public static String getName(int index) {
  35 + return Arrays.stream(ExceptionEnum.values())
  36 + .filter(c -> c.getCode() == index)
  37 + .findFirst().map(c -> c.name)
  38 + .orElse(null);
  39 + }
  40 +
  41 +
  42 + public int getCode() {
  43 + return this.code;
  44 + }
  45 +
  46 + @Override
  47 + public String getName() {
  48 + return this.name;
  49 + }
  50 +
  51 +}
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/MerchantServiceImpl.java
... ... @@ -4,10 +4,10 @@ import com.diligrp.xtrade.product.domain.builder.MerchantBuilder;
4 4 import com.diligrp.xtrade.product.domain.dto.MerchantRequestDto;
5 5 import com.diligrp.xtrade.product.domain.dto.MerchantResponseDto;
6 6 import com.diligrp.xtrade.product.domain.emuns.AccountType;
7   -import com.diligrp.xtrade.product.domain.emuns.ResponseCode;
8 7 import com.diligrp.xtrade.product.domain.entity.AccountDo;
9 8 import com.diligrp.xtrade.product.domain.entity.MerchantDo;
10 9 import com.diligrp.xtrade.product.domain.entity.OperatorDo;
  10 +import com.diligrp.xtrade.product.exception.ExceptionEnum;
11 11 import com.diligrp.xtrade.product.exception.ProductException;
12 12 import com.diligrp.xtrade.product.repository.IAccountRepository;
13 13 import com.diligrp.xtrade.product.repository.IMerchantRepository;
... ... @@ -34,7 +34,7 @@ public class MerchantServiceImpl implements MerchantService {
34 34 requestDto.setRealName(operatorDo.getName());
35 35 AccountDo accountDo = accountRepository.getAccountByName(requestDto.getAccountName());
36 36 if (accountDo != null) {
37   - throw new ProductException(ResponseCode.ACCOUNT_EXIST);
  37 + throw new ProductException(ExceptionEnum.MERCHANT_ACCOUNT_EXIST);
38 38 }
39 39 MerchantDo merchantDo = merchantRepository.getByAccountId(requestDto.getAccountId());
40 40 if (merchantDo == null){
... ... @@ -42,7 +42,7 @@ public class MerchantServiceImpl implements MerchantService {
42 42 merchantRepository.add(merchantDo);
43 43 } else {
44 44 if (AccountType.PERSONAL.getCode() != merchantDo.getType()){
45   - throw new ProductException(ResponseCode.CARD_MERCHANT_CREATED);
  45 + throw new ProductException(ExceptionEnum.CARD_MERCHANT_CREATED);
46 46 }
47 47 merchantRepository.update(merchantDo);
48 48 }
... ...