From 5a3d6b6d93d28757c960c1e42d07a4852705dbe6 Mon Sep 17 00:00:00 2001 From: Yen Date: Thu, 13 Jun 2024 10:30:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=B4=E6=9C=9F=E5=93=81=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/api/GoodsImminentBatchApi.java | 204 +++++++++++++ .../entity/so/GoodsImminentBatchQuery.java | 42 +++ .../goods/entity/vo/GoodsImminentBatchVo.java | 126 ++++++++ .../mapper/GoodsImminentBatchMapper.java | 7 + .../service/GoodsImminentBatchService.java | 8 + .../impl/GoodsImminentBatchServiceImpl.java | 16 ++ .../mapper/goods/GoodsImminentBatchMapper.xml | 270 ++++++++++++++++++ 7 files changed, 673 insertions(+) create mode 100644 src/main/java/com/qs/serve/modules/goods/controller/api/GoodsImminentBatchApi.java create mode 100644 src/main/java/com/qs/serve/modules/goods/entity/so/GoodsImminentBatchQuery.java create mode 100644 src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsImminentBatchVo.java create mode 100644 src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml diff --git a/src/main/java/com/qs/serve/modules/goods/controller/api/GoodsImminentBatchApi.java b/src/main/java/com/qs/serve/modules/goods/controller/api/GoodsImminentBatchApi.java new file mode 100644 index 00000000..0d7b9f46 --- /dev/null +++ b/src/main/java/com/qs/serve/modules/goods/controller/api/GoodsImminentBatchApi.java @@ -0,0 +1,204 @@ +package com.qs.serve.modules.goods.controller.api; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.qs.serve.common.config.DevEnvironmentConfig; +import com.qs.serve.common.model.annotation.SysLog; +import com.qs.serve.common.model.dto.PageVo; +import com.qs.serve.common.model.dto.R; +import com.qs.serve.common.model.enums.BizType; +import com.qs.serve.common.model.enums.SystemModule; +import com.qs.serve.common.util.*; +import com.qs.serve.modules.bms.common.BookAccountUtil; +import com.qs.serve.modules.bms.entity.BmsSupplier; +import com.qs.serve.modules.bms.service.BmsSupplierService; +import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; +import com.qs.serve.modules.goods.entity.*; +import com.qs.serve.modules.goods.entity.bo.GoodsImminentBatchBo; +import com.qs.serve.modules.goods.entity.dto.GoodsAccrIdsDto; +import com.qs.serve.modules.goods.entity.dto.GoodsRuleItemDTO; +import com.qs.serve.modules.goods.entity.so.GoodsImminentBatchQuery; +import com.qs.serve.modules.goods.entity.vo.GoodsImminentBatchVo; +import com.qs.serve.modules.goods.mapper.GoodsSkuMapper; +import com.qs.serve.modules.goods.mapper.GoodsSpuMapper; +import com.qs.serve.modules.goods.service.*; +import com.qs.serve.modules.seeyon.service.impl.SeeYonRequestBaseService; +import com.qs.serve.modules.tbs.service.TbsActivityGoodsService; +import com.qs.serve.modules.tbs.service.TbsBudgetConditionService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 商品 临期批次 + * @author YenHex + * @since 2024-06-11 + */ +@Slf4j +@AllArgsConstructor +@RestController +@RequestMapping("my/imminentBatch") +public class GoodsImminentBatchApi { + + private GoodsRuleService goodsRuleService; + private GoodsCategoryRuleService goodsCategoryRuleService; + private BmsSupplierService bmsSupplierService; + private GoodsCategoryService goodsCategoryService; + private GoodsAccreditService goodsAccreditService; + private GoodsImminentBatchService goodsImminentBatchService; + + + /** + * 翻页 + * @param param + * @return + */ + @GetMapping("/page") + public R> getPage(GoodsImminentBatchQuery param){ + GoodsCategoryRule categoryRule = goodsCategoryRuleService.getById(param.getSearchCateRuleId()); + if(categoryRule!=null&&categoryRule.getIgnoreBrandIds()!=null&&categoryRule.getIgnoreBrandIds().length>0){ + param.setSelectNotIntCateIds(Arrays.asList(categoryRule.getIgnoreBrandIds())); + log.info("setSelectNotIntCateIds {}", JsonUtil.objectToJson(param)); + } + BmsSupplier supplier = bmsSupplierService.getByNameOrCode(param.getSupplierCode()); + if(supplier==null){ + return R.error("供应商不存在或停用"); + } + + //客户规则设置 + String userId = AuthContextUtils.getSysUserId(); + this.toSetSpuParam(param, supplier,userId); + //产品规则设置 + this.tiSetSpuParam2(param, supplier); + + if(DevEnvironmentConfig.OPEN_TENANT_BOOK){ + param.setBookCodeList(BookAccountUtil.getCurrentUserAccount()); + } + long total = goodsImminentBatchService.countVoList(param); + if(total<1){ + return R.byEmptyList(); + } + List list = goodsImminentBatchService.selectVoList(param); + return R.byPageList(total,list); + } + + /** + * ID查询 + * @param id + * @return + */ + @GetMapping("/getById/{id}") + @SysLog(module = SystemModule.GOODS, title = "临期批次", biz = BizType.QUERY) + public R getById(@PathVariable("id") String id){ + GoodsImminentBatch goodsImminentBatch = goodsImminentBatchService.getById(id); + return R.ok(goodsImminentBatch); + } + + + private void tiSetSpuParam2(GoodsImminentBatchQuery param, BmsSupplier supplier) { + GoodsAccrIdsDto accrIdsDto = goodsAccreditService + .listIgnoreAcc2(supplier.getId(), supplier.listBizRegionIds(), supplier.listSaleRegionIds()); + param.setSubAccInfo(accrIdsDto); + } + + /** + * 设置Spu查询条件 + * @param param + * @param supplier + */ + private void toSetSpuParam(GoodsImminentBatchQuery param, BmsSupplier supplier, String userId) { + + //用户维度的客户规则 + List userRules = goodsRuleService.listByUserId(userId); + List ruleItems = goodsRuleService.listBySupplierId(supplier.getId()); + if(userRules!=null){ + if(ruleItems!=null){ + ruleItems.addAll(userRules); + }else { + ruleItems = userRules; + } + } + GoodsRuleItemDTO ruleItemDTO = goodsRuleService.buildGoodsRuleItemDTO(ruleItems); + if(ruleItemDTO!=null){ + + if(ruleItemDTO.getNotInCategoryIds()!=null){ + if(CollUtil.isEmpty(param.getSelectNotIntCateIds())){ + param.setSelectNotIntCateIds(ruleItemDTO.getNotInCategoryIds()); + }else{ + param.getSelectNotIntCateIds().addAll(ruleItemDTO.getNotInCategoryIds()); + } + } + + if(CollUtil.isNotEmpty(ruleItemDTO.getOnlyCategoryIds())){ + if (CollUtil.isEmpty(param.getSelectCateIds())){ + param.setSelectCateIds(ruleItemDTO.getOnlyCategoryIds()); + }else{ + List onlyIds = ruleItemDTO.getOnlyCategoryIds(); + List onlyCategoryList = goodsCategoryService.listByIds(onlyIds); + for (GoodsCategory category : onlyCategoryList) { + List childList = goodsCategoryService.list(new LambdaQueryWrapper() + .likeRight(GoodsCategory::getLevelPath,category.getLevelPath()+"_")); + if(CollUtil.isNotEmpty(childList)){ + List childIds = childList.stream().map(a->a.getId().toString()).collect(Collectors.toList()); + onlyIds.addAll(childIds); + } + } + List selectCateIds = param.getSelectCateIds(); + List goodsCategoryList = goodsCategoryService.listByIds(selectCateIds); + for (GoodsCategory category : goodsCategoryList) { + List childList = goodsCategoryService.list(new LambdaQueryWrapper() + .likeRight(GoodsCategory::getLevelPath,category.getLevelPath()+"_")); + if(CollUtil.isNotEmpty(childList)){ + List childIds = childList.stream().map(a->a.getId().toString()).collect(Collectors.toList()); + selectCateIds.addAll(childIds); + } + } + //交集 + Collection ids = cn.hutool.core.collection.CollectionUtil + .intersection(onlyIds, selectCateIds); + List idsList = new ArrayList<>(); + idsList.addAll(ids); + idsList.add("#"); + param.setSelectCateIds(idsList); + } + } + + if(CollUtil.isNotEmpty(ruleItemDTO.getOnlySpuIds())){ + if (CollUtil.isEmpty(param.getSelectSpuIds())){ + List ids = ruleItemDTO.getOnlySpuIds().stream() + .filter(Objects::nonNull).map(Long::parseLong).collect(Collectors.toList()); + param.setSelectSpuIds(ids); + }else{ + List ids = ruleItemDTO.getOnlySpuIds().stream() + .filter(Objects::nonNull).map(Long::parseLong).collect(Collectors.toList()); + //交集 + Collection id2s = cn.hutool.core.collection.CollectionUtil + .intersection(ids, param.getSelectSpuIds()); + List idsList = new ArrayList<>(); + idsList.addAll(id2s); + idsList.add(-1L); + param.setSelectSpuIds(idsList); + } + } + + if(CollUtil.isNotEmpty(ruleItemDTO.getNotInSpuIds())){ + if (CollUtil.isEmpty(param.getSelectNotInSpuIds())){ + List ids = ruleItemDTO.getNotInSpuIds().stream() + .filter(Objects::nonNull).map(Long::parseLong).collect(Collectors.toList()); + param.setSelectNotInSpuIds(ids); + }else{ + List ids = ruleItemDTO.getNotInSpuIds().stream() + .filter(Objects::nonNull).map(Long::parseLong).collect(Collectors.toList()); + param.getSelectNotInSpuIds().addAll(ids); + } + } + + } + } +} + diff --git a/src/main/java/com/qs/serve/modules/goods/entity/so/GoodsImminentBatchQuery.java b/src/main/java/com/qs/serve/modules/goods/entity/so/GoodsImminentBatchQuery.java new file mode 100644 index 00000000..3e565f5e --- /dev/null +++ b/src/main/java/com/qs/serve/modules/goods/entity/so/GoodsImminentBatchQuery.java @@ -0,0 +1,42 @@ +package com.qs.serve.modules.goods.entity.so; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.qs.serve.modules.goods.entity.dto.GoodsAccrIdsDto; +import lombok.Data; + +import java.util.List; + +/** + * @author YenHex + * @since 2024/6/12 + */ +@Data +public class GoodsImminentBatchQuery { + + /** 关键字查询 */ + private String skuName; + private String skuCode; + private String spuName; + private String spuCode; + private String skuAddCode; + + /** 供应商编码 */ + private String supplierCode; + + /** 选中的商品规则 */ + private String searchCateRuleId; + + private Integer selectSpecialFlag; + private Integer orderFlag; + private String belong; + + /** 账套编码列表 */ + private List bookCodeList; + private GoodsAccrIdsDto subAccInfo; + private List notInSkuIds; + private List selectSpuIds; + private List selectNotInSpuIds; + private List selectCateIds; + private List selectNotIntCateIds; + +} diff --git a/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsImminentBatchVo.java b/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsImminentBatchVo.java new file mode 100644 index 00000000..acebc238 --- /dev/null +++ b/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsImminentBatchVo.java @@ -0,0 +1,126 @@ +package com.qs.serve.modules.goods.entity.vo; + +import com.baomidou.mybatisplus.annotation.SqlCondition; +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.hibernate.validator.constraints.Length; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; +import java.time.LocalDate; + +/** + * @author YenHex + * @since 2024/6/12 + */ +@Data +public class GoodsImminentBatchVo { + + /** 批次skuId */ + private Long id; + + private String batchCode; + + /** 数量 */ + private Integer quantity; + + /** 已下单数量 */ + private Integer orderQuantity; + + /** 截止销售时间 */ + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") + private LocalDate endDate; + + /** 批次备注 */ + private String remark; + + private String spuId; + + private String spuCode; + + private String spuName; + + private String skuId; + + private String skuCode; + + private String skuName; + + private String skuAddCode; + + /** 图片 */ + private String picUrl; + + /** 销售价格 */ + private BigDecimal salesPrice; + + /** 市场价 */ + private BigDecimal marketPrice; + + /** 成本价 */ + private BigDecimal costPrice; + + /** 规格值 */ + private String specInfos; + + /** 库存 */ + private Integer stock; + + /** 重量(kg) */ + private BigDecimal weight; + + /** 体积(m³) */ + private BigDecimal volume; + + /** 净重 */ + private BigDecimal invUnitWeight; + + /** 最低起批数(0->不限制) */ + private Integer minPurchase; + + /** 是否可以下单 1、是;0否 */ + private Integer orderFlag; + + private Integer specialFlag; + + /** 在线下单 */ + private Integer orderOnlineFlag; + + /** 线下下单 */ + private Integer orderOfflineFlag; + + /** 单位id */ + private Long unitId; + + /** 单位 */ + private String unitName; + + /** 账套编码 */ + private String bookBelong; + + /** 账套名称 */ + private String bookName; + + /** 产地 */ + private String belong; + + /** 包装 */ + private String wrapVal; + + /** 口味 */ + private String tasteVal; + + /** 一级类目:品牌名称 */ + private String cateFirstLabel; + + /** 二级类目:类目名称 */ + private String cateSecondLabel; + + /** 三级类目:系列名称 */ + private String cateThirdLabel; + +} diff --git a/src/main/java/com/qs/serve/modules/goods/mapper/GoodsImminentBatchMapper.java b/src/main/java/com/qs/serve/modules/goods/mapper/GoodsImminentBatchMapper.java index c4736e2f..1b897909 100644 --- a/src/main/java/com/qs/serve/modules/goods/mapper/GoodsImminentBatchMapper.java +++ b/src/main/java/com/qs/serve/modules/goods/mapper/GoodsImminentBatchMapper.java @@ -1,7 +1,14 @@ package com.qs.serve.modules.goods.mapper; +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qs.serve.common.model.dto.RowParam; import com.qs.serve.modules.goods.entity.GoodsImminentBatch; +import com.qs.serve.modules.goods.entity.so.GoodsImminentBatchQuery; +import com.qs.serve.modules.goods.entity.vo.GoodsImminentBatchVo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 临期批次 Mapper diff --git a/src/main/java/com/qs/serve/modules/goods/service/GoodsImminentBatchService.java b/src/main/java/com/qs/serve/modules/goods/service/GoodsImminentBatchService.java index 892115cc..0600d4f5 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/GoodsImminentBatchService.java +++ b/src/main/java/com/qs/serve/modules/goods/service/GoodsImminentBatchService.java @@ -2,6 +2,10 @@ package com.qs.serve.modules.goods.service; import com.baomidou.mybatisplus.extension.service.IService; import com.qs.serve.modules.goods.entity.GoodsImminentBatch; +import com.qs.serve.modules.goods.entity.so.GoodsImminentBatchQuery; +import com.qs.serve.modules.goods.entity.vo.GoodsImminentBatchVo; + +import java.util.List; /** * 临期批次 服务接口 @@ -12,5 +16,9 @@ public interface GoodsImminentBatchService extends IService boolean checkExist(String batchCode,String skuId); + long countVoList(GoodsImminentBatchQuery query); + + List selectVoList(GoodsImminentBatchQuery query); + } diff --git a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsImminentBatchServiceImpl.java b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsImminentBatchServiceImpl.java index d69ca1e3..c1ec5362 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsImminentBatchServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsImminentBatchServiceImpl.java @@ -2,6 +2,9 @@ package com.qs.serve.modules.goods.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qs.serve.common.model.dto.RowParam; +import com.qs.serve.modules.goods.entity.so.GoodsImminentBatchQuery; +import com.qs.serve.modules.goods.entity.vo.GoodsImminentBatchVo; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -9,6 +12,8 @@ import com.qs.serve.modules.goods.entity.GoodsImminentBatch; import com.qs.serve.modules.goods.service.GoodsImminentBatchService; import com.qs.serve.modules.goods.mapper.GoodsImminentBatchMapper; +import java.util.List; + /** * 临期批次 服务实现类 * @author YenHex @@ -24,5 +29,16 @@ public class GoodsImminentBatchServiceImpl extends ServiceImpl().eq(GoodsImminentBatch::getBatchCode,batchCode).eq(GoodsImminentBatch::getSkuId,skuId)); return count>0; } + + @Override + public long countVoList(GoodsImminentBatchQuery query) { + return baseMapper.countVoList(query); + } + + @Override + public List selectVoList(GoodsImminentBatchQuery query) { + return baseMapper.selectVoList(query,new RowParam(true)); + } + } diff --git a/src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml b/src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml new file mode 100644 index 00000000..9fcaad0d --- /dev/null +++ b/src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + goods_imminent_batch.`id`, + goods_imminent_batch.`batch_code`, + goods_imminent_batch.`quantity`, + goods_imminent_batch.`order_quantity`, + goods_imminent_batch.`end_date`, + goods_imminent_batch.`remark` + + + + + + + + goods_sku.`sku_name`, + goods_sku.`sku_code`, + goods_sku.`pic_url`, + goods_sku.`sales_price`, + goods_sku.`market_price`, + goods_sku.`cost_price`, + goods_sku.`spec_infos`, + goods_sku.`stock`, + goods_sku.`unit_id`, + goods_sku.`unit_name`, + goods_sku.`weight`, + goods_sku.`volume`, + goods_sku.`inv_unit_weight`, + goods_sku.`min_purchase`, + goods_sku.`cost_flag`, + goods_sku.`belong`, + goods_sku.`belong_sort`, + goods_sku.`wrap_val`, + goods_sku.`taste_val`, + goods_sku.`order_flag`, + goods_sku.`special_flag`, + goods_sku.`abct`, + goods_sku.`order_online_flag`, + goods_sku.`order_offline_flag`, + goods_sku.`book_belong`, + goods_sku.`book_name` + + + + goods_spu.`spu_code`, + goods_spu.`name` as `spu_name`, + goods_spu.`category_first`, + goods_spu.`category_second`, + goods_spu.`category_third`, + goods_spu.`category_last`, + goods_spu.`pic_urls`, + goods_spu.`shelf`, + goods_spu.`sort`, + goods_spu.`sale_num`, + goods_spu.`spec_type`, + goods_spu.`taste_value`, + goods_spu.`create_time`, + goods_spu.`update_time`, + goods_spu.`create_by`, + goods_spu.`update_by`, + goods_spu.`tenant_id`, + goods_spu.`cost_flag`, + goods_spu.`order_flag`, + goods_spu.`book_belong`, + goods_spu.`book_name`, + goods_spu.`special_sku_id`, + goods_spu.`spu_cunhuo_flag`, + goods_spu.`sku_num_val` + + + + + and `goods_spu`.`name` like concat('%',#{query.spuName},'%') + and `goods_spu`.`goods_spu` like concat('%',#{query.skuCode},'%') + + and `goods_spu`.`book_belong` in + + #{selectId} + + + + + and `goods_spu`.`id` in + + #{selectId} + + + + and `goods_spu`.`id` not in + + #{selectId} + + + + and (`goods_spu`.`category_first` in + + #{selectId} + + or `goods_spu`.`category_second` in + + #{selectId} + + or `goods_spu`.`category_third` in + + #{selectId} + ) + + + and (`goods_spu`.`category_first` not in + + #{selectId} + + and `goods_spu`.`category_second` not in + + #{selectId} + + and `goods_spu`.`category_third` not in + + #{selectId} + ) + + + + + and (`goods_sku`.`belong` = #{query.belong} or goods_sku.special_flag=1) + + + and `goods_sku`.`special_flag` = #{query.selectSpecialFlag} + + + and `goods_sku`.`sku_add_code` like concat('%', #{query.skuAddCode},'%') + + + and (`goods_sku`.`order_flag` = #{query.orderFlag} or `goods_sku`.`special_flag` = 1) + + + + and `goods_sku`.`sku_name` like concat('%', #{query.skuName},'%') + + + and `goods_sku`.`sku_code` like concat('%', #{query.skuCode},'%') + + + and `goods_sku`.`id` not in + + #{selectId} + + + + and `goods_sku`.`id` not in( + select sku.id FROM goods_sku sku + left join goods_spu spu on sku.spu_id = spu.id + left join goods_category cate1 on cate1.id = spu.category_first + left join goods_category cate2 on cate2.id = spu.category_second + left join goods_category cate3 on cate3.id = spu.category_third + where + ( + sku.id in + + #{selectId} + + or spu.id in + + #{selectId} + + or cate1.id in + + #{selectId} + + or cate2.id in + + #{selectId} + + or cate3.id in + + #{selectId} + + ) and + sku.id not in + + #{selectId} + + and + spu.id not in + + #{selectId} + + and + cate1.id not in + + #{selectId} + + and + cate2.id not in + + #{selectId} + + and + cate3.id not in + + #{selectId} + + ) + + + +