Commit 2f9f2b83d8fb9971acc4d9ba9d51a7d074049515

Authored by yangfan
2 parents 1f52991a 4833e3c3
Showing 34 changed files with 541 additions and 350 deletions
... ... @@ -26,7 +26,7 @@
26 26 </properties>
27 27  
28 28 <dependencies>
29   -
  29 +
30 30 <dependency>
31 31 <groupId>com.diligrp</groupId>
32 32 <artifactId>xtrade-shared-spring-boot-starter</artifactId>
... ... @@ -38,7 +38,7 @@
38 38 <artifactId>xxl-job-core</artifactId>
39 39 <version>${xxl-job.version}</version>
40 40 </dependency> -->
41   -
  41 +
42 42 <dependency>
43 43 <groupId>com.alibaba.cloud</groupId>
44 44 <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
... ... @@ -54,13 +54,13 @@
54 54 <artifactId>nacos-client</artifactId>
55 55 <version>${nacos-client.version}</version>
56 56 </dependency>
57   -
  57 +
58 58 <dependency>
59 59 <groupId>com.alibaba.nacos</groupId>
60 60 <artifactId>nacos-api</artifactId>
61 61 <version>${nacos-client.version}</version>
62 62 </dependency>
63   -
  63 +
64 64 <dependency>
65 65 <groupId>org.springframework.boot</groupId>
66 66 <artifactId>spring-boot-configuration-processor</artifactId>
... ... @@ -118,12 +118,6 @@
118 118 <groupId>org.springframework.boot</groupId>
119 119 <artifactId>spring-boot-starter-test</artifactId>
120 120 <scope>test</scope>
121   - <exclusions>
122   - <exclusion>
123   - <groupId>org.junit.vintage</groupId>
124   - <artifactId>junit-vintage-engine</artifactId>
125   - </exclusion>
126   - </exclusions>
127 121 </dependency>
128 122 </dependencies>
129 123  
... ...
src/main/java/com/diligrp/xtrade/order/dao/OrderItemDao.java
... ... @@ -44,7 +44,7 @@ public interface OrderItemDao {
44 44 * @return
45 45 * @throws
46 46 */
47   - List<OrderItemDo> selectOrderItemByOrderId(@Param("orderId") Long orderId);
  47 + List<OrderItemDo> selectItemsByOrderId(@Param("orderId") Long orderId);
48 48  
49 49 /**
50 50 *
... ...
src/main/java/com/diligrp/xtrade/order/domain/builder/DefaultOrderBuilder.java 0 → 100644
  1 +package com.diligrp.xtrade.order.domain.builder;
  2 +
  3 +import java.math.BigDecimal;
  4 +import java.math.RoundingMode;
  5 +import java.util.List;
  6 +
  7 +import com.diligrp.xtrade.order.domain.dto.AccountDto;
  8 +import com.diligrp.xtrade.order.domain.dto.OrderItemDto;
  9 +import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
  10 +import com.diligrp.xtrade.order.domain.emuns.OrderType;
  11 +import com.diligrp.xtrade.order.domain.emuns.SaleUnit;
  12 +import com.diligrp.xtrade.order.domain.emuns.TradeType;
  13 +import com.diligrp.xtrade.order.domain.entity.OrderDo;
  14 +import com.diligrp.xtrade.order.domain.entity.OrderItemDo;
  15 +import com.diligrp.xtrade.order.exception.OrderException;
  16 +
  17 +/**
  18 + * @ClassName: DefaultOrderCreator
  19 + * @Description 订单实体相关模型
  20 + * @author zhangxing
  21 + * @date 2020年4月21日
  22 + */
  23 +public class DefaultOrderBuilder {
  24 +
  25 + /**
  26 + * 构建初始订单数据 TODO need modify because of change
  27 + */
  28 + public static OrderDo initializeOrderBaseData(Long orderId, AccountDto saccountDto, Integer createSrc) {
  29 + OrderDo order = new OrderDo();
  30 + order.setOrderId(orderId);
  31 + order.setBaccount(saccountDto.getAccountId());
  32 + order.setSname(saccountDto.getAccountName());
  33 + order.setSmobile(saccountDto.getMobile());
  34 + order.setScardType(saccountDto.getType());
  35 + order.setCreatedSrc(createSrc);
  36 + order.setOrderType(OrderType.NORMAL.getCode());
  37 + order.setTradeType(TradeType.NORMAL.getCode());
  38 + order.setMarketCode("SYDEV");
  39 + return order;
  40 + }
  41 +
  42 + /**
  43 + * 订单详情初始化数据 TODO need modify because of change
  44 + */
  45 + public static OrderItemDo initializeItemData(Long itemId, Long orderId, OrderItemDto orderItem){
  46 + OrderItemDo orderItemDo = new OrderItemDo();
  47 + orderItemDo.setItemId(itemId);
  48 + orderItemDo.setOrderId(orderId);
  49 + orderItemDo.setProductId(orderItem.getPid());
  50 + orderItemDo.setProductName(orderItem.getPname());
  51 + // 销售单价
  52 + BigDecimal price = BigDecimal.valueOf(orderItem.getPrice());
  53 + // 销售数量
  54 + BigDecimal amount = BigDecimal.valueOf(orderItem.getAmount());
  55 +
  56 + orderItemDo.setAmount(orderItem.getAmount());
  57 +
  58 + BigDecimal tempWeight = BigDecimal.valueOf(0.0D);
  59 +
  60 + if (SaleUnit.KILO.getCode() == orderItem.getSaleUnit()) {
  61 + tempWeight = BigDecimal.valueOf(orderItem.getAmount());
  62 + } else if (SaleUnit.PIECE.getCode() == orderItem.getSaleUnit()) {
  63 + if (orderItem.getUnitWeight() == null || orderItem.getUnitWeight() < 0) {
  64 + throw new OrderException(String.format("%s件重非法", orderItem.getPname()));
  65 + }
  66 + BigDecimal dKiloPerItem = BigDecimal.valueOf(orderItem.getUnitWeight());
  67 + tempWeight = amount.multiply(dKiloPerItem);
  68 + }
  69 + orderItemDo.setWeight(tempWeight.doubleValue());
  70 + Long itemMoney = price.multiply(amount).setScale(0, RoundingMode.HALF_UP).longValue();
  71 + orderItemDo.setMoney(itemMoney);
  72 + return orderItemDo;
  73 + }
  74 +
  75 + /**
  76 + * 构建基本的订单详情数据 TODO need modify because of change
  77 + */
  78 + public static OrderQueryResponseDto buildOrderDetail(OrderDo order,
  79 + List<OrderItemDo> orderItem) {
  80 + OrderQueryResponseDto orderQueryResponseDto = new OrderQueryResponseDto();
  81 + return orderQueryResponseDto;
  82 + }
  83 +
  84 +}
... ...
src/main/java/com/diligrp/xtrade/order/domain/builder/DefaultOrderCreator.java deleted 100644 → 0
1   -package com.diligrp.xtrade.order.domain.builder;
2   -
3   -import org.springframework.beans.BeanUtils;
4   -
5   -import com.diligrp.xtrade.order.domain.dto.AccountDto;
6   -import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
7   -import com.diligrp.xtrade.order.domain.entity.OrderDo;
8   -
9   -/**
10   - * @ClassName: DefaultOrderCreator
11   - * @Description 订单实体相关模型
12   - * @author zhangxing
13   - * @date 2020年4月21日
14   - */
15   -public class DefaultOrderCreator {
16   -
17   - //最终订单数据
18   - private OrderDo order;
19   -
20   - //订单创建请求实体
21   - private OrderCreateRequestDto orderCreateRequestDto;
22   -
23   - //卖家实体
24   - private AccountDto saccountDto;
25   -
26   - //买家实体
27   - private AccountDto baccountDto;
28   -
29   - //无参构造器
30   - public DefaultOrderCreator(){
31   -
32   - }
33   -
34   - public DefaultOrderCreator(OrderCreateRequestDto orderCreateRequestDto, AccountDto saccountDto, AccountDto baccountDto){
35   - this.orderCreateRequestDto = orderCreateRequestDto;
36   - this.baccountDto = baccountDto;
37   - this.saccountDto = saccountDto;
38   - }
39   -
40   - /**
41   - * 初始化订单数据用于后面的校验
42   - */
43   - public void initialize() {
44   -
45   - }
46   -
47   - public OrderDo getOrder() {
48   - return order;
49   - }
50   -
51   - public void setOrder(OrderDo order) {
52   - this.order = order;
53   - }
54   -
55   - public OrderCreateRequestDto getOrderCreateRequestDto() {
56   - return orderCreateRequestDto;
57   - }
58   -
59   - public void setOrderCreateRequestDto(OrderCreateRequestDto orderCreateRequestDto) {
60   - this.orderCreateRequestDto = orderCreateRequestDto;
61   - }
62   -
63   - public AccountDto getSaccountDto() {
64   - return saccountDto;
65   - }
66   -
67   - public void setSaccountDto(AccountDto saccountDto) {
68   - this.saccountDto = saccountDto;
69   - }
70   -
71   - public AccountDto getBaccountDto() {
72   - return baccountDto;
73   - }
74   -
75   - public void setBaccountDto(AccountDto baccountDto) {
76   - this.baccountDto = baccountDto;
77   - }
78   -
79   - public static OrderDo build(OrderCreateRequestDto orderCreateRequestDto) {
80   - OrderDo orderDo = new OrderDo();
81   - BeanUtils.copyProperties(orderCreateRequestDto, orderDo);
82   - return orderDo;
83   - }
84   -}
src/main/java/com/diligrp/xtrade/order/domain/entity/OrderDo.java
... ... @@ -70,6 +70,9 @@ public class OrderDo extends BaseDo{
70 70  
71 71 //订单类型
72 72 private Integer orderType;
  73 +
  74 + //订单类型
  75 + private Integer tradeType;
73 76  
74 77 //支付方式
75 78 private Integer payType;
... ... @@ -263,6 +266,14 @@ public class OrderDo extends BaseDo{
263 266 public void setOrderType(Integer orderType) {
264 267 this.orderType = orderType;
265 268 }
  269 +
  270 + public Integer getTradeType() {
  271 + return tradeType;
  272 + }
  273 +
  274 + public void setTradeType(Integer tradeType) {
  275 + this.tradeType = tradeType;
  276 + }
266 277  
267 278  
268 279 }
... ...
src/main/java/com/diligrp/xtrade/order/rpc/feign/AccountResolver.java 0 → 100644
  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 +}
... ...
src/main/java/com/diligrp/xtrade/order/service/OrderService.java
... ... @@ -19,7 +19,7 @@ public interface OrderService {
19 19 * @Title createOrder
20 20 * @Description 创建订单
21 21 */
22   - void createOrder(OrderCreateRequestDto orderCreateRequestDto);
  22 + void createOrder(OrderCreateRequestDto orderCreateDto);
23 23  
24 24 /**
25 25 * @Title orderLists
... ...
src/main/java/com/diligrp/xtrade/order/service/impl/OrderServiceImpl.java
1 1 package com.diligrp.xtrade.order.service.impl;
2 2  
  3 +import java.math.BigDecimal;
3 4 import java.util.ArrayList;
4 5 import java.util.List;
5 6  
... ... @@ -7,38 +8,66 @@ import javax.annotation.Resource;
7 8  
8 9 import org.springframework.beans.BeanUtils;
9 10 import org.springframework.stereotype.Service;
  11 +import org.springframework.transaction.annotation.Transactional;
10 12  
11 13 import com.diligrp.xtrade.order.dao.OrderDao;
12   -import com.diligrp.xtrade.order.domain.builder.DefaultOrderCreator;
  14 +import com.diligrp.xtrade.order.dao.OrderItemDao;
  15 +import com.diligrp.xtrade.order.domain.builder.DefaultOrderBuilder;
  16 +import com.diligrp.xtrade.order.domain.dto.AccountDto;
13 17 import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
  18 +import com.diligrp.xtrade.order.domain.dto.OrderItemDto;
14 19 import com.diligrp.xtrade.order.domain.dto.OrderQueryRequestDto;
15 20 import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
16 21 import com.diligrp.xtrade.order.domain.emuns.IdGenerator;
17 22 import com.diligrp.xtrade.order.domain.entity.OrderDo;
  23 +import com.diligrp.xtrade.order.domain.entity.OrderItemDo;
  24 +import com.diligrp.xtrade.order.rpc.feign.AccountResolver;
18 25 import com.diligrp.xtrade.order.service.OrderService;
19 26 import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
20 27  
21 28 @Service("orderService")
22 29 public class OrderServiceImpl implements OrderService {
23   -
24   - @Resource
  30 +
  31 + @Resource
25 32 private OrderDao orderDao;
26   -
27   - @Resource
28   - KeyGeneratorManager keyGeneratorManager;
29   -
  33 +
  34 + @Resource
  35 + private OrderItemDao orderItemDao;
  36 +
  37 + @Resource
  38 + private KeyGeneratorManager keyGeneratorManager;
  39 +
  40 + @Resource
  41 + private AccountResolver accountResolver;
  42 +
  43 + // TODO need modify because of change
30 44 @Override
31   - public void createOrder(OrderCreateRequestDto orderCreateRequestDto) {
32   - OrderDo order = DefaultOrderCreator.build(orderCreateRequestDto);
33   - order.setOrderId(keyGeneratorManager.getKeyGenerator(IdGenerator.ORDER_SEQUENCE).nextId());
  45 + @Transactional(rollbackFor = Exception.class)
  46 + public void createOrder(OrderCreateRequestDto orderCreateDto) {
  47 + Long orderId = getOrderKey();
  48 + AccountDto saccountDto = accountResolver.getAccount(orderCreateDto.getSaccount());
  49 + OrderDo order = DefaultOrderBuilder.initializeOrderBaseData(orderId, saccountDto,
  50 + orderCreateDto.getCreatedSrc());
  51 + Long totalMoney = 0L;
  52 + BigDecimal weight = BigDecimal.valueOf(0.0D);
  53 + List<OrderItemDo> orderItemDos = new ArrayList<OrderItemDo>();
  54 + for (OrderItemDto orderItem : orderCreateDto.getItems()) {
  55 + // 订单详情数据封装
  56 + OrderItemDo orderItemDo = DefaultOrderBuilder.initializeItemData(getOrderItemKey(), orderId, orderItem);
  57 + totalMoney += orderItemDo.getMoney();
  58 + weight = weight.add(BigDecimal.valueOf(orderItemDo.getWeight()));
  59 + orderItemDos.add(orderItemDo);
  60 + }
  61 + orderItemDao.insertBatch(orderItemDos);
34 62 orderDao.insertEntity(order);
35 63 }
36 64  
  65 + // TODO need modify because of change
37 66 @Override
38 67 public List<OrderQueryResponseDto> orderLists(OrderQueryRequestDto orderQueryRequestDto) {
39 68 OrderDo order = new OrderDo();
40 69 BeanUtils.copyProperties(orderQueryRequestDto, order);
41   - List<OrderDo> orderDos = orderDao.selectEntryList(order);
  70 + List<OrderDo> orderDos = orderDao.selectEntryList(order);
42 71 List<OrderQueryResponseDto> roResponseDtos = new ArrayList<OrderQueryResponseDto>();
43 72 for (OrderDo orderDo : orderDos) {
44 73 OrderQueryResponseDto orderQueryResponseDto = new OrderQueryResponseDto();
... ... @@ -48,12 +77,26 @@ public class OrderServiceImpl implements OrderService {
48 77 return roResponseDtos;
49 78 }
50 79  
  80 + // TODO need modify because of change
51 81 @Override
52 82 public OrderQueryResponseDto orderDetail(Long orderId) {
53   - OrderDo order = orderDao.selectEntityByOrderId(orderId);
54   - OrderQueryResponseDto queryResponseDto = new OrderQueryResponseDto();
55   - BeanUtils.copyProperties(order, queryResponseDto);
56   - return queryResponseDto;
  83 + OrderQueryResponseDto orderQueryResponseDto = DefaultOrderBuilder
  84 + .buildOrderDetail(orderDao.selectEntityByOrderId(orderId), orderItemDao.selectItemsByOrderId(orderId));
  85 + return orderQueryResponseDto;
  86 + }
  87 +
  88 + /**
  89 + * 获取订单业务主键
  90 + */
  91 + private Long getOrderKey() {
  92 + return keyGeneratorManager.getKeyGenerator(IdGenerator.ORDER_SEQUENCE).nextId();
  93 + }
  94 +
  95 + /**
  96 + * 获取订单详情主键
  97 + */
  98 + private Long getOrderItemKey() {
  99 + return keyGeneratorManager.getKeyGenerator(IdGenerator.ORDER_ITEM_SEQUENCE).nextId();
57 100 }
58 101  
59 102 }
... ...
src/main/java/com/diligrp/xtrade/product/controllor/MerchantController.java
... ... @@ -24,6 +24,11 @@ public class MerchantController {
24 24 @Autowired
25 25 private MerchantService merchantService;
26 26  
  27 + /**
  28 + * 新建市场
  29 + * @author miaoguoxin
  30 + * @date 2020/4/22
  31 + */
27 32 @PostMapping("/save")
28 33 public Message<MerchantResponseDto> save(@RequestBody @Validated(Constant.InsertGroup.class)
29 34 MerchantRequestDto requestDto) throws Exception {
... ...
src/main/java/com/diligrp/xtrade/product/dao/MerchantDao.java
1 1 package com.diligrp.xtrade.product.dao;
2 2  
3   -import com.diligrp.xtrade.product.domain.entity.Merchant;
  3 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
4 4 import org.apache.ibatis.annotations.Param;
5 5  
6 6 import java.util.List;
7 7  
8 8 public interface MerchantDao {
9 9  
10   - Merchant findById(Long id);
  10 + MerchantDo findById(Long id);
11 11  
12   - List<Merchant> findPage(@Param("offset") int offset, @Param("limit") int limit);
  12 + List<MerchantDo> findPage(@Param("offset") int offset, @Param("limit") int limit);
13 13  
14   - List<Merchant> findByCondition(Merchant xtMerchant);
  14 + List<MerchantDo> findByCondition(MerchantDo xtMerchantDo);
15 15  
16   - int insert(Merchant merchant);
  16 + int insert(MerchantDo merchantDo);
17 17  
18   - int update(Merchant xtMerchant);
  18 + int update(MerchantDo xtMerchantDo);
19 19  
20 20 int deleteById(Long id);
21 21  
... ...
src/main/java/com/diligrp/xtrade/product/domain/converter/MerchantConverter.java renamed to src/main/java/com/diligrp/xtrade/product/domain/builder/MerchantBuilder.java
1   -package com.diligrp.xtrade.product.domain.converter;
  1 +package com.diligrp.xtrade.product.domain.builder;
2 2  
3 3 import com.diligrp.xtrade.product.domain.dto.MerchantRequestDto;
4 4 import com.diligrp.xtrade.product.domain.dto.MerchantResponseDto;
5 5 import com.diligrp.xtrade.product.domain.emuns.AccountType;
6 6 import com.diligrp.xtrade.product.domain.emuns.MerchantStatus;
7   -import com.diligrp.xtrade.product.domain.entity.Merchant;
  7 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
8 8 import org.springframework.beans.BeanUtils;
9   -import org.springframework.stereotype.Component;
10 9  
11 10 import java.util.Optional;
12 11  
... ... @@ -15,26 +14,26 @@ import java.util.Optional;
15 14 * @Date: 2020/4/22 09:10
16 15 * @Description: 用于merchant的实体转换
17 16 */
18   -@Component
19   -public class MerchantConverter {
  17 +public class MerchantBuilder {
20 18  
21   - public Merchant request2Entity(MerchantRequestDto requestDto) {
  19 + public static MerchantDo request2Entity(MerchantRequestDto requestDto) {
22 20 Integer type = Optional.ofNullable(requestDto.getAccountType())
23 21 .map(AccountType::getCode)
24 22 .orElse(0);
25   - Merchant merchant = new Merchant();
26   - merchant.setMerName(requestDto.getMerchantName());
27   - merchant.setAccountId(requestDto.getAccountId());
28   - merchant.setType(type);
29   - merchant.setDescription(requestDto.getAddress());
30   - merchant.setStatus(MerchantStatus.NORMAL.getType());
31   - return merchant;
  23 + MerchantDo merchantDo = new MerchantDo();
  24 + merchantDo.setMerName(requestDto.getMerchantName());
  25 + merchantDo.setAccountId(requestDto.getAccountId());
  26 + merchantDo.setAccountName(requestDto.getAccountName());
  27 + merchantDo.setType(type);
  28 + merchantDo.setDescription(requestDto.getAddress());
  29 + merchantDo.setStatus(MerchantStatus.NORMAL.getType());
  30 + return merchantDo;
32 31 }
33 32  
34   - public MerchantResponseDto entity2Response(Merchant merchant){
  33 + public static MerchantResponseDto entity2Response(MerchantDo merchantDo){
35 34 MerchantResponseDto responseDto = new MerchantResponseDto();
36   - BeanUtils.copyProperties(merchant,responseDto);
37   - responseDto.setType(AccountType.getAccountType(merchant.getType()));
  35 + BeanUtils.copyProperties(merchantDo,responseDto);
  36 + responseDto.setType(AccountType.getAccountType(merchantDo.getType()));
38 37 return responseDto;
39 38 }
40 39 }
... ...
src/main/java/com/diligrp/xtrade/product/domain/dto/MerchantRequestDto.java
... ... @@ -18,12 +18,15 @@ public class MerchantRequestDto implements Serializable {
18 18 /**真实名字*/
19 19 private transient String realName;
20 20 /**用户名字*/
21   - @NotBlank(message = "{merchant.user_name.not.blank}", groups = Constant.InsertGroup.class)
  21 + @NotBlank(message = "{account_name.not.blank}", groups = Constant.InsertGroup.class)
22 22 @Pattern(regexp = "^[a-zA-Z0-9\u4E00-\u9FA5._,:-]*$",message = "{illegal.pattern}",groups = Constant.InsertGroup.class)
23   - private String userName;
  23 + private String accountName;
24 24 /**密码*/
  25 + @NotBlank(message = "{account_password.not.blank}", groups = Constant.InsertGroup.class)
  26 + @Pattern(regexp = "^[a-zA-Z0-9\u4E00-\u9FA5._,:-]*$",message = "{illegal.pattern}",groups = Constant.InsertGroup.class)
25 27 private String password;
26 28 /**电话*/
  29 + @Pattern(regexp = "^[1][3,4,5,8][0-9]{9}$",message = "{phone.pattern}",groups = Constant.InsertGroup.class)
27 30 private String mobile;
28 31 /**账户类型*/
29 32 @NotNull(message = "{account_type.not.null}", groups = Constant.InsertGroup.class)
... ... @@ -51,12 +54,12 @@ public class MerchantRequestDto implements Serializable {
51 54 this.accountId = accountId;
52 55 }
53 56  
54   - public String getUserName() {
55   - return userName;
  57 + public String getAccountName() {
  58 + return accountName;
56 59 }
57 60  
58   - public void setUserName(String userName) {
59   - this.userName = userName;
  61 + public void setAccountName(String accountName) {
  62 + this.accountName = accountName;
60 63 }
61 64  
62 65 public String getPassword() {
... ...
src/main/java/com/diligrp/xtrade/product/domain/emuns/AccountType.java
... ... @@ -16,7 +16,7 @@ public enum AccountType implements IEnumType {
16 16 PUBLIC(20, "对公账户"),
17 17  
18 18 /**临时卡用*/
19   - Anonymous(30, "不记名");
  19 + ANONYMOUS(30, "不记名");
20 20  
21 21 private int code;
22 22 private String name;
... ...
src/main/java/com/diligrp/xtrade/product/domain/emuns/IKeyGeneratorKeys.java
... ... @@ -8,10 +8,10 @@ package com.diligrp.xtrade.product.domain.emuns;
8 8 * @date 2020年4月21日
9 9 */
10 10 public enum IKeyGeneratorKeys {
  11 + CATEGORY_SEQUENCE("CATEGORY_SEQUENCE","品类id"),
11 12 SHOP_SEQUENCE("SHOP_SEQUENCE","店铺id"),
12 13 MERCHANT_SEQUENCE("MERCHANT_SEQUENCE","市场id"),
13 14 ACCOUNT_SEQUENCE("ACCOUNT_SEQUENCE","账号id"),
14   - CATEGORY_SEQUENCE("CATEGORY_SEQUENCE","品类is")
15 15 ;
16 16  
17 17 private String code;
... ...
src/main/java/com/diligrp/xtrade/product/domain/entity/Account.java renamed to src/main/java/com/diligrp/xtrade/product/domain/entity/AccountDo.java
... ... @@ -7,7 +7,7 @@ import com.diligrp.xtrade.shared.domain.BaseDo;
7 7 * @Date: 2020/4/21 17:20
8 8 * @Description: 账户实体
9 9 */
10   -public class Account extends BaseDo {
  10 +public class AccountDo extends BaseDo {
11 11 private String name;
12 12 private String password;
13 13 private String realName;
... ...
src/main/java/com/diligrp/xtrade/product/domain/entity/Merchant.java renamed to src/main/java/com/diligrp/xtrade/product/domain/entity/MerchantDo.java
... ... @@ -6,7 +6,7 @@ import com.diligrp.xtrade.shared.domain.BaseDo;
6 6 /**
7 7 * 商户实体(xt_merchant)
8 8 */
9   -public class Merchant extends BaseDo {
  9 +public class MerchantDo extends BaseDo {
10 10 //商户id
11 11 private Long merId;
12 12  
... ...
src/main/java/com/diligrp/xtrade/product/domain/entity/Operator.java renamed to src/main/java/com/diligrp/xtrade/product/domain/entity/OperatorDo.java
... ... @@ -5,7 +5,7 @@ package com.diligrp.xtrade.product.domain.entity;
5 5 * @Date: 2020/4/21 17:15
6 6 * @Description: 操作员实体
7 7 */
8   -public class Operator {
  8 +public class OperatorDo {
9 9 private Long accountId;
10 10 private String account;
11 11 private String name;
... ...
src/main/java/com/diligrp/xtrade/product/domain/entity/Product.java renamed to src/main/java/com/diligrp/xtrade/product/domain/entity/ProductDo.java
... ... @@ -7,47 +7,47 @@ import com.diligrp.xtrade.shared.domain.BaseDo;
7 7 * @author zhangxing
8 8 *
9 9 */
10   -public class Product extends BaseDo{
11   -
  10 +public class ProductDo extends BaseDo{
  11 +
12 12 //商品业务id
13 13 private Long productId;
14   -
  14 +
15 15 //商品名称
16 16 private String productName;
17   -
  17 +
18 18 //品类id
19 19 private Long cateId;
20   -
  20 +
21 21 //品类名称
22 22 private String cateName;
23   -
  23 +
24 24 //账户Id
25 25 private Long accountId;
26   -
  26 +
27 27 //账户名称
28 28 private String accountName;
29   -
  29 +
30 30 //商品状态
31 31 private Integer status;
32   -
  32 +
33 33 //商品件重
34 34 private Double unitWeight;
35   -
  35 +
36 36 //商品单位
37 37 private Integer unit;
38   -
  38 +
39 39 //商品价格
40 40 private Long price;
41   -
  41 +
42 42 //商品数量
43 43 private Double amount;
44   -
  44 +
45 45 //商品重量
46 46 private Double weight;
47   -
  47 +
48 48 //商品产地
49 49 private String place;
50   -
  50 +
51 51 /**
52 52 * 获取 分类ID
53 53 * @return
... ...
src/main/java/com/diligrp/xtrade/product/repository/AccountRepository.java
1 1 package com.diligrp.xtrade.product.repository;
2 2  
3   -import com.diligrp.xtrade.product.domain.entity.Account;
4   -import com.diligrp.xtrade.product.domain.entity.Operator;
  3 +import com.diligrp.xtrade.product.domain.entity.AccountDo;
  4 +import com.diligrp.xtrade.product.domain.entity.OperatorDo;
5 5 import org.springframework.stereotype.Repository;
6 6  
7 7 import java.util.ArrayList;
... ... @@ -14,21 +14,27 @@ import java.util.List;
14 14 */
15 15 @Repository
16 16 public class AccountRepository implements IAccountRepository {
17   - private final static List<Account> ACCOUNTS = new ArrayList<>();
  17 + private final static List<AccountDo> ACCOUNT_DOS = new ArrayList<>();
18 18 @Override
19   - public Operator getOperator() {
20   - return new Operator();
  19 + public OperatorDo getOperator() {
  20 + OperatorDo operatorDo = new OperatorDo();
  21 + operatorDo.setAccount("miao");
  22 + operatorDo.setName("缪");
  23 + operatorDo.setAccountId(1L);
  24 + operatorDo.setMerAccountId(10000L);
  25 + operatorDo.setAdmin(true);
  26 + return operatorDo;
21 27 }
22 28  
23 29 @Override
24   - public Account getAccountByName(String userName) {
25   - Account account = new Account();
26   - account.setName(userName);
  30 + public AccountDo getAccountByName(String userName) {
  31 + AccountDo accountDo = new AccountDo();
  32 + accountDo.setName(userName);
27 33 return null;
28 34 }
29 35  
30 36 @Override
31   - public void add(Account account) {
32   - ACCOUNTS.add(account);
  37 + public void add(AccountDo accountDo) {
  38 + ACCOUNT_DOS.add(accountDo);
33 39 }
34 40 }
... ...
src/main/java/com/diligrp/xtrade/product/repository/IAccountRepository.java
1 1 package com.diligrp.xtrade.product.repository;
2 2  
3   -import com.diligrp.xtrade.product.domain.entity.Account;
4   -import com.diligrp.xtrade.product.domain.entity.Operator;
  3 +import com.diligrp.xtrade.product.domain.entity.AccountDo;
  4 +import com.diligrp.xtrade.product.domain.entity.OperatorDo;
5 5  
6 6 /**
7 7 * @Auther: miaoguoxin
... ... @@ -10,9 +10,9 @@ import com.diligrp.xtrade.product.domain.entity.Operator;
10 10 */
11 11 public interface IAccountRepository {
12 12  
13   - Operator getOperator();
  13 + OperatorDo getOperator();
14 14  
15   - Account getAccountByName(String userName);
  15 + AccountDo getAccountByName(String userName);
16 16  
17   - void add(Account account);
  17 + void add(AccountDo accountDo);
18 18 }
... ...
src/main/java/com/diligrp/xtrade/product/repository/IMerchantRepository.java
1 1 package com.diligrp.xtrade.product.repository;
2 2  
3   -import com.diligrp.xtrade.product.domain.entity.Merchant;
  3 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
4 4  
5 5 /**
6 6 * @Auther: miaoguoxin
... ... @@ -9,9 +9,9 @@ import com.diligrp.xtrade.product.domain.entity.Merchant;
9 9 */
10 10 public interface IMerchantRepository {
11 11  
12   - Merchant getByAccountId(Long accountId);
  12 + MerchantDo getByAccountId(Long accountId);
13 13  
14   - void add(Merchant merchant);
  14 + void add(MerchantDo merchantDo);
15 15  
16   - void update(Merchant merchant);
  16 + void update(MerchantDo merchantDo);
17 17 }
... ...
src/main/java/com/diligrp/xtrade/product/repository/MerchantRepository.java
... ... @@ -4,7 +4,7 @@ import com.diligrp.xtrade.product.dao.MerchantDao;
4 4 import com.diligrp.xtrade.product.dao.ShopDao;
5 5 import com.diligrp.xtrade.product.domain.emuns.AccountType;
6 6 import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;
7   -import com.diligrp.xtrade.product.domain.entity.Merchant;
  7 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
8 8 import com.diligrp.xtrade.product.domain.entity.ShopDo;
9 9 import com.diligrp.xtrade.shared.sequence.IKeyGenerator;
10 10 import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
... ... @@ -28,31 +28,31 @@ public class MerchantRepository implements IMerchantRepository {
28 28 private KeyGeneratorManager keyGeneratorManager;
29 29  
30 30 @Override
31   - public Merchant getByAccountId(Long accountId) {
32   - Merchant merchant = new Merchant();
33   - merchant.setAccountId(accountId);
34   - List<Merchant> merchants = merchantDao.findByCondition(merchant);
35   - if (merchants.isEmpty()){
  31 + public MerchantDo getByAccountId(Long accountId) {
  32 + MerchantDo merchantDo = new MerchantDo();
  33 + merchantDo.setAccountId(accountId);
  34 + List<MerchantDo> merchantDos = merchantDao.findByCondition(merchantDo);
  35 + if (merchantDos.isEmpty()){
36 36 return null;
37 37 }
38   - return merchants.get(0);
  38 + return merchantDos.get(0);
39 39 }
40 40  
41 41 @Override
42   - public void add(Merchant newMerchant) {
  42 + public void add(MerchantDo newMerchantDo) {
43 43 IKeyGenerator keyGenerator = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.MERCHANT_SEQUENCE);
44   - newMerchant.setMerId(keyGenerator.nextId());
45   - newMerchant.setMarketId("SY001");
46   - newMerchant.setCreatedTime(LocalDateTime.now());
47   - merchantDao.insert(newMerchant);
  44 + newMerchantDo.setMerId(keyGenerator.nextId());
  45 + newMerchantDo.setMarketId("SY001");
  46 + newMerchantDo.setCreatedTime(LocalDateTime.now());
  47 + merchantDao.insert(newMerchantDo);
48 48 }
49 49  
50 50 @Override
51   - public void update(Merchant merchant) {
52   - merchant.setModifiedTime(LocalDateTime.now());
  51 + public void update(MerchantDo merchantDo) {
  52 + merchantDo.setModifiedTime(LocalDateTime.now());
53 53 ShopDo shopDo = new ShopDo();
54 54 shopDo.setType(AccountType.PUBLIC.getCode());
55   - shopDo.setMerId(merchant.getMerId());
  55 + shopDo.setMerId(merchantDo.getMerId());
56 56 shopDao.update(shopDo);
57 57 }
58 58 }
... ...
src/main/java/com/diligrp/xtrade/product/service/AccountService.java
1 1 package com.diligrp.xtrade.product.service;
2 2  
3 3 import com.diligrp.xtrade.product.domain.dto.MerchantRequestDto;
4   -import com.diligrp.xtrade.product.domain.entity.Account;
5   -import com.diligrp.xtrade.product.domain.entity.Merchant;
  4 +import com.diligrp.xtrade.product.domain.entity.AccountDo;
  5 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
6 6  
7 7 /**
8 8 * @Auther: miaoguoxin
... ... @@ -10,7 +10,7 @@ import com.diligrp.xtrade.product.domain.entity.Merchant;
10 10 */
11 11 public interface AccountService {
12 12  
13   - Account build(MerchantRequestDto requestDto, Merchant merchant) throws Exception;
  13 + AccountDo build(MerchantRequestDto requestDto, MerchantDo merchantDo) throws Exception;
14 14  
15   - void create(MerchantRequestDto requestDto, Merchant merchant) throws Exception;
  15 + void create(MerchantRequestDto requestDto, MerchantDo merchantDo) throws Exception;
16 16 }
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/AccountServiceImpl.java
1 1 package com.diligrp.xtrade.product.service.impl;
2 2  
  3 +import com.alibaba.nacos.common.utils.Md5Utils;
3 4 import com.diligrp.xtrade.product.domain.dto.MerchantRequestDto;
4 5 import com.diligrp.xtrade.product.domain.emuns.AccountStatus;
5 6 import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;
6   -import com.diligrp.xtrade.product.domain.entity.Account;
7   -import com.diligrp.xtrade.product.domain.entity.Merchant;
  7 +import com.diligrp.xtrade.product.domain.entity.AccountDo;
  8 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
8 9 import com.diligrp.xtrade.product.repository.IAccountRepository;
9 10 import com.diligrp.xtrade.product.service.AccountService;
10   -import com.diligrp.xtrade.shared.security.PasswordUtils;
11 11 import com.diligrp.xtrade.shared.sequence.IKeyGenerator;
12 12 import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
13 13 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -27,25 +27,27 @@ public class AccountServiceImpl implements AccountService {
27 27 private KeyGeneratorManager keyGeneratorManager;
28 28  
29 29 @Override
30   - public Account build(MerchantRequestDto requestDto, Merchant merchant) throws Exception {
31   - Account newAccount = new Account();
32   - newAccount.setName(requestDto.getUserName());
33   - newAccount.setRealName(requestDto.getRealName());
34   - newAccount.setPassword(PasswordUtils.encrypt(requestDto.getPassword(),
35   - requestDto.getUserName()));
36   - newAccount.setMobile(requestDto.getMobile());
37   - newAccount.setStatus(AccountStatus.NORMAL.getCode());
38   - newAccount.setIsAdmin(1);
39   - newAccount.setMerId(merchant.getMerId());
40   - newAccount.setCreatedTime(LocalDateTime.now());
  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());
41 42 IKeyGenerator keyGenerator = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.ACCOUNT_SEQUENCE);
42   - newAccount.setId(keyGenerator.nextId());
43   - return newAccount;
  43 + newAccountDo.setId(keyGenerator.nextId());
  44 + return newAccountDo;
44 45 }
45 46  
46 47 @Override
47   - public void create(MerchantRequestDto requestDto, Merchant merchant) throws Exception {
48   - Account newAccount = this.build(requestDto, merchant);
49   - accountRepository.add(newAccount);
  48 + public void create(MerchantRequestDto requestDto, MerchantDo merchantDo) throws Exception {
  49 + AccountDo newAccountDo = this.build(requestDto, merchantDo);
  50 + accountRepository.add(newAccountDo);
50 51 }
  52 +
51 53 }
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/CategoryServiceImpl.java
1   -package com.diligrp.xtrade.product.service.impl;
2   -
3   -import java.util.List;
4   -
5   -import org.apache.commons.lang3.StringUtils;
6   -import org.springframework.beans.BeanUtils;
7   -import org.springframework.beans.factory.annotation.Autowired;
8   -import org.springframework.stereotype.Service;
9   -
10   -import com.diligrp.xtrade.product.dao.CategoryDao;
11   -import com.diligrp.xtrade.product.domain.dto.CategoryDto;
12   -import com.diligrp.xtrade.product.domain.dto.CategoryQueryDto;
13   -import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;
14   -import com.diligrp.xtrade.product.domain.entity.CategoryDo;
15   -import com.diligrp.xtrade.product.service.CategoryService;
16   -import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
17   -
18   -/**
19   - * @ClassName: CategoryServiceImpl
20   - * @Description TODO(用一句话描述该文件做什么)
21   - * @author yangfan
22   - * @date 2020年4月20日
23   - */
24   -@Service("categoryService")
25   -public class CategoryServiceImpl implements CategoryService {
26   -
27   - @Autowired
28   - private KeyGeneratorManager keyGeneratorManager;
29   - @Autowired
30   - private CategoryDao categoryDao;
31   -
32   - @Override
33   - public void insert(CategoryDto category) {
34   - CategoryDo categoryDo = new CategoryDo();
35   - BeanUtils.copyProperties(category, categoryDo);
36   - long id = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.CATEGORY_SEQUENCE).nextId();
37   - String cateCode = ""+id;
38   - //cateCode 生成 子级品类继承上级品类cateCode 父code_子code
39   - if (StringUtils.isNotBlank(category.getParentId())) {
40   - CategoryDo pCategoryDo = selectEntityById(Long.valueOf(category.getParentId()));
41   - cateCode = String.format("%s_%d", pCategoryDo.getCateCode(),id);
42   - }
43   - categoryDo.setCateCode(cateCode);
44   - categoryDao.insert(categoryDo);
45   - }
46   -
47   - @Override
48   - public void update(CategoryDto category) {
49   - CategoryDo categoryDo = new CategoryDo();
50   - BeanUtils.copyProperties(category, categoryDo);
51   - categoryDao.update(categoryDo);
52   - }
53   -
54   - @Override
55   - public void delectById(Long id) {
56   - categoryDao.delect(id);
57   - }
58   -
59   - @Override
60   - public CategoryDo selectEntityById(Long id) {
61   - return categoryDao.selectEntityById(id);
62   - }
63   -
64   - @Override
65   - public List<CategoryDo> selectList(CategoryQueryDto categoryQueryDto) {
66   - return categoryDao.selectList(categoryQueryDto);
67   - }
68   -
69   - @Override
70   - public List<CategoryDo> selectCateChild(String cateCode) {
71   - return categoryDao.selectCateChild(cateCode);
72   - }
73   -
74   -}
  1 +package com.diligrp.xtrade.product.service.impl;
  2 +
  3 +import java.util.List;
  4 +
  5 +import org.apache.commons.lang3.StringUtils;
  6 +import org.springframework.beans.BeanUtils;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +import com.diligrp.xtrade.product.dao.CategoryDao;
  11 +import com.diligrp.xtrade.product.domain.dto.CategoryDto;
  12 +import com.diligrp.xtrade.product.domain.dto.CategoryQueryDto;
  13 +import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;
  14 +import com.diligrp.xtrade.product.domain.entity.CategoryDo;
  15 +import com.diligrp.xtrade.product.service.CategoryService;
  16 +import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
  17 +
  18 +/**
  19 + * @ClassName: CategoryServiceImpl
  20 + * @Description TODO(用一句话描述该文件做什么)
  21 + * @author yangfan
  22 + * @date 2020年4月20日
  23 + */
  24 +@Service("categoryService")
  25 +public class CategoryServiceImpl implements CategoryService {
  26 +
  27 + @Autowired
  28 + private KeyGeneratorManager keyGeneratorManager;
  29 + @Autowired
  30 + private CategoryDao categoryDao;
  31 +
  32 + @Override
  33 + public void insert(CategoryDto category) {
  34 + CategoryDo categoryDo = new CategoryDo();
  35 + BeanUtils.copyProperties(category, categoryDo);
  36 + long id = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.CATEGORY_SEQUENCE).nextId();
  37 + String cateCode = ""+id;
  38 + //cateCode 生成 子级品类继承上级品类cateCode 父code_子code
  39 + if (StringUtils.isNotBlank(category.getParentId())) {
  40 + CategoryDo pCategoryDo = selectEntityById(Long.valueOf(category.getParentId()));
  41 + cateCode = String.format("%s_%d", pCategoryDo.getCateCode(),id);
  42 + }
  43 + categoryDo.setCateCode(cateCode);
  44 + categoryDao.insert(categoryDo);
  45 + }
  46 +
  47 + @Override
  48 + public void update(CategoryDto category) {
  49 + CategoryDo categoryDo = new CategoryDo();
  50 + BeanUtils.copyProperties(category, categoryDo);
  51 + categoryDao.update(categoryDo);
  52 + }
  53 +
  54 + @Override
  55 + public void delectById(Long id) {
  56 + categoryDao.delect(id);
  57 + }
  58 +
  59 + @Override
  60 + public CategoryDo selectEntityById(Long id) {
  61 + return categoryDao.selectEntityById(id);
  62 + }
  63 +
  64 + @Override
  65 + public List<CategoryDo> selectList(CategoryQueryDto categoryQueryDto) {
  66 + return categoryDao.selectList(categoryQueryDto);
  67 + }
  68 +
  69 + @Override
  70 + public List<CategoryDo> selectCateChild(String cateCode) {
  71 + return categoryDao.selectCateChild(cateCode);
  72 + }
  73 +
  74 +}
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/MerchantServiceImpl.java
1 1 package com.diligrp.xtrade.product.service.impl;
2 2  
3   -import com.diligrp.xtrade.product.domain.converter.MerchantConverter;
  3 +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 7 import com.diligrp.xtrade.product.domain.emuns.ResponseCode;
8   -import com.diligrp.xtrade.product.domain.entity.Account;
9   -import com.diligrp.xtrade.product.domain.entity.Merchant;
10   -import com.diligrp.xtrade.product.domain.entity.Operator;
  8 +import com.diligrp.xtrade.product.domain.entity.AccountDo;
  9 +import com.diligrp.xtrade.product.domain.entity.MerchantDo;
  10 +import com.diligrp.xtrade.product.domain.entity.OperatorDo;
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;
... ... @@ -24,33 +24,31 @@ public class MerchantServiceImpl implements MerchantService {
24 24 @Autowired
25 25 private IMerchantRepository merchantRepository;
26 26 @Autowired
27   - private MerchantConverter merchantConverter;
28   - @Autowired
29 27 private AccountService accountService;
30 28  
31 29 @Override
32 30 @Transactional
33 31 public MerchantResponseDto create(MerchantRequestDto requestDto) throws Exception {
34   - Operator operator = accountRepository.getOperator();
35   - requestDto.setAccountId(operator.getAccountId());
36   - requestDto.setRealName(operator.getName());
37   - Account account = accountRepository.getAccountByName(requestDto.getUserName());
38   - if (account != null) {
  32 + OperatorDo operatorDo = accountRepository.getOperator();
  33 + requestDto.setAccountId(operatorDo.getAccountId());
  34 + requestDto.setRealName(operatorDo.getName());
  35 + AccountDo accountDo = accountRepository.getAccountByName(requestDto.getAccountName());
  36 + if (accountDo != null) {
39 37 throw new ProductException(ResponseCode.ACCOUNT_EXIST);
40 38 }
41   - Merchant merchant = merchantRepository.getByAccountId(requestDto.getAccountId());
42   - if (merchant == null){
43   - merchant = merchantConverter.request2Entity(requestDto);
44   - merchantRepository.add(merchant);
  39 + MerchantDo merchantDo = merchantRepository.getByAccountId(requestDto.getAccountId());
  40 + if (merchantDo == null){
  41 + merchantDo = MerchantBuilder.request2Entity(requestDto);
  42 + merchantRepository.add(merchantDo);
45 43 } else {
46   - if (AccountType.PERSONAL.getCode() != merchant.getType()){
  44 + if (AccountType.PERSONAL.getCode() != merchantDo.getType()){
47 45 throw new ProductException(ResponseCode.CARD_MERCHANT_CREATED);
48 46 }
49   - merchantRepository.update(merchant);
  47 + merchantRepository.update(merchantDo);
50 48 }
51 49 //创建市场管理员账户
52   - accountService.create(requestDto,merchant);
53   - return merchantConverter.entity2Response(merchant);
  50 + accountService.create(requestDto, merchantDo);
  51 + return MerchantBuilder.entity2Response(merchantDo);
54 52 }
55 53  
56 54 }
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/ProductServiceImpl.java
... ... @@ -14,7 +14,7 @@ public class ProductServiceImpl implements ProductService {
14 14  
15 15 @Override
16 16 public void createProduct(ProductCreateRequestDto productCreateRequestDto) {
17   -
  17 +
18 18 }
19 19  
20 20 @Override
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/ShopServiceImpl.java
... ... @@ -25,7 +25,7 @@ public class ShopServiceImpl implements ShopService {
25 25 private ShopDao shopDao;
26 26 @Autowired
27 27 private KeyGeneratorManager KeyGeneratorManager;
28   -
  28 +
29 29 @Override
30 30 public void insert(ShopDto shop) {
31 31 ShopDo shopDo = new ShopDo();
... ...
src/main/resources/ValidationMessages.properties 0 → 100644
  1 +illegal.pattern=\u542B\u6709\u975E\u6CD5\u5B57\u7B26
  2 +phone.pattern=\u7535\u8BDD\u53F7\u7801\u4E0D\u6B63\u786E
  3 +account_name.not.blank=\u8D26\u6237\u540D\u5B57\u4E0D\u80FD\u4E3A\u7A7A
  4 +account_password.not.blank=\u8D26\u6237\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
  5 +account_type.not.null=\u8D26\u6237\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A
  6 +merchant_name.not.blank=\u5E02\u573A\u540D\u5B57\u4E0D\u80FD\u4E3A\u7A7A
... ...
src/main/resources/mapping/com/diligrp/xtrade/order/OrderItemDao.xml
... ... @@ -13,7 +13,7 @@
13 13 VALUES (#{itemId}, #{orderId}, #{productName}, #{productId}, #{price}, #{amount}, #{saleUnit}, #{unitWeight}, #{scommission}, #{bcommission}, #{ruleid}, #{ruleRate}, #{}weight, #{totalMoney}, NOW(), NOW());
14 14 </insert>
15 15  
16   - <select id="selectOrderItemByItemId" parameterType="long" resultType="orderItemDo">
  16 + <select id="selectItemsByOrderId" parameterType="long" resultType="orderItemDo">
17 17 SELECT
18 18 <include refid="QUERY_COLUMN_LIST"/>
19 19 FROM `xt_order_item`
... ...
src/main/resources/mapping/com/diligrp/xtrade/product/MerchantDao.xml
... ... @@ -2,7 +2,7 @@
2 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3 <mapper namespace="com.diligrp.xtrade.product.dao.MerchantDao">
4 4  
5   - <resultMap type="com.diligrp.xtrade.product.domain.entity.Merchant" id="XtMerchantMap">
  5 + <resultMap type="com.diligrp.xtrade.product.domain.entity.MerchantDo" id="XtMerchantMap">
6 6 <result property="id" column="id"/>
7 7 <result property="merId" column="mer_id"/>
8 8 <result property="merName" column="mer_name"/>
... ... @@ -28,37 +28,67 @@
28 28 created_time,
29 29 modified_time
30 30 </sql>
31   - <sql id="Base_Condition_Column">
32   - <if test="merId != null">
  31 + <sql id="UPDATE_Column">
  32 + <set> <if test="merId != null">
33 33 mer_id = #{merId},
34 34 </if>
35   - <if test="merName != null and merName != ''">
36   - mer_name = #{merName},
37   - </if>
38   - <if test="marketId != null and marketId != ''">
39   - market_id = #{marketId},
40   - </if>
41   - <if test="accountId != null">
42   - account_id = #{accountId},
43   - </if>
44   - <if test="accountName != null and accountName != ''">
45   - account_name = #{accountName},
46   - </if>
47   - <if test="type != null">
48   - type = #{type},
49   - </if>
50   - <if test="status != null">
51   - `status` = #{status},
52   - </if>
53   - <if test="description != null and description != ''">
54   - `description` = #{description},
55   - </if>
56   - <if test="createdTime != null">
57   - created_time = #{createdTime},
58   - </if>
59   - <if test="modifiedTime != null">
60   - modified_time = #{modifiedTime},
61   - </if>
  35 + <if test="merName != null and merName != ''">
  36 + mer_name = #{merName},
  37 + </if>
  38 + <if test="marketId != null and marketId != ''">
  39 + market_id = #{marketId},
  40 + </if>
  41 + <if test="accountId != null">
  42 + account_id = #{accountId},
  43 + </if>
  44 + <if test="accountName != null and accountName != ''">
  45 + account_name = #{accountName},
  46 + </if>
  47 + <if test="type != null">
  48 + type = #{type},
  49 + </if>
  50 + <if test="status != null">
  51 + `status` = #{status},
  52 + </if>
  53 + <if test="description != null and description != ''">
  54 + `description` = #{description},
  55 + </if>
  56 + <if test="createdTime != null">
  57 + created_time = #{createdTime},
  58 + </if>
  59 + <if test="modifiedTime != null">
  60 + modified_time = #{modifiedTime},
  61 + </if>
  62 + </set>
  63 + </sql>
  64 +
  65 + <sql id="WHERE_COLUMN">
  66 + <where>
  67 + <if test="merId != null">
  68 + and mer_id = #{merId}
  69 + </if>
  70 + <if test="merName != null and merName != ''">
  71 + and mer_name = #{merName}
  72 + </if>
  73 + <if test="marketId != null and marketId != ''">
  74 + and market_id = #{marketId}
  75 + </if>
  76 + <if test="accountId != null">
  77 + and account_id = #{accountId}
  78 + </if>
  79 + <if test="accountName != null and accountName != ''">
  80 + and account_name = #{accountName}
  81 + </if>
  82 + <if test="type != null">
  83 + and type = #{type}
  84 + </if>
  85 + <if test="status != null">
  86 + and `status` = #{status}
  87 + </if>
  88 + <if test="description != null and description != ''">
  89 + and `description` = #{description}
  90 + </if>
  91 + </where>
62 92 </sql>
63 93  
64 94 <!--查询单个-->
... ... @@ -77,19 +107,17 @@
77 107 limit #{offset}, #{limit}
78 108 </select>
79 109  
80   - <select id="findByCondition" parameterType="com.diligrp.xtrade.product.domain.entity.Merchant" resultMap="XtMerchantMap">
  110 + <select id="findByCondition" parameterType="com.diligrp.xtrade.product.domain.entity.MerchantDo" resultMap="XtMerchantMap">
81 111 SELECT
82 112 <include refid="Base_Column"/>
83 113 from xt_merchant
84   - <where>
85   - <include refid="Base_Condition_Column"/>
86   - </where>
  114 + <include refid="WHERE_COLUMN"/>
87 115 </select>
88 116  
89 117 <!--新增所有列-->
90 118 <insert id="insert" keyProperty="id" useGeneratedKeys="true">
91 119 insert into xt_merchant(mer_id, mer_name, market_id, account_id, account_name, type, status, description,
92   - created_time, modified_time)
  120 + created_time, modified_time)
93 121 values (#{merId}, #{merName}, #{marketId}, #{accountId}, #{accountName}, #{type}, #{status}, #{description},
94 122 #{createdTime}, #{modifiedTime})
95 123 </insert>
... ... @@ -97,9 +125,7 @@
97 125 <!--通过主键修改数据-->
98 126 <update id="update">
99 127 update xt_merchant
100   - <set>
101   - <include refid="Base_Condition_Column"/>
102   - </set>
  128 + <include refid="UPDATE_Column"/>
103 129 where id = #{id}
104 130 </update>
105 131  
... ...
src/test/java/com/diligrp/BaseTests.java 0 → 100644
  1 +package com.diligrp;
  2 +
  3 +import org.junit.runner.RunWith;
  4 +import org.springframework.boot.test.context.SpringBootTest;
  5 +import org.springframework.test.context.junit4.SpringRunner;
  6 +
  7 +/**
  8 + * @Auther: miaoguoxin
  9 + * @Date: 2019/7/18 21:42
  10 + */
  11 +@RunWith(SpringRunner.class)
  12 +@SpringBootTest
  13 +public class BaseTests {
  14 +
  15 +}
... ...
src/test/java/com/diligrp/xtrade/product/controllor/MerchantDoControllerTest.java 0 → 100644
  1 +package com.diligrp.xtrade.product.controllor;
  2 +
  3 +import com.diligrp.BaseTests;
  4 +import org.junit.jupiter.api.Test;
  5 +
  6 +/**
  7 + * @Auther: miaoguoxin
  8 + * @Date: 2020/4/22 13:58
  9 + */
  10 +class MerchantDoControllerTest extends BaseTests {
  11 +
  12 + @Test
  13 + void save() {
  14 +
  15 + }
  16 +}
... ...
src/test/java/com/diligrp/xtrade/product/service/MerchantDoServiceTest.java 0 → 100644
  1 +package com.diligrp.xtrade.product.service;
  2 +
  3 +import com.diligrp.BaseTests;
  4 +import com.diligrp.xtrade.product.domain.dto.MerchantRequestDto;
  5 +import com.diligrp.xtrade.product.service.MerchantService;
  6 +import com.diligrp.xtrade.shared.util.JsonUtils;
  7 +import org.junit.jupiter.api.Test;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +
  10 +import static org.junit.jupiter.api.Assertions.*;
  11 +
  12 +/**
  13 + * @Auther: miaoguoxin
  14 + * @Date: 2020/4/22 13:59
  15 + * @Description:
  16 + */
  17 +class MerchantDoServiceTest extends BaseTests {
  18 + @Autowired
  19 + private MerchantService merchantService;
  20 + @Test
  21 + void create() throws Exception {
  22 + String mockJson = "{\n" +
  23 + " \"accountName\": \"test1\",\n" +
  24 + " \"password\": \"123456\",\n" +
  25 + " \"mobile\": \"135446546546\",\n" +
  26 + " \"accountType\": 20,\n" +
  27 + " \"merchantName\": \"测试商户\",\n" +
  28 + " \"address\": \"成都市\"\n" +
  29 + "}";
  30 + MerchantRequestDto requestDto = JsonUtils.fromJsonString(mockJson, MerchantRequestDto.class);
  31 + merchantService.create(requestDto);
  32 + }
  33 +}
... ...