Commit 1fc09b8aa21b867c6fe5b851c0c8961f77a37ff5

Authored by miaoguoxin
2 parents e1585fd2 63794f75

Merge remote-tracking branch 'origin/master'

src/main/java/com/diligrp/xtrade/order/controllor/OrderApiController.java
1 1 package com.diligrp.xtrade.order.controllor;
2 2  
3   -import java.util.List;
4   -
5 3 import javax.annotation.Resource;
6 4  
7 5 import org.springframework.validation.annotation.Validated;
... ... @@ -11,10 +9,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
11 9 import org.springframework.web.bind.annotation.RestController;
12 10  
13 11 import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
14   -import com.diligrp.xtrade.order.domain.dto.OrderQueryRequestDto;
15   -import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
  12 +import com.diligrp.xtrade.order.domain.dto.OrderRequestDto;
  13 +import com.diligrp.xtrade.order.domain.dto.OrderResponseDto;
16 14 import com.diligrp.xtrade.order.service.OrderService;
17 15 import com.diligrp.xtrade.shared.domain.Message;
  16 +import com.diligrp.xtrade.shared.domain.Page;
18 17  
19 18 /**
20 19 * 订单相关接口实现
... ... @@ -41,7 +40,7 @@ public class OrderApiController {
41 40 * 订单列表接口
42 41 */
43 42 @RequestMapping(value = "/listOrders")
44   - public Message<List<OrderQueryResponseDto>> listOrders(@RequestBody OrderQueryRequestDto orderQueryRequestDto) {
  43 + public Message<Page<OrderResponseDto>> listOrders(@RequestBody OrderRequestDto orderQueryRequestDto) {
45 44 return Message.success(orderservice.orderLists(orderQueryRequestDto));
46 45 }
47 46  
... ... @@ -49,7 +48,16 @@ public class OrderApiController {
49 48 * 订单详情
50 49 */
51 50 @RequestMapping(value = "/orderDetail")
52   - public Message<OrderQueryResponseDto> orderDetail(@RequestBody @Validated OrderQueryRequestDto orderQueryRequestDto) {
  51 + public Message<OrderResponseDto> orderDetail(@RequestBody @Validated OrderRequestDto orderQueryRequestDto) {
53 52 return Message.success(orderservice.orderDetail(orderQueryRequestDto.getOrderId()));
54 53 }
  54 +
  55 + /**
  56 + * 订单详情
  57 + */
  58 + @RequestMapping(value = "/updateBuyer")
  59 + public Message<Boolean> updateBuyer(@RequestBody @Validated OrderRequestDto orderQueryRequestDto) {
  60 + orderservice.updateBuyer(orderQueryRequestDto);
  61 + return Message.success(Boolean.TRUE);
  62 + }
55 63 }
... ...
src/main/java/com/diligrp/xtrade/order/dao/OrderDao.java
... ... @@ -66,8 +66,8 @@ public interface OrderDao {
66 66 * @return
67 67 * @throws
68 68 */
69   - int updateBuyerInfo(@Param("baccount") Long baccount, @Param("bcardNo") Long bcardNo,
70   - @Param("bcardType") Long bcardType, @Param("bname") Long bname, @Param("bmobile") Long bmobile);
  69 + int updateBuyerInfo(@Param("baccount") Long baccount, @Param("bcardNo") String bcardNo,
  70 + @Param("bcardType") Integer bcardType, @Param("bname") String bname, @Param("bmobile") String bmobile);
71 71  
72 72 /**
73 73 *
... ...
src/main/java/com/diligrp/xtrade/order/domain/builder/OrderDataBuilder.java
... ... @@ -5,7 +5,7 @@ import java.util.List;
5 5 import org.springframework.beans.BeanUtils;
6 6  
7 7 import com.diligrp.xtrade.order.domain.dto.OrderItemDto;
8   -import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
  8 +import com.diligrp.xtrade.order.domain.dto.OrderResponseDto;
9 9 import com.diligrp.xtrade.order.domain.entity.OrderDo;
10 10 import com.diligrp.xtrade.order.domain.entity.OrderItemDo;
11 11  
... ... @@ -21,8 +21,8 @@ public class OrderDataBuilder {
21 21 /**
22 22 * 构建基本的订单详情数据 TODO need modify because of change
23 23 */
24   - public static OrderQueryResponseDto buildOrderDetail(OrderDo order, List<OrderItemDo> orderItem) {
25   - OrderQueryResponseDto orderResponseDto = new OrderQueryResponseDto();
  24 + public static OrderResponseDto buildOrderDetail(OrderDo order, List<OrderItemDo> orderItem) {
  25 + OrderResponseDto orderResponseDto = new OrderResponseDto();
26 26 BeanUtils.copyProperties(order, orderResponseDto);
27 27 for (OrderItemDo orderItemDo : orderItem) {
28 28 OrderItemDto orderItemDto = new OrderItemDto();
... ...
src/main/java/com/diligrp/xtrade/order/domain/dto/OrderQueryRequestDto.java renamed to src/main/java/com/diligrp/xtrade/order/domain/dto/OrderRequestDto.java
... ... @@ -2,6 +2,9 @@ package com.diligrp.xtrade.order.domain.dto;
2 2  
3 3 import java.time.LocalDateTime;
4 4  
  5 +import javax.validation.constraints.Min;
  6 +import javax.validation.constraints.NotNull;
  7 +
5 8 import com.diligrp.xtrade.shared.domain.BaseDo;
6 9  
7 10 /**
... ... @@ -11,9 +14,11 @@ import com.diligrp.xtrade.shared.domain.BaseDo;
11 14 * @author zhangxing
12 15 * @date 2020年4月21日
13 16 */
14   -public class OrderQueryRequestDto extends BaseDo{
  17 +public class OrderRequestDto extends BaseDo{
15 18  
16 19 // 订单业务id
  20 + @NotNull(message = "订单号不能为空")
  21 + @Min(message = "订单号非法", value = 1)
17 22 private Long orderId;
18 23  
19 24 // 卖家账号
... ...
src/main/java/com/diligrp/xtrade/order/domain/dto/OrderQueryResponseDto.java renamed to src/main/java/com/diligrp/xtrade/order/domain/dto/OrderResponseDto.java
... ... @@ -10,7 +10,7 @@ import java.util.List;
10 10 * @author zhangxing
11 11 * @date 2020年4月21日
12 12 */
13   -public class OrderQueryResponseDto {
  13 +public class OrderResponseDto {
14 14  
15 15  
16 16 //订单业务id
... ...
src/main/java/com/diligrp/xtrade/order/domain/emuns/OrderStatus.java
... ... @@ -11,7 +11,9 @@ public enum OrderStatus {
11 11 /**
12 12 * 未支付
13 13 */
14   - UNPAIED(1, "未支付");
  14 + UNPAIED(1, "未支付"),
  15 +
  16 + PAIED(3, "未支付");
15 17  
16 18 // 编码
17 19 private int code;
... ...
src/main/java/com/diligrp/xtrade/order/exception/OrderError.java 0 → 100644
  1 +package com.diligrp.xtrade.order.exception;
  2 +
  3 +import java.util.Arrays;
  4 +
  5 +import com.diligrp.xtrade.shared.type.IEnumType;
  6 +
  7 +/**
  8 + * 订单错误信息描述
  9 + */
  10 +public enum OrderError implements IEnumType{
  11 +
  12 + ORDER_NOT_EXIST(300001, "订单不存在"),
  13 + ORDER_IS_PAIED(300002, "订单已支付"),
  14 + ORDER_IS_CLOSED(300003, "订单已关闭"),
  15 + SELLER_EQUAL_BUYER(300004, "买卖家相同");
  16 +
  17 + private int code;
  18 + private String name;
  19 +
  20 + OrderError(int code, String name) {
  21 + this.setCode(code);
  22 + this.name = name;
  23 + }
  24 +
  25 + public static OrderError getByType(int code) {
  26 + return Arrays.stream(values())
  27 + .filter(e -> e.getCode() == code)
  28 + .findFirst()
  29 + .orElse(null);
  30 + }
  31 +
  32 + public static String getName(int index) {
  33 + return Arrays.stream(OrderError.values())
  34 + .filter(e -> e.getCode() == index)
  35 + .findFirst().map(e -> e.name)
  36 + .orElse(null);
  37 + }
  38 +
  39 +
  40 + @Override
  41 + public int getCode() {
  42 + return this.code;
  43 + }
  44 +
  45 + @Override
  46 + public String getName() {
  47 + return this.name;
  48 + }
  49 +
  50 + public void setCode(int code) {
  51 + this.code = code;
  52 + }
  53 +
  54 +}
... ...
src/main/java/com/diligrp/xtrade/order/exception/OrderException.java
1   -package com.diligrp.xtrade.order.exception;
2   -
3   -public class OrderException extends RuntimeException{
4   -
5   - private static final long serialVersionUID = 1L;
6   -
7   - private static final int DEFAULT_CODE = 1000;
8   -
9   - private int code;
10   -
11   - public OrderException() {
12   - super();
13   - }
14   -
15   - public OrderException(String message, int code){
16   - super(message);
17   - this.code = code;
18   - }
19   -
20   - public OrderException(String message) {
21   - this(message, DEFAULT_CODE);
22   - }
23   -
24   - public OrderException(String message, Throwable cause) {
25   - super(message, cause);
26   - this.code = DEFAULT_CODE;
27   - }
28   -
29   - public OrderException(Throwable cause) {
30   - super(cause);
31   - this.code = DEFAULT_CODE;
32   - }
33   -
34   - public int getCode() {
35   - return code;
36   - }
37   -
38   - public void setCode(int code) {
39   - this.code = code;
40   - }
41   -
42   -}
  1 +package com.diligrp.xtrade.order.exception;
  2 +
  3 +public class OrderException extends RuntimeException{
  4 +
  5 + private static final long serialVersionUID = 1L;
  6 +
  7 + private static final int DEFAULT_CODE = 1000;
  8 +
  9 + private int code;
  10 +
  11 + public OrderException() {
  12 + super();
  13 + }
  14 +
  15 + public OrderException(String message, int code){
  16 + super(message);
  17 + this.code = code;
  18 + }
  19 +
  20 + public OrderException(OrderError orderError){
  21 + super(orderError.getName());
  22 + this.code = orderError.getCode();
  23 + }
  24 +
  25 + public OrderException(String message) {
  26 + this(message, DEFAULT_CODE);
  27 + }
  28 +
  29 + public OrderException(String message, Throwable cause) {
  30 + super(message, cause);
  31 + this.code = DEFAULT_CODE;
  32 + }
  33 +
  34 + public OrderException(Throwable cause) {
  35 + super(cause);
  36 + this.code = DEFAULT_CODE;
  37 + }
  38 +
  39 + public int getCode() {
  40 + return code;
  41 + }
  42 +
  43 + public void setCode(int code) {
  44 + this.code = code;
  45 + }
  46 +
  47 +}
... ...
src/main/java/com/diligrp/xtrade/order/service/OrderService.java
1 1 package com.diligrp.xtrade.order.service;
2 2  
3 3 import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
4   -import com.diligrp.xtrade.order.domain.dto.OrderQueryRequestDto;
5   -import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
  4 +import com.diligrp.xtrade.order.domain.dto.OrderRequestDto;
  5 +import com.diligrp.xtrade.order.domain.dto.OrderResponseDto;
6 6 import com.diligrp.xtrade.shared.domain.Page;
7 7  
8 8 /**
... ... @@ -24,11 +24,18 @@ public interface OrderService {
24 24 * @Title orderLists
25 25 * @Description 获取订单列表
26 26 */
27   - Page<OrderQueryResponseDto> orderLists(OrderQueryRequestDto orderQueryRequestDto);
  27 + Page<OrderResponseDto> orderLists(OrderRequestDto orderQueryRequestDto);
28 28  
29 29 /**
30 30 * @Title orderDetail
31 31 * @Description 获取订单详情
32 32 */
33   - OrderQueryResponseDto orderDetail(Long orderId);
  33 + OrderResponseDto orderDetail(Long orderId);
  34 +
  35 + /**
  36 + *
  37 + * @Title updateBuyer
  38 + * @Description 更新买家信息
  39 + */
  40 + void updateBuyer(OrderRequestDto orderQueryRequestDto);
34 41 }
... ...
src/main/java/com/diligrp/xtrade/order/service/impl/OrderServiceImpl.java
... ... @@ -16,10 +16,13 @@ import com.diligrp.xtrade.order.domain.builder.OrderDataBuilder;
16 16 import com.diligrp.xtrade.order.domain.dto.AccountDto;
17 17 import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
18 18 import com.diligrp.xtrade.order.domain.dto.OrderItemDto;
19   -import com.diligrp.xtrade.order.domain.dto.OrderQueryRequestDto;
20   -import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
  19 +import com.diligrp.xtrade.order.domain.dto.OrderRequestDto;
  20 +import com.diligrp.xtrade.order.domain.dto.OrderResponseDto;
21 21 import com.diligrp.xtrade.order.domain.emuns.IdGenerator;
  22 +import com.diligrp.xtrade.order.domain.emuns.OrderStatus;
22 23 import com.diligrp.xtrade.order.domain.entity.OrderDo;
  24 +import com.diligrp.xtrade.order.exception.OrderError;
  25 +import com.diligrp.xtrade.order.exception.OrderException;
23 26 import com.diligrp.xtrade.order.rpc.feign.AccountResolver;
24 27 import com.diligrp.xtrade.order.service.OrderService;
25 28 import com.diligrp.xtrade.shared.domain.Page;
... ... @@ -68,9 +71,29 @@ public class OrderServiceImpl implements OrderService {
68 71  
69 72 // TODO need modify because of change
70 73 @Override
71   - public Page<OrderQueryResponseDto> orderLists(OrderQueryRequestDto orderQueryRequestDto) {
72   - Page<OrderQueryResponseDto> orderPage = new Page<OrderQueryResponseDto>();
73   - List<OrderQueryResponseDto> roResponseDtos = new ArrayList<OrderQueryResponseDto>();
  74 + public void updateBuyer(OrderRequestDto orderRequestDto) {
  75 + OrderDo orderDo = orderDao.selectEntityByOrderId(orderRequestDto.getOrderId());
  76 + if (orderDo == null) {
  77 + throw new OrderException(OrderError.ORDER_NOT_EXIST);
  78 + }
  79 + if (orderDo.getOrderStatus() == OrderStatus.PAIED.getCode()) {
  80 + throw new OrderException(OrderError.ORDER_IS_PAIED);
  81 + }
  82 +
  83 + AccountDto buyer = accountResolver.getAccount(orderRequestDto.getBaccount());
  84 + if (orderDo.getSaccount().equals(orderRequestDto.getBaccount())
  85 + || orderDo.getSaccount().equals(buyer.getParentAccountId())) {
  86 + throw new OrderException(OrderError.SELLER_EQUAL_BUYER);
  87 + }
  88 + orderDao.updateBuyerInfo(buyer.getAccountId(), buyer.getCardNo(), buyer.getType(), buyer.getAccountName(),
  89 + buyer.getMobile());
  90 + }
  91 +
  92 + // TODO need modify because of change
  93 + @Override
  94 + public Page<OrderResponseDto> orderLists(OrderRequestDto orderQueryRequestDto) {
  95 + Page<OrderResponseDto> orderPage = new Page<OrderResponseDto>();
  96 + List<OrderResponseDto> roResponseDtos = new ArrayList<OrderResponseDto>();
74 97 orderPage.setData(roResponseDtos);
75 98 OrderDo order = new OrderDo();
76 99 BeanUtils.copyProperties(orderQueryRequestDto, order);
... ... @@ -80,7 +103,7 @@ public class OrderServiceImpl implements OrderService {
80 103 }
81 104 List<OrderDo> orderDos = orderDao.selectEntryList(order);
82 105 for (OrderDo orderDo : orderDos) {
83   - OrderQueryResponseDto orderQueryResponseDto = new OrderQueryResponseDto();
  106 + OrderResponseDto orderQueryResponseDto = new OrderResponseDto();
84 107 BeanUtils.copyProperties(orderDo, orderQueryResponseDto);
85 108 roResponseDtos.add(orderQueryResponseDto);
86 109 }
... ... @@ -89,9 +112,9 @@ public class OrderServiceImpl implements OrderService {
89 112  
90 113 // TODO need modify because of change
91 114 @Override
92   - public OrderQueryResponseDto orderDetail(Long orderId) {
93   - OrderQueryResponseDto orderResponseDto = OrderDataBuilder
94   - .buildOrderDetail(orderDao.selectEntityByOrderId(orderId), orderItemDao.selectItemsByOrderId(orderId));
  115 + public OrderResponseDto orderDetail(Long orderId) {
  116 + OrderResponseDto orderResponseDto = OrderDataBuilder.buildOrderDetail(orderDao.selectEntityByOrderId(orderId),
  117 + orderItemDao.selectItemsByOrderId(orderId));
95 118 return orderResponseDto;
96 119 }
97 120  
... ...
src/main/java/com/diligrp/xtrade/product/common/utils/ImageUtil.java 0 → 100644
  1 +package com.diligrp.xtrade.product.common.utils;
  2 +
  3 +import java.awt.image.BufferedImage;
  4 +import java.io.IOException;
  5 +import java.io.InputStream;
  6 +import java.security.MessageDigest;
  7 +import java.security.NoSuchAlgorithmException;
  8 +
  9 +import javax.imageio.ImageIO;
  10 +
  11 +import com.diligrp.xtrade.product.exception.ExceptionEnum;
  12 +import com.diligrp.xtrade.product.exception.ProductException;
  13 +
  14 +
  15 +/**
  16 + *
  17 + * <B>Description</B> 图片工具类 <br />
  18 + * <B>Copyright</B> Copyright (c) 2015 www.diligrp.com All rights reserved. <br />
  19 + * 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
  20 + * <B>Company</B> 地利集团
  21 + * @createTime 2015年4月24日 上午11:30:36
  22 + * @author celine
  23 + */
  24 +public class ImageUtil {
  25 +
  26 + /**
  27 + * 检测文件是否是图片
  28 + * @param inputStream
  29 + * @return
  30 + * @createTime 2015年4月24日 上午11:35:29
  31 + * @author celine
  32 + */
  33 + public static Boolean isImage(InputStream inputStream) {
  34 + try {
  35 + BufferedImage bi = ImageIO.read(inputStream);
  36 + return null == bi ? false : true;
  37 + } catch (IOException e) {
  38 + throw new ProductException(ExceptionEnum.FILE_UP_ERROR);
  39 + }
  40 + }
  41 +
  42 + public static Boolean checkImageSize(InputStream inputStream, int maxWidth, int maxHeight, int minWidth,
  43 + int minHeight) {
  44 + try {
  45 + BufferedImage bi = ImageIO.read(inputStream);
  46 + if (bi != null) {
  47 + if (bi.getWidth() <= maxWidth && bi.getHeight() <= maxHeight && bi.getWidth() >= minWidth
  48 + && bi.getHeight() >= minHeight) {
  49 + return true;
  50 + }
  51 + }
  52 + return false;
  53 + } catch (IOException e) {
  54 + throw new ProductException(ExceptionEnum.FILE_UP_ERROR);
  55 + }
  56 + }
  57 +
  58 + public static String getMd5(byte[] imgBytes) {
  59 + if (imgBytes != null && imgBytes.length > 0) {
  60 + StringBuilder sb = new StringBuilder();
  61 + MessageDigest md5;
  62 + try {
  63 + md5 = MessageDigest.getInstance("MD5");
  64 + } catch (NoSuchAlgorithmException e) {
  65 + throw new ProductException(ExceptionEnum.FILE_UP_ERROR);
  66 + }
  67 + md5.update(imgBytes);
  68 + for (byte by : md5.digest()) {
  69 + sb.append(String.format("%02X", by));
  70 + }
  71 + return sb.toString();
  72 + }
  73 + return "";
  74 + }
  75 +
  76 +}
... ...
src/main/java/com/diligrp/xtrade/product/controllor/CategoryController.java
1 1 package com.diligrp.xtrade.product.controllor;
2 2  
  3 +import java.io.IOException;
3 4 import java.util.List;
4 5  
5 6 import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.beans.factory.annotation.Value;
6 8 import org.springframework.web.bind.annotation.PathVariable;
  9 +import org.springframework.web.bind.annotation.RequestBody;
7 10 import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RequestMethod;
  12 +import org.springframework.web.bind.annotation.RequestParam;
8 13 import org.springframework.web.bind.annotation.RestController;
  14 +import org.springframework.web.multipart.MultipartFile;
9 15  
  16 +import com.diligrp.xtrade.product.common.utils.ImageUtil;
10 17 import com.diligrp.xtrade.product.domain.dto.CategoryDto;
11 18 import com.diligrp.xtrade.product.domain.entity.CategoryDo;
  19 +import com.diligrp.xtrade.product.exception.ExceptionEnum;
  20 +import com.diligrp.xtrade.product.exception.ProductException;
12 21 import com.diligrp.xtrade.product.service.CategoryService;
13 22 import com.diligrp.xtrade.shared.domain.Message;
14 23  
... ... @@ -21,7 +30,15 @@ import com.diligrp.xtrade.shared.domain.Message;
21 30 @RestController
22 31 @RequestMapping("sapi/category/")
23 32 public class CategoryController {
  33 +
  34 + @Value("${max.file.size}")
  35 + private int MAX_FILE_SIZE;
24 36  
  37 + private final Integer MAX_WIDTH = 300;
  38 + private final Integer MAX_HEIGHT = 300;
  39 + private final Integer MIN_WIDTH = 200;
  40 + private final Integer MIN_HEIGHT = 200;
  41 +
25 42 @Autowired
26 43 private CategoryService categoryService;
27 44  
... ... @@ -33,7 +50,14 @@ public class CategoryController {
33 50 * @return
34 51 * @throws
35 52 */
36   - public Message<?> save(CategoryDto categoryDTO) {
  53 + @RequestMapping("save")
  54 + public Message<?> save(@RequestBody CategoryDto categoryDTO,@RequestParam(value = "file",required = false) MultipartFile file) {
  55 + checkImageFile(file);
  56 + try {
  57 + categoryDTO.setImage(file.getBytes());
  58 + } catch (IOException e) {
  59 + throw new ProductException(ExceptionEnum.FILE_UP_ERROR);
  60 + }
37 61 categoryService.insert(categoryDTO);
38 62 return Message.success();
39 63 }
... ... @@ -93,4 +117,29 @@ public class CategoryController {
93 117 List<CategoryDo> categoryDos = categoryService.selectCateChild(cateCode);
94 118 return Message.success(categoryDos);
95 119 }
  120 +
  121 + /**
  122 + *
  123 + * @Title checkImageFile
  124 + * @Description 文件检查
  125 + * @param file
  126 + * @throws
  127 + */
  128 + private void checkImageFile(MultipartFile file) {
  129 + try {
  130 + if (!ImageUtil.isImage(file.getInputStream())) {
  131 + throw new ProductException(ExceptionEnum.NOT_IMAGE);
  132 + }
  133 + if (!ImageUtil.checkImageSize(file.getInputStream(), MAX_WIDTH, MAX_HEIGHT, MIN_WIDTH, MIN_HEIGHT)) {
  134 +
  135 + throw new ProductException(200005,"上传图片长宽超过限制,请保证图片大小范围为" + MIN_WIDTH + "*" + MIN_HEIGHT + "到" + MAX_WIDTH + "*"
  136 + + MAX_HEIGHT);
  137 + }
  138 + if (file.getBytes().length > MAX_FILE_SIZE) {
  139 + new ProductException(200005,"上传图片大小超过限制,请保证图片不超过256K");
  140 + }
  141 + } catch (IOException e) {
  142 + throw new ProductException(ExceptionEnum.FILE_UP_ERROR);
  143 + }
  144 + }
96 145 }
... ...
src/main/java/com/diligrp/xtrade/product/domain/dto/CategoryDto.java
... ... @@ -37,7 +37,7 @@ public class CategoryDto{
37 37 /**
38 38 * 图片
39 39 */
40   - private String image;
  40 + private byte[] image;
41 41 /**
42 42 * 品类有效期
43 43 */
... ... @@ -50,7 +50,10 @@ public class CategoryDto{
50 50 * 品类等级
51 51 */
52 52 private Integer level;
53   -
  53 + /**
  54 + * 市场id
  55 + */
  56 + private Integer marketId;
54 57 public String getParentId() {
55 58 return parentId;
56 59 }
... ... @@ -93,10 +96,11 @@ public class CategoryDto{
93 96 public void setIcon(String icon) {
94 97 this.icon = icon;
95 98 }
96   - public String getImage() {
  99 +
  100 + public byte[] getImage() {
97 101 return image;
98 102 }
99   - public void setImage(String image) {
  103 + public void setImage(byte[] image) {
100 104 this.image = image;
101 105 }
102 106 public Integer getValidDay() {
... ... @@ -117,5 +121,11 @@ public class CategoryDto{
117 121 public void setLevel(Integer level) {
118 122 this.level = level;
119 123 }
  124 + public Integer getMarketId() {
  125 + return marketId;
  126 + }
  127 + public void setMarketId(Integer marketId) {
  128 + this.marketId = marketId;
  129 + }
120 130  
121 131 }
... ...
src/main/java/com/diligrp/xtrade/product/domain/dto/CategoryQueryDto.java
... ... @@ -34,6 +34,10 @@ public class CategoryQueryDto{
34 34 * 品类等级
35 35 */
36 36 private Integer level;
  37 + /**
  38 + * 市场id
  39 + */
  40 + private Integer marketId;
37 41  
38 42 private Integer currentPage;
39 43  
... ... @@ -79,5 +83,11 @@ public class CategoryQueryDto{
79 83 public void setCurrentPage(Integer currentPage) {
80 84 this.currentPage = currentPage;
81 85 }
  86 + public Integer getMarketId() {
  87 + return marketId;
  88 + }
  89 + public void setMarketId(Integer marketId) {
  90 + this.marketId = marketId;
  91 + }
82 92  
83 93 }
... ...
src/main/java/com/diligrp/xtrade/product/domain/entity/CategoryDo.java
... ... @@ -36,7 +36,7 @@ public class CategoryDo extends BaseDo{
36 36 /**
37 37 * 图片
38 38 */
39   - private String image;
  39 + private byte[] image;
40 40 /**
41 41 * 品类有效期
42 42 */
... ... @@ -49,6 +49,10 @@ public class CategoryDo extends BaseDo{
49 49 * 品类等级
50 50 */
51 51 private Integer level;
  52 + /**
  53 + * 市场id
  54 + */
  55 + private Integer marketId;
52 56  
53 57 public String getCateCode() {
54 58 return cateCode;
... ... @@ -86,10 +90,11 @@ public class CategoryDo extends BaseDo{
86 90 public void setIcon(String icon) {
87 91 this.icon = icon;
88 92 }
89   - public String getImage() {
  93 +
  94 + public byte[] getImage() {
90 95 return image;
91 96 }
92   - public void setImage(String image) {
  97 + public void setImage(byte[] image) {
93 98 this.image = image;
94 99 }
95 100 public Integer getValidDay() {
... ... @@ -110,5 +115,11 @@ public class CategoryDo extends BaseDo{
110 115 public void setLevel(Integer level) {
111 116 this.level = level;
112 117 }
  118 + public Integer getMarketId() {
  119 + return marketId;
  120 + }
  121 + public void setMarketId(Integer marketId) {
  122 + this.marketId = marketId;
  123 + }
113 124  
114 125 }
... ...
src/main/java/com/diligrp/xtrade/product/exception/ExceptionEnum.java
... ... @@ -14,6 +14,9 @@ public enum ExceptionEnum implements IEnumType {
14 14 SHOP_NOT_EXISTENCE(200001, "SHOP_NOT_EXISTENCE"),
15 15 MERCHANT_ACCOUNT_EXIST(200002,"商户账号已存在"),
16 16 CARD_MERCHANT_CREATED(200003,"该卡已创建商户,请使用用户名密码登录"),
  17 + CATE_EXISTENCE(200004,"品类已存在"),
  18 + FILE_UP_ERROR(200005,"文件上传失败"),
  19 + NOT_IMAGE(200006,"只能上传图片")
17 20 ;
18 21  
19 22 private int code;
... ...
src/main/java/com/diligrp/xtrade/product/exception/ProductException.java
... ... @@ -8,4 +8,7 @@ public class ProductException extends BaseBusinessException {
8 8 public ProductException(IEnumType type) {
9 9 super(type);
10 10 }
  11 + public ProductException(int code, String message) {
  12 + super(code,message);
  13 + }
11 14 }
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/CategoryServiceImpl.java
... ... @@ -7,11 +7,14 @@ import org.springframework.beans.BeanUtils;
7 7 import org.springframework.beans.factory.annotation.Autowired;
8 8 import org.springframework.stereotype.Service;
9 9  
  10 +import com.diligrp.xtrade.product.common.utils.ImageUtil;
10 11 import com.diligrp.xtrade.product.dao.CategoryDao;
11 12 import com.diligrp.xtrade.product.domain.dto.CategoryDto;
12 13 import com.diligrp.xtrade.product.domain.dto.CategoryQueryDto;
13 14 import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;
14 15 import com.diligrp.xtrade.product.domain.entity.CategoryDo;
  16 +import com.diligrp.xtrade.product.exception.ExceptionEnum;
  17 +import com.diligrp.xtrade.product.exception.ProductException;
15 18 import com.diligrp.xtrade.product.service.CategoryService;
16 19 import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
17 20  
... ... @@ -29,9 +32,15 @@ public class CategoryServiceImpl implements CategoryService {
29 32 @Autowired
30 33 private CategoryDao categoryDao;
31 34  
  35 + private static String ICON_PREFIX = "/mobile/category/getImageByIcon/";
  36 +
32 37 @Override
33 38 public void insert(CategoryDto category) {
34 39 CategoryDo categoryDo = new CategoryDo();
  40 + // 查询品类名是否存在
  41 + if(categoryIsExit(category)) {
  42 + throw new ProductException(ExceptionEnum.CATE_EXISTENCE);
  43 + }
35 44 BeanUtils.copyProperties(category, categoryDo);
36 45 long id = keyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.CATEGORY_SEQUENCE).nextId();
37 46 String cateCode = ""+id;
... ... @@ -41,12 +50,17 @@ public class CategoryServiceImpl implements CategoryService {
41 50 cateCode = String.format("%s_%d", pCategoryDo.getCateCode(),id);
42 51 }
43 52 categoryDo.setCateCode(cateCode);
  53 + category.setIcon(ICON_PREFIX + ImageUtil.getMd5(categoryDo.getImage()) + id);
44 54 categoryDao.insert(categoryDo);
45 55 }
46 56  
47 57 @Override
48 58 public void update(CategoryDto category) {
49 59 CategoryDo categoryDo = new CategoryDo();
  60 + // 查询品类名是否存在
  61 + if(categoryIsExit(category)) {
  62 + throw new ProductException(ExceptionEnum.CATE_EXISTENCE);
  63 + }
50 64 BeanUtils.copyProperties(category, categoryDo);
51 65 categoryDao.update(categoryDo);
52 66 }
... ... @@ -70,5 +84,24 @@ public class CategoryServiceImpl implements CategoryService {
70 84 public List<CategoryDo> selectCateChild(String cateCode) {
71 85 return categoryDao.selectCateChild(cateCode);
72 86 }
73   -
  87 +
  88 + /**
  89 + * 根据品类名称,等级,市场查询品类名是否重复
  90 + * @Title categoryIsExit
  91 + * @Description 根据品类名称,等级,市场查询品类名是否重复
  92 + * @param category
  93 + * @return true/false
  94 + * @throws
  95 + */
  96 + private boolean categoryIsExit(CategoryDto category) {
  97 + CategoryQueryDto categoryQueryDto = new CategoryQueryDto();
  98 + categoryQueryDto.setCname(category.getCname());
  99 + categoryQueryDto.setLevel(category.getLevel());
  100 + categoryQueryDto.setMarketId(category.getMarketId());
  101 + List<CategoryDo> categorys = categoryDao.selectList(categoryQueryDto);
  102 + if(categorys != null && categorys.size() > 0) {
  103 + return true;
  104 + }
  105 + return false;
  106 + }
74 107 }
... ...