Commit 589fb3fa4d8652ace9c20b3a8c7d226e526eed7a
1 parent
e7afe41d
代码优化
Showing
3 changed files
with
15 additions
and
3 deletions
src/main/java/com/diligrp/xtrade/product/domain/builder/MerchantBuilder.java
... | ... | @@ -19,7 +19,7 @@ public class MerchantBuilder { |
19 | 19 | public static MerchantDo buildDoFromRequest(MerchantRequestDto requestDto) { |
20 | 20 | Integer type = Optional.ofNullable(requestDto.getAccountType()) |
21 | 21 | .map(AccountType::getCode) |
22 | - .orElse(0); | |
22 | + .orElse(null); | |
23 | 23 | MerchantDo merchantDo = new MerchantDo(); |
24 | 24 | merchantDo.setMerName(requestDto.getMerchantName()); |
25 | 25 | merchantDo.setAccountId(requestDto.getAccountId()); | ... | ... |
src/main/java/com/diligrp/xtrade/product/repository/MerchantRepository.java
... | ... | @@ -42,12 +42,11 @@ public class MerchantRepository implements IMerchantRepository { |
42 | 42 | public void add(MerchantDo newMerchantDo) { |
43 | 43 | IKeyGenerator keyGenerator = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.MERCHANT_SEQUENCE); |
44 | 44 | newMerchantDo.setMerId(keyGenerator.nextId()); |
45 | - newMerchantDo.setMarketId("SY001"); | |
46 | 45 | merchantDao.insert(newMerchantDo); |
47 | 46 | } |
48 | 47 | |
49 | 48 | @Override |
50 | 49 | public void update(MerchantDo merchantDo) { |
51 | - | |
50 | + merchantDao.update(merchantDo); | |
52 | 51 | } |
53 | 52 | } | ... | ... |
src/main/java/com/diligrp/xtrade/product/service/impl/MerchantServiceImpl.java
... | ... | @@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
18 | 18 | import org.springframework.stereotype.Service; |
19 | 19 | import org.springframework.transaction.annotation.Transactional; |
20 | 20 | |
21 | +import java.util.Optional; | |
22 | + | |
21 | 23 | @Service |
22 | 24 | public class MerchantServiceImpl implements MerchantService { |
23 | 25 | @Autowired |
... | ... | @@ -42,11 +44,14 @@ public class MerchantServiceImpl implements MerchantService { |
42 | 44 | MerchantDo merchantDo = merchantRepository.getByAccountId(requestDto.getAccountId()); |
43 | 45 | if (merchantDo == null){ |
44 | 46 | merchantDo = MerchantBuilder.buildDoFromRequest(requestDto); |
47 | + merchantDo.setMarketId("SYSGDL"); | |
45 | 48 | merchantRepository.add(merchantDo); |
46 | 49 | } else { |
47 | 50 | if (AccountType.PERSONAL.getCode() != merchantDo.getType()){ |
48 | 51 | throw new ProductException(ExceptionEnum.CARD_MERCHANT_CREATED); |
49 | 52 | } |
53 | + this.updateMerchant(merchantDo, requestDto); | |
54 | + merchantRepository.update(merchantDo); | |
50 | 55 | shopService.updateShopTypeWithMerchant(merchantDo); |
51 | 56 | } |
52 | 57 | //创建市场管理员账户 |
... | ... | @@ -54,4 +59,12 @@ public class MerchantServiceImpl implements MerchantService { |
54 | 59 | return MerchantBuilder.buildResponseFromDo(merchantDo); |
55 | 60 | } |
56 | 61 | |
62 | + private void updateMerchant(MerchantDo merchantDo, MerchantRequestDto requestDto) { | |
63 | + Integer accountType = Optional.ofNullable(requestDto.getAccountType()) | |
64 | + .map(AccountType::getCode).orElse(null); | |
65 | + merchantDo.setMerName(requestDto.getMerchantName()); | |
66 | + merchantDo.setAccountId(requestDto.getAccountId()); | |
67 | + merchantDo.setType(accountType); | |
68 | + merchantDo.setDescription(requestDto.getAddress()); | |
69 | + } | |
57 | 70 | } | ... | ... |