| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Isolation; |
| | | 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.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | |
| | | private BaseCateParamMapper baseCateParamMapper; |
| | | @Autowired |
| | | private BrandMapper brandMapper; |
| | | @Autowired |
| | | private FileRecordMapper fileRecordMapper; |
| | | |
| | | @Override |
| | | public String create(BaseData baseData) { |
| | |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | return PageData.from(baseDataMapper.selectPage(page, queryWrapper)); |
| | | IPage<BaseData> result =baseDataMapper.selectPage(page, queryWrapper); |
| | | if(result!=null && result.getRecords()!=null){ |
| | | for(BaseData data :result.getRecords()){ |
| | | //多图,英文逗号隔开 |
| | | if(StringUtils.isNotBlank(data.getBgImg())){ |
| | | String tImg = data.getBgImg().replace(",", ",").replace(".avif", "").replace("/n1/jfs/", "/n0/jfs/"); |
| | | String[] imgs =tImg.split(","); |
| | | data.setBgImgs(imgs); |
| | | |
| | | } |
| | | } |
| | | } |
| | | return PageData.from(result); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | public static boolean IS_RUNNING = false; |
| | | @Override |
| | | @Async |
| | | @Transactional |
| | | public void dealBaseData() { |
| | | public synchronized void dealBaseData() { |
| | | if(IS_RUNNING){ |
| | | return; |
| | | } |
| | |
| | | BigDecimal rate = systemDictDataBiz.getGoodsPriceRate(); |
| | | OssModel ossModel = initOssModel(); |
| | | Date date = new Date(); |
| | | List<BaseCateParam> baseCateParamList = new ArrayList<>(); |
| | | List<Multifile> fileList = new ArrayList<>(); |
| | | List<Integer> goodsIdList = new ArrayList<>(); |
| | | List<FileRecord> fileRecords = new ArrayList<>(); |
| | | List<BaseGoodsParam> baseGoodsParamList = new ArrayList<>(); |
| | | 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); |
| | | //查询是否存在商品 |
| | | BaseGoods model = baseGoodsMapper.selectOne(new QueryWrapper<>(goods).last(" limit 1")); |
| | | goods.setName(StringUtils.defaultString(data.getName(),data.getTitle())); |
| | | goods.setRemark(data.getTitle()); |
| | | goods.setContent(data.getTitle()); |
| | | goods.setStatus(Constants.ZERO); |
| | | goods.setOrigin(Constants.BasegoodsOrigin.basedata); |
| | | goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName())); |
| | | goods.setPinyin(PinYinUtil.getFullSpell(goods.getName())); |
| | | goods.setZdPrice(data.getPrice()); |
| | |
| | | goods.setBrandId(bModel.getId()); |
| | | } |
| | | //处理列表数据 |
| | | BaseCategory cModel = getCateModelFromList(rate,data.getCategory(),ossModel,data.getCategoryImg(), cateList); |
| | | BaseCategory cModel = getCateModelFromList(rate,data.getCategory(),ossModel,data.getCategoryImg(), cateList,fileRecords); |
| | | if(cModel!= null){ |
| | | goods.setCategoryId(cModel.getId()); |
| | | } |
| | | goods.setImgurl(getOssImgurl(ossModel,ossModel.getGoodsFolder(), data.getImgurl())); |
| | | // goods.setImgurl(getOssImgurl(ossModel,ossModel.getGoodsFolder(), data.getImgurl())); |
| | | goods.setImgurl(getOssImgurlFile(ossModel.getGoodsFolder(), data.getImgurl(), data.getId(),Constants.ZERO,fileRecords)); |
| | | 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); |
| | | |
| | | if(model!=null){ |
| | | //如果已经存在,更新商品数据 |
| | | goods.setEditDate(date); |
| | | goods.setId(model.getId()); |
| | | baseGoodsMapper.updateById(goods); |
| | | goodsIdList.add(goods.getId()); |
| | | }else{ |
| | | //插入新商品数据 |
| | | goods.setCreateDate(date); |
| | | baseGoodsMapper.insert(goods); |
| | | } |
| | | //处理分类属性 |
| | | dealCateParamAll(cModel.getId(),goods.getId(),data,paramList, baseGoodsParamList ); |
| | | //处理背景图 |
| | | dealBgImgAll(ossModel,goods.getId(),data,fileList,fileRecords); |
| | | data.setEditDate(new Date()); |
| | | data.setStatus(Constants.ONE); |
| | | //更新数据处理状态 |
| | | baseDataMapper.updateById(data); |
| | | } |
| | | if(goodsIdList.size()>0){ |
| | | //删除原有附件大图 |
| | | UpdateWrapper<Multifile> updateModel = new UpdateWrapper<>(); |
| | | updateModel.lambda().set(Multifile::getIsdeleted,Constants.ONE); |
| | | updateModel.lambda().set(Multifile::getEditDate, new Date()); |
| | | updateModel.lambda().in(Multifile::getObjId, goodsIdList); |
| | | updateModel.lambda().eq(Multifile::getObjType, Constants.ONE); |
| | | multifileMapper.delete(updateModel); |
| | | //删除原有商品属性 |
| | | UpdateWrapper<BaseGoodsParam> bgModel = new UpdateWrapper<>(); |
| | | bgModel.lambda().set(BaseGoodsParam::getIsdeleted,Constants.ONE); |
| | | bgModel.lambda().set(BaseGoodsParam::getEditDate, new Date()); |
| | | bgModel.lambda().in(BaseGoodsParam::getGoodsId, goodsIdList); |
| | | baseGoodsParamMapper.delete(bgModel); |
| | | } |
| | | |
| | | if(fileList.size()>0){ |
| | | multifileMapper.insertBatch(fileList); |
| | | } |
| | | if(baseGoodsParamList.size()>0){ |
| | | baseGoodsParamMapper.insertBatch(baseGoodsParamList); |
| | | } |
| | | if(fileRecords.size()>0){ |
| | | fileRecordMapper.insertBatch(fileRecords); |
| | | } |
| | | log.info("开始处理源数据=================success================处理数据共("+allLis.size()+")个==="); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | log.info("开始处理源数据=================error==================="+e.getMessage()); |
| | | throw e; |
| | | }finally { |
| | | IS_RUNNING = false; |
| | | log.info("开始处理源数据=================end==================="); |
| | |
| | | } |
| | | |
| | | |
| | | private void dealBgImgAll(OssModel ossModel, Integer id, BaseData data) { |
| | | private void dealBgImgAll(OssModel ossModel, Integer id, BaseData data,List<Multifile> fileList,List<FileRecord> fileRecords) { |
| | | int i =0; |
| | | //多图,英文逗号隔开 |
| | | if(StringUtils.isNotBlank(data.getBgImg())){ |
| | | String tImg = data.getBgImg().replace(",", ","); |
| | | String tImg = data.getBgImg().replace(",", ",").replace(".avif", ""); |
| | | String[] imgs =tImg.split(","); |
| | | for (int j = 0; j < imgs.length; j++) { |
| | | if(StringUtils.isNotBlank(imgs[j])){ |
| | | i += addImg(i,ossModel,id,imgs[j]); |
| | | i += addImg(i,ossModel,id,imgs[j],fileList,fileRecords); |
| | | } |
| | | } |
| | | } |
| | |
| | | // addImg(i,ossModel,id,data.getBgImg3()); |
| | | } |
| | | |
| | | private int addImg(int i,OssModel ossModel, Integer id,String bgImg) { |
| | | private int addImg(int i,OssModel ossModel, Integer id,String bgImg,List<Multifile> fileList,List<FileRecord> fileRecords) { |
| | | if(StringUtils.isNotBlank(bgImg)){ |
| | | String img =getOssImgurl(ossModel, ossModel.getGoodsFolder() ,bgImg); |
| | | bgImg = bgImg.replace("/n1/jfs/", "/n0/jfs/"); |
| | | // String img =getOssImgurl(ossModel, ossModel.getGoodsFolder() ,bgImg); |
| | | String img = getOssImgurlFile(ossModel.getGoodsFolder(), bgImg, null,Constants.TWO,fileRecords); |
| | | if(StringUtils.isNotBlank(img)){ |
| | | |
| | | Multifile f = new Multifile(); |
| | | f.setFileurl(img); |
| | | f.setObjType(Constants.ZERO); |
| | | f.setObjType(Constants.ONE); |
| | | 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); |
| | | fileList.add(f); |
| | | // multifileMapper.insert(f); |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | private void dealCateParamAll(Integer cateId,Integer goodsId, BaseData data ,List<BaseCateParam> cateList) { |
| | | private void dealCateParamAll(Integer cateId,Integer goodsId, BaseData data ,List<BaseCateParam> cateList,List<BaseGoodsParam> paramList) { |
| | | Method[] fields = data.getClass().getMethods(); // 获取对象的所有属性 |
| | | for (Method item : fields) { |
| | | String name = item.getName(); |
| | | if(name.indexOf("getAttr") == 0){ |
| | | try { |
| | | String val =(String) item.invoke(data); |
| | | dealCateParam(cateId,goodsId,val.toString(),cateList); |
| | | dealCateParam(cateId,goodsId,val.toString(),cateList,paramList); |
| | | } catch (Exception e) { |
| | | // throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // dealCateParam(cateId,goodsId,data.getAttr1(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr2(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr3(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr4(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr5(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr6(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr7(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr8(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr9(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr10(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr11(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr12(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr13(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr14(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr15(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr16(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr17(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr18(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr19(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr20(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr21(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr22(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr23(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr24(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr25(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr26(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr27(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr28(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr29(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr30(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr31(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr32(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr33(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr34(),cateList); |
| | | } |
| | | |
| | | private void dealCateParam(Integer cateId, Integer goodsId, String attr,List<BaseCateParam> list) { |
| | | private void dealCateParam(Integer cateId, Integer goodsId, String attr,List<BaseCateParam> list,List<BaseGoodsParam> paramList) { |
| | | if(StringUtils.isBlank(attr)){ |
| | | return; |
| | | } |
| | |
| | | p.setVal(val); |
| | | p.setCreateDate(new Date()); |
| | | p.setGoodsId(goodsId); |
| | | baseGoodsParamMapper.insert(p); |
| | | paramList.add(p); |
| | | // baseGoodsParamMapper.insert(p); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | |
| | | private BaseCategory getCateModelFromList(BigDecimal dRate,String name, OssModel ossModel, String img, List<BaseCategory> list) { |
| | | private BaseCategory getCateModelFromList(BigDecimal dRate,String name, OssModel ossModel, String img, List<BaseCategory> list, List<FileRecord> fileRecords) { |
| | | if(StringUtils.isBlank(name)){ |
| | | return null; |
| | | } |
| | |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setPinyin(PinYinUtil.getFullSpell(model.getName())); |
| | | model.setShortPinyin(PinYinUtil.getFirstSpell(model.getName())); |
| | | model.setImgurl(getOssImgurl(ossModel, ossModel.getCateFolder() ,img)); |
| | | // model.setImgurl(getOssImgurl(ossModel, ossModel.getCateFolder() ,img)); |
| | | model.setImgurl(getOssImgurlFile(ossModel.getCateFolder(), img, null,Constants.ONE,fileRecords)); |
| | | //插入新的品牌信息 |
| | | baseCategoryMapper.insert(model); |
| | | //加入集合中 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getOssImgurl(OssModel ossModel, String folder,String img) { |
| | | public String getOssImgurl(OssModel ossModel, String folder,String img ) { |
| | | if(StringUtils.isBlank(img)){ |
| | | return null; |
| | | } |
| | |
| | | String tempFileName = nowDate + "/" + fileName; |
| | | String key =folder+ tempFileName;// 文件名 |
| | | |
| | | |
| | | ALiYunUtil obs = new ALiYunUtil(ossModel.getEndpoint(), ossModel.getAccessId(), ossModel.getAccessKey()); |
| | | if (obs.uploadOnlineObject(img,ossModel.getBucket(), key,null)) { |
| | | return tempFileName; |
| | |
| | | } |
| | | return null; |
| | | } |
| | | public String getOssImgurlFile(String folder,String img ,String id,Integer objType,List<FileRecord> fileRecords) { |
| | | 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 =folder+ tempFileName;// 文件名 |
| | | |
| | | FileRecord model = new FileRecord(); |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setCreateDate(new Date()); |
| | | model.setName(tempFileName); |
| | | model.setInfo(null); |
| | | model.setFolder(folder); |
| | | model.setUrl(img); |
| | | model.setObjId(id); |
| | | model.setType(objType); |
| | | model.setStatus(Constants.ZERO); |
| | | model.setKeyval(key); |
| | | fileRecords.add(model); |
| | | |
| | | return tempFileName; |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public String getOssImgurl(OssModel ossModel, String folder, File f) { |