|
|
|
@ -145,19 +145,22 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
|
|
|
// 新增:控制 item_no(每个PO递增) |
|
|
|
// 新增:控制 item_no(每个PO递增) |
|
|
|
Map<String, Integer> orderLineMap = new HashMap<>(); |
|
|
|
|
|
|
|
// 获取当前用户(避免循环里重复取) |
|
|
|
|
|
|
|
// 获取当前用户(避免循环里重复取) |
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
if (currentUser == null || currentUser.getSite() == null) { |
|
|
|
throw new RuntimeException("无法获取当前用户站点信息"); |
|
|
|
} |
|
|
|
String site = currentUser.getSite(); |
|
|
|
|
|
|
|
|
|
|
|
if (site == null) { |
|
|
|
throw new RuntimeException("当前用户site为空!"); |
|
|
|
throw new RuntimeException("当前用户site为空!"); |
|
|
|
} |
|
|
|
|
|
|
|
// 用于收集重复数据的信息 |
|
|
|
List<String> duplicateItems = new ArrayList<>(); |
|
|
|
// 转换并保存每条数据 |
|
|
|
for (PODetailExcelDTO excelDTO : excelList) { |
|
|
|
|
|
|
|
@ -216,13 +219,23 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ========== 2. 生成 item_no(核心) ========== |
|
|
|
// ========== 2. 检查是否重复 ========== |
|
|
|
String poNo = excelDTO.getPoNo(); |
|
|
|
String item = excelDTO.getItem(); |
|
|
|
|
|
|
|
// 检查数据库中是否已存在相同的订单号+款号 |
|
|
|
Integer existCount = baseMapper.countByOrderAndItem(poNo, site, item); |
|
|
|
if (existCount != null && existCount > 0) { |
|
|
|
duplicateItems.add("订单号: " + poNo + ", 款号: " + item); |
|
|
|
continue; // 跳过重复数据,继续处理下一条 |
|
|
|
} |
|
|
|
|
|
|
|
// ========== 3. 生成 item_no(核心) ========== |
|
|
|
Integer maxItemNo = baseMapper.getMaxItemNo(poNo, site); |
|
|
|
int lineNo = (maxItemNo == null ? 0 : maxItemNo) + 1; |
|
|
|
orderLineMap.put(poNo, lineNo); |
|
|
|
|
|
|
|
// ========== 3. 保存 PODetail ========== |
|
|
|
// ========== 4. 保存 PODetail ========== |
|
|
|
PODetailVo poDetailVo = new PODetailVo(); |
|
|
|
|
|
|
|
// 主键字段(必须) |
|
|
|
@ -276,6 +289,12 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 如果有重复数据,抛出异常并提示 |
|
|
|
if (!duplicateItems.isEmpty()) { |
|
|
|
String duplicateMsg = String.join("; ", duplicateItems); |
|
|
|
throw new RuntimeException("以下数据已存在,跳过保存: " + duplicateMsg); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException("文件读取失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
|