|
@@ -0,0 +1,142 @@
|
|
|
+package com.fjhx.supply.service.supplier.impl;
|
|
|
+
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
+import com.fjhx.item.service.product.ProductClassifyService;
|
|
|
+import com.fjhx.item.service.product.ProductInfoService;
|
|
|
+import com.fjhx.supply.entity.supplier.dto.SupplierPriceDto;
|
|
|
+import com.fjhx.supply.entity.supplier.dto.SupplierPriceSelectDto;
|
|
|
+import com.fjhx.supply.entity.supplier.po.SupplierInfo;
|
|
|
+import com.fjhx.supply.entity.supplier.po.SupplierPrice;
|
|
|
+import com.fjhx.supply.entity.supplier.vo.SupplierPriceAddVo;
|
|
|
+import com.fjhx.supply.entity.supplier.vo.SupplierPriceVo;
|
|
|
+import com.fjhx.supply.mapper.supplier.SupplierPriceMapper;
|
|
|
+import com.fjhx.supply.service.supplier.SupplierPriceService;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 供应商价格 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author zlj
|
|
|
+ * @since 2023-03-17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SupplierPriceServiceImpl extends ServiceImpl<SupplierPriceMapper, SupplierPrice> implements SupplierPriceService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductClassifyService productClassifyService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<SupplierPriceVo> getPage(SupplierPriceSelectDto dto) {
|
|
|
+ IWrapper<SupplierPrice> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("sp", SupplierPrice::getId);
|
|
|
+ wrapper.eq("si", SupplierInfo::getType, dto.getSupplierType());
|
|
|
+ wrapper.keyword(dto,
|
|
|
+ new SqlField("si.name")
|
|
|
+ );
|
|
|
+ Page<SupplierPriceVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<SupplierPriceVo> records = page.getRecords();
|
|
|
+
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.ITEM);
|
|
|
+ productInfoService.attributeAssign(records, SupplierPrice::getProductInfoId, (item, product) -> {
|
|
|
+ item.setDefinition(product.getDefinition());
|
|
|
+ item.setProductClassifyId(product.getProductClassifyId());
|
|
|
+ item.setProductType(product.getType());
|
|
|
+ item.setProductCode(product.getCode());
|
|
|
+ item.setProductName(product.getName());
|
|
|
+ item.setProductSpec(product.getSpec());
|
|
|
+ item.setProductUnit(product.getUnit());
|
|
|
+ });
|
|
|
+
|
|
|
+ productClassifyService.attributeAssign(records, SupplierPriceVo::getProductClassifyId, (item, productClassify) -> {
|
|
|
+ item.setProductClassifyName(productClassify.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+ DynamicDataSourceContextHolder.clear();
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SupplierPriceAddVo add(SupplierPriceDto supplierPriceDto) {
|
|
|
+ SupplierPriceAddVo supplierPriceAddVo = new SupplierPriceAddVo();
|
|
|
+
|
|
|
+ // 添加产品列表
|
|
|
+ List<SupplierPrice> supplierPriceList = supplierPriceDto.getSupplierPriceList();
|
|
|
+ // 添加产品id列表
|
|
|
+ List<Long> productInfoIdList = supplierPriceList.stream().map(SupplierPrice::getProductInfoId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 供应商id
|
|
|
+ Long supplierInfoId = supplierPriceDto.getSupplierInfoId();
|
|
|
+
|
|
|
+ // 存在供应商价格列表
|
|
|
+ List<SupplierPrice> existSupplierPriceList = list(q -> q
|
|
|
+ .eq(SupplierPrice::getSupplierInfoId, supplierInfoId)
|
|
|
+ .in(SupplierPrice::getProductInfoId, productInfoIdList));
|
|
|
+
|
|
|
+ if (existSupplierPriceList.size() == 0) {
|
|
|
+ supplierPriceList.forEach(item -> item.setSupplierInfoId(supplierPriceDto.getSupplierInfoId()));
|
|
|
+ saveBatch(supplierPriceList);
|
|
|
+ supplierPriceAddVo.setAddSuccess(true);
|
|
|
+ return supplierPriceAddVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 存在价格更新
|
|
|
+ if (supplierPriceDto.isRenewWhileItExists()) {
|
|
|
+
|
|
|
+ // 产品id,明细map
|
|
|
+ Map<Long, SupplierPrice> map = existSupplierPriceList.stream()
|
|
|
+ .collect(Collectors.toMap(SupplierPrice::getProductInfoId, Function.identity()));
|
|
|
+
|
|
|
+ for (SupplierPrice supplierPrice : supplierPriceList) {
|
|
|
+ supplierPrice.setSupplierInfoId(supplierInfoId);
|
|
|
+
|
|
|
+ SupplierPrice existSupplierPrice = map.get(supplierPrice.getProductInfoId());
|
|
|
+ if (existSupplierPrice != null) {
|
|
|
+ supplierPrice.setId(existSupplierPrice.getId());
|
|
|
+ supplierPrice.setPrice(existSupplierPrice.getPrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saveOrUpdateBatch(supplierPriceList);
|
|
|
+ supplierPriceAddVo.setAddSuccess(true);
|
|
|
+ return supplierPriceAddVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 存在价格不更新
|
|
|
+ supplierPriceAddVo.setExistSupplierPriceList(existSupplierPriceList);
|
|
|
+ return supplierPriceAddVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(SupplierPriceDto supplierPriceDto) {
|
|
|
+ supplierPriceDto.setSupplierInfoId(null);
|
|
|
+ supplierPriceDto.setProductInfoId(null);
|
|
|
+
|
|
|
+ this.updateById(supplierPriceDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|