| | |
| | | import io.swagger.models.auth.In; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.bouncycastle.jcajce.provider.asymmetric.GOST; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | @Autowired |
| | | private GoodsMapper goodsMapper; |
| | | @Autowired |
| | | private ShopGoodsRelationMapper shopGoodsRelationMapper; |
| | | |
| | | |
| | | |
| | |
| | | @Autowired |
| | | private MultifileService multifileService; |
| | | |
| | | @Autowired |
| | | private CollectMapper collectMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private GoodsAdminJoinMapper goodsAdminJoinMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private ShopMapper shopMapper; |
| | | |
| | | @Autowired |
| | | private GoodsSkuAttrJoinMapper goodsSkuAttrJoinMapper; |
| | |
| | | || goods.getDeductRata() == null |
| | | || goods.getPrice() == null |
| | | || goods.getSkuPrice() == null |
| | | || StringUtils.isBlank(goods.getImgurl()) |
| | | || org.apache.commons.collections.CollectionUtils.isEmpty(goods.getFileList())) { |
| | | // || StringUtils.isBlank(goods.getImgurl()) |
| | | // || org.apache.commons.collections.CollectionUtils.isEmpty(goods.getFileList()) |
| | | ) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), ResponseStatus.BAD_REQUEST.getMessage()); |
| | | } |
| | | |
| | |
| | | goods.setEditor(user.getId()); |
| | | goods.setId(id); |
| | | goodsMapper.updateById(goods); |
| | | //删除供货价 |
| | | shopGoodsRelationMapper.delete(new UpdateWrapper<ShopGoodsRelation>().lambda().eq(ShopGoodsRelation::getGoodsId,id)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void updateStatusById(List<Goods> list) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | |
| | | |
| | | |
| | | for(Goods model:list){ |
| | | if(Constants.equalsInteger(model.getStatus(),Constants.ZERO)){ |
| | | MPJLambdaWrapper<Goods> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(Goods.class); |
| | | queryWrapper.innerJoin(GoodsSku.class,GoodsSku::getGoodsId,Goods::getId); |
| | | queryWrapper.eq(GoodsSku::getIsdeleted,Constants.ZERO); |
| | | queryWrapper.eq(Goods::getId,model.getId()); |
| | | List<Goods> query= goodsAdminJoinMapper.selectJoinList(Goods.class,queryWrapper); |
| | | if(query==null||query.size()<=0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), model.getName()+":商品未配置SKU,无法上架"); |
| | | } |
| | | } |
| | | Goods update=new Goods(); |
| | | update.setEditor(user.getId()); |
| | | update.setEditDate(new Date()); |
| | | update.setStatus(model.getStatus()); |
| | | update.setId(model.getId()); |
| | | goodsMapper.updateById(model); |
| | | if(list == null || list.size()==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | List<Integer> idList = new ArrayList<>(); |
| | | for(Goods model:list){ |
| | | idList.add(model.getId() ); |
| | | } |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if(Constants.formatIntegerNum(list.get(0).getStatus()) == Constants.ONE){ |
| | | //如果是批量下架 |
| | | goodsMapper.update(null,new UpdateWrapper<Goods>().lambda() |
| | | .set(Goods::getEditDate,new Date() ) |
| | | .set(Goods::getEditor,user.getId()) |
| | | .set(Goods::getStatus,Constants.ONE ) |
| | | .in(Goods::getId,idList)); |
| | | return; |
| | | } |
| | | long shopNum = shopMapper.selectCount(new QueryWrapper<Shop>().lambda() |
| | | .eq(Shop::getIsdeleted,Constants.ZERO) |
| | | .eq(Shop::getStatus,Constants.ZERO)); |
| | | MPJLambdaWrapper<Goods> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(Goods.class); |
| | | queryWrapper.select("(select count(s.id) from shop_goods_relation s " + |
| | | "left join shop g on s.SHOP_ID =g.id " + |
| | | "where g.status=0 and s.ISDELETED=0 and s.GOODS_ID=t.id) as pricedShopNum "); |
| | | queryWrapper.eq(GoodsSku::getIsdeleted,Constants.ZERO); |
| | | queryWrapper.in(Goods::getId,idList); |
| | | List<Goods> goodsList= goodsAdminJoinMapper.selectJoinList(Goods.class,queryWrapper); |
| | | if(goodsList==null || goodsList.size() == 0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "商品信息查询无效 "); |
| | | } |
| | | //查询全部sku信息 |
| | | List<GoodsSku> goodsSkuList=goodsSkuMapper.selectList(new QueryWrapper<GoodsSku>().lambda() |
| | | .eq(GoodsSku::getIsdeleted,Constants.ZERO) |
| | | .in(GoodsSku::getGoodsId,idList) ); |
| | | if(goodsSkuList==null || goodsSkuList.size() == 0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "商品尚未设置零售价,请先设置价格! "); |
| | | } |
| | | for(Goods param: list){ |
| | | Goods goods = getGoodsFromListById(param.getId(),goodsList,goodsSkuList); |
| | | if(goods ==null ){ |
| | | continue; |
| | | } |
| | | //如果是上架 |
| | | goods.setGoodsSkuList(goodsSkuList); |
| | | if(goods.getSkuPrice() == null || goods.getSkuPrice().compareTo(new BigDecimal(0)) <=0){ |
| | | //默认sku信息 |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), goods.getName()+":商品商品尚未设置零售价,无法上架"); |
| | | } |
| | | if(Constants.formatLongNum(goods.getPricedShopNum()) <= shopNum){ |
| | | //默认sku信息 |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), goods.getName()+":有未设置供货价的经销商,无法上架"); |
| | | } |
| | | } |
| | | goodsMapper.update(null,new UpdateWrapper<Goods>().lambda() |
| | | .set(Goods::getEditDate,new Date() ) |
| | | .set(Goods::getEditor,user.getId()) |
| | | .set(Goods::getStatus,Constants.ZERO ) |
| | | .in(Goods::getId,idList)); |
| | | } |
| | | |
| | | private Goods getGoodsFromListById(Integer id, List<Goods> goodsList, List<GoodsSku> skuList) { |
| | | for(Goods model: goodsList){ |
| | | if(Constants.equalsObject(model.getIdList(),id)){ |
| | | for(GoodsSku sku :skuList){ |
| | | if(Constants.equalsInteger(sku.getGoodsId(),id)){ |
| | | model.setSkuPrice(sku.getPrice()); |
| | | } |
| | | } |
| | | return model; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | @Override |
| | | public List<Goods> findList(Goods goods) { |
| | | QueryWrapper<Goods> wrapper = new QueryWrapper<>(goods); |
| | | wrapper.lambda() |
| | | .in(goods.getIdList() != null && goods.getIdList().size()>0, Goods::getId, goods.getIdList()) |
| | | .eq( Goods::getIsdeleted, Constants.ZERO); |
| | | return goodsMapper.selectList(wrapper); |
| | | } |
| | | |
| | |
| | | IPage<Goods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | MPJLambdaWrapper<Goods> queryWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | |
| | | queryWrapper.selectAll(Goods.class); |
| | | |
| | | 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::getParentCategoryId); |
| | | //库存量 |
| | | queryWrapper.select("(select sum(STOCK) from goods_sku where ISDELETED=0 and GOODS_ID=t.id) as stockNum "); |
| | | if(pageWrap.getModel().getShopId() !=null){ |
| | | queryWrapper.select("(select s.price from shop_goods_relation s where s.ISDELETED=0 and s.GOODS_ID=t.id and s.shop_id="+pageWrap.getModel().getShopId()+" limit 1) as shopPrice");//商家供货价 |
| | | }else{ |
| | | queryWrapper.select("(select count(s.id) from shop_goods_relation s left join shop g on s.SHOP_ID =g.id where g.status=0 and s.ISDELETED=0 and s.GOODS_ID=t.id) as pricedShopNum "); |
| | | } |
| | | //实际销量 |
| | | queryWrapper.select("(select sum(gd.GOODS_NUM) from goodsorder_detail gd" + |
| | | " inner join goods_sku gs on gs.id=gd.GOODS_SKU_ID" + |
| | |
| | | queryWrapper.eq(pageWrap.getModel().getParentCategoryId() != null, Goods::getParentCategoryId, pageWrap.getModel().getParentCategoryId()); |
| | | queryWrapper.eq(pageWrap.getModel().getBrandId() != null, Goods::getBrandId, pageWrap.getModel().getBrandId()); |
| | | queryWrapper.eq(pageWrap.getModel().getStatus() != null, Goods::getStatus, pageWrap.getModel().getStatus()); |
| | | |
| | | queryWrapper.orderByDesc(Goods::getCreateDate); |
| | | queryWrapper.in(pageWrap.getModel().getIdList() != null && pageWrap.getModel().getIdList().size()>0, Goods::getId, pageWrap.getModel().getIdList()); |
| | | if(pageWrap.getModel().getShopId() !=null){ |
| | | queryWrapper.orderByAsc("shopPrice"); |
| | | } |
| | | queryWrapper.orderByDesc(Goods::getId); |
| | | IPage<Goods> result = goodsAdminJoinMapper.selectJoinPage(page, Goods.class, queryWrapper); |
| | | initResult(result.getRecords()); |
| | | initResult(result.getRecords(),pageWrap.getModel().getShopId()==null); |
| | | return PageData.from(result); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | private void initResult(List<Goods> list) { |
| | | private void initResult(List<Goods> list,boolean shopId) { |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | | long shopNum = 0; |
| | | if(shopId){//不针对商家搜索的话, |
| | | shopNum = shopMapper.selectCount(new QueryWrapper<Shop>().lambda() |
| | | .eq(Shop::getIsdeleted,Constants.ZERO) |
| | | .eq(Shop::getStatus,Constants.ZERO)); |
| | | } |
| | | String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_FILE).getCode(); |
| | | for (Goods goods : list) { |
| | | goods.setShopNum(shopNum); |
| | | goods.setResourcePath(path); |
| | | //查询sku |
| | | MPJLambdaWrapper<GoodsSku> queryWrapper = new MPJLambdaWrapper<GoodsSku>() |
| | |
| | | */ |
| | | @Override |
| | | public IPage<GoodsInfoResponse> getGoodsPage(PageWrap<GoodsRequest> pageWrap) { |
| | | GoodsRequest model = pageWrap.getModel(); |
| | | |
| | | QueryWrapper<GoodsRequest> wrapper = new QueryWrapper<GoodsRequest>() |
| | | .eq("g.ISDELETED",Constants.ZERO) |
| | | .eq("g.PARENT_CATEGORY_ID",pageWrap.getModel().getParentCategoryId()) |
| | | .eq(!Objects.isNull(pageWrap.getModel()) && Objects.nonNull(pageWrap.getModel().getCategoryId()), |
| | | "g.CATEGORY_ID", pageWrap.getModel().getCategoryId()) |
| | | .eq(!Objects.isNull(model) && Objects.nonNull(model.getCategoryId()), |
| | | "g.CATEGORY_ID", model.getCategoryId()) |
| | | //适用品牌 适用系列 |
| | | .apply(!Objects.isNull(model) && Objects.nonNull(model.getApplicableBrandId()), |
| | | " find_in_set( '["+model.getApplicableBrandId()+"]' , g.BRAND_IDS ) ") |
| | | .apply(!Objects.isNull(model) && Objects.nonNull(model.getSeriesBrandId()), |
| | | " find_in_set( '["+model.getSeriesBrandId()+"]' , g.SERIAL_IDS ) ") |
| | | .eq("g.STATUS", Constants.ZERO) |
| | | .like(StringUtils.isNotBlank(pageWrap.getModel().getGoodsName()),"g.NAME",pageWrap.getModel().getGoodsName()); |
| | | // .eq(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getType()), "g.TYPE", pageWrap.getModel().getType()); |
| | | .like(StringUtils.isNotBlank(model.getGoodsName()),"g.NAME",model.getGoodsName()); |
| | | |
| | | for(PageWrap.SortData sortData:pageWrap.getSorts1()){ |
| | | if ("CREATE_DATE".equalsIgnoreCase(sortData.getProperty())){ |
| | | if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){ |
| | | wrapper.orderByAsc("g.CREATE_DATE"); |
| | | } |
| | | if(Objects.nonNull(model.getSortInfo())){ |
| | | //排序方式:0=综合排序;1=销量由低到高 ;2=价格由低到高;3=销量由高到低;4=价格由高到低 |
| | | if(Constants.equalsInteger(model.getSortInfo(),Constants.ZERO)){ |
| | | wrapper.orderByDesc("g.CREATE_DATE"); |
| | | |
| | | } |
| | | if ("realSaleNum".equalsIgnoreCase(sortData.getProperty())){ |
| | | |
| | | if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){ |
| | | wrapper.orderByAsc("realSaleNum"); |
| | | } |
| | | }else if(Constants.equalsInteger(model.getSortInfo(),Constants.ONE)){ |
| | | wrapper.orderByAsc("realSaleNum"); |
| | | }else if(Constants.equalsInteger(model.getSortInfo(),Constants.TWO)){ |
| | | wrapper.orderByAsc("g.price"); |
| | | }else if(Constants.equalsInteger(model.getSortInfo(),Constants.THREE)){ |
| | | wrapper.orderByDesc("realSaleNum"); |
| | | }else if(Constants.equalsInteger(model.getSortInfo(),Constants.FOUR)){ |
| | | wrapper.orderByDesc("g.price"); |
| | | } |
| | | if ("PRICE".equalsIgnoreCase(sortData.getProperty())){ |
| | | if (PageWrap.ASC.equalsIgnoreCase(sortData.getDirection())){ |
| | | wrapper.orderByAsc("g.PRICE"); |
| | | } |
| | | wrapper.orderByDesc("g.PRICE"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | IPage<GoodsInfoResponse> page = goodsMapper.goodsPage(pageWrap.toPage(),wrapper); |
| | | IPage<GoodsInfoResponse> page = |
| | | Objects.isNull(model.getShopId())? |
| | | goodsMapper.goodsPage(pageWrap.toPage(),wrapper) |
| | | : |
| | | goodsMapper.goodsPageForShop(pageWrap.toPage(),wrapper,model.getShopId()) ; |
| | | if (!CollectionUtils.isEmpty(page.getRecords())){ |
| | | String preFixPath = systemDictDataBiz.getPreFixPath(Constants.RESOURCE_PATH, Constants.GOODS_FILE); |
| | | page.getRecords().forEach(s->s.setImgurl(preFixPath+s.getImgurl())); |
| | | } |
| | | |
| | | |
| | | // if (pageWrap.getModel().getType().equals(Constants.TWO)) { |
| | | // for (GoodsInfoResponse goodsResponse : page.getRecords()) { |
| | | // //查询商品的分类 |
| | | // goodsResponse.setCategoryLabels(labelsMapper.selectById(goodsResponse.getCategoryId())); |
| | | // //查询商品的品牌 |
| | | // goodsResponse.setBrandLabels(labelsMapper.selectById(goodsResponse.getBrandId())); |
| | | // //查询商品的标签信息 |
| | | // if (StringUtils.isNotBlank(goodsResponse.getLabels())) { |
| | | // goodsResponse.setLabelsList(labelsMapper.selectList(new QueryWrapper<Labels>() |
| | | // .apply(" find_in_set( id, " + goodsResponse.getLabels().split(",") + " ) "))); |
| | | // } |
| | | // //查询是否已订阅 |
| | | // goodsResponse.setIsSubscribe(goodsorderDetailMapper.selectCount(new QueryWrapper<GoodsorderDetail>() |
| | | // .eq("CREATOR", pageWrap.getModel().getMemberId()) |
| | | // .apply(" GOODS_SKU_ID in ( SELECT g.id FROM goods_sku g where g.GOODS_ID = " + goodsResponse.getId() + " ) ") |
| | | // )); |
| | | // //sku基础信息 |
| | | // this.getSkuInfo(goodsResponse); |
| | | // } |
| | | // } |
| | | return page; |
| | | } |
| | | |
| | |
| | | |
| | | String fullUrl = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+ |
| | | systemDictDataBiz.queryByCode(Constants.OSS,Constants.GOODS_FILE).getCode(); |
| | | Integer sumStock = Constants.ZERO; |
| | | for (GoodsSkuResponse goodsSkuResponse:goodsSkuResponseList) { |
| | | if(StringUtils.isBlank(goodsSkuResponse.getImgurl())){ |
| | | goodsSkuResponse.setImgurl(fullUrl + goodsSkuResponse.getGoodsImgUrl()); |
| | |
| | | indexData.append("," + ( skuAttr.getSortnum()-1)); |
| | | } |
| | | goodsSkuResponse.setIndexData(indexData.toString().substring(1)); |
| | | sumStock = sumStock + goodsSkuResponse.getStock(); |
| | | } |
| | | |
| | | //真实销量 = realSaleNum - saleNum; |
| | | //真实库存= sumStock - (realSaleNum - saleNum) |
| | | goodsResponse.setStock(sumStock - goodsResponse.getRealSaleNum() + goodsResponse.getSaleNum()); |
| | | goodsResponse.setGoodsSkuResponseList(goodsSkuResponseList); |
| | | //Sku基础信息 |
| | | List<SkuResponse> skuResponseList = skuMapper.getSkuResponseList(goodsResponse.getId()); |
| | |
| | | |
| | | |
| | | @Override |
| | | public GoodsInfoResponse getGoodsInfo(Integer goodsId) { |
| | | |
| | | public GoodsInfoResponse getGoodsInfo(Integer goodsId,Integer memberId) { |
| | | String fullUrl = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+ |
| | | systemDictDataBiz.queryByCode(Constants.OSS,Constants.GOODS_FILE).getCode(); |
| | | GoodsInfoResponse goodsResponse = goodsMapper.getGoodsInfo(goodsId); |
| | | if(Objects.isNull(goodsResponse)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前专区关联商品已删除"); |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | goodsResponse.setImgurl(fullUrl + goodsResponse.getImgurl()); |
| | | //查询商品的分类 |
| | |
| | | Constants.GOODS_FILE); |
| | | List<MultiFileDTO> multiFileDTOS = objAllFileUrl.get(Constants.MultiFile.PLATFORM_GOOD_ROTATION.getKey()); |
| | | goodsResponse.setGoodBannerMultiFiles(multiFileDTOS); |
| | | goodsResponse.setCollectStatus(Constants.ZERO); |
| | | if(Objects.nonNull(memberId)){ |
| | | goodsResponse.setCollectStatus(collectMapper.selectCount(new QueryWrapper<Collect>().lambda() |
| | | .eq(Collect::getMemberId,memberId) |
| | | .eq(Collect::getObjId,goodsId) |
| | | .eq(Collect::getObjType,Constants.ONE) |
| | | )>Constants.ZERO?Constants.ONE:Constants.ZERO); |
| | | } |
| | | |
| | | return goodsResponse; |
| | | } |
| | | |