Browse Source

feat: 商品进销存调整

Joburgess 5 years ago
parent
commit
c5ad11bc6c

+ 19 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsDao.java

@@ -47,9 +47,27 @@ public interface GoodsDao extends BaseDAO<Integer, Goods> {
     void batchInsert(@Param("goodsList") List<Goods> goodsList);
 
     /**
+     * @describe 批量更新商品
+     * @author Joburgess
+     * @date 2020.09.28
+     * @param goodsList:
+     * @return void
+     */
+    void batchUpdate(@Param("goodsList") List<Goods> goodsList);
+
+    /**
      * 获取商品列表
      * @param goodsIds
      * @return
      */
     List<Goods> getGoodies(@Param("goodsIds") List<Integer> goodsIds);
-}
+
+    /**
+     * @describe 根据货号查找商品
+     * @author Joburgess
+     * @date 2020.09.28
+     * @param sns:
+     * @return java.util.List<com.ym.mec.biz.dal.entity.Goods>
+     */
+    List<Goods> findBySns(@Param("sns") List<String> sns);
+}

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

@@ -51,6 +51,9 @@ public class Goods {
 	@ApiModelProperty(value = "库存数量",required = false)
 	private Integer stockCount;
 
+	@ApiModelProperty(value = "税务库存")
+	private Integer taxStockCount;
+
 	/** 总销量数 */
 	@ApiModelProperty(value = "总销量数",required = false)
 	private Integer sellCount;
@@ -118,6 +121,8 @@ public class Goods {
 	@ApiModelProperty(value = "商品类型", required = false)
 	private GoodsType type;
 
+	private String supplyChannel;
+
 	public BigDecimal getAgreeCostPrice() {
 		return agreeCostPrice;
 	}
@@ -334,6 +339,22 @@ public class Goods {
 		this.goodsList = goodsList;
 	}
 
+	public Integer getTaxStockCount() {
+		return taxStockCount;
+	}
+
+	public void setTaxStockCount(Integer taxStockCount) {
+		this.taxStockCount = taxStockCount;
+	}
+
+	public String getSupplyChannel() {
+		return supplyChannel;
+	}
+
+	public void setSupplyChannel(String supplyChannel) {
+		this.supplyChannel = supplyChannel;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 31 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -20,7 +20,9 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.ByteArrayInputStream;
@@ -28,6 +30,8 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 @Service
 public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implements GoodsService {
@@ -63,7 +67,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	}
 
 	@Override
-	@Transactional(rollbackFor = Exception.class)
+	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 	public List<Goods> importGoods(MultipartFile file) throws Exception {
 		Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
 		InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
@@ -83,7 +87,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 						continue;
 					}
 					String columnValue = columns.get(s);
-					if(null == row.get(s) || StringUtils.isEmpty(row.get(s).toString())){
+					if(null == row.get(s) || StringUtils.isBlank(row.get(s).toString())){
 						LOGGER.error("商品导入异常:参数{}不可为空 param:{}",columnValue,objectMap);
 						continue valueIsNull;
 					}
@@ -131,9 +135,31 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 				}
 			}
 		}
-		if(goodsList.size() != 0){
-			goodsDao.batchInsert(goodsList);
+		if(CollectionUtils.isEmpty(goodsList)){
+			return goodsList;
 		}
+
+		List<String> goodsSnList = goodsList.stream().map(Goods::getSn).collect(Collectors.toList());
+		List<Goods> existsGoods = goodsDao.findBySns(goodsSnList);
+		List<String> existsSns = existsGoods.stream().map(Goods::getSn).collect(Collectors.toList());
+
+		Map<String, List<Goods>> snGoodsMap = goodsList.stream().collect(Collectors.groupingBy(Goods::getSn));
+		for (Goods existsGood : existsGoods) {
+			List<Goods> goods = snGoodsMap.get(existsGood.getSn());
+			int stockCount = goods.stream().mapToInt(Goods::getStockCount).sum();
+			int taxStockCount = goods.stream().mapToInt(Goods::getTaxStockCount).sum();
+			existsGood.setStockCount((Objects.isNull(existsGood.getStockCount())?0:existsGood.getStockCount()) + stockCount);
+			existsGood.setTaxStockCount((Objects.isNull(existsGood.getTaxStockCount())?0:existsGood.getTaxStockCount()) + taxStockCount);
+		}
+
+		if(!CollectionUtils.isEmpty(existsGoods)){
+			goodsDao.batchUpdate(existsGoods);
+		}
+		List<Goods> newGoods = goodsList.stream().filter(g -> !existsSns.contains(g.getSn())).collect(Collectors.toList());
+		if(!CollectionUtils.isEmpty(newGoods)){
+			goodsDao.batchInsert(newGoods);
+		}
+
 		return goodsList;
 	}
-}
+}

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

@@ -16,6 +16,7 @@
         <result column="specification_" property="specification"/>
         <result column="image_" property="image"/>
         <result column="stock_count_" property="stockCount"/>
+        <result column="tax_stock_count_" property="taxStockCount"/>
         <result column="sell_count_" property="sellCount"/>
         <result column="market_price_" property="marketPrice"/>
         <result column="discount_price_" property="discountPrice"/>
@@ -32,6 +33,7 @@
         <result column="update_time_" property="updateTime"/>
         <result column="complement_goods_id_list_" property="complementGoodsIdList"/>
         <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+        <result column="supply_channel_" property="supplyChannel" />
     </resultMap>
 
     <!-- 根据主键查询一条记录 -->
@@ -48,23 +50,25 @@
     <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Goods" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
         INSERT INTO goods
-        (goods_category_id_,sn_,name_,brand_,specification_,image_,stock_count_,sell_count_,market_price_,
+        (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_)
-        VALUES(#{goodsCategoryId},#{sn},#{name},#{brand},#{specification},#{image},#{stockCount},#{sellCount},#{marketPrice},
+        complement_goods_id_list_,update_time_,create_time_,type_,agree_cost_price_,supply_channel_)
+        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})
+        #{memo},#{publishTime},#{complementGoodsIdList},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{agreeCostPrice},#{supplyChannel})
     </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_)
+        discount_price_,group_purchase_price_,desc_,update_time_,create_time_,type_,agree_cost_price_,sn_,
+        stock_count_,tax_stock_count_,supply_channel_)
         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.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goods.agreeCostPrice},#{goods.sn},
+            #{goods.stockCount},#{goods.taxStockCount},#{goods.supplyChannel})
         </foreach>
     </insert>
     <!-- 根据主键查询一条记录 -->
@@ -137,10 +141,95 @@
             <if test="complementGoodsIdList != null">
                 complement_goods_id_list_ = #{complementGoodsIdList},
             </if>
+            <if test="taxStockCount != null">
+                tax_stock_count_ = #{taxStockCount},
+            </if>
+            <if test="supplyChannel != null">
+                supply_channel_ = #{supplyChannel},
+            </if>
         </set>
         WHERE id_ = #{id}
     </update>
 
+    <update id="batchUpdate" parameterType="com.ym.mec.biz.dal.entity.Goods">
+        <foreach collection="goodsList" item="goods" separator=";">
+            UPDATE goods
+            <set>
+                <if test="goods.agreeCostPrice != null">
+                    agree_cost_price_ = #{goods.agreeCostPrice},
+                </if>
+                <if test="goods.specification != null">
+                    specification_ = #{goods.specification},
+                </if>
+                <if test="goods.status != null">
+                    status_ = #{goods.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+                </if>
+                <if test="goods.isTop != null">
+                    is_top_ = #{goods.isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+                </if>
+                <if test="goods.type != null">
+                    type_ = #{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+                </if>
+                <if test="goods.sn != null">
+                    sn_ = #{goods.sn},
+                </if>
+                <if test="goods.marketPrice != null">
+                    market_price_ = #{goods.marketPrice},
+                </if>
+                <if test="goods.memo != null">
+                    memo_ = #{goods.memo},
+                </if>
+                <if test="goods.isNew != null">
+                    is_new_ = #{goods.isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+                </if>
+                <if test="goods.groupPurchasePrice != null">
+                    group_purchase_price_ = #{goods.groupPurchasePrice},
+                </if>
+                <if test="goods.name != null">
+                    name_ = #{goods.name},
+                </if>
+                <if test="goods.stockCount != null">
+                    stock_count_ = #{goods.stockCount},
+                </if>
+                <if test="goods.goodsCategoryId != null">
+                    goods_category_id_ = #{goods.goodsCategoryId},
+                </if>
+                <if test="goods.brand != null">
+                    brand_ = #{goods.brand},
+                </if>
+                <if test="goods.brief != null">
+                    brief_ = #{goods.brief},
+                </if>
+                <if test="goods.discountPrice != null">
+                    discount_price_ = #{goods.discountPrice},
+                </if>
+                <if test="goods.sellCount != null">
+                    sell_count_ = #{goods.sellCount},
+                </if>
+                <if test="goods.image != null">
+                    image_ = #{goods.image},
+                </if>
+                <if test="goods.desc != null">
+                    desc_ = #{goods.desc},
+                </if>
+                <if test="goods.publishTime != null">
+                    publish_time_ = #{goods.publishTime},
+                </if>
+                <if test="goods.complementGoodsIdList != null">
+                    complement_goods_id_list_ = #{goods.complementGoodsIdList},
+                </if>
+                <if test="goods.taxStockCount != null">
+                    tax_stock_count_ = #{goods.taxStockCount},
+                </if>
+                <if test="goods.supplyChannel != null">
+                    supply_channel_ = #{goods.supplyChannel},
+                </if>
+                    update_time_ = NOW()
+            </set>
+            WHERE id_ = #{goods.id}
+        </foreach>
+    </update>
+
     <!-- 根据主键删除一条记录 -->
     <delete id="delete">
 		DELETE FROM goods WHERE id_ = #{id} 
@@ -202,4 +291,11 @@
             #{goodsId}
         </foreach>
     </select>
+
+    <select id="findBySns" resultMap="Goods">
+        SELECT * FROM goods WHERE sn_ IN
+        <foreach collection="sns" item="sn" separator="," open="(" close=")">
+            #{sn}
+        </foreach>
+    </select>
 </mapper>

+ 3 - 1
mec-web/src/main/resources/columnMapper.ini

@@ -11,6 +11,8 @@
 商品图片(插入一张图片) = image
 商品明细 = desc
 商品采购价2(元) = agreeCostPrice
+库存数量 = stockCount
+税务库存 = taxStockCount
 
 [财务支出导入模板]
 财务流程编号 = financialProcessNo
@@ -23,4 +25,4 @@
 付款金额 = amount
 备注 = itemDetail
 付款时间 = paymentTime
-事由 = cause
+事由 = cause

BIN
mec-web/src/main/resources/excelTemplate/商品导入模板.xls