From f9020cc3f4bdca4128c5ad7166d5f10580017218 Mon Sep 17 00:00:00 2001 From: fl <3098731433@qq.com> Date: Mon, 7 Jul 2025 10:56:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=97=E7=BD=91,epc=E5=92=8C=E5=9B=BD?= =?UTF-8?q?=E7=BD=91=E6=A8=A1=E6=9D=BF=E4=B8=8B=E8=BC=89=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bonus/tool/dto/ComOtherPersonBean.java | 5 ++ .../service/impl/StateGridServiceImpl.java | 82 ++++++++++++++++--- .../com/bonus/tool/template/TestGWDOC.java | 2 +- 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/search-tool/src/main/java/com/bonus/tool/dto/ComOtherPersonBean.java b/search-tool/src/main/java/com/bonus/tool/dto/ComOtherPersonBean.java index 3481824..3ce4e7a 100644 --- a/search-tool/src/main/java/com/bonus/tool/dto/ComOtherPersonBean.java +++ b/search-tool/src/main/java/com/bonus/tool/dto/ComOtherPersonBean.java @@ -78,4 +78,9 @@ public class ComOtherPersonBean extends PersonFileBean{ */ private String workType; + /** + * 身份证 + */ + private String idCard; + } diff --git a/search-tool/src/main/java/com/bonus/tool/service/impl/StateGridServiceImpl.java b/search-tool/src/main/java/com/bonus/tool/service/impl/StateGridServiceImpl.java index 985ece8..98b28a8 100644 --- a/search-tool/src/main/java/com/bonus/tool/service/impl/StateGridServiceImpl.java +++ b/search-tool/src/main/java/com/bonus/tool/service/impl/StateGridServiceImpl.java @@ -22,6 +22,8 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.time.LocalDate; +import java.time.Period; import java.util.*; import java.util.stream.Collectors; @@ -343,7 +345,7 @@ public class StateGridServiceImpl implements StateGridService { Map map2 = new HashMap<>(); List> imgList = new ArrayList<>(); // 项目合同关键页图片 map2.put("proName", item.getProName() != null ? item.getProName() : ""); // 项目名称 - map2.put("voltageLevel", item.getVoltage() != null ? item.getProName() : ""); // 电压等级 + map2.put("voltageLevel", item.getVoltage() != null ? item.getVoltage() : ""); // 电压等级 map2.put("proLocation", item.getProjectLocation() != null ? item.getProjectLocation() : ""); // 项目所在地 map2.put("employerName", item.getOwnerUnit() != null ? item.getOwnerUnit() : ""); // 发包人名称 map2.put("employerAddress", item.getOwnerLocation() != null ? item.getOwnerLocation() : ""); // 发包人地址 @@ -401,9 +403,10 @@ public class StateGridServiceImpl implements StateGridService { Map map2 = new HashMap<>(); List proList = new ArrayList<>(); List> zjProList = new ArrayList<>(); + Map ageAndGender = getAgeAndGender(item.getIdCard()); map2.put("name", item.getUserName() != null ? item.getUserName() : ""); // 姓名 - map2.put("sex", ""); // 性别 - map2.put("age", item.getAge() != null ? item.getAge() : ""); // 年龄 + map2.put("sex", ageAndGender.get("gender")); // 性别 + map2.put("age", ageAndGender.get("age")); // 年龄 map2.put("title", item.getTitle() != null ? item.getTitle() : ""); // 职称 map2.put("majorStudied", item.getMajor() != null ? item.getMajor() : ""); // 所学专业 map2.put("graduationSchool", item.getAlmaMater() != null ? item.getAlmaMater() : ""); // 毕业学校 @@ -507,7 +510,18 @@ public class StateGridServiceImpl implements StateGridService { //本项目现场作业人员统计表 if (tbData.getComOtherList() != null && !tbData.getComOtherList().isEmpty()) { - for (ComOtherPersonBean item : tbData.getComOtherList()) { + //使用 Java 8 Stream 进行分组、排序并每组只取一个 + Map groupedMap = tbData.getComOtherList().stream() + .filter(Objects::nonNull) // 非空过滤 + .sorted(Comparator.comparing(ComOtherPersonBean::getPostName)) // 按 postName 排序 + .collect(Collectors.toMap( + ComOtherPersonBean::getPostName, // 分组字段 + item -> item, // 当前元素本身 + (existing, replacement) -> existing // 如果键冲突,保留第一个出现的元素 + )); + // 获取去重后的有序列表 + List result = new ArrayList<>(groupedMap.values()); + for (ComOtherPersonBean item : result) { //表格 数据 Map map = new HashMap<>(); map.put("name", item.getUserName() != null ? item.getUserName() : "" ); // 姓名 @@ -516,7 +530,7 @@ public class StateGridServiceImpl implements StateGridService { map.put("zc", item.getTitle() != null ? item.getTitle() : "" ); // 职称\技能 map.put("major",item.getMajor() != null ? item.getMajor() : "" ); // 专业 map.put("zsCode", item.getDiplomaNum() != null ? item.getDiplomaNum() : ""); // 证书号 - map.put("post", item.getPostName() != null ? item.getPostName() : ""); // 工种 + map.put("post", ""); // 工种 map.put("tsCode", ""); // 特殊作业操作证书号 map.put("dwCode", ""); // 电网建设作业人员资格认定证书号 list7.add(map); @@ -526,7 +540,6 @@ public class StateGridServiceImpl implements StateGridService { // 投入本项目主要项目团队(施工团队)一览表 if (tbData.getComOtherList() != null && !tbData.getComOtherList().isEmpty()) { - //使用 Java 8 Stream 进行分组、排序并每组只取一个 Map groupedMap = tbData.getComOtherList().stream() .filter(Objects::nonNull) // 非空过滤 @@ -541,9 +554,10 @@ public class StateGridServiceImpl implements StateGridService { for (ComOtherPersonBean item : result) { Map map = new HashMap<>(); List proList = new ArrayList<>(); + Map ageAndGender = getAgeAndGender(item.getIdCard()); map.put("name", item.getUserName() != null ? item.getUserName() : ""); // 姓名 - map.put("sex", ""); // 性别 - map.put("age", ""); // 年龄 + map.put("sex", ageAndGender.get("sex")); // 性别 + map.put("age", ageAndGender.get("gender")); // 年龄 map.put("title", item.getTitle() != null ? item.getTitle() : ""); // 职称 map.put("majorStudied", item.getMajor() != null ? item.getMajor() : ""); // 所学专业 map.put("graduationSchool", ""); // 毕业学校 @@ -899,8 +913,16 @@ public class StateGridServiceImpl implements StateGridService { jlMap.put("card", item.getIdCard() != null ? item.getIdCard() : ""); jlMap.put("xl", item.getEducation() != null ? item.getEducation() : ""); jlMap.put("zc", item.getTitle() != null ? item.getTitle() : ""); - jlMap.put("zs", item.getDiploma() != null ? item.getDiploma() : ""); - jlMap.put("bh", item.getDiplomaNum() != null ? item.getDiplomaNum() : ""); + StringBuilder diploma = new StringBuilder(); + StringBuilder diplomaNum = new StringBuilder(); + if(item.getCertList() != null && !item.getCertList().isEmpty()){ + item.getCertList().forEach(item2 -> { + diploma.append(item2.getDiploma()).append(" "); + diplomaNum.append(item2.getDiplomaNum()).append(" "); + }); + } + jlMap.put("zs",diploma); + jlMap.put("bh", diplomaNum); jlMap.put("rcdate", item.getEinDate() != null ? item.getEinDate() : ""); jlMap.put("tcDate", item.getExitDate() != null ? item.getExitDate() : ""); // 处理业绩经历 @@ -989,6 +1011,46 @@ public class StateGridServiceImpl implements StateGridService { } } + /** + * 根据18位身份证号获取年龄和性别,并返回Map + * + * @param idCard 18位身份证号 + * @return 包含年龄和性别的Map,例如:{ "age": 25, "gender": "男" } + */ + public static Map getAgeAndGender(String idCard) { + Map result = new HashMap<>(); + if (idCard == null || idCard.length() != 18) { + result.put("age", ""); + result.put("gender", ""); + return result; + } + // 提取出生年月日 + String yearStr = idCard.substring(6, 10); + String monthStr = idCard.substring(10, 12); + String dayStr = idCard.substring(12, 14); + + int birthYear = Integer.parseInt(yearStr); + int birthMonth = Integer.parseInt(monthStr); + int birthDay = Integer.parseInt(dayStr); + + // 当前日期和出生日期 + LocalDate today = LocalDate.now(); + LocalDate birthDate = LocalDate.of(birthYear, birthMonth, birthDay); + + // 计算年龄 + int age = Period.between(birthDate, today).getYears(); + + // 判断性别(第17位,索引为16) + int genderDigit = Character.getNumericValue(idCard.charAt(16)); + String gender = (genderDigit % 2 == 1) ? "男" : "女"; + + // 放入Map中 + result.put("age", age); + result.put("gender", gender); + + return result; + } + /** * 根据文件类型对文件列表进行分组,并设置到item对象中。 * @param 继承自PersonFileBean的类型 diff --git a/search-tool/src/main/java/com/bonus/tool/template/TestGWDOC.java b/search-tool/src/main/java/com/bonus/tool/template/TestGWDOC.java index 7ca358e..15e31bb 100644 --- a/search-tool/src/main/java/com/bonus/tool/template/TestGWDOC.java +++ b/search-tool/src/main/java/com/bonus/tool/template/TestGWDOC.java @@ -476,7 +476,7 @@ public class TestGWDOC { data.put("list10", list10); data.put("list11", list11); data.put("list12", list12); - WordUtils.exportMillCertificateWord2(null, null, data, "test", "GW_DOC.ftl", "C:\\Users\\10488\\Desktop\\test (2)\\"); + WordUtils.exportMillCertificateWord2(null, null, data, "test", "GW_DOC.ftl", "C:\\Users\\admin\\Desktop\\"); } catch (Exception e) { log.error("GW下载", e); }