diff --git a/.gitignore b/.gitignore index 9154f4c..e3de2f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,27 @@ -# ---> Java -# Compiled class file -*.class +/ecology-develop.iml +/E9-bmj.iml +/out/ +/.idea/ -# Log file -*.log -# BlueJ files -*.ctxt +HELP.md +target/ -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +### IntelliJ IDEA ### +.idea +HELP.md +target/ -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar +/src/test +/src/rebel.xml +/src/META-INF +### IntelliJ IDEA ### +.idea -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* +/log +/src/test +/src/rebel.xml +/src/META-INF + +/log diff --git a/WEB-INF/lib/zip4j-2.11.5.jar b/WEB-INF/lib/zip4j-2.11.5.jar new file mode 100644 index 0000000..c08f0f3 Binary files /dev/null and b/WEB-INF/lib/zip4j-2.11.5.jar differ diff --git a/src/com/api/secret/web/AuthorityChangeController.java b/src/com/api/secret/web/AuthorityChangeController.java new file mode 100644 index 0000000..cdf324e --- /dev/null +++ b/src/com/api/secret/web/AuthorityChangeController.java @@ -0,0 +1,12 @@ +package com.api.secret.web; + +import javax.ws.rs.Path; + +/** + * @author:dxfeng + * @createTime: 2025/04/09 + * @version: 1.0 + */ +@Path("/secret/authority/change") +public class AuthorityChangeController extends com.engine.secret.web.AuthorityChangeController{ +} diff --git a/src/com/api/secret/web/AutoGenerateNumberController.java b/src/com/api/secret/web/AutoGenerateNumberController.java new file mode 100644 index 0000000..c0e6862 --- /dev/null +++ b/src/com/api/secret/web/AutoGenerateNumberController.java @@ -0,0 +1,12 @@ +package com.api.secret.web; + +import javax.ws.rs.Path; + +/** + * @author:dxfeng + * @createTime: 2025/04/16 + * @version: 1.0 + */ +@Path("/secret/auto/number") +public class AutoGenerateNumberController extends com.engine.secret.web.AutoGenerateNumberController{ +} diff --git a/src/com/api/secret/web/QualificationApplicationController.java b/src/com/api/secret/web/QualificationApplicationController.java new file mode 100644 index 0000000..79ff4e7 --- /dev/null +++ b/src/com/api/secret/web/QualificationApplicationController.java @@ -0,0 +1,8 @@ +package com.api.secret.web; + +import javax.ws.rs.Path; + + +@Path("/secret/demand") +public class QualificationApplicationController extends com.engine.secret.web.QualificationApplicationController { +} diff --git a/src/com/engine/secret/entity/autonumber/AcceptanceNumber.java b/src/com/engine/secret/entity/autonumber/AcceptanceNumber.java new file mode 100644 index 0000000..c41f429 --- /dev/null +++ b/src/com/engine/secret/entity/autonumber/AcceptanceNumber.java @@ -0,0 +1,24 @@ +package com.engine.secret.entity.autonumber; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/04/16 + * @version: 1.0 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class AcceptanceNumber { + private Integer id; + private Integer year; + private Integer month; + private Integer monthlySerial; + private Integer globalSerial; + private Integer secretType; +} diff --git a/src/com/engine/secret/entity/unpack/ApplicationResource.java b/src/com/engine/secret/entity/unpack/ApplicationResource.java new file mode 100644 index 0000000..d778014 --- /dev/null +++ b/src/com/engine/secret/entity/unpack/ApplicationResource.java @@ -0,0 +1,24 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ApplicationResource { + private String id; + private String aid; + private String fid; + private String rid; + private String createdTime; + private String isDelete; +} diff --git a/src/com/engine/secret/entity/unpack/CheckFields.java b/src/com/engine/secret/entity/unpack/CheckFields.java new file mode 100644 index 0000000..7f39f2d --- /dev/null +++ b/src/com/engine/secret/entity/unpack/CheckFields.java @@ -0,0 +1,15 @@ +package com.engine.secret.entity.unpack; + +import lombok.Data; + +/** + * @author:dxfeng + * @createTime: 2025/04/30 + * @version: 1.0 + */ +@Data +public class CheckFields { + private String name; + private String fields; + private String formFields; +} diff --git a/src/com/engine/secret/entity/unpack/DataConfig.java b/src/com/engine/secret/entity/unpack/DataConfig.java new file mode 100644 index 0000000..a2ebc58 --- /dev/null +++ b/src/com/engine/secret/entity/unpack/DataConfig.java @@ -0,0 +1,29 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class DataConfig { + private String id; + private String mainTableName; + private String relatedField; + private String detailTableName; + private String rootPath; + List childDataConfig; + List detailList; + List fileList; + +} diff --git a/src/com/engine/secret/entity/unpack/DataConfigDetail.java b/src/com/engine/secret/entity/unpack/DataConfigDetail.java new file mode 100644 index 0000000..aa0ddba --- /dev/null +++ b/src/com/engine/secret/entity/unpack/DataConfigDetail.java @@ -0,0 +1,31 @@ +package com.engine.secret.entity.unpack; + +import com.engine.secret.util.ModeUtil; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang.StringUtils; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class DataConfigDetail { + private String fieldName; + private String path; + private String condition; + private String convertSql; + + public String getConvertSql() { + if (StringUtils.isBlank(convertSql)) { + return ""; + } + return ModeUtil.ToDBC(convertSql); + } +} diff --git a/src/com/engine/secret/entity/unpack/FileConfig.java b/src/com/engine/secret/entity/unpack/FileConfig.java new file mode 100644 index 0000000..2d935dc --- /dev/null +++ b/src/com/engine/secret/entity/unpack/FileConfig.java @@ -0,0 +1,23 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class FileConfig { + private String fieldName; + private String fileId; + private String isFilled; + private String fixedValue; + private String attachments; +} diff --git a/src/com/engine/secret/entity/unpack/ResourceInfo.java b/src/com/engine/secret/entity/unpack/ResourceInfo.java new file mode 100644 index 0000000..7c45f0b --- /dev/null +++ b/src/com/engine/secret/entity/unpack/ResourceInfo.java @@ -0,0 +1,26 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ResourceInfo { + private String id; + private String fileName; + private String filePath; + private String fileSuffix; + private String virtualPath; + private String createdTime; + private String updatedTime; + private String isDelete; +} diff --git a/src/com/engine/secret/entity/unpack/UnpackParam.java b/src/com/engine/secret/entity/unpack/UnpackParam.java new file mode 100644 index 0000000..99c167e --- /dev/null +++ b/src/com/engine/secret/entity/unpack/UnpackParam.java @@ -0,0 +1,24 @@ +package com.engine.secret.entity.unpack; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/04/30 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class UnpackParam { + private String docId; + private String requestId; + private boolean isCorrection; + private List checkFields; +} diff --git a/src/com/engine/secret/enums/ApplicationCategory.java b/src/com/engine/secret/enums/ApplicationCategory.java new file mode 100644 index 0000000..61238d9 --- /dev/null +++ b/src/com/engine/secret/enums/ApplicationCategory.java @@ -0,0 +1,32 @@ +package com.engine.secret.enums; + +/** + * 申请类别 + * + * @author:dxfeng + * @createTime: 2025/04/07 + * @version: 1.0 + */ +public enum ApplicationCategory { + // 涉密信息系统集成资质、国家秘密载体印制资质、武器装备科研生产单位保密资质、涉密军事设施建设保密资质 + CLASSIFIED_INFO_SYSTEM_INTEGRATION_QUALIFICATION("涉密信息系统集成资质", 0), + NATIONAL_SECRET_CARRIER_PRINTING_QUALIFICATION("国家秘密载体印制资质", 1), + WEAPON_EQUIPMENT_RESEARCH_SECURITY_QUALIFICATION("武器装备科研生产单位保密资质", 2), + CLASSIFIED_MILITARY_FACILITY_CONSTRUCTION_QUALIFICATION("涉密军事设施建设保密资质", 3); + + ApplicationCategory(String name, Integer value) { + this.name = name; + this.value = value; + } + + private String name; + private Integer value; + + public String getName() { + return name; + } + + public Integer getValue() { + return value; + } +} diff --git a/src/com/engine/secret/enums/CategoryValue.java b/src/com/engine/secret/enums/CategoryValue.java new file mode 100644 index 0000000..3ebb174 --- /dev/null +++ b/src/com/engine/secret/enums/CategoryValue.java @@ -0,0 +1,15 @@ +package com.engine.secret.enums; + +/** + * @author:dxfeng + * @createTime: 2025/04/07 + * @version: 1.0 + */ +public interface CategoryValue { + /** + * 获取值 + * + * @return + */ + int getSelectValue(); +} diff --git a/src/com/engine/secret/enums/IntegrateCategory.java b/src/com/engine/secret/enums/IntegrateCategory.java new file mode 100644 index 0000000..b5dcd96 --- /dev/null +++ b/src/com/engine/secret/enums/IntegrateCategory.java @@ -0,0 +1,44 @@ +package com.engine.secret.enums; + +/** + * 集成资质 + * + * @author:dxfeng + * @createTime: 2025/04/07 + * @version: 1.0 + */ +public enum IntegrateCategory implements CategoryValue { + // 总体集成、系统咨询、软件开发、安防监控、屏蔽室建设、运行维护、数据恢复、工程监理 + SYSTEM_INTEGRATION("总体集成", 0), + SYSTEM_CONSULTING("系统咨询", 1), + SOFTWARE_DEVELOPMENT("软件开发", 2), + SECURITY_SURVEILLANCE("安防监控", 3), + SHIELDED_ROOM_CONSTRUCTION("屏蔽室建设", 4), + OPERATION_MAINTENANCE("运行维护", 5), + DATA_RECOVERY("数据恢复", 6), + PROJECT_SUPERVISION("工程监理", 7); + + IntegrateCategory(String name, Integer value) { + this.name = name; + this.value = value; + } + + private String name; + private Integer value; + + public static IntegrateCategory getValue(String name) { + for (IntegrateCategory item : IntegrateCategory.values()) { + if (item.name.equalsIgnoreCase(name)) { + return item; + } + } + //throw new RuntimeException("不支持的操作类型"); + return null; + } + + + @Override + public int getSelectValue() { + return value; + } +} diff --git a/src/com/engine/secret/enums/PrintCategory.java b/src/com/engine/secret/enums/PrintCategory.java new file mode 100644 index 0000000..5e7afc8 --- /dev/null +++ b/src/com/engine/secret/enums/PrintCategory.java @@ -0,0 +1,41 @@ +package com.engine.secret.enums; + +/** + * 印制资质 + * + * @author:dxfeng + * @createTime: 2025/04/07 + * @version: 1.0 + */ +public enum PrintCategory implements CategoryValue { + // 涉密文件资料、国家统一考试试卷、涉密防伪票据证书、涉密光电磁介质、涉密档案数字化加工 + CLASSIFIED_DOCUMENTS("涉密文件资料", 0), + NATIONAL_EXAM_PAPERS("国家统一考试试卷", 1), + CLASSIFIED_VOUCHERS("涉密防伪票据证书", 2), + SECURE_ELECTRONIC_STORAGE("涉密光电磁介质", 3), + CLASSIFIED_DIGITIZATION("涉密档案数字化加工", 4); + + PrintCategory(String name, Integer value) { + this.name = name; + this.value = value; + } + + private String name; + private Integer value; + + public static PrintCategory getValue(String name) { + for (PrintCategory item : PrintCategory.values()) { + if (item.name.equalsIgnoreCase(name)) { + return item; + } + } + //throw new RuntimeException("不支持的操作类型"); + return null; + } + + + @Override + public int getSelectValue() { + return value; + } +} diff --git a/src/com/engine/secret/exception/CustomizeRunTimeException.java b/src/com/engine/secret/exception/CustomizeRunTimeException.java new file mode 100644 index 0000000..76b71b3 --- /dev/null +++ b/src/com/engine/secret/exception/CustomizeRunTimeException.java @@ -0,0 +1,22 @@ +package com.engine.secret.exception; + +/** + * @Author weaver_cl + * @Description: + * @Date 2023/2/21 + * @Version V1.0 + **/ +public class CustomizeRunTimeException extends RuntimeException{ + + public CustomizeRunTimeException(String message) { + super(message); + } + + public CustomizeRunTimeException(Throwable cause) { + super(cause); + } + + public CustomizeRunTimeException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/src/com/engine/secret/instance/AutoGenerateNumberInstance.java b/src/com/engine/secret/instance/AutoGenerateNumberInstance.java new file mode 100644 index 0000000..ae0b031 --- /dev/null +++ b/src/com/engine/secret/instance/AutoGenerateNumberInstance.java @@ -0,0 +1,234 @@ +package com.engine.secret.instance; + +import cn.hutool.core.convert.Convert; +import com.engine.secret.entity.autonumber.AcceptanceNumber; +import com.engine.secret.exception.CustomizeRunTimeException; +import com.engine.secret.util.ModeUtil; +import weaver.common.DateUtil; +import weaver.conn.RecordSetTrans; +import weaver.formmode.IgnoreCaseHashMap; +import weaver.general.Util; +import weaver.hrm.User; + +import java.time.LocalDate; +import java.util.Map; +import java.util.UUID; + +/** + * @author:dxfeng + * @createTime: 2025/04/16 + * @version: 1.0 + */ +public class AutoGenerateNumberInstance { + private static final String TABLE_NAME = "uf_sldh"; + private static final String RECORD_TABLE_NAME = "uf_sldh_dt1"; + + private static final AutoGenerateNumberInstance INSTANCE = new AutoGenerateNumberInstance(); + + private AutoGenerateNumberInstance() { + // 私有化构造方法 + } + + public static AutoGenerateNumberInstance getInstance() { + return INSTANCE; + } + + /** + * 集成、印制受理编号 + * + * @param param + * @return + */ + public synchronized String getAcceptanceNumber(User user, Map param) { + RecordSetTrans rs = new RecordSetTrans(); + rs.setAutoCommit(false); + try { + Integer secretType = Convert.toInt(param.get("secretType")); + String requestId = Util.null2String(param.get("requestId")); + + LocalDate now = LocalDate.now(); + int year = now.getYear(); + int currentMonth = now.getMonthValue(); + + + AcceptanceNumber yearNumber; + rs.executeQuery("select * from uf_sldh where secret_type= ? and year = ? and month = 0 FOR UPDATE", secretType, year); + if (rs.next()) { + yearNumber = getSelectNum(rs); + } else { + yearNumber = buildNewNum(year, 0, secretType); + } + yearNumber.setGlobalSerial(yearNumber.getGlobalSerial() + 1); + // 更新年度流水号 + saveNum(rs, yearNumber); + + AcceptanceNumber monthNumber; + rs.executeQuery("select * from uf_sldh where secret_type= ? and year = ? and month = ? FOR UPDATE", secretType, year, currentMonth); + if (rs.next()) { + monthNumber = getSelectNum(rs); + } else { + monthNumber = buildNewNum(year, currentMonth, secretType); + } + monthNumber.setMonthlySerial(monthNumber.getMonthlySerial() + 1); + // 更新月度、流水号 + saveNum(rs, monthNumber); + + // 生成编号 + String formattedYear = String.format("%04d", year); + String formattedMonth = String.format("%02d", monthNumber.getMonth()); + String formattedMonthlySerial = String.format("%02d", monthNumber.getMonthlySerial()); + String formattedGlobalSerial = String.format("%03d", yearNumber.getGlobalSerial()); + + String num = formattedYear + formattedMonth + formattedMonthlySerial + formattedGlobalSerial; + rs.writeLog("requestId===" + requestId + ",secretType===" + secretType + ",num===" + num); + insertGenerateRecord(rs, requestId, num, user.getUID()); + // 插入编号生成记录 + rs.commit(); + return num; + } catch (Exception e) { + rs.rollback(); + rs.writeLog(e); + throw new CustomizeRunTimeException(e.getMessage()); + } + } + + /** + * 军工受理单号 + * + * @param param + * @return + */ + public synchronized String getWarIndustryAcceptanceNumber(User user, Map param) { + RecordSetTrans rs = new RecordSetTrans(); + rs.setAutoCommit(false); + try { + Integer secretType = Convert.toInt(param.get("secretType")); + String requestId = Util.null2String(param.get("requestId")); + + LocalDate now = LocalDate.now(); + int year = now.getYear(); + + + AcceptanceNumber yearNumber; + rs.executeQuery("select * from uf_sldh where secret_type= ? and year = ? and month = 0 FOR UPDATE", secretType, year); + if (rs.next()) { + yearNumber = getSelectNum(rs); + } else { + yearNumber = buildNewNum(year, 0, secretType); + } + yearNumber.setGlobalSerial(yearNumber.getGlobalSerial() + 1); + // 更新年度流水号 + saveNum(rs, yearNumber); + + // 生成编号 + String formattedYear = String.format("%04d", year); + String formattedGlobalSerial = String.format("%03d", yearNumber.getGlobalSerial()); + + String num = "JS" + formattedYear + formattedGlobalSerial; + rs.writeLog("requestId===" + requestId + ",secretType===" + secretType + ",num===" + num); + insertGenerateRecord(rs, requestId, num, user.getUID()); + rs.commit(); + return num; + } catch (Exception e) { + rs.rollback(); + rs.writeLog(e); + throw new CustomizeRunTimeException(e.getMessage()); + } + } + + /** + * 构建查询对象 + * + * @param rs + * @return + */ + private AcceptanceNumber getSelectNum(RecordSetTrans rs) { + return AcceptanceNumber.builder() + .id(rs.getInt("id")) + .year(rs.getInt("year")) + .month(rs.getInt("month")) + .monthlySerial(rs.getInt("monthly_serial")) + .globalSerial(rs.getInt("global_serial")) + .secretType(rs.getInt("secret_type")) + .build(); + } + + /** + * 构建新对象 + * + * @param year + * @param currentMonth + * @param secretType + * @return + */ + private AcceptanceNumber buildNewNum(Integer year, Integer currentMonth, Integer secretType) { + return AcceptanceNumber.builder() + .year(year) + .month(currentMonth) + .monthlySerial(0) + .globalSerial(0) + .secretType(secretType) + .build(); + } + + /** + * 保存编号数据 + * + * @param rs + * @param number + * @throws Exception + */ + private void saveNum(RecordSetTrans rs, AcceptanceNumber number) throws Exception { + if (null == number.getId()) { + Map insertMap = buildSaveMap(number); + String uuid = UUID.randomUUID().toString(); + insertMap.put("modeuuid", uuid); + int formModeId = ModeUtil.getModeIdByTableName(TABLE_NAME); + insertMap.put("formmodeid", formModeId); + ModeUtil.buildModeInsertFields(insertMap, 1); + ModeUtil.insertData(rs, insertMap, TABLE_NAME); + ModeUtil.refreshRight(uuid, TABLE_NAME, formModeId, 1); + } else { + Map updateMap = buildSaveMap(number); + ModeUtil.buildModeUpdateFields(updateMap, 1); + ModeUtil.updateDataById(rs, updateMap, TABLE_NAME); + } + + } + + /** + * 构建数据库映射关系 + * + * @param number + * @return + */ + private IgnoreCaseHashMap buildSaveMap(AcceptanceNumber number) { + IgnoreCaseHashMap dataMap = new IgnoreCaseHashMap<>(); + if (null != number.getId()) { + dataMap.put("id", number.getId()); + } + dataMap.put("year", number.getYear()); + dataMap.put("month", number.getMonth()); + dataMap.put("monthly_serial", number.getMonthlySerial()); + dataMap.put("global_serial", number.getGlobalSerial()); + dataMap.put("secret_type", number.getSecretType()); + return dataMap; + } + + /** + * 插入编号生成记录 + * + * @param requestId + * @param num + * @param userId + */ + private void insertGenerateRecord(RecordSetTrans rs, String requestId, String num, int userId) throws Exception { + IgnoreCaseHashMap dataMap = new IgnoreCaseHashMap<>(); + dataMap.put("request_id", requestId); + dataMap.put("num", num); + dataMap.put("operate_user", userId); + dataMap.put("operate_time", DateUtil.getFullDate()); + ModeUtil.insertData(rs, dataMap, RECORD_TABLE_NAME); + + } +} diff --git a/src/com/engine/secret/service/AuthorityChangeService.java b/src/com/engine/secret/service/AuthorityChangeService.java new file mode 100644 index 0000000..4c5ebb9 --- /dev/null +++ b/src/com/engine/secret/service/AuthorityChangeService.java @@ -0,0 +1,19 @@ +package com.engine.secret.service; + +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/04/09 + * @version: 1.0 + */ +public interface AuthorityChangeService { + + /** + * 将审批事权移交至省级 + * + * @param param + * @return + */ + Map delegateToProvincialAuthority(Map param); +} diff --git a/src/com/engine/secret/service/AutoGenerateNumberService.java b/src/com/engine/secret/service/AutoGenerateNumberService.java new file mode 100644 index 0000000..21c6310 --- /dev/null +++ b/src/com/engine/secret/service/AutoGenerateNumberService.java @@ -0,0 +1,18 @@ +package com.engine.secret.service; + +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/04/16 + * @version: 1.0 + */ +public interface AutoGenerateNumberService { + /** + * 获取受理单号 + * + * @param param + * @return + */ + String getAcceptanceNumber(Map param) ; +} diff --git a/src/com/engine/secret/service/QualificationApplicationService.java b/src/com/engine/secret/service/QualificationApplicationService.java new file mode 100644 index 0000000..26284db --- /dev/null +++ b/src/com/engine/secret/service/QualificationApplicationService.java @@ -0,0 +1,27 @@ +package com.engine.secret.service; + +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2024/08/29 + * @version: 1.0 + */ +public interface QualificationApplicationService { + + /** + * 解析文件 + * + * @param param + * @return + */ + Map parsingFiles(Map param); + + /** + * 删除已经解析的数据 + * + * @param params + * @return + */ + Map deleteParsedData(Map params); +} diff --git a/src/com/engine/secret/service/UnpackZipService.java b/src/com/engine/secret/service/UnpackZipService.java new file mode 100644 index 0000000..cb6596e --- /dev/null +++ b/src/com/engine/secret/service/UnpackZipService.java @@ -0,0 +1,43 @@ +package com.engine.secret.service; + +import com.engine.secret.entity.unpack.UnpackParam; +import com.fasterxml.jackson.databind.JsonNode; +import net.lingala.zip4j.ZipFile; +import net.lingala.zip4j.model.FileHeader; + +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +public interface UnpackZipService { + + /** + * 材料收件 + * + * @param unpackParam + * @param rootNode + * @param imageFileMap + * @return + * @throws Exception + */ + Map registerAcceptance(ZipFile zipFile, UnpackParam unpackParam, JsonNode rootNode, Map imageFileMap) throws Exception; + + /** + * 材料补正 + * + * @return + */ + Map reviewResubmittedMaterials(ZipFile zipFile, String requestId, JsonNode rootNode, Map imageFileMap); + + /** + * 删除文件解析数据 + * + * @param param + * @return + */ + Map deleteParsedData(Map param); + +} diff --git a/src/com/engine/secret/service/impl/AuthorityChangeServiceImpl.java b/src/com/engine/secret/service/impl/AuthorityChangeServiceImpl.java new file mode 100644 index 0000000..528c66c --- /dev/null +++ b/src/com/engine/secret/service/impl/AuthorityChangeServiceImpl.java @@ -0,0 +1,67 @@ +package com.engine.secret.service.impl; + +import com.engine.core.impl.Service; +import com.engine.secret.exception.CustomizeRunTimeException; +import com.engine.secret.service.AuthorityChangeService; +import com.engine.secret.util.FlowUtil; +import com.engine.secret.util.ModeUtil; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.Util; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/04/09 + * @version: 1.0 + */ +public class AuthorityChangeServiceImpl extends Service implements AuthorityChangeService { + @Override + public Map delegateToProvincialAuthority(Map param) { + RecordSet rs = new RecordSet(); + String ids = Util.null2String(param.get("ids")); + if (StringUtils.isBlank(ids)) { + throw new CustomizeRunTimeException("请至少选择一条数据"); + } + String customId = Util.null2String(param.get("customId")); + if (StringUtils.isBlank(customId)) { + throw new CustomizeRunTimeException("未获取到查询列表ID"); + } + String modeTableName = ModeUtil.getTableNameByCustomId(customId); + rs.writeLog("ids==" + ids); + rs.writeLog("customId==" + customId); + rs.writeLog("modeTableName==" + modeTableName); + String options = user.getLastname() + "-自动提交流程-"; + + // 查询对应的流程,并更新 + String[] split = ids.split(","); + for (String s : split) { + rs.writeLog("id==" + s); + // 更新事权类别为省级事权 + rs.executeUpdate("update " + modeTableName + " set bmzzzgsqlb = ?,tjdqjd = ? where id =? ", 0, 1, s); + // 查询对应的requestId + rs.executeQuery("select requestId from " + modeTableName + " where id = ?", s); + if (rs.next()) { + String requestId = rs.getString("requestId"); + rs.writeLog("requestId==" + requestId); + List currentUserIds = FlowUtil.getCurrentUserIds(requestId); + if (CollectionUtils.isEmpty(currentUserIds)) { + throw new CustomizeRunTimeException("requestId[" + requestId + "],流程提交失败,未获取到当前节点处理人"); + } + + String submitResult = FlowUtil.submitWorkflowRequest(requestId, currentUserIds.get(0), options + DateUtil.getFullDate()); + if (!"success".equals(submitResult)) { + throw new CustomizeRunTimeException("requestId[" + requestId + "],流程提交失败"); + } + } + } + + + return new HashMap<>(); + } +} diff --git a/src/com/engine/secret/service/impl/AutoGenerateNumberServiceImpl.java b/src/com/engine/secret/service/impl/AutoGenerateNumberServiceImpl.java new file mode 100644 index 0000000..98c19e1 --- /dev/null +++ b/src/com/engine/secret/service/impl/AutoGenerateNumberServiceImpl.java @@ -0,0 +1,42 @@ +package com.engine.secret.service.impl; + +import cn.hutool.core.convert.Convert; +import com.engine.core.impl.Service; +import com.engine.secret.exception.CustomizeRunTimeException; +import com.engine.secret.instance.AutoGenerateNumberInstance; +import com.engine.secret.service.AutoGenerateNumberService; +import weaver.conn.RecordSet; + +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/04/16 + * @version: 1.0 + */ +public class AutoGenerateNumberServiceImpl extends Service implements AutoGenerateNumberService { + + @Override + public String getAcceptanceNumber(Map param) { + Integer secretType = Convert.toInt(param.get("secretType")); + Integer requestId = Convert.toInt(param.get("requestId")); + if (null == secretType) { + throw new CustomizeRunTimeException("未获取到[保密资质(资格)类型],请检查表单数据"); + } + // 查询当前请求是否已经生成单号,如已生成过,直接取原来单号,不重新生成 + RecordSet rs = new RecordSet(); + rs.executeQuery("select num from uf_sldh_dt1 where request_id = ? ", requestId); + if (rs.next()) { + return rs.getString("num"); + } + + AutoGenerateNumberInstance instance = AutoGenerateNumberInstance.getInstance(); + if (0 == secretType || 1 == secretType) { + // 集成、印制 + return instance.getAcceptanceNumber(user, param); + } else { + // 军工 + return instance.getWarIndustryAcceptanceNumber(user, param); + } + } +} diff --git a/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java new file mode 100644 index 0000000..44f985c --- /dev/null +++ b/src/com/engine/secret/service/impl/OfflineZipUnpackServiceImpl.java @@ -0,0 +1,1135 @@ +package com.engine.secret.service.impl; + +import cn.hutool.core.convert.Convert; +import com.alibaba.fastjson.JSON; +import com.engine.core.impl.Service; +import com.engine.secret.entity.unpack.*; +import com.engine.secret.exception.CustomizeRunTimeException; +import com.engine.secret.service.UnpackZipService; +import com.engine.secret.util.ConfigUtil; +import com.engine.secret.util.FieldConvertUtil; +import com.engine.secret.util.FlowUtil; +import com.engine.secret.util.ModeUtil; +import com.fasterxml.jackson.databind.JsonNode; +import com.wbi.util.Util; +import com.weaver.formmodel.data.model.Formfield; +import net.lingala.zip4j.ZipFile; +import net.lingala.zip4j.model.FileHeader; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import weaver.conn.RecordSet; +import weaver.formmode.IgnoreCaseHashMap; +import weaver.general.BaseBean; +import weaver.systeminfo.SystemEnv; + +import java.io.InputStream; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +/** + * 离线数据包解析实现类 + * + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipService { + + /** + * 解析类型,当前解析类,固定值为0 + */ + private static final String SOURCE_TYPE = "0"; + + /** + * 文件上传目录 + */ + private int uploadCatalogue; + + private Map> applicationResourceMap; + private Map> resourceInfoMap; + private Map fileHeaderMap; + private String relatedFlowId; + private final Map returnMap = new HashMap<>(); + private ZipFile zipFile; + + private final Map> insertTableMap = new ConcurrentHashMap<>(); + + private final BaseBean baseBean = new BaseBean(); + + @Override + public Map registerAcceptance(ZipFile zipFile, UnpackParam unpackParam, JsonNode rootNode, Map imageFileMap) { + try { + initializeResources(zipFile, unpackParam.getRequestId(), imageFileMap); + insertDataAndFiles(rootNode, unpackParam); + } catch (Exception e) { + baseBean.writeLog(e); + throw new CustomizeRunTimeException(e.getMessage()); + } + returnMap.put("data", insertTableMap); + return returnMap; + } + + @Override + public Map reviewResubmittedMaterials(ZipFile zipFile, String requestId, JsonNode rootNode, Map imageFileMap) { + try { + initializeResources(zipFile, requestId, imageFileMap); + updateCorrectedMaterials(rootNode); + } catch (Exception e) { + baseBean.writeLog(e); + throw new CustomizeRunTimeException(e); + } + return returnMap; + } + + @Override + public Map deleteParsedData(Map param) { + String requestId = Util.null2String(param.get("requestId")); + String isCorrection = Util.null2String(param.get("isCorrection")); + + // 读取配置表 + RecordSet rs = new RecordSet(); + List dataConfig = getDataConfig("0"); + + if ("true".equals(isCorrection)) { + // 补正 + } else { + // 非补正 + for (DataConfig config : dataConfig) { + String mainTableName = config.getMainTableName(); + String relatedField = config.getRelatedField(); + List childDataConfig = config.getChildDataConfig(); + + String sql = "select id from " + mainTableName + " where " + relatedField + " =?"; + rs.executeQuery(sql, requestId); + if (rs.next()) { + int billId = rs.getInt("id"); + if (billId < 0) { + continue; + } + // 删除明细表数据 + for (DataConfig childConfig : childDataConfig) { + String detailTableName = childConfig.getDetailTableName(); + rs.executeUpdate("delete from " + detailTableName + " where mainid = ?", billId); + } + // 删除主表数据 + rs.executeUpdate("delete from " + mainTableName + " where id = ?", billId); + } + } + + } + return null; + } + + /** + * 初始化全局变量数据 + * + * @param zipFile + * @param requestId + * @param imageFileMap + */ + private void initializeResources(ZipFile zipFile, String requestId, Map imageFileMap) { + this.fileHeaderMap = imageFileMap; + this.relatedFlowId = requestId; + this.zipFile = zipFile; + } + + + /** + * 更新补正文件 + * + * @param rootNode + * @throws Exception + */ + private void updateCorrectedMaterials(JsonNode rootNode) throws Exception { + initializeUploadCatalogue(); + List dataConfigList = getDataConfig(SOURCE_TYPE); + baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList)); + + initializeResourceMaps(rootNode); + + if (CollectionUtils.isNotEmpty(dataConfigList)) { + processDataConfigForUpdate(dataConfigList); + } + } + + /** + * 初始化文件上传目录 + */ + private void initializeUploadCatalogue() { + String uploadCatalogueStr = ConfigUtil.getConfig("UPLOAD_CATALOGUE"); + if (StringUtils.isBlank(uploadCatalogueStr)) { + throw new CustomizeRunTimeException("未获取到解析文件目录设置,检查配置[uf_config]"); + } + uploadCatalogue = Convert.toInt(uploadCatalogueStr, -1); + baseBean.writeLog("uploadCatalogue==" + uploadCatalogue); + } + + /** + * 解析JSON文件,构建applicationResourceMap、resourceInfoMap + * + * @param rootNode + */ + private void initializeResourceMaps(JsonNode rootNode) { + List applicationResourceList = getApplicationResourceList(rootNode); + applicationResourceMap = applicationResourceList.stream() + .collect(Collectors.groupingBy(ApplicationResource::getFid)); + baseBean.writeLog("applicationResourceMap==" + JSON.toJSONString(applicationResourceMap)); + + List resourceInfoList = getResourceInfoList(rootNode); + resourceInfoMap = resourceInfoList.stream() + .collect(Collectors.groupingBy(ResourceInfo::getVirtualPath, + Collectors.toMap(ResourceInfo::getId, item -> item))); + baseBean.writeLog("resourceInfoMap==" + JSON.toJSONString(resourceInfoMap)); + } + + /** + * 更新主表补正文件数据 + * + * @param dataConfigList + * @throws Exception + */ + private void processDataConfigForUpdate(List dataConfigList) throws Exception { + RecordSet rs = new RecordSet(); + for (DataConfig dataConfig : dataConfigList) { + String mainTableName = dataConfig.getMainTableName(); + String relatedField = dataConfig.getRelatedField(); + String rootPath = dataConfig.getRootPath(); + baseBean.writeLog("rootPath==" + rootPath); + + List childDataConfigList = dataConfig.getChildDataConfig(); + List fieldDetailList = dataConfig.getDetailList(); + List fileList = dataConfig.getFileList(); + + if (CollectionUtils.isNotEmpty(fieldDetailList)) { + String sql = "select id from " + mainTableName + " where " + relatedField + " =?"; + rs.executeQuery(sql, relatedFlowId); + if (rs.next()) { + int billId = rs.getInt("id"); + if (billId < 0) { + continue; + } + + updateFileList(billId, fileList, mainTableName, false); + + if (CollectionUtils.isNotEmpty(childDataConfigList)) { + processChildDataConfigForUpdate(billId, childDataConfigList); + } + } + } + } + } + + /** + * 更新明细表补正文件数据 + * + * @param billId + * @param childDataConfigList + * @throws Exception + */ + private void processChildDataConfigForUpdate(int billId, List childDataConfigList) throws + Exception { + for (DataConfig childDataConfig : childDataConfigList) { + String detailTableName = childDataConfig.getDetailTableName(); + List childFileList = childDataConfig.getFileList(); + + if (CollectionUtils.isNotEmpty(childFileList)) { + baseBean.writeLog("开始解析文件,写入明细数据"); + updateFileList(billId, childFileList, detailTableName, true); + } + } + } + + /** + * 文件列表更新 + * + * @param mainId + * @param fileConfigList + * @param tableName + * @param isDetail + * @throws Exception + */ + private void updateFileList(int mainId, List fileConfigList, String tableName, boolean isDetail) throws Exception { + Map dataMap = new IgnoreCaseHashMap<>(); + String fileTypeField = ""; + String fileTypeValue = ""; + + for (FileConfig fileConfig : fileConfigList) { + String fieldName = fileConfig.getFieldName(); + String fileId = fileConfig.getFileId(); + String fixedValue = fileConfig.getFixedValue(); + String attachments = fileConfig.getAttachments(); + + if (StringUtils.isNotBlank(fixedValue)) { + continue; + } + + if (StringUtils.isNotBlank(attachments)) { + fileTypeField = fieldName; + fileTypeValue = attachments; + continue; + } + + if (!"2".equals(fileConfig.getIsFilled())) { + continue; + } + + List applicationResources = applicationResourceMap.get(fileId); + if (CollectionUtils.isEmpty(applicationResources)) { + baseBean.writeLog("根据fid未获取到数据,fileId==" + fileId); + continue; + } + + Map fileResourceMap = resourceInfoMap.get(fileConfig.getIsFilled()); + if (fileResourceMap == null || fileResourceMap.isEmpty()) { + baseBean.writeLog("根据文件类型未获取到数据,isFilled==" + fileConfig.getIsFilled()); + continue; + } + + List docIds = processFileResources(applicationResources, fileResourceMap); + if (!docIds.isEmpty()) { + dataMap.put(fieldName, StringUtils.join(docIds, ",")); + } + } + + if (dataMap.isEmpty() || StringUtils.isBlank(fileTypeField) || StringUtils.isBlank(fileTypeValue)) { + baseBean.writeLog("dataMap.size==" + dataMap.size()); + baseBean.writeLog("fileTypeField==" + fileTypeField); + baseBean.writeLog("fileTypeValue==" + fileTypeValue); + return; + } + + baseBean.writeLog("文件更新集合,dataMap==" + JSON.toJSONString(dataMap)); + updateData(mainId, dataMap, tableName, isDetail, fileTypeField, fileTypeValue); + } + + /** + * 上传对应的文件,返回docId集合 + * + * @param applicationResources + * @param fileResourceMap + * @return + * @throws Exception + */ + private List processFileResources(List applicationResources, + Map fileResourceMap) throws Exception { + List docIds = new ArrayList<>(); + + for (ApplicationResource resource : applicationResources) { + ResourceInfo resourceInfo = fileResourceMap.get(resource.getRid()); + if (resourceInfo == null) { + baseBean.writeLog("根据文件rid未获取到数据,rid==" + resource.getRid()); + continue; + } + + int imageFileId = generateImageFileId(zipFile, fileHeaderMap.get(resourceInfo.getFileName()), + resourceInfo.getFileName()); + int docId = ModeUtil.createDocId(uploadCatalogue, imageFileId, user); + docIds.add(docId); + } + + return docIds; + } + + + /** + * 更新补正文件数据 + * + * @param mainId + * @param dataMap + * @param tableName + * @param isDetail + * @param fileTypeField + * @param fileTypeValue + */ + private void updateData(int mainId, Map dataMap, String tableName, + boolean isDetail, String fileTypeField, String fileTypeValue) { + if (isDetail) { + //dataMap.put("mainid", mainId); + String whereSql = " where mainid = " + mainId + " and " + fileTypeField + "=" + fileTypeValue; + baseBean.writeLog("whereSql===" + whereSql); + ModeUtil.updateData(dataMap, tableName, whereSql); + } else { + dataMap.put("id", mainId); + ModeUtil.updateDataById(dataMap, tableName); + } + } + + /** + * 插入数据和文件 + * + * @param rootNode + * @throws Exception + */ + private void insertDataAndFiles(JsonNode rootNode, UnpackParam unpackParam) throws Exception { + initializeUploadCatalogue(); + List dataConfigList = getDataConfig(SOURCE_TYPE); + baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList)); + + checkDatas(dataConfigList, rootNode, unpackParam); + initializeResourceMaps(rootNode); + + if (CollectionUtils.isNotEmpty(dataConfigList)) { + processDataConfigForInsert(rootNode, dataConfigList); + } + } + + /** + * 校验数据是否一致 + * + * @param dataConfigList + * @param rootNode + * @param unpackParam + * @throws Exception + */ + private void checkDatas(List dataConfigList, JsonNode rootNode, UnpackParam unpackParam) throws Exception { + // 字段校验 + List checkFields = unpackParam.getCheckFields(); + String requestId = unpackParam.getRequestId(); + Map dataConfigMap = dataConfigList.stream().collect(Collectors.toMap(DataConfig::getMainTableName, item -> item, (k1, k2) -> k1)); + for (CheckFields checkField : checkFields) { + DataConfig dataConfig = dataConfigMap.get(checkField.getName()); + + + String fields = checkField.getFields(); + String formFields = checkField.getFormFields(); + if (StringUtils.isNotBlank(fields) && StringUtils.isNotBlank(formFields)) { + String[] fieldArray = fields.split(","); + String[] formFieldsArray = formFields.split(","); + if (fieldArray.length != formFieldsArray.length) { + throw new CustomizeRunTimeException("表单校验参数格式错误"); + } + List formFieldList = ModeUtil.getFieldList(dataConfig.getMainTableName()); + Map mainTableFieldMap = formFieldList.stream() + .filter(item -> item.getViewtype() == 0) + .collect(Collectors.toMap(Formfield::getFieldname, + item -> item, (k1, k2) -> k1)); + + String tableNameByRequestId = FlowUtil.getTableNameByRequestId(requestId); + RecordSet rs = new RecordSet(); + rs.executeQuery("select * from " + tableNameByRequestId + " where requestId = ?", requestId); + + IgnoreCaseHashMap flowDataMap = ModeUtil.getSingleRecordMap(rs); + + // 根据根结点,获取配置 + String rootPath = dataConfig.getRootPath(); + JsonNode checkNode; + if (StringUtils.isBlank(rootPath)) { + checkNode = rootNode; + } else { + checkNode = rootNode.get(rootPath); + } + if (null == checkNode) { + throw new CustomizeRunTimeException("未获取到根结点数据[" + rootPath + "]"); + } + + List detailList = dataConfig.getDetailList(); + Map configDetailMap = detailList.stream().collect(Collectors.toMap(DataConfigDetail::getFieldName, item -> item, (k1, k2) -> k1)); + for (int i = 0; i < fieldArray.length; i++) { + String field = fieldArray[i]; + String formField = formFieldsArray[i]; + boolean check = processFieldForCheck(checkNode, configDetailMap.get(field), mainTableFieldMap, Util.null2String(flowDataMap.get(formField))); + if (!check) { + Formfield formfield = mainTableFieldMap.get(field); + throw new CustomizeRunTimeException("[" + SystemEnv.getHtmlLabelName(formfield.getFieldlabel(), user.getLanguage()) + "]字段校验不通过,表单填写内容与解析包对应内容不一致"); + } + } + } + } + } + + /** + * 解析配置表 + * + * @param rootNode + * @param dataConfigList + * @throws Exception + */ + private void processDataConfigForInsert(JsonNode rootNode, List dataConfigList) throws Exception { + for (DataConfig dataConfig : dataConfigList) { + String mainTableName = dataConfig.getMainTableName(); + String relatedField = dataConfig.getRelatedField(); + String rootPath = dataConfig.getRootPath(); + baseBean.writeLog("rootPath==" + rootPath); + + List fieldDetailList = dataConfig.getDetailList(); + List childDataConfigList = dataConfig.getChildDataConfig(); + List fileList = dataConfig.getFileList(); + + List formFieldList = ModeUtil.getFieldList(mainTableName); + Map mainTableFieldMap = formFieldList.stream() + .filter(item -> item.getViewtype() == 0) + .collect(Collectors.toMap(Formfield::getFieldname, + item -> item, (k1, k2) -> k1)); + + if (CollectionUtils.isNotEmpty(fieldDetailList)) { + processRootPath(rootNode, mainTableName, relatedField, fieldDetailList, + mainTableFieldMap, childDataConfigList, formFieldList, fileList, rootPath); + } + } + } + + /** + * 根据根路径配置,判断处理方式 + * + * @param rootNode + * @param mainTableName + * @param relatedField + * @param fieldDetailList + * @param mainTableFieldMap + * @param childDataConfigList + * @param formFieldList + * @param fileList + * @param rootPath + * @throws Exception + */ + private void processRootPath(JsonNode rootNode, String mainTableName, String relatedField, + List fieldDetailList, Map mainTableFieldMap, + List childDataConfigList, List formFieldList, + List fileList, String rootPath) throws Exception { + if (StringUtils.isNotBlank(rootPath)) { + if (rootPath.contains("[*]")) { + processArrayRootPath(rootNode, mainTableName, relatedField, fieldDetailList, + mainTableFieldMap, childDataConfigList, formFieldList, + fileList, rootPath); + } else { + processSingleRootPath(rootNode, mainTableName, relatedField, fieldDetailList, + mainTableFieldMap, childDataConfigList, formFieldList, + fileList, rootPath); + } + } else { + processRootNode(rootNode, mainTableName, relatedField, fieldDetailList, + mainTableFieldMap, childDataConfigList, formFieldList, fileList); + } + } + + /** + * 处理数组数据 + * + * @param rootNode + * @param mainTableName + * @param relatedField + * @param fieldDetailList + * @param mainTableFieldMap + * @param childDataConfigList + * @param formFieldList + * @param fileList + * @param rootPath + * @throws Exception + */ + private void processArrayRootPath(JsonNode rootNode, String mainTableName, String relatedField, + List fieldDetailList, Map mainTableFieldMap, + List childDataConfigList, List formFieldList, + List fileList, String rootPath) throws Exception { + String path = rootPath.replace("[*]", ""); + JsonNode jsonNode = rootNode.at(path); + + if (jsonNode == null) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段:[" + path + "]"); + } + if (!jsonNode.isArray()) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + path + "]"); + } + Set tableIdList = getTableIdList(mainTableName); + for (JsonNode node : jsonNode) { + int billId = insertMainTable(node, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); + if (billId < 0) { + continue; + } + tableIdList.add(billId); + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); + dealFileList(billId, fileList, mainTableName, false); + } + } + + /** + * 处理单节点数据 + * + * @param rootNode + * @param mainTableName + * @param relatedField + * @param fieldDetailList + * @param mainTableFieldMap + * @param childDataConfigList + * @param formFieldList + * @param fileList + * @param rootPath + * @throws Exception + */ + private void processSingleRootPath(JsonNode rootNode, String mainTableName, String relatedField, + List fieldDetailList, Map mainTableFieldMap, + List childDataConfigList, List formFieldList, + List fileList, String rootPath) throws Exception { + JsonNode jsonNode = rootNode.at(rootPath); + int billId = insertMainTable(jsonNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); + if (billId < 0) { + return; + } + getTableIdList(mainTableName).add(billId); + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); + dealFileList(billId, fileList, mainTableName, false); + } + + /** + * 处理完整节点数据 + * + * @param rootNode + * @param mainTableName + * @param relatedField + * @param fieldDetailList + * @param mainTableFieldMap + * @param childDataConfigList + * @param formFieldList + * @param fileList + * @throws Exception + */ + private void processRootNode(JsonNode rootNode, String mainTableName, String relatedField, + List fieldDetailList, Map mainTableFieldMap, + List childDataConfigList, List formFieldList, + List fileList) throws Exception { + + int billId = insertMainTable(rootNode, mainTableName, relatedField, fieldDetailList, mainTableFieldMap); + if (billId < 0) { + return; + } + getTableIdList(mainTableName).add(billId); + dealDetailData(rootNode, billId, childDataConfigList, formFieldList); + dealFileList(billId, fileList, mainTableName, false); + } + + /** + * 处理明细表数据 + * + * @param rootNode + * @param mainId + * @param childDataConfigList + * @param formFieldList + * @throws Exception + */ + private void dealDetailData(JsonNode rootNode, int mainId, List childDataConfigList, + List formFieldList) throws Exception { + if (CollectionUtils.isEmpty(childDataConfigList)) { + return; + } + + for (DataConfig childDataConfig : childDataConfigList) { + String detailTableName = childDataConfig.getDetailTableName(); + Map detailTableFieldMap = formFieldList.stream() + .filter(item -> detailTableName.equals(item.getDetailtable())) + .collect(Collectors.toMap(Formfield::getFieldname, + item -> item, (k1, k2) -> k1)); + + List fieldList = childDataConfig.getDetailList(); + List fileList = childDataConfig.getFileList(); + + if (CollectionUtils.isNotEmpty(fileList)) { + baseBean.writeLog("开始解析文件,写入明细数据"); + dealFileList(mainId, fileList, detailTableName, true); + } else { + processDetailRootPath(rootNode, detailTableName, mainId, fieldList, detailTableFieldMap, + childDataConfig.getRootPath()); + } + } + } + + /** + * 根据明细表根路径配置,判断处理方式 + * + * @param rootNode + * @param detailTableName + * @param mainId + * @param fieldList + * @param detailTableFieldMap + * @param rootPath + * @throws Exception + */ + private void processDetailRootPath(JsonNode rootNode, String detailTableName, int mainId, + List fieldList, Map detailTableFieldMap, + String rootPath) throws Exception { + if (StringUtils.isNotBlank(rootPath)) { + if (rootPath.contains("[*]")) { + processDetailArrayRootPath(rootNode, detailTableName, mainId, fieldList, + detailTableFieldMap, rootPath); + } else { + processDetailSingleRootPath(rootNode, detailTableName, mainId, fieldList, + detailTableFieldMap, rootPath); + } + } else { + insertDetailTable(rootNode, detailTableName, mainId, fieldList, detailTableFieldMap); + } + } + + /** + * 处理明细表数据数据 + * + * @param rootNode + * @param detailTableName + * @param mainId + * @param fieldList + * @param detailTableFieldMap + * @param rootPath + * @throws Exception + */ + private void processDetailArrayRootPath(JsonNode rootNode, String detailTableName, int mainId, + List fieldList, Map detailTableFieldMap, + String rootPath) throws Exception { + String path = rootPath.replace("[*]", ""); + JsonNode jsonNode = rootNode.at(path); + + if (jsonNode == null) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段:[" + path + "]"); + } + if (!jsonNode.isArray()) { + throw new CustomizeRunTimeException("数据解析失败,未找到对应字段集合:[" + path + "]"); + } + + for (JsonNode node : jsonNode) { + insertDetailTable(node, detailTableName, mainId, fieldList, detailTableFieldMap); + } + } + + /** + * 处理明细表单节点数据 + * + * @param rootNode + * @param detailTableName + * @param mainId + * @param fieldList + * @param detailTableFieldMap + * @param rootPath + * @throws Exception + */ + private void processDetailSingleRootPath(JsonNode rootNode, String detailTableName, int mainId, + List fieldList, Map detailTableFieldMap, + String rootPath) throws Exception { + JsonNode jsonNode = rootNode.at(rootPath); + insertDetailTable(jsonNode, detailTableName, mainId, fieldList, detailTableFieldMap); + } + + /** + * 插入主表数据 + * + * @param jsonNode + * @param mainTableName + * @param relatedField + * @param fieldList + * @param mainTableFieldMap + * @return + * @throws Exception + */ + private int insertMainTable(JsonNode jsonNode, String mainTableName, String relatedField, + List fieldList, Map mainTableFieldMap) throws Exception { + Map insertMap = new IgnoreCaseHashMap<>(); + + for (DataConfigDetail fieldDetail : fieldList) { + processFieldForInsert(jsonNode, insertMap, fieldDetail, mainTableFieldMap); + } + + if (insertMap.isEmpty()) { + return -1; + } + + if (StringUtils.isNotBlank(relatedField)) { + insertMap.put(relatedField, relatedFlowId); + } + + String uuid = UUID.randomUUID().toString(); + insertMap.put("modeuuid", uuid); + int formModeId = ModeUtil.getModeIdByTableName(mainTableName); + insertMap.put("formmodeid", formModeId); + + ModeUtil.buildModeInsertFields(insertMap, user.getUID()); + baseBean.writeLog("insertMainTable: " + JSON.toJSONString(insertMap)); + + ModeUtil.insertData(insertMap, mainTableName); + return ModeUtil.refreshRight(uuid, mainTableName, formModeId, user.getUID()); + } + + /** + * 构建待插入数据的字段集合 + * + * @param jsonNode + * @param insertMap + * @param fieldDetail + * @param fieldMap + * @throws Exception + */ + private boolean processFieldForInsert(JsonNode jsonNode, Map insertMap, + DataConfigDetail fieldDetail, Map fieldMap) throws Exception { + String fieldName = fieldDetail.getFieldName(); + JsonNode atNode = jsonNode.at(fieldDetail.getPath()); + + if (atNode != null) { + String value = atNode.asText(); + if (StringUtils.isNotBlank(fieldDetail.getCondition()) && !value.equals(fieldDetail.getCondition())) { + return true; + } + + Formfield formfield = fieldMap.get(fieldName.toLowerCase()); + if (formfield == null) { + return false; + } + + Object reallyValue = getFieldValue(fieldDetail, value, formfield); + insertMap.put(fieldName, reallyValue); + } + return false; + } + + /** + * 构建待校验数据的字段集合 + * + * @param jsonNode + * @param fieldDetail + * @param fieldMap + * @return + * @throws Exception + */ + private boolean processFieldForCheck(JsonNode jsonNode, DataConfigDetail fieldDetail, Map fieldMap,String flowData) throws Exception { + String fieldName = fieldDetail.getFieldName(); + JsonNode atNode = jsonNode.at(fieldDetail.getPath()); + + if (atNode != null) { + String value = atNode.asText(); + if (StringUtils.isNotBlank(fieldDetail.getCondition()) && !value.equals(fieldDetail.getCondition())) { + return false; + } + + Formfield formfield = fieldMap.get(fieldName.toLowerCase()); + if (formfield == null) { + return false; + } + + return flowData.equals(Util.null2String(getFieldValue(fieldDetail, value, formfield))); + } + return false; + } + + /** + * 字段值转换,转换为数据库中对应的实际值 + * + * @param fieldDetail + * @param value + * @param formfield + * @return + * @throws Exception + */ + private Object getFieldValue(DataConfigDetail fieldDetail, String value, Formfield formfield) throws Exception { + if (StringUtils.isNotBlank(fieldDetail.getConvertSql())) { + return FieldConvertUtil.executeConvertSql(fieldDetail.getConvertSql(), value); + } + return FieldConvertUtil.getReallyValue(formfield, value); + } + + /** + * 插入明细表数据 + * + * @param jsonNode + * @param detailTableName + * @param mainId + * @param fieldList + * @param detailTableFieldMap + * @throws Exception + */ + private void insertDetailTable(JsonNode jsonNode, String detailTableName, int mainId, + List fieldList, Map detailTableFieldMap) throws Exception { + Map insertMap = new IgnoreCaseHashMap<>(); + + for (DataConfigDetail fieldDetail : fieldList) { + boolean isReturn = processFieldForInsert(jsonNode, insertMap, fieldDetail, detailTableFieldMap); + if (isReturn) { + return; + } + } + + if (insertMap.isEmpty()) { + return; + } + + insertMap.put("mainId", mainId); + baseBean.writeLog("insertDetailTable: " + JSON.toJSONString(insertMap)); + ModeUtil.insertData(insertMap, detailTableName); + } + + /** + * 处理文件列表 + * + * @param mainId + * @param fileConfigList + * @param tableName + * @param isDetail + * @throws Exception + */ + private void dealFileList(int mainId, List fileConfigList, String tableName, boolean isDetail) throws + Exception { + Map dataMap = new IgnoreCaseHashMap<>(); + Map defaultDataMap = new IgnoreCaseHashMap<>(); + + for (FileConfig fileConfig : fileConfigList) { + processFileConfig(fileConfig, dataMap, defaultDataMap); + } + + if (dataMap.isEmpty()) { + baseBean.writeLog("dataMap集合为空"); + return; + } + + dataMap.putAll(defaultDataMap); + baseBean.writeLog("文件插入集合,dataMap==" + JSON.toJSONString(dataMap)); + + if (isDetail) { + dataMap.put("mainid", mainId); + ModeUtil.insertData(dataMap, tableName); + } else { + dataMap.put("id", mainId); + ModeUtil.updateDataById(dataMap, tableName); + } + } + + /** + * 根据文件配置,构建数据集合 + * + * @param fileConfig + * @param dataMap + * @param defaultDataMap + * @throws Exception + */ + private void processFileConfig(FileConfig fileConfig, Map dataMap, + Map defaultDataMap) throws Exception { + String fieldName = fileConfig.getFieldName(); + String isFilled = fileConfig.getIsFilled(); + + if ("2".equals(isFilled)) { + return; + } + + String fileId = fileConfig.getFileId(); + String fixedValue = fileConfig.getFixedValue(); + String attachments = fileConfig.getAttachments(); + + if (StringUtils.isNotBlank(fixedValue)) { + defaultDataMap.put(fieldName, fixedValue); + return; + } + + if (StringUtils.isNotBlank(attachments)) { + defaultDataMap.put(fieldName, attachments); + return; + } + + List applicationResources = applicationResourceMap.get(fileId); + if (CollectionUtils.isEmpty(applicationResources)) { + baseBean.writeLog("根据fid未获取到数据,fileId==" + fileId); + return; + } + + Map fileResourceMap = resourceInfoMap.get(isFilled); + if (fileResourceMap == null || fileResourceMap.isEmpty()) { + baseBean.writeLog("根据文件类型未获取到数据,isFilled==" + isFilled); + return; + } + + List docIds = processFileResources(applicationResources, fileResourceMap); + if (!docIds.isEmpty()) { + dataMap.put(fieldName, StringUtils.join(docIds, ",")); + } + } + + /** + * 获取配置主项 + * + * @param type + * @return + */ + private List getDataConfig(String type) { + List dataConfigList = new ArrayList<>(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select * from " + QualificationApplicationServiceImpl.CONFIG_TABLE_NAME + " where main_table is not null and source_type = ?", type); + + while (rs.next()) { + DataConfig dataConfig = buildDataConfig(rs); + dataConfig.setDetailList(getDetailList(dataConfig.getId())); + dataConfig.setFileList(getFileList(dataConfig.getId())); + + String detailTableName = dataConfig.getDetailTableName(); + if (StringUtils.isNotBlank(detailTableName)) { + dataConfig.setChildDataConfig(getChildDataConfig(detailTableName, type)); + } + + dataConfigList.add(dataConfig); + } + return dataConfigList; + } + + /** + * 构建DataConfig对象 + * + * @param rs + * @return + * @throws RuntimeException + */ + private DataConfig buildDataConfig(RecordSet rs) throws RuntimeException { + DataConfig dataConfig = new DataConfig(); + dataConfig.setId(rs.getString("id")); + dataConfig.setMainTableName(rs.getString("main_table")); + dataConfig.setRelatedField(rs.getString("related_field")); + dataConfig.setDetailTableName(rs.getString("detail_tables")); + dataConfig.setRootPath(rs.getString("root_path")); + return dataConfig; + } + + /** + * 构建明细表配置项集合 + * + * @param detailTableName + * @param type + * @return + */ + private List getChildDataConfig(String detailTableName, String type) { + String[] detailNameArray = detailTableName.split(","); + List dataConfigList = new ArrayList<>(); + + for (String dtName : detailNameArray) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select * from " + QualificationApplicationServiceImpl.CONFIG_TABLE_NAME + " where main_table is null and detail_tables = ? and source_type = ?", dtName, type); + + while (rs.next()) { + DataConfig dataConfig = new DataConfig(); + dataConfig.setId(rs.getString("id")); + dataConfig.setDetailTableName(rs.getString("detail_tables")); + dataConfig.setRootPath(rs.getString("root_path")); + dataConfig.setDetailList(getDetailList(dataConfig.getId())); + dataConfig.setFileList(getFileList(dataConfig.getId())); + dataConfigList.add(dataConfig); + } + } + return dataConfigList; + } + + /** + * 获取字段配置对照关系集合 + * + * @param mainId + * @return + */ + private List getDetailList(String mainId) { + List detailList = new ArrayList<>(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select * from " + QualificationApplicationServiceImpl.CONFIG_DETAIL_TABLE_NAME + " where mainId = ?", mainId); + + while (rs.next()) { + detailList.add(DataConfigDetail.builder() + .fieldName(rs.getString("field_name")) + .path(rs.getString("config_path")) + .condition(rs.getString("conditions")) + .convertSql(rs.getString("convert_sql")) + .build()); + } + return detailList; + } + + /** + * 获取文件配置对照关系集合 + * + * @param mainId + * @return + */ + private List getFileList(String mainId) { + List fileList = new ArrayList<>(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select * from " + QualificationApplicationServiceImpl.FILE_DETAIL_TABLE_NAME + " where mainId = ?", mainId); + + while (rs.next()) { + fileList.add(FileConfig.builder() + .fieldName(rs.getString("field_name")) + .fileId(rs.getString("file_id")) + .isFilled(rs.getString("file_type")) + .fixedValue(rs.getString("fixed_value")) + .attachments(rs.getString("attachments")) + .build()); + } + return fileList; + } + + /** + * 解析配置文件爱你,构建ApplicationResource集合 + * + * @param rootNode + * @return + */ + private List getApplicationResourceList(JsonNode rootNode) { + List applicationResourceList = new ArrayList<>(); + JsonNode applicationResourceListNode = rootNode.at("/applicationResourceList"); + + if (applicationResourceListNode != null && applicationResourceListNode.isArray()) { + for (JsonNode jsonNode : applicationResourceListNode) { + applicationResourceList.add(ApplicationResource.builder() + .id(jsonNode.at("/id").asText()) + .aid(jsonNode.at("/aid").asText()) + .fid(jsonNode.at("/fid").asText()) + .rid(jsonNode.at("/rid").asText()) + .createdTime(jsonNode.at("/createdTime").asText()) + .isDelete(jsonNode.at("/isDelete").asText()) + .build()); + } + } + return applicationResourceList; + } + + + /** + * 解析配置文件爱你,构建ResourceInfo集合 + * + * @param rootNode + * @return + */ + private List getResourceInfoList(JsonNode rootNode) { + List resourceInfoList = new ArrayList<>(); + JsonNode resourceInfoListNode = rootNode.at("/resourceInfoList"); + + if (resourceInfoListNode != null && resourceInfoListNode.isArray()) { + for (JsonNode jsonNode : resourceInfoListNode) { + resourceInfoList.add(ResourceInfo.builder() + .id(jsonNode.at("/id").asText()) + .fileName(jsonNode.at("/fileName").asText()) + .filePath(jsonNode.at("/filePath").asText()) + .fileSuffix(jsonNode.at("/fileSuffix").asText()) + .virtualPath(jsonNode.at("/virtualPath").asText()) + .createdTime(jsonNode.at("/createdTime").asText()) + .updatedTime(jsonNode.at("/updatedTime").asText()) + .isDelete(jsonNode.at("/isDelete").asText()) + .build()); + } + } + return resourceInfoList; + } + + + /** + * 上传文件,生成imageFileId + * + * @param zipFile + * @param header + * @param fileName + * @return + */ + private int generateImageFileId(ZipFile zipFile, FileHeader header, String fileName) { + try (InputStream is = zipFile.getInputStream(header)) { + return ModeUtil.generateImageFileId(is, fileName); + } catch (Exception e) { + throw new CustomizeRunTimeException(e); + } + } + + + /** + * 获取主表的ID集合 + * + * @param mainTableName + * @return + */ + private Set getTableIdList(String mainTableName) { + return insertTableMap.computeIfAbsent(mainTableName, k -> ConcurrentHashMap.newKeySet()); + + } +} \ No newline at end of file diff --git a/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java b/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java new file mode 100644 index 0000000..a865c26 --- /dev/null +++ b/src/com/engine/secret/service/impl/QualificationApplicationServiceImpl.java @@ -0,0 +1,239 @@ +package com.engine.secret.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; +import com.engine.common.util.ServiceUtil; +import com.engine.core.impl.Service; +import com.engine.secret.entity.unpack.CheckFields; +import com.engine.secret.entity.unpack.UnpackParam; +import com.engine.secret.exception.CustomizeRunTimeException; +import com.engine.secret.service.QualificationApplicationService; +import com.engine.secret.util.ConfigUtil; +import com.engine.secret.util.ModeUtil; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.wbi.util.Util; +import net.lingala.zip4j.ZipFile; +import net.lingala.zip4j.model.FileHeader; +import org.apache.commons.lang.StringUtils; +import weaver.docs.docs.DocImageManager; +import weaver.file.ImageFileManager; +import weaver.general.BaseBean; +import weaver.general.GCONST; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2024/08/29 + * @version: 1.0 + */ +public class QualificationApplicationServiceImpl extends Service implements QualificationApplicationService { + + + public static final String CONFIG_TABLE_NAME = "uf_config_package"; + public static final String CONFIG_DETAIL_TABLE_NAME = "uf_config_package_dt1"; + public static final String FILE_DETAIL_TABLE_NAME = "uf_config_package_dt2"; + + BaseBean baseBean = new BaseBean(); + + Map fileHeaderMap; + + + @Override + public Map parsingFiles(Map param) { + try { + Map returnMap; + + String docId = Util.null2String(param.get("docId")); + String requestId = Util.null2String(param.get("requestId")); + String isCorrection = Util.null2String(param.get("isCorrection")); + String checkFields = Util.null2String(param.get("checkFields")); + if (StringUtils.isBlank(docId)) { + throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传"); + } + baseBean.writeLog("docId==" + docId); + + if (StringUtils.isBlank(requestId)) { + throw new CustomizeRunTimeException("流程关联失败,未获取到流程ID,请保存后重试"); + } + + baseBean.writeLog("requestId==" + requestId); + List checkFieldsList = new ArrayList<>(); + if (StringUtils.isNotBlank(checkFields)) { + checkFieldsList = JSON.parseObject(checkFields, new TypeReference>() {}); + } + + UnpackParam unpackParam = UnpackParam.builder() + .docId(docId) + .requestId(requestId) + .isCorrection(Boolean.parseBoolean(isCorrection)) + .checkFields(checkFieldsList) + .build(); + + + // docId 转为换imageFileId + DocImageManager imgManger = new DocImageManager(); + imgManger.setDocid(Integer.parseInt(docId)); + imgManger.selectDocImageInfo(); + imgManger.next(); + String imageFileId = imgManger.getImagefileid(); + baseBean.writeLog("imageFileId==" + imageFileId); + if (StringUtils.isBlank(imageFileId) || "-1".equals(imageFileId)) { + throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传,imageFileId=[" + imageFileId + "]"); + } + + + // 初始化配置 + String unzipPwd = ConfigUtil.getConfig("UNZIP_PWD"); + baseBean.writeLog("unzipPwd==" + unzipPwd); + + + // 根据文件id获取文件流 + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(Integer.parseInt(imageFileId)); + manager.getImageFileName(); + InputStream inputStream = manager.getInputStream(); + + Path fixedDir = Paths.get(GCONST.getRootPath() + "filesystem" + File.separatorChar + "downloadBatchTemp"); + Files.createDirectories(fixedDir); + Path tempZipFile = Files.createTempFile(fixedDir, "offline_temp_", ".zip"); + baseBean.writeLog("tempZipFile==" + tempZipFile.toString()); + Files.copy(inputStream, tempZipFile, StandardCopyOption.REPLACE_EXISTING); + + //解压文件,处理压缩包 + baseBean.writeLog("开始解压文件,处理压缩包"); + returnMap = unzipWithPassword(tempZipFile, Paths.get("output"), unzipPwd, unpackParam); + baseBean.writeLog("压缩包处理完成"); + return returnMap; + } catch (Exception e) { + baseBean.writeLog(e); + throw new CustomizeRunTimeException(e.getMessage(), e); + } + } + + @Override + public Map deleteParsedData(Map param) { + return ServiceUtil.getService(OfflineZipUnpackServiceImpl.class, user).deleteParsedData(param); + } + + /** + * 解压ZIP文件 + * + * @param zipFilePath + * @param outputDir + * @param password + */ + private Map unzipWithPassword(Path zipFilePath, Path outputDir, String password, UnpackParam unpackParam) { + try { + ZipFile zipFile = new ZipFile(zipFilePath.toFile()); + if (zipFile.isEncrypted()) { + zipFile.setPassword(password.toCharArray()); + } + // 遍历并解压所有文件 + zipFile.extractAll(outputDir.toString()); + baseBean.writeLog("已解压所有文件"); + + // 遍历 ZIP 内文件(可选) + List fileHeaders = zipFile.getFileHeaders(); + + //imageFileMap = new HashMap<>(); + fileHeaderMap = new HashMap<>(); + for (FileHeader header : fileHeaders) { + if (header.isDirectory()) { + continue; + } + String fullPath = header.getFileName(); + int lastSlashIndex = fullPath.lastIndexOf('/'); + String fileName = (lastSlashIndex != -1) + ? fullPath.substring(lastSlashIndex + 1) + : fullPath; + fileHeaderMap.put(fileName, header); + } + + + baseBean.writeLog("fileHeaders.size==" + fileHeaders.size()); + baseBean.writeLog("fileHeaderMap.size==" + fileHeaderMap.size()); + baseBean.writeLog("fileHeaderMap==" + JSON.toJSONString(fileHeaderMap)); + + + // 获取数据文件,用于后续数据解析 + String jsonFileName = "(database)data.json"; + if (unpackParam.isCorrection()) { + jsonFileName = "(extra)data.json"; + } + FileHeader fileHeader = fileHeaderMap.get(jsonFileName); + int dataJsonImageId = generateImageFileId(zipFile, fileHeader, jsonFileName); + + if (dataJsonImageId > 0) { + // 离线端方式 + JsonNode rootNode = parseJsonContent(dataJsonImageId); + OfflineZipUnpackServiceImpl offlineZipUnpackService = ServiceUtil.getService(OfflineZipUnpackServiceImpl.class, user); + if (unpackParam.isCorrection()) { + return offlineZipUnpackService.reviewResubmittedMaterials(zipFile, unpackParam.getRequestId(), rootNode, fileHeaderMap); + } + return offlineZipUnpackService.registerAcceptance(zipFile, unpackParam, rootNode, fileHeaderMap); + } + + // TODO 兼容其他方式 + + return new HashMap<>(); + + } catch (Exception e) { + if (e.getMessage().contains("Wrong password")) { + throw new CustomizeRunTimeException("数据包解压失败,密码错误"); + } else { + baseBean.writeLog(e); + throw new CustomizeRunTimeException(e.getMessage(), e); + } + } finally { + try { + Files.deleteIfExists(zipFilePath); + } catch (IOException e) { + baseBean.writeLog(e); + } + } + } + + + /** + * 获取JSON文件内容 + * + * @param imageFieldId + * @return + * @throws IOException + */ + private static JsonNode parseJsonContent(Integer imageFieldId) throws IOException { + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(imageFieldId); + InputStream inputStream = manager.getInputStream(); + ObjectMapper mapper = new ObjectMapper(); + return mapper.readTree(inputStream); + } + + /** + * 上传文件 返回imageFileId + * + * @param zipFile + * @param header + * @return + */ + private int generateImageFileId(ZipFile zipFile, FileHeader header, String fileName) { + try (InputStream is = zipFile.getInputStream(header)) { + return ModeUtil.generateImageFileId(is, fileName); + } catch (Exception e) { + throw new CustomizeRunTimeException(e); + } + } + +} diff --git a/src/com/engine/secret/util/ConfigUtil.java b/src/com/engine/secret/util/ConfigUtil.java new file mode 100644 index 0000000..30f830d --- /dev/null +++ b/src/com/engine/secret/util/ConfigUtil.java @@ -0,0 +1,24 @@ +package com.engine.secret.util; + +import org.apache.commons.lang.StringUtils; +import weaver.conn.RecordSet; + +/** + * @author:dxfeng + * @createTime: 2025/03/31 + * @version: 1.0 + */ +public class ConfigUtil { + public static String getConfig(String name) { + if (StringUtils.isBlank(name)) { + return ""; + } + RecordSet rs = new RecordSet(); + rs.executeQuery("select value from uf_config where name = ?",name.trim()); + if(rs.next()){ + return rs.getString("value").trim(); + } + return ""; + } + +} diff --git a/src/com/engine/secret/util/ExceptionUtil.java b/src/com/engine/secret/util/ExceptionUtil.java new file mode 100644 index 0000000..acf11da --- /dev/null +++ b/src/com/engine/secret/util/ExceptionUtil.java @@ -0,0 +1,20 @@ +package com.engine.secret.util; + +/** + * @Author weaver_cl + * @Description: + * @Date 2023/2/21 + * @Version V1.0 + **/ +public class ExceptionUtil { + public static String getRealMessage(Throwable e) { + while (e != null) { + Throwable cause = e.getCause(); + if (cause == null) { + return e.getMessage(); + } + e = cause; + } + return ""; + } +} diff --git a/src/com/engine/secret/util/FieldConvertUtil.java b/src/com/engine/secret/util/FieldConvertUtil.java new file mode 100644 index 0000000..c051ee4 --- /dev/null +++ b/src/com/engine/secret/util/FieldConvertUtil.java @@ -0,0 +1,166 @@ +package com.engine.secret.util; + +import com.weaver.formmodel.data.model.Formfield; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.validator.GenericValidator; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.definedfield.HrmFieldManager; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/04/02 + * @version: 1.0 + */ +public class FieldConvertUtil { + + /** + * 转换存入数据库的值 + * + * @param formfield + * @param value + * @return + * @throws Exception + */ + public static Object getReallyValue(Formfield formfield, String value) throws Exception { + if (StringUtils.isBlank(value)) { + return null; + } + RecordSet rs = new RecordSet(); + Object object = null; + String type = Util.null2String(formfield.getType()); + switch (formfield.getFieldhtmltype()) { + case "1": + // INPUT + if ("2".equals(type)) { + object = new BigDecimal(value).intValue(); + } else if ("3".equals(type)) { + object = new BigDecimal(value).floatValue(); + } else if ("1".equals(type)) { + object = value; + } else { + try { + object = new BigDecimal(value).toPlainString(); + } catch (NumberFormatException ignore) { + object = value; + } + } + break; + case "3": + // BROWSER + org.json.JSONObject jsonObject = new org.json.JSONObject(); + jsonObject.put("fieldhtmltype", formfield.getFieldhtmltype()); + jsonObject.put("type", type); + jsonObject.put("fieldvalue", value); + if ("161".equals(type) || "162".equals(type)) { + jsonObject.put("dmlurl", formfield.getFielddbtype()); + } else { + jsonObject.put("dmlurl", type); + } + + jsonObject.put("fieldid", 0); + object = HrmFieldManager.getReallyFieldvalue(jsonObject); + // 如果是日期,校验日期的合法性 + if ("2".equals(type)) { + boolean isDate = GenericValidator.isDate(Util.null2String(object), "yyyy-MM-dd", true); + if (!isDate) { + rs.writeLog("日期格式校验失败,object==" + Util.null2String(object)); + object = ""; + } + } + break; + case "5": + // 区分单选、复选、下拉框 + switch (type) { + case "1": + case "3": + // 下拉框、单选框 + object = ModeUtil.getSelectValue(formfield, value); + if (StringUtils.isBlank(Util.null2String(object))) { + if (isNumberOrCommaSeparatedNumbers(value)) { + object = value; + } + } + break; + case "2": + if (StringUtils.isNotBlank(value)) { + List selectValues = new ArrayList<>(); + // 兼容分隔符 + String separator = ","; + if (value.contains("、")) { + separator = "、"; + } + String[] split = value.split(separator); + for (String s : split) { + selectValues.add(ModeUtil.getSelectValue(formfield, s)); + } + object = StringUtils.join(selectValues, ","); + if (StringUtils.isBlank(Util.null2String(object))) { + if (isNumberOrCommaSeparatedNumbers(value)) { + object = value; + } + } + } + break; + default: + break; + } + + break; + case "4": + // CHECKBOX + case "6": + // FILEUPLOAD + break; + case "7": + // TEXT + case "2": + // TEXTAREA + default: + object = value; + break; + } + return object; + } + + + /** + * 执行转换SQL + * + * @param convertSql + * @param value + * @return + */ + public static String executeConvertSql(String convertSql, String value) { + RecordSet rs = new RecordSet(); + value = Util.null2String(value); + long count = convertSql.chars().filter(c -> c == '?').count(); + List paramsList = new ArrayList<>(); + for (int i = 0; i < count; i++) { + paramsList.add(value); + } + rs.executeQuery(convertSql, paramsList); + if (rs.next()) { + return rs.getString(1); + } + return ""; + } + + + /** + * 校验字符串是否为纯数字或逗号分隔的数字 + * + * @param str + * @return + */ + public static boolean isNumberOrCommaSeparatedNumbers(String str) { + // 正则表达式匹配纯数字或逗号分隔的数字 + // 允许前后有空格,数字之间用逗号分隔 + String regex = "^\\s*\\d+(\\s*,\\s*\\d+)*\\s*$"; + return str.matches(regex); + } +} diff --git a/src/com/engine/secret/util/FlowUtil.java b/src/com/engine/secret/util/FlowUtil.java new file mode 100644 index 0000000..aac67bb --- /dev/null +++ b/src/com/engine/secret/util/FlowUtil.java @@ -0,0 +1,81 @@ +package com.engine.secret.util; + +import com.alibaba.fastjson.JSON; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.workflow.webservices.WorkflowRequestInfo; +import weaver.workflow.webservices.WorkflowServiceImpl; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/04/09 + * @version: 1.0 + */ +public class FlowUtil { + + /** + * 根据流程请求ID,获取对应流程的表名 + * + * @param requestId + * @return + */ + public static String getTableNameByRequestId(String requestId) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select a.tablename from workflow_bill a join workflow_base b on a.id = b.formid where b.id = ( select workflowid from workflow_requestbase where requestid = ?)", requestId); + if (rs.next()) { + return rs.getString("tablename"); + } + return ""; + } + + + /** + * 获取流程的当前处理人 + * + * @param requestId + * @return + */ + public static List getCurrentUserIds(String requestId) { + RecordSet rs = new RecordSet(); + String sql = "select * from workflow_currentoperator where isremark = '0' and usertype = 0 and requestid=? order by id asc"; + List currentUserIds = new ArrayList(); + rs.executeQuery(sql, requestId); + while (rs.next()) { + currentUserIds.add(Util.getIntValue(Util.null2String(rs.getString("userid")))); + } + return currentUserIds; + } + + + /** + * 提交流程到下一节点 + * + * @param requestId + * @param creator + * @param opinions + * @return + */ + public static String submitWorkflowRequest(String requestId, int creator, String opinions) { + BaseBean bean = new BaseBean(); + WorkflowServiceImpl workflowService = new WorkflowServiceImpl(); + WorkflowRequestInfo wri = workflowService.getWorkflowRequest(Util.getIntValue(requestId, 0), creator, 0); + bean.writeLog("wri==" + JSON.toJSONString(wri)); + return workflowService.submitWorkflowRequest(wri, Util.getIntValue(requestId, 0), creator, "submit", opinions); + } + + /** + * 提交流程到下一节点(机器人节点) + * + * @param requestId + * @param opinions + * @return + */ + public static String submitWorkflowRequest(String requestId, String opinions) { + WorkflowServiceImpl workflowService = new WorkflowServiceImpl(); + return workflowService.submitWorkflowRequest(null, Util.getIntValue(requestId, 0), 0, "submit", opinions); + } +} diff --git a/src/com/engine/secret/util/ModeUtil.java b/src/com/engine/secret/util/ModeUtil.java new file mode 100644 index 0000000..d9491d4 --- /dev/null +++ b/src/com/engine/secret/util/ModeUtil.java @@ -0,0 +1,480 @@ +package com.engine.secret.util; + +import com.engine.secret.exception.CustomizeRunTimeException; +import com.weaver.formmodel.data.manager.FormInfoManager; +import com.weaver.formmodel.data.model.Formfield; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.util.IOUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; +import weaver.docs.docs.*; +import weaver.file.ImageFileManager; +import weaver.formmode.IgnoreCaseHashMap; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @author:dxfeng + * @createTime: 2025/03/26 + * @version: 1.0 + */ +public class ModeUtil { + + /** + * 生成附件ID + * + * @param inputStream + * @param filename + * @return + */ + public static int generateImageFileId(InputStream inputStream, String filename) { + int imageFileId; + try { + byte[] bytes = IOUtils.toByteArray(inputStream); + ImageFileManager ifm = new ImageFileManager(); + ifm.setData(bytes); + ifm.setImagFileName(filename); + imageFileId = ifm.saveImageFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + return imageFileId; + } + + /** + * 附件imageFieldId生成docId + * + * @param secCategory + * @param imageFieldId + * @param user + * @return + * @throws Exception + */ + public static int createDocId(int secCategory, int imageFieldId, User user) throws Exception { + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(imageFieldId); + String filenameqc = manager.getImageFileName(); + String filenamebc = filenameqc.substring(0, filenameqc.lastIndexOf(".")); + RecordSet rs = new RecordSet(); + DocManager dm = new DocManager(); + DocImageManager imgManger = new DocImageManager(); + + imgManger.setDocfiletype("2"); + + int docId = dm.getNextDocId(rs); + imgManger.setDocid(docId); + imgManger.setImagefileid(imageFieldId); + imgManger.setImagefilename(filenameqc); + imgManger.setIsextfile("1"); + imgManger.AddDocImageInfo(); + + String date = TimeUtil.getCurrentDateString(); + String time = TimeUtil.getOnlyCurrentTimeString(); + dm.setId(docId); + dm.setMaincategory(0); + dm.setSubcategory(0); + dm.setSeccategory(secCategory); + dm.setLanguageid(user.getLanguage()); + + dm.setDocstatus("1"); + dm.setDocsubject(filenamebc); + dm.setDoccreaterid(user.getUID()); + dm.setDocCreaterType(user.getLogintype()); + dm.setUsertype(user.getLogintype()); + dm.setOwnerid(user.getUID()); + dm.setOwnerType(user.getLogintype()); + dm.setDoclastmoduserid(user.getUID()); + dm.setDocLastModUserType(user.getLogintype()); + dm.setDoccreatedate(date); + dm.setDoclastmoddate(date); + dm.setDoccreatetime(time); + dm.setDoclastmodtime(time); + dm.setDoclangurage(user.getLanguage()); + dm.setKeyword(filenameqc); + dm.setIsapprover("0"); + dm.setIsreply(""); + dm.setDocdepartmentid(user.getUserDepartment()); + dm.setDocreplyable("1"); + dm.setAccessorycount(1); + dm.setParentids("" + docId); + dm.setUserid(user.getUID()); + DocCoder docCoder = new DocCoder(); + dm.setDocCode(docCoder.getDocCoder("" + secCategory)); + dm.setDocEditionId(dm.getNextEditionId(rs)); + dm.setDocEdition(1); + dm.AddDocInfo(); + dm.AddShareInfo(); + DocViewer DocViewer = new DocViewer(); + DocViewer.setDocShareByDoc("" + docId); + DocComInfo dc = new DocComInfo(); + dc.addDocInfoCache("" + docId); + return docId; + } + + /** + * 获取单个记录映射 + * + * @param rs RecordSet + * @return + */ + public static IgnoreCaseHashMap getSingleRecordMap(RecordSet rs) { + IgnoreCaseHashMap dataMap = new IgnoreCaseHashMap<>(); + if (rs.next()) { + String[] columnNames = rs.getColumnName(); + for (String columnName : columnNames) { + dataMap.put(columnName, parseBlankToNull(rs.getString(columnName))); + } + } + return dataMap; + } + + public static List> getRecordMapList(RecordSet rs) { + List> list = new ArrayList<>(); + while (rs.next()) { + String[] columnNames = rs.getColumnName(); + Map dataMap = new IgnoreCaseHashMap<>(); + for (String columnName : columnNames) { + dataMap.put(columnName.toLowerCase(), parseBlankToNull(rs.getString(columnName))); + } + list.add(dataMap); + } + return list; + } + + /** + * 插入数据 + * + * @param dataMap 数据集合 + * @param tableName 表名 + */ + public static void insertData(Map dataMap, String tableName) { + List fieldList = new ArrayList<>(); + List dataList = new ArrayList<>(); + List paramList = new ArrayList<>(); + + dataMap.forEach((key, value) -> { + if (null != value) { + String valueStr = String.valueOf(value); + if (StringUtils.isNotBlank(valueStr)) { + fieldList.add(key); + dataList.add(valueStr); + paramList.add("?"); + } + } + }); + String insertSql = " insert into " + tableName + "(" + StringUtils.join(fieldList, ",") + ") values (" + StringUtils.join(paramList, ",") + ")"; + RecordSet rs = new RecordSet(); + rs.executeUpdate(insertSql, dataList); + if (StringUtils.isNotBlank(rs.getExceptionMsg())) { + throw new CustomizeRunTimeException(rs.getExceptionMsg()); + } + } + + public static void insertData(RecordSetTrans rs,Map dataMap, String tableName) throws Exception { + List fieldList = new ArrayList<>(); + List dataList = new ArrayList<>(); + List paramList = new ArrayList<>(); + + dataMap.forEach((key, value) -> { + if (null != value) { + String valueStr = String.valueOf(value); + if (StringUtils.isNotBlank(valueStr)) { + fieldList.add(key); + dataList.add(valueStr); + paramList.add("?"); + } + } + }); + String insertSql = " insert into " + tableName + "(" + StringUtils.join(fieldList, ",") + ") values (" + StringUtils.join(paramList, ",") + ")"; + rs.executeUpdate(insertSql, dataList); + } + + /** + * 根据ID更新数据 + * + * @param dataMap + * @param tableName + */ + public static void updateDataById(Map dataMap, String tableName) { + List fieldList = new ArrayList<>(); + List dataList = new ArrayList<>(); + String id = Util.null2String(dataMap.get("id")); + dataMap.remove("id"); + + dataMap.forEach((key, value) -> { + fieldList.add(key + " = ? "); + dataList.add(value); + }); + dataList.add(id); + String updateSql = "update " + tableName + " set " + StringUtils.join(fieldList, ",") + " where id = ? "; + RecordSet rs = new RecordSet(); + rs.executeUpdate(updateSql, dataList); + if (StringUtils.isNotBlank(rs.getExceptionMsg())) { + throw new CustomizeRunTimeException(rs.getExceptionMsg()); + } + } + + /** + * 根据ID更新数据 + * + * @param dataMap + * @param tableName + */ + public static void updateDataById(RecordSetTrans rs,Map dataMap, String tableName) throws Exception { + List fieldList = new ArrayList<>(); + List dataList = new ArrayList<>(); + String id = Util.null2String(dataMap.get("id")); + dataMap.remove("id"); + + dataMap.forEach((key, value) -> { + fieldList.add(key + " = ? "); + dataList.add(value); + }); + dataList.add(id); + String updateSql = "update " + tableName + " set " + StringUtils.join(fieldList, ",") + " where id = ? "; + rs.executeUpdate(updateSql, dataList); + } + + /** + * 更新数据 + * + * @param dataMap + * @param tableName + * @param whereSql + */ + public static void updateData(Map dataMap, String tableName, String whereSql) { + List fieldList = new ArrayList<>(); + List dataList = new ArrayList<>(); + dataMap.forEach((key, value) -> { + fieldList.add(key + " = ? "); + dataList.add(value); + }); + String updateSql = "update " + tableName + " set " + StringUtils.join(fieldList, ",") + whereSql; + RecordSet rs = new RecordSet(); + rs.executeUpdate(updateSql, dataList); + if (StringUtils.isNotBlank(rs.getExceptionMsg())) { + throw new CustomizeRunTimeException(rs.getExceptionMsg()); + } + } + + /** + * 删除数据 + * + * @param deleteSql + */ + public static void deleteData(String deleteSql) { + RecordSet rs = new RecordSet(); + rs.executeUpdate(deleteSql); + if (StringUtils.isNotBlank(rs.getExceptionMsg())) { + throw new CustomizeRunTimeException(rs.getExceptionMsg()); + } + } + + + /** + * 构建建模表基本数据 + * + * @param mainDataMap 参数集合 + */ + public static void buildModeInsertFields(Map mainDataMap, int userId) { + String dateTime = DateUtil.getFullDate(); + String[] dateSplit = dateTime.split(" "); + mainDataMap.put("modedatacreater", userId); + mainDataMap.put("modedatacreatedate", dateSplit[0]); + mainDataMap.put("modedatacreatetime", dateSplit[1]); + mainDataMap.put("modedatacreatertype", "0"); + } + + /** + * 构建建模表基本数据 + * + * @param mainDataMap 参数集合 + */ + public static void buildModeUpdateFields(Map mainDataMap, int userId) { + String dateTime = DateUtil.getFullDate(); + mainDataMap.put("modedatamodifier", userId); + mainDataMap.put("modedatamodifydatetime", dateTime); + } + + /** + * 建模表数据权限重构 + * + * @param uuid + * @param modeTable + * @param formModeId + */ + public static int refreshRight(String uuid, String modeTable, int formModeId, int creator) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select id from " + modeTable + " where modeuuid='" + uuid + "'"); + if (rs.next()) { + //建模数据的id + int bid = Util.getIntValue(rs.getString("id")); + ModeRightInfo modeRightInfo = new ModeRightInfo(); + modeRightInfo.setNewRight(true); + //新建的时候添加共享 + modeRightInfo.editModeDataShare(creator, formModeId, bid); + return bid; + } + return -1; + } + + + /** + * 转换空字符串为null + * + * @param str 字符串 + * @return 转换后的字符串 + */ + public static Object parseBlankToNull(String str) { + return StringUtils.isBlank(str) ? null : str; + } + + /** + * 转换空字符串为null + * + * @param obj 对象 + * @return 转换后的字符串 + */ + public static String parseBlankToNull(Object obj) { + return Objects.isNull(obj) ? null : StringUtils.isBlank(obj.toString()) ? null : obj.toString(); + } + + /** + * 根据建模表名,获取建模ID + * + * @param modeTable + * @return + */ + public static int getModeIdByTableName(String modeTable) { + int formModeId = -1; + RecordSet rs = new RecordSet(); + rs.executeQuery("select id from modeinfo where formid =( select id from workflow_bill where tablename = ? ) and isdelete = 0 order by id", modeTable); + if (rs.next()) { + formModeId = rs.getInt("id"); + } + return formModeId; + } + + public static List getFieldList(String tableName) { + int formId = getFormIdByTableName(tableName); + return FormInfoManager.getInstance().getAllField(formId); + } + + public static List getFieldList(int formId) { + return FormInfoManager.getInstance().getAllField(formId); + } + + /** + * 根据表名,获取表单ID + * + * @param modeTable + * @return + */ + public static int getFormIdByTableName(String modeTable) { + int formId = -1; + RecordSet rs = new RecordSet(); + rs.executeQuery("select id from workflow_bill where tablename = ? ", modeTable); + if (rs.next()) { + formId = rs.getInt("id"); + } + return formId; + } + + /** + * 获取表单下拉框展示文本 + * + * @param formId 表单ID + * @param fieldName 字段明湖曾 + * @param value 下拉框值 + * @return + */ + public static String getSelectName(String formId, String fieldName, String value) { + String cancelReason = ""; + RecordSet rs = new RecordSet(); + rs.executeQuery("select selectname from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? ) and selectvalue = ?", formId, fieldName, value); + if (rs.next()) { + cancelReason = rs.getString("selectname"); + } + return cancelReason; + } + + /** + * 获取表单下拉框值 + * + * @param formId 表单ID + * @param fieldName 字段明湖曾 + * @param selectName 下拉框展示内容 + * @return + */ + public static String getSelectValue(String formId, String fieldName, String selectName) { + String selectValue = ""; + RecordSet rs = new RecordSet(); + rs.executeQuery("select selectvalue from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? ) and selectname = ?", formId, fieldName, selectName); + if (rs.next()) { + selectValue = rs.getString("selectvalue"); + } + return selectValue; + } + + public static String getSelectValue(Formfield formfield, String selectName) { + String selectValue = ""; + RecordSet rs = new RecordSet(); + String detailTable = Util.null2String(formfield.getDetailtable()); + if (StringUtils.isNotBlank(detailTable)) { + rs.executeQuery("select selectvalue from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? and detailtable = ? ) and selectname = ?", formfield.getBillid(), formfield.getFieldname(), Util.null2String(detailTable), selectName); + } else { + rs.executeQuery("select selectvalue from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? AND (detailtable IS NULL OR detailtable = '') ) and selectname = ?", formfield.getBillid(), formfield.getFieldname(), selectName); + } + if (rs.next()) { + selectValue = rs.getString("selectvalue"); + } + return selectValue; + } + + + /** + * 全角转半角 + * + * @param input + * @return + */ + public static String ToDBC(String input) { + if (input == null) { + input = ""; + } + char[] c = input.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (c[i] == 12288) { + //全角空格为12288,半角空格为32 + c[i] = (char) 32; + continue; + } + if (c[i] > 65280 && c[i] < 65375) { + //其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 + c[i] = (char) (c[i] - 65248); + } + } + return new String(c); + } + + public static String getTableNameByCustomId(String customId) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select tablename from workflow_bill where id = (select formid from mode_customsearch where id = ?)", customId); + if (rs.next()) { + return rs.getString("tablename"); + } + return ""; + } + + +} diff --git a/src/com/engine/secret/util/ResponseResult.java b/src/com/engine/secret/util/ResponseResult.java new file mode 100644 index 0000000..3baf8d5 --- /dev/null +++ b/src/com/engine/secret/util/ResponseResult.java @@ -0,0 +1,192 @@ +package com.engine.secret.util; + + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.engine.core.exception.ECException; +import com.engine.secret.exception.CustomizeRunTimeException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import weaver.general.BaseBean; +import weaver.hrm.User; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * 请求执行器 + *

Copyright: Copyright (c) 2022

+ *

Company: 泛微软件

+ * + * @author qiantao + * @version 1.0 + **/ +@Slf4j +public class ResponseResult { + + private static final long serialVersionUID = 1L; + + private final User user; + + private final BaseBean baseBean = new BaseBean(); + + private final Boolean isLog = "true".equals(baseBean.getPropValue("hrmSalary", "log")); + + public ResponseResult(User user) { + this.user = user; + } + + /** + * 统一返回方法(自定义返回格式) + */ + public String customRun(Function f, T t) { + try { + if (isLog) { + log.info("run api , param {}", t); + } + return getJsonString(f.apply(t)); + } catch (com.engine.secret.exception.CustomizeRunTimeException e) { + log.error("api run fail", e); + return Error(e.getMessage()); + } catch (ECException e) { + log.error("api run fail", e); + Throwable cause = e.getCause(); + return Error(cause.getMessage()); + } catch (Exception e) { + log.error("api run fail", e); + return Error("系统异常!"); + } + } + + /** + * 统一返回方法 + */ + public String run(Function f, T t) { + try { + if (isLog) { + log.info("run api , param {}", t); + } + return Ok(f.apply(t)); + } catch (com.engine.secret.exception.CustomizeRunTimeException e) { + log.error("api run fail", e); + return Error(e.getMessage()); + } catch (ECException e) { + log.error("api run fail", e); + Throwable cause = e.getCause(); + return Error(cause.getMessage()); + } catch (Exception e) { + log.error("api run fail", e); + return Error("系统异常!"); + } + } + + /** + * 统一返回方法(有参无返回) + */ + public String run(Consumer f, T t) { + try { + if (isLog) { + log.info("run api , param {}", t); + } + f.accept(t); + return Ok(); + } catch (com.engine.secret.exception.CustomizeRunTimeException e) { + log.error("api run fail", e); + return Error(e.getMessage()); + } catch (ECException e) { + log.error("api run fail", e); + return Error(ExceptionUtil.getRealMessage(e)); + } catch (Exception e) { + log.error("api run fail", e); + return Error("系统异常!", e); + } + } + + + /** + * 统一返回方法(无参有返回) + */ + public String run(Supplier f) { + try { + if (isLog) { + log.info("run api"); + } + return Ok(f.get()); + } catch (CustomizeRunTimeException e) { + log.error("api run fail", e); + return Error(e.getMessage()); + } catch (ECException e) { + log.error("api run fail", e); + Throwable cause = e.getCause(); + return Error(cause.getMessage()); + } catch (Exception e) { + log.error("api run fail", e); + return Error("系统异常!", e); + } + } + + + private static String getJsonString(Object apidatas) { + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.writeValueAsString(apidatas); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return ""; + } + + + /** + * 成功返回 + */ + private String Ok() { + Map apidatas = new HashMap<>(); + apidatas.put("api_status", true); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } + + + /** + * 成功返回 + */ + private String Ok(R r) { + Map apidatas = new HashMap<>(); + apidatas.put("api_status", true); + apidatas.put("data", r); + String success = JSON.toJSONString(apidatas); + if (isLog) { + log.info("run salary api success return {}", success); + } + return success; + } + + + /** + * 失败返回 + */ + private static String Error(String message) { + Map apidatas = new HashMap<>(); + apidatas.put("api_status", false); + apidatas.put("errormsg", message); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } + + + /** + * 系统异常失败返回 + */ + private static String Error(String message, Exception e) { + Map apidatas = new HashMap<>(); + apidatas.put("api_status", false); + apidatas.put("errormsg", message); + apidatas.put("error", e.getMessage()); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } + +} diff --git a/src/com/engine/secret/web/AuthorityChangeController.java b/src/com/engine/secret/web/AuthorityChangeController.java new file mode 100644 index 0000000..4b68aa1 --- /dev/null +++ b/src/com/engine/secret/web/AuthorityChangeController.java @@ -0,0 +1,39 @@ +package com.engine.secret.web; + +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.secret.service.AuthorityChangeService; +import com.engine.secret.service.impl.AuthorityChangeServiceImpl; +import com.engine.secret.util.ResponseResult; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/04/09 + * @version: 1.0 + */ +public class AuthorityChangeController { + public AuthorityChangeService getService(User user) { + return ServiceUtil.getService(AuthorityChangeServiceImpl.class, user); + } + + @POST + @Path("/delegateToProvincialAuthority") + @Produces(MediaType.APPLICATION_JSON) + public String delegateToProvincialAuthority(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + Map params = ParamUtil.request2Map(request); + return new ResponseResult, Map>(user).run(getService(user)::delegateToProvincialAuthority, params); + + } +} diff --git a/src/com/engine/secret/web/AutoGenerateNumberController.java b/src/com/engine/secret/web/AutoGenerateNumberController.java new file mode 100644 index 0000000..66d5c36 --- /dev/null +++ b/src/com/engine/secret/web/AutoGenerateNumberController.java @@ -0,0 +1,38 @@ +package com.engine.secret.web; + +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.secret.service.AutoGenerateNumberService; +import com.engine.secret.service.impl.AutoGenerateNumberServiceImpl; +import com.engine.secret.util.ResponseResult; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/04/16 + * @version: 1.0 + */ +public class AutoGenerateNumberController { + public AutoGenerateNumberService getService(User user) { + return ServiceUtil.getService(AutoGenerateNumberServiceImpl.class, user); + } + + @GET + @Path("/getAcceptanceNumber") + @Produces(MediaType.APPLICATION_JSON) + public String getAcceptanceNumber(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + Map param = ParamUtil.request2Map(request); + return new ResponseResult, String>(user).run(getService(user)::getAcceptanceNumber, param); + } +} diff --git a/src/com/engine/secret/web/QualificationApplicationController.java b/src/com/engine/secret/web/QualificationApplicationController.java new file mode 100644 index 0000000..89d12c5 --- /dev/null +++ b/src/com/engine/secret/web/QualificationApplicationController.java @@ -0,0 +1,49 @@ +package com.engine.secret.web; + +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.secret.service.QualificationApplicationService; +import com.engine.secret.service.impl.QualificationApplicationServiceImpl; +import com.engine.secret.util.ResponseResult; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2024/08/29 + * @version: 1.0 + */ +public class QualificationApplicationController { + public QualificationApplicationService getService(User user) { + return ServiceUtil.getService(QualificationApplicationServiceImpl.class, user); + } + + @POST + @Path("/parsingFiles") + @Produces(MediaType.APPLICATION_JSON) + public String parsingFiles(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + Map params = ParamUtil.request2Map(request); + return new ResponseResult, Map>(user).run(getService(user)::parsingFiles, params); + + } + + @POST + @Path("/deleteParsedData") + @Produces(MediaType.APPLICATION_JSON) + public String deleteParsedData(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + Map params = ParamUtil.request2Map(request); + return new ResponseResult, Map>(user).run(getService(user)::deleteParsedData, params); + + } +} diff --git a/src/weaver/interfaces/secret/action/ApprovalReviewEndAction.java b/src/weaver/interfaces/secret/action/ApprovalReviewEndAction.java new file mode 100644 index 0000000..90be985 --- /dev/null +++ b/src/weaver/interfaces/secret/action/ApprovalReviewEndAction.java @@ -0,0 +1,75 @@ +package weaver.interfaces.secret.action; + +import com.engine.secret.util.FlowUtil; +import org.apache.commons.lang.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.MainTableInfo; +import weaver.soa.workflow.request.Property; +import weaver.soa.workflow.request.RequestInfo; + +import java.util.HashMap; +import java.util.Map; + +/** + * 审批复核 归档Action + * + * @author:dxfeng + * @createTime: 2025/04/09 + * @version: 1.0 + */ +public class ApprovalReviewEndAction implements Action { + RecordSet rs = new RecordSet(); + + @Override + public String execute(RequestInfo requestInfo) { + try { + MainTableInfo mainTableInfo = requestInfo.getMainTableInfo(); + Property[] properties = mainTableInfo.getProperty(); + Map mainDataMap = new HashMap<>(); + for (Property property : properties) { + mainDataMap.put(property.getName(), property.getValue()); + } + // 获取主流程ID + String mainRequestId = mainDataMap.get("zlcid"); + if (StringUtils.isBlank(mainRequestId)) { + requestInfo.getRequestManager().setMessagecontent("未获取到主流程请求ID"); + return FAILURE_AND_CONTINUE; + } + + // 获取审批复核结论 + String conclusion = mainDataMap.get("spfhjl"); + + // 更新主流程表单的审批复核结论 + String tableNameByRequestId = FlowUtil.getTableNameByRequestId(mainRequestId); + if (StringUtils.isBlank(tableNameByRequestId)) { + requestInfo.getRequestManager().setMessagecontent("主流程表单名称获取异常,请确认"); + return FAILURE_AND_CONTINUE; + } + String sql = "update " + tableNameByRequestId + " set spfhjl = ? where requestid = ?"; + + rs.writeLog("mainRequestId==" + mainRequestId); + rs.writeLog("conclusion==" + conclusion); + rs.writeLog("tableNameByRequestId==" + tableNameByRequestId); + rs.writeLog("sql==" + sql); + + rs.executeUpdate(sql, conclusion, mainRequestId); + + // 更新完成后,自动提交流程到下一节点 + rs.writeLog("mainRequestId==" + mainRequestId); + String options = requestInfo.getCreatorid() + "-自动提交流程-" + DateUtil.getFullDate(); + String submitResult = FlowUtil.submitWorkflowRequest(mainRequestId, options); + if (!"success".equals(submitResult)) { + requestInfo.getRequestManager().setMessagecontent("requestId[" + mainRequestId + "],流程提交失败"); + return FAILURE_AND_CONTINUE; + } + + return SUCCESS; + } catch (Exception e) { + rs.writeLog(e); + requestInfo.getRequestManager().setMessagecontent(e.getMessage()); + return FAILURE_AND_CONTINUE; + } + } +} diff --git a/src/weaver/interfaces/secret/action/MeetingConveningEndAction.java b/src/weaver/interfaces/secret/action/MeetingConveningEndAction.java new file mode 100644 index 0000000..a6ee35d --- /dev/null +++ b/src/weaver/interfaces/secret/action/MeetingConveningEndAction.java @@ -0,0 +1,119 @@ +package weaver.interfaces.secret.action; + +import com.engine.secret.util.ConfigUtil; +import com.engine.secret.util.FlowUtil; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.*; + +import java.util.*; + +/** + * @author:dxfeng + * @createTime: 2025/04/14 + * @version: 1.0 + */ +public class MeetingConveningEndAction implements Action { + RecordSet rs = new RecordSet(); + private static final String MAIN_FLOW_TABLE = ConfigUtil.getConfig("xqxksqlc_table"); + + @Override + public String execute(RequestInfo requestInfo) { + try { + MainTableInfo mainTableInfo = requestInfo.getMainTableInfo(); + Property[] properties = mainTableInfo.getProperty(); + Map mainDataMap = new HashMap<>(); + List> detailMapList = new ArrayList<>(); + for (Property property : properties) { + mainDataMap.put(property.getName(), property.getValue()); + } + + DetailTableInfo detailTableInfo = requestInfo.getDetailTableInfo(); + DetailTable detailTable = detailTableInfo.getDetailTable(0); + String detailTableName = detailTable.getTableDBName(); + String updateDetailSql = "update " + detailTableName + " set zlctjzt = ? where id = ?"; + Row[] rows = detailTable.getRow(); + for (Row row : rows) { + Map detailDataMap = new HashMap<>(mainDataMap); + Cell[] cells = row.getCell(); + String detailId = row.getId(); + for (Cell cell : cells) { + detailDataMap.put(cell.getName(), cell.getValue()); + } + detailDataMap.put("detailId", detailId); + detailMapList.add(detailDataMap); + } + + Set errorMsg = new HashSet<>(); + if (CollectionUtils.isNotEmpty(detailMapList)) { + for (Map detail : detailMapList) { + dealMainFlow(requestInfo, detail, updateDetailSql, errorMsg); + } + } + + // 根据错误信息,返回提示 + if (CollectionUtils.isNotEmpty(errorMsg)) { + requestInfo.getRequestManager().setMessagecontent(StringUtils.join(errorMsg, "
")); + return FAILURE_AND_CONTINUE; + } + + + return SUCCESS; + } catch (Exception e) { + rs.writeLog(e); + requestInfo.getRequestManager().setMessagecontent(e.getMessage()); + return FAILURE_AND_CONTINUE; + } + } + + /** + * 提交主流程 + * + * @param requestInfo + * @param detail + * @param updateDetailSql + * @param errorMsg + */ + private void dealMainFlow(RequestInfo requestInfo, Map detail, String updateDetailSql, Set errorMsg) { + String mainId = detail.get("xzxksqdh"); + + + String conclusion = detail.get("spfhjl"); + String detailId = detail.get("detailId"); + String submitStatus = detail.get("zlctjzt"); + if ("1".equals(submitStatus)) { + // 已经提交成功的流程,不重复处理 + return; + } + + String mainRequestId = ""; + rs.executeQuery("select requestid from " + MAIN_FLOW_TABLE + " where id = ?", mainId); + if (rs.next()) { + mainRequestId = rs.getString("requestid"); + } + if (StringUtils.isBlank(mainRequestId)) { + errorMsg.add("主流程ID[" + mainId + "],主流程requestId获取异常,请确认"); + rs.executeUpdate(updateDetailSql, "2", detailId); + return; + } + + rs.writeLog("mainRequestId==" + mainRequestId); + rs.writeLog("conclusion==" + conclusion); + + rs.executeUpdate("update " + MAIN_FLOW_TABLE + " set spfhjl = ? where requestid = ?", conclusion, mainRequestId); + + // 更新完成后,自动提交流程到下一节点 + rs.writeLog("mainRequestId==" + mainRequestId); + String options = requestInfo.getCreatorid() + "-自动提交流程-" + DateUtil.getFullDate(); + String submitResult = FlowUtil.submitWorkflowRequest(mainRequestId, options); + if (!"success".equals(submitResult)) { + errorMsg.add("requestId[" + mainRequestId + "],流程提交失败"); + rs.executeUpdate(updateDetailSql, "2", detailId); + } else { + rs.executeUpdate(updateDetailSql, "1", detailId); + } + } +}