Browse Source

管乐迷商城调整

zouxuan 1 year ago
parent
commit
38db8bd38d

+ 16 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ComplementGoodsDto.java

@@ -0,0 +1,16 @@
+package com.ym.mec.biz.dal.dto;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class ComplementGoodsDto {
+        private Integer skuStockId;
+
+        private Integer goodsId;
+
+        private BigDecimal organCostPrice;
+
+        private String skuCode;
+}

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/Goods.java

@@ -114,6 +114,10 @@ public class Goods {
 	@ApiModelProperty(value = "附件商品列表编号(用逗号分开)",required = false)
 	private String complementGoodsIdList;
 
+	/** 发布时间 */
+	@ApiModelProperty(value = "附件商品详情",required = false)
+	private String complementGoodsJson;
+
 	/** 辅件列表 */
 	@ApiModelProperty(value = "辅件列表(子商品)",required = false)
 	private List<Goods> goodsList;

+ 28 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.BasicUserDto;
+import com.ym.mec.biz.dal.dto.ComplementGoodsDto;
 import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.GoodsProcurement;
@@ -14,11 +15,14 @@ import com.ym.mec.biz.dal.page.GoodsQuery;
 import com.ym.mec.biz.dal.page.GoodsQueryInfo;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
 import com.ym.mec.common.entity.UploadReturnBean;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
+import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.excel.POIUtil;
@@ -36,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.math.BigDecimal;
@@ -65,6 +70,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	private SellOrderDao sellOrderDao;
 	@Autowired
 	private OrganizationDao organizationDao;
+	@Resource
+	private MallFeignService mallFeignService;
 
 	@Override
 	public BaseDAO<Integer, Goods> getDAO() {
@@ -154,24 +161,35 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	}
 
 	@Override
-	@Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
+	@Transactional(rollbackFor = Exception.class)
 	public void addGoods(Goods goods, Integer operatorId) {
 		if(StringUtils.isBlank(goods.getSn())){
 			throw new BizException("请指定商品货号");
 		}
+		if(StringUtils.isEmpty(goods.getComplementGoodsJson())){
+			throw new BizException("请指定子商品");
+		}
 		Goods existsGood = goodsDao.lockBySn(goods.getSn());
 		if(Objects.nonNull(existsGood)){
 			throw new BizException("商品货号重复");
-		}else{
-			if(Objects.isNull(goods.getStockCount())){
-				goods.setStockCount(0);
-			}
-			if(Objects.isNull(goods.getTaxStockCount())){
-				goods.setTaxStockCount(0);
-			}
-			goods.setSellCount(0);
-			goodsDao.insert(goods);
 		}
+		List<ComplementGoodsDto> complementGoods = JSON.parseArray(goods.getComplementGoodsJson(), ComplementGoodsDto.class);
+		//获取最小的库存数
+		String skuIds = complementGoods.stream().map(e -> e.getSkuStockId().toString()).collect(Collectors.joining(","));
+		PmsProductQueryParamDto paramDto = new PmsProductQueryParamDto();
+		paramDto.setSkuStockIds(skuIds);
+		paramDto.setPublishStatus(1);
+		paramDto.setPageSize(1000);
+		paramDto.setPageNum(1);
+		List<PmsProductDto> productList = mallFeignService.getProductList(paramDto).getRows();
+		if(CollectionUtils.isEmpty(productList)){
+			throw new BizException("子商品不存在");
+		}
+		//获取最小库存数量
+		Integer stock = productList.stream().map(PmsProductDto::getStock).min(Integer::compareTo).get();
+		goods.setStockCount(stock);
+		goods.setSellCount(0);
+		goodsDao.insert(goods);
 	}
 
 	@Override

+ 20 - 0
mec-client-api/src/main/java/com/ym/mec/mall/MallFeignService.java

@@ -0,0 +1,20 @@
+package com.ym.mec.mall;
+
+import com.ym.mec.common.config.FeignConfiguration;
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
+import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.mall.fallback.MallFeignServiceFallback;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@FeignClient(name = "${app-config.open-feign.mall-server.name:mall-server}",
+		contextId = "MallFeignService",
+		url = "${app-config.open-feign.mall-server.url:}",
+		configuration = FeignConfiguration.class, fallback = MallFeignServiceFallback.class)
+public interface MallFeignService {
+
+	@RequestMapping(value = "open/product/list")
+	PageInfo<PmsProductDto> getProductList(PmsProductQueryParamDto productQueryParam);
+
+}

+ 20 - 0
mec-client-api/src/main/java/com/ym/mec/mall/fallback/MallFeignServiceFallback.java

@@ -0,0 +1,20 @@
+package com.ym.mec.mall.fallback;
+
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
+import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.mall.MallFeignService;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class MallFeignServiceFallback implements MallFeignService {
+
+
+    @Override
+    public PageInfo<PmsProductDto> getProductList(PmsProductQueryParamDto productQueryParam) {
+        return null;
+    }
+
+}

+ 38 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/dto/PmsProductDto.java

@@ -0,0 +1,38 @@
+package com.ym.mec.common.dto;
+
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+public class PmsProductDto implements Serializable {
+    //skuStockId
+    private Integer skuStockId;
+
+    private Long goodsId;
+
+    private String skuCode;
+
+    private String name;
+    //货号
+    private String productSn;
+
+    //删除状态:0->未删除;1->已删除
+    private Integer deleteStatus;
+
+    //上架状态:0->下架;1->上架
+    private Integer publishStatus;
+
+    private BigDecimal price;
+
+    //库存
+    private Integer stock;
+
+    //品牌名称
+    private String brandName;
+
+    //商品分类名称
+    private String productCategoryName;
+}

+ 28 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/dto/PmsProductQueryParamDto.java

@@ -0,0 +1,28 @@
+package com.ym.mec.common.dto;
+
+
+import lombok.Data;
+
+
+@Data
+public class PmsProductQueryParamDto {
+    //skuId多个逗号隔开
+    private String skuStockIds;
+    //上架状态
+    private Integer publishStatus;
+    //商品名称模糊关键字
+    private String keyword;
+    //商品货号
+    private String productSn;
+    //商品编号,多个逗号隔开
+    private String productIds;
+    //需要排除的商品编号
+    private String excludeProductIds;
+    //商品分类
+    private Long productCategoryId;
+    //商品品牌
+    private Long brandId;
+
+    private Integer pageSize;
+    private Integer pageNum;
+}

+ 4 - 0
mec-mall/mall-admin/pom.xml

@@ -49,6 +49,10 @@
             <artifactId>easyexcel</artifactId>
             <version>3.2.1</version>
         </dependency>
+        <dependency>
+            <groupId>com.ym</groupId>
+            <artifactId>mec-client-api</artifactId>
+        </dependency>
 
 
     </dependencies>