package com.engine.hzzx.conn; import com.engine.hzzx.exception.CustomizeRunTimeException; import org.apache.commons.lang3.StringUtils; import weaver.common.DateUtil; import weaver.conn.RecordSet; import weaver.formmode.setup.ModeRightInfo; import weaver.general.Util; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * @author:dxfeng * @createTime: 2025/02/27 * @version: 1.0 */ public class DataUtil { /** * 根据流程ID获取流程表名 * * @param workflowId * @return */ public static String getTableNameById(String workflowId) { RecordSet rs = new RecordSet(); rs.executeQuery("select formid from workflow_base where id= ?", workflowId); if (rs.next()) { String formId = rs.getString("formid"); if (StringUtils.isNotBlank(formId)) { rs.executeQuery("select tablename from workflow_bill wb where id = ?", formId); if (rs.next()) { return rs.getString("tablename"); } } } return null; } /** * 根据建模表名,获取建模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; } /** * 根据表名,获取表单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 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 (StringUtils.isNotBlank(value)) { fieldList.add(key); dataList.add(value); 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()); } } /** * 根据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()); } } /** * 构建建模表基本数据 * * @param mainDataMap 参数集合 */ public static void buildModeInsertFields(Map mainDataMap, String 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, String 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, String 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(Integer.parseInt(creator), formModeId, bid); return bid; } return -1; } /** * 获取表单下拉框展示文本 * * @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; } /** * 获取文档ID * * @param imageFileId * @return */ public static String getDocIdByImageId(String imageFileId) { if (StringUtils.isBlank(imageFileId)) { return ""; } RecordSet rs = new RecordSet(); rs.executeQuery("select docid from DocImageFile where IMAGEFILEID=?", imageFileId); if (rs.next()) { return rs.getString("docid"); } return ""; } }