| | |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.business.model.dto.GoodCreatePlatRequest; |
| | | import com.doumee.dao.business.model.dto.GoodsRequest; |
| | | import com.doumee.dao.business.model.dto.PlatGoodsParam; |
| | | import com.doumee.service.business.GoodsService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.Charset; |
| | |
| | | |
| | | @Autowired |
| | | private GoodsMapper goodsMapper; |
| | | @Autowired |
| | | private BaseGoodsMapper baseGoodsMapper; |
| | | @Autowired |
| | | private BaseGoodsParamMapper baseGoodsParamMapper; |
| | | @Autowired |
| | | private CategoryMapper categoryMapper; |
| | | @Autowired |
| | |
| | | || param.getGoodsParamList().size()==0))){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Goods goods = new Goods(); |
| | | |
| | | if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("ISDELETED",Constants.ZERO).eq("name",goods.getName()))>0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+goods.getName()+"】已存在"); |
| | | Category category = categoryMapper.selectById(param.getCategoryId()); |
| | | if(category ==null ||Constants.equalsInteger(category.getIsdeleted(), Constants.ONE) ||Constants.equalsInteger(category.getCompanyId(), user.getCompanyId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,类别信息不正确,请刷新重试!"); |
| | | } |
| | | if(category.getPlatCateId() == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请前往【类别管理】先关联平台类别!"); |
| | | } |
| | | BaseGoods bp = new BaseGoods(); |
| | | bp.setCategoryId(category.getPlatCateId()); |
| | | bp.setIsdeleted(Constants.ZERO); |
| | | List<BaseGoods> goodsList = new ArrayList<>(); |
| | | List<Integer> ids = null; |
| | | if(Constants.equalsInteger(Constants.ONE, param.getType())){ |
| | | //如果选择部分商品 |
| | | for(PlatGoodsParam p : param.getGoodsParamList()){ |
| | | if(p.getGoodsId() == null || p.getPrice() == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请正确选择平台商品并配置入手价!"); |
| | | } |
| | | ids.add(p.getGoodsId()); |
| | | } |
| | | } |
| | | goodsList = baseGoodsMapper.selectList(new QueryWrapper<>(bp).lambda().in((ids!=null && ids.size()>0),BaseGoods::getId,ids)); |
| | | if(Constants.equalsInteger(Constants.ONE, param.getType()) || goodsList==null || ids.size()!=goodsList.size()){ |
| | | // 如果选择平台商品和查询结果对不上,提示错误 |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请正确选择平台商品!"); |
| | | } |
| | | for(BaseGoods model : goodsList){ |
| | | //遍历平台商品信息,进行商品信息同步 |
| | | Goods goods = initGoodsPlatParam(user,model,param); |
| | | if(goods == null){ |
| | | continue; |
| | | } |
| | | goodsMapper.insert(goods); |
| | | //开始处理附件 |
| | | dealPlatMultifule(goods.getId(),user,model); |
| | | //开始处理参数配置 |
| | | dealPlatGoodsParam(model,goods,user); |
| | | } |
| | | |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user) { |
| | | BaseGoodsParam baseGoodsParam = new BaseGoodsParam(); |
| | | baseGoodsParam.setGoodsId(model.getId()); |
| | | baseGoodsParam.setIsdeleted(Constants.ZERO); |
| | | List<BaseGoodsParam> goodsParamList = baseGoodsParamMapper.selectList(new QueryWrapper<>(baseGoodsParam)); |
| | | if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){ |
| | | for (int i = 0; i < goodsParamList.size(); i++) { |
| | | BaseGoodsParam bgParam = goodsParamList.get(i); |
| | | GoodsParam goodsParam = new GoodsParam(); |
| | | goodsParam.setCreator(user.getId()); |
| | | goodsParam.setCreateDate(new Date()); |
| | | goodsParam.setIsdeleted(Constants.ZERO); |
| | | goodsParam.setSortnum(i+Constants.ONE); |
| | | goodsParam.setStatus(Constants.ZERO); |
| | | goodsParam.setGoodsId(goods.getId()); |
| | | goodsParam.setVal(bgParam.getVal()); |
| | | goodsParam.setName(bgParam.getName()); |
| | | goodsParamMapper.insert(goodsParam); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private Goods initGoodsPlatParam(LoginUserInfo user, BaseGoods model, GoodCreatePlatRequest param) { |
| | | Goods goods = new Goods(); |
| | | goods.setIsdeleted(Constants.ZERO); |
| | | goods.setGoodsId(model.getId()); |
| | | if(goodsMapper.selectCount(new QueryWrapper<>(goods))>0){ |
| | | //如果已经同步过,跳过此次同步 |
| | | return null; |
| | | } |
| | | goods.setType(Constants.ONE); |
| | | goods.setStatus(Constants.ZERO); |
| | | goods.setCreateDate(new Date()); |
| | | goods.setCreator(user.getId()); |
| | |
| | | //处理拼音问题 |
| | | goods.setPinyin(PinYinUtil.getFullSpell(goods.getName())); |
| | | goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName())); |
| | | goodsMapper.insert(goods); |
| | | goods.setName(model.getName()); |
| | | goods.setCategoryId(param.getCategoryId()); |
| | | //获取入手价格 |
| | | goods.setPrice(getPriceFromParam(model,param)); |
| | | goods.setZdPrice(model.getZdPrice()); |
| | | goods.setRemark(model.getRemark()); |
| | | goods.setImgurl(model.getImgurl()); |
| | | goods.setBrandId(model.getBrandId()); |
| | | return goods; |
| | | } |
| | | |
| | | List<Multifile> multifileList = goods.getMultifileList(); |
| | | /** |
| | | * 开始处理平台商品关联附件,复制一套到企业商品上 |
| | | */ |
| | | private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model) { |
| | | Multifile f = new Multifile(); |
| | | f.setObjId(model.getId()); |
| | | f.setIsdeleted(Constants.ZERO); |
| | | 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 multifile = multifileList.get(i); |
| | |
| | | multifile.setCreateDate(new Date()); |
| | | multifile.setIsdeleted(Constants.ZERO); |
| | | multifile.setSortnum(i+Constants.ONE); |
| | | multifile.setObjId(goods.getId()); |
| | | multifile.setObjId(id); |
| | | multifile.setType(Constants.ZERO); |
| | | multifile.setObjType(Constants.ZERO); |
| | | multifile.setFileurl(multifile.getFileurl()); |
| | | multifile.setName(multifile.getName()); |
| | | multifile.setSortnum(multifile.getSortnum()); |
| | | multifile.setCompanyId(user.getCompanyId()); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | | } |
| | | List<GoodsParam> goodsParamList = goods.getGoodsParamList(); |
| | | if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){ |
| | | for (int i = 0; i < goodsParamList.size(); i++) { |
| | | GoodsParam goodsParam = goodsParamList.get(i); |
| | | goodsParam.setCreator(user.getId()); |
| | | goodsParam.setCreateDate(new Date()); |
| | | goodsParam.setIsdeleted(Constants.ZERO); |
| | | goodsParam.setSortnum(i+Constants.ONE); |
| | | goodsParam.setStatus(Constants.ZERO); |
| | | goodsParam.setGoodsId(goods.getId()); |
| | | goodsParamMapper.insert(goodsParam); |
| | | } |
| | | |
| | | private BigDecimal getPriceFromParam(BaseGoods model, GoodCreatePlatRequest param) { |
| | | if(Constants.equalsInteger(Constants.ONE, param.getType())){ |
| | | for(PlatGoodsParam p: param.getGoodsParamList()){ |
| | | if(Constants.equalsInteger(model.getId(),p.getGoodsId())){ |
| | | return p.getPrice(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return goods.getId(); |
| | | //如果没有配置入手价,安装加价系数来计算 |
| | | if(model.getCateRatePrice()==null){ |
| | | model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate()); |
| | | } |
| | | //返回 |
| | | return Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate()); |
| | | } |
| | | |
| | | @Override |