|
|
@@ -1,16 +1,13 @@ |
|
|
|
package com.hz.pm.api.common.util; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelReader; |
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
|
import com.hz.pm.api.projectlib.entity.ProjectGovSystemReplaceInfos; |
|
|
|
import com.hz.pm.api.projectlib.model.enumeration.GovSystemReplaceTypeEnum; |
|
|
|
import com.ningdatech.basic.util.CollUtils; |
|
|
|
|
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
@@ -26,32 +23,29 @@ public class UpdateProjectSystemReplaceInfoBatchNoUtil { |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
ExcelReader reader = ExcelUtil.getReader("/Users/wendy/Desktop/response.xls"); |
|
|
|
ExcelReader reader = ExcelUtil.getReader("/Users/wendy/Desktop/2024.xls"); |
|
|
|
List<ProjectGovSystemReplaceInfos> replaceInfos = reader.readAll(ProjectGovSystemReplaceInfos.class); |
|
|
|
CollUtils.group(replaceInfos, ProjectGovSystemReplaceInfos::getProjectCode).forEach((k, v) -> { |
|
|
|
v.sort(Comparator.comparing(ProjectGovSystemReplaceInfos::getBatchNo)); |
|
|
|
Integer batchNo = CollUtil.getLast(v).getBatchNo(); |
|
|
|
if (batchNo == 1 && v.size() > 1) { |
|
|
|
Set<String> targetSystsems = CollUtils.fieldSet(v, ProjectGovSystemReplaceInfos::getTargetSystem); |
|
|
|
if (targetSystsems.size() > 1 && CollUtils.fieldSet(v, ProjectGovSystemReplaceInfos::getReplaceType).size() == 1) { |
|
|
|
// System.out.println("项目编码:" + k); |
|
|
|
// System.out.println(JSONUtil.toJsonStr(targetSystsems)); |
|
|
|
Map<String, List<ProjectGovSystemReplaceInfos>> group = CollUtils.group(v, ProjectGovSystemReplaceInfos::getTargetSystem); |
|
|
|
AtomicInteger newBatchNo = new AtomicInteger(0); |
|
|
|
group.entrySet().stream().sorted(Comparator.comparing(w -> { |
|
|
|
w.getValue().sort(Comparator.comparing(ProjectGovSystemReplaceInfos::getId)); |
|
|
|
return w.getValue().get(0).getId(); |
|
|
|
})).forEach(entry -> { |
|
|
|
int currBatchNo = newBatchNo.incrementAndGet(); |
|
|
|
for (ProjectGovSystemReplaceInfos infos : entry.getValue()) { |
|
|
|
String sql = String.format("update ND_PROJECT_GOV_SYSTEM_REPLACE_INFOS set batch_no = %d where id = %d;", currBatchNo, infos.getId()); |
|
|
|
System.out.println(sql); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
Map<Boolean, List<ProjectGovSystemReplaceInfos>> map = CollUtils.group(replaceInfos, w -> w.getId() == null); |
|
|
|
List<ProjectGovSystemReplaceInfos> oldEntities = map.get(Boolean.FALSE); |
|
|
|
for (ProjectGovSystemReplaceInfos entity : oldEntities) { |
|
|
|
String updateSql = String.format("update ND_PROJECT_GOV_SYSTEM_REPLACE_INFOS set source_system = '%s', target_system = '%s', batch_no = %d, replace_type = '%s' where id = %d;", entity.getSourceSystem(), entity.getTargetSystem(), entity.getBatchNo(), |
|
|
|
GovSystemReplaceTypeEnum.getByVal(entity.getReplaceType()).get().getCode() |
|
|
|
, entity.getId()); |
|
|
|
System.out.println(updateSql); |
|
|
|
} |
|
|
|
List<ProjectGovSystemReplaceInfos> newEntities = map.get(Boolean.TRUE); |
|
|
|
for (ProjectGovSystemReplaceInfos entity : newEntities) { |
|
|
|
String insertSql = String.format("INSERT INTO ND_PROJECT_GOV_SYSTEM_REPLACE_INFOS (SOURCE_SYSTEM, TARGET_SYSTEM, REPLACE_TYPE, PROJECT_ID, BATCH_NO, CREATE_BY, CREATE_ON, PROJECT_CODE) \n" + |
|
|
|
"VALUES('%s', '%s', '%d', %d, %d, 150, '2024-08-22 14:27:11.822', '%s');", |
|
|
|
entity.getSourceSystem(), |
|
|
|
entity.getTargetSystem(), |
|
|
|
GovSystemReplaceTypeEnum.getByVal(entity.getReplaceType()).get().getCode(), |
|
|
|
entity.getProjectId(), |
|
|
|
entity.getBatchNo(), |
|
|
|
entity.getProjectCode()); |
|
|
|
System.out.println(insertSql); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |