Sfoglia il codice sorgente

产品备案信息的修改

yangbo 4 anni fa
parent
commit
d6abb2355e

+ 26 - 3
kmall-admin/src/main/java/com/kmall/admin/controller/GoodsProductController.java

@@ -197,7 +197,11 @@ public class GoodsProductController {
     @ResponseBody
     public R batchAddImgByZip(@RequestParam("file") MultipartFile file) throws IOException {
         //上传文件
-        batchAdd(file, 2);
+        try {
+            batchAdd(file, 2);
+        } catch (Exception e) {
+            return R.error(500, e.getMessage());
+        }
         return R.ok();
     }
 
@@ -278,6 +282,12 @@ public class GoodsProductController {
 
 
                     MultipartFile mulFileByPath = getMulFileByPath(destDirPath + "/" + entry.getName());
+                    long fileSize = mulFileByPath.getSize();
+                    int maxSize = 5 * 1024 * 1024;
+                    if (fileSize > maxSize) {
+                        throw new RRException("文件名为:" + entry.getName() + "的图片过大,超过" + (maxSize / 1024 * 1024) + "M,请重新调整后上传!");
+                    }
+
                     //上传文件
                     String url = FileManager.uploadToMinIO(mulFileByPath);
                     list.add(url);
@@ -288,9 +298,15 @@ public class GoodsProductController {
                         }
                         String fileName = tmp.split("\\.")[0];
                         String[] split = fileName.split("_");
+                        if (split.length != 2) {
+                            throw new RRException("文件名为:" + fileName + "的产品命名格式不正确,请检查!");
+                        }
                         String sku = split[0];
                         String imgType = split[1];
                         GoodsProductEntity entity = goodsProductService.queryBySku(sku);
+                        if (entity == null) {
+                            throw new RRException("sku为:" + sku + "的产品不存在!");
+                        }
                         GoodsProductEntity upd = new GoodsProductEntity();
                         upd.setMallGoodsProductSn(entity.getMallGoodsProductSn());
                         PdProductImgDto tmpDto = new PdProductImgDto();
@@ -320,7 +336,6 @@ public class GoodsProductController {
                         tmpDto.setImageUrl(url);
                         pdProductImgDtoList.add(tmpDto);
 
-
                         goodsProductService.update(upd);
 
                     } else if (type == 2) {
@@ -331,6 +346,9 @@ public class GoodsProductController {
                         }
                         String fileName = tmp.split("\\.")[0];
                         String[] split = fileName.split("_");
+                        if (split.length != 2) {
+                            throw new RRException("文件名为:" + fileName + "的产品命名格式不正确,请检查!");
+                        }
                         String barCode = split[0];
                         String imgType = split[1];
                         GoodsProductEntity entity = goodsProductService.queryByBarcode(barCode);
@@ -450,7 +468,12 @@ public class GoodsProductController {
     @ResponseBody
     public R batchAddImg(@RequestParam("file") MultipartFile file) throws IOException {
         //上传文件
-        batchAdd(file, 1);
+        try {
+            batchAdd(file, 1);
+        } catch (Exception e) {
+
+            return R.error(500, e.getCause().getMessage());
+        }
         return R.ok();
     }
 

+ 3 - 0
kmall-admin/src/main/java/com/kmall/admin/dao/GoodsProductDao.java

@@ -6,6 +6,7 @@ import com.kmall.manager.dao.BaseDao;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 产品信息备案表Dao
@@ -24,4 +25,6 @@ public interface GoodsProductDao extends BaseDao<GoodsProductEntity> {
     GoodsProductEntity selectBySku(String sku);
 
     GoodsProductEntity selectByBarcode(String barCode);
+
+    int updateStatusBySkuBatch(@Param("list") List<String> skuList, @Param("map") Map<String, Object> map);
 }

+ 4 - 0
kmall-admin/src/main/java/com/kmall/admin/service/GoodsProductService.java

@@ -82,4 +82,8 @@ public interface GoodsProductService {
 
     GoodsProductEntity queryByBarcode(String barCode);
 
+    int updateSendOmsPassStatus(List<String> skuList);
+
+    int updateSendOmsFailStatus(List<String> skuList);
+
 }

+ 42 - 2
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsProductServiceImpl.java

@@ -23,6 +23,7 @@ import org.springframework.util.StringUtils;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 产品信息备案表Service实现类
@@ -182,21 +183,30 @@ public class GoodsProductServiceImpl implements GoodsProductService {
             dto.setOperateFlag(operateFlag);
             goodsProductDtoList.add(dto);
         }
+        boolean isPass = true;
         try {
             ResponseMessage result = requestOmsProduct(goodsProductDtoList);
+            if (!"0".equals(result.getCode())) {
+                isPass = false;
+            }
+            rollbackHandler(goodsProductDtoList, isPass);
             return result.getMsg();
         }catch (Exception e){
+            isPass = false;
             e.printStackTrace();
             LOGGER.error(e.getMessage());
         }
-
+        rollbackHandler(goodsProductDtoList, isPass);
         return "请求失败,请联系管理员";
     }
 
     @Override
     @Transactional
     public String sendAllProduct(String operateFlag) {
-        List<GoodsProductEntity> goodsProductEntityList = goodsProductDao.queryList(new HashMap<>());// 查询所有
+        // 查询所有发送失败或者未发送的
+        Map<String, Object> condition = new HashMap<>();
+        condition.put("isSend", "0,2");
+        List<GoodsProductEntity> goodsProductEntityList = goodsProductDao.queryList(condition);
         if (goodsProductEntityList == null || goodsProductEntityList.size()==0){
             return "无数据,请添加数据";
         }
@@ -212,13 +222,20 @@ public class GoodsProductServiceImpl implements GoodsProductService {
             dto.setOperateFlag(operateFlag);
             goodsProductDtoList.add(dto);
         }
+        boolean isPass = true;
         try {
             ResponseMessage result = requestOmsProduct(goodsProductDtoList);
+            if (!"0".equals(result.getCode())) {
+                isPass = false;
+            }
+            rollbackHandler(goodsProductDtoList, isPass);
             return result.getMsg();
         }catch (Exception e){
+            isPass = false;
             e.printStackTrace();
             LOGGER.error(e.getMessage());
         }
+        rollbackHandler(goodsProductDtoList, isPass);
         return "请求失败,请联系管理员";
     }
 
@@ -232,6 +249,20 @@ public class GoodsProductServiceImpl implements GoodsProductService {
         return goodsProductDao.selectByBarcode(barCode);
     }
 
+    @Override
+    public int updateSendOmsPassStatus(List<String> skuList) {
+        Map<String, Object> param = new HashMap<>();
+        param.put("isSend", 1);
+        return goodsProductDao.updateStatusBySkuBatch(skuList, param);
+    }
+
+    @Override
+    public int updateSendOmsFailStatus(List<String> skuList) {
+        Map<String, Object> param = new HashMap<>();
+        param.put("isSend", 2);
+        return goodsProductDao.updateStatusBySkuBatch(skuList, param);
+    }
+
 
     private ResponseMessage requestOmsProduct(List<GoodsProductDto> goodsProductDtoList){
         Map<String, String> sParaTemp = new TreeMap<String, String>();
@@ -273,6 +304,15 @@ public class GoodsProductServiceImpl implements GoodsProductService {
        return result;
     }
 
+    private void rollbackHandler(List<GoodsProductDto> goodsProductDtoList, boolean pass){
+        List<String> skuList = goodsProductDtoList.stream().map(GoodsProductDto::getSku).collect(Collectors.toList());
+        if (pass) {
+            this.updateSendOmsPassStatus(skuList);
+        } else {
+            this.updateSendOmsFailStatus(skuList);
+        }
+    }
+
 
 
 }

+ 25 - 3
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -1615,16 +1615,38 @@ public class GoodsServiceImpl implements GoodsService {
 
                 if(!isFail){
                     GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
+
+                    MngChangeEntity mngChangeEntity = new MngChangeEntity();
+                    mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
+                    mngChangeEntity.setChangeReason("更新商户商品总库存");
+                    mngChangeEntity.setCreateTime(new Date());
+                    mngChangeEntity.setModTime(new Date());
+                    mngChangeEntity.setCreaterSn(user.getUsername());
+                    mngChangeEntity.setModerSn(user.getUsername());
+                    mngChangeEntity.setIsValid(0);
+                    mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
+
                     if(goods!=null) {// 修改商品
+                        mngChangeEntity.setOriginalNum(goods.getGoodsNumber());//原库存数
+                        mngChangeEntity.setValidNum(goods.getGoodsNumber() + Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
+                        mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
+                        mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
+                        mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goods.getId())));
+
                         goodsEntity.setId(goods.getId());
-                        goodsEntity.setVideoUrl(goods.getVideoUrl());
-                        goodsEntity.setListPicUrl(goods.getListPicUrl());
-                        goodsEntity.setPrimaryPicUrl(goods.getPrimaryPicUrl());
                         goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
                         goodsDao.update(goodsEntity);
                     }else{
+                        mngChangeEntity.setOriginalNum(0);//原库存数
+                        mngChangeEntity.setValidNum(Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
+                        mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
+                        mngChangeEntity.setChangeType(Dict.changeType.item_2.getItem());
+
                         goodsDao.save(goodsEntity);
+                        mngChangeEntity.setGoodsId(goodsEntity.getId().intValue());
                     }
+
+                    mngChangeDao.save(mngChangeEntity);
                     // 修改产品
                     ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
 

+ 26 - 0
kmall-admin/src/main/resources/mybatis/mapper/GoodsProductDao.xml

@@ -166,6 +166,9 @@
 		<if test="name != null and name.trim() != ''">
 			AND `prod_name` LIKE concat('%',#{name},'%')
 		</if>
+		<if test="isSend != null and isSend.trim() != ''">
+			AND `is_send` in (${isSend})
+		</if>
         <choose>
             <when test="sidx != null and sidx.trim() != ''">
                 order by ${sidx} ${order}
@@ -576,6 +579,29 @@
 		</set>
 		where mall_goods_product_sn = #{mallGoodsProductSn}
 	</update>
+
+
+	<update id="updateStatusBySkuBatch" parameterType="map">
+		update mall_goods_product
+		<set>
+			<if test="map.isLaw != null">`is_law` = #{map.isLaw}, </if>
+			<if test="map.isGift != null">`is_gift` = #{map.isGift}, </if>
+			<if test="map.moderSn != null">`moder_sn` = #{map.moderSn}, </if>
+			<if test="map.modTime != null">`mod_time` = #{map.modTime}, </if>
+			<if test="map.tstm != null">`tstm` = #{map.tstm}, </if>
+			<if test="map.exField != null">`ex_field` = #{map.exField}, </if>
+			<if test="map.exField2 != null">`ex_field2` = #{map.exField2}, </if>
+			<if test="map.exField3 != null">`ex_field3` = #{map.exField3}, </if>
+			<if test="map.exField4 != null">`ex_field4` = #{map.exField4}, </if>
+			<if test="map.exField5 != null">`ex_field5` = #{map.exField5}, </if>
+			<if test="map.isSend != null">`is_send` = #{map.isSend}, </if>
+		</set>
+		where sku in
+		<foreach collection="list" item="sku" open="(" separator="," close=")">
+			 #{sku}
+		</foreach>
+
+	</update>
 	
 	<delete id="delete">
 		delete from mall_goods_product where mall_goods_product_sn = #{value}

+ 2 - 1
kmall-admin/src/main/webapp/WEB-INF/page/shop/goodsproduct.html

@@ -48,7 +48,8 @@
                         <i-button type="ghost" icon="ios-cloud-upload-outline">商品图片批量导入</i-button>
                     </Upload>
                 </i-col>
-                <i-col style="display: inline-grid;">
+                <!-- 商品图片隐藏 -->
+                <i-col style="display: none;">
                     <Upload :show-upload-list="false" :on-success="uploadExcelSuccess" :on-error="uploadExcelError" :on-format-error="uploadExcelFormatError"
                             :on-progress="uploadExcelProgress"
                             :format="['xls','xlsx','zip']"