|
|
|
@ -52,9 +52,20 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
public void saveModel(PODetailVo model){ |
|
|
|
PODetail poDetail = new PODetail(); |
|
|
|
BeanUtils.copyProperties(model, poDetail); |
|
|
|
|
|
|
|
// 获取当前用户 |
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String currentUserName = currentUser != null ? currentUser.getUsername() : "system"; |
|
|
|
Date currentTime = new Date(); |
|
|
|
|
|
|
|
if(model.getId() != null){ |
|
|
|
// 编辑保存:更新 c_edit(修改时间)和 c_end_planner(修改人) |
|
|
|
poDetail.setEdit(currentTime); |
|
|
|
poDetail.setEndPlanner(currentUserName); |
|
|
|
baseMapper.updateById(poDetail); |
|
|
|
} else { |
|
|
|
// 新增保存:设置 create_time(创建时间) |
|
|
|
poDetail.setCreateTime(currentTime); |
|
|
|
baseMapper.insert(poDetail); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -101,6 +112,11 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取当前用户和时间 |
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String currentUserName = currentUser != null ? currentUser.getUsername() : "system"; |
|
|
|
Date currentTime = new Date(); |
|
|
|
|
|
|
|
// 主表跟明细为1对1关系,所以主表跟明细一起更新 |
|
|
|
List<POHeader> poHeaders = new ArrayList<>(); |
|
|
|
poDetailVoList.forEach(model -> { |
|
|
|
@ -111,6 +127,10 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
BeanUtils.copyProperties(model, poHeader); |
|
|
|
poHeader.setId(model.getPoHeaderId()); |
|
|
|
poHeaders.add(poHeader); |
|
|
|
|
|
|
|
// 设置 PODetail 的审计字段:c_edit(修改时间)和 c_end_planner(修改人) |
|
|
|
model.setEdit(currentTime); |
|
|
|
model.setEndPlanner(currentUserName); |
|
|
|
}); |
|
|
|
|
|
|
|
//更新主表 |
|
|
|
@ -147,23 +167,23 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
|
|
|
|
// 新增:控制 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为空!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 用于收集重复数据的信息 |
|
|
|
List<String> duplicateItems = new ArrayList<>(); |
|
|
|
// 用于收集错误信息 |
|
|
|
List<String> errorMessages = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 转换并保存每条数据 |
|
|
|
int rowNum = 1; // Excel行号(从1开始,第1行是标题) |
|
|
|
for (PODetailExcelDTO excelDTO : excelList) { |
|
|
|
@ -224,17 +244,9 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
throw new RuntimeException("保存 POHeader 失败,订单号: " + excelDTO.getPoNo()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ========== 2. 检查是否重复 ========== |
|
|
|
String poNo = excelDTO.getPoNo(); |
|
|
|
|
|
|
|
// 检查数据库中是否已存在相同的订单号(使用订单号+站点判断) |
|
|
|
Integer existCount = baseMapper.countByOrderAndItem(poNo, site); |
|
|
|
if (existCount != null && existCount > 0) { |
|
|
|
duplicateItems.add("第" + rowNum + "行 - 订单号: " + poNo); |
|
|
|
continue; // 跳过重复数据,继续处理下一条 |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 3. 生成 item_no(核心) ========== |
|
|
|
Integer maxItemNo = baseMapper.getMaxItemNo(poNo, site); |
|
|
|
int lineNo = (maxItemNo == null ? 0 : maxItemNo) + 1; |
|
|
|
@ -265,8 +277,8 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
if (advancePaymentInput != null && !advancePaymentInput.trim().isEmpty()) { |
|
|
|
String trimmed = advancePaymentInput.trim(); |
|
|
|
// 支持中文"是"、英文"Y"或"Yes"(不区分大小写) |
|
|
|
needAdvance = "是".equals(trimmed) |
|
|
|
|| "Y".equalsIgnoreCase(trimmed) |
|
|
|
needAdvance = "是".equals(trimmed) |
|
|
|
|| "Y".equalsIgnoreCase(trimmed) |
|
|
|
|| "YES".equalsIgnoreCase(trimmed); |
|
|
|
} |
|
|
|
poDetailVo.setAdvancePayment(needAdvance ? "Y" : "N"); |
|
|
|
@ -313,7 +325,7 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
String errorMsg = "导入过程中发现 " + errorMessages.size() + " 个错误:\n" + String.join("\n", errorMessages); |
|
|
|
throw new RuntimeException(errorMsg); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果有重复数据,抛出异常并提示 |
|
|
|
if (!duplicateItems.isEmpty()) { |
|
|
|
String duplicateMsg = "以下数据已存在,跳过保存:\n" + String.join("\n", duplicateItems); |
|
|
|
|