From 04d88ef5d6e9f4814ad16f51f1550bd5be7c6fe6 Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期五, 15 九月 2023 09:12:31 +0800 Subject: [PATCH] 优化素材库处理源数据 --- server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java | 128 +++++++++++++++++++++++++++++++++++++++--- 1 files changed, 119 insertions(+), 9 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 c0d4df7..1fe955e 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 @@ -1,26 +1,35 @@ package com.doumee.service.business.impl; +import com.doumee.biz.system.SystemDictDataBiz; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Constants; +import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.PinYinUtil; import com.doumee.core.utils.Utils; +import com.doumee.core.utils.aliyun.ALiYunUtil; import com.doumee.dao.business.*; import com.doumee.dao.business.model.*; +import com.doumee.dao.business.model.dto.OssModel; import com.doumee.service.business.BaseDataService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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; /** * 鍟嗗搧婧愭暟鎹俊鎭〃Service瀹炵幇 @@ -28,10 +37,16 @@ * @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; @Autowired private BaseGoodsMapper baseGoodsMapper; @Autowired @@ -283,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 { @@ -294,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(); @@ -310,11 +329,22 @@ p.setIsdeleted(Constants.ZERO); //鏌ヨ鍏ㄩ儴绫诲埆灞炴�т俊鎭� List<BaseCateParam> paramList = baseCateParamMapper.selectList(new QueryWrapper<>(p)); + //榛樿獚鍔犱环绯绘暟 + BigDecimal rate = systemDictDataBiz.getGoodsPriceRate(); + OssModel ossModel = initOssModel(); Date date = new Date(); for(BaseData data : allLis){ BaseGoods goods = new BaseGoods(); goods.setBaseDataId(data.getId()); goods.setIsdeleted(Constants.ZERO); + if(baseGoodsMapper.selectCount(new QueryWrapper<>(goods)) >0){ + //濡傛灉宸茬粡瀛樺湪锛岄�昏緫鍒犻櫎鏃х殑鍟嗗搧鏁版嵁 + UpdateWrapper<BaseGoods> updateModel = new UpdateWrapper<>(); + updateModel.lambda().set(BaseGoods::getIsdeleted,Constants.ONE); + updateModel.lambda().set(BaseGoods::getEditDate, new Date()); + updateModel.lambda().eq(BaseGoods::getBaseDataId, data.getId()); + baseGoodsMapper.update(null, updateModel); + } goods.setCreateDate(date); goods.setName(StringUtils.defaultString(data.getName(),data.getTitle())); goods.setRemark(data.getTitle()); @@ -322,7 +352,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); @@ -330,26 +359,72 @@ goods.setBrandId(bModel.getId()); } //澶勭悊鍒楄〃鏁版嵁 - BaseCategory cModel = getCateModelFromList(data.getBrand(),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 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() { + OssModel model = new OssModel(); + model.setUrl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()); + model.setEndpoint(systemDictDataBiz.queryByCode(Constants.OSS, Constants.ENDPOINT).getCode()); + model.setAccessId(systemDictDataBiz.queryByCode(Constants.OSS, Constants.ACCESS_ID).getCode()); + 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.setGoodsFolder(systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode()); + return model; } @@ -362,7 +437,7 @@ String val =(String) item.invoke(data); dealCateParam(cateId,goodsId,val.toString(),cateList); } catch (Exception e) { - throw new RuntimeException(e); +// throw new RuntimeException(e); } } } @@ -407,12 +482,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(); @@ -459,6 +538,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())){ @@ -485,7 +567,10 @@ * @return */ - private BaseCategory getCateModelFromList(String name, 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())){ @@ -496,12 +581,37 @@ BaseCategory model = new BaseCategory(); model.setCreateDate(new Date()); model.setName(name); + model.setPriceRate(dRate); model.setIsdeleted(Constants.ZERO); - model.setImgurl(img); + model.setPinyin(PinYinUtil.getFullSpell(model.getName())); + model.setShortPinyin(PinYinUtil.getFirstSpell(model.getName())); + model.setImgurl(getOssImgurl(ossModel,img)); //鎻掑叆鏂扮殑鍝佺墝淇℃伅 baseCategoryMapper.insert(model); //鍔犲叆闆嗗悎涓� list.add(model); return model; } + + private String getOssImgurl(OssModel ossModel, String img) { + if(StringUtils.isBlank(img)){ + return null; + } + try { + String nowDate = DateUtil.getNowShortDate();// 褰撳墠鏃堕棿锛堝勾鏈堟棩锛� + String nfix = img.lastIndexOf(".")>0?img.substring(img.lastIndexOf(".")):null; + nfix = StringUtils.defaultString(nfix,".jpg"); + String fileName = UUID.randomUUID() + nfix; + String tempFileName = nowDate + "/" + fileName; + String key = ossModel.getCateFolder() + tempFileName;// 鏂囦欢鍚� + + ALiYunUtil obs = new ALiYunUtil(ossModel.getEndpoint(), ossModel.getAccessId(), ossModel.getAccessKey()); + if (obs.uploadOnlineObject(img,ossModel.getBucket(), key,null)) { + return tempFileName; + } + }catch (Exception e){ + + } + return null; + } } -- Gitblit v1.9.3