Commit 589fb3fa4d8652ace9c20b3a8c7d226e526eed7a

Authored by miaoguoxin
1 parent e7afe41d

代码优化

src/main/java/com/diligrp/xtrade/product/domain/builder/MerchantBuilder.java
@@ -19,7 +19,7 @@ public class MerchantBuilder { @@ -19,7 +19,7 @@ public class MerchantBuilder {
19 public static MerchantDo buildDoFromRequest(MerchantRequestDto requestDto) { 19 public static MerchantDo buildDoFromRequest(MerchantRequestDto requestDto) {
20 Integer type = Optional.ofNullable(requestDto.getAccountType()) 20 Integer type = Optional.ofNullable(requestDto.getAccountType())
21 .map(AccountType::getCode) 21 .map(AccountType::getCode)
22 - .orElse(0); 22 + .orElse(null);
23 MerchantDo merchantDo = new MerchantDo(); 23 MerchantDo merchantDo = new MerchantDo();
24 merchantDo.setMerName(requestDto.getMerchantName()); 24 merchantDo.setMerName(requestDto.getMerchantName());
25 merchantDo.setAccountId(requestDto.getAccountId()); 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,12 +42,11 @@ public class MerchantRepository implements IMerchantRepository {
42 public void add(MerchantDo newMerchantDo) { 42 public void add(MerchantDo newMerchantDo) {
43 IKeyGenerator keyGenerator = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.MERCHANT_SEQUENCE); 43 IKeyGenerator keyGenerator = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.MERCHANT_SEQUENCE);
44 newMerchantDo.setMerId(keyGenerator.nextId()); 44 newMerchantDo.setMerId(keyGenerator.nextId());
45 - newMerchantDo.setMarketId("SY001");  
46 merchantDao.insert(newMerchantDo); 45 merchantDao.insert(newMerchantDo);
47 } 46 }
48 47
49 @Override 48 @Override
50 public void update(MerchantDo merchantDo) { 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,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
19 import org.springframework.transaction.annotation.Transactional; 19 import org.springframework.transaction.annotation.Transactional;
20 20
  21 +import java.util.Optional;
  22 +
21 @Service 23 @Service
22 public class MerchantServiceImpl implements MerchantService { 24 public class MerchantServiceImpl implements MerchantService {
23 @Autowired 25 @Autowired
@@ -42,11 +44,14 @@ public class MerchantServiceImpl implements MerchantService { @@ -42,11 +44,14 @@ public class MerchantServiceImpl implements MerchantService {
42 MerchantDo merchantDo = merchantRepository.getByAccountId(requestDto.getAccountId()); 44 MerchantDo merchantDo = merchantRepository.getByAccountId(requestDto.getAccountId());
43 if (merchantDo == null){ 45 if (merchantDo == null){
44 merchantDo = MerchantBuilder.buildDoFromRequest(requestDto); 46 merchantDo = MerchantBuilder.buildDoFromRequest(requestDto);
  47 + merchantDo.setMarketId("SYSGDL");
45 merchantRepository.add(merchantDo); 48 merchantRepository.add(merchantDo);
46 } else { 49 } else {
47 if (AccountType.PERSONAL.getCode() != merchantDo.getType()){ 50 if (AccountType.PERSONAL.getCode() != merchantDo.getType()){
48 throw new ProductException(ExceptionEnum.CARD_MERCHANT_CREATED); 51 throw new ProductException(ExceptionEnum.CARD_MERCHANT_CREATED);
49 } 52 }
  53 + this.updateMerchant(merchantDo, requestDto);
  54 + merchantRepository.update(merchantDo);
50 shopService.updateShopTypeWithMerchant(merchantDo); 55 shopService.updateShopTypeWithMerchant(merchantDo);
51 } 56 }
52 //创建市场管理员账户 57 //创建市场管理员账户
@@ -54,4 +59,12 @@ public class MerchantServiceImpl implements MerchantService { @@ -54,4 +59,12 @@ public class MerchantServiceImpl implements MerchantService {
54 return MerchantBuilder.buildResponseFromDo(merchantDo); 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 }