| | |
| | | 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 org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | 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; |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | return goods.getId(); |
| | | } |
| | | |
| | | @Async |
| | | @Override |
| | | @Transactional( rollbackFor = {Exception.class, BusinessException.class}) |
| | | public Integer createPlat(GoodCreatePlatRequest param){ |
| | |
| | | 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); |
| | |
| | | // 如果选择平台商品和查询结果对不上,提示错误 |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请正确选择平台商品!"); |
| | | } |
| | | for(BaseGoods model : goodsList){ |
| | | //遍历平台商品信息,进行商品信息同步 |
| | | Goods goods = initGoodsPlatParam(user,model,param); |
| | | if(goods == null){ |
| | | continue; |
| | | List<Multifile> multifileList = new ArrayList<>(); |
| | | List<GoodsParam> goodsParamList = new ArrayList<>(); |
| | | try{ |
| | | for(BaseGoods model : goodsList){ |
| | | //遍历平台商品信息,进行商品信息同步 |
| | | //分类加价系数 |
| | | |
| | | model.setCateRatePrice(baseCategory.getPriceRate()); |
| | | Goods goods = initGoodsPlatParam(user,model,param); |
| | | if(goods == null){ |
| | | continue; |
| | | } |
| | | goodsMapper.insert(goods); |
| | | //开始处理附件 |
| | | dealPlatMultifule(goods.getId(),user,model,multifileList); |
| | | //开始处理参数配置 |
| | | dealPlatGoodsParam(model,goods,user,goodsParamList); |
| | | } |
| | | goodsMapper.insert(goods); |
| | | //开始处理附件 |
| | | dealPlatMultifule(goods.getId(),user,model); |
| | | //开始处理参数配置 |
| | | dealPlatGoodsParam(model,goods,user); |
| | | if(multifileList.size()>0){ |
| | | multifileMapper.insertBatch(multifileList); |
| | | } |
| | | if(goodsParamList.size()>0){ |
| | | goodsParamMapper.insertBatch(goodsParamList); |
| | | } |
| | | cateParamSelectService.dealCateParamSelect(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisTemplate.opsForValue().set(user.getCompanyId()+Constants.OPEN_SYNC_SWITCH,false); |
| | | } |
| | | |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user) { |
| | | private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user,List<GoodsParam> paramList) { |
| | | BaseGoodsParam baseGoodsParam = new BaseGoodsParam(); |
| | | baseGoodsParam.setGoodsId(model.getId()); |
| | | baseGoodsParam.setIsdeleted(Constants.ZERO); |
| | |
| | | .eq("ISDELETED",Constants.ZERO) |
| | | .eq("STATUS",Constants.ZERO) |
| | | .last(" limit 1 ")); |
| | | if(Objects.isNull(cateParam)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"企业分类数据同步异常请联系管理员"); |
| | | } |
| | | // if(Objects.isNull(cateParam)){ |
| | | // throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"企业分类数据同步异常请联系管理员"); |
| | | // } |
| | | GoodsParam goodsParam = new GoodsParam(); |
| | | goodsParam.setCreator(user.getId()); |
| | | goodsParam.setCreateDate(new Date()); |
| | |
| | | goodsParam.setGoodsId(goods.getId()); |
| | | goodsParam.setVal(bgParam.getVal()); |
| | | goodsParam.setName(bgParam.getName()); |
| | | goodsParam.setPramaId(cateParam.getId()); |
| | | goodsParamMapper.insert(goodsParam); |
| | | |
| | | //存储 cate_param_select 查询是否已存在 |
| | | if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>() |
| | | .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){ |
| | | CateParamSelect cateParamSelect = new CateParamSelect(); |
| | | cateParamSelect.setCreator(user.getId()); |
| | | cateParamSelect.setCreateDate(new Date()); |
| | | cateParamSelect.setName(goodsParam.getVal()); |
| | | cateParamSelect.setIsdeleted(Constants.ZERO); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelect.setParamId(goodsParam.getPramaId()); |
| | | cateParamSelect.setCategoryId(goods.getCategoryId()); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelectMapper.insert(cateParamSelect); |
| | | }; |
| | | |
| | | goodsParam.setPramaId(Objects.isNull(cateParam)?null:cateParam.getId()); |
| | | paramList.add(goodsParam); |
| | | // goodsParamMapper.insert(goodsParam); |
| | | } |
| | | } |
| | | } |
| | |
| | | Goods goods = new Goods(); |
| | | goods.setIsdeleted(Constants.ZERO); |
| | | goods.setGoodsId(model.getId()); |
| | | goods.setCompanyId(user.getCompanyId()); |
| | | if(goodsMapper.selectCount(new QueryWrapper<>(goods))>0){ |
| | | //如果已经同步过,跳过此次同步 |
| | | return null; |
| | |
| | | /** |
| | | * 开始处理平台商品关联附件,复制一套到企业商品上 |
| | | */ |
| | | private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model) { |
| | | 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++) { |
| | |
| | | multifile.setName(multifile.getName()); |
| | | multifile.setSortnum(multifile.getSortnum()); |
| | | multifile.setCompanyId(user.getCompanyId()); |
| | | multifileMapper.insert(multifile); |
| | | fileList.add(multifile); |
| | | // multifileMapper.insert(multifile); |
| | | } |
| | | } |
| | | } |
| | |
| | | if(Constants.equalsInteger(Constants.ONE, param.getType())){ |
| | | for(PlatGoodsParam p: param.getGoodsParamList()){ |
| | | if(Constants.equalsInteger(model.getId(),p.getGoodsId())){ |
| | | return p.getPrice(); |
| | | return p.getPrice().setScale(0,BigDecimal.ROUND_CEILING); |
| | | } |
| | | } |
| | | throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"数据异常请刷新重试"); |
| | | } |
| | | //如果没有配置入手价,安装加价系数来计算 |
| | | if(model.getCateRatePrice()==null){ |
| | | model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate()); |
| | | } |
| | | //返回 |
| | | return Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate()); |
| | | //返回 .multiply(model.getCateRatePrice()) |
| | | 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); |
| | |
| | | multifile.setObjId(goods.getId()); |
| | | multifile.setType(Constants.ZERO); |
| | | multifile.setObjType(Constants.ZERO); |
| | | multifile.setCompanyId(goods.getCompanyId()); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | | } |
| | |
| | | goodsParam.setSortnum(i+Constants.ONE); |
| | | goodsParam.setGoodsId(goods.getId()); |
| | | goodsParamMapper.insert(goodsParam); |
| | | //存储 cate_param_select 查询是否已存在 |
| | | if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>() |
| | | .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){ |
| | | CateParamSelect cateParamSelect = new CateParamSelect(); |
| | | cateParamSelect.setCreator(user.getId()); |
| | | cateParamSelect.setCreateDate(new Date()); |
| | | cateParamSelect.setName(goodsParam.getVal()); |
| | | cateParamSelect.setIsdeleted(Constants.ZERO); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelect.setParamId(goodsParam.getPramaId()); |
| | | cateParamSelect.setCategoryId(goods.getCategoryId()); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelectMapper.insert(cateParamSelect); |
| | | }; |
| | | } |
| | | } |
| | | return goods.getId(); |
| | |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | goodsMapper.deleteBatchIds(ids); |
| | | for(Integer id : ids){ |
| | | deleteById(id); |
| | | } |
| | | // goodsMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | | @Override |
| | |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前登录用户类别错误,无法进行该操作"); |
| | | } |
| | | if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId()).eq("ISDELETED",Constants.ZERO).ne("id",goods.getId()).eq("name",goods.getName()))>0){ |
| | | if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId()) |
| | | .eq("ISDELETED",Constants.ZERO).ne("id",goods.getId()).eq("name",goods.getName()))>0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+goods.getName()+"】已存在"); |
| | | }; |
| | | goods.setStatus(Constants.ZERO); |
| | |
| | | goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName())); |
| | | goodsMapper.updateById(goods); |
| | | |
| | | multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",goods.getId())); |
| | | multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",goods.getId()) |
| | | .eq("OBJ_TYPE",0).eq("COMPANY_ID",user.getCompanyId())); |
| | | List<Multifile> multifileList = goods.getMultifileList(); |
| | | if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ |
| | | for (int i = 0; i < multifileList.size(); i++) { |
| | |
| | | multifile.setSortnum(i+Constants.ONE); |
| | | multifile.setObjId(goods.getId()); |
| | | multifile.setType(Constants.ZERO); |
| | | multifile.setCompanyId(goods.getCompanyId()); |
| | | multifile.setObjType(Constants.ZERO); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | |
| | | goodsParam.setGoodsId(goods.getId()); |
| | | goodsParamMapper.insert(goodsParam); |
| | | //存储 cate_param_select 查询是否已存在 |
| | | if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>() |
| | | .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){ |
| | | CateParamSelect cateParamSelect = new CateParamSelect(); |
| | | cateParamSelect.setCreator(user.getId()); |
| | | cateParamSelect.setCreateDate(new Date()); |
| | | cateParamSelect.setName(goodsParam.getVal()); |
| | | cateParamSelect.setIsdeleted(Constants.ZERO); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelect.setParamId(goodsParam.getPramaId()); |
| | | cateParamSelect.setCategoryId(goods.getCategoryId()); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelectMapper.insert(cateParamSelect); |
| | | }; |
| | | // if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>() |
| | | // .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){ |
| | | // CateParamSelect cateParamSelect = new CateParamSelect(); |
| | | // cateParamSelect.setCreator(user.getId()); |
| | | // cateParamSelect.setCreateDate(new Date()); |
| | | // cateParamSelect.setName(goodsParam.getVal()); |
| | | // cateParamSelect.setIsdeleted(Constants.ZERO); |
| | | // cateParamSelect.setStatus(Constants.ZERO); |
| | | // cateParamSelect.setParamId(goodsParam.getPramaId()); |
| | | // cateParamSelect.setCategoryId(goods.getCategoryId()); |
| | | // cateParamSelect.setStatus(Constants.ZERO); |
| | | // cateParamSelectMapper.insert(cateParamSelect); |
| | | // }; |
| | | } |
| | | } |
| | | } |
| | |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | //拉式商品 且 上架时,需要限制 平台商品是否已下架 |
| | | if(dbGoods.getType().equals(Constants.goodsType.PULL)&&goods.getStatus().equals(Constants.ZERO)){ |
| | | if(dbGoods.getType().equals(Constants.goodsType.PULL.getValue())&&goods.getStatus().equals(Constants.ZERO)){ |
| | | BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId()); |
| | | if(Objects.isNull(baseGoods)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到平台商品信息"); |
| | |
| | | continue; |
| | | } |
| | | //拉式商品 且 上架时,需要限制 平台商品是否已下架 |
| | | if(dbGoods.getType().equals(Constants.goodsType.PULL)&&batchDisableDTO.getStatus().equals(Constants.ZERO)){ |
| | | if(dbGoods.getType().equals(Constants.goodsType.PULL.getValue())&&batchDisableDTO.getStatus().equals(Constants.ZERO)){ |
| | | BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId()); |
| | | if(Objects.isNull(baseGoods)||!baseGoods.getStatus().equals(Constants.ZERO)){ |
| | | errNum++; |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | queryWrapper.leftJoin(Category.class, Category::getId, Goods::getCategoryId); |
| | | queryWrapper.leftJoin(Brand.class, Brand::getId, Goods::getBrandId); |
| | | queryWrapper.eq(Goods::getStatus,Constants.ZERO); |
| | | queryWrapper.eq(Goods::getCompanyId, goods.getCompanyId()); |
| | | queryWrapper.eq(Goods::getIsdeleted,Constants.ZERO); |
| | | queryWrapper.like(StringUtils.isNotBlank(goods.getAttrFirstIds()),Goods::getAttrFirstIds,goods.getAttrFirstIds()); |
| | | queryWrapper.like(StringUtils.isNotBlank(goods.getAttrFirstNames()),Goods::getAttrFirstNames,goods.getAttrFirstNames()); |
| | |
| | | queryWrapper.between(!Objects.isNull(goods.getSPrice())&&!Objects.isNull(goods.getEPrice()), |
| | | 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 "))); |
| | | }); |
| | | List<Goods> goodsList = this.goodsMapper.selectListByCollection(goods); |
| | | // List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper); |
| | | if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){ |
| | | this.dealGoodsMsg(goodsList); |
| | | } |
| | | return goodsList; |
| | | } |
| | | |
| | |
| | | if (pageWrap.getModel().getStatus() != null) { |
| | | queryWrapper.eq(Goods::getStatus, pageWrap.getModel().getStatus()); |
| | | } |
| | | |
| | | if (pageWrap.getModel().getType() != null) { |
| | | queryWrapper.eq(Goods::getType, pageWrap.getModel().getType()); |
| | | } |
| | | if (pageWrap.getModel().getCategoryId() != null) { |
| | | queryWrapper.eq(Goods::getCategoryId, pageWrap.getModel().getCategoryId()); |
| | | } |
| | |
| | | goodsIPage.getRecords().forEach(i->{ |
| | | i.setPrefixUrl(prefixUrl); |
| | | if(i.getType().equals(Constants.ONE)){ |
| | | i.setBasePrice(i.getBasePrice().multiply(i.getBasePriceRate())); |
| | | i.setBasePrice(Constants.formatBigdecimal(i.getBasePrice()).multiply(Constants.formatBigdecimal(i.getBasePriceRate())).setScale(0,BigDecimal.ROUND_CEILING)); |
| | | } |
| | | |
| | | }); |
| | | return PageData.from(goodsIPage); |
| | | } |
| | |
| | | if(brand == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品品牌无效,请检查输入!"); |
| | | } |
| | | if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("ISDELETED",Constants.ZERO).eq("name",m.getName()))>0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+m.getName()+"】已存在"); |
| | | }; |
| | | if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId()).eq("ISDELETED",Constants.ZERO).eq("name",m.getName()))>0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"第【"+(num)+"】行【"+m.getName()+"】已存在"); |
| | | } |
| | | Goods newModel = new Goods(); |
| | | newModel.setRemark(m.getId()); |
| | | newModel.setCategoryId(cate.getId()); |
| | |
| | | //插入产品参数关联表 |
| | | goodsParamMapper.insert(gp); |
| | | //存储 cate_param_select 查询是否已存在 |
| | | if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>() |
| | | .eq("PARAM_ID",gp.getPramaId()).eq("NAME",gp.getName()))<=Constants.ZERO){ |
| | | CateParamSelect cateParamSelect = new CateParamSelect(); |
| | | cateParamSelect.setCreator(user.getId()); |
| | | cateParamSelect.setCreateDate(new Date()); |
| | | cateParamSelect.setName(gp.getVal()); |
| | | cateParamSelect.setIsdeleted(Constants.ZERO); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelect.setParamId(gp.getPramaId()); |
| | | cateParamSelect.setCategoryId(newModel.getCategoryId()); |
| | | cateParamSelect.setStatus(Constants.ZERO); |
| | | cateParamSelectMapper.insert(cateParamSelect); |
| | | }; |
| | | // if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>() |
| | | // .eq("PARAM_ID",gp.getPramaId()).eq("NAME",gp.getName()))<=Constants.ZERO){ |
| | | // CateParamSelect cateParamSelect = new CateParamSelect(); |
| | | // cateParamSelect.setCreator(user.getId()); |
| | | // cateParamSelect.setCreateDate(new Date()); |
| | | // cateParamSelect.setName(gp.getVal()); |
| | | // cateParamSelect.setIsdeleted(Constants.ZERO); |
| | | // cateParamSelect.setStatus(Constants.ZERO); |
| | | // cateParamSelect.setParamId(gp.getPramaId()); |
| | | // cateParamSelect.setCategoryId(newModel.getCategoryId()); |
| | | // cateParamSelect.setStatus(Constants.ZERO); |
| | | // cateParamSelectMapper.insert(cateParamSelect); |
| | | // }; |
| | | } |
| | | } |
| | | if(mulFiles !=null && mulFiles.size()>0){ |
| | | for(int i=0;i<mulFiles.size();i++){ |
| | | String s = mulFiles.get(i); |
| | | Multifile f = new Multifile(); |
| | | f.setObjType(Constants.ZERO); |
| | | f.setName(s); |
| | | f.setType(Constants.ZERO); |
| | | f.setObjId(newModel.getId()); |
| | | f.setCreateDate(newModel.getCreateDate()); |
| | | f.setCreator(newModel.getCreator()); |
| | | f.setIsdeleted(Constants.ZERO); |
| | | f.setSortnum(i); |
| | | f.setCompanyId(user.getCompanyId()); |
| | | f.setFileurl(s); |
| | | multifileMapper.insert(f); |
| | | } |
| | | } |
| | | num++; |
| | | } |
| | | return num; |
| | | |
| | | } |
| | | @Transactional(rollbackFor = {Exception.class, BusinessException.class}) |
| | | @Override |
| | | public Integer importBatchImg(MultipartFile file){ |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | ExcelImporter ie = null; |
| | | List<GoodsImport> dataList =null; |
| | | try { |
| | | ie = new ExcelImporter(file,0,0); |
| | | dataList = ie.getDataList(GoodsImport.class,null); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if(dataList == null || dataList.size() ==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!"); |
| | | } |
| | | |
| | | int num =1; |
| | | for(GoodsImport m: dataList){ |
| | | if( StringUtils.isBlank(m.getId()) ){ |
| | | continue; |
| | | } |
| | | Goods g = new Goods(); |
| | | g.setIsdeleted(Constants.ZERO); |
| | | g.setRemark(m.getId()); |
| | | g.setCompanyId(user.getCompanyId()); |
| | | //品类数据 |
| | | g = goodsMapper.selectOne(new QueryWrapper<>(g).last(" limit 1")); |
| | | if(g == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品不存在,请检查输入!"); |
| | | } |
| | | |
| | | Goods newModel = new Goods(); |
| | | newModel.setId(g.getId()); |
| | | newModel.setEditor(user.getId()); |
| | | newModel.setEditDate(new Date()); |
| | | |
| | | String[] params = StringUtils.defaultString(m.getParamStr(),"").split("\n"); |
| | | List<String> mulFiles = null; |
| | | String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode(); |
| | | |
| | | String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode() |
| | | + proDir + File.separator + user.getCompanyId(); |
| | | if(StringUtils.isNotBlank(path)){ |
| | | OssModel ossModel = baseDataService.initOssModel(); |
| | | File dir =new File(path+File.separator+newModel.getRemark()+File.separator); |
| | | if(dir!=null && dir.isDirectory()){ |
| | | File[] files = dir.listFiles(); |
| | | if(files!=null && files.length>0){ |
| | | for(File f:files){ |
| | | if(StringUtils.isBlank(newModel.getImgurl()) && isImgFile(f)){ |
| | | //取第一张图片作为列表图 |
| | | newModel.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f)); |
| | | } |
| | | if((mulFiles ==null || mulFiles.size() == 0) && f.isDirectory()){ |
| | | //如果是文件夹 |
| | | File[] fs = f.listFiles(); |
| | | if(fs!=null && fs.length>0){ |
| | | for(File mf : fs){ |
| | | if(isImgFile(mf)){ |
| | | if(mulFiles==null){ |
| | | mulFiles = new ArrayList<>(); |
| | | } |
| | | mulFiles.add(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),mf)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //查询商品信息 |
| | | goodsMapper.updateById(newModel); |
| | | if(mulFiles !=null && mulFiles.size()>0){ |
| | | multifileMapper.update(null,new UpdateWrapper<Multifile>().lambda() |
| | | .set(Multifile::getIsdeleted,Constants.ONE) |
| | | .eq(Multifile::getIsdeleted,Constants.ZERO) |
| | | .eq(Multifile::getObjId,g.getId()) |
| | | .eq(Multifile::getType,Constants.ZERO)); |
| | | for(int i=0;i<mulFiles.size();i++){ |
| | | String s = mulFiles.get(i); |
| | | Multifile f = new Multifile(); |
| | |
| | | .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.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.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; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void openSyncSwitch() { |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Boolean openSyncSwitch = (Boolean)redisTemplate.opsForValue().get(loginUserInfo.getCompanyId()+Constants.OPEN_SYNC_SWITCH); |
| | | if(openSyncSwitch!=null && openSyncSwitch ){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"数据同步中,请稍后刷新重试"); |
| | | } |
| | | redisTemplate.opsForValue().set(loginUserInfo.getCompanyId()+Constants.OPEN_SYNC_SWITCH,true); |
| | | } |
| | | } |
| | | |