Prechádzať zdrojové kódy

feat: 商品进销存

Joburgess 5 rokov pred
rodič
commit
67bcdcd35b

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsProcurementDao.java

@@ -32,4 +32,15 @@ public interface GoodsProcurementDao extends BaseDAO<Long, GoodsProcurement> {
      */
     GoodsProcurement getWithTaxStockSurplusProcurement(@Param("goodsId") Integer goodsId);
 
+    /**
+     * @describe 根据商品编号与批次号获取进货清单
+     * @author Joburgess
+     * @date 2020.10.12
+     * @param goodsId:
+     * @param batchNo:
+     * @return com.ym.mec.biz.dal.entity.GoodsProcurement
+     */
+    GoodsProcurement getWithGoodsAndBatchNo(@Param("goodsId") Integer goodsId,
+                                            @Param("batchNo") String batchNo);
+
 }

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/GoodsBatchNoDto.java

@@ -10,6 +10,14 @@ public class GoodsBatchNoDto {
 
     private String batchNo;
 
+    public GoodsBatchNoDto() {
+    }
+
+    public GoodsBatchNoDto(Integer goodsId, String batchNo) {
+        this.goodsId = goodsId;
+        this.batchNo = batchNo;
+    }
+
     public Integer getGoodsId() {
         return goodsId;
     }

+ 11 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.service;
 
+import com.ym.mec.biz.dal.dto.GoodsBatchNoDto;
 import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.enums.AccountType;
@@ -38,7 +39,6 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      */
     List<Goods> findGoodsByIds(String ids);
 
-
     /**
      * 查询某种类型的商品
      * @param type
@@ -75,5 +75,14 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * @param accountType: 收款账户类型
      * @return java.lang.String
      */
-    List<Goods> subtractStock(List<Integer> goodsIds, AccountType accountType);
+    List<GoodsBatchNoDto> subtractStock(List<Integer> goodsIds, AccountType accountType);
+
+    /**
+     * @describe 增加商品库存
+     * @author Joburgess
+     * @date 2020.10.12
+     * @param goodsBatchNoDtos:
+     * @return void
+     */
+    void increaseStock(List<GoodsBatchNoDto> goodsBatchNoDtos, AccountType accountType);
 }

+ 49 - 11
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -9,6 +9,7 @@ import com.ym.mec.biz.dal.dao.GoodsProcurementDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dao.TeacherDao;
 import com.ym.mec.biz.dal.dto.BasicUserDto;
+import com.ym.mec.biz.dal.dto.GoodsBatchNoDto;
 import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.GoodsProcurement;
@@ -77,7 +78,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 			existsGood.setTaxStockCount(existsGood.getTaxStockCount()+existsGood.getTaxStockCount());
 			goodsDao.update(existsGood);
 		}else{
-			goodsDao.insert(existsGood);
+			goodsDao.insert(goods);
+			existsGood=goods;
 		}
 
 		String batchNo = idGeneratorService.generatorId("payment") + "";
@@ -269,7 +271,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 
 	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-	public List<Goods> subtractStock(List<Integer> goodsIds, AccountType accountType) {
+	public List<GoodsBatchNoDto> subtractStock(List<Integer> goodsIds, AccountType accountType) {
 		if(CollectionUtils.isEmpty(goodsIds)){
 			return Collections.emptyList();
 		}
@@ -277,7 +279,6 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		Map<Integer, Long> goodsSellNumMap = goodsIds.stream().collect(Collectors.groupingBy(s -> s, Collectors.counting()));
 
 		List<Goods> tempGoodsList = goodsDao.lockGoods(new ArrayList<>(goodsIds));
-		Map<Integer, Integer> singleGoodsSellNumMap = new HashMap<>();
 		Map<Integer, Goods> idTempGoodsMap = tempGoodsList.stream().collect(Collectors.toMap(Goods::getId, g -> g));
 		List<Integer> singleGoodsIds = new ArrayList<>();
 		for (Integer goodsId : goodsIds) {
@@ -288,30 +289,67 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 				List<Integer> complementGoodsIds = Arrays.stream(tempGoods.getComplementGoodsIdList().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
 				singleGoodsIds.addAll(complementGoodsIds);
 			}
+			tempGoods.setSellCount((int) (tempGoods.getSellCount() + goodsSellNumMap.get(tempGoods.getId())));
+//			goodsDao.update(tempGoods);
 		}
+		goodsDao.batchUpdate(tempGoodsList);
 		List<Goods> singleGoodsList = goodsDao.getGoodies(singleGoodsIds);
 		Map<Integer, Goods> idSingleGoodsMap = singleGoodsList.stream().collect(Collectors.toMap(Goods::getId, g -> g));
+		List<GoodsBatchNoDto> goodsBatchNoDtos = new ArrayList<>();
 		for (Integer singleGoodsId : singleGoodsIds) {
 			Goods goods = idSingleGoodsMap.get(singleGoodsId);
 			GoodsProcurement goodsProcurement = null;
 			if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(accountType))){
 				goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
 				goods.setStockCount(new AtomicInteger(goods.getStockCount()).decrementAndGet());
-				goodsProcurement.setStockCount(new AtomicInteger(goodsProcurement.getStockCount()).decrementAndGet());
-				goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
+				if(Objects.nonNull(goodsProcurement)){
+					goodsProcurement.setStockCount(new AtomicInteger(goodsProcurement.getStockCount()).decrementAndGet());
+					goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
+				}
 			}else if(StockType.EXTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.EXTERNAL.equals(accountType))){
 				goodsProcurement = goodsProcurementDao.getWithTaxStockSurplusProcurement(goods.getId());
 				goods.setTaxStockCount(new AtomicInteger(goods.getTaxStockCount()).decrementAndGet());
-				goodsProcurement.setTaxStockCount(new AtomicInteger(goodsProcurement.getTaxStockCount()).decrementAndGet());
-				goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
+				if(Objects.nonNull(goodsProcurement)){
+					goodsProcurement.setTaxStockCount(new AtomicInteger(goodsProcurement.getTaxStockCount()).decrementAndGet());
+					goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
+				}
+			}
+
+			goodsDao.update(goods);
+			if(Objects.nonNull(goodsProcurement)){
+				goodsBatchNoDtos.add(new GoodsBatchNoDto(goods.getId(), goodsProcurement.getBatchNo()));
+				goodsProcurementDao.update(goodsProcurement);
+			}else{
+				goodsBatchNoDtos.add(new GoodsBatchNoDto(goods.getId(), goodsProcurement.getBatchNo()));
 			}
-			if(Objects.isNull(goodsProcurement)){
-				throw new BizException("商品类型不明");
+		}
+
+		return goodsBatchNoDtos;
+	}
+
+	@Override
+	public void increaseStock(List<GoodsBatchNoDto> goodsBatchNoDtos, AccountType accountType) {
+		Set<Integer> goodsIds = goodsBatchNoDtos.stream().map(GoodsBatchNoDto::getGoodsId).collect(Collectors.toSet());
+		List<Goods> goodsList = goodsDao.getGoodies(new ArrayList<>(goodsIds));
+		Map<Integer, Goods> idGoodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getId, g -> g));
+		for (GoodsBatchNoDto goodsBatchNoDto : goodsBatchNoDtos) {
+			Goods goods = idGoodsMap.get(goodsBatchNoDto.getGoodsId());
+			GoodsProcurement goodsProcurement = goodsProcurementDao.getWithGoodsAndBatchNo(goods.getId(), goodsBatchNoDto.getBatchNo());
+			if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(accountType))){
+				goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+				if(Objects.nonNull(goodsProcurement)){
+					goodsProcurement.setStockCount(new AtomicInteger(goodsProcurement.getStockCount()).incrementAndGet());
+					goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
+				}
+			}else if(StockType.EXTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.EXTERNAL.equals(accountType))){
+				goods.setTaxStockCount(new AtomicInteger(goods.getTaxStockCount()).incrementAndGet());
+				if(Objects.nonNull(goodsProcurement)){
+					goodsProcurement.setTaxStockCount(new AtomicInteger(goodsProcurement.getTaxStockCount()).incrementAndGet());
+					goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).decrementAndGet());
+				}
 			}
 			goodsDao.update(goods);
 			goodsProcurementDao.update(goodsProcurement);
 		}
-
-		return null;
 	}
 }

+ 6 - 6
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -52,23 +52,23 @@
         INSERT INTO goods
         (goods_category_id_,sn_,name_,brand_,specification_,image_,stock_count_,tax_stock_count_,sell_count_,market_price_,
         discount_price_,group_purchase_price_,brief_,desc_,is_new_,is_top_,status_,memo_,publish_time_,
-        complement_goods_id_list_,update_time_,create_time_,type_,agree_cost_price_,supply_channel_)
+        complement_goods_id_list_,update_time_,create_time_,type_,agree_cost_price_)
         VALUES(#{goodsCategoryId},#{sn},#{name},#{brand},#{specification},#{image},#{stockCount},#{taxStockCount},#{sellCount},#{marketPrice},
         #{discountPrice},#{groupPurchasePrice},#{brief},#{desc},
         #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-        #{memo},#{publishTime},#{complementGoodsIdList},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{agreeCostPrice},#{supplyChannel})
+        #{memo},#{publishTime},#{complementGoodsIdList},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{agreeCostPrice})
     </insert>
     <insert id="batchInsert">
         INSERT INTO goods
         (goods_category_id_,name_,brand_,specification_,image_,market_price_,
         discount_price_,group_purchase_price_,desc_,update_time_,create_time_,type_,agree_cost_price_,sn_,
-        stock_count_,tax_stock_count_,supply_channel_)
+        stock_count_,tax_stock_count_)
         VALUES
         <foreach collection="goodsList" separator="," item="goods">
             (#{goods.goodsCategoryId},#{goods.name},#{goods.brand},#{goods.specification},#{goods.image},#{goods.marketPrice},
             #{goods.discountPrice},#{goods.groupPurchasePrice},#{goods.desc},now(),now(),
             #{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goods.agreeCostPrice},#{goods.sn},
-            #{goods.stockCount},#{goods.taxStockCount},#{goods.supplyChannel})
+            #{goods.stockCount},#{goods.taxStockCount},)
         </foreach>
     </insert>
     <!-- 根据主键查询一条记录 -->
@@ -234,7 +234,7 @@
         SELECT g.*,gc.name_ goods_category_name_ FROM goods g
         LEFT JOIN goods_category gc ON g.goods_category_id_ = gc.id_
         <include refid="queryGoodsPageSql"/>
-        ORDER BY g.id_
+        ORDER BY g.id_ DESC
         <include refid="global.limit"/>
     </select>
     <!-- 查询当前表的总记录数 -->
@@ -267,7 +267,7 @@
                 AND g.complement_goods_id_list_ IS NOT NULL
             </if>
             <if test="search!=null and search!=''">
-                AND (g.sn_=#{search} OR g.name_ LIKE CONCAT('%', #{search}, '%') OR gp.supply_channel_ LIKE CONCAT('%', #{search}, '%'))
+                AND (g.sn_=#{search} OR g.id_=#{search} OR g.name_ LIKE CONCAT('%', #{search}, '%'))
             </if>
         </where>
     </sql>

+ 4 - 0
mec-biz/src/main/resources/config/mybatis/GoodsProcurementMapper.xml

@@ -140,4 +140,8 @@
 	<select id="getWithTaxStockSurplusProcurement" resultMap="GoodsProcurement">
 		SELECT * FROM goods_procurement WHERE goods_id_ = #{goodsId} AND tax_stock_count_>tax_stock_sold_num_
 	</select>
+
+	<select id="getWithGoodsAndBatchNo" resultMap="GoodsProcurement">
+		SELECT * FROM goods_procurement WHERE goods_id_ = #{goodsId} AND batch_no_=#{batchNo}
+	</select>
 </mapper>