Commit 1f52991a4507cc7c89b6b57de08cb66afc13e183

Authored by yangfan
1 parent 121c6583

shop

src/main/java/com/diligrp/xtrade/product/controllor/ShopController.java
... ... @@ -81,6 +81,7 @@ public class ShopController {
81 81 */
82 82 @RequestMapping("selectShop")
83 83 public Message<?> selectShop(@Validated @RequestBody ShopQueryDto shop){
84   - return null;
  84 + List<ShopDo> shops = shopService.selectShop(shop);
  85 + return Message.success(shops);
85 86 }
86 87 }
... ...
src/main/java/com/diligrp/xtrade/product/domain/dto/ShopDto.java
1 1 package com.diligrp.xtrade.product.domain.dto;
2 2  
  3 +import javax.validation.constraints.Max;
3 4 import javax.validation.constraints.NotBlank;
  5 +import javax.validation.constraints.Pattern;
  6 +
  7 +import org.hibernate.validator.constraints.Length;
4 8  
5 9 /**
6 10 * @ClassName: ShopDTO
... ... @@ -29,21 +33,26 @@ public class ShopDto {
29 33 /**
30 34 * 店铺类型
31 35 */
  36 + @Pattern(regexp = "^(20|10)$",message = "店铺类型错误")
32 37 private Integer type;
33 38  
34 39 /**
35 40 * 店铺状态
36 41 */
  42 + @Pattern(regexp = "^(1|2)$")
37 43 private Integer status;
38 44  
39 45 /**
40 46 * 是否自营
41 47 */
  48 + @Pattern(regexp = "^(1|2)$")
42 49 private Integer selfShop;
43 50  
44 51 /**
45 52 * 主营业务
46 53 */
  54 + @NotBlank(message = "业务描述不能为空")
  55 + @Length(max = 200,message = "业务描述不超过200字")
47 56 private String mainBiz;
48 57  
49 58 /**
... ... @@ -54,6 +63,8 @@ public class ShopDto {
54 63 /**
55 64 * 描述
56 65 */
  66 + @NotBlank(message = "店铺描述不能为空")
  67 + @Length(max = 200,message = "店铺描述不超过200字")
57 68 private String description;
58 69  
59 70 public Long getMerId() {
... ...
src/main/java/com/diligrp/xtrade/product/domain/emuns/ExceptionEnum.java 0 → 100644
  1 +package com.diligrp.xtrade.product.domain.emuns;
  2 +
  3 +import java.util.Arrays;
  4 +
  5 +import com.diligrp.xtrade.shared.type.IEnumType;
  6 +
  7 +/**
  8 + * @ClassName: ExceptionEnum
  9 + * @Description TODO(用一句话描述该文件做什么)
  10 + * @author yangfan
  11 + * @date 2020年4月22日
  12 + */
  13 +public enum ExceptionEnum implements IEnumType {
  14 + SHOP_NOT_EXISTENCE(20001, "SHOP_NOT_EXISTENCE");
  15 +
  16 + private int code;
  17 + private String name;
  18 +
  19 + ExceptionEnum(int code, String name) {
  20 + this.code = code;
  21 + this.name = name;
  22 + }
  23 +
  24 + public static ExceptionEnum getByType(int code) {
  25 + return Arrays.stream(values())
  26 + .filter(exceptionEnum -> exceptionEnum.getCode() == code)
  27 + .findFirst()
  28 + .orElse(null);
  29 + }
  30 +
  31 + public static String getName(int index) {
  32 + return Arrays.stream(ExceptionEnum.values())
  33 + .filter(c -> c.getCode() == index)
  34 + .findFirst().map(c -> c.name)
  35 + .orElse(null);
  36 + }
  37 +
  38 +
  39 + public int getCode() {
  40 + // TODO Auto-generated method stub
  41 + return 0;
  42 + }
  43 +
  44 + @Override
  45 + public String getName() {
  46 + // TODO Auto-generated method stub
  47 + return null;
  48 + }
  49 +
  50 +}
... ...
src/main/java/com/diligrp/xtrade/product/domain/emuns/ShopStatus.java
1 1 package com.diligrp.xtrade.product.domain.emuns;
2 2  
  3 +
3 4 public enum ShopStatus {
  5 + OPEN(1, "开店"), OFF(2, "关店");
  6 +
  7 + private Integer code;
  8 + private String name;
  9 +
  10 + private ShopStatus(Integer code, String name) {
  11 + this.code = code;
  12 + this.name = name;
  13 + }
  14 +
  15 + public int getCode() {
  16 + return code;
  17 + }
  18 +
  19 + public String getName() {
  20 + return name;
  21 + }
  22 +
  23 + public static ShopStatus getByCode(int code) {
  24 + for (ShopStatus shopStatus : values()) {
  25 + if (shopStatus.getCode() == code) {
  26 + return shopStatus;
  27 + }
  28 + }
  29 + return null;
  30 + }
  31 +
  32 + public static String getNameByCode(int code) {
  33 + for (ShopStatus shopStatus : ShopStatus.values()) {
  34 + if (shopStatus.getCode() == code) {
  35 + return shopStatus.name;
  36 + }
  37 + }
  38 + return null;
  39 + }
4 40  
5 41 }
... ...
src/main/java/com/diligrp/xtrade/product/service/impl/ShopServiceImpl.java
... ... @@ -9,8 +9,12 @@ import org.springframework.stereotype.Service;
9 9 import com.diligrp.xtrade.product.dao.ShopDao;
10 10 import com.diligrp.xtrade.product.domain.dto.ShopDto;
11 11 import com.diligrp.xtrade.product.domain.dto.ShopQueryDto;
  12 +import com.diligrp.xtrade.product.domain.emuns.ExceptionEnum;
12 13 import com.diligrp.xtrade.product.domain.emuns.IKeyGeneratorKeys;
  14 +import com.diligrp.xtrade.product.domain.emuns.ShopEnums;
  15 +import com.diligrp.xtrade.product.domain.emuns.ShopStatus;
13 16 import com.diligrp.xtrade.product.domain.entity.ShopDo;
  17 +import com.diligrp.xtrade.product.exception.ProductException;
14 18 import com.diligrp.xtrade.product.service.ShopService;
15 19 import com.diligrp.xtrade.shared.sequence.KeyGeneratorManager;
16 20  
... ... @@ -25,15 +29,25 @@ public class ShopServiceImpl implements ShopService {
25 29 @Override
26 30 public void insert(ShopDto shop) {
27 31 ShopDo shopDo = new ShopDo();
  32 + Long merId = shop.getMerId();
  33 + //TODO 查询商户合法性
  34 + if(false) {
  35 + // throw new ProductException(type);
  36 + }
28 37 Long shopId = KeyGeneratorManager.getKeyGenerator(IKeyGeneratorKeys.SHOP_SEQUENCE).nextId();
29 38 BeanUtils.copyProperties(shop, shopDo);
  39 + shopDo.setStatus(ShopStatus.OPEN.getCode());
30 40 shopDo.setShopId(shopId);
31 41 shopDao.insert(shopDo);
32 42 }
  43 +
33 44  
34 45 @Override
35 46 public void update(ShopDto shop) {
36   - ShopDo shopDo = new ShopDo();
  47 + ShopDo shopDo = shopDao.selectByShopId(shop.getShopId());
  48 + if(shopDo == null) {
  49 + throw new ProductException(ExceptionEnum.SHOP_NOT_EXISTENCE);
  50 + }
37 51 BeanUtils.copyProperties(shop, shopDo);
38 52 shopDao.update(shopDo);
39 53 }
... ...