Commit 3cac59c94201dc65bed2ed56cfa1339326422d10

Authored by zhangxing
2 parents e33e6638 3ffd4365
src/main/java/com/diligrp/xtrade/product/controllor/ProductApiController.java
1 1 package com.diligrp.xtrade.product.controllor;
2 2  
3   -import com.diligrp.xtrade.product.domain.dto.ProductCreateRequestDto;
4   -import com.diligrp.xtrade.product.domain.dto.ProductQueryRequestDto;
5   -import com.diligrp.xtrade.product.domain.dto.ProductQueryResponsetDto;
6   -import com.diligrp.xtrade.product.service.ProductService;
7   -import com.diligrp.xtrade.shared.domain.Message;
  3 +import javax.annotation.Resource;
  4 +
8 5 import org.springframework.web.bind.annotation.RequestBody;
9 6 import org.springframework.web.bind.annotation.RequestMapping;
10 7 import org.springframework.web.bind.annotation.RestController;
11 8  
12   -import javax.annotation.Resource;
13   -import java.util.List;
  9 +import com.diligrp.xtrade.product.domain.dto.ProductCreateRequestDto;
  10 +import com.diligrp.xtrade.product.domain.dto.ProductQueryRequestDto;
  11 +import com.diligrp.xtrade.product.domain.dto.ProductQueryResponseDto;
  12 +import com.diligrp.xtrade.product.service.ProductService;
  13 +import com.diligrp.xtrade.shared.domain.Message;
  14 +import com.diligrp.xtrade.shared.domain.Page;
14 15  
15 16 @RestController
16 17 @RequestMapping(value = "/sapi/product")
17 18 public class ProductApiController {
18 19  
19   - @Resource
20   - private ProductService productService;
  20 + @Resource private ProductService productService;
21 21  
  22 + /**
  23 + * 创建商品
  24 + *
  25 + * @param productCreateRequestDto
  26 + * @return
  27 + */
22 28 @RequestMapping(value = "/createProduct")
23   - public Message<?> createOrder(@RequestBody ProductCreateRequestDto productCreateRequestDto) {
  29 + public Message<Boolean> createOrder(@RequestBody ProductCreateRequestDto productCreateRequestDto) {
24 30 productService.createProduct(productCreateRequestDto);
25   - return Message.success();
  31 + return Message.success(Boolean.TRUE);
26 32 }
27 33  
  34 + /**
  35 + * 分页查询商品列表 TODO:分页功能
  36 + *
  37 + * @param productQueryRequestDto
  38 + * @return
  39 + */
28 40 @RequestMapping(value = "/listProducts")
29   - public Message<List<ProductQueryResponsetDto>> listOrders(@RequestBody ProductQueryRequestDto productQueryRequestDto) {
30   - return Message.success(productService.orderLists(productQueryRequestDto));
  41 + public Message<Page<ProductQueryResponseDto>> listOrders(@RequestBody ProductQueryRequestDto productQueryRequestDto) {
  42 + return Message.success(productService.productLists(productQueryRequestDto));
31 43 }
32 44  
  45 + /**
  46 + * 查询商品详情
  47 + *
  48 + * @param productQueryRequestDto
  49 + * @return
  50 + */
33 51 @RequestMapping(value = "/productDetail")
34   - public Message<ProductQueryResponsetDto> orderDetail(@RequestBody ProductQueryRequestDto productQueryRequestDto) {
35   - return Message.success(productService.orderDetail(productQueryRequestDto));
  52 + public Message<ProductQueryResponseDto> orderDetail(@RequestBody ProductQueryRequestDto productQueryRequestDto) {
  53 + return Message.success(productService.productDetail(productQueryRequestDto.getProductId()));
36 54 }
37 55  
38 56 }
... ...
src/main/java/com/diligrp/xtrade/product/dao/ProductDao.java
... ... @@ -30,22 +30,13 @@ public interface ProductDao {
30 30  
31 31 /**
32 32 *
33   - * @Title lastSequence
34   - * @Description 返回插入的编号,在事务开启状态下有效
35   - * @return
36   - * @throws
37   - */
38   - int lastSequence();
39   -
40   - /**
41   - *
42 33 * @Title deleteByArrayKey
43   - * @Description 删除记录
  34 + * @Description 批量删除记录
44 35 * @param id 主键
45 36 * @return
46 37 * @throws
47 38 */
48   - int deleteByArrayKey(@Param("id") Long id);
  39 + int deleteByArrayKey(List<Long> ids);
49 40  
50 41 /**
51 42 *
... ...
src/main/java/com/diligrp/xtrade/product/domain/builder/ProductBuilder.java
1 1 package com.diligrp.xtrade.product.domain.builder;
2 2  
  3 +import java.util.Optional;
  4 +
  5 +import com.diligrp.xtrade.product.domain.dto.ProductCreateRequestDto;
  6 +import com.diligrp.xtrade.product.domain.dto.ProductQueryRequestDto;
  7 +import com.diligrp.xtrade.product.domain.dto.ProductQueryResponseDto;
  8 +import com.diligrp.xtrade.product.domain.emuns.ProductStatus;
  9 +import com.diligrp.xtrade.product.domain.entity.ProductDo;
  10 +
  11 +/**
  12 + * @ClassName:ProductBuilder
  13 + * @Description:用于商品相应实体操作
  14 + * @author dengjf
  15 + * @date 2020-04-23
  16 + */
3 17 public class ProductBuilder {
4 18  
  19 + /**
  20 + * 构建基本商品数据
  21 + *
  22 + * @param createDto
  23 + * @return ProductDo
  24 + */
  25 + public static ProductDo buildDoFromCreate(ProductCreateRequestDto createDto) {
  26 + Integer status = Optional.ofNullable(createDto.getStatus())
  27 + .map(ProductStatus::getCode)
  28 + .orElse(null);
  29 + ProductDo productDo = new ProductDo();
  30 + productDo.setProductId(createDto.getProductId());
  31 + productDo.setProductName(createDto.getProductName());
  32 + productDo.setAccountId(createDto.getAccountId());
  33 + productDo.setAccountName(createDto.getAccountName());
  34 + productDo.setCateId(createDto.getCateId());
  35 + productDo.setCateName(createDto.getCateName());
  36 + productDo.setPrice(createDto.getPrice());
  37 + productDo.setUnitWeight(createDto.getUnitWeight());
  38 + productDo.setUnit(createDto.getUnit());
  39 + productDo.setWeight(createDto.getWeight());
  40 + productDo.setStatus(status);
  41 + productDo.setPlace(createDto.getPlace());
  42 + return productDo;
  43 + }
  44 + /**
  45 + * 构建查询商品数据
  46 + *
  47 + * @param queryRequestDto
  48 + * @return ProductDo
  49 + */
  50 + public static ProductDo buildDoFromQueryRequest(ProductQueryRequestDto queryDto) {
  51 + Integer status = Optional.ofNullable(queryDto.getStatus())
  52 + .map(ProductStatus::getCode)
  53 + .orElse(null);
  54 + ProductDo productDo = new ProductDo();
  55 + productDo.setProductId(queryDto.getProductId());
  56 + productDo.setProductName(queryDto.getProductName());
  57 + productDo.setAccountId(queryDto.getAccountId());
  58 + productDo.setAccountName(queryDto.getAccountName());
  59 + productDo.setCateId(queryDto.getCateId());
  60 + productDo.setCateName(queryDto.getCateName());
  61 + productDo.setStatus(status);
  62 + return productDo;
  63 + }
  64 + /**
  65 + * 构建查询商品数据
  66 + *
  67 + * @param ProductDo
  68 + * @return ProductQueryResponseDto
  69 + */
  70 + public static ProductQueryResponseDto buildDoToQueryResponse(ProductDo productDo) {
  71 + ProductQueryResponseDto responseDo = new ProductQueryResponseDto();
  72 + responseDo.setProductId(productDo.getProductId());
  73 + responseDo.setProductName(productDo.getProductName());
  74 + responseDo.setAccountId(productDo.getAccountId());
  75 + responseDo.setAccountName(productDo.getAccountName());
  76 + responseDo.setCateId(productDo.getCateId());
  77 + responseDo.setCateName(productDo.getCateName());
  78 + responseDo.setStatus(productDo.getStatus());
  79 + responseDo.setPrice(productDo.getPrice());
  80 + responseDo.setPlace(productDo.getPlace());
  81 + responseDo.setUnit(productDo.getUnit());
  82 + responseDo.setUnitWeight(productDo.getUnitWeight());
  83 + return responseDo;
  84 + }
  85 +
5 86 }
... ...
src/main/java/com/diligrp/xtrade/product/domain/dto/ProductCreateRequestDto.java
1 1 package com.diligrp.xtrade.product.domain.dto;
2 2  
  3 +import javax.validation.constraints.NotNull;
  4 +
  5 +import com.diligrp.xtrade.product.domain.emuns.ProductStatus;
  6 +
3 7 public class ProductCreateRequestDto {
  8 + //商品业务id
  9 + private Long productId;
  10 +
  11 + //商品名称
  12 + private String productName;
  13 +
  14 + //品类id
  15 + @NotNull(message = "品类id不能为空")
  16 + private Long cateId;
  17 +
  18 + //品类名称
  19 + private String cateName;
  20 +
  21 + //账户Id
  22 + @NotNull(message = "账户id不能为空")
  23 + private Long accountId;
  24 +
  25 + //账户名称
  26 + @NotNull(message = "账户名称不能为空")
  27 + private String accountName;
  28 +
  29 + //商品状态
  30 + private ProductStatus status;
  31 +
  32 + //商品件重
  33 + private Double unitWeight;
  34 +
  35 + //商品单位
  36 + private Integer unit;
  37 +
  38 + //商品价格
  39 + private Long price;
  40 +
  41 + //商品数量
  42 + private Double amount;
  43 +
  44 + //商品重量
  45 + private Double weight;
  46 +
  47 + //商品产地
  48 + private String place;
  49 +
  50 + /**
  51 + * 获取 分类ID
  52 + * @return
  53 + */
  54 + public Long getCateId() {
  55 + return cateId;
  56 + }
  57 +
  58 + /**
  59 + * 设置 分类ID
  60 + * @param cateId
  61 + */
  62 + public void setCateId(Long cateId) {
  63 + this.cateId = cateId;
  64 + }
  65 +
  66 + /**
  67 + * 获取 cateName
  68 + * @return
  69 + */
  70 + public String getCateName() {
  71 + return cateName;
  72 + }
  73 +
  74 + /**
  75 + * 设置 cateName
  76 + * @param cateName
  77 + */
  78 + public void setCateName(String cateName) {
  79 + this.cateName = cateName;
  80 + }
  81 +
  82 + /**
  83 + * 获取 卖家用户ID
  84 + * @return
  85 + */
  86 + public Long getAccountId() {
  87 + return accountId;
  88 + }
  89 +
  90 + /**
  91 + * 设置 卖家用户ID
  92 + * @param accountId
  93 + */
  94 + public void setAccountId(Long accountId) {
  95 + this.accountId = accountId;
  96 + }
  97 +
  98 + /**
  99 + * 获取 卖家用户名
  100 + * @return
  101 + */
  102 + public String getAccountName() {
  103 + return accountName;
  104 + }
  105 +
  106 + /**
  107 + * 设置 卖家用户名
  108 + * @param accountName
  109 + */
  110 + public void setAccountName(String accountName) {
  111 + this.accountName = accountName;
  112 + }
  113 +
  114 + /**
  115 + * 获取 快捷卖货用
  116 + * @return
  117 + */
  118 + public Long getProductId() {
  119 + return productId;
  120 + }
  121 +
  122 + /**
  123 + * 设置 快捷卖货用
  124 + * @param productCode
  125 + */
  126 + public void setProductId(Long productId) {
  127 + this.productId = productId;
  128 + }
  129 +
  130 + /**
  131 + * 获取 productName
  132 + * @return
  133 + */
  134 + public String getProductName() {
  135 + return productName;
  136 + }
  137 +
  138 + /**
  139 + * 设置 productName
  140 + * @param productName
  141 + */
  142 + public void setProductName(String productName) {
  143 + this.productName = productName;
  144 + }
  145 +
  146 + /**
  147 + * 获取 商品状态 1-生效 2-失效 -1-删除
  148 + * @return
  149 + */
  150 + public ProductStatus getStatus() {
  151 + return status;
  152 + }
  153 +
  154 + /**
  155 + * 设置 商品状态 1-生效 2-失效 -1-删除
  156 + * @param status
  157 + */
  158 + public void setStatus(ProductStatus status) {
  159 + this.status = status;
  160 + }
  161 +
  162 + /**
  163 + * 获取 数量
  164 + * @return
  165 + */
  166 + public Double getUnitWeight() {
  167 + return unitWeight;
  168 + }
  169 +
  170 + /**
  171 + * 设置 数量
  172 + * @param unitWeight
  173 + */
  174 + public void setUnitWeight(Double unitWeight) {
  175 + this.unitWeight = unitWeight;
  176 + }
  177 +
  178 + public Double getAmount() {
  179 + return amount;
  180 + }
  181 +
  182 + public void setAmount(Double amount) {
  183 + this.amount = amount;
  184 + }
  185 +
  186 + /**
  187 + * 获取 入库单位1件2斤
  188 + * @return
  189 + */
  190 + public Integer getUnit() {
  191 + return unit;
  192 + }
  193 +
  194 + /**
  195 + * 设置 入库单位1件2斤
  196 + * @param productUnit
  197 + */
  198 + public void setUnit(Integer unit) {
  199 + this.unit = unit;
  200 + }
  201 +
  202 + /**
  203 + * 获取 单价
  204 + * @return
  205 + */
  206 + public Long getPrice() {
  207 + return price;
  208 + }
  209 +
  210 + /**
  211 + * 设置 单价
  212 + * @param price
  213 + */
  214 + public void setPrice(Long price) {
  215 + this.price = price;
  216 + }
  217 +
  218 + /**
  219 + * 获取 总重量
  220 + * @return
  221 + */
  222 + public Double getWeight() {
  223 + return weight;
  224 + }
  225 +
  226 + /**
  227 + * 设置 总重量
  228 + * @param weight
  229 + */
  230 + public void setWeight(Double weight) {
  231 + this.weight = weight;
  232 + }
  233 +
  234 + /**
  235 + * 获取 产地
  236 + * @return
  237 + */
  238 + public String getPlace() {
  239 + return place;
  240 + }
4 241  
  242 + /**
  243 + * 设置 产地
  244 + * @param place
  245 + */
  246 + public void setPlace(String place) {
  247 + this.place = place;
  248 + }
5 249 }
... ...
src/main/java/com/diligrp/xtrade/product/domain/dto/ProductQueryRequestDto.java
1 1 package com.diligrp.xtrade.product.domain.dto;
2 2  
  3 +import com.diligrp.xtrade.product.domain.emuns.ProductStatus;
  4 +
3 5 public class ProductQueryRequestDto {
  6 + //商品业务id
  7 + private Long productId;
  8 +
  9 + //商品名称
  10 + private String productName;
  11 +
  12 + //品类id
  13 + private Long cateId;
  14 +
  15 + //品类名称
  16 + private String cateName;
  17 +
  18 + //账户Id
  19 + private Long accountId;
  20 +
  21 + //账户名称
  22 + private String accountName;
  23 +
  24 + //商品状态
  25 + private ProductStatus status;
  26 +
  27 +
  28 +
  29 +
  30 + public Long getProductId() {
  31 + return productId;
  32 + }
  33 +
  34 + public void setProductId(Long productId) {
  35 + this.productId = productId;
  36 + }
  37 +
  38 + public String getProductName() {
  39 + return productName;
  40 + }
  41 +
  42 + public void setProductName(String productName) {
  43 + this.productName = productName;
  44 + }
  45 +
  46 + public Long getCateId() {
  47 + return cateId;
  48 + }
  49 +
  50 + public void setCateId(Long cateId) {
  51 + this.cateId = cateId;
  52 + }
  53 +
  54 + public String getCateName() {
  55 + return cateName;
  56 + }
  57 +
  58 + public void setCateName(String cateName) {
  59 + this.cateName = cateName;
  60 + }
  61 +
  62 + public Long getAccountId() {
  63 + return accountId;
  64 + }
  65 +
  66 + public void setAccountId(Long accountId) {
  67 + this.accountId = accountId;
  68 + }
  69 +
  70 + public String getAccountName() {
  71 + return accountName;
  72 + }
  73 +
  74 + public void setAccountName(String accountName) {
  75 + this.accountName = accountName;
  76 + }
  77 +
  78 +
  79 + public ProductStatus getStatus() {
  80 + return status;
  81 + }
4 82  
  83 + public void setStatus(ProductStatus status) {
  84 + this.status = status;
  85 + }
  86 +
5 87 }
... ...
src/main/java/com/diligrp/xtrade/product/domain/dto/ProductQueryResponseDto.java 0 → 100644
  1 +package com.diligrp.xtrade.product.domain.dto;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class ProductQueryResponseDto implements Serializable{
  6 + //商品业务id
  7 + private Long productId;
  8 +
  9 + //商品名称
  10 + private String productName;
  11 +
  12 + //品类id
  13 + private Long cateId;
  14 +
  15 + //品类名称
  16 + private String cateName;
  17 +
  18 + //账户Id
  19 + private Long accountId;
  20 +
  21 + //账户名称
  22 + private String accountName;
  23 +
  24 + //商品状态
  25 + private Integer status;
  26 +
  27 + //商品件重
  28 + private Double unitWeight;
  29 +
  30 + //商品单位
  31 + private Integer unit;
  32 +
  33 + //商品价格
  34 + private Long price;
  35 +
  36 + //商品数量
  37 + private Double amount;
  38 +
  39 + //商品重量
  40 + private Double weight;
  41 +
  42 + //商品产地
  43 + private String place;
  44 +
  45 + /**
  46 + * 获取 分类ID
  47 + * @return
  48 + */
  49 + public Long getCateId() {
  50 + return cateId;
  51 + }
  52 +
  53 + /**
  54 + * 设置 分类ID
  55 + * @param cateId
  56 + */
  57 + public void setCateId(Long cateId) {
  58 + this.cateId = cateId;
  59 + }
  60 +
  61 + /**
  62 + * 获取 cateName
  63 + * @return
  64 + */
  65 + public String getCateName() {
  66 + return cateName;
  67 + }
  68 +
  69 + /**
  70 + * 设置 cateName
  71 + * @param cateName
  72 + */
  73 + public void setCateName(String cateName) {
  74 + this.cateName = cateName;
  75 + }
  76 +
  77 + /**
  78 + * 获取 卖家用户ID
  79 + * @return
  80 + */
  81 + public Long getAccountId() {
  82 + return accountId;
  83 + }
  84 +
  85 + /**
  86 + * 设置 卖家用户ID
  87 + * @param accountId
  88 + */
  89 + public void setAccountId(Long accountId) {
  90 + this.accountId = accountId;
  91 + }
  92 +
  93 + /**
  94 + * 获取 卖家用户名
  95 + * @return
  96 + */
  97 + public String getAccountName() {
  98 + return accountName;
  99 + }
  100 +
  101 + /**
  102 + * 设置 卖家用户名
  103 + * @param accountName
  104 + */
  105 + public void setAccountName(String accountName) {
  106 + this.accountName = accountName;
  107 + }
  108 +
  109 + /**
  110 + * 获取 快捷卖货用
  111 + * @return
  112 + */
  113 + public Long getProductId() {
  114 + return productId;
  115 + }
  116 +
  117 + /**
  118 + * 设置 快捷卖货用
  119 + * @param productCode
  120 + */
  121 + public void setProductId(Long productId) {
  122 + this.productId = productId;
  123 + }
  124 +
  125 + /**
  126 + * 获取 productName
  127 + * @return
  128 + */
  129 + public String getProductName() {
  130 + return productName;
  131 + }
  132 +
  133 + /**
  134 + * 设置 productName
  135 + * @param productName
  136 + */
  137 + public void setProductName(String productName) {
  138 + this.productName = productName;
  139 + }
  140 +
  141 + /**
  142 + * 获取 商品状态 1-生效 2-失效 -1-删除
  143 + * @return
  144 + */
  145 + public Integer getStatus() {
  146 + return status;
  147 + }
  148 +
  149 + /**
  150 + * 设置 商品状态 1-生效 2-失效 -1-删除
  151 + * @param status
  152 + */
  153 + public void setStatus(Integer status) {
  154 + this.status = status;
  155 + }
  156 +
  157 + /**
  158 + * 获取 数量
  159 + * @return
  160 + */
  161 + public Double getUnitWeight() {
  162 + return unitWeight;
  163 + }
  164 +
  165 + /**
  166 + * 设置 数量
  167 + * @param unitWeight
  168 + */
  169 + public void setUnitWeight(Double unitWeight) {
  170 + this.unitWeight = unitWeight;
  171 + }
  172 +
  173 + public Double getAmount() {
  174 + return amount;
  175 + }
  176 +
  177 + public void setAmount(Double amount) {
  178 + this.amount = amount;
  179 + }
  180 +
  181 + /**
  182 + * 获取 入库单位1件2斤
  183 + * @return
  184 + */
  185 + public Integer getUnit() {
  186 + return unit;
  187 + }
  188 +
  189 + /**
  190 + * 设置 入库单位1件2斤
  191 + * @param productUnit
  192 + */
  193 + public void setUnit(Integer unit) {
  194 + this.unit = unit;
  195 + }
  196 +
  197 + /**
  198 + * 获取 单价
  199 + * @return
  200 + */
  201 + public Long getPrice() {
  202 + return price;
  203 + }
  204 +
  205 + /**
  206 + * 设置 单价
  207 + * @param price
  208 + */
  209 + public void setPrice(Long price) {
  210 + this.price = price;
  211 + }
  212 +
  213 + /**
  214 + * 获取 总重量
  215 + * @return
  216 + */
  217 + public Double getWeight() {
  218 + return weight;
  219 + }
  220 +
  221 + /**
  222 + * 设置 总重量
  223 + * @param weight
  224 + */
  225 + public void setWeight(Double weight) {
  226 + this.weight = weight;
  227 + }
  228 +
  229 + /**
  230 + * 获取 产地
  231 + * @return
  232 + */
  233 + public String getPlace() {
  234 + return place;
  235 + }
  236 +
  237 + /**
  238 + * 设置 产地
  239 + * @param place
  240 + */
  241 + public void setPlace(String place) {
  242 + this.place = place;
  243 + }
  244 +}
... ...
src/main/java/com/diligrp/xtrade/product/domain/dto/ProductQueryResponsetDto.java deleted 100644 → 0
1   -package com.diligrp.xtrade.product.domain.dto;
2   -
3   -public class ProductQueryResponsetDto {
4   -
5   -}
src/main/java/com/diligrp/xtrade/product/domain/emuns/IKeyGeneratorKeys.java
... ... @@ -12,6 +12,7 @@ public enum IKeyGeneratorKeys {
12 12 SHOP_SEQUENCE("SHOP_SEQUENCE", "店铺id"),
13 13 MERCHANT_SEQUENCE("MERCHANT_SEQUENCE", "市场id"),
14 14 ACCOUNT_SEQUENCE("ACCOUNT_SEQUENCE", "账号id"),
  15 + PRODUCT_SEQUENCE("PRODUCT_SEQUENCE", "商品id"),
15 16 ;
16 17  
17 18 private String code;
... ...
src/main/java/com/diligrp/xtrade/product/domain/emuns/ProductStatus.java
1 1 package com.diligrp.xtrade.product.domain.emuns;
2 2  
3   -public enum ProductStatus {
  3 +import java.util.Arrays;
  4 +
  5 +import com.diligrp.xtrade.shared.type.IEnumType;
  6 +import com.fasterxml.jackson.annotation.JsonCreator;
  7 +import com.fasterxml.jackson.annotation.JsonValue;
  8 +
  9 +public enum ProductStatus implements IEnumType {
  10 +
  11 + /**删除*/
  12 + DELETED(-1, "已删除"),
  13 + /**未上架*/
  14 + UNSHELF(1, "未上架"),
  15 + /**上架*/
  16 + UPPERSHELF(2, "上架"),
  17 + /**下架*/
  18 + LOWERSHELF(3, "下架");
  19 +
  20 +
  21 + private int code;
  22 + private String name;
  23 +
  24 + ProductStatus(int code, String name) {
  25 + this.name = name;
  26 + this.code = code;
  27 + }
  28 +
  29 + @JsonCreator
  30 + public static ProductStatus getProductStatus(int code) {
  31 + return Arrays.stream(ProductStatus.values())
  32 + .filter(status -> status.getCode() == code)
  33 + .findFirst()
  34 + .orElse(null);
  35 + }
  36 +
  37 + public static String getName(int code) {
  38 + return Arrays.stream(ProductStatus.values())
  39 + .filter(status -> status.getCode() == code)
  40 + .findFirst()
  41 + .map(status -> status.name)
  42 + .orElse(null);
  43 + }
  44 +
  45 + @Override
  46 + public String getName() {
  47 + return this.name;
  48 + }
  49 +
  50 + @Override
  51 + @JsonValue
  52 + public int getCode() {
  53 + return this.code;
  54 + }
4 55  
5 56 }
... ...
src/main/java/com/diligrp/xtrade/product/service/ProductService.java
1 1 package com.diligrp.xtrade.product.service;
2 2  
3   -import java.util.List;
4   -
5 3 import com.diligrp.xtrade.product.domain.dto.ProductCreateRequestDto;
6 4 import com.diligrp.xtrade.product.domain.dto.ProductQueryRequestDto;
7   -import com.diligrp.xtrade.product.domain.dto.ProductQueryResponsetDto;
  5 +import com.diligrp.xtrade.product.domain.dto.ProductQueryResponseDto;
  6 +import com.diligrp.xtrade.shared.domain.Page;
8 7  
9 8 public interface ProductService {
10 9  
11 10 void createProduct(ProductCreateRequestDto productCreateRequestDto);
12 11  
13   - List<ProductQueryResponsetDto> orderLists(ProductQueryRequestDto productQueryRequestDto);
  12 + Page<ProductQueryResponseDto> productLists(ProductQueryRequestDto productQueryRequestDto);
14 13  
15   - ProductQueryResponsetDto orderDetail(ProductQueryRequestDto productQueryRequestDto);
  14 + ProductQueryResponseDto productDetail(Long productId);
16 15  
17 16 }
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/ProductServiceImpl.java
1 1 package com.diligrp.xtrade.product.service.impl;
2 2  
  3 +import java.util.ArrayList;
3 4 import java.util.List;
4 5  
  6 +import javax.annotation.Resource;
  7 +
  8 +import org.springframework.beans.BeanUtils;
5 9 import org.springframework.stereotype.Service;
6 10  
  11 +import com.diligrp.xtrade.product.dao.ProductDao;
  12 +import com.diligrp.xtrade.product.domain.builder.ProductBuilder;
7 13 import com.diligrp.xtrade.product.domain.dto.ProductCreateRequestDto;
8 14 import com.diligrp.xtrade.product.domain.dto.ProductQueryRequestDto;
9   -import com.diligrp.xtrade.product.domain.dto.ProductQueryResponsetDto;
  15 +import com.diligrp.xtrade.product.domain.dto.ProductQueryResponseDto;
  16 +import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;
  17 +import com.diligrp.xtrade.product.domain.entity.ProductDo;
10 18 import com.diligrp.xtrade.product.service.ProductService;
  19 +import com.diligrp.xtrade.shared.domain.Page;
  20 +import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
11 21  
12 22 @Service("productService")
13 23 public class ProductServiceImpl implements ProductService {
14 24  
  25 + @Resource ProductDao productDao;
  26 + @Resource KeyGeneratorManager keyGeneratorManager;
  27 +
15 28 @Override
16 29 public void createProduct(ProductCreateRequestDto productCreateRequestDto) {
17   -
  30 + Long productId = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.PRODUCT_SEQUENCE).nextId();
  31 + productCreateRequestDto.setProductId(productId);
  32 + ProductDo productDo = ProductBuilder.buildDoFromCreate(productCreateRequestDto);
  33 + productDao.insertEntity(productDo);
18 34 }
19 35  
20 36 @Override
21   - public List<ProductQueryResponsetDto> orderLists(ProductQueryRequestDto productQueryRequestDto) {
22   - return null;
  37 + public Page<ProductQueryResponseDto> productLists(ProductQueryRequestDto queryDto) {
  38 + Page<ProductQueryResponseDto> productPage = new Page<ProductQueryResponseDto>();
  39 + List<ProductQueryResponseDto> productList = new ArrayList<ProductQueryResponseDto>();
  40 + ProductDo product = new ProductDo();
  41 + BeanUtils.copyProperties(queryDto, product);
  42 + int total = productDao.selectEntryListCount(product);
  43 + if (total == 0) {
  44 + return productPage;
  45 + }
  46 + List<ProductDo> productDos = productDao.selectEntryList(product);
  47 + for (ProductDo productDo : productDos) {
  48 + ProductQueryResponseDto productQueryResponseDto = new ProductQueryResponseDto();
  49 + BeanUtils.copyProperties(productDo, productQueryResponseDto);
  50 + productList.add(productQueryResponseDto);
  51 + }
  52 + productPage.setTotal(total);
  53 + productPage.setData(productList);
  54 + return productPage;
23 55 }
24 56  
25 57 @Override
26   - public ProductQueryResponsetDto orderDetail(ProductQueryRequestDto productQueryRequestDto) {
27   - return null;
  58 + public ProductQueryResponseDto productDetail(Long productId) {
  59 + return ProductBuilder.buildDoToQueryResponse(productDao.selectEntryById(productId));
28 60 }
29 61  
30 62 }
... ...
src/main/resources/mapping/com/diligrp/xtrade/product/ProductDao.xml
... ... @@ -65,14 +65,11 @@
65 65 <insert id="insertEntry" parameterType="productDo">
66 66 <![CDATA[
67 67 INSERT INTO xt_product (id,product_id,product_name,cate_id,cname,account_id,account_name,price,unit_weight,unit,amount,weight,status,place,created_time,modified_time)
68   - VALUES (#{id},#{productId},#{productName},#{cateId},#{cname},#{accountId},#{accountName},#{price},#{unitWeight},#{unit},#{amount},#{weight},#{status},#{place},#{createdTime},#{modifiedTime})
  68 + VALUES (#{id},#{productId},#{productName},#{cateId},#{cname},#{accountId},#{accountName},#{price},#{unitWeight},#{unit},#{amount},#{weight},1,#{status},#{place},now(),now())
69 69 ]]>
70 70 </insert>
71 71  
72   - <!-- 返回插入的编号,在事务开启状态下有效 -->
73   - <select id="lastSequence" resultType="int"><![CDATA[SELECT LAST_INSERT_ID() AS id]]></select>
74   -
75   - <!-- 删除记录,主键IN(array) -->
  72 + <!-- 批量删除记录,主键IN(array) -->
76 73 <delete id="deleteByArrayKey"
77 74 parameterType="java.lang.reflect.Array">
78 75 <![CDATA[DELETE FROM xt_product WHERE id IN]]>
... ...