浏览代码

问题修复

zhh 6 年之前
父节点
当前提交
1d7e490d13

+ 22 - 0
mall-admin/src/main/java/com/macro/mall/service/impl/PmsProductServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import java.lang.reflect.Method;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -78,6 +79,8 @@ public class PmsProductServiceImpl implements PmsProductService {
         relateAndInsertList(productLadderDao, productParam.getProductLadderList(), productId);
         //满减价格
         relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), productId);
+        //处理sku的编码
+        handleSkuStockCode(productParam.getSkuStockList(),productId);
         //添加sku库存信息
         relateAndInsertList(skuStockDao, productParam.getSkuStockList(), productId);
         //添加商品参数,添加自定义商品规格
@@ -90,6 +93,24 @@ public class PmsProductServiceImpl implements PmsProductService {
         return count;
     }
 
+    private void handleSkuStockCode(List<PmsSkuStock> skuStockList, Long productId) {
+        if(CollectionUtils.isEmpty(skuStockList))return;
+        for(int i=0;i<skuStockList.size();i++){
+            PmsSkuStock skuStock = skuStockList.get(i);
+            if(StringUtils.isEmpty(skuStock.getSkuCode())){
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+                StringBuilder sb = new StringBuilder();
+                //日期
+                sb.append(sdf.format(new Date()));
+                //四位商品id
+                sb.append(String.format("%04d", productId));
+                //三位索引id
+                sb.append(String.format("%03d", i+1));
+                skuStock.setSkuCode(sb.toString());
+            }
+        }
+    }
+
     @Override
     public PmsProductResult getUpdateInfo(Long id) {
         return productDao.getUpdateInfo(id);
@@ -121,6 +142,7 @@ public class PmsProductServiceImpl implements PmsProductService {
         PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
         skuStockExample.createCriteria().andProductIdEqualTo(id);
         skuStockMapper.deleteByExample(skuStockExample);
+        handleSkuStockCode(productParam.getSkuStockList(),id);
         relateAndInsertList(skuStockDao, productParam.getSkuStockList(), id);
         //修改商品参数,添加自定义商品规格
         PmsProductAttributeValueExample productAttributeValueExample = new PmsProductAttributeValueExample();

+ 3 - 2
mall-admin/src/main/resources/dao/PmsMemberPriceDao.xml

@@ -3,11 +3,12 @@
 <mapper namespace="com.macro.mall.dao.PmsMemberPriceDao">
     <!--批量新增回写主键支持-->
     <insert id="insertList">
-        INSERT INTO pms_member_price (product_id, member_level_id, member_price) VALUES
+        INSERT INTO pms_member_price (product_id, member_level_id, member_price,member_level_name) VALUES
         <foreach collection="list" separator="," item="item" index="index">
             (#{item.productId,jdbcType=BIGINT},
             #{item.memberLevelId,jdbcType=BIGINT},
-            #{item.memberPrice,jdbcType=DECIMAL})
+            #{item.memberPrice,jdbcType=DECIMAL},
+            #{item.memberLevelName,jdbcType=VARCHAR})
         </foreach>
     </insert>
 </mapper>