From 386b367b42dbe1b6466a68d329774089f284c5d8 Mon Sep 17 00:00:00 2001 From: fl <3098731433@qq.com> Date: Thu, 8 May 2025 14:52:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E7=89=88=E4=B8=8B=E8=BD=BD=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tool/service/impl/EpcServiceImpl.java | 8 +- .../tool/service/impl/SouthServiceImpl.java | 6 +- .../service/impl/StateGridServiceImpl.java | 98 +++++++++++---- .../tool/template/util/SnowflakeIdWorker.java | 114 ++++++++++++++++++ 4 files changed, 193 insertions(+), 33 deletions(-) create mode 100644 search-tool/src/main/java/com/bonus/tool/template/util/SnowflakeIdWorker.java diff --git a/search-tool/src/main/java/com/bonus/tool/service/impl/EpcServiceImpl.java b/search-tool/src/main/java/com/bonus/tool/service/impl/EpcServiceImpl.java index 9381b03..fd69e3a 100644 --- a/search-tool/src/main/java/com/bonus/tool/service/impl/EpcServiceImpl.java +++ b/search-tool/src/main/java/com/bonus/tool/service/impl/EpcServiceImpl.java @@ -170,7 +170,7 @@ public class EpcServiceImpl implements EpcService { //1.2公司核心人员文件 data.getComCoreList().forEach(item -> { //获取附件信息 - List comCoreList = stateGridMapper.getFileSourceList(item.getId(),TableType.TB_KEY_PEOPLE.getCode()); + List comCoreList = stateGridMapper.getFileSourceList(Long.parseLong(item.getUserId()),TableType.TB_KEY_PEOPLE.getCode()); personFileGroup(item, comCoreList); //获取人员业绩 TbCompanyPerfVo tbCompanyPerfVo = new TbCompanyPerfVo(); @@ -186,14 +186,14 @@ public class EpcServiceImpl implements EpcService { //1.3公司其他人员文件 data.getComOtherList().forEach(item -> { //获取附件信息 - List comOtherList = stateGridMapper.getFileSourceList(item.getId(),TableType.TB_OTHER_PEOPLE.getCode()); + List comOtherList = stateGridMapper.getFileSourceList(item.getUserId(),TableType.TB_OTHER_PEOPLE.getCode()); personFileGroup(item, comOtherList); }); //2.2拟派人员材料 data.getSubPersonList().forEach(item -> { //获取附件信息 - List comOtherList = stateGridMapper.getFileSourceList(item.getId(),TableType.TB_SUB_PEOPLE.getCode()); + List comOtherList = stateGridMapper.getFileSourceList(item.getUserId(),TableType.TB_SUB_PEOPLE.getCode()); personFileGroup(item, comOtherList); }); //将数据转换为模版数据 @@ -299,7 +299,7 @@ public class EpcServiceImpl implements EpcService { List> infoList = new ArrayList<>(); if (item.getPeoplePerfList() != null && !item.getPeoplePerfList().isEmpty()) { for (int j = 0; j < item.getPeoplePerfList().size(); j++) { - TbCompanyPerfVo tbCompanyPerfVo = item.getPeoplePerfList().get(i); + TbCompanyPerfVo tbCompanyPerfVo = item.getPeoplePerfList().get(j); Map expMap = new HashMap<>(); expMap.put("time", tbCompanyPerfVo.getStartTime()+"至"+tbCompanyPerfVo.getEndTime()); expMap.put("xm", tbCompanyPerfVo.getProName()); diff --git a/search-tool/src/main/java/com/bonus/tool/service/impl/SouthServiceImpl.java b/search-tool/src/main/java/com/bonus/tool/service/impl/SouthServiceImpl.java index dff0a5c..5e3e6de 100644 --- a/search-tool/src/main/java/com/bonus/tool/service/impl/SouthServiceImpl.java +++ b/search-tool/src/main/java/com/bonus/tool/service/impl/SouthServiceImpl.java @@ -173,7 +173,7 @@ public class SouthServiceImpl implements SouthService { //1.2公司核心人员文件 data.getComCoreList().forEach(item -> { //获取附件信息 - List comCoreList = stateGridMapper.getFileSourceList(item.getId(), TableType.TB_KEY_PEOPLE.getCode()); + List comCoreList = stateGridMapper.getFileSourceList(Long.parseLong(item.getUserId()), TableType.TB_KEY_PEOPLE.getCode()); personFileGroup(item, comCoreList); //获取人员业绩 TbCompanyPerfVo tbCompanyPerfVo = new TbCompanyPerfVo(); @@ -189,14 +189,14 @@ public class SouthServiceImpl implements SouthService { //1.3公司其他人员文件 data.getComOtherList().forEach(item -> { //获取附件信息 - List comOtherList = stateGridMapper.getFileSourceList(item.getId(),TableType.TB_OTHER_PEOPLE.getCode()); + List comOtherList = stateGridMapper.getFileSourceList(item.getUserId(),TableType.TB_OTHER_PEOPLE.getCode()); personFileGroup(item, comOtherList); }); //2.2拟派人员材料 data.getSubPersonList().forEach(item -> { //获取附件信息 - List comOtherList = stateGridMapper.getFileSourceList(item.getId(),TableType.TB_SUB_PEOPLE.getCode()); + List comOtherList = stateGridMapper.getFileSourceList(item.getUserId(),TableType.TB_SUB_PEOPLE.getCode()); personFileGroup(item, comOtherList); }); epcServiceImpl.dealWithWordData(request, response, data, "NW_DOC.ftl"); 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 58f3bbf..773fd43 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 @@ -9,6 +9,7 @@ import com.bonus.tool.mapper.StateGridMapper; import com.bonus.tool.mapper.TbCompanyPerfMapper; import com.bonus.tool.service.StateGridService; import com.bonus.tool.template.util.FreeMarkerUtil; +import com.bonus.tool.template.util.SnowflakeIdWorker; import com.bonus.tool.template.util.WordUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.SmartInitializingSingleton; @@ -35,6 +36,8 @@ public class StateGridServiceImpl implements StateGridService { @Resource private TbCompanyPerfMapper tbCompanyPerfMapper; + SnowflakeIdWorker idWorker = new SnowflakeIdWorker(1, 1); + /** * 国网模版列表查询 * @@ -216,7 +219,7 @@ public class StateGridServiceImpl implements StateGridService { //1.2公司核心人员文件 data.getComCoreList().forEach(item -> { //获取附件信息 - List comCoreList = getFileSourceList(item.getId(),TableType.TB_KEY_PEOPLE.getCode()); + List comCoreList = getFileSourceList(Long.parseLong(item.getUserId()),TableType.TB_KEY_PEOPLE.getCode()); personFileGroup(item, comCoreList); //获取人员业绩 TbCompanyPerfVo tbCompanyPerfVo = new TbCompanyPerfVo(); @@ -234,7 +237,7 @@ public class StateGridServiceImpl implements StateGridService { //1.3公司其他人员文件 data.getComOtherList().forEach(item -> { //获取附件信息 - List comOtherList = getFileSourceList(item.getId(),TableType.TB_OTHER_PEOPLE.getCode()); + List comOtherList = getFileSourceList(item.getUserId(),TableType.TB_OTHER_PEOPLE.getCode()); personFileGroup(item, comOtherList); }); @@ -253,7 +256,7 @@ public class StateGridServiceImpl implements StateGridService { //2.2拟派人员材料 item.getSubPersonList().forEach(personItem -> { //获取附件信息 - List comOtherList = getFileSourceList(personItem.getId(),TableType.TB_SUB_PEOPLE.getCode()); + List comOtherList = getFileSourceList(personItem.getUserId(),TableType.TB_SUB_PEOPLE.getCode()); personFileGroup(personItem, comOtherList); }); @@ -338,10 +341,10 @@ public class StateGridServiceImpl implements StateGridService { List> zmImgList = new ArrayList<>(); // 处理分包商业绩 if (item.getSubPerfList() != null && !item.getSubPerfList().isEmpty()) { - int perfIndex = 1; + int perfIndex = 0; for (SubPerformanceBean perfItem : item.getSubPerfList()) { Map perfMap = new HashMap<>(); - perfMap.put("i", perfIndex++); + perfMap.put("i", ++perfIndex); perfMap.put("proName", perfItem.getProName() != null ? perfItem.getProName() : ""); perfMap.put("unit", perfItem.getConsUnit() != null ? perfItem.getConsUnit() : ""); perfMap.put("money", perfItem.getMoney() != null ? perfItem.getMoney().toString() : ""); @@ -358,20 +361,20 @@ public class StateGridServiceImpl implements StateGridService { yjList.add(perfMap); // 处理业绩证明材料图片 if (perfItem.getSubPerfFileList() != null && !perfItem.getSubPerfFileList().isEmpty()) { - Map zmMap = new HashMap<>(); - zmMap.put("proName", perfIndex + "、" + perfItem.getProName()); + Map map2 = new HashMap<>(); + map2.put("proName", perfIndex + "、" + perfItem.getProName()); List> imgList = new ArrayList<>(); - int imgIndex = 1; for (TbFileSourceVo file : perfItem.getSubPerfFileList()) { - Map imgMap = new HashMap<>(); - imgMap.put("index", 100000 * perfIndex + imgIndex++); - imgMap.put("width", "481.15"); - imgMap.put("height", "634.5"); - imgMap.put("base64Url", file.getFilePath() != null ? FreeMarkerUtil.getImageBase(filePath+file.getFilePath()) : ""); - imgList.add(imgMap); + Map map3 = new HashMap<>(); + map3.put("index", idWorker.nextId()); + map3.put("width", "481.15"); + map3.put("height", "634.5"); + System.err.println("处理业绩证明材料图片:"+filePath+file.getFilePath()); + map3.put("base64Url", file.getFilePath() != null ? FreeMarkerUtil.getImageBase(filePath+file.getFilePath()) : ""); + imgList.add(map3); } - zmMap.put("imgList", imgList); - zmImgList.add(zmMap); + map2.put("imgList", imgList); + zmImgList.add(map2); } } } @@ -389,6 +392,7 @@ public class StateGridServiceImpl implements StateGridService { } // 处理分包商拟派人员 if (item.getSubPersonList() != null && !item.getSubPersonList().isEmpty()) { + //先处理人员 int personIndex = 1; for (SubOtherPeopleBean personItem : item.getSubPersonList()) { Map personMap = new HashMap<>(); @@ -443,6 +447,49 @@ public class StateGridServiceImpl implements StateGridService { personImgList.add(personImgMap); } } + //再循环图片 + for (SubOtherPeopleBean personItem : item.getSubPersonList()) { + // 处理拟派人员证件图片 + Map personImgMap = new HashMap<>(); + personImgMap.put("userType", personItem.getPostName() != null ? personItem.getPostName() : ""); + List> imgList = new ArrayList<>(); + Map imgMap = new HashMap<>(); + // 处理身份证 + if (personItem.getIdCardFileList() != null && !personItem.getIdCardFileList().isEmpty()) { + for (TbFileSourceVo file : personItem.getIdCardFileList()) { + imgMap.put("index", idWorker.nextId()); + imgMap.put("width", "375.35"); + imgMap.put("height", "207.85"); + imgMap.put("base64Url", file.getFilePath() != null ? FreeMarkerUtil.getImageBase(filePath+file.getFilePath()) : ""); + imgList.add(imgMap); + } + } + // 处理资格证书 + if (personItem.getDiplomaFileList() != null && !personItem.getDiplomaFileList().isEmpty()) { + for (TbFileSourceVo file : personItem.getDiplomaFileList()) { + imgMap.put("index", idWorker.nextId()); + imgMap.put("width", "481.15"); + imgMap.put("height", "634.5"); + imgMap.put("base64Url", file.getFilePath() != null ? FreeMarkerUtil.getImageBase(filePath+file.getFilePath()) : ""); + imgList.add(imgMap); + } + } + // 处理其他资质 + if (personItem.getOtherFileList() != null && !personItem.getOtherFileList().isEmpty()) { + for (TbFileSourceVo file : personItem.getOtherFileList()) { + imgMap.put("index", idWorker.nextId()); + imgMap.put("width", "481.15"); + imgMap.put("height", "634.5"); + imgMap.put("base64Url", file.getFilePath() != null ? FreeMarkerUtil.getImageBase(filePath+file.getFilePath()) : ""); + imgList.add(imgMap); + } + } + if (!imgList.isEmpty()) { + personImgMap.put("imgList", imgList); + personImgList.add(personImgMap); + } + } + } subMap.put("yjList", yjList); subMap.put("zzList", zzList); @@ -457,7 +504,6 @@ public class StateGridServiceImpl implements StateGridService { List> otherUserList = new ArrayList<>(); List> userSettingList = new ArrayList<>(); List> personImgList = new ArrayList<>(); - if (tbData.getComOtherList() != null && !tbData.getComOtherList().isEmpty()) { int otherIndex = 1; for (ComOtherPersonBean item : tbData.getComOtherList()) { @@ -473,15 +519,15 @@ public class StateGridServiceImpl implements StateGridService { otherMap.put("bh", ""); // 处理证书列表 List> zsList = new ArrayList<>(); -// if (item.getDiploma() != null || item.getDiplomaNum() != null || item.getMajor() != null || item.getLevel() != null) { -// Map zsMap = new HashMap<>(); -// zsMap.put("zs", item.getDiploma() != null ? item.getDiploma() : ""); -// zsMap.put("jb", item.getLevel() != null ? item.getLevel() : ""); -// zsMap.put("zh", item.getDiplomaNum() != null ? item.getDiplomaNum() : ""); -// zsMap.put("zy", item.getMajor() != null ? item.getMajor() : ""); -// zsMap.put("bh", ""); -// zsList.add(zsMap); -// } + if (item.getDiploma() != null || item.getDiplomaNum() != null || item.getMajor() != null || item.getLevel() != null) { + Map zsMap = new HashMap<>(); + zsMap.put("zs", item.getDiploma() != null ? item.getDiploma() : ""); + zsMap.put("jb", item.getLevel() != null ? item.getLevel() : ""); + zsMap.put("zh", item.getDiplomaNum() != null ? item.getDiplomaNum() : ""); + zsMap.put("zy", item.getMajor() != null ? item.getMajor() : ""); + zsMap.put("bh", ""); + zsList.add(zsMap); + } otherMap.put("zsList", zsList); otherUserList.add(otherMap); // 处理人员证件图片 diff --git a/search-tool/src/main/java/com/bonus/tool/template/util/SnowflakeIdWorker.java b/search-tool/src/main/java/com/bonus/tool/template/util/SnowflakeIdWorker.java new file mode 100644 index 0000000..5d7267a --- /dev/null +++ b/search-tool/src/main/java/com/bonus/tool/template/util/SnowflakeIdWorker.java @@ -0,0 +1,114 @@ +package com.bonus.tool.template.util; + +public class SnowflakeIdWorker { + + // 开始时间截 (UTC 2025-01-01) + private final long twepoch = 1704268800000L; + + // 机器id所占的位数 + private final long workerIdBits = 5L; + + // 数据标识id所占的位数 + private final long datacenterIdBits = 5L; + + // 支持的最大机器id,结果是31 (这个值不包含id为0的情况) + private final long maxWorkerId = -1L ^ (-1L << workerIdBits); + + // 支持的最大数据标识id,结果是31 + private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); + + // 序列在id中占的位数 + private final long sequenceBits = 12L; + + // 机器ID向左移12位 + private final long workerIdShift = sequenceBits; + + // 数据标识id向左移17位(12+5) + private final long datacenterIdShift = sequenceBits + workerIdBits; + + // 时间截向左移22位(12+5+5) + private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits; + + // 生成序列的掩码,这里为4095 (0b111111111111=4095) + private final long sequenceMask = -1L ^ (-1L << sequenceBits); + + // 工作机器ID(0~31) + private long workerId; + + // 数据中心ID(0~31) + private long datacenterId; + + // 毫秒内序列(0~4095) + private long sequence = 0L; + + // 上次生成ID的时间截 + private long lastTimestamp = -1L; + + // 构造函数 + public SnowflakeIdWorker(long workerId, long datacenterId) { + if (workerId > maxWorkerId || workerId < 0) { + throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId)); + } + if (datacenterId > maxDatacenterId || datacenterId < 0) { + throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId)); + } + this.workerId = workerId; + this.datacenterId = datacenterId; + } + + // 获得下一个ID (该方法是线程安全的) + public synchronized long nextId() { + long timestamp = timeGen(); + + // 如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常 + if (timestamp < lastTimestamp) { + throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); + } + + // 如果是同一时间生成的,则进行毫秒内序列 + if (lastTimestamp == timestamp) { + sequence = (sequence + 1) & sequenceMask; + // 毫秒内序列溢出 + if (sequence == 0) { + // 阻塞到下一个毫秒,获得新的时间戳 + timestamp = tilNextMillis(lastTimestamp); + } + } + // 时间戳改变,毫秒内序列重置 + else { + sequence = 0L; + } + + // 上次生成ID的时间截 + lastTimestamp = timestamp; + + // 移位并通过或运算拼到一起组成64位的ID + return ((timestamp - twepoch) << timestampLeftShift) + | (datacenterId << datacenterIdShift) + | (workerId << workerIdShift) + | sequence; + } + + // 阻塞到下一个毫秒,直到获得新的时间戳 + protected long tilNextMillis(long lastTimestamp) { + long timestamp = timeGen(); + while (timestamp <= lastTimestamp) { + timestamp = timeGen(); + } + return timestamp; + } + + // 返回以毫秒为单位的当前时间 + protected long timeGen() { + return System.currentTimeMillis(); + } + + public static void main(String[] args) { + SnowflakeIdWorker idWorker = new SnowflakeIdWorker(1, 1); + for (int i = 0; i < 10; i++) { + long id = idWorker.nextId(); + System.out.println(Long.toBinaryString(id)); + System.out.println(id); + } + } +}