Commit cea3dade2ab0ee54e7b73665a8444cc0d72ee8d8

Authored by zhangxing
1 parent 67fef66f

id生成器枚举

src/main/java/com/diligrp/xtrade/order/controllor/OrderApiController.java
... ... @@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
13 13 import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
14 14 import com.diligrp.xtrade.order.domain.dto.OrderQueryRequestDto;
15 15 import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
16   -import com.diligrp.xtrade.order.service.Orderservice;
  16 +import com.diligrp.xtrade.order.service.OrderService;
17 17 import com.diligrp.xtrade.shared.domain.Message;
18 18  
19 19 /**
... ... @@ -26,7 +26,7 @@ import com.diligrp.xtrade.shared.domain.Message;
26 26 public class OrderApiController {
27 27  
28 28 @Resource
29   - private Orderservice orderservice;
  29 + private OrderService orderservice;
30 30  
31 31 /**
32 32 * 订单创建接口
... ...
src/main/java/com/diligrp/xtrade/order/domain/emuns/IDGenerator.java renamed to src/main/java/com/diligrp/xtrade/order/domain/emuns/IdGenerator.java
1   -package com.diligrp.xtrade.order.domain.emuns;
2   -
3   -public enum IDGenerator {
4   -
5   - ORDER_SEQUENCE(1,"ORDER_SEQUENCE");
6   -
7   - private int type;
8   - private String name;
9   -
10   - private IDGenerator(int type, String name) {
11   - this.type = type;
12   - this.name = name;
13   - }
14   -
15   - public int getType() {
16   - return type;
17   - }
18   -
19   - public String getName() {
20   - return name;
21   - }
22   -
23   - public static IDGenerator getByType(int type) {
24   - for (IDGenerator idGenerator : values()) {
25   - if (idGenerator.getType() == type) {
26   - return idGenerator;
27   - }
28   - }
29   - return null;
30   - }
31   -
32   - public static String getName(int index) {
33   - for (IDGenerator idGenerator : IDGenerator.values()) {
34   - if (idGenerator.getType() == index) {
35   - return idGenerator.name;
36   - }
37   - }
38   - return null;
39   - }
40   -}
  1 +package com.diligrp.xtrade.order.domain.emuns;
  2 +
  3 +/**
  4 + * @ClassName: IdGenerator
  5 + * @Description id生成key枚举
  6 + * @author zhangxing
  7 + * @date 2020年4月21日
  8 + */
  9 +public enum IdGenerator {
  10 +
  11 + //订单id生成key
  12 + ORDER_SEQUENCE(1,"ORDER_SEQUENCE"),
  13 +
  14 + //订单详情id生成key
  15 + ORDER_ITEM_SEQUENCE(2,"ORDER_ITEM_SEQUENCE");
  16 +
  17 + //编码
  18 + private int code;
  19 +
  20 + //名称
  21 + private String name;
  22 +
  23 + private IdGenerator(int code, String name) {
  24 + this.code = code;
  25 + this.name = name;
  26 + }
  27 +
  28 + public int getCode() {
  29 + return code;
  30 + }
  31 +
  32 + public String getName() {
  33 + return name;
  34 + }
  35 +
  36 + public static IdGenerator getByType(int code) {
  37 + for (IdGenerator idGenerator : values()) {
  38 + if (idGenerator.getCode() == code) {
  39 + return idGenerator;
  40 + }
  41 + }
  42 + return null;
  43 + }
  44 +
  45 + public static String getName(int index) {
  46 + for (IdGenerator idGenerator : IdGenerator.values()) {
  47 + if (idGenerator.getCode() == index) {
  48 + return idGenerator.name;
  49 + }
  50 + }
  51 + return null;
  52 + }
  53 +}
... ...
src/main/java/com/diligrp/xtrade/order/service/impl/OrderServiceImpl.java
... ... @@ -12,7 +12,7 @@ import com.diligrp.xtrade.order.domain.builder.DefaultOrderCreator;
12 12 import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
13 13 import com.diligrp.xtrade.order.domain.dto.OrderQueryRequestDto;
14 14 import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
15   -import com.diligrp.xtrade.order.domain.emuns.IDGenerator;
  15 +import com.diligrp.xtrade.order.domain.emuns.IdGenerator;
16 16 import com.diligrp.xtrade.order.domain.entity.OrderDo;
17 17 import com.diligrp.xtrade.order.service.OrderService;
18 18 import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
... ... @@ -27,7 +27,7 @@ public class OrderServiceImpl implements OrderService {
27 27 @Override
28 28 public void createOrder(OrderCreateRequestDto orderCreateRequestDto) {
29 29 OrderDo order = DefaultOrderCreator.build(orderCreateRequestDto);
30   - order.setOrderId(keyGeneratorManager.getKeyGenerator(IDGenerator.ORDER_SEQUENCE).nextId());
  30 + order.setOrderId(keyGeneratorManager.getKeyGenerator(IdGenerator.ORDER_SEQUENCE).nextId());
31 31 orderDao.insertEntity(order);
32 32 }
33 33  
... ...