Commit cb720a7afe390af265a9ed765fd47b43c45a7863

Authored by yangfan
2 parents 5f41a972 7c177029
src/main/java/com/diligrp/xtrade/order/domain/builder/DefaultOrderCreator.java
@@ -33,21 +33,32 @@ public class DefaultOrderCreator { @@ -33,21 +33,32 @@ public class DefaultOrderCreator {
33 33
34 private OrderCreateRequestDto orderCreateDto; 34 private OrderCreateRequestDto orderCreateDto;
35 35
36 - private DefaultOrderCreator(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto) { 36 + private DefaultOrderCreator(AccountDto saccountDto, AccountDto baccountDto, OrderCreateRequestDto orderCreateDto) {
37 this.saccountDto = saccountDto; 37 this.saccountDto = saccountDto;
38 this.orderCreateDto = orderCreateDto; 38 this.orderCreateDto = orderCreateDto;
  39 + this.baccountDto = baccountDto;
39 } 40 }
40 41
41 public static DefaultOrderCreator builder(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto, 42 public static DefaultOrderCreator builder(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto,
42 Long orderId) { 43 Long orderId) {
43 orderCreateDto.setOrderId(orderId); 44 orderCreateDto.setOrderId(orderId);
44 - return new DefaultOrderCreator(saccountDto, orderCreateDto); 45 + return new DefaultOrderCreator(saccountDto, null, orderCreateDto);
  46 + }
  47 +
  48 + public static DefaultOrderCreator builder(AccountDto saccountDto, AccountDto baccountDto,
  49 + OrderCreateRequestDto orderCreateDto, Long orderId) {
  50 + orderCreateDto.setOrderId(orderId);
  51 + return new DefaultOrderCreator(saccountDto, baccountDto, orderCreateDto);
  52 + }
  53 +
  54 + public static DefaultOrderCreator builder(AccountDto baccountDto) {
  55 + return new DefaultOrderCreator(null, baccountDto, null);
45 } 56 }
46 57
47 public OrderDo createOrder() { 58 public OrderDo createOrder() {
48 return this.orderDo; 59 return this.orderDo;
49 } 60 }
50 - 61 +
51 public List<OrderItemDo> createOrderItems() { 62 public List<OrderItemDo> createOrderItems() {
52 return this.items; 63 return this.items;
53 } 64 }
src/main/java/com/diligrp/xtrade/order/domain/dto/OrderQueryResponseDto.java
@@ -82,6 +82,9 @@ public class OrderQueryResponseDto { @@ -82,6 +82,9 @@ public class OrderQueryResponseDto {
82 //支付时间 82 //支付时间
83 private LocalDateTime payTime; 83 private LocalDateTime payTime;
84 84
  85 + //创建时间
  86 + private LocalDateTime createdTime;
  87 +
85 //订单详情 88 //订单详情
86 private List<OrderItemDto> items = new ArrayList<OrderItemDto>(); 89 private List<OrderItemDto> items = new ArrayList<OrderItemDto>();
87 90
@@ -280,5 +283,13 @@ public class OrderQueryResponseDto { @@ -280,5 +283,13 @@ public class OrderQueryResponseDto {
280 public void setOrderType(Integer orderType) { 283 public void setOrderType(Integer orderType) {
281 this.orderType = orderType; 284 this.orderType = orderType;
282 } 285 }
  286 +
  287 + public LocalDateTime getCreatedTime() {
  288 + return createdTime;
  289 + }
  290 +
  291 + public void setCreatedTime(LocalDateTime createdTime) {
  292 + this.createdTime = createdTime;
  293 + }
283 294
284 } 295 }
src/main/java/com/diligrp/xtrade/order/rpc/feign/AccountResolver.java
1 -package com.diligrp.xtrade.order.rpc.feign;  
2 -  
3 -import javax.annotation.Resource;  
4 -  
5 -import org.springframework.http.HttpStatus;  
6 -import org.springframework.stereotype.Component;  
7 -  
8 -import com.diligrp.xtrade.order.domain.dto.AccountDto;  
9 -import com.diligrp.xtrade.order.exception.OrderException;  
10 -import com.diligrp.xtrade.shared.domain.Message;  
11 -  
12 -/**  
13 - * @ClassName: AccountResolver  
14 - * @Description 远程卡务调用解析  
15 - * @author zhangxing  
16 - * @date 2020年4月22日  
17 - */  
18 -@Component  
19 -public class AccountResolver {  
20 -  
21 - @Resource  
22 - private AccountRPC accountRPC;  
23 -  
24 - /**  
25 - * 根据id获取账户信息  
26 - */  
27 - public AccountDto getAccount(Long accountId) {  
28 - Message<AccountDto> message = accountRPC.getDltAccount(accountId);  
29 - if (!HttpStatus.OK.equals(message.getCode())) {  
30 - throw new OrderException(message.getMessage());  
31 - }  
32 - return message.getData();  
33 - }  
34 -} 1 +package com.diligrp.xtrade.order.rpc.feign;
  2 +
  3 +import javax.annotation.Resource;
  4 +
  5 +import org.springframework.http.HttpStatus;
  6 +import org.springframework.stereotype.Component;
  7 +
  8 +import com.diligrp.xtrade.order.domain.dto.AccountDto;
  9 +import com.diligrp.xtrade.order.exception.OrderException;
  10 +import com.diligrp.xtrade.shared.domain.Message;
  11 +
  12 +/**
  13 + * @ClassName: AccountResolver
  14 + * @Description 远程卡务调用解析
  15 + * @author zhangxing
  16 + * @date 2020年4月22日
  17 + */
  18 +@Component
  19 +public class AccountResolver {
  20 +
  21 + @Resource
  22 + private AccountRPC accountRPC;
  23 +
  24 + /**
  25 + * 根据id获取账户信息
  26 + */
  27 + public AccountDto getAccount(Long accountId) {
  28 + Message<AccountDto> message = accountRPC.getDltAccount(accountId);
  29 + if (HttpStatus.OK.value() != message.getCode()) {
  30 + throw new OrderException(message.getMessage());
  31 + }
  32 + return message.getData();
  33 + }
  34 +}
src/main/java/com/diligrp/xtrade/order/service/OrderService.java
1 package com.diligrp.xtrade.order.service; 1 package com.diligrp.xtrade.order.service;
2 2
3 -import java.util.List;  
4 -  
5 import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto; 3 import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
6 import com.diligrp.xtrade.order.domain.dto.OrderQueryRequestDto; 4 import com.diligrp.xtrade.order.domain.dto.OrderQueryRequestDto;
7 import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto; 5 import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
  6 +import com.diligrp.xtrade.shared.domain.Page;
8 7
9 /** 8 /**
10 * 9 *
@@ -25,7 +24,7 @@ public interface OrderService { @@ -25,7 +24,7 @@ public interface OrderService {
25 * @Title orderLists 24 * @Title orderLists
26 * @Description 获取订单列表 25 * @Description 获取订单列表
27 */ 26 */
28 - List<OrderQueryResponseDto> orderLists(OrderQueryRequestDto orderQueryRequestDto); 27 + Page<OrderQueryResponseDto> orderLists(OrderQueryRequestDto orderQueryRequestDto);
29 28
30 /** 29 /**
31 * @Title orderDetail 30 * @Title orderDetail
src/main/java/com/diligrp/xtrade/order/service/impl/OrderServiceImpl.java
@@ -22,6 +22,7 @@ import com.diligrp.xtrade.order.domain.emuns.IdGenerator; @@ -22,6 +22,7 @@ import com.diligrp.xtrade.order.domain.emuns.IdGenerator;
22 import com.diligrp.xtrade.order.domain.entity.OrderDo; 22 import com.diligrp.xtrade.order.domain.entity.OrderDo;
23 import com.diligrp.xtrade.order.rpc.feign.AccountResolver; 23 import com.diligrp.xtrade.order.rpc.feign.AccountResolver;
24 import com.diligrp.xtrade.order.service.OrderService; 24 import com.diligrp.xtrade.order.service.OrderService;
  25 +import com.diligrp.xtrade.shared.domain.Page;
25 import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager; 26 import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
26 27
27 @Service("orderService") 28 @Service("orderService")
@@ -67,17 +68,23 @@ public class OrderServiceImpl implements OrderService { @@ -67,17 +68,23 @@ public class OrderServiceImpl implements OrderService {
67 68
68 // TODO need modify because of change 69 // TODO need modify because of change
69 @Override 70 @Override
70 - public List<OrderQueryResponseDto> orderLists(OrderQueryRequestDto orderQueryRequestDto) { 71 + public Page<OrderQueryResponseDto> orderLists(OrderQueryRequestDto orderQueryRequestDto) {
  72 + Page<OrderQueryResponseDto> orderPage = new Page<OrderQueryResponseDto>();
  73 + List<OrderQueryResponseDto> roResponseDtos = new ArrayList<OrderQueryResponseDto>();
  74 + orderPage.setData(roResponseDtos);
71 OrderDo order = new OrderDo(); 75 OrderDo order = new OrderDo();
72 BeanUtils.copyProperties(orderQueryRequestDto, order); 76 BeanUtils.copyProperties(orderQueryRequestDto, order);
  77 + int total = orderDao.selectEntryListCount(order);
  78 + if (total == 0) {
  79 + return orderPage;
  80 + }
73 List<OrderDo> orderDos = orderDao.selectEntryList(order); 81 List<OrderDo> orderDos = orderDao.selectEntryList(order);
74 - List<OrderQueryResponseDto> roResponseDtos = new ArrayList<OrderQueryResponseDto>();  
75 for (OrderDo orderDo : orderDos) { 82 for (OrderDo orderDo : orderDos) {
76 OrderQueryResponseDto orderQueryResponseDto = new OrderQueryResponseDto(); 83 OrderQueryResponseDto orderQueryResponseDto = new OrderQueryResponseDto();
77 BeanUtils.copyProperties(orderDo, orderQueryResponseDto); 84 BeanUtils.copyProperties(orderDo, orderQueryResponseDto);
78 roResponseDtos.add(orderQueryResponseDto); 85 roResponseDtos.add(orderQueryResponseDto);
79 } 86 }
80 - return roResponseDtos; 87 + return orderPage;
81 } 88 }
82 89
83 // TODO need modify because of change 90 // TODO need modify because of change
src/main/java/com/diligrp/xtrade/product/dao/ShopDao.java
@@ -6,24 +6,26 @@ import org.apache.ibatis.annotations.Mapper; @@ -6,24 +6,26 @@ import org.apache.ibatis.annotations.Mapper;
6 6
7 import com.diligrp.xtrade.product.domain.dto.ShopQueryDto; 7 import com.diligrp.xtrade.product.domain.dto.ShopQueryDto;
8 import com.diligrp.xtrade.product.domain.entity.ShopDo; 8 import com.diligrp.xtrade.product.domain.entity.ShopDo;
  9 +import org.apache.ibatis.annotations.Param;
  10 +
9 /** 11 /**
10 - * 12 + * @author yangfan
11 * @ClassName: ShopDao 13 * @ClassName: ShopDao
12 * @Description 店铺dao 14 * @Description 店铺dao
13 - * @author yangfan  
14 * @date 2020年4月21日 15 * @date 2020年4月21日
15 */ 16 */
16 @Mapper 17 @Mapper
17 public interface ShopDao { 18 public interface ShopDao {
18 -  
19 - void insert(ShopDo shop);  
20 -  
21 - void update(ShopDo shop);  
22 -  
23 - ShopDo selectByShopId(Long shopId);  
24 -  
25 - List<ShopDo> selectByMerId(Long merId);  
26 -  
27 - List<ShopDo> selectShop(ShopQueryDto shopQueryDto);  
28 - 19 +
  20 + void insert(ShopDo shop);
  21 +
  22 + void update(ShopDo shop);
  23 +
  24 + ShopDo selectByShopId(Long shopId);
  25 +
  26 + List<ShopDo> selectByMerId(Long merId);
  27 +
  28 + List<ShopDo> selectShop(ShopQueryDto shopQueryDto);
  29 +
  30 + void updateTypeByMerId(@Param("type") Integer type, @Param("merId") Long merId);
29 } 31 }
src/main/java/com/diligrp/xtrade/product/domain/builder/MerchantAccountBuilder.java 0 → 100644
  1 +package com.diligrp.xtrade.product.domain.builder;
  2 +
  3 +import com.alibaba.nacos.common.utils.Md5Utils;
  4 +import com.diligrp.xtrade.product.domain.dto.MerchantRequestDto;
  5 +import com.diligrp.xtrade.product.domain.emuns.AccountStatus;
  6 +import com.diligrp.xtrade.product.domain.entity.AccountDo;
  7 +
  8 +import java.time.LocalDateTime;
  9 +
  10 +/**
  11 + * @Auther: miaoguoxin
  12 + * @Date: 2020/4/23 09:23
  13 + */
  14 +public class MerchantAccountBuilder {
  15 +
  16 + public static AccountDo buildDoFromMerchant(MerchantRequestDto requestDto, Long merId) {
  17 + String password = String.format("%s_%s",
  18 + requestDto.getAccountName(), requestDto.getPassword());
  19 + AccountDo newAccountDo = new AccountDo();
  20 + newAccountDo.setName(requestDto.getAccountName());
  21 + newAccountDo.setRealName(requestDto.getRealName());
  22 + newAccountDo.setPassword(Md5Utils.getMD5(password, "UTF-8"));
  23 + newAccountDo.setMobile(requestDto.getMobile());
  24 + newAccountDo.setStatus(AccountStatus.NORMAL.getCode());
  25 + newAccountDo.setIsAdmin(1);
  26 + newAccountDo.setMerId(merId);
  27 + newAccountDo.setCreatedTime(LocalDateTime.now());
  28 + return newAccountDo;
  29 + }
  30 +}
src/main/java/com/diligrp/xtrade/product/domain/builder/MerchantBuilder.java
@@ -16,10 +16,10 @@ import java.util.Optional; @@ -16,10 +16,10 @@ import java.util.Optional;
16 */ 16 */
17 public class MerchantBuilder { 17 public class MerchantBuilder {
18 18
19 - public static MerchantDo request2Entity(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());
@@ -30,7 +30,7 @@ public class MerchantBuilder { @@ -30,7 +30,7 @@ public class MerchantBuilder {
30 return merchantDo; 30 return merchantDo;
31 } 31 }
32 32
33 - public static MerchantResponseDto entity2Response(MerchantDo merchantDo){ 33 + public static MerchantResponseDto buildResponseFromDo(MerchantDo merchantDo){
34 MerchantResponseDto responseDto = new MerchantResponseDto(); 34 MerchantResponseDto responseDto = new MerchantResponseDto();
35 BeanUtils.copyProperties(merchantDo,responseDto); 35 BeanUtils.copyProperties(merchantDo,responseDto);
36 responseDto.setType(AccountType.getAccountType(merchantDo.getType())); 36 responseDto.setType(AccountType.getAccountType(merchantDo.getType()));
src/main/java/com/diligrp/xtrade/product/repository/AccountRepository.java
1 package com.diligrp.xtrade.product.repository; 1 package com.diligrp.xtrade.product.repository;
2 2
  3 +import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;
3 import com.diligrp.xtrade.product.domain.entity.AccountDo; 4 import com.diligrp.xtrade.product.domain.entity.AccountDo;
4 import com.diligrp.xtrade.product.domain.entity.OperatorDo; 5 import com.diligrp.xtrade.product.domain.entity.OperatorDo;
  6 +import com.diligrp.xtrade.shared.sequence.IKeyGenerator;
  7 +import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
  8 +import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.stereotype.Repository; 9 import org.springframework.stereotype.Repository;
6 10
7 import java.util.ArrayList; 11 import java.util.ArrayList;
@@ -15,6 +19,8 @@ import java.util.List; @@ -15,6 +19,8 @@ import java.util.List;
15 @Repository 19 @Repository
16 public class AccountRepository implements IAccountRepository { 20 public class AccountRepository implements IAccountRepository {
17 private final static List<AccountDo> ACCOUNT_DOS = new ArrayList<>(); 21 private final static List<AccountDo> ACCOUNT_DOS = new ArrayList<>();
  22 + @Autowired
  23 + private KeyGeneratorManager keyGeneratorManager;
18 @Override 24 @Override
19 public OperatorDo getOperator() { 25 public OperatorDo getOperator() {
20 OperatorDo operatorDo = new OperatorDo(); 26 OperatorDo operatorDo = new OperatorDo();
@@ -35,6 +41,8 @@ public class AccountRepository implements IAccountRepository { @@ -35,6 +41,8 @@ public class AccountRepository implements IAccountRepository {
35 41
36 @Override 42 @Override
37 public void add(AccountDo accountDo) { 43 public void add(AccountDo accountDo) {
  44 + IKeyGenerator keyGenerator = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.ACCOUNT_SEQUENCE);
  45 + accountDo.setId(keyGenerator.nextId());
38 ACCOUNT_DOS.add(accountDo); 46 ACCOUNT_DOS.add(accountDo);
39 } 47 }
40 } 48 }
src/main/java/com/diligrp/xtrade/product/repository/MerchantRepository.java
@@ -42,16 +42,11 @@ public class MerchantRepository implements IMerchantRepository { @@ -42,16 +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 - merchantDo.setModifiedTime(LocalDateTime.now());  
52 - ShopDo shopDo = new ShopDo();  
53 - shopDo.setType(AccountType.PUBLIC.getCode());  
54 - shopDo.setMerId(merchantDo.getMerId());  
55 - shopDao.update(shopDo); 50 + merchantDao.update(merchantDo);
56 } 51 }
57 } 52 }
src/main/java/com/diligrp/xtrade/product/service/AccountService.java
@@ -10,7 +10,5 @@ import com.diligrp.xtrade.product.domain.entity.MerchantDo; @@ -10,7 +10,5 @@ import com.diligrp.xtrade.product.domain.entity.MerchantDo;
10 */ 10 */
11 public interface AccountService { 11 public interface AccountService {
12 12
13 - AccountDo build(MerchantRequestDto requestDto, MerchantDo merchantDo) throws Exception;  
14 -  
15 - void create(MerchantRequestDto requestDto, MerchantDo merchantDo) throws Exception; 13 + void create(MerchantRequestDto requestDto, MerchantDo merchantDo);
16 } 14 }
src/main/java/com/diligrp/xtrade/product/service/ShopService.java
@@ -4,10 +4,11 @@ import java.util.List; @@ -4,10 +4,11 @@ import java.util.List;
4 4
5 import com.diligrp.xtrade.product.domain.dto.ShopDto; 5 import com.diligrp.xtrade.product.domain.dto.ShopDto;
6 import com.diligrp.xtrade.product.domain.dto.ShopQueryDto; 6 import com.diligrp.xtrade.product.domain.dto.ShopQueryDto;
  7 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
7 import com.diligrp.xtrade.product.domain.entity.ShopDo; 8 import com.diligrp.xtrade.product.domain.entity.ShopDo;
8 9
9 public interface ShopService { 10 public interface ShopService {
10 - 11 +
11 /** 12 /**
12 * @Title insert 13 * @Title insert
13 * @Description 保存shop 14 * @Description 保存shop
@@ -15,18 +16,18 @@ public interface ShopService { @@ -15,18 +16,18 @@ public interface ShopService {
15 * @throws 16 * @throws
16 */ 17 */
17 void insert(ShopDto shop); 18 void insert(ShopDto shop);
18 - 19 +
19 /** 20 /**
20 - * 21 + *
21 * @Title update 22 * @Title update
22 * @Description 修改 23 * @Description 修改
23 * @param shop 24 * @param shop
24 * @throws 25 * @throws
25 */ 26 */
26 void update(ShopDto shop); 27 void update(ShopDto shop);
27 - 28 +
28 /** 29 /**
29 - * 30 + *
30 * @Title selectByMerId 31 * @Title selectByMerId
31 * @Description 店铺id查询 32 * @Description 店铺id查询
32 * @param merId 33 * @param merId
@@ -34,9 +35,9 @@ public interface ShopService { @@ -34,9 +35,9 @@ public interface ShopService {
34 * @throws 35 * @throws
35 */ 36 */
36 ShopDo selectByShopId(Long shopId); 37 ShopDo selectByShopId(Long shopId);
37 - 38 +
38 /** 39 /**
39 - * 40 + *
40 * @Title selectByMerId 41 * @Title selectByMerId
41 * @Description 根据商户id获取名下全部商铺 42 * @Description 根据商户id获取名下全部商铺
42 * @param merId 43 * @param merId
@@ -44,9 +45,9 @@ public interface ShopService { @@ -44,9 +45,9 @@ public interface ShopService {
44 * @throws 45 * @throws
45 */ 46 */
46 List<ShopDo> selectShopByMerId(Long merId); 47 List<ShopDo> selectShopByMerId(Long merId);
47 - 48 +
48 /** 49 /**
49 - * 50 + *
50 * @Title selectShop 51 * @Title selectShop
51 * @Description 商铺查询 52 * @Description 商铺查询
52 * @param shopQuery 53 * @param shopQuery
@@ -54,4 +55,6 @@ public interface ShopService { @@ -54,4 +55,6 @@ public interface ShopService {
54 * @throws 55 * @throws
55 */ 56 */
56 List<ShopDo> selectShop(ShopQueryDto shopQuery); 57 List<ShopDo> selectShop(ShopQueryDto shopQuery);
  58 +
  59 + void updateShopTypeWithMerchant(MerchantDo merchantDo);
57 } 60 }
src/main/java/com/diligrp/xtrade/product/service/impl/AccountServiceImpl.java
1 package com.diligrp.xtrade.product.service.impl; 1 package com.diligrp.xtrade.product.service.impl;
2 2
3 -import com.alibaba.nacos.common.utils.Md5Utils; 3 +import com.diligrp.xtrade.product.domain.builder.MerchantAccountBuilder;
4 import com.diligrp.xtrade.product.domain.dto.MerchantRequestDto; 4 import com.diligrp.xtrade.product.domain.dto.MerchantRequestDto;
5 -import com.diligrp.xtrade.product.domain.emuns.AccountStatus;  
6 -import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;  
7 import com.diligrp.xtrade.product.domain.entity.AccountDo; 5 import com.diligrp.xtrade.product.domain.entity.AccountDo;
8 import com.diligrp.xtrade.product.domain.entity.MerchantDo; 6 import com.diligrp.xtrade.product.domain.entity.MerchantDo;
9 import com.diligrp.xtrade.product.repository.IAccountRepository; 7 import com.diligrp.xtrade.product.repository.IAccountRepository;
10 import com.diligrp.xtrade.product.service.AccountService; 8 import com.diligrp.xtrade.product.service.AccountService;
11 -import com.diligrp.xtrade.shared.sequence.IKeyGenerator;  
12 -import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;  
13 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
15 11
16 -import java.time.LocalDateTime;  
17 -  
18 /** 12 /**
19 * @Auther: miaoguoxin 13 * @Auther: miaoguoxin
20 * @Date: 2020/4/22 11:10 14 * @Date: 2020/4/22 11:10
@@ -23,30 +17,10 @@ import java.time.LocalDateTime; @@ -23,30 +17,10 @@ import java.time.LocalDateTime;
23 public class AccountServiceImpl implements AccountService { 17 public class AccountServiceImpl implements AccountService {
24 @Autowired 18 @Autowired
25 private IAccountRepository accountRepository; 19 private IAccountRepository accountRepository;
26 - @Autowired  
27 - private KeyGeneratorManager keyGeneratorManager;  
28 -  
29 - @Override  
30 - public AccountDo build(MerchantRequestDto requestDto, MerchantDo merchantDo) throws Exception {  
31 - String password = String.format("%s_%s",  
32 - requestDto.getAccountName(), requestDto.getPassword());  
33 - AccountDo newAccountDo = new AccountDo();  
34 - newAccountDo.setName(requestDto.getAccountName());  
35 - newAccountDo.setRealName(requestDto.getRealName());  
36 - newAccountDo.setPassword(Md5Utils.getMD5(password, "UTF-8"));  
37 - newAccountDo.setMobile(requestDto.getMobile());  
38 - newAccountDo.setStatus(AccountStatus.NORMAL.getCode());  
39 - newAccountDo.setIsAdmin(1);  
40 - newAccountDo.setMerId(merchantDo.getMerId());  
41 - newAccountDo.setCreatedTime(LocalDateTime.now());  
42 - IKeyGenerator keyGenerator = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.ACCOUNT_SEQUENCE);  
43 - newAccountDo.setId(keyGenerator.nextId());  
44 - return newAccountDo;  
45 - }  
46 20
47 @Override 21 @Override
48 - public void create(MerchantRequestDto requestDto, MerchantDo merchantDo) throws Exception {  
49 - AccountDo newAccountDo = this.build(requestDto, merchantDo); 22 + public void create(MerchantRequestDto requestDto, MerchantDo merchantDo) {
  23 + AccountDo newAccountDo = MerchantAccountBuilder.buildDoFromMerchant(requestDto, merchantDo.getMerId());
50 accountRepository.add(newAccountDo); 24 accountRepository.add(newAccountDo);
51 } 25 }
52 26
src/main/java/com/diligrp/xtrade/product/service/impl/MerchantServiceImpl.java
@@ -13,10 +13,13 @@ import com.diligrp.xtrade.product.repository.IAccountRepository; @@ -13,10 +13,13 @@ import com.diligrp.xtrade.product.repository.IAccountRepository;
13 import com.diligrp.xtrade.product.repository.IMerchantRepository; 13 import com.diligrp.xtrade.product.repository.IMerchantRepository;
14 import com.diligrp.xtrade.product.service.AccountService; 14 import com.diligrp.xtrade.product.service.AccountService;
15 import com.diligrp.xtrade.product.service.MerchantService; 15 import com.diligrp.xtrade.product.service.MerchantService;
  16 +import com.diligrp.xtrade.product.service.ShopService;
16 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
18 import org.springframework.transaction.annotation.Transactional; 19 import org.springframework.transaction.annotation.Transactional;
19 20
  21 +import java.util.Optional;
  22 +
20 @Service 23 @Service
21 public class MerchantServiceImpl implements MerchantService { 24 public class MerchantServiceImpl implements MerchantService {
22 @Autowired 25 @Autowired
@@ -25,6 +28,8 @@ public class MerchantServiceImpl implements MerchantService { @@ -25,6 +28,8 @@ public class MerchantServiceImpl implements MerchantService {
25 private IMerchantRepository merchantRepository; 28 private IMerchantRepository merchantRepository;
26 @Autowired 29 @Autowired
27 private AccountService accountService; 30 private AccountService accountService;
  31 + @Autowired
  32 + private ShopService shopService;
28 33
29 @Override 34 @Override
30 @Transactional(rollbackFor = Exception.class) 35 @Transactional(rollbackFor = Exception.class)
@@ -38,17 +43,28 @@ public class MerchantServiceImpl implements MerchantService { @@ -38,17 +43,28 @@ public class MerchantServiceImpl implements MerchantService {
38 } 43 }
39 MerchantDo merchantDo = merchantRepository.getByAccountId(requestDto.getAccountId()); 44 MerchantDo merchantDo = merchantRepository.getByAccountId(requestDto.getAccountId());
40 if (merchantDo == null){ 45 if (merchantDo == null){
41 - merchantDo = MerchantBuilder.request2Entity(requestDto); 46 + merchantDo = MerchantBuilder.buildDoFromRequest(requestDto);
  47 + merchantDo.setMarketId("SYSGDL");
42 merchantRepository.add(merchantDo); 48 merchantRepository.add(merchantDo);
43 } else { 49 } else {
44 if (AccountType.PERSONAL.getCode() != merchantDo.getType()){ 50 if (AccountType.PERSONAL.getCode() != merchantDo.getType()){
45 throw new ProductException(ExceptionEnum.CARD_MERCHANT_CREATED); 51 throw new ProductException(ExceptionEnum.CARD_MERCHANT_CREATED);
46 } 52 }
  53 + this.updateMerchant(merchantDo, requestDto);
47 merchantRepository.update(merchantDo); 54 merchantRepository.update(merchantDo);
  55 + shopService.updateShopTypeWithMerchant(merchantDo);
48 } 56 }
49 //创建市场管理员账户 57 //创建市场管理员账户
50 accountService.create(requestDto, merchantDo); 58 accountService.create(requestDto, merchantDo);
51 - return MerchantBuilder.entity2Response(merchantDo); 59 + return MerchantBuilder.buildResponseFromDo(merchantDo);
52 } 60 }
53 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 + }
54 } 70 }
src/main/java/com/diligrp/xtrade/product/service/impl/ShopServiceImpl.java
1 package com.diligrp.xtrade.product.service.impl; 1 package com.diligrp.xtrade.product.service.impl;
2 2
  3 +import java.time.LocalDateTime;
3 import java.util.List; 4 import java.util.List;
4 5
  6 +import com.diligrp.xtrade.product.domain.emuns.AccountType;
  7 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
5 import org.springframework.beans.BeanUtils; 8 import org.springframework.beans.BeanUtils;
6 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
@@ -68,4 +71,9 @@ public class ShopServiceImpl implements ShopService { @@ -68,4 +71,9 @@ public class ShopServiceImpl implements ShopService {
68 return shops; 71 return shops;
69 } 72 }
70 73
  74 + @Override
  75 + public void updateShopTypeWithMerchant(MerchantDo merchantDo) {
  76 + shopDao.updateTypeByMerId(AccountType.PUBLIC.getCode(), merchantDo.getMerId());
  77 + }
  78 +
71 } 79 }
src/main/resources/mapping/com/diligrp/xtrade/product/ShopDao.xml
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 <mapper namespace="com.diligrp.xtrade.product.dao.ShopDao"> 3 <mapper namespace="com.diligrp.xtrade.product.dao.ShopDao">
4 - 4 +
5 <sql id="QUERY_COLUMN_LIST"> 5 <sql id="QUERY_COLUMN_LIST">
6 <![CDATA[ 6 <![CDATA[
7 `id`, `shop_id` AS shopId, `shop_name` AS shopName, `address`, `mer_id` AS merId, `type`, `status`, 7 `id`, `shop_id` AS shopId, `shop_name` AS shopName, `address`, `mer_id` AS merId, `type`, `status`,
@@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
33 <if test="selfShop != null and selfShop != ''"><![CDATA[AND self_shop = #{selfShop}]]></if> 33 <if test="selfShop != null and selfShop != ''"><![CDATA[AND self_shop = #{selfShop}]]></if>
34 </where> 34 </where>
35 </sql> 35 </sql>
36 - 36 +
37 <insert id="insert" parameterType="com.diligrp.xtrade.product.domain.entity.ShopDo"> 37 <insert id="insert" parameterType="com.diligrp.xtrade.product.domain.entity.ShopDo">
38 <![CDATA[ 38 <![CDATA[
39 INSERT INTO `xt_shop`(`id`, `shop_id`, `shop_name`, `self_shop`, `mer_id`, `main_biz`, `type`, `status`, `address`, `description`, `created_time`, `modified_time`) 39 INSERT INTO `xt_shop`(`id`, `shop_id`, `shop_name`, `self_shop`, `mer_id`, `main_biz`, `type`, `status`, `address`, `description`, `created_time`, `modified_time`)
@@ -42,21 +42,27 @@ @@ -42,21 +42,27 @@
42 </insert> 42 </insert>
43 <select id="selectByShopId" parameterType="long" resultType="com.diligrp.xtrade.product.domain.entity.ShopDo"> 43 <select id="selectByShopId" parameterType="long" resultType="com.diligrp.xtrade.product.domain.entity.ShopDo">
44 <![CDATA[ 44 <![CDATA[
45 - SELECT 45 + SELECT
46 ]]> 46 ]]>
47 <include refid="QUERY_COLUMN_LIST" /> 47 <include refid="QUERY_COLUMN_LIST" />
48 <![CDATA[ 48 <![CDATA[
49 FROM `xt_shop` WHERE shop_id = #{shopId} 49 FROM `xt_shop` WHERE shop_id = #{shopId}
50 ]]> 50 ]]>
51 </select> 51 </select>
52 - <update id="update" parameterType="com.diligrp.xtrade.product.domain.entity.ShopDo"> 52 + <update id="update" parameterType="com.diligrp.xtrade.product.domain.entity.ShopDo">
53 <![CDATA[UPDATE `xt_shop`]]> 53 <![CDATA[UPDATE `xt_shop`]]>
54 <include refid="UPDATE_COLUMN_SET" /> 54 <include refid="UPDATE_COLUMN_SET" />
55 <![CDATA[WHERE shop_id = #{shopId}]]> 55 <![CDATA[WHERE shop_id = #{shopId}]]>
56 </update> 56 </update>
57 - <select id="selectByMerId" parameterType="long" resultType="com.diligrp.xtrade.product.domain.entity.ShopDo"> 57 + <update id="updateTypeByMerId">
  58 + UPDATE xt_shop
  59 + SET type = #{type},
  60 + modified_time = now()
  61 + WHERE mer_id = #{merId}
  62 + </update>
  63 + <select id="selectByMerId" parameterType="long" resultType="com.diligrp.xtrade.product.domain.entity.ShopDo">
58 <![CDATA[ 64 <![CDATA[
59 - SELECT 65 + SELECT
60 ]]> 66 ]]>
61 <include refid="QUERY_COLUMN_LIST" /> 67 <include refid="QUERY_COLUMN_LIST" />
62 <![CDATA[ 68 <![CDATA[
@@ -65,12 +71,12 @@ @@ -65,12 +71,12 @@
65 </select> 71 </select>
66 <select id="selectShop" parameterType="com.diligrp.xtrade.product.domain.dto.ShopQueryDto" resultType="com.diligrp.xtrade.product.domain.entity.ShopDo"> 72 <select id="selectShop" parameterType="com.diligrp.xtrade.product.domain.dto.ShopQueryDto" resultType="com.diligrp.xtrade.product.domain.entity.ShopDo">
67 <![CDATA[ 73 <![CDATA[
68 - SELECT 74 + SELECT
69 ]]> 75 ]]>
70 <include refid="QUERY_COLUMN_LIST" /> 76 <include refid="QUERY_COLUMN_LIST" />
71 <![CDATA[ 77 <![CDATA[
72 - FROM `xt_shop` 78 + FROM `xt_shop`
73 ]]> 79 ]]>
74 <include refid="QUERY_WHERE_CLAUSE" /> 80 <include refid="QUERY_WHERE_CLAUSE" />
75 </select> 81 </select>
76 -</mapper>  
77 \ No newline at end of file 82 \ No newline at end of file
  83 +</mapper>