|  |  | 
 |  |  | import com.doumee.dao.business.join.GoodsJoinMapper; | 
 |  |  | import com.doumee.dao.business.model.*; | 
 |  |  | import com.doumee.dao.business.model.dto.*; | 
 |  |  | import com.doumee.dao.system.model.SystemDepartment; | 
 |  |  | import com.doumee.service.CateParamSelectService; | 
 |  |  | import com.doumee.service.business.BaseDataService; | 
 |  |  | import com.doumee.service.business.GoodsService; | 
 |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
 |  |  | 
 |  |  | import java.net.URLEncoder; | 
 |  |  | import java.nio.charset.Charset; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 商品信息表Service实现 | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private CategoryMapper categoryMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private BaseCategoryMapper baseCategoryMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private CateAttrMapper cateAttrMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private CateParamMapper cateParamMapper; | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private GoodsJoinMapper goodsJoinMapper; | 
 |  |  |  | 
 |  |  |     @Lazy | 
 |  |  |     @Autowired | 
 |  |  |     private CateParamSelectMapper cateParamSelectMapper; | 
 |  |  |     private CateParamSelectService cateParamSelectService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RedisTemplate redisTemplate; | 
 |  |  | 
 |  |  |         if(category.getPlatCateId() == null){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请前往【类别管理】先关联平台类别!"); | 
 |  |  |         } | 
 |  |  |         BaseCategory baseCategory = baseCategoryMapper.selectById(category.getPlatCateId()); | 
 |  |  |         if(baseCategory == null){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请前往【类别管理】先关联平台类别!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         BaseGoods bp = new BaseGoods(); | 
 |  |  |         bp.setCategoryId(category.getPlatCateId()); | 
 |  |  |         bp.setIsdeleted(Constants.ZERO); | 
 |  |  | 
 |  |  |         try{ | 
 |  |  |             for(BaseGoods model : goodsList){ | 
 |  |  |                 //遍历平台商品信息,进行商品信息同步 | 
 |  |  |                 //分类加价系数 | 
 |  |  |  | 
 |  |  |                 model.setCateRatePrice(baseCategory.getPriceRate()); | 
 |  |  |                 Goods goods = initGoodsPlatParam(user,model,param); | 
 |  |  |                 if(goods == null){ | 
 |  |  |                     continue; | 
 |  |  | 
 |  |  |             if(goodsParamList.size()>0){ | 
 |  |  |                 goodsParamMapper.insertBatch(goodsParamList); | 
 |  |  |             } | 
 |  |  |             cateParamSelectService.dealCateParamSelect(); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |            e.printStackTrace(); | 
 |  |  |         }finally { | 
 |  |  | 
 |  |  |     private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model,List<Multifile> fileList ) { | 
 |  |  |         Multifile f = new Multifile(); | 
 |  |  |         f.setObjId(model.getId()); | 
 |  |  |         f.setObjType(Constants.ONE); | 
 |  |  |         f.setIsdeleted(Constants.ZERO); | 
 |  |  |         f.setObjType(Constants.ONE); | 
 |  |  |         List<Multifile> multifileList =multifileMapper.selectList(new QueryWrapper<>(f)); | 
 |  |  |         if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ | 
 |  |  |             for (int i = 0; i < multifileList.size(); i++) { | 
 |  |  | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"数据异常请刷新重试"); | 
 |  |  |         } | 
 |  |  |         //如果没有配置入手价,安装加价系数来计算 | 
 |  |  | //        if(model.getCateRatePrice()==null){ | 
 |  |  | //            model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate()); | 
 |  |  | //        } | 
 |  |  |         if(model.getCateRatePrice()==null){ | 
 |  |  |             model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate()); | 
 |  |  |         } | 
 |  |  |         //返回 .multiply(model.getCateRatePrice()) | 
 |  |  |         return (Constants.formatBigdecimal(model.getPrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING); | 
 |  |  |         return (Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ | 
 |  |  |             for (int i = 0; i < multifileList.size(); i++) { | 
 |  |  |                 Multifile multifile = multifileList.get(i); | 
 |  |  |                 if(StringUtils.isBlank(multifile.getFileurl())){ | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 multifile.setCreator(user.getId()); | 
 |  |  |                 multifile.setCreateDate(new Date()); | 
 |  |  |                 multifile.setIsdeleted(Constants.ZERO); | 
 |  |  | 
 |  |  |         if (CollectionUtils.isEmpty(ids)) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         goodsMapper.deleteBatchIds(ids); | 
 |  |  |         for(Integer id : ids){ | 
 |  |  |             deleteById(id); | 
 |  |  |         } | 
 |  |  | //        goodsMapper.deleteBatchIds(ids); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |         if(!Objects.isNull(category)){ | 
 |  |  |             goods.setCategoryName(category.getName()); | 
 |  |  |         } | 
 |  |  |         goods.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",id))); | 
 |  |  |         goods.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_TYPE",Constants.ZERO).eq("OBJ_ID",id))); | 
 |  |  |         return goods; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                 Goods::getPrice,goods.getSPrice(),goods.getEPrice()); | 
 |  |  |         queryWrapper.orderByDesc(Goods::getId); | 
 |  |  |         List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper); | 
 |  |  |         String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
 |  |  |                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
 |  |  |         goodsList.forEach(i->{ | 
 |  |  |             i.setPrefixUrl(prefixUrl); | 
 |  |  |             i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM "))); | 
 |  |  |             i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId()).orderByAsc(" SORTNUM "))); | 
 |  |  |         }); | 
 |  |  |         if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){ | 
 |  |  |             this.dealGoodsMsg(goodsList); | 
 |  |  |         } | 
 |  |  |         return goodsList; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
 |  |  |         goodsIPage.getRecords().forEach(i->{ | 
 |  |  |             i.setPrefixUrl(prefixUrl); | 
 |  |  |             if(i.getType().equals(Constants.ONE)){ | 
 |  |  |                 i.setBasePrice(Constants.formatBigdecimal(i.getBasePrice()).multiply(Constants.formatBigdecimal(i.getBasePriceRate())).setScale(0,BigDecimal.ROUND_CEILING)); | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |         return PageData.from(goodsIPage); | 
 |  |  |     } | 
 |  |  | 
 |  |  |                 .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getEPrice()), "  t.PRICE <=  "+pageWrap.getModel().getEPrice()+" "); | 
 |  |  |         queryWrapper.orderByDesc(Goods::getId); | 
 |  |  |         IPage<Goods> goodsIPage =  goodsJoinMapper.selectJoinPage(page, Goods.class, queryWrapper); | 
 |  |  |         String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
 |  |  |                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
 |  |  |         goodsIPage.getRecords().forEach(i->{ | 
 |  |  |             i.setCategoryImgurl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
 |  |  |                     + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode() + i.getCategoryImgurl()); | 
 |  |  |             i.setPrefixUrl(prefixUrl); | 
 |  |  |             i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM "))); | 
 |  |  |             i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>() | 
 |  |  |                     .eq("GOODS_ID",i.getId()) | 
 |  |  |                     .orderByAsc(" SORTNUM "))); | 
 |  |  |         }); | 
 |  |  |         if(!Objects.isNull(goodsIPage.getRecords())&&goodsIPage.getRecords().size()>Constants.ZERO){ | 
 |  |  |             this.dealGoodsMsg(goodsIPage.getRecords()); | 
 |  |  |         } | 
 |  |  |         return PageData.from(goodsIPage); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     public void dealGoodsMsg(List<Goods> goodsList){ | 
 |  |  |         String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
 |  |  |                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
 |  |  |         String prefixUrlCategory = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
 |  |  |                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode(); | 
 |  |  |         List<Integer> integerList = goodsList.stream().map(Goods::getId).collect(Collectors.toList()); | 
 |  |  |  | 
 |  |  |         List<Multifile> mFileList = multifileMapper.selectList(new QueryWrapper<Multifile>() | 
 |  |  |                 .lambda().in(Multifile::getObjId,integerList) | 
 |  |  |                 .eq(Multifile::getType,Constants.ZERO) | 
 |  |  |                 .eq(Multifile::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(Multifile::getObjType,Constants.ZERO)); | 
 |  |  |         List<GoodsParam> goodsParamList = goodsParamMapper.selectList(new QueryWrapper<GoodsParam>() | 
 |  |  |                     .in("GOODS_ID",integerList) | 
 |  |  |                     .orderByAsc(" SORTNUM ")); | 
 |  |  |         goodsList.forEach(i->{ | 
 |  |  |             i.setCategoryImgurl(prefixUrlCategory + i.getCategoryImgurl()); | 
 |  |  |             i.setPrefixUrl(prefixUrl); | 
 |  |  |             i.setMultifileList(mFileList.stream().filter(s -> s.getObjId().equals(i.getId())).collect(Collectors.toList())); | 
 |  |  |             i.setGoodsParamList(goodsParamList.stream().filter(s -> s.getGoodsId().equals(i.getId())).collect(Collectors.toList())); | 
 |  |  |         }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public List<Goods> findListForH5(GoodsRequest goodsRequest) { | 
 |  |  | 
 |  |  |                 .apply(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getEPrice()), "  t.PRICE <=  "+goodsRequest.getEPrice()+" "); | 
 |  |  |         queryWrapper.orderByDesc(Goods::getId); | 
 |  |  |         List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper); | 
 |  |  |         String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
 |  |  |                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
 |  |  |         goodsList.forEach(i->{ | 
 |  |  |             i.setCategoryImgurl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
 |  |  |                     + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode() + i.getCategoryImgurl()); | 
 |  |  |             i.setPrefixUrl(prefixUrl); | 
 |  |  |             i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM "))); | 
 |  |  |             i.setGoodsParamList(goodsParamMapper.selectList( | 
 |  |  |                     new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId()) | 
 |  |  |                             .apply(" name in ( select cp.NAME from cate_param cp where cp.CATEGORY_ID = "+i.getCategoryId()+" and cp.ISSHOW = 1 and cp.ISDELETED = 0 and cp.STATUS = 0 ) ") | 
 |  |  |                             .orderByAsc(" SORTNUM "))); | 
 |  |  |         }); | 
 |  |  |         if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){ | 
 |  |  |             this.dealGoodsMsg(goodsList); | 
 |  |  |         } | 
 |  |  |         return goodsList; | 
 |  |  |     } | 
 |  |  |  |