|
|
@@ -314,6 +314,28 @@ public class CostProjectTaskSurveyGenericController {
|
|
|
data.setType(type);
|
|
|
}
|
|
|
|
|
|
+ // 计算并设置 orderNum(仅针对核定表 type=3)
|
|
|
+ if ("3".equals(type) && StringUtil.isNotEmpty(surveyTemplateId)) {
|
|
|
+ // 收集所有 rowId 和 parentId
|
|
|
+ Map<String, String> rowIdToParentIdMap = new HashMap<>();
|
|
|
+ for (CostSurveyTemplateUploadData data : dataList) {
|
|
|
+ if (StringUtil.isNotEmpty(data.getRowid())) {
|
|
|
+ rowIdToParentIdMap.put(data.getRowid(), data.getParentId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算 orderNum
|
|
|
+ Map<String, Integer> rowIdToOrderNum = calculateOrderNumForVerify(surveyTemplateId, rowIdToParentIdMap);
|
|
|
+
|
|
|
+ // 为每条数据设置 orderNum
|
|
|
+ for (CostSurveyTemplateUploadData data : dataList) {
|
|
|
+ Integer orderNum = rowIdToOrderNum.get(data.getRowid());
|
|
|
+ if (orderNum != null) {
|
|
|
+ data.setOrderNum(orderNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
costSurveyTemplateUploadDataManager.saveData(dataList);
|
|
|
|
|
|
// 更新成本调查表
|
|
|
@@ -1557,6 +1579,7 @@ public class CostProjectTaskSurveyGenericController {
|
|
|
// 读取数据行
|
|
|
List<CostSurveyTemplateUploadData> dataList = new ArrayList<>();
|
|
|
Map<String, Integer> rowIdToExcelRowMap = new HashMap<>();
|
|
|
+ Map<String, String> rowIdToParentIdMap = new HashMap<>();
|
|
|
int importRowCount = 0;
|
|
|
|
|
|
// 从第2行开始读取数据(第0行是标题,第1行是表头)
|
|
|
@@ -1595,6 +1618,7 @@ public class CostProjectTaskSurveyGenericController {
|
|
|
parentRowId = parentRowId.trim();
|
|
|
}
|
|
|
}
|
|
|
+ rowIdToParentIdMap.put(currentRowId, parentRowId);
|
|
|
|
|
|
for (Map.Entry<Integer, CostVerifyTemplateHeaders> entry : columnIndexMap.entrySet()) {
|
|
|
Cell cell = dataRow.getCell(entry.getKey());
|
|
|
@@ -1615,6 +1639,17 @@ public class CostProjectTaskSurveyGenericController {
|
|
|
return CommonResult.<String>error().message("Excel文件没有有效数据");
|
|
|
}
|
|
|
|
|
|
+ // 计算 orderNum:根据模板的排序规则计算每个 rowId 的序号
|
|
|
+ Map<String, Integer> rowIdToOrderNum = calculateOrderNumForVerify(surveyTemplateId, rowIdToParentIdMap);
|
|
|
+
|
|
|
+ // 为每条数据设置 orderNum
|
|
|
+ for (CostSurveyTemplateUploadData data : dataList) {
|
|
|
+ Integer orderNum = rowIdToOrderNum.get(data.getRowid());
|
|
|
+ if (orderNum != null) {
|
|
|
+ data.setOrderNum(orderNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 保存数据(核定表不需要复杂的字段校验)
|
|
|
costSurveyTemplateUploadDataManager.saveData(dataList);
|
|
|
|
|
|
@@ -1635,6 +1670,34 @@ public class CostProjectTaskSurveyGenericController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
+ * 计算核定表的 orderNum(根据模板的排序规则)
|
|
|
+ */
|
|
|
+ private Map<String, Integer> calculateOrderNumForVerify(String surveyTemplateId, Map<String, String> rowIdToParentIdMap) {
|
|
|
+ Map<String, Integer> result = new HashMap<>();
|
|
|
+
|
|
|
+ // 获取模板项
|
|
|
+ List<CostVerifyTemplateItems> itemsList = costVerifyTemplateItemsDao.selectByVerifyTemplateId(surveyTemplateId, null);
|
|
|
+ if (itemsList == null || itemsList.isEmpty()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按 rowid 分组
|
|
|
+ Map<String, List<CostVerifyTemplateItems>> itemsByRowId = itemsList.stream()
|
|
|
+ .filter(item -> StringUtil.isNotEmpty(item.getRowid()))
|
|
|
+ .collect(Collectors.groupingBy(CostVerifyTemplateItems::getRowid));
|
|
|
+
|
|
|
+ // 按父子关系排序(使用与导出相同的排序逻辑)
|
|
|
+ List<String> sortedRowIds = sortRowIdsByParentChildVerify(itemsByRowId);
|
|
|
+
|
|
|
+ // 构建 rowId -> orderNum 的映射(orderNum 从 1 开始)
|
|
|
+ for (int i = 0; i < sortedRowIds.size(); i++) {
|
|
|
+ result.put(sortedRowIds.get(i), i + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取友好的行号显示
|
|
|
*/
|
|
|
private String getRowDisplay(String rowid, Map<String, Integer> rowIdToExcelRowMap) {
|
|
|
@@ -3108,6 +3171,12 @@ public class CostProjectTaskSurveyGenericController {
|
|
|
int totalCellsWritten = 0;
|
|
|
int cellsSkippedNoMapping = 0;
|
|
|
|
|
|
+ // 构建 rowId -> orderNum 的映射(orderNum 从 1 开始)
|
|
|
+ Map<String, Integer> rowIdToOrderNum = new HashMap<>();
|
|
|
+ for (int i = 0; i < sortedRowIds.size(); i++) {
|
|
|
+ rowIdToOrderNum.put(sortedRowIds.get(i), i + 1);
|
|
|
+ }
|
|
|
+
|
|
|
for (String rowId : sortedRowIds) {
|
|
|
List<CostVerifyTemplateItems> rowItems = itemsByRowId.get(rowId);
|
|
|
if (rowItems != null && !rowItems.isEmpty()) {
|