|
|
@@ -3,9 +3,6 @@ package com.sckw.product.service.operation;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.sckw.core.common.enums.enums.DictEnum;
|
|
|
-import com.sckw.core.common.enums.enums.DictTypeEnum;
|
|
|
-import com.sckw.core.exception.BusinessException;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.model.page.PageResult;
|
|
|
import com.sckw.core.model.vo.TableBottom;
|
|
|
@@ -14,33 +11,30 @@ import com.sckw.core.model.vo.TableTop;
|
|
|
import com.sckw.core.utils.BeanUtils;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
|
-import com.sckw.excel.utils.DateUtil;
|
|
|
import com.sckw.product.dao.KwpGoodsMapper;
|
|
|
import com.sckw.product.enums.GoodsStatusEnum;
|
|
|
-import com.sckw.product.model.*;
|
|
|
+import com.sckw.product.model.GoodsListExport;
|
|
|
+import com.sckw.product.model.KwpGoods;
|
|
|
+import com.sckw.product.model.OperationGoodsListExport;
|
|
|
import com.sckw.product.model.dto.OperatorGoodsListQueryDTO;
|
|
|
import com.sckw.product.model.vo.req.OperatorGoodsExportQueryVO;
|
|
|
import com.sckw.product.model.vo.req.OperatorGoodsListQueryVO;
|
|
|
import com.sckw.product.model.vo.req.OperatorGoodsStsQueryVO;
|
|
|
-import com.sckw.product.model.vo.res.*;
|
|
|
-import com.sckw.product.service.KwpGoodsAddressService;
|
|
|
-import com.sckw.product.service.KwpGoodsAttributeService;
|
|
|
-import com.sckw.product.service.KwpGoodsImageService;
|
|
|
-import com.sckw.product.service.KwpGoodsPriceRangeService;
|
|
|
+import com.sckw.product.model.vo.res.GoodsDetail;
|
|
|
+import com.sckw.product.model.vo.res.GoodsList;
|
|
|
+import com.sckw.product.model.vo.res.OperationGoodsDetail;
|
|
|
+import com.sckw.product.model.vo.res.OperationGoodsList;
|
|
|
+import com.sckw.product.service.KwpGoodsService;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.RemoteUserService;
|
|
|
-import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
import com.sckw.system.api.model.dto.res.KwsUserResDto;
|
|
|
import com.sckw.system.api.model.dto.res.SysDictResDto;
|
|
|
-import com.sckw.system.api.model.dto.res.UserCacheResDto;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -60,13 +54,17 @@ public class GoodsManagerService {
|
|
|
private RemoteUserService remoteUserService;
|
|
|
|
|
|
|
|
|
+ private final KwpGoodsService kwpGoodsService;
|
|
|
private final KwpGoodsMapper kwpGoodsMapper;
|
|
|
- private final KwpGoodsAddressService kwpGoodsAddressService;
|
|
|
- private final KwpGoodsAttributeService kwpGoodsAttributeService;
|
|
|
- private final KwpGoodsImageService kwpGoodsImageService;
|
|
|
- private final KwpGoodsPriceRangeService kwpGoodsPriceRangeService;
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc: 分页查询
|
|
|
+ * @author: yzc
|
|
|
+ * @date: 2023-09-18 15:19
|
|
|
+ * @Param params:
|
|
|
+ * @return: com.sckw.core.model.page.PageResult
|
|
|
+ */
|
|
|
public PageResult select(OperatorGoodsListQueryVO params) {
|
|
|
LambdaQueryWrapper<KwpGoods> wrapper = buildWrapper(BeanUtils.copyProperties(params, OperatorGoodsListQueryDTO.class));
|
|
|
Page<KwpGoods> page = new Page<>(params.getPage(), params.getPageSize());
|
|
|
@@ -75,7 +73,8 @@ public class GoodsManagerService {
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
return PageResult.build(params.getPage(), params.getPageSize(), goodsIpage.getTotal(), Collections.emptyList());
|
|
|
}
|
|
|
- List<OperationGoodsList> result = buildGoodLists(list);
|
|
|
+ List<GoodsList> goodsLists = kwpGoodsService.buildGoodLists(list);
|
|
|
+ List<OperationGoodsList> result = BeanUtils.copyToList(goodsLists, OperationGoodsList.class);
|
|
|
return PageResult.build(params.getPage(), params.getPageSize(), goodsIpage.getTotal(), result);
|
|
|
}
|
|
|
|
|
|
@@ -129,67 +128,6 @@ public class GoodsManagerService {
|
|
|
return wrapper;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @desc: 构建商品列表
|
|
|
- * @author: lt
|
|
|
- * @date: 2023-09-14 10:14
|
|
|
- * @Param list:
|
|
|
- * @return: java.util.List<com.sckw.product.model.vo.res.GoodsList>
|
|
|
- */
|
|
|
- private List<OperationGoodsList> buildGoodLists(List<KwpGoods> list) {
|
|
|
- List<OperationGoodsList> result = new ArrayList<>(list.size());
|
|
|
- List<Long> goodsIds = new ArrayList<>(list.size());
|
|
|
- List<Long> supplyEntIds = new ArrayList<>(list.size());
|
|
|
- List<Long> userIds = new ArrayList<>();
|
|
|
- list.forEach(e -> {
|
|
|
- goodsIds.add(e.getId());
|
|
|
- if (Objects.nonNull(e.getSupplyEntId())) {
|
|
|
- supplyEntIds.add(e.getSupplyEntId());
|
|
|
- }
|
|
|
- if (Objects.nonNull(e.getManager())) {
|
|
|
- userIds.add(e.getManager());
|
|
|
- }
|
|
|
- if (Objects.nonNull(e.getCreateBy())) {
|
|
|
- userIds.add(e.getCreateBy());
|
|
|
- }
|
|
|
- });
|
|
|
- //地址信息
|
|
|
- Map<Long, String> addressMap = kwpGoodsAddressService.getByGoodsIds(goodsIds).stream()
|
|
|
- .collect(Collectors.toMap(KwpGoodsAddress::getGoodsId, KwpGoodsAddress::getName, (k1, k2) -> k1));
|
|
|
- //价格梯度信息
|
|
|
- Map<Long, List<KwpGoodsPriceRange>> priceRangeMap = kwpGoodsPriceRangeService.getByGoodsIds(goodsIds).stream()
|
|
|
- .collect(Collectors.groupingBy(KwpGoodsPriceRange::getGoodsId));
|
|
|
- //用户信息
|
|
|
- Map<Long, UserCacheResDto> userMap = remoteSystemService.queryUserCacheMapByIds(userIds);
|
|
|
- //供应企业信息
|
|
|
- List<EntCacheResDto> entList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(supplyEntIds)) {
|
|
|
- entList = remoteSystemService.queryEntCacheByIds(supplyEntIds);
|
|
|
- }
|
|
|
- Map<Long, String> entMap = entList.stream().collect(Collectors.toMap(EntCacheResDto::getId, EntCacheResDto::getFirmName, (k1, k2) -> k1));
|
|
|
- list.forEach(e -> {
|
|
|
- Long id = e.getId();
|
|
|
- OperationGoodsList operationGoodsList = BeanUtils.copyProperties(e, OperationGoodsList.class);
|
|
|
- UserCacheResDto manager = userMap.get(e.getManager());
|
|
|
- UserCacheResDto createUser = userMap.get(e.getCreateBy());
|
|
|
- operationGoodsList.setStatusLabel(DictEnum.getLabel(DictTypeEnum.GOODS_STATUS.getType(), String.valueOf(operationGoodsList.getStatus())))
|
|
|
- .setGoodsTypeLabel(DictEnum.getLabel(DictTypeEnum.PRODUCT_NAME_TYPE.getType(), operationGoodsList.getGoodsType()))
|
|
|
- .setUnitLabel(DictEnum.getLabel(DictTypeEnum.UNIT_TYPE.getType(), operationGoodsList.getUnit()))
|
|
|
- .setTaxRateLabel(DictEnum.getLabel(DictTypeEnum.TAX_RATE.getType(), operationGoodsList.getTaxRate()))
|
|
|
- .setPrepaidLimitLabel(Objects.equals(e.getPrepaidLimit(), 1) ? "是" : "否")
|
|
|
- .setAddress(addressMap.get(id)).setSupplyEnt(entMap.get(e.getSupplyEntId()))
|
|
|
- .setManageName(Objects.nonNull(manager) ? manager.getName() : null)
|
|
|
- .setPhone(Objects.nonNull(manager) ? manager.getPhone() : null)
|
|
|
- .setCreateByName(Objects.nonNull(createUser) ? createUser.getName() : null);
|
|
|
- List<KwpGoodsPriceRange> priceRanges = priceRangeMap.get(id);
|
|
|
- if (CollectionUtils.isNotEmpty(priceRanges)) {
|
|
|
- operationGoodsList.setHighestPrice(priceRanges.get(priceRanges.size() - 1).getPrice()).setLowestPrice(priceRanges.get(0).getPrice());
|
|
|
- }
|
|
|
- result.add(operationGoodsList);
|
|
|
- });
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @desc: 获取商品详情
|
|
|
* @author: lt
|
|
|
@@ -198,52 +136,8 @@ public class GoodsManagerService {
|
|
|
* @return: com.sckw.product.model.vo.res.GoodsDetail
|
|
|
*/
|
|
|
public OperationGoodsDetail getDetail(Long id) {
|
|
|
- KwpGoods goods = kwpGoodsMapper.selectById(id);
|
|
|
- if (Objects.isNull(goods)) {
|
|
|
- throw new BusinessException("当前商品不存在!");
|
|
|
- }
|
|
|
- OperationGoodsDetail detail = BeanUtils.copyProperties(goods, OperationGoodsDetail.class);
|
|
|
- Map<Long, EntCacheResDto> entMap = remoteSystemService.queryEntCacheMapByIds(Arrays.asList(detail.getEntId(), detail.getSupplyEntId()));
|
|
|
- EntCacheResDto ent = entMap.get(detail.getEntId());
|
|
|
- if (Objects.nonNull(ent)) {
|
|
|
- detail.setEnt(ent.getFirmName()).setEntHead(ent.getHead())
|
|
|
- .setEntBusiness(ent.getBusiness()).setEntAddress(ent.getCityName());
|
|
|
- }
|
|
|
- EntCacheResDto supplyEnt = entMap.get(detail.getSupplyEntId());
|
|
|
- if (Objects.nonNull(supplyEnt)) {
|
|
|
- detail.setSupplyEnt(supplyEnt.getFirmName());
|
|
|
- }
|
|
|
- UserCacheResDto managerInfo = remoteSystemService.queryUserCacheById(detail.getManager());
|
|
|
- if (Objects.nonNull(managerInfo)) {
|
|
|
- detail.setManagerName(managerInfo.getName()).setManagerPhone(managerInfo.getPhone());
|
|
|
- }
|
|
|
- detail.setGoodsTypeLabel(DictEnum.getLabel(DictTypeEnum.PRODUCT_NAME_TYPE.getType(), detail.getGoodsType()))
|
|
|
- .setUnitLabel(DictEnum.getLabel(DictTypeEnum.UNIT_TYPE.getType(), detail.getUnit()))
|
|
|
- .setTaxRateLabel(DictEnum.getLabel(DictTypeEnum.TAX_RATE.getType(), detail.getTaxRate()))
|
|
|
- .setStatusLabel(DictEnum.getLabel(DictTypeEnum.GOODS_STATUS.getType(), String.valueOf(detail.getStatus())))
|
|
|
- .setPrepaidLimitLabel(Objects.equals(detail.getPrepaidLimit(), 1) ? "是" : "否");
|
|
|
- //商品图片信息
|
|
|
- List<KwpGoodsImage> goodsImages = kwpGoodsImageService.getByGoodsId(id);
|
|
|
- List<GoodsImagesDetail> images = BeanUtils.copyToList(goodsImages, GoodsImagesDetail.class);
|
|
|
- //商品价格段信息
|
|
|
- List<KwpGoodsPriceRange> priceRanges = kwpGoodsPriceRangeService.getByGoodsId(id);
|
|
|
- List<GoodsPriceRangesDetail> ranges = BeanUtils.copyToList(priceRanges, GoodsPriceRangesDetail.class);
|
|
|
- ranges.stream().filter(r -> r.getEndAmount().compareTo(new BigDecimal("-1.00")) == 0)
|
|
|
- .forEach(r -> {
|
|
|
- r.setEndAmountLabel("不限");
|
|
|
- });
|
|
|
- //商品属性信息
|
|
|
- List<KwpGoodsAttribute> attributesList = kwpGoodsAttributeService.getByGoodsId(id);
|
|
|
- List<GoodsAttributesDetail> attributes = BeanUtils.copyToList(attributesList, GoodsAttributesDetail.class);
|
|
|
- //商品地址信息
|
|
|
- KwpGoodsAddress goodsAddress = kwpGoodsAddressService.getByGoodsId(id);
|
|
|
- AddressInfoDetail addressInfo = BeanUtils.copyProperties(goodsAddress, AddressInfoDetail.class);
|
|
|
- if (Objects.nonNull(addressInfo)) {
|
|
|
- addressInfo.setTypeName(DictEnum.getLabel(DictTypeEnum.ADDRESS_TYPE.getType(), addressInfo.getType()));
|
|
|
- }
|
|
|
- detail.setImages(images).setPriceRanges(ranges).setAttributes(attributes).setAddressInfo(addressInfo);
|
|
|
-
|
|
|
- return detail;
|
|
|
+ GoodsDetail goodsDetail = kwpGoodsService.detail(id);
|
|
|
+ return BeanUtils.copyProperties(goodsDetail, OperationGoodsDetail.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -287,24 +181,11 @@ public class GoodsManagerService {
|
|
|
public List<OperationGoodsListExport> export(OperatorGoodsExportQueryVO params) {
|
|
|
LambdaQueryWrapper<KwpGoods> wrapper = buildWrapper(BeanUtils.copyProperties(params, OperatorGoodsListQueryDTO.class));
|
|
|
List<KwpGoods> list = kwpGoodsMapper.selectList(wrapper);
|
|
|
- List<OperationGoodsList> goodsLists = buildGoodLists(list);
|
|
|
- if (CollectionUtils.isEmpty(goodsLists)) {
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- List<OperationGoodsListExport> result = new ArrayList<>();
|
|
|
- AtomicInteger i = new AtomicInteger(1);
|
|
|
- goodsLists.forEach(e -> {
|
|
|
- OperationGoodsListExport export = BeanUtils.copyProperties(e, OperationGoodsListExport.class);
|
|
|
- export.setSerialNumber(String.valueOf(i.getAndIncrement()))
|
|
|
- .setAmount(Objects.isNull(e.getAmount()) ? null : String.valueOf(e.getAmount()))
|
|
|
- .setHighestPrice(Objects.isNull(e.getHighestPrice()) ? null : String.valueOf(e.getHighestPrice()))
|
|
|
- .setLowestPrice(Objects.isNull(e.getLowestPrice()) ? null : String.valueOf(e.getLowestPrice()))
|
|
|
- .setAddedTime(Objects.isNull(e.getAddedTime()) ? null : DateUtil.getDateTime(e.getAddedTime()))
|
|
|
- .setShelfTime(Objects.isNull(e.getShelfTime()) ? null : DateUtil.getDateTime(e.getShelfTime()))
|
|
|
- .setCreateTime(Objects.isNull(e.getCreateTime()) ? null : DateUtil.getDateTime(e.getCreateTime()));
|
|
|
- result.add(export);
|
|
|
- });
|
|
|
- return result;
|
|
|
+ List<GoodsListExport> exportResults = kwpGoodsService.getExportResults(list);
|
|
|
+ return BeanUtils.copyToList(exportResults, OperationGoodsListExport.class);
|
|
|
}
|
|
|
|
|
|
|