refactor(sip): 优化订单导入功能
- 新增校验产品编码是否重复的逻辑 - 增加折扣不能为空的校验 - 优化订单导入逻辑,支持增量更新 - 新增删除订单明细的接口和 SQLmaster
parent
a8ae726103
commit
688e9ef6f9
|
@ -30,6 +30,7 @@ public interface OrderInfoMapper
|
|||
* @return 合同档案集合
|
||||
*/
|
||||
public List<OrderInfo> selectOrderInfoList(OrderInfo orderInfo);
|
||||
public List<OrderList> selectOrderListList(Long id);
|
||||
|
||||
/**
|
||||
* 新增合同档案
|
||||
|
@ -87,6 +88,7 @@ public interface OrderInfoMapper
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteOrderListByOrderId(Long id);
|
||||
public int deleteOrderListById(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 删除合同清单
|
||||
|
|
|
@ -196,13 +196,26 @@ public class OrderInfoServiceImpl implements IOrderInfoService
|
|||
@Override
|
||||
public AjaxResult listImportData(List<OrderList> orderListList, Long orderId) {
|
||||
Assert.notNull(orderId, "合同ID不能为空");
|
||||
List<String> productCodeList = orderListList.stream().map(OrderList::getProductCode).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
List<String> productCodeList = orderListList.stream()
|
||||
.map(OrderList::getProductCode)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 校验productCode是否重复
|
||||
Set<String> uniqueProductCodes = new HashSet<>(productCodeList);
|
||||
if (uniqueProductCodes.size() != productCodeList.size()) {
|
||||
return AjaxResult.error("产品编码在excel中存在重复");
|
||||
}
|
||||
|
||||
if (productCodeList.isEmpty()) {
|
||||
return AjaxResult.error("文件为空或产品编码为空");
|
||||
}
|
||||
for (OrderList orderList : orderListList) {
|
||||
orderList.setOrderId(orderId);
|
||||
if (orderList.getDiscount() != null && (orderList.getDiscount().compareTo(BigDecimal.ONE) > 0 || orderList.getDiscount().compareTo(BigDecimal.ZERO) <= 0)) {
|
||||
if (orderList.getDiscount() == null) {
|
||||
return AjaxResult.error("折扣不能为空");
|
||||
}
|
||||
if (orderList.getDiscount().compareTo(BigDecimal.ONE) > 0 || orderList.getDiscount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return AjaxResult.error("折扣区间需在0-1之间");
|
||||
}
|
||||
if (orderList.getPrice() == null) {
|
||||
|
@ -218,11 +231,61 @@ public class OrderInfoServiceImpl implements IOrderInfoService
|
|||
}
|
||||
orderList.setAmount(amount);
|
||||
}
|
||||
orderInfoMapper.deleteOrderListByOrderId(orderId);
|
||||
orderInfoMapper.batchOrderList(orderListList);
|
||||
// orderInfoMapper.deleteOrderListByOrderId(orderId);
|
||||
// orderInfoMapper.batchOrderList(orderListList);
|
||||
List<OrderList> orderInfoList = orderInfoMapper.selectOrderListList(orderId);
|
||||
Map<String, List<OrderList>> stringListMap = compareOrderLists(orderInfoList, orderListList);
|
||||
List<OrderList> deleteList = stringListMap.get("removed");
|
||||
List<OrderList> addList = stringListMap.get("added");
|
||||
List<OrderList> updateList = stringListMap.get("modified");
|
||||
if (CollUtil.isNotEmpty(addList)) {
|
||||
orderInfoMapper.batchOrderList(addList);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(deleteList)) {
|
||||
orderInfoMapper.deleteOrderListById(deleteList.stream().map(OrderList::getId).collect(Collectors.toList()));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(updateList)) {
|
||||
orderInfoMapper.updateListBatch(updateList);
|
||||
}
|
||||
return AjaxResult.success("导入成功");
|
||||
}
|
||||
public Map<String, List<OrderList>> compareOrderLists(List<OrderList> orderInfoList, List<OrderList> orderListList) {
|
||||
// 创建一个映射,用于快速查找订单
|
||||
Map<String, OrderList> orderInfoMap = orderInfoList.stream()
|
||||
.collect(Collectors.toMap(OrderList::getProductCode, order -> order));
|
||||
|
||||
Map<String, OrderList> orderListMap = orderListList.stream()
|
||||
.collect(Collectors.toMap(OrderList::getProductCode, order -> order));
|
||||
|
||||
// 找出新增的订单
|
||||
List<OrderList> addedOrders = orderListList.stream()
|
||||
.filter(order -> !orderInfoMap.containsKey(order.getProductCode()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 找出删除的订单
|
||||
List<OrderList> removedOrders = orderInfoList.stream()
|
||||
.filter(order -> !orderListMap.containsKey(order.getProductCode()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 找出需要修改的订单
|
||||
List<OrderList> modifiedOrders = orderListList.stream()
|
||||
.filter(order -> orderInfoMap.containsKey(order.getProductCode()))
|
||||
.filter(order -> !order.equals(orderInfoMap.get(order.getProductCode())))
|
||||
.collect(Collectors.toList());
|
||||
// 修改的订单添加id
|
||||
for (OrderList modifiedOrder : modifiedOrders) {
|
||||
OrderList orderList = orderInfoMap.get(modifiedOrder.getProductCode());
|
||||
modifiedOrder.setId(orderList.getId());
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
Map<String, List<OrderList>> result = new HashMap<>();
|
||||
result.put("added", addedOrders);
|
||||
result.put("removed", removedOrders);
|
||||
result.put("modified", modifiedOrders);
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 查询代表处信息并构建映射
|
||||
*/
|
||||
|
|
|
@ -343,6 +343,12 @@
|
|||
from order_list
|
||||
where order_id = #{orderId}
|
||||
</delete>
|
||||
<delete id="deleteOrderListById">
|
||||
delete from order_list where id in
|
||||
<foreach item="item" index="index" collection="list" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="batchOrderList">
|
||||
insert into order_list(id , order_id, product_code, quantity, price, amount,discount,remark, created_at, updated_at) values
|
||||
|
|
Loading…
Reference in New Issue