| | |
| | | private UploadFileService uploadFileService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public Integer create(Goods goods) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | isCreateParamValid(goods, user); |
| | | |
| | | Date date =new Date(); |
| | | goods.setIsdeleted(Constants.ZERO); |
| | | goods.setCreateDate(new Date()); |
| | | goods.setCreateDate(date); |
| | | goods.setCreator(user.getId()); |
| | | goods.setEditDate(date); |
| | | goods.setEditor(user.getId()); |
| | | goods.setStatus(Constants.ONE); |
| | | goods.setIsrec(Constants.ZERO); |
| | | if(StringUtils.isNotBlank(goods.getLabels())){ |
| | | goods.setLabels( StringUtils.removeEnd( goods.getLabels().replace(",",","),",")); |
| | | } |
| | | goodsMapper.insert(goods); |
| | | dealBatchMultiFiles(goods, goods.getFileList(), user); |
| | | dealDefaultGoodsSku(goods); |
| | | dealBatchMultiFiles(goods, goods.getFileList(), user,false); |
| | | return goods.getId(); |
| | | } |
| | | private void dealDefaultGoodsSku(Goods goods) { |
| | | Date date = goods.getEditDate(); |
| | | Integer userId = goods.getEditor(); |
| | | Sku sku = new Sku(); |
| | | sku.setIsdeleted(Constants.ZERO); |
| | | sku.setCreateDate(date); |
| | | sku.setCreator(userId); |
| | | sku.setEditDate(date); |
| | | sku.setEditor(userId); |
| | | sku.setGoodsId(goods.getId()); |
| | | sku.setName("默认"); |
| | | sku.setSortnum(0); |
| | | skuMapper.insert(sku); |
| | | |
| | | public void dealBatchMultiFiles(Goods goods, List<Multifile> fileList, LoginUserInfo user) { |
| | | SkuAttr skuAttr = new SkuAttr(); |
| | | skuAttr.setIsdeleted(Constants.ZERO); |
| | | skuAttr.setCreateDate(date); |
| | | skuAttr.setCreator(userId); |
| | | skuAttr.setEditDate(date); |
| | | skuAttr.setEditor(userId); |
| | | skuAttr.setSkuId(sku.getId()); |
| | | skuAttr.setName("默认"); |
| | | skuAttr.setSortnum(0); |
| | | skuAttrMapper.insert(skuAttr); |
| | | |
| | | GoodsSku goodsSku = new GoodsSku(); |
| | | goodsSku.setIsdeleted(Constants.ZERO); |
| | | goodsSku.setCreateDate(date); |
| | | goodsSku.setCreator(userId); |
| | | goodsSku.setEditDate(date); |
| | | goodsSku.setEditor(userId); |
| | | goodsSku.setSkuId(sku.getId()); |
| | | goodsSku.setGoodsId(goods.getId()); |
| | | goodsSku.setName(goods.getName()); |
| | | goodsSku.setPrice(goods.getSkuPrice()); |
| | | goodsSku.setShowPrice(goods.getPrice()); |
| | | goodsSku.setStock(goods.getStockNum()); |
| | | goodsSku.setIntegralRate(goods.getDeductRata()); |
| | | goodsSku.setUnitName(goods.getUnitName()); |
| | | goodsSku.setWeight(goods.getWeight()); |
| | | goodsSku.setImgurl(goods.getImgurl()); |
| | | goodsSku.setStatus(goods.getStatus()); |
| | | goodsSkuMapper.insert(goodsSku); |
| | | |
| | | GoodsSkuAttr goodsSkuAttr = new GoodsSkuAttr(); |
| | | goodsSkuAttr.setIsdeleted(Constants.ZERO); |
| | | goodsSkuAttr.setCreateDate(date); |
| | | goodsSkuAttr.setCreator(userId); |
| | | goodsSkuAttr.setEditDate(date); |
| | | goodsSkuAttr.setEditor(userId); |
| | | goodsSkuAttr.setSkuId(sku.getId()); |
| | | goodsSkuAttr.setGoodsSkuId(goodsSku.getId()); |
| | | goodsSkuAttr.setSkuAttrId(skuAttr.getId()); |
| | | goodsSkuAttrMapper.insert(goodsSkuAttr); |
| | | } |
| | | |
| | | public void dealBatchMultiFiles(Goods goods, List<Multifile> fileList, LoginUserInfo user,boolean update) { |
| | | Date today = new Date(); |
| | | Multifile del = new Multifile(); |
| | | del.setObjId(goods.getId()); |
| | | multifileMapper.delete(new QueryWrapper<>(del)); |
| | | fileList.stream().forEach(s -> { |
| | | s.setIsdeleted(Constants.ZERO); |
| | | s.setCreator(user.getId()); |
| | | s.setCreateDate(today); |
| | | s.setObjId(goods.getId()); |
| | | s.setType(Constants.ZERO); |
| | | s.setObjType(Constants.MultiFile.PLATFORM_GOOD_ROTATION.getKey()); |
| | | multifileMapper.insert(s); |
| | | /* if(Constants.equalsInteger(goods.getType(),Constants.ZERO)){ |
| | | //平台商城 |
| | | //清空原有的 |
| | | if(update){ |
| | | multifileMapper.delete(new UpdateWrapper<Multifile>().lambda() |
| | | .eq(Multifile::getIsdeleted,Constants.ZERO) |
| | | .eq(Multifile::getObjId,goods.getId())); |
| | | } |
| | | if(fileList!=null && fileList.size()>0){ |
| | | List<Multifile> multifileList = new ArrayList<>(); |
| | | fileList.stream().forEach(s -> { |
| | | if(StringUtils.isNotBlank(s.getFileurl())){ |
| | | s.setIsdeleted(Constants.ZERO); |
| | | s.setCreator(user.getId()); |
| | | s.setCreateDate(today); |
| | | s.setObjId(goods.getId()); |
| | | s.setType(Constants.ZERO); |
| | | s.setObjType(Constants.MultiFile.PLATFORM_GOOD_ROTATION.getKey()); |
| | | multifileList.add(s); |
| | | } |
| | | }); |
| | | if(multifileList.size()>0){ |
| | | multifileMapper.insert(multifileList); |
| | | } |
| | | if(Constants.equalsInteger(goods.getType(),Constants.ONE)){ |
| | | //咖豆商城 |
| | | } |
| | | |
| | | if(Constants.equalsInteger(goods.getType(),Constants.TWO)){ |
| | | //咖啡计划商品 |
| | | }*/ |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | public void isCreateParamValid(Goods goods, LoginUserInfo user) { |
| | | //平台商城 |
| | | if (StringUtils.isBlank(goods.getName()) |
| | | || goods.getCategoryId() == null |
| | | || goods.getBrandList() == null |
| | | || goods.getBrandList().size() == 0 |
| | | || goods.getWeight() == null |
| | | || goods.getPrice() == null |
| | | || goods.getSkuPrice() == null |
| | | || StringUtils.isBlank(goods.getImgurl()) |
| | | || org.apache.commons.collections.CollectionUtils.isEmpty(goods.getFileList()) |
| | | ) { |
| | | || org.apache.commons.collections.CollectionUtils.isEmpty(goods.getFileList())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), ResponseStatus.BAD_REQUEST.getMessage()); |
| | | } |
| | | |
| | | //查询分类 |
| | | Labels cate = labelsMapper.selectById(goods.getCategoryId()); |
| | | if(cate == null || Constants.equalsInteger(cate.getIsdeleted(),Constants.ONE) |
| | | ||! Constants.equalsInteger(cate.getType(),Constants.LabelsType.GOODSTYPE.getKey())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,分类信息不存在"); |
| | | } |
| | | if(goods.getBrandId()!=null){ |
| | | Labels brand = labelsMapper.selectById(goods.getCategoryId()); |
| | | if(brand == null || Constants.equalsInteger(brand.getIsdeleted(),Constants.ONE) |
| | | ||! Constants.equalsInteger(brand.getType(),Constants.LabelsType.GOODSBRAND.getKey())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,品牌信息不存在"); |
| | | } |
| | | } |
| | | List<Integer> bIds = new ArrayList<>(); |
| | | for(Labels b : goods.getBrandList()){ |
| | | bIds.add(b.getId()); |
| | | if(b.getChildIdList() == null || b.getChildIdList().size() ==0){ |
| | | bIds.addAll(b.getChildIdList()); |
| | | } |
| | | } |
| | | List<String> idsBrand = new ArrayList<>(); |
| | | List<String> idsSerial = new ArrayList<>(); |
| | | //查询全部适用品牌和系列数据 |
| | | List<Labels> allBrands = labelsMapper.selectList(new QueryWrapper<Labels>().lambda() |
| | | .in(Labels::getId,bIds) |
| | | .eq(Labels::getIsdeleted,Constants.ZERO) |
| | | ); |
| | | for(Labels b : goods.getBrandList()){ |
| | | Labels tb = findLabelFromListByid(allBrands,b.getId(),Constants.LabelsType.APPLICABLE_BRAND.getKey(),null); |
| | | if(tb == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请选择正确的适用品牌"); |
| | | } |
| | | idsBrand.add("["+b.getId()+"]"); |
| | | if(b.getChildIdList() == null || b.getChildIdList().size() ==0){ |
| | | for(Integer c :b.getChildIdList()){ |
| | | Labels cb = findLabelFromListByid(allBrands,b.getId(),Constants.LabelsType.SERIES_BRAND.getKey(),b.getId()); |
| | | if(cb == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,品牌【"+tb.getName() +"】下所属系列不正确"); |
| | | } |
| | | idsSerial.add("["+c+"]"); |
| | | } |
| | | } |
| | | } |
| | | goods.setBrandIds(String.join(",",idsBrand)); |
| | | if(idsSerial.size()>0){ |
| | | goods.setSerialIds(String.join(",",idsSerial)); |
| | | } |
| | | |
| | | } |
| | | |
| | | private Labels findLabelFromListByid(List<Labels> allBrands, Integer id, int type,Integer parentId) { |
| | | if(allBrands == null || allBrands.size() ==0){ |
| | | return null; |
| | | } |
| | | for(Labels labels:allBrands){ |
| | | if(!Constants.equalsInteger(id,labels.getId())){ |
| | | return null; |
| | | } |
| | | if(!Constants.equalsInteger(type,labels.getType())){ |
| | | return null; |
| | | } |
| | | if(parentId !=null && !Constants.equalsInteger(parentId,labels.getParentId())){ |
| | | return null; |
| | | } |
| | | return labels; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public void updateById(Goods goods) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Goods query=goodsMapper.selectById(goods.getId()); |
| | |
| | | goods.setLabels( StringUtils.removeEnd( goods.getLabels().replace(",",","),",")); |
| | | } |
| | | goodsMapper.updateById(goods); |
| | | dealBatchMultiFiles(goods, goods.getFileList(), user); |
| | | //清空原有的sku数据 |
| | | skuMapper.update(null,new UpdateWrapper<Sku>().lambda() |
| | | .set(Sku::getIsdeleted,Constants.ONE) |
| | | .eq(Sku::getIsdeleted,Constants.ZERO) |
| | | .eq(Sku::getGoodsId,goods.getSkuId())); |
| | | goodsSkuMapper.update(null,new UpdateWrapper<GoodsSku>().lambda() |
| | | .set(GoodsSku::getIsdeleted,Constants.ONE) |
| | | .eq(GoodsSku::getIsdeleted,Constants.ZERO) |
| | | .eq(GoodsSku::getGoodsId,goods.getSkuId())); |
| | | dealDefaultGoodsSku(goods);//新建sku信息 |
| | | dealBatchMultiFiles(goods, goods.getFileList(), user,true); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | queryWrapper.eq(Goods::getId,id); |
| | | queryWrapper.selectAll(Goods.class); |
| | | queryWrapper.select("(select name from labels where id=t1.parent_id) as categoryName"); |
| | | queryWrapper.selectAs(Labels::getName ,Goods::getBrandName); |
| | | queryWrapper.select("t1.name",Goods::getCategoryName); |
| | | queryWrapper.select("t2.name" ,Goods::getBrandName); |
| | | queryWrapper.leftJoin(Labels.class,Labels::getId,Goods::getCategoryId); |
| | | queryWrapper.leftJoin(Labels.class,Labels::getId,Goods::getBrandId); |
| | | Goods goods=goodsAdminJoinMapper.selectJoinOne(Goods.class,queryWrapper); |
| | | |
| | | if(goods == null){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | Multifile find = new Multifile(); |
| | | find.setObjId(id); |
| | | find.setIsdeleted(Constants.ZERO); |
| | |
| | | queryGoodsSku.setIsdeleted(Constants.ZERO); |
| | | List<GoodsSku> goodsSkuList=goodsSkuMapper.selectList(new QueryWrapper<>(queryGoodsSku)); |
| | | goods.setGoodsSkuList(goodsSkuList); |
| | | if(goodsSkuList.size()>0){ |
| | | //默认sku信息 |
| | | GoodsSku goodsSku = goodsSkuList.get(0); |
| | | goods.setSkuPrice(goodsSku.getPrice()); |
| | | goods.setWeight(goodsSku.getWeight()); |
| | | goods.setStockNum(goodsSku.getStock()); |
| | | goods.setUnitName(goodsSku.getUnitName()); |
| | | } |
| | | |
| | | initGoodsApplyBrandAndSerial(goods); |
| | | return goods; |
| | | } |
| | | |
| | | private void initGoodsApplyBrandAndSerial(Goods goods) { |
| | | List<Integer> idbrandList = getNumIdByIdsString(goods.getBrandIds()); |
| | | List<Integer> idSerailList = getNumIdByIdsString(goods.getSerialIds()); |
| | | if(idbrandList.size()>0){ |
| | | List<Labels> brandList = new ArrayList<>(); |
| | | List<Integer> allIds = new ArrayList<>(); |
| | | allIds.addAll(idbrandList); |
| | | if(idSerailList.size()>0){ |
| | | allIds.addAll(idSerailList); |
| | | } |
| | | List<Labels> allBrands = labelsMapper.selectList(new QueryWrapper<Labels>().lambda() |
| | | .in(Labels::getId,allIds) |
| | | .eq(Labels::getIsdeleted,Constants.ZERO) |
| | | ); |
| | | for(Integer b : idbrandList){ |
| | | Labels tb = findLabelFromListByid(allBrands,b,Constants.LabelsType.APPLICABLE_BRAND.getKey(),null); |
| | | if(tb != null){ |
| | | brandList.add(tb); |
| | | tb.setChildIdList(new ArrayList<>()); |
| | | tb.setChildList(new ArrayList<>()); |
| | | for(Integer c : idSerailList) { |
| | | Labels cb = findLabelFromListByid(allBrands, c, Constants.LabelsType.SERIES_BRAND.getKey(), b); |
| | | if (cb != null) { |
| | | tb.getChildIdList().add(c); |
| | | tb.getChildList().add(cb); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private List<Integer> getNumIdByIdsString(String brandIds) { |
| | | List<Integer> idbrandList = new ArrayList<>(); |
| | | if(StringUtils.isNotBlank(brandIds)){ |
| | | String[] idsBrand = brandIds.replace("[","").replace("]", "").split(","); |
| | | try { |
| | | for(String s :idsBrand){ |
| | | idbrandList.add(Integer.parseInt(s)); |
| | | } |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | return idbrandList; |
| | | } |
| | | |
| | | |
| | |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | |
| | | queryWrapper.selectAll(Goods.class); |
| | | queryWrapper.selectAs(Labels::getName, Goods::getCategoryName); |
| | | queryWrapper.select("ls.name as parentName "); |
| | | |
| | | queryWrapper.select("t1.name",Goods::getCategoryName); |
| | | queryWrapper.select("t2.name" ,Goods::getBrandName); |
| | | queryWrapper.select("t3.name" ,Goods::getParentName); |
| | | queryWrapper.leftJoin(Labels.class,Labels::getId,Goods::getCategoryId); |
| | | queryWrapper.leftJoin(Labels.class,Labels::getId,Goods::getBrandId); |
| | | queryWrapper.leftJoin(Labels.class,Labels::getId,Goods::getParentCategoryId); |
| | | //库存量 |
| | | queryWrapper.select("(select sum(STOCK) from goods_sku where ISDELETED=0 and GOODS_ID=t.id) as stockNum "); |
| | | //实际销量 |
| | |
| | | " INNER JOIN goodsorder go on go.id=gd.ORDER_ID and go.ISDELETED=0 and go.PAY_STATUS=1 " + |
| | | " where gs.GOODS_ID=t.id) as salesVolume "); |
| | | |
| | | queryWrapper.leftJoin(Labels.class, Labels::getId, Goods::getCategoryId); |
| | | queryWrapper.leftJoin("labels ls on ls.id=t.PARENT_CATEGORY_ID"); |
| | | |
| | | if (Constants.equalsInteger(pageWrap.getModel().getTabStatus(), Constants.TWO)) { |
| | | //已售罄 |
| | | queryWrapper.exists("select gs.STOCK from goods_sku gs " + |
| | | " INNER JOIN goods g on g.id=gs.GOODS_ID " + |
| | | " where gs.STOCK<=0 and gs.ISDELETED=0 and g.id=t.id "); |
| | | } |
| | | |
| | | queryWrapper.eq(!Constants.equalsInteger(pageWrap.getModel().getTabStatus(), 3), Goods::getIsdeleted, Constants.ZERO); |
| | | queryWrapper.eq(Constants.equalsInteger(pageWrap.getModel().getTabStatus(), 3), Goods::getIsdeleted, Constants.ONE); |
| | | |
| | |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | | Multifile multifile=new Multifile(); |
| | | |
| | | String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_FILE).getCode(); |
| | | for (Goods model : list) { |
| | | multifile.setIsdeleted(Constants.ZERO); |
| | | multifile.setObjId(model.getId()); |
| | | List<Multifile> fileList=multifileMapper.selectList(new QueryWrapper<>(multifile)); |
| | | for(Multifile file:fileList){ |
| | | if(StringUtils.isNotBlank(file.getFileurl())){ |
| | | file.setFileFullUrl(path+file.getFileurl()); |
| | | } |
| | | } |
| | | model.setFileList(fileList); |
| | | model.setResourcePath(path); |
| | | |
| | | for (Goods goods : list) { |
| | | goods.setResourcePath(path); |
| | | //查询sku |
| | | MPJLambdaWrapper<GoodsSku> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.eq(GoodsSku::getIsdeleted,Constants.ZERO); |
| | | queryWrapper.eq(GoodsSku::getGoodsId,model.getId()); |
| | | List<GoodsSku> gsList=goodsSkuMapper.selectList(queryWrapper); |
| | | for(GoodsSku sd:gsList){ |
| | | if(StringUtils.isNotBlank(sd.getImgurl())){ |
| | | sd.setImgurl(path+sd.getImgurl()); |
| | | } |
| | | } |
| | | model.setGoodsSkuList(gsList); |
| | | MPJLambdaWrapper<GoodsSku> queryWrapper = new MPJLambdaWrapper<GoodsSku>() |
| | | .eq(GoodsSku::getIsdeleted,Constants.ZERO) |
| | | .last("limit 1") |
| | | .eq(GoodsSku::getGoodsId,goods.getId()); |
| | | GoodsSku goodsSku = goodsSkuMapper.selectOne(queryWrapper); |
| | | goods.setGoodsSkuList(new ArrayList<>()); |
| | | if(goodsSku !=null){ |
| | | goods.getGoodsSkuList().add(goodsSku); |
| | | //默认sku信息 |
| | | goods.setSkuPrice(goodsSku.getPrice()); |
| | | goods.setWeight(goodsSku.getWeight()); |
| | | goods.setStockNum(goodsSku.getStock()); |
| | | goods.setUnitName(goodsSku.getUnitName()); |
| | | } |
| | | } |
| | | } |
| | | |