refactor(sip): 优化产品信息查询和导入功能
- 新增按产品编码列表查询产品信息的方法 - 优化订单导入时的产品信息处理逻辑 - 修复项目产品信息保存时的产品编码校验问题 - 优化产品信息变更日志的生成逻辑master
parent
1a66bb45b1
commit
2be0ced2ce
|
@ -29,6 +29,7 @@ public interface ProductInfoMapper
|
|||
* @return 产品管理集合
|
||||
*/
|
||||
public List<ProductInfo> selectProductInfoList(ProductInfo productInfo);
|
||||
public List<ProductInfo> selectProductInfoByCodeList(List<String> productCodeList);
|
||||
|
||||
/**
|
||||
* 新增产品管理
|
||||
|
|
|
@ -63,4 +63,5 @@ public interface IProductInfoService
|
|||
public int deleteProductInfoById(Long id);
|
||||
|
||||
List<ProductInfo> query(MaintenanceRecordsDto dto);
|
||||
List<ProductInfo> selectProductInfoByCodeList(List<String> productCodeList);
|
||||
}
|
||||
|
|
|
@ -319,7 +319,9 @@ public class OrderInfoServiceImpl implements IOrderInfoService
|
|||
throw new ServiceException("excel模板错误,导入失败");
|
||||
}
|
||||
//只处理当前产品表有的数据
|
||||
List<ProductInfo> productInfos = productInfoService.selectProductInfoList(new ProductInfo());
|
||||
// List<ProductInfo> productInfos = productInfoService.selectProductInfoList(new ProductInfo());
|
||||
List<String> codeList = orderListList.stream().map(OrderList::getProductCode).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
||||
List<ProductInfo> productInfos = productInfoService.selectProductInfoByCodeList(codeList);
|
||||
Map<String, ProductInfo> productInfoMap = productInfos.stream().collect(Collectors.toMap(ProductInfo::getProductCode, Function.identity(), (v1, v2) -> v1));
|
||||
orderListList = orderListList.stream().filter(item -> item != null && StringUtils.isNotEmpty(item.getProductCode())
|
||||
&& productInfoMap.containsKey(item.getProductCode()))
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.ruoyi.sip.service.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.ShiroUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
@ -114,4 +116,12 @@ public class ProductInfoServiceImpl implements IProductInfoService
|
|||
}
|
||||
return productInfoMapper.query(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductInfo> selectProductInfoByCodeList(List<String> productCodeList) {
|
||||
if (CollUtil.isEmpty(productCodeList)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return productInfoMapper.selectProductInfoByCodeList(productCodeList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import java.time.ZoneId;
|
||||
|
@ -241,8 +242,9 @@ public class ProjectInfoServiceImpl implements IProjectInfoService {
|
|||
logIndex = compareField(logContent, logIndex, "代理商", oldProjectInfo.getPartnerName(), projectInfo.getPartnerName());
|
||||
logIndex = compareField(logContent, logIndex, "联系方式", oldProjectInfo.getContactWay(), projectInfo.getContactWay());
|
||||
logIndex = compareBigDecimalField(logContent, logIndex, "预计金额", oldProjectInfo.getEstimatedAmount(), projectInfo.getEstimatedAmount());
|
||||
logIndex = compareField(logContent, logIndex, "预计下单时间", oldProjectInfo.getEstimatedOrderTime(), projectInfo.getEstimatedOrderTime());
|
||||
logIndex = compareField(logContent, logIndex, "预计发货时间", oldProjectInfo.getEstimatedDeliverTime(), projectInfo.getEstimatedDeliverTime());
|
||||
logIndex = compareField(logContent, logIndex, "预计下单时间", formatterDate(oldProjectInfo.getEstimatedOrderTime()),
|
||||
formatterDate(projectInfo.getEstimatedOrderTime()));
|
||||
logIndex = compareField(logContent, logIndex, "预计发货时间", formatterDate(oldProjectInfo.getEstimatedDeliverTime()), formatterDate(projectInfo.getEstimatedDeliverTime()));
|
||||
logIndex = compareField(logContent, logIndex, "竞争对手", oldProjectInfo.getCompetitor(), projectInfo.getCompetitor());
|
||||
logIndex = compareField(logContent, logIndex, "关键技术问题", oldProjectInfo.getKeyProblem(), projectInfo.getKeyProblem());
|
||||
logIndex = compareField(logContent, logIndex, "项目简述", oldProjectInfo.getProjectDesc(), projectInfo.getProjectDesc());
|
||||
|
@ -297,6 +299,12 @@ public class ProjectInfoServiceImpl implements IProjectInfoService {
|
|||
}
|
||||
}
|
||||
|
||||
private String formatterDate(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date);
|
||||
}
|
||||
/**
|
||||
* 比较产品信息列表并生成日志内容
|
||||
*
|
||||
|
@ -323,11 +331,11 @@ public class ProjectInfoServiceImpl implements IProjectInfoService {
|
|||
|
||||
if (oldProduct == null && newProduct != null) {
|
||||
// 新增产品
|
||||
logContent.append(index).append(".").append(type).append("新增:").append(newProduct.getProductBomCode()).append("\n");
|
||||
logContent.append(index).append(".").append(type).append("新增:").append(StringUtils.isEmpty(newProduct.getProductBomCode()) ? "空" : newProduct.getProductBomCode()).append("\n");
|
||||
index++;
|
||||
} else if (oldProduct != null && newProduct == null) {
|
||||
// 删除产品
|
||||
logContent.append(index).append(".").append(type).append("删除:").append(oldProduct.getProductBomCode()).append("\n");
|
||||
logContent.append(index).append(".").append(type).append("删除:").append(StringUtils.isEmpty(oldProduct.getProductBomCode()) ? "空" : oldProduct.getProductBomCode()).append("\n");
|
||||
index++;
|
||||
} else if (oldProduct != null) {
|
||||
// 变更产品
|
||||
|
|
|
@ -3,9 +3,14 @@ package com.ruoyi.sip.service.impl;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.sip.domain.ProductInfo;
|
||||
import com.ruoyi.sip.service.IProductInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.sip.mapper.ProjectProductInfoMapper;
|
||||
|
@ -23,6 +28,8 @@ import com.ruoyi.common.core.text.Convert;
|
|||
public class ProjectProductInfoServiceImpl implements IProjectProductInfoService {
|
||||
@Autowired
|
||||
private ProjectProductInfoMapper projectProductInfoMapper;
|
||||
@Autowired
|
||||
private IProductInfoService productInfoService;
|
||||
|
||||
/**
|
||||
* 查询项目产品信息
|
||||
|
@ -97,6 +104,21 @@ public class ProjectProductInfoServiceImpl implements IProjectProductInfoService
|
|||
|
||||
@Override
|
||||
public void saveBatch(List<ProjectProductInfo> list) {
|
||||
//校验数据是否在产品库中
|
||||
List<String> codeList = list.stream().map(ProjectProductInfo::getProductBomCode).distinct().collect(Collectors.toList());
|
||||
List<ProductInfo> productInfos = productInfoService.selectProductInfoByCodeList(codeList);
|
||||
Set<String> existsProductCodeMapSet = productInfos.stream().map(ProductInfo::getProductCode).collect(Collectors.toSet());
|
||||
StringJoiner stringJoiner = new StringJoiner(",");
|
||||
for (String code : codeList) {
|
||||
if (!existsProductCodeMapSet.contains(code)) {
|
||||
stringJoiner.add(code);
|
||||
}
|
||||
}
|
||||
if (stringJoiner.length() > 0) {
|
||||
throw new ServiceException(StringUtils.format("产品编码[{}]在产品库中未找到,请确认后重试", stringJoiner.toString()));
|
||||
}
|
||||
|
||||
|
||||
List<ProjectProductInfo> projectProductInfos = projectProductInfoMapper.selectProjectProductInfoListByProjectId(list.get(0).getProjectId());
|
||||
Set<Long> idSet = list.stream().map(ProjectProductInfo::getId).collect(Collectors.toSet());
|
||||
String[] deleteIds = projectProductInfos.stream().filter(item -> !idSet.contains(item.getId())).map(item -> item.getId().toString()).toArray(String[]::new);
|
||||
|
|
|
@ -38,6 +38,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectProductInfoVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectProductInfoByCodeList" resultMap="ProductInfoResult">
|
||||
<include refid="selectProductInfoVo"/>
|
||||
where product_code in
|
||||
<foreach item="item" index="index" collection="list"
|
||||
open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="listByProductCodeList" resultMap="ProductInfoResult">
|
||||
<include refid="selectProductInfoVo"/>
|
||||
where product_code in
|
||||
|
|
Loading…
Reference in New Issue