From e587344857bc7e968132dc368ea3266748386191 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 11 九月 2023 09:46:08 +0800
Subject: [PATCH] a

---
 server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java |   87 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 76 insertions(+), 11 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java
index bacf9a0..9d0a328 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java
@@ -16,14 +16,17 @@
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.UUID;
@@ -34,10 +37,13 @@
  * @date 2023/09/08 11:39
  */
 @Service
+@Slf4j
 public class BaseDataServiceImpl implements BaseDataService {
 
     @Autowired
     private BaseDataMapper baseDataMapper;
+    @Autowired
+    private MultifileMapper multifileMapper;
     @Autowired
     @Lazy
     private SystemDictDataBiz systemDictDataBiz;
@@ -292,10 +298,12 @@
     }
     public static   boolean IS_RUNNING = false;
     @Override
+    @Transactional
     public   void dealBaseData() {
         if(IS_RUNNING){
             return;
         }
+        log.info("寮�濮嬪鐞嗘簮鏁版嵁=================start===================");
         IS_RUNNING = true;
 
         try {
@@ -303,6 +311,8 @@
             param.setStatus(Constants.ZERO);
             List<BaseData> allLis=findList(param);
             if(allLis==null || allLis.size() ==0){
+
+                log.info("寮�濮嬪鐞嗘簮鏁版嵁=================end========鏃犲緟澶勭悊鏁版嵁===========");
                 return ;
             }
             Brand brand = new Brand();
@@ -319,7 +329,7 @@
             p.setIsdeleted(Constants.ZERO);
             //鏌ヨ鍏ㄩ儴绫诲埆灞炴�т俊鎭�
             List<BaseCateParam> paramList = baseCateParamMapper.selectList(new QueryWrapper<>(p));
-
+            BigDecimal rate = getPriceRate();
             OssModel ossModel = initOssModel();
             Date date = new Date();
             for(BaseData data : allLis){
@@ -333,7 +343,6 @@
                 goods.setStatus(Constants.ZERO);
                 goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
                 goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
-                goods.setPrice(data.getSaleprice());
                 goods.setZdPrice(data.getPrice());
                 //澶勭悊鍝佺墝鏁版嵁
                 Brand bModel = getBrandModelFromList(data.getBrand(),brandList);
@@ -341,26 +350,70 @@
                     goods.setBrandId(bModel.getId());
                 }
                 //澶勭悊鍒楄〃鏁版嵁
-                BaseCategory cModel = getCateModelFromList(data.getBrand(),ossModel,data.getCategoryImg(), cateList);
-                if(bModel!= null){
-                    goods.setBrandId(bModel.getId());
+                BaseCategory cModel = getCateModelFromList(rate,data.getCategory(),ossModel,data.getCategoryImg(), cateList);
+                if(cModel!= null){
+                    goods.setCategoryId(cModel.getId());
                 }
-
+                goods.setImgurl(getOssImgurl(ossModel, data.getImgurl()));
+                goods.setPrice(Constants.formatBigdecimal(data.getSaleprice()).multiply(Constants.formatBigdecimal(cModel.getPriceRate())));
                 //鎻掑叆鏂板晢鍝佹暟鎹�
                 baseGoodsMapper.insert(goods);
                 //澶勭悊鍒嗙被灞炴��
                 dealCateParamAll(cModel.getId(),goods.getId(),data,paramList);
+                //澶勭悊鑳屾櫙鍥�
+                dealBgImgAll(ossModel,goods.getId(),data);
 
                 data.setEditDate(new Date());
                 data.setStatus(Constants.ONE);
                 //鏇存柊鏁版嵁澶勭悊鐘舵��
                 baseDataMapper.updateById(data);
             }
+            log.info("寮�濮嬪鐞嗘簮鏁版嵁=================success================澶勭悊鏁版嵁鍏憋紙"+allLis.size()+"锛変釜===");
         }catch (Exception e){
-
+            e.printStackTrace();
+            log.info("寮�濮嬪鐞嗘簮鏁版嵁=================error==================="+e.getMessage());
         }finally {
             IS_RUNNING = false;
+            log.info("寮�濮嬪鐞嗘簮鏁版嵁=================end===================");
         }
+    }
+
+    private BigDecimal getPriceRate() {
+        try {
+
+            BigDecimal rate = new BigDecimal(Double.parseDouble(systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.GOODS_PRICE_RATE).getCode()));
+            return rate;
+        }catch (Exception e){
+            return  new BigDecimal(1.2);
+        }
+
+    }
+
+    private void dealBgImgAll(OssModel ossModel, Integer id, BaseData data) {
+        int i =0;
+        i += addImg(i,ossModel,id,data.getBgImg());
+        i += addImg(i,ossModel,id,data.getBgImg2());
+        addImg(i,ossModel,id,data.getBgImg3());
+    }
+
+    private int addImg(int i,OssModel ossModel, Integer id,String bgImg) {
+        if(StringUtils.isNotBlank(bgImg)){
+            String img =getOssImgurl(ossModel,bgImg);
+            if(StringUtils.isNotBlank(img)){
+                Multifile f = new Multifile();
+                f.setFileurl(img);
+                f.setObjType(Constants.ZERO);
+                f.setName(bgImg.substring(bgImg.lastIndexOf("/")+1));
+                f.setType(Constants.ZERO);
+                f.setObjId(id);
+                f.setCreateDate(new Date());
+                f.setIsdeleted(Constants.ZERO);
+                f.setSortnum(i);
+                multifileMapper.insert(f);
+                return  1;
+            }
+        }
+        return  0;
     }
 
     private OssModel initOssModel() {
@@ -371,8 +424,7 @@
         model.setAccessKey(systemDictDataBiz.queryByCode(Constants.OSS, Constants.ACCESS_KEY).getCode());
         model.setBucket(systemDictDataBiz.queryByCode(Constants.OSS, Constants.BUCKETNAME).getCode());
         model.setCateFolder(systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode());
-        model.setAccessKey(systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode());
-
+        model.setGoodsFolder(systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode());
         return model;
     }
 
@@ -386,7 +438,7 @@
                     String val =(String) item.invoke(data);
                     dealCateParam(cateId,goodsId,val.toString(),cateList);
                 } catch (Exception e) {
-                    throw new RuntimeException(e);
+//                    throw new RuntimeException(e);
                 }
             }
         }
@@ -431,12 +483,16 @@
         if(StringUtils.isBlank(attr)){
             return;
         }
+//        鍟嗗搧鍚嶇О锛氱伀鏄熶汉F30BX
         //濡傛灉灞炴�т笉涓虹┖锛屽鐞嗗睘鎬ф暟鎹�
         int index  = attr.indexOf("锛�");
         if(index <=0){
             return;
         }
         String attrName = attr.substring(0,index);
+        if(StringUtils.isBlank(attrName) || StringUtils.equals(attrName, "鍟嗗搧鍚嶇О") || StringUtils.equals(attrName, "鍟嗗搧缂栧彿")){
+            return;
+        }
         String val = attr.substring(index+1);
         BaseCateParam cate = getCateParamModelFromList(cateId,attrName, list);
         BaseGoodsParam p = new BaseGoodsParam();
@@ -483,6 +539,9 @@
      */
 
     private Brand getBrandModelFromList(String name, List<Brand> brandList) {
+        if(StringUtils.isBlank(name)){
+            return null;
+        }
         if(brandList!=null && brandList.size()>0){
             for(Brand brand : brandList){
                 if(StringUtils.equals(name,brand.getName())){
@@ -509,7 +568,10 @@
      * @return
      */
 
-    private BaseCategory getCateModelFromList(String name,OssModel ossModel, String img,List<BaseCategory> list) {
+    private BaseCategory getCateModelFromList(BigDecimal dRate,String name, OssModel ossModel, String img, List<BaseCategory> list) {
+        if(StringUtils.isBlank(name)){
+            return  null;
+        }
         if(list!=null && list.size()>0){
             for(BaseCategory p : list){
                 if(StringUtils.equals(name,p.getName())){
@@ -520,7 +582,10 @@
         BaseCategory model = new BaseCategory();
         model.setCreateDate(new Date());
         model.setName(name);
+        model.setPriceRate(dRate);
         model.setIsdeleted(Constants.ZERO);
+        model.setPinyin(PinYinUtil.getFullSpell(model.getName()));
+        model.setShortPinyin(PinYinUtil.getFirstSpell(model.getName()));
         model.setImgurl(getOssImgurl(ossModel,img));
         //鎻掑叆鏂扮殑鍝佺墝淇℃伅
         baseCategoryMapper.insert(model);

--
Gitblit v1.9.3