package com.product.data.sync.service; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.product.admin.service.CodeService; import com.product.admin.service.SystemMenusService; import com.product.common.lang.StringUtils; import com.product.core.cache.DataPoolRefreshCache; import com.product.core.config.Global; import com.product.core.connection.ConnectionManager; import com.product.core.dao.BaseDao; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.entity.RequestParameterEntity; import com.product.core.exception.BaseException; import com.product.core.service.support.AbstractBaseService; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.core.util.CodeUtil; import com.product.data.sync.config.CmnConst; import com.product.data.sync.config.SystemCode; import com.product.data.sync.service.ide.ISyFeDataService; import com.product.data.sync.service.media.GdMediaUtil; import com.product.data.sync.util.BusinessDataSync; import com.product.data.sync.util.DataManipulationUtils; import com.product.file.service.FileManagerService; import com.product.file.util.CreateDocumentIndexThread; import com.product.module.sys.service.UserService; import com.product.util.BaseDaoServiceImpl; import com.product.util.BaseUtil; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.File; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * Copyright LX * * @Title: SyFeDataService * @Project: product-server * @date: 2021-09-30 14:19 * @author: zm * @Description: fe数据移植到产品 */ @Service public class SyFeDataService extends AbstractBaseService implements ISyFeDataService { private static Logger logger = LoggerFactory.getLogger(SyFeDataService.class); @Autowired public BaseDao baseDao; @Autowired public FunctionSynchrService functionSynchrService; @Autowired FileManagerService fileManagerService; @Autowired SystemMenusService systemMenusService; @Autowired GdMediaUtil gdMediaUtil; //公司fe id 对应 产品uuid Map OrgIdUUIDmap = Maps.newHashMap(); //金格主目录 String jinGePath = "D:\\OA\\FEGOV\\Media"; //暂存文件目录 String TSPath = "D:\\filePackage"; @Autowired private UserService userService; @Autowired private CodeService codeService; @Autowired private FeDataDSService feDataDSService; //fe 人员id 对应 userid private JSONObject userIdJson = new JSONObject(); //fe 公司部门id 对应 机构uuid private JSONObject groupJson = new JSONObject(); //字段类型关联 private JSONObject fieldTypeJson = new JSONObject(); //流程nodes fe id 对应 产品uuid private JSONObject nodesIdUUID = new JSONObject(); //源数据表名 本数据表名 private JSONObject originalTable = new JSONObject(); //唯一字段 private String pk; //表唯一标识 和本表uuid private JSONObject pxMap = new JSONObject(); //已开发公共功能 公告管理 系统参数(没有) 问卷管理 考勤管理 车辆管理 协同办公 private String[] funTable = {"FE_APP5.PUB_NOTICE", "FE_BASE5.RESEARCH_TOPIC", "FE_APP5.HR_ATTENDANCE", "FE_APP5.CAR_INFO", "FE_BASE5.SYS_COLLABORATIVE"}; //我们产品的功能权限 private String[] functionCode = {"001-004-000-000","001-004-000-001","001-004-000-002"}; //本产品按钮uuid private List buttonUuid = Lists.newArrayList(); //已同步表结构 private JSONObject dataTableObject = new JSONObject(); public Boolean isStr(String str) { boolean a = false; for (int i = 0; i < funTable.length; i++) { if (str.equals(funTable[i])) { a = true; } } return a; } //公告管理1 系统参数 问卷管理 考勤管理 车辆管理 协同办公 @Override public String saveSyncFedata(FieldSetEntity fs) throws SQLException, ClassNotFoundException { //同步组织架构 DataTableEntity dataTableEntity = baseDao.listTable("product_sys_users"); String clientUUID = "4d4679ed-c4c3-41b8-abfe-451a66fd4043"; if (dataTableEntity.getRows() < 10) { String uuid = feDataDSService.FEDataMigration(); if(!BaseUtil.strIsNull(uuid)){ clientUUID = uuid; } } //封装两边人员关联和部门关联 // packageDepartmentPersonnel(); String tricode_fun = Global.getSystemConfig("data.synchronism.function", ""); if(BaseUtil.strIsNull(tricode_fun)){ return null; } String[] tricode_funs = tricode_fun.split(","); // String[] tricode_funs = fs.getString("tricode_fun").split(","); //封装本产品需赋权限的按钮uuid // this.packageButton(); // Connection conn = functionSynchrService.getConnection(fs); ExecutorService exec = Executors.newCachedThreadPool(); for (int i = 0; i < tricode_funs.length; i++) { //获取jdbc连接 BusinessDataSync async = new BusinessDataSync(tricode_funs[i]); async.setBaseDao(baseDao); async.setFileManagerService(fileManagerService); async.setSystemMenusService(systemMenusService); async.setFeDataDSService(feDataDSService); async.setGdMediaUtil(gdMediaUtil); async.setClientUUID(clientUUID); Thread t = new Thread(async); exec.submit(t); // nodesIdUUID = new JSONObject(); // //同步表及基础数据 // String sf28 = this.synchronizeTablesData(conn, tricode_funs[i]); // String table_name = sf28.split("\\.")[1]; // String moduleUUID; // if (!isStr(sf28)) { // //同步mvc // moduleUUID = this.synchronizationModuleName(conn, tricode_funs[i], sf28); // } else { // //已有功能的表就不同步mvc 查询该功能的模块uuid // StringBuffer sql = new StringBuffer(); // sql.append(" tricode = (\n") // .append("SELECT tricode_parent FROM product_sys_functions a LEFT JOIN \n") // .append("product_sys_datamodel_table b on a.table_uuid = b.uuid \n") // .append("WHERE b.table_name = ? GROUP BY tricode_parent\n") // .append(") AND function_type_uuid = 0"); // FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_functions", sql.toString(), new String[]{this.originalTable.getString(table_name)}, false); // moduleUUID = fieldSetEntity.getUUID(); // } // //迁移 wf_model流程模块表 //// this.syncModel(tricode_funs[i], conn, moduleUUID, sf28, null, SpringMVCContextHolder.getCurrentUser().getUser_id(), false); // //根据要求流程要同步两次 // //查询主公司uuid // FieldSetEntity fieldSetEntity = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS, " org_level_code = ? ", new String[]{"001"},false); // FieldSetEntity user = baseDao.getFieldSetByFilter("product_sys_org_manager" , " manager_type = ? ", new String[]{"2"}, false); // this.syncModel(tricode_funs[i], conn, moduleUUID, sf28, fieldSetEntity.getUUID(), user.getInteger("user_id"), true); } //同时开始执行 exec.shutdown(); while (true) { if (exec.isTerminated()) { //System.out.println("所有的子线程都结束了!"); break; } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } systemMenusService.initSystemMenu(); System.out.println("=================同步成功==============="); return "OK"; } /** * 附件添加索引 */ public void dataSyncCreateIndexUtil() { String sql="SELECT uuid attachment_uuid,function_uuid FROM product_sys_attachments WHERE function_uuid IS NOT NULL AND function_uuid!=''"; DataTableEntity dtAttachment=baseDao.listTable(sql, new Object[] {}); if (!BaseUtil.dataTableIsEmpty(dtAttachment)) { for (int i = 0; i < dtAttachment.getRows(); i++) { FieldSetEntity fseAttachment=dtAttachment.getFieldSetEntity(i); CreateDocumentIndexThread.getInstance().appendAttaInfo(fseAttachment); } } } /** * 封装单位部门 人员对应Json */ public void packageDepartmentPersonnel() { DataTableEntity staffsData = baseDao.listTable("product_sys_staffs"); for (int i = 0; i < staffsData.getRows(); i++) { //数据源用户id userIdJson.put(staffsData.getString(i, "remark"), staffsData.getString(i, "user_id")); } DataTableEntity orgData = baseDao.listTable("product_sys_org_levels"); for (int i = 0; i < orgData.getRows(); i++) { //源数据id groupJson.put(orgData.getString(i, "sequence"), orgData.getString(i, "uuid")); } } /** * 封装本产品的按钮uuid */ public void packageButton(){ StringBuffer sql = new StringBuffer(); String tricodeIn = BaseUtil.buildQuestionMarkFilter("tricode", this.functionCode, true); sql.append(" SELECT uuid FROM product_sys_function_buttons WHERE function_uuid IN ( ") .append(" SELECT uuid FROM product_sys_functions WHERE ") .append(tricodeIn).append(" ) "); DataTableEntity dataTableEntity = baseDao.listTable(sql.toString(),new String[]{}); for (int i = 0; i < dataTableEntity.getRows(); i++) { this.buttonUuid.add(dataTableEntity.getString(i,"uuid")); } } /** * 同步表及表数据 * * @param conn 连接 * @param funCode 功能code * @throws SQLException */ private String synchronizeTablesData(Connection conn, String funCode) throws SQLException { FieldSetEntity Orlfs = null; try { logger.info("功能code" + funCode); Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", "SF05=?", new Object[]{funCode}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } String sf28 = Orlfs.getString("sf28"); //功能如果未关联基础表 查询流程表 if (BaseUtil.strIsNull(sf28) || sf28.indexOf(".") == -1) { FieldSetEntity modelFse; try { //查询流程是否绑定表 modelFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.wf_model", "wm05=(SELECT se16 FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)", new Object[]{funCode }); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } if (modelFse == null) { return null; } String wm04 = modelFse.getString("wm04"); if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) { return null; } else { sf28 = wm04; } } //判断是否存在已开发功能的表 //如果是已开发功能定义 通过自己定义的数据关联 同步数据 String[] sf28s = sf28.split("\\."); boolean flag = true; if (isStr(sf28)) { flag = false; } this.syncTable(sf28s, flag, null, conn); return sf28; } /** * 同步公告表数据 * * @param conn * @param tableName * @throws SQLException */ private void syncNotice(Connection conn, String tableName) throws SQLException { //判断是否是已经同步过的表 DataTableEntity dataTable = baseDao.listTable("product_oa_announcement"); if (!BaseUtil.dataTableIsEmpty(dataTable)) { return; } DataTableEntity noticeDt = null; try { noticeDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } for (int i = 0; i < noticeDt.getRows(); i++) { FieldSetEntity feFs = noticeDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_oa_announcement"); fs.setValue("title", feFs.getString("title")); fs.setValue("content", feFs.getString("content")); fs.setValue("type", feFs.getString("notice_category")); //Set 转换为字符串逗号分隔 //写方法判断是多人还是部门,若是部门转换为人 fs.setValue("extent", this.getUserIds(feFs.getString("receivers"))); fs.setValue("expiration_date", feFs.getDate("displayed_date")); fs.setValue("status", feFs.getString("is_reminded")); fs.setValue("publish_status", feFs.getString("status")); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); String uuid = baseDao.add(fs); //重新获取jdbc连接 Connection connection = null; try { connection = feDataDSService.getJDBC(); } catch (ClassNotFoundException e) { e.printStackTrace(); } DataTableEntity subFeFs = getSubDt(connection, "FE_APP5.PUB_NOTICE_RECEIVER", "NOTICE_ID", feFs.getString("id")); for (int j = 0; j < subFeFs.getRows(); j++) { FieldSetEntity fsSubFe = subFeFs.getFieldSetEntity(j); FieldSetEntity fsSub = new FieldSetEntity(); fsSub.setTableName("product_oa_announcement_role"); String userId = userIdJson.getString(fsSubFe.getString("receiver")); if (null == userId) { continue; } fsSub.setValue("user_id", userId); fsSub.setValue("status", fsSubFe.getString("readed")); fsSub.setValue("announcement_uuid", uuid); baseDao.add(fsSub); } DataManipulationUtils.close(null, null, connection); } } /** * 获取userId * * @param receivers 字段值 */ public String getUserIds(String receivers) throws SQLException { String[] receiversArr = receivers.split(","); Connection conn = null; Set extentArr = new HashSet<>(); try { //查询公司部门表数据 conn = feDataDSService.getJDBC(); for (int j = 0; j < receiversArr.length; j++) { if (receiversArr[j].contains("[")) { String companyId = receiversArr[j].replace("[", "").replace("]", ""); StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM FE_BASE5.sys_users WHERE SU03 like CONCAT(CONCAT('%',(SELECT SG03 FROM fe_base5.sys_group WHERE SG00 = " + companyId + ")), '%') "); //人员数据 DataTableEntity dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{}); String[] remark = new String[dataTableEntity.getRows()]; for (int i = 0; i < dataTableEntity.getRows(); i++) { remark[i] = dataTableEntity.getString(i, "su00"); } DataTableEntity userData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", remark.length, true), remark); if (!BaseUtil.dataTableIsEmpty(userData)) { for (int i = 0; i < userData.getRows(); i++) { extentArr.add(userData.getString(i, "user_id")); } } //{岗位} } else if (receiversArr[j].contains("{")) { String postId = receiversArr[j].replace("{", "").replace("}", ""); StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM FE_BASE5.sys_users WHERE SU34 = " + postId); //人员数据 DataTableEntity dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{}); String[] remark = new String[dataTableEntity.getRows()]; for (int i = 0; i < dataTableEntity.getRows(); i++) { remark[i] = dataTableEntity.getString(i, "su00"); } DataTableEntity userData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", remark.length, true), remark); if (!BaseUtil.dataTableIsEmpty(userData)) { for (int i = 0; i < userData.getRows(); i++) { extentArr.add(userData.getString(i, "user_id")); } } } else { String userId = userIdJson.getString(receiversArr[j]); if (null == userId) { continue; } extentArr.add(userId); } } } catch (Exception e) { e.printStackTrace(); throw new BaseException(e.getMessage(), e.toString()); } DataManipulationUtils.close(null, null, conn); return StringUtils.join(extentArr, ","); } /** * 查询子表信息 * * @param conn * @param subTableName 子表名 * @param fieldName 字段名 * @param field 字段值 * @return * @throws SQLException */ private DataTableEntity getSubDt(Connection conn, String subTableName, String fieldName, String field) throws SQLException { DataTableEntity noticeDt = null; try { noticeDt = BaseDaoServiceImpl.getDataTable(conn, subTableName, fieldName + "=?", new Object[]{field}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } return noticeDt; } /** * 同步问卷调查 0 * * @param conn * @param tableName * @throws SQLException */ private void syncResearchTopic(Connection conn, String tableName) throws SQLException { //判断是否是已经同步过的表 DataTableEntity dataTable = baseDao.listTable("product_oa_questionnaire"); if (!BaseUtil.dataTableIsEmpty(dataTable)) { return; } DataTableEntity researchTopicDt = null; try { researchTopicDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } JSONObject qSubIdUUIDMap = new JSONObject(); JSONObject qSubOptionIdUUIDMap = new JSONObject(); for (int i = 0; i < researchTopicDt.getRows(); i++) { FieldSetEntity feFs = researchTopicDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); //问卷管理 fs.setTableName("product_oa_questionnaire"); //问卷标题 fs.setValue("questionnaire_title", feFs.getString("rt01")); //问卷说明 fs.setValue("questionnaire_explain", feFs.getString("rt01")); //问卷内容 fs.setValue("questionnaire_content", feFs.getString("rt02")); //是否匿名(1.是、0.否) fs.setValue("is_anonymous", feFs.getString("rt06")); String[] RT13Arr = feFs.getString("rt13").split(","); ArrayList votersArr = new ArrayList<>(); for (int j = 0; j < RT13Arr.length; j++) { RT13Arr[j] = RT13Arr[j].replace("[", ""); RT13Arr[j] = RT13Arr[j].replace("]", ""); String userId = userIdJson.getString(RT13Arr[j]); } if (votersArr.size() == 0) { continue; } //参与投票人 fs.setValue("voters", StringUtils.join(votersArr, ",")); //调查截止日期 fs.setValue("deadline", feFs.getString("rt04")); String[] RT15Arr = feFs.getString("rt15").split(","); String[] resultViewerArr = new String[RT15Arr.length]; for (int j = 0; j < RT15Arr.length; j++) { resultViewerArr[j] = userIdJson.getString(RT15Arr[j]); } //结果查看人 fs.setValue("result_viewer", StringUtils.join(resultViewerArr, ",")); //发布人 fs.setValue("publisher", userIdJson.getString(feFs.getString("rt08"))); //发布时间 fs.setValue("pubdate", feFs.getDate("rt03")); //是否发布 fs.setValue("is_publish", feFs.getString("rt05")); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); //主表uuid String uuid = baseDao.add(fs); DataTableEntity subFeFs = getSubDt(conn, "FE_BASE5.RESEARCH_SUB", "RS01", feFs.getString("rt00")); for (int j = 0; j < subFeFs.getRows(); j++) { FieldSetEntity feSubFs = subFeFs.getFieldSetEntity(i); FieldSetEntity subFs = new FieldSetEntity(); //问卷管理子表 subFs.setTableName("product_oa_questionnaire_sub"); // 主表uuid subFs.setValue("questionnaire_uuid", uuid); //内容类型(1.单选题目、2.复选题目、3.简答题) subFs.setValue("content_type", feSubFs.getInteger("rs04") + 1); //选项题目 subFs.setValue("option_topic", feSubFs.getString("rs02")); //题目说明 subFs.setValue("title_description", feSubFs.getString("rs03")); //多选择类型(1.最多、2.最少、3.必选) subFs.setValue("option_type", feSubFs.getString("rs07")); //可选择项数 subFs.setValue("option_num", feSubFs.getString("rs06")); String subUUID = baseDao.add(subFs); qSubIdUUIDMap.put(subUUID, feSubFs.getString("rs00")); if (feSubFs.getInteger("rs04") != 2) { DataTableEntity subFeFsto = getSubDt(conn, "fe_base5.RESEARCH_OPTION", "RO01", feSubFs.getString("RS00")); for (int k = 0; k < subFeFsto.getRows(); k++) { FieldSetEntity feSubFsto = subFeFsto.getFieldSetEntity(i); FieldSetEntity subFsto = new FieldSetEntity(); subFsto.setTableName("product_oa_questionnaire_sub_option"); //问卷管理子表uuid subFsto.setValue("parent_uuid", subUUID); //选项内容 subFsto.setValue("option_content", feSubFsto.getString("ro02")); //是否可填(1.是、0.否) subFsto.setValue("is_write", feSubFsto.getString("ro04")); //选项序号 subFsto.setValue("option_num", numberToLetter(k + 1)); String subUUIDto = baseDao.add(subFsto); qSubOptionIdUUIDMap.put(feSubFsto.getString("ro00"), subUUIDto); } } } DataTableEntity vFeFs = getSubDt(conn, "fe_base5.RESEARCH_VOTER", "rv01", feFs.getString("rt00")); for (int j = 0; j < vFeFs.getRows(); j++) { FieldSetEntity feSubFs = vFeFs.getFieldSetEntity(j); FieldSetEntity subFs = new FieldSetEntity(); subFs.setTableName("product_oa_questionnaire_mine"); subFs.setValue("questionnaire_uuid", uuid); subFs.setValue("voting_status", feSubFs.getString("rv06")); logger.info("用户user_id:" + userIdJson.getString(feSubFs.getString("rv04"))); subFs.setValue("vote_user", userIdJson.getString(feSubFs.getString("rv04"))); subFs.setValue("subject_uuid", qSubIdUUIDMap.getString(feSubFs.getString("rv02"))); subFs.setValue("option_answer_uuid", qSubOptionIdUUIDMap.getString(feSubFs.getString("rv03"))); subFs.setValue("answer_contents", feSubFs.getString("rv07")); baseDao.add(subFs); } } } //数字转字母 1-26 : A-Z private String numberToLetter(int num) { if (num <= 0) { return null; } String letter = ""; num--; do { if (letter.length() > 0) { num--; } letter = ((char) (num % 26 + (int) 'A')) + letter; num = (int) ((num - num % 26) / 26); } while (num > 0); return letter; } //车辆基本信息表 private void syncCarInfo(Connection conn, String tableName) throws SQLException { //判断是否是已经同步过的表 DataTableEntity dataTable = baseDao.listTable("product_oa_car_driver_info"); if (!BaseUtil.dataTableIsEmpty(dataTable)) { return; } //同步司机信息 DataTableEntity driverInfoDt = null; try { driverInfoDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CHAUFFEUR_INFO", "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } JSONObject driverIdUUIDMap = new JSONObject(); for (int i = 0; i < driverInfoDt.getRows(); i++) { FieldSetEntity fsFe = driverInfoDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_oa_car_driver_info"); fs.setValue("name", fsFe.getString("CHAUFFEUR_NAME")); fs.setValue("driver_license_num", fsFe.getString("LICENCE_NO")); fs.setValue("IDCard_num", fsFe.getString("IDENTITY_CARD_NO")); fs.setValue("driving_model", carType(fsFe.getString("DRIVE_CAR_MODEL"))); fs.setValue("driving_experience", fsFe.getString("DRIVE_YEAR")); fs.setValue("phone_num", fsFe.getString("HANDSET_NO")); fs.setValue("address", fsFe.getString("ADDRESS")); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); String uuid = baseDao.add(fs); driverIdUUIDMap.put("ID", uuid); } //同步车辆基本信息 DataTableEntity researchTopicDt = null; try { researchTopicDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } JSONObject carBrandUUIDMap = new JSONObject(); JSONObject carIdUUIDMap = new JSONObject(); for (int i = 0; i < researchTopicDt.getRows(); i++) { FieldSetEntity fsFe = researchTopicDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_oa_car_info"); fs.setValue("plate_number", fsFe.getString("CAR_BRAND_NO")); fs.setValue("vehicle_status", fsFe.getString("CAR_STATE")); // fs.setValue("org_level_uuid", OrgIdUUIDmap.getString(fsFe.getString("CAR_BRAND_NO"))); fs.setValue("vehicle_type", carType(fsFe.getString("CAR_TYPE"))); fs.setValue("leaders", userIdJson.getString(fsFe.getString("FROM_LEADER"))); fs.setValue("purchase_date", fsFe.getDate("BUY_DATE")); fs.setValue("brand_series", fsFe.getString("ROAD_BRIDGE_CHARGE")); fs.setValue("purchase_price", fsFe.getString("BUY_PRICE")); fs.setValue("vehicle_use", fsFe.getString("OIL_CHARGE")); fs.setValue("seats_num", fsFe.getString("SEAT_AMOUNT")); fs.setValue("fuel_type", fsFe.getString("OIL_TYPE")); fs.setValue("owner_name", fsFe.getString("MASTER_NAME")); fs.setValue("vehicle_certificate", fsFe.getString("CAR_PAPER")); //附件 // fs.setValue("attachment_uuid",); if (!fsFe.getString("DRIVER").isEmpty()) { fs.setValue("driver_id", driverIdUUIDMap.getString(fsFe.getString("DRIVER"))); } fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); String uuid = baseDao.add(fs); carBrandUUIDMap.put(fsFe.getString("CAR_BRAND_NO"), uuid); carIdUUIDMap.put(fsFe.getString("ID"), uuid); } //同步车辆出险事故信息表 DataTableEntity carSlipDt = null; try { carSlipDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CAR_SLIP", "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } for (int i = 0; i < carSlipDt.getRows(); i++) { FieldSetEntity fsFe = carSlipDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_oa_car_accident_record"); fs.setValue("vehicle_info_uuid", carBrandUUIDMap.getString(fsFe.getString("CAR_BRAND_NO"))); fs.setValue("accident_time", fsFe.getDate("SLIP_DATE")); fs.setValue("driver_info_uuid", driverIdUUIDMap.getString(fsFe.getString("DRIVE_PERSON"))); fs.setValue("accident_location", fsFe.getDate("SLIP_ADDRESS")); fs.setValue("accident_cause", fsFe.getDate("SLIP_REASON")); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); fs.setValue("flow_flag", 2); baseDao.add(fs); } //同步车辆申请信息表 DataTableEntity carApplicationDt = null; try { carApplicationDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CAR_APPLICATION", "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } for (int i = 0; i < carApplicationDt.getRows(); i++) { FieldSetEntity fsFe = carApplicationDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_oa_car_application"); fs.setValue("applicant", userIdJson.getString(fsFe.getString("PROPOSER"))); // fs.setValue("org_level_uuid", OrgIdUUIDmap.getString(fsFe.getString("SECTION_DEPARTMENT"))); fs.setValue("applicattion_time", fsFe.getDate("APPLICATION_DATE")); fs.setValue("start_place", fsFe.getString("START_END_ADDRESS")); fs.setValue("person_board", fsFe.getString("FOLLOW_PERSON")); fs.setValue("vehicle_line", fsFe.getString("CAR_LINE")); fs.setValue("scheduled_start_time", fsFe.getDate("USE_START_DATE")); fs.setValue("scheduled_end_time", fsFe.getDate("USE_END_DATE")); fs.setValue("project_name", fsFe.getString("USE_END_DATE")); fs.setValue("use_reason", fsFe.getString("USE_REASON")); if (!fsFe.getString("DRIVER").isEmpty()) { fs.setValue("driver_info_uuid", driverIdUUIDMap.getString(fsFe.getString("DRIVER"))); } fs.setValue("status", fsFe.getString("STATUS")); fs.setValue("driving_time", fsFe.getString("START_DATE")); fs.setValue("return_time", fsFe.getString("RETURN_DATE")); fs.setValue("actual_line", fsFe.getString("FACT_WAY")); fs.setValue("repair_cost", fsFe.getString("id04")); fs.setValue("fuel_charge", fsFe.getString("OIL_CHARGE")); fs.setValue("toll", fsFe.getString("id05")); fs.setValue("other_expenses", fsFe.getString("id01")); fs.setValue("total_cost", fsFe.getString("id02")); fs.setValue("manager_confirmation", fsFe.getString("id08")); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); fs.setValue("flow_flag", 2); baseDao.add(fs); } } private String carType(String type) { String reType = ""; switch (type) { case "轿车": reType = "1"; break; case "货车": reType = "2"; break; default: reType = "3"; } return reType; } /** * 同步已开发功能数据 * * @param tableName 表名 * @return * @throws SQLException */ private void syncFunTable(Connection conn, String tableName) throws SQLException { //公告表 if (tableName.equals("FE_APP5.PUB_NOTICE")) { syncNotice(conn, tableName); //两个表建立关联 this.originalTable.put("PUB_NOTICE", "product_oa_announcement"); } //同步问卷调查 if (tableName.equals("FE_BASE5.RESEARCH_TOPIC")) { syncResearchTopic(conn, tableName); this.originalTable.put("RESEARCH_TOPIC", "product_oa_questionnaire"); } //考勤表 if (tableName.equals("FE_APP5.APP_KQLRB")) { this.synchronousClock(conn, tableName); } //车辆基本信息表 为空 if (tableName.equals("FE_APP5.CAR_INFO")) { syncCarInfo(conn, tableName); this.originalTable.put("CAR_INFO", "product_oa_car_driver_info"); } //协同办公 不管 if (tableName.equals("FE_BASE5.SYS_COLLABORATIVE")) { syncCcooperates(conn, tableName); this.originalTable.put("SYS_COLLABORATIVE", "product_oa_cooperates"); } //会议室申请 if (tableName.equals("FE_APP5.BS_MEETING_FLOW")) { } //会议室管理 if (tableName.equals("FE_APP5.BS_MEETINGROOM")) { } } /** * 同步考勤数据 */ private void synchronousClock(Connection conn ,String tableName) throws SQLException { DataTableEntity clockDt = null; try { clockDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } if(!BaseUtil.dataTableIsEmpty(clockDt)){ for (int i = 0; i < clockDt.getRows(); i++) { FieldSetEntity fse = clockDt.getFieldSetEntity(i); FieldSetEntity fieldSetEntity = new FieldSetEntity(); fieldSetEntity.setTableName("product_oa_punch_record"); //公司部门id String dept = fse.getString("dept"); //mac地址 String mac = fse.getString("mac"); } } } /** * 会议室申请 * * @param conn * @param tableName */ private void ConferenceRoomApplication(Connection conn, String tableName) throws SQLException { //判断是否是已经同步过的表 DataTableEntity dataTable = baseDao.listTable("product_oa_conference_apply"); if (!BaseUtil.dataTableIsEmpty(dataTable)) { return; } DataTableEntity ccooperatesDt = null; try { ccooperatesDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } } //同步协同办公 private void syncCcooperates(Connection conn, String tableName) throws SQLException { //判断是否是已经同步过的表 DataTableEntity dataTable = baseDao.listTable("product_oa_cooperates"); if (!BaseUtil.dataTableIsEmpty(dataTable)) { return; } DataTableEntity ccooperatesDt = null; try { ccooperatesDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } DataTableEntity accessoryData = this.getTableNameAttachment(conn, tableName); for (int i = 0; i < ccooperatesDt.getRows(); i++) { FieldSetEntity feFs = ccooperatesDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_oa_cooperates"); //标题 fs.setValue("title", feFs.getString("title")); String content = feFs.getString("content"); if (BaseUtil.strIsNull(content)) { content = ""; } //内容 fs.setValue("content", content); String important = feFs.getString("important"); if (!BaseUtil.strIsNull(important)) { //紧急程度(1.平件、2.急件、3.特急、4.特提) fs.setValue("emergency_degree", emergencyDegreeType(important)); } else { //为空就放0 fs.setValue("emergency_degree", 0); } //附件hiddenidea // fs.setValue("attachment",); //发起时间 fs.setValue("start_time", feFs.getString("stime")); //是否允许转发(1.是、0.否) fs.setValue("is_forward", feFs.getString("repeating")); //是否允许加签(1.是、0.否) fs.setValue("is_countersign", feFs.getString("modifyflow")); //是否允许跟踪(1.是、0.否) fs.setValue("is_track", feFs.getString("track")); //是否隐藏回复意见(1.是、0.否) fs.setValue("is_hide_comments", feFs.getString("hiddenidea")); //状态(0.待发、1.已发) fs.setValue("status", 1); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); Map> fileMaps = this.synchronizationAttachments(conn, accessoryData, feFs, fs.getTableName()); List value = fileMaps.get("COL_MDL_CONTENT_MEDIA"); //存入附件uuid fs.setValue("attachment", StringUtils.join(value, ",")); String uuid = baseDao.add(fs); DataTableEntity coNodeDt = null; try { //flowcode 流程字段 coNodeDt = BaseDaoServiceImpl.getDataTable(conn, "SELECT a.NAME receiver_name,a.VALUE receiver,b.NAME sender_name,b.VALUE sender,a.STATUS ,a.PARENTGUID PARENTGUID ,a.MGUID MGUID FROM WF_CO_NODE a LEFT JOIN WF_CO_NODE b on a.PARENTGUID=b.GUID where a.MGUID=?", new Object[]{feFs.getString("flowcode")}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } JSONObject grade = new JSONObject(); for (int j = 0; j < coNodeDt.getRows(); j++) { FieldSetEntity subfsFe = coNodeDt.getFieldSetEntity(j); FieldSetEntity subfs = new FieldSetEntity(); //协同办公流程表 subfs.setTableName("product_oa_cooperate_flow_node"); grade.put(subfsFe.getString("guid"), 1); //办理人层级 subfs.setValue("grade", 1); //关联协同表uuid subfs.setValue("cooperate_uuid", uuid); //接收人(关联用户表id) subfs.setValue("receiver", subfsFe.getString("receiver")); //接收人姓名 subfs.setValue("receiver_name", subfsFe.getString("receiver_name")); //发送人(关联用户表id) subfs.setValue("sender", subfsFe.getString("sender")); //发送人姓名 subfs.setValue("sender_name", subfsFe.getString("sender_name")); //0:未收未办 1:已收未 2:已收已办 subfs.setValue("status", subfsFe.getInteger("status") == 1 ? 2 : 0); //0:暂存 1:加签 2:转发 3:退回4:送办 5:终止 6:撤销 subfs.setValue("type", 0); String uuids = baseDao.add(subfs); // DataTableEntity IDEAMANAGEDt = null; // try { // IDEAMANAGEDt = BaseDaoServiceImpl.getDataTable(conn, "select c.ID02 ID02,c.ID03 ID03,c.ID04 ID04,c.ID08 ID08 from FE_BASE5.WF_TASK a JOIN FE_BASE5.WF_INFOR b on a.WT00=b.WI01 JOIN FE_BASE5.IDEAMANAGE c on b.WI21= c.ID06 where a. WT13=? ", new Object[]{subfsFe.getString("mguid")}); // } catch (Exception e) { // DataManipulationUtils.close(null, null, conn); // throw e; // } // for (int k = 0; k < IDEAMANAGEDt.getRows(); k++) { // FieldSetEntity subfsFeto = coNodeDt.getFieldSetEntity(i); // FieldSetEntity subfsto = new FieldSetEntity(); // //协同办公留言表 // subfsto.setTableName("product_oa_cooperate_flow_reply"); // //关联product_oa_cooperate_flow_node表uuid // subfsto.setValue("parent_uuid", uuids); // //回复内容 // subfsto.setValue("reply_content", subfsFeto.getString("id04")); // //回复时间 // subfsto.setValue("reply_datetime", subfsFeto.getString("id03")); // //回复人,关联user表id // subfsto.setValue("reply_user", this.getUserId(subfsFeto.getInteger("id02"))); // baseDao.add(subfsto); // //附件 //// subfsto.setValue("reply_attachment",); // } } } } private String emergencyDegreeType(String type) { String reType = ""; switch (type) { case "平件": reType = "1"; break; case "加急": reType = "2"; break; case "特急": reType = "3"; break; case "特提": reType = "4"; break; default: throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + type); } return reType; } /** * 迁移功能权限许可 * * @param conn JDBC连接 * @param funUUID 方法uuid * @param funCode 功能code * @param buttonMap 按钮map * @throws SQLException */ public void syncFunctionPermission(Connection conn, String funUUID, String funCode, JSONObject buttonMap) throws SQLException { DataTableEntity permissionDt = null; try { permissionDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_FUNCTION_USER", "FU02=?", new Object[]{funCode}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } Map funUsers = Maps.newHashMap(); for (int i = 0; i < permissionDt.getRows(); i++) { FieldSetEntity permissionFs = permissionDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_sys_function_permission"); fs.setValue("function_uuid", funUUID); //角色id String fu01 = permissionFs.getString("fu01"); //该权限管理的是用户表(SYS_USERS) 并非角色表 if ("U".equals(permissionFs.getString("fu03"))) { String fu04 = permissionFs.getString("fu04"); DataTableEntity data = funUsers.get(fu04); if (BaseUtil.dataTableIsEmpty(data)) { data = new DataTableEntity(); } data.addFieldSetEntity(permissionFs); funUsers.put(fu04, data); continue; } //获取角色数据 FieldSetEntity roleFse = baseDao.getFieldSetEntityByFilter("product_sys_role", " sequence = ? ", new String[]{fu01}, true); // String orgLevelUuid = roleFse.getString("org_level_uuid"); fs.setValue("role_uuid", roleFse.getUUID()); String fu04 = permissionFs.getString("fu04"); //获取权限里的按钮 List buttonIdType = new ArrayList<>(); buttonIdType.add(funCode); for (int j = 0; j < fu04.length(); j++) { String type = String.valueOf(fu04.charAt(j)); if (type.equals("1")) { //放入值的下标 buttonIdType.add(buttonTypeRole(j)); } } if (buttonIdType.size() == 1) { continue; } DataTableEntity eventDt = null; try { StringBuffer where = new StringBuffer(); where.append(" SE01=? ").append(" and ( ").append(BaseUtil.buildQuestionMarkFilter("SE12", buttonIdType.size() - 1, true)).append(" or SE08=1) "); eventDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", where.toString(), buttonIdType.toArray()); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } List buttonId = new ArrayList<>(); for (int j = 0; j < eventDt.getRows(); j++) { buttonId.add(buttonMap.getString(eventDt.getString(j, "se00"))); } buttonId.addAll(this.buttonUuid); fs.setValue("button_uuid", StringUtils.join(buttonId, ",")); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); baseDao.add(fs); } //同步每个功能权限后 还要同步客户权限 this.customerPermission(funUUID, buttonMap); } /** * 同步客户权限 * @param funUUID 功能权限 * @param buttonMap 案例uuid map */ public void customerPermission(String funUUID,JSONObject buttonMap){ FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_sys_function_permission"); fs.setValue("function_uuid", funUUID); //客户uuid fs.setValue("role_uuid", "8dddd416-a790-4a4e-8418-8c032d5f2394"); List buttonUuid = new ArrayList<>(); for (String key : buttonMap.keySet()) { buttonUuid.add(buttonMap.getString(key)); } //若没有按钮 直接退出 if(buttonUuid.size() == 0){ return; } fs.setValue("button_uuid", StringUtils.join(buttonUuid, ",")); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); baseDao.add(fs); } /** * 创建一个功能下的角色 * 把直接关联功能的用户放入角色下 * * @param conn 连接 * @param map k 为按钮权限,u 为关联用户权限的data * @param funUUID 功能uuid * @param funCode 功能code * @param buttonJson 按钮json * @param orgLevelUuid 公司uuid */ public void newFunctionRole(Connection conn, Map map, String funUUID, String funCode, JSONObject buttonJson, String orgLevelUuid) { for (Map.Entry m : map.entrySet()) { List buttonIdType = new ArrayList<>(); buttonIdType.add(funCode); String key = m.getKey(); for (int j = 0; j < key.length(); j++) { String type = String.valueOf(key.charAt(j)); if (type.equals("1")) { //放入值的下标 buttonIdType.add(buttonTypeRole(j)); } } //查询这条功能数据 FieldSetEntity funFse = baseDao.getFieldSetEntity("product_sys_function", funUUID, false); //功能名称 String functionName = funFse.getString("function_name"); //创建角色 FieldSetEntity lxRoleFs = new FieldSetEntity(); lxRoleFs.setTableName("product_sys_role"); if (BaseUtil.strIsNull(orgLevelUuid)) { orgLevelUuid = SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid(); } lxRoleFs.setValue("org_level_uuid", orgLevelUuid); String name = functionName + "功能下角色"; lxRoleFs.setValue("role_name", name); lxRoleFs.setValue("role_description", name); lxRoleFs.setValue("is_used", 1); feDataDSService.userAndTime(lxRoleFs); baseDao.add(lxRoleFs); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_sys_function_permission"); fs.setValue("function_uuid", funUUID); StringBuffer where = new StringBuffer(); where.append(" SE01=? ").append(" and ( ").append(BaseUtil.buildQuestionMarkFilter("SE12", buttonIdType.size() - 1, true)).append(" or SE08=1) "); DataTableEntity eventDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", where.toString(), buttonIdType.toArray()); List buttonId = new ArrayList<>(); for (int j = 0; j < eventDt.getRows(); j++) { buttonId.add(buttonJson.getString(eventDt.getString(j, "se00"))); } fs.setValue("button_uuid", StringUtils.join(buttonId, ",")); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); //创建角色 String uuid = baseDao.add(fs); //角色关联用户uuid DataTableEntity dataTableEntity = map.get(key); //获取关联用户 for (int i = 0; i < dataTableEntity.getRows(); i++) { String userId = dataTableEntity.getString(i, "fu01"); //获取用户 FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_staffs", " remark = ? ", new String[]{userId}, false); String roleUuids = fieldSetEntity.getString("role_uuids"); if (BaseUtil.strIsNull(roleUuids)) { fieldSetEntity.setValue("role_uuids", uuid); } else { roleUuids = roleUuids + "," + uuid; fieldSetEntity.setValue("role_uuids", roleUuids); } //保存修改角色权限后的用户 baseDao.add(fieldSetEntity); } } } private String buttonTypeRole(int type) { String button_category_uuid = ""; switch (type) { case 0: button_category_uuid = "01"; break; case 1: button_category_uuid = "02"; break; case 2: button_category_uuid = "03"; break; case 3: button_category_uuid = "04"; break; case 4: button_category_uuid = "05"; break; case 5: button_category_uuid = "06"; break; case 6: button_category_uuid = "07"; break; case 7: button_category_uuid = "08"; break; case 8: button_category_uuid = "09"; break; case 9: button_category_uuid = "10"; break; case 10: button_category_uuid = "11"; break; case 11: button_category_uuid = "12"; break; default: throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + type); } return button_category_uuid; } /** * 迁移功能下的按钮页面 * * @param conn * @param funUUID * @param funCode * @throws SQLException */ public JSONObject syncButtonsPage(Connection conn, String funUUID, String funCode) throws SQLException { DataTableEntity buttonsDt = null; try {//获取显示按钮 buttonsDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", "SE30 = '1' AND SE01= ? ", new Object[]{funCode}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } String flow_uuid = null; String sendButton = null; JSONObject map = new JSONObject(); //名字为k 的json Map nameButtonMap = Maps.newHashMap(); for (int i = 0; i < buttonsDt.getRows(); i++) { FieldSetEntity buttonsFs = buttonsDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); //页面表 fs.setTableName("product_sys_function_buttons"); fs.setValue("function_uuid", funUUID); //按钮名称 fs.setValue("button_name", buttonsFs.getString("se02")); //按钮标题 如果为空 就用描述 String buttonsFsString = buttonsFs.getString("se31"); if (BaseUtil.strIsNull(buttonsFsString) || " ".equals(buttonsFsString)) { buttonsFsString = buttonsFs.getString("se09"); } fs.setValue("button_title", buttonsFsString); //按钮描述 fs.setValue("button_description", buttonsFs.getString("se09")); //点击触发按钮事件的类型:1: 入口,2:普通按钮 若为入口可能会绑定流程 if (buttonsFs.getInteger("se08") == 1) { fs.setValue("button_type", 1); //绑定的流程 String se16 = buttonsFs.getString("se16"); //不为空 单独处理流程关联 if (!BaseUtil.strIsNull(se16)) { flow_uuid = se16; } } else { fs.setValue("button_type", 2); } fs.setValue("button_type", buttonsFs.getInteger("se08") == 1 ? 1 : 2); //是否启用 fs.setValue("status_uuid", 1); String type; if(buttonsFs.getInteger("se08") == 1){ //是否为功能入口,1=是,0=否 fs.setValue("is_main", 1); type = "main"; }else { type = buttonType(buttonsFs.getString("se12")); fs.setValue("is_main", 0); } //按钮分类:关联字典表(新增,修改,删除,查看,列表,导入,导出,送审) fs.setValue("button_category_uuid", type); //是删除按钮 都多选 if ("delete".equals(type)) { //是否多选 1 是 fs.setValue("multiple_choice", 1); //是否提醒 fs.setValue("is_warn", 1); } else { //是否多选 1 是 fs.setValue("multiple_choice", 0); fs.setValue("is_warn", 0); } //客户端类型:关联数据字典 fs.setValue("client_type_uuid", "Web"); //位置top fs.setValue("top_location", buttonsFs.getInteger("se11") + "px"); //位置left fs.setValue("left_location", buttonsFs.getInteger("se10") + "px"); //事件前 fron_event 1000 fs.setValue("fron_event", buttonsFs.getString("se03")); //逻辑方法 logical_method 800 fs.setValue("logical_method", buttonsFs.getString("se04")); //事件后 event_after 900 fs.setValue("event_after", buttonsFs.getString("se05")); //脚本类型 event_type 250 fs.setValue("event_type", buttonsFs.getString("se15")); //引入脚本 script_method 暂不插入 // System.out.println("se14:" + buttonsFs.getString("se14")); // fs.setValue("script_method", buttonsFs.getString("se14")); //路由名称 fs.setValue("route_name", BaseUtil.getPageCode()); String uuid = baseDao.add(fs); //09为送办按钮 if ("09".equals(buttonsFs.getString("se12")) && !BaseUtil.strIsNull(buttonsFs.getString("se14"))) { sendButton = uuid; } map.put(buttonsFs.getString("se00"), uuid); //名字唯一 nameButtonMap.put(buttonsFs.getString("se09"), fs); } DataTableEntity pageDt = null; try { pageDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_PAGE", "SP01=?", new Object[]{funCode}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } JSONObject pageMap = new JSONObject(); Map pageNameMap = Maps.newHashMap(); for (int i = 0; i < pageDt.getRows(); i++) { FieldSetEntity pageFs = pageDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); //页面表 fs.setTableName("product_sys_mvc_page"); fs.setValue("function_uuid", funUUID); //页面名称 String sp02 = pageFs.getString("sp02"); fs.setValue("page_name", sp02); //禁用页面元素 fs.setValue("page_element_disabled", 0); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); //位置top fs.setValue("top_location", pageFs.getString("sp07")); //位置left fs.setValue("left_location", pageFs.getString("sp06")); //表单类型 名称带有列表都是列表类型 if (sp02.contains("列表")) { fs.setValue("page_type", 1); } else { fs.setValue("page_type", 0); } //页面是否可修改 fs.setValue("page_element_disabled", pageFs.getInteger("sp08") == 1 ? 0 : 1); //页面路径暂存 fe引入js代码路径 fs.setValue("page_url", pageFs.getString("sp09")); //先存入流程id 迁移流程后再替换 fs.setValue("flow_uuid", pageFs.getString("sp09")); //打开方式 fs.setValue("page_open_with", 0); String uuid = baseDao.add(fs); pageMap.put(pageFs.getString("sp00"), uuid); pageNameMap.put(sp02, fs); } DataTableEntity pageButtonDt = null; try { pageButtonDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT_PAGE", "SEP06=?", new Object[]{funCode}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } for (int i = 0; i < pageButtonDt.getRows(); i++) { FieldSetEntity pageButtonFs = pageButtonDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_sys_link"); fs.setValue("function_uuid", funUUID); //连线类型 fs.setValue("link_type", 0); //起始uuid String pageUuid = pageMap.getString(pageButtonFs.getString("sep01")); fs.setValue("line_from", pageUuid); //起始类型 页面 fs.setValue("from_type", 2); //截止uuid String buttonUuid = map.getString(pageButtonFs.getString("sep02")); //为空表示关联失效的按钮 ,就不搬 if (BaseUtil.strIsNull(buttonUuid)) { continue; } fs.setValue("line_to", buttonUuid); //相等说明为送办 找到页面uuid存入流程 if (!BaseUtil.strIsNull(flow_uuid) && buttonUuid != null && buttonUuid.equals(sendButton)) { if (pageUuid != null) { FieldSetEntity fse = baseDao.getFieldSetEntity("product_sys_mvc_page", pageUuid, false); fse.setValue("flow_uuid", flow_uuid); baseDao.update(fse); } } //截止类型 fs.setValue("to_type", 1); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); baseDao.add(fs); } DataTableEntity buttonPageDt = null; try { //按钮连页面 按钮连按钮 buttonPageDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_REDIRECT", "SR06=?", new Object[]{funCode}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } for (int i = 0; i < buttonPageDt.getRows(); i++) { FieldSetEntity buttonPageFs = buttonPageDt.getFieldSetEntity(i); FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_sys_link"); fs.setValue("function_uuid", funUUID); fs.setValue("link_type", 0); //按钮与页面或者按钮与页面关系字段 String sr05 = buttonPageFs.getString("sr05"); String[] sr05s = sr05.split("-->"); FieldSetEntity buttonFse = nameButtonMap.get(sr05s[0]); if (buttonFse == null) { continue; } //判断是否是入口 if (1 == buttonFse.getInteger("is_main")) { //起始类型 0 入口 1 按钮 2 页面 fs.setValue("from_type", 0); } else { //起始类型 0 入口 1 按钮 2 页面 fs.setValue("from_type", 1); } fs.setValue("line_from", buttonFse.getUUID()); //获取按钮信息 //连接类型 1按钮连按钮 0按钮连页面 Integer sr02 = buttonPageFs.getInteger("sr02"); //连接的是按钮 if (1 == sr02) { //获取按钮fse 1 FieldSetEntity buttonFse2 = nameButtonMap.get(sr05s[1]); if (buttonFse2 == null) { continue; } //判断是否是入口 if (1 == buttonFse2.getInteger("is_main")) { //结束类型 0 入口 1 按钮 2 页面 fs.setValue("to_type", 0); } else { fs.setValue("to_type", 1); } fs.setValue("line_to", buttonFse2.getUUID()); } else { //连接的是页面 //获取页面fse 0 FieldSetEntity pageFse = pageNameMap.get(sr05s[1]); if (pageFse == null) { continue; } //页面类型 fs.setValue("to_type", 2); //页面uuid fs.setValue("line_to", pageFse.getUUID()); } fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); baseDao.add(fs); } return map; } /** * 按钮类型转换 * * @param type * @return */ private String buttonType(String type) { String button_category_uuid = ""; if (type == null) { button_category_uuid = "main"; return button_category_uuid; } switch (type) { case "01": button_category_uuid = "add"; break; case "02": button_category_uuid = "update"; break; case "03": button_category_uuid = "delete"; break; case "04": button_category_uuid = "view"; break; case "05": button_category_uuid = "print"; break; case "06": button_category_uuid = "import"; break; case "07": button_category_uuid = "custom"; break; case "08": button_category_uuid = "custom"; break; case "09": button_category_uuid = "audit"; break; case "10": button_category_uuid = "custom"; break; case "11": button_category_uuid = "custom"; break; case "12": button_category_uuid = "custom"; break; default: button_category_uuid = "custom"; } return button_category_uuid; } /** * @param funFs * @param moduleCode 模块code * @throws SQLException */ public void syncFunctions(FieldSetEntity funFs, String moduleCode, String sf28) throws SQLException, ClassNotFoundException { System.out.println(funFs.getString("sf28")); if(!BaseUtil.strIsNull(funFs.getString("sf28"))){ sf28 = funFs.getString("sf28"); } String table = sf28.split("\\.")[1].toLowerCase(); FieldSetEntity product_sys_datamodel_table = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", "table_name=?", new String[]{table}, false); //迁移功能 FieldSetEntity fs = new FieldSetEntity(); fs.setTableName("product_sys_functions"); //表uuid fs.setValue("table_uuid",product_sys_datamodel_table.getString("uuid")); //功能名称 fs.setValue("function_name", funFs.getString("sf03")); //功能描述 fs.setValue("function_description", funFs.getString("sf03")); //上级code 上级模块code fs.setValue("tricode_parent", moduleCode); //功能code String funCode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, moduleCode); fs.setValue("tricode", funCode); //功能短编码 fs.setValue("function_shortcode", "feqy"); fs.setValue("status_uuid", "1"); fs.setValue("function_type_uuid", "1"); fs.setValue("client_type_uuid", "Web"); fs.setValue("version_uuid", "001"); fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue("created_utc_datetime", new Date()); fs.setValue("data_type", 1); String funUUID = baseDao.add(fs); String sf05 = funFs.getString("sf05"); //获取jdbc连接 Connection conn = feDataDSService.getJDBC(); //迁移MVC JSONObject buttonMap = this.syncButtonsPage(conn, funUUID, sf05); //迁移菜单 try { this.synchronizationMenu(conn, funFs.getString("sf05"), funUUID); }catch (Exception e){ e.getStackTrace(); } //迁移功能权限许可 this.syncFunctionPermission(conn, funUUID, sf05, buttonMap); //关闭连接 DataManipulationUtils.close(null, null, conn); } /** * 同步模块名称 * * @param conn 连接 * @param funCode 功能code */ public String synchronizationModuleName(Connection conn, String funCode, String sf28) throws SQLException { FieldSetEntity funFse = null; try { //通过 funFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", " SF05 = ? ", new Object[]{funCode}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } if (funFse == null) { return null; } //模块名称 String sf01 = funFse.getString("sf01"); //同步模块名称 FieldSetEntity moduleFs = baseDao.getFieldSetEntityByFilter("product_sys_functions", " function_name = ? ", new String[]{sf01}, false); String moduleCode = null; String moduleUUID = null; if (moduleFs == null) { moduleFs = new FieldSetEntity(); moduleFs.setTableName("product_sys_functions"); //产品uuid moduleFs.setValue("table_uuid", "ff44dc40-5fa6-4b99-a0c6-463fd5fb5c5b85"); moduleFs.setValue("function_name", sf01); moduleFs.setValue("function_description", sf01); //产品code moduleFs.setValue("tricode_parent", "001"); moduleCode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, "001"); moduleFs.setValue("tricode", moduleCode); moduleFs.setValue("function_shortcode", "feqymk"); moduleFs.setValue("status_uuid", "1"); moduleFs.setValue("function_type_uuid", "0"); moduleFs.setValue("function_icon", "0"); moduleFs.setValue("client_type_uuid", "Web"); moduleFs.setValue("version_uuid", "001"); moduleFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); moduleFs.setValue("created_utc_datetime", new Date()); moduleFs.setValue("data_type", 2); //新增一个fe迁移总模块 moduleUUID = baseDao.add(moduleFs); } else { moduleCode = moduleFs.getString("tricode"); moduleUUID = moduleFs.getUUID(); } //同步模块下的功能 try { this.syncFunctions(funFse, moduleCode, sf28); } catch (ClassNotFoundException e) { e.printStackTrace(); } //同步菜单 return moduleUUID; } /** * 同步菜单 如果没有上级目录 创建上级目录 * @param conn jdbc连接 * @param funCode 同步code */ public void synchronizationMenu(Connection conn, String funCode, String funUUID) throws SQLException,BaseException{ //根据功能code获取菜单 FieldSetEntity menuFse = null; try { //菜单信息 menuFse = BaseDaoServiceImpl.getFieldSet(conn, "FE_BASE5.DESKTOP_MENU_MANAGEMENT", " URL = ? ", new Object[]{funCode}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } //查询是否有菜单和目录名称 FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_menus"," menu_name = ? ",new String[] {menuFse.getString("temp")}, false); //创建菜单 FieldSetEntity fieldSet = new FieldSetEntity(); fieldSet.setTableName("product_sys_menus"); //是否目录 0否、1是 fieldSet.setValue("is_catalog", 0); //是否显示 0:不显示、 1:显示 fieldSet.setValue("is_show", "1"); //关联功能 fieldSet.setValue("function_uuid", funUUID); //菜单描述 fieldSet.setValue("menu_description", menuFse.getString("name")); //菜单名称 fieldSet.setValue("menu_name", menuFse.getString("name")); //排列顺序 方源菜单id fieldSet.setValue("sequence", menuFse.getString("id")); //图标 fieldSet.setValue("menu_icon", "form"); String menuCode; //没有就创建菜单目录 if(fieldSetEntity == null){ FieldSetEntity menuFieldSet = new FieldSetEntity(); menuFieldSet.setTableName("product_sys_menus"); //是否目录 0否、1是 menuFieldSet.setValue("is_catalog", 1); //是否显示 0:不显示、 1:显示 menuFieldSet.setValue("is_show", "1"); //关联功能为空 menuFieldSet.setValue("function_uuid", ""); //图标 menuFieldSet.setValue("menu_icon", "clipboard"); //菜单描述 menuFieldSet.setValue("menu_description", menuFse.getString("temp")); //菜单名称 menuFieldSet.setValue("menu_name", menuFse.getString("temp")); //排列顺序 方源菜单目录id menuFieldSet.setValue("sequence", menuFse.getString("fatherid")); menuCode = CodeUtil.getNewCodeByTemp("product_sys_menus", "tricode", ""); //编码 menuFieldSet.setValue("tricode", menuCode); //父级编码 menuFieldSet.setValue("tricode_parent", ""); baseDao.add(menuFieldSet); }else { menuCode = fieldSetEntity.getString("tricode"); } //生成的菜单编码 fieldSet.setValue("tricode", CodeUtil.getNewCodeByTemp("product_sys_menus", "tricode", menuCode)); //父级编码 fieldSet.setValue("tricode_parent", menuCode); baseDao.add(fieldSet); } /** * 迁移业务数据表 * * @param sf28s 库名和表名 * @param conn 连接 * @return * @throws SQLException */ public void syncTable(String[] sf28s, boolean isNew, String subField, Connection conn) throws SQLException { FieldSetEntity Orlfs; //表名 String taName = sf28s[1]; String masterTableName = ""; //获取主表的表名 if (sf28s.length == 3) { masterTableName = sf28s[2]; } try { Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_TABLE", "ST03=?", new Object[]{taName}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } Map map = null; //是否是新表 if (isNew) { //判断是否是已经同步过的表 FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", " table_name = ? ", new String[]{taName.toLowerCase()}, false); if (fieldSetEntity == null) { //同步表结构 及字段信息 map = this.syncTableField(conn, Orlfs, sf28s, subField); //刷新table 表 DataPoolRefreshCache.getInstance().put("product_sys_datamodel_table"); //刷新field 表 DataPoolRefreshCache.getInstance().put("product_sys_datamodel_field"); try { Thread.sleep(7000); } catch (InterruptedException e) { e.printStackTrace(); } } else { return; } } else { //已有表 this.syncFunTable(conn, sf28s[0] + '.' + sf28s[1]); return; } //迁移表里面数据 DataTableEntity dataDt = null; try { dataDt = BaseDaoServiceImpl.getDataTable(conn, sf28s[0] + "." + sf28s[1], null, new String[]{}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } //查询该表字有没有附件字段 media attachment DataTableEntity accessoryData = this.getTableFieldAttachment(Orlfs.getString("st00")); Boolean syncAttachments = false; if (!BaseUtil.dataTableIsEmpty(accessoryData)) { syncAttachments = true; } //业务表 fe的id 对应UUID for (int i = 0; i < dataDt.getRows(); i++) { FieldSetEntity dataFs = dataDt.getFieldSetEntity(i); FieldSetEntity tableFs = new FieldSetEntity(); tableFs.setTableName(this.originalTable.getString(taName)); //key 为本表字段 value 为数据源字段 for (String key : map.keySet()) { //单关联的用户user_id if ("USER".equals(fieldTypeJson.getString(key))) { tableFs.setValue(key, userIdJson.getString(dataFs.getString(map.get(key)))); //单关联的组织架构uuid } else if ("GROUP".equals(fieldTypeJson.getString(key))) { tableFs.setValue(key, groupJson.get(dataFs.getString(map.get(key)))); //多选组织架构 转换为用户user_ids } else if ("USERSGROUPS".equals(fieldTypeJson.getString(map.get(key)))) { tableFs.setValue(key, this.getUserIds(dataFs.getString(map.get(key)))); } else { //是否有字段关联主表 if (subField != null && subField.equals(map.get(key))) { //表名加下标 唯一 tableFs.setValue(key, pxMap.getString(masterTableName + dataFs.getString(map.get(key)))); } else { tableFs.setValue(key, dataFs.getString(map.get(key))); } } } //同步附件 if (syncAttachments) { Map> fileMaps = this.synchronizationAttachments(conn, accessoryData, dataFs, taName); if (fileMaps.size() > 0) { for (String fieldName : fileMaps.keySet()) { List value = fileMaps.get(fieldName); tableFs.setValue(fieldName, StringUtils.join(value, ",")); } } } // if("app_notice_urge".equals(tableFs.getTableName())){ // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // e.printStackTrace(); // } // } String uuid = baseDao.add(tableFs); //表唯一id 对应uuid pxMap.put(taName + dataFs.getString(this.pk), uuid); } //同步完一张表数据后清空json数据 fieldTypeJson.clear(); DataTableEntity subTble = null; try { //查询是否有子表 subTble = BaseDaoServiceImpl.getDataTable(conn, "SELECT a.SF01, a.SF10,b.ST02 ST02,b.ST03 ST03 FROM FE_BASE5.SYS_FIELD a INNER JOIN FE_BASE5.SYS_TABLE b on a.SF00=b.ST00 WHERE a.SF10 LIKE ? ", new String[]{"%" + sf28s[1] + "%"}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } for (int i = 0; i < subTble.getRows(); i++) { FieldSetEntity sf = subTble.getFieldSetEntity(i); String a[] = {sf.getString("st02"), sf.getString("st03"), taName}; if (isStr(sf.getString("st02") + "\\." + sf.getString("st03"))) { isNew = false; } this.syncTable(a, isNew, sf.getString("sf01").toLowerCase(), conn); } } /** * 判断是否是引用数据 是就要转换(如人员id,机构id) * * @param tableName 表名点.字段名 * @return */ public void transformReferenceData(Connection conn, String tableName, String fieldName, FieldSetEntity fieldSetEntity) throws SQLException { DataTableEntity dataTable; try { StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ") .append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ") .append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND C.SP01 = 'prompt' AND SP02 = '[100001]' "); dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{fieldName, tableName}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } //是否是关联单个人员控件 if (BaseUtil.dataTableIsEmpty(dataTable)) { try { //是否是关联单个单位部门控件 StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ") .append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ") .append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND C.SP01 = 'orgtype' AND SP02 = 'A11' "); dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tableName, fieldName}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } if (BaseUtil.dataTableIsEmpty(dataTable)) { try { //是否是关联部门岗位人员多选控件 StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ") .append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ") .append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND C.SP01 = 'prompt' AND SP02 = '[111110]' "); dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tableName, fieldName}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } //如果是多选控件 if (!BaseUtil.dataTableIsEmpty(dataTable)) { fieldTypeJson.put(fieldName.toLowerCase(), "USERSGROUPS"); } } else { fieldTypeJson.put(fieldName.toLowerCase(), "GROUP"); } } else { fieldTypeJson.put(fieldName.toLowerCase(), "USER"); fieldSetEntity.setValue("field_reference", "user_name_by_user_id"); } } /** * 同步附件 * * @param accessoryData 附件字段data * @param tableFs 数据值 */ public Map> synchronizationAttachments(Connection conn, DataTableEntity accessoryData, FieldSetEntity tableFs, String table) { Map> filesMap = Maps.newHashMap(); for (int i = 0; i < accessoryData.getRows(); i++) { //类型 String type = accessoryData.getString(i, "si02"); //字段 String field = accessoryData.getString(i, "si04").toLowerCase(); //获取附件值 String attachmentsValue = tableFs.getString(field); if (!BaseUtil.strIsNull(attachmentsValue)) { List fileUuids = Lists.newArrayList(); //普通附件 if ("attachment".equals(type)) { //取出附件表数据 fileUuids = this.synchronizeCommonAccessories(conn, field, table, attachmentsValue); //金格附件 } else if ("media".equals(type)) { //附件值 //通过金格标识拼装全路径this.jinGePath String path1 = attachmentsValue.substring(0, 4); String path2 = attachmentsValue.substring(4, 6); String path3 = attachmentsValue.substring(6, 8); String path4 = attachmentsValue.substring(0, 14); StringBuffer fullPath = new StringBuffer(); fullPath.append(this.jinGePath).append("\\") .append(path1).append("\\") .append(path2).append("\\") .append(path3).append("\\") .append(path4); Map fileTimeName = feDataDSService.getFilesFolder(fullPath.toString()); if (fileTimeName == null) { //未找到附件直接跳过 continue; } DataTableEntity mediaSortInfo = this.getMediaSortInfo(attachmentsValue); //循环金格控件表数据 与文件数据配置 if (!BaseUtil.dataTableIsEmpty(mediaSortInfo)) { fileUuids = Lists.newArrayList(); for (int j = 0; j < mediaSortInfo.getRows(); j++) { //最新修改时间 String time = mediaSortInfo.getString(j, "wms04"); //创建时间 String name = mediaSortInfo.getString(j, "wms01"); //获取要移动的文件名称 String fileName = fileTimeName.get(time); if (BaseUtil.strIsNull(fileName)) { continue; } String filePath = fullPath.toString() + "\\" + fileName; String newPath = this.TSPath + "\\" + name; //复制到临时目录下 if (feDataDSService.copyFile(filePath, newPath)) { //通过路径获取File File file = new File(newPath); RequestParameterEntity rpe = new RequestParameterEntity(); Map fileMap = Maps.newHashMap(); //文件名 文件file fileMap.put(name, file); FieldSetEntity fieldSetEntity = new FieldSetEntity(); fieldSetEntity.setTableName(tableFs.getTableName()); fieldSetEntity.setValue(field, name); rpe.setFiles(fileMap); rpe.setFormData(fieldSetEntity); FieldSetEntity fileFse = fileManagerService.uploadFile(rpe); fileUuids.add(fileFse.getUUID()); } } } } if(fileUuids != null && fileUuids.size() > 0){ filesMap.put(field, fileUuids); } } } return filesMap; } /** * 同步普通附件方法 * @param conn 连接 * @param field 本字段名 * @param table 本表名 * @param attachmentsValue 源关联值 * @return */ public List synchronizeCommonAccessories(Connection conn, String field, String table, String attachmentsValue) { //取出附件表数据 DataTableEntity attachmentsData = this.getOrdinaryAttachments(conn, attachmentsValue); if (!BaseUtil.dataTableIsEmpty(attachmentsData)) { List fileUuids = Lists.newArrayList(); for (int j = 0; j < attachmentsData.getRows(); j++) { //保存名称 String sa02 = attachmentsData.getString(j, "sa02"); //显示名称 String sa03 = attachmentsData.getString(j, "sa03"); //保存路径 String sa04 = attachmentsData.getString(j, "sa04"); String filePath = sa04 + "\\" + sa02; String newPath = this.TSPath + "\\" + sa03; //复制到临时目录下 if (feDataDSService.copyFile(filePath, newPath)) { RequestParameterEntity rpe = new RequestParameterEntity(); Map fileMap = Maps.newHashMap(); //通过路径获取File File file = new File(newPath); //文件名 文件file fileMap.put(sa03, file); FieldSetEntity fieldSetEntity = new FieldSetEntity(); fieldSetEntity.setTableName(table); fieldSetEntity.setValue(field, sa03); rpe.setFiles(fileMap); rpe.setFormData(fieldSetEntity); FieldSetEntity fileFse = fileManagerService.uploadFile(rpe); fileUuids.add(fileFse.getUUID()); } } return fileUuids; } else { return null; } } /** * 获取普通附件信息 * * @param value 附件标识 * @return */ public DataTableEntity getOrdinaryAttachments(Connection conn, String value) { DataTableEntity dataTableEntity = null; StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM FE_BASE5.SYS_ATTACHMENT WHERE SA01 = ? "); System.out.println(value); dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{value}); return dataTableEntity; } /** * 获取金格附件信息 * * @param value 附件标识 * @return */ public DataTableEntity getMediaSortInfo(String value) { DataTableEntity dataTableEntity = null; Connection conn = null; try { conn = feDataDSService.getJDBC(); } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM FE_APP5.WF_MEDIA_SORT WHERE WMS02 = ? "); dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{value}); try { DataManipulationUtils.close(null, null, conn); } catch (SQLException e) { e.printStackTrace(); } return dataTableEntity; } /** * 通过表名获取同步的附件字段 * * @param tableName 表名 * @return */ public DataTableEntity getTableNameAttachment(Connection conn, String tableName) { DataTableEntity dataTableEntity = null; String[] names = tableName.split("\\."); StringBuffer sql = new StringBuffer(); sql.append(" SELECT A.SI02,A.SI04 FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ") .append(" ON A.SI01 = B.SF00 WHERE B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) ") .append("AND (A.SI02 = 'media' OR A.SI02 = 'attachment') GROUP BY A.SI04,A.SI02 "); dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{names[1]}); return dataTableEntity; } /** * 通过表id获取同步的附件字段 * * @param tableId 表id * @return */ public DataTableEntity getTableFieldAttachment(String tableId) { DataTableEntity dataTableEntity = null; Connection conn = null; try { conn = feDataDSService.getJDBC(); } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } StringBuffer sql = new StringBuffer(); sql.append(" SELECT A.SI02,A.SI04 FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ") .append(" ON A.SI01 = B.SF00 WHERE B.SF01 = ? AND (A.SI02 = 'media' OR A.SI02 = 'attachment') GROUP BY A.SI04,A.SI02 "); dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{tableId}); try { DataManipulationUtils.close(null, null, conn); } catch (SQLException e) { e.printStackTrace(); } return dataTableEntity; } /** * 迁移"product_sys_datamodel_field 和"product_sys_datamodel_table表 * * @throws SQLException */ public Map syncTableField(Connection conn, FieldSetEntity Orlfs, String[] tableName, String subField) throws SQLException { Map map = Maps.newHashMap(); FieldSetEntity tableFs = new FieldSetEntity(); tableFs.setTableName("product_sys_datamodel_table"); String table_name = Orlfs.getString("st03"); this.originalTable.put(table_name, table_name.toLowerCase()); tableFs.setValue("table_name", table_name.toLowerCase()); tableFs.setValue("table_description", Orlfs.getString("st04")); tableFs.setValue("table_primary_key", "uuid"); tableFs.setValue("table_type", "1"); tableFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); tableFs.setValue("created_utc_datetime", new Date()); tableFs.setValue("sequence", 1); baseDao.saveFieldSetEntity(tableFs); DataTableEntity Orldt = null; try { Orldt = BaseDaoServiceImpl.getDataTable(conn, "select a.*,b.DATA_TYPE from SYS_FIELD a LEFT JOIN (select * from all_tab_columns where TABLE_NAME=? and OWNER =?) b on a.SF01=b.COLUMN_NAME where SF00=(select ST00 from SYS_TABLE where ST03=?)", new String[]{tableName[1], tableName[0], tableName[1]}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } DataTableEntity dt = new DataTableEntity(); String table_uuid = tableFs.getString("uuid"); boolean is_pk = false; for (int i = 0; i < Orldt.getRows(); i++) { FieldSetEntity rowFs = Orldt.getFieldSetEntity(i); FieldSetEntity fieldFs = new FieldSetEntity(); fieldFs.setTableName("product_sys_datamodel_field"); fieldFs.setValue("table_uuid", table_uuid); //判断字段是否引用了用户字段 或 单位部门字段 String sf01 = rowFs.getString("sf01"); // 判断是否是引用数据 是就要转换(如人员id,机构id) transformReferenceData(conn, table_name, sf01, fieldFs); map.put(sf01.toLowerCase(), sf01.toLowerCase()); fieldFs.setValue("field_name", sf01.toLowerCase()); fieldFs.setValue("field_description", rowFs.getString("sf02")); fieldFs.setValue("field_show_name", rowFs.getString("sf02")); String type = this.fieldTypeFE(rowFs.getString("sf03")); //是否有字段关联主表 if ("pk".equals(type)) { //如果已经有pk if(is_pk){ type = "string"; }else { this.pk = sf01.toLowerCase(); is_pk = true; } } fieldFs.setValue("field_type", type); if ("GUID".equals(rowFs.getString("sf03"))) { fieldFs.setValue("is_unique", 1); } else { fieldFs.setValue("is_unique", 0); } if ("NATIVE".equals(rowFs.getString("sf03"))) { fieldFs.setValue("NATIVE", 1); } if ("UNITCODE".equals(rowFs.getString("sf03"))) { fieldFs.setValue("UNITCODE", 1); } //如果是关联主表字段 长度改为64 if (subField != null && subField.equals(sf01.toLowerCase())) { fieldFs.setValue("field_type", "string"); fieldFs.setValue("field_length", 64); } else { fieldFs.setValue("field_length", rowFs.getString("sf04")); } fieldFs.setValue("field_unit", rowFs.getString("sf05")); fieldFs.setValue("is_required", 0); fieldFs.setValue("is_filter", 1); if (null != rowFs.getString("sf10") && "".equals(rowFs.getString("sf10"))) { fieldFs.setValue("field_type", "parentuuid"); fieldFs.setValue("field_relation_table", rowFs.getString("sf10").split("\\.")[1]); } baseDao.saveFieldSetEntity(fieldFs); dt.addFieldSetEntity(fieldFs); } //如果没有自增主键 创建一个 if (!is_pk) { //添加自增主键 FieldSetEntity fieldFs = new FieldSetEntity(); fieldFs.setTableName("product_sys_datamodel_field"); fieldFs.setValue("table_uuid", table_uuid); fieldFs.setValue("field_name", tableFs.getString("table_name") + "_id"); fieldFs.setValue("field_description", "自增主键"); fieldFs.setValue("field_type", "pk"); fieldFs.setValue("field_length", 11); fieldFs.setValue("is_required", 0); fieldFs.setValue("is_unique", 1); fieldFs.setValue("is_international", 0); fieldFs.setValue("created_by", 1); fieldFs.setValue("created_utc_datetime", new Date()); fieldFs.setValue("field_show_name", "自增主键"); baseDao.saveFieldSetEntity(fieldFs); dt.addFieldSetEntity(fieldFs); } //添加uuid唯一标识 FieldSetEntity fieldFs = new FieldSetEntity(); fieldFs.setTableName("product_sys_datamodel_field"); fieldFs.setValue("table_uuid", table_uuid); fieldFs.setValue("field_name", "uuid"); fieldFs.setValue("field_description", "唯一标识"); fieldFs.setValue("field_type", "string"); fieldFs.setValue("field_length", 80); fieldFs.setValue("field_unit", 0); fieldFs.setValue("is_required", 0); fieldFs.setValue("is_unique", 0); fieldFs.setValue("is_international", 0); fieldFs.setValue("created_by", 1); fieldFs.setValue("created_utc_datetime", new Date()); fieldFs.setValue("field_show_name", "唯一标识"); baseDao.saveFieldSetEntity(fieldFs); dt.addFieldSetEntity(fieldFs); //创建表方法 StringBuilder createStatement = createTable(createFields(dt), Orlfs.getString("st03"), Orlfs.getString("st04")); //创建表方法 execute(createStatement.toString()); return map; } /** * //迁移 wf_model流程模块表 * * @param conn * @throws SQLException */ public void syncModel(String tricode_funs, Connection conn, String module_uuid, String sf28, String org_level_uuid, int created_by, boolean flag) throws SQLException { FieldSetEntity Orlfs = null; try { //通过 Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.wf_model", "wm05=(SELECT se16 FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)", new Object[]{tricode_funs }); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } if (Orlfs == null) { return; } FieldSetEntity modelFs = new FieldSetEntity(); //flow流程表 modelFs.setTableName("product_sys_flow_model"); //名称 modelFs.setValue("title", Orlfs.getString("wm01")); //描述 modelFs.setValue("flow_model_describe", Orlfs.getString("wm02")); //关联模块表 modelFs.setValue("module_uuid", module_uuid); //流程关联主表名称 String wm04 = Orlfs.getString("wm04"); //流程表没有就从功能表里面查询 if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) { try { //通过 FieldSetEntity funFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", " SF05 = ? ", new Object[]{tricode_funs}); wm04 = funFse.getString("sf28"); if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) { return; } } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } //如果功能表和流程表绑定的数据表不相同 以流程表为主 } else if (!wm04.equals(sf28)) { String[] wm04s = wm04.split("\\."); this.syncTable(wm04s, false, null, conn); } String[] wm04s = wm04.split("\\."); String table_name = wm04s[1].toLowerCase(); //主表表名 modelFs.setValue("table_uuid", table_name); //生成uuid String typeCode = UUID.randomUUID().toString(); modelFs.setValue("type_code", typeCode); modelFs.setValue("org_level_uuid", org_level_uuid); modelFs.setValue("created_by", created_by); modelFs.setValue("created_utc_datetime", new Date()); String modelUuid = baseDao.add(modelFs); //wm05 为流程编码 查询存有编码的mvc页面 改为流程uuid String wm05 = Orlfs.getString("wm05"); FieldSetEntity mvcPageFse = baseDao.getFieldSetEntityByFilter("product_sys_mvc_page", " flow_uuid = ?", new String[]{wm05}, false); if (mvcPageFse != null) { //mvc页面绑定流程uuid mvcPageFse.setValue("flow_uuid", typeCode); baseDao.update(mvcPageFse); } //迁移WF_NODES 流程节点表 JSONObject nodesUUID = this.syncNodes(tricode_funs, conn, modelUuid); //迁移WF_NODES 流程节点表 到"product_sys_flow_processor 处理器迁移 this.syncProcessor(tricode_funs, conn, modelUuid); //迁移WF_LINKS this.syncLinks(tricode_funs, conn, modelUuid); if(flag) { //迁移 WF_TASK JSONObject taskIdUUID = this.syncTask(tricode_funs, conn, modelUuid); //迁移wf_infor 节点任务处理情况表 Map stateMap = this.syncDetail(tricode_funs, conn, nodesUUID, sf28, modelUuid, taskIdUUID); //同步消息 try { this.synchronizingProcessMessages(conn,tricode_funs,stateMap); }catch (BaseException e){ e.printStackTrace(); } //源数据id 与 本数据uuid 关联 pxMap.clear(); } } /** * 迁移 flow处理器 * * @throws SQLException */ public void syncProcessor(String tricode_funs, Connection conn, String modelUUID) throws SQLException { DataTableEntity OrlDt = null; try { OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.wf_nodes", " WN01=(select wm00 from fe_base5.wf_model where wm05=(SELECT se16 FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)) and WN04 ='5'", new Object[]{tricode_funs }); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } for (int i = 0; i < OrlDt.getRows(); i++) { FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i); FieldSetEntity processorFs = new FieldSetEntity(); // flow处理器 processorFs.setTableName("product_sys_flow_processor"); processorFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); processorFs.setValue("created_utc_datetime", new Date()); //标题 processorFs.setValue("title", Orlfs.getString("wn02")); //类型:1-java,2-sql WN47 1 sql 2 java processorFs.setValue("processor_type", Orlfs.getInteger("wn47") == 1 ? 2 : 1); //详细内容 processorFs.setValue("content", Orlfs.getString("wn48")); //关联"product_sys_flow_model processorFs.setValue("flow_uuid", modelUUID); //坐标,节点到上边界的垂直距离 processorFs.setValue("location_top", Orlfs.getInteger("wn38") + "px"); //坐标,节点到左边界的垂直距离 processorFs.setValue("location_left", Orlfs.getInteger("wn37") + "px"); String uuid = baseDao.add(processorFs); //顺序号 nodesIdUUID.put(Orlfs.getString("wn00"), uuid); } } public JSONObject syncNodes(String tricode_funs, Connection conn, String modelUUID) throws SQLException { DataTableEntity OrlDt = null; try { OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.wf_nodes", " WN01=(select wm00 from fe_base5.wf_model where wm05=(SELECT se16 FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)) and WN04 !='5'", new Object[]{tricode_funs }); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } JSONObject map = new JSONObject(); nodesIdUUID = new JSONObject(); for (int i = 0; i < OrlDt.getRows(); i++) { FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i); FieldSetEntity nodeFs = new FieldSetEntity(); // WN62 关联表单字段 WN63 1 人员 2岗位 //flow节点表 nodeFs.setTableName("product_sys_flow_node"); //创建人 nodeFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); //创建时间 nodeFs.setValue("created_utc_datetime", new Date()); //标题 nodeFs.setValue("title", Orlfs.getString("wn02")); //描述 nodeFs.setValue("flow_node_describe", Orlfs.getString("wn03")); //组件类型:1-开始节点,2-处理节点,0-结束节点 //1开始 99结束; 3普通 4子任务 5处理器 6或处理7与处理8 会签 String module_type = "2"; if ("1".equals(Orlfs.getString("wn04"))) { module_type = "1"; } else if ("99".equals(Orlfs.getString("wn04"))) { module_type = "0"; } nodeFs.setValue("module_type", module_type); //是否多人处理 String wn26 = Orlfs.getString("wn26"); nodeFs.setValue("is_multiperson", wn26); if ("1".equals(wn26)) { //处理类型 String wn25 = Orlfs.getString("wn25"); // 类型:0-等待处理,1-竞争处理,2-顺序处理 先A 后b 。。。下一个节点 // WN25 0 无 1多人办理等待 2 竞争处理 if (!BaseUtil.strIsNull(wn25)) { if ("2".equals(wn25)) { nodeFs.setValue("deal_type", 1); } else { nodeFs.setValue("deal_type", 0); } } } else if ("0".equals(wn26)) { nodeFs.setValue("deal_type", 0); } //默认送直属领导 nodeFs.setValue("is_default_direct_supervisor", Orlfs.getString("wn34")); //是否允许加签 nodeFs.setValue("is_allow_add", Orlfs.getString("wn15")); //是否允许退回 nodeFs.setValue("is_allow_back", Orlfs.getString("wn13")); //wn48 结束节点调用的方法 String wn48 = Orlfs.getString("wn48"); if (!BaseUtil.strIsNull(wn48)) { //其他消息推送方法,调用java代码 暂存于此 nodeFs.setValue("msg_push_sp_func", wn48); } //节点权限关联表单字段同步 //WN62 关联表单字段 String wn62 = Orlfs.getString("wn62"); if (!BaseUtil.strIsNull(wn62)) { //WN63 1 人员 2岗位 String wn63 = Orlfs.getString("wn63"); if (BaseUtil.strIsNull(wn63)) { if ("1".equals(wn63)) { //人员 nodeFs.setValue("default_form_field_user", wn62.toLowerCase()); } else { //岗位 nodeFs.setValue("default_form_field_post", wn62.toLowerCase()); } } } //获取人员岗位单位部门 存入流程节点的人员 岗位 单位部门权限设置 Map map1 = this.syncNodeInstitutions(Orlfs); if (map1 != null && map1.size() > 0) { String userList = map1.get("userList"); //人员id if (!BaseUtil.strIsNull(userList)) { nodeFs.setValue("default_users", userList); } String postList = map1.get("postList"); //岗位uuid if (!BaseUtil.strIsNull(postList)) { nodeFs.setValue("default_posts", postList); } String deptList = map1.get("deptList"); //单位部门uuid if (!BaseUtil.strIsNull(deptList)) { nodeFs.setValue("default_depts", deptList); } } //需要在数据源表里面插入一个部门 所有直接关联单位都改为这个部门 //坐标,节点到上边界的垂直距离 nodeFs.setValue("location_top", Orlfs.getInteger("wn38") + "px"); //坐标,节点到左边界的水平距离 nodeFs.setValue("location_left", Orlfs.getInteger("wn37") + "px"); //关联"product_sys_flow_model nodeFs.setValue("flow_uuid", modelUUID); //关联附件 nodeFs.setValue("node_attachment_upload", 1); //下载附件 nodeFs.setValue("node_attachment_download", 0); //预览附件 nodeFs.setValue("node_attachment_preview", 1); String uuid = baseDao.add(nodeFs); //节点唯一号 map.put(Orlfs.getString("wn53"), uuid); //顺序号 nodesIdUUID.put(Orlfs.getString("wn00"), uuid); } return map; } /** * 同步节点配置的组织架构 * * @param fieldSetEntity */ public Map syncNodeInstitutions(FieldSetEntity fieldSetEntity) { String wn00 = fieldSetEntity.getString("wn00"); DataTableEntity OrlDt = null; try { Connection conn = feDataDSService.getJDBC(); OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.WF_ROLES", " WR01 = ? ", new Object[]{wn00}); DataManipulationUtils.close(null, null, conn); } catch (Exception e) { e.getStackTrace(); } if (BaseUtil.dataTableIsEmpty(OrlDt)) { return null; } //用户 List userList = Lists.newArrayList(); //部门 List deptList = Lists.newArrayList(); //岗位 List postList = Lists.newArrayList(); for (int i = 0; i < OrlDt.getRows(); i++) { FieldSetEntity fse = OrlDt.getFieldSetEntity(i); String wr04 = fse.getString("wr04"); String wr03 = fse.getString("wr03"); //用户 if ("X".equals(wr04)) { userList.add(wr03); //角色 岗位 } else if ("Y".equals(wr04)) { postList.add(wr03); //机构 } else if ("Z".equals(wr04)) { deptList.add(wr03); } } Map map = Maps.newHashMap(); //查询人员 if (userList.size() > 0) { DataTableEntity staffData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", userList.toArray(), true)); if (!BaseUtil.dataTableIsEmpty(staffData)) { userList.clear(); for (int i = 0; i < staffData.getRows(); i++) { userList.add(staffData.getString(i, "user_id")); } map.put("userList", StringUtils.join(userList, ",")); } } //查询岗位 if (postList.size() > 0) { DataTableEntity postData = baseDao.listTable("product_sys_job_posts", BaseUtil.buildQuestionMarkFilter("sequence", postList.toArray(), true)); if (!BaseUtil.dataTableIsEmpty(postData)) { postList.clear(); for (int i = 0; i < postData.getRows(); i++) { postList.add(postData.getString(i, "uuid")); } map.put("postList", StringUtils.join(postList, ",")); } } //查询机构(单位部门) if (deptList.size() > 0) { DataTableEntity orgData = baseDao.listTable("product_sys_org_levels", BaseUtil.buildQuestionMarkFilter("sequence", deptList.toArray(), true)); if (!BaseUtil.dataTableIsEmpty(orgData)) { deptList.clear(); for (int i = 0; i < orgData.getRows(); i++) { deptList.add(orgData.getString(i, "uuid")); } map.put("deptList", StringUtils.join(deptList, ",")); } } return map; } /** * @param conn * @param UUIDMap 流程节点node表fe uuid 对应 产品uuid * @param tableName 表名 * @return * @throws SQLException */ public Map syncDetail(String tricode_funs, Connection conn, JSONObject UUIDMap, String tableName, String modelUUID, JSONObject taskIdUUID) throws SQLException { tableName = tableName.split("\\.")[1]; OrgIdUUIDmap = Maps.newHashMap(); DataTableEntity OrlDt = null; try { StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM fe_base5.wf_infor where WI01 in (SELECT WT00 FROM fe_base5.wf_task where WT13= " + "(SELECT se16 FROM fe_base5.SYS_EVENT WHERE SE08 = 1 AND SE01 = ?)) ORDER BY WI01,WI00 "); OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tricode_funs}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } Map stateMap = Maps.newHashMap(); for (int i = 0; i < OrlDt.getRows(); i++) { FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i); FieldSetEntity DetailFs = new FieldSetEntity(); //flow明细表 DetailFs.setTableName("product_sys_flow_detail"); if (null == Orlfs.getString("wi02")) { //标题 DetailFs.setValue("title", "无标题"); } else { DetailFs.setValue("title", Orlfs.getString("wi02")); } //节点名称 DetailFs.setValue("node_title", Orlfs.getString("wi04")); //预期处理人 DetailFs.setValue("expect_person", userIdJson.getString(Orlfs.getString("wi05"))); //接收时间 Date wi08 = Orlfs.getDate("wi08"); DetailFs.setValue("accept_time",wi08); //创建时间 DetailFs.setValue("created_utc_datetime", wi08); String wi12 = userIdJson.getString(Orlfs.getString("wi12")); //实际处理人 DetailFs.setValue("actual_person", wi12); //修改人为实际处理人 DetailFs.setValue("updated_by", wi12); //处理时间 Date wi11 = Orlfs.getDate("wi11"); DetailFs.setValue("deal_time",wi11); DetailFs.setValue("updated_utc_datetime", wi11); //源uuid,关联本表 FieldSetEntity fieldSetEntity = OrgIdUUIDmap.get(Orlfs.getString("wi14")); if(fieldSetEntity != null){ DetailFs.setValue("source_uuid", fieldSetEntity.getUUID()); } //创建人 上个节点处理人 DetailFs.setValue("created_by", userIdJson.getString(Orlfs.getString("wi15"))); //节点标识(0-普通,1-加签,2-退回) DetailFs.setValue("node_sign", 0); String node_uuid = UUIDMap.getString(Orlfs.getString("wi62")); if (BaseUtil.strIsNull(node_uuid)) { continue; } //关联节点表 DetailFs.setValue("node_uuid", node_uuid); //意见 DetailFs.setValue("opinion", Orlfs.getString("wi20")); //预期处理时间(小时) DetailFs.setValue("expect_deal_time", Orlfs.getString("wi09")); //完成标识(0-未收,1-已收未办,2-已办,3-终止,4-竞争失败) // DetailFs.setValue("node_deal_sign", nodeDealType(Orlfs.getString("wi07"))); //办理状态(0-未收,1-已收未办,2-已办,3-终止,4-竞争失败) String nodeState = nodeDealType(Orlfs.getString("wi13")); DetailFs.setValue("node_deal_sign", nodeState); //关联表 DetailFs.setValue("table_name", this.originalTable.getString(tableName)); //关联业务UUID DetailFs.setValue("record_uuid", this.pxMap.getString(tableName + Orlfs.getString("wi29"))); //关联流程表uuid DetailFs.setValue("flow_uuid", modelUUID); String task_uuid = taskIdUUID.getString(Orlfs.getString("wi01")); if (BaseUtil.strIsNull(task_uuid)) { continue; } String attachmentsValue = Orlfs.getString("attachment"); //如果附件字段有值 同步附件 if(!BaseUtil.strIsNull(attachmentsValue)){ List fileUuids = this.synchronizeCommonAccessories(conn, "flow_attachment", DetailFs.getTableName(), attachmentsValue); //存入附件uuid DetailFs.setValue("flow_attachment", StringUtils.join(fileUuids, ",")); } //关联流程任务表 DetailFs.setValue("task_uuid", task_uuid); baseDao.add(DetailFs); String wi00 = Orlfs.getString("wi00"); OrgIdUUIDmap.put(wi00, DetailFs); stateMap.put(wi00, nodeState); } return stateMap; } /** * 同步流程消息表 */ public void synchronizingProcessMessages(Connection conn,String tricode_funs, Map stateMap) throws SQLException { DataTableEntity OrlDt = null; try { StringBuffer sql = new StringBuffer(); sql.append(" SELECT * FROM FE_BASE5.MESSAGEINFOR WHERE ME14 IN ( ") .append("SELECT WI00 FROM fe_base5.wf_infor where WI01 in (SELECT WT00 FROM fe_base5.wf_task where WT13= ") .append("(SELECT se16 FROM fe_base5.SYS_EVENT WHERE SE08 = 1 AND SE01 = ?))) ORDER BY ME14"); OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tricode_funs}); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } String id = null; String message_uuid = null; String state = null; for (int i = 0; i < OrlDt.getRows(); i++) { FieldSetEntity fs = OrlDt.getFieldSetEntity(i); //流程节点id String me14 = fs.getString("me14"); String sendUserId; //业务uuid FieldSetEntity fieldSet = OrgIdUUIDmap.get(fs.getString("me14")); String source_uuid = null; if(fieldSet != null){ source_uuid = fieldSet.getUUID(); }else { continue; } if(!me14.equals(id)){ //不一样创建消息主表 id = me14; FieldSetEntity message = new FieldSetEntity(); //消息主表 message.setTableName("product_sys_message"); //消息主题 message.setValue("title", fs.getString("me01")); //消息内容 message.setValue("content", fs.getString("me02")); //是否需要发送邮件 message.setValue("is_send_mail", 0); //消息类型21 流程消息都为任务消息 message.setValue("message_type", 21); //是否需要发送短信 0不发;1为强制;2为被动 System.out.println(fs.getString("me20")); message.setValue("is_send_sms","0".equals(fs.getString("me20")) ? 0:1); //发送时间 String me07 = fs.getString("me07"); message.setValue("send_time", me07); //创建时间 message.setValue("created_utc_datetime", me07); //发送人 sendUserId = userIdJson.getString(fs.getString("me03")); if(BaseUtil.strIsNull(sendUserId)){ //流程infor 数据创建人为发送人 sendUserId = fieldSet.getString("created_by"); } message.setValue("send_user_id", sendUserId); //创建人及发送人 message.setValue("created_by", sendUserId); // 业务表 message.setValue("source_table", "product_sys_flow_detail"); message.setValue("source_uuid",source_uuid); //url 业务地址 //获取当前节点状态 state = stateMap.get(fs.getString("me14")); //办理页面 if("0".equals(state) || "1".equals(state)){ message.setValue("url", "162132180172861usZ0N439?uuid="+source_uuid); //查询原文页面 }else if("2".equals(state)){ message.setValue("url", "1621321824686868oKWL726?uuid="+source_uuid); } message_uuid = baseDao.add(message); } FieldSetEntity message_user = new FieldSetEntity(); message_user.setTableName("product_sys_message_user"); //关联lx_sys_message表UUID message_user.setValue("message_uuid", message_uuid); //mail_send 是否发送邮件 message_user.setValue("mail_send", 0); // 是否阅读 节点状态为未读 //0未读 if("0".equals(state)){ message_user.setValue("read_type", 0); }else { message_user.setValue("read_type", 1); } //read_time 阅读时间 暂时为空 //receive_time 接收时间 无字段 //sms_send 是否发送短信 message_user.setValue("sms_send", 0); //user_id 消息接收人 String user_id = userIdJson.getString(fs.getString("me05")); //找不到发送人就放接收人 if(BaseUtil.strIsNull(user_id)){ user_id = userIdJson.getString(fs.getString("me03")); if(BaseUtil.strIsNull(user_id)){ continue; } } message_user.setValue("user_id",user_id); baseDao.add(message_user); } } //迁移WF_LINKS 连线表 public void syncLinks(String tricode_funs, Connection conn, String modelUUID) throws SQLException { DataTableEntity OrlDt = null; try { StringBuilder sql = new StringBuilder(); sql.append("select a.WL04 WL04,a.WL05 WL05,a.WL06 WL06,(SELECT WN04 FROM fe_base5.WF_NODES where WN00=a.WL05) source_type,"); sql.append("(select wa01 from fe_base5.WF_ACTION where wa00=a.WL03) WL03S,(SELECT WN04 FROM fe_base5.WF_NODES where WN00=(select wa01 from fe_base5.WF_ACTION where wa00=a.WL03)) "); sql.append(" target_type from fe_base5.wf_links a where WL05 in (select wn00 from fe_base5.wf_nodes where WN01=(select wm00 from fe_base5.wf_model where wm05=(SELECT se16 FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)))"); OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{tricode_funs }); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } for (int i = 0; i < OrlDt.getRows(); i++) { FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i); FieldSetEntity linksFs = new FieldSetEntity(); linksFs.setTableName("product_sys_flow_link"); linksFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); linksFs.setValue("created_utc_datetime", new Date()); //标题 linksFs.setValue("title", Orlfs.getString("wl04")); //连线起始位置uuid"product_sys_flow_node uuid 若为空则跳过 if(Orlfs.getString("wl03s") == null){ continue; } linksFs.setValue("source_uuid", nodesIdUUID.getString(Orlfs.getString("wl03s"))); //连线起点类型:1-节点,2-处理器 linksFs.setValue("source_type", "5".equals(Orlfs.getString("target_type")) ? 2 : 1); //连线截止位置uuid"product_sys_flow_node uuid System.out.println(Orlfs.getString("wl05")); System.out.println(nodesIdUUID.getString(Orlfs.getString("wl05"))); linksFs.setValue("target_uuid", nodesIdUUID.getString(Orlfs.getString("wl05"))); //连线截止类型:1-节点,2-处理器 linksFs.setValue("target_type", "5".equals(Orlfs.getString("source_type")) ? 2 : 1); //线的判定条件 linksFs.setValue("judge", Orlfs.getString("wl06")); //关联"product_sys_flow_model linksFs.setValue("flow_uuid", modelUUID); baseDao.add(linksFs); } } /** * 通过数据源表序列号 获取当前员工user_id */ // public Integer getUserId(Integer id){ // FieldSetEntity userFse = baseDao.getFieldSetEntityByFilter("product_sys_staffs", " remark = ? ",new Integer[]{id},false); // if(userFse == null){ // return null; // } // return userFse.getInteger("user_id"); // } /** * 同步task 表 * * @param conn * @param modelUUID 流程模块uuid * @return * @throws SQLException */ public JSONObject syncTask(String tricode_funs, Connection conn, String modelUUID) throws SQLException { DataTableEntity OrlDt = null; try { OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.WF_TASK", "WT13=(SELECT se16 FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)", new Object[]{tricode_funs }); } catch (Exception e) { DataManipulationUtils.close(null, null, conn); throw e; } JSONObject map = new JSONObject(); for (int i = 0; i < OrlDt.getRows(); i++) { FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i); FieldSetEntity taskFs = new FieldSetEntity(); taskFs.setTableName("product_sys_flow_task"); if (null == Orlfs.getString("wt05")) { //标题 taskFs.setValue("title", "无标题"); } else { taskFs.setValue("title", Orlfs.getString("wt05")); } // 发起人 //wt07用户id 获取用户id String id = userIdJson.getString(Orlfs.getString("wt07")); //发送人为空 就跳过 if (id == null) { continue; } taskFs.setValue("sender", id); //发起时间 taskFs.setValue("send_time", Orlfs.getDate("wt09")); //结束时间 taskFs.setValue("finish_time", Orlfs.getDate("wt10")); //关联流程表 taskFs.setValue("flow_uuid", modelUUID); //完成标识(1-在办,2-正常结束,3-终止) taskFs.setValue("finish_type", finishType(Orlfs.getString("wt16"))); //关联表 String tbName = Orlfs.getString("wt03").split("\\.")[1]; taskFs.setValue("table_name", this.originalTable.getString(tbName)); //当前环节节点uuid taskFs.setValue("cur_node_uuid", Orlfs.getString("wt00")); //关联业务UUID String record_uuid = pxMap.getString(tbName + Orlfs.getString("wt04")); if (BaseUtil.strIsNull(record_uuid)) { continue; } taskFs.setValue("record_uuid", record_uuid); taskFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); taskFs.setValue("created_utc_datetime", new Date()); String uuid = baseDao.add(taskFs); map.put(Orlfs.getString("wt00"), uuid); } return map; } /** * 创建表语句 * * @param sb * @param table_name * @param table_description * @return * @throws BaseException */ private StringBuilder createTable(StringBuilder sb, String table_name, String table_description) throws BaseException { StringBuilder createStatement = new StringBuilder(); createStatement.append(" create table `" + table_name + "` ( "); createStatement.append("\n"); createStatement.append(sb); createStatement.append("\n"); createStatement.append(" ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='" + table_description + "'"); return createStatement; } /** * 组装字段信息 * * @param dt * @throws BaseException */ private StringBuilder createFields(DataTableEntity dt) throws BaseException { StringBuilder table = new StringBuilder(); if (!BaseUtil.dataTableIsEmpty(dt)) { for (int i = 0; i < dt.getRows(); i++) { FieldSetEntity fse = dt.getFieldSetEntity(i); //字段类型 String field_type = fse.getString(CmnConst.FIELD_TYPE); //字段名 String field_name = fse.getString(CmnConst.FIELD_NAME); //字段描述 String field_description = fse.getString(CmnConst.FIELD_DESCRIPTION); //字段长度 Integer field_length = fse.getInteger(CmnConst.FIELD_LENGTH); //小数位数 Integer field_unit = fse.getInteger(CmnConst.FIELD_UNIT); //是否必填 Boolean is_required = fse.getBoolean(CmnConst.IS_REQUIRED); //是否唯一 Boolean is_unique = fse.getBoolean(CmnConst.IS_UNIQUE); //是否为主键 Boolean is_primary_key = "pk".equals(field_type) ? true : false; String field = newField(field_name, field_description, field_type, is_required, field_length, field_unit, is_primary_key, is_unique); if (table.length() > 0) { table.append(",\n\t"); } table.append(field); } } return table; } /** * 新字段组装 * * @param field_name 字段名称 * @param field_description 字段描述 * @param field_type 字段类型 * @param is_required 是否必填 * @param field_length 字段长度 * @param field_unit 小数长度 * @param is_primary_key 是否自增主键 * @param is_unique 是否唯一 * @return */ private String newField(String field_name, String field_description, String field_type, boolean is_required, Integer field_length, Integer field_unit, boolean is_primary_key, boolean is_unique) { StringBuilder sql = new StringBuilder(); sql.append(" `" + field_name + "` "); sql.append(" " + fieldType(field_type)); sql.append(" (" + field_length); if ("decimal".equals(field_type) && field_unit != null && field_unit > 0) { sql.append("," + field_unit); } sql.append(") " + (!is_required && !is_primary_key ? " DEFAULT NULL " : " NOT NULL ")); if (is_primary_key) { sql.append(" AUTO_INCREMENT "); } sql.append(" COMMENT '" + (field_description == null ? "" : field_description)).append("'"); if (is_primary_key) { sql.append(" ,\t\n PRIMARY KEY (`" + field_name + "`) USING BTREE "); } else if (CmnConst.UUID.equals(field_name) || is_unique) { sql.append(" ,\t\nUNIQUE KEY `" + field_name + "` (`" + field_name + "`) USING BTREE"); } return sql.toString(); } /** * 流程节点类型 1、开始 2、处理节点 0、结束 * * @param field_type * @return */ private String nodeType(String field_type) { String type = ""; switch (field_type) { case "1": type = "1"; break; case "99": type = "0"; break; case "5": type = "2"; break; case "3": type = "3"; case "4": type = "3"; break; case "6": type = "3"; break; case "7": type = "3"; break; case "8": type = "3"; break; default: throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type); } return type; } /** * 流程完成状态 * * @param field_type * @return */ private String finishType(String field_type) { String finishType = ""; switch (field_type) { case "0": finishType = "1"; break; case "1": finishType = "2"; break; case "2": finishType = "3"; break; case "3": finishType = "3"; break; default: throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type); } return finishType; } /** * 办理状态 * * @param field_type * @return */ private String nodeDealType(String field_type) { //源数据 0:已办;1:已收在办;2:未收未办;3 终止;4 冻结 //本数据 完成标识(0-未收,1-已收未办,2-已办,3-终止,4-竞争失败) String finishType = ""; switch (field_type) { case "0": finishType = "2"; break; case "1": finishType = "1"; break; case "2": finishType = "0"; break; case "3": finishType = "3"; break; case "4": finishType = "3"; break; default: throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type); } return finishType; } /** * 字段类型对照 * * @param field_type * @return */ private String fieldType(String field_type) { String mysql_field_type = ""; switch (field_type) { case "string": mysql_field_type = "varchar"; break; case "code": mysql_field_type = "varchar"; break; case "flowsign": mysql_field_type = "int"; break; case "datetime": mysql_field_type = "datetime"; break; case "file": mysql_field_type = "varchar"; break; case "int": mysql_field_type = "int"; break; case "pk": mysql_field_type = "bigint"; break; case "parentuuid": mysql_field_type = "varchar"; break; case "uuid": mysql_field_type = "varchar"; break; case "userid": mysql_field_type = "bigint"; break; case "orgUuid": mysql_field_type = "varchar"; break; case "number": mysql_field_type = "decimal"; break; case "serialNumber": mysql_field_type = "varchar"; break; case "email": mysql_field_type = "varchar"; break; case "idcard": mysql_field_type = "int"; break; case "url": mysql_field_type = "varchar"; break; case "mac": mysql_field_type = "varchar"; break; case "table_name": mysql_field_type = "varchar"; break; case "field_name": mysql_field_type = "varchar"; break; case "text": mysql_field_type = "text"; break; default: throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type); } return mysql_field_type; } /** * 字段类型对照 * * @param field_type * @return */ private String fieldTypeFE(String field_type) { String mysql_field_type = ""; switch (field_type) { //主键不设唯一不舍必填 case "AUTO": mysql_field_type = "pk"; break; case "NUMERIC": mysql_field_type = "number"; break; case "DATETIME": mysql_field_type = "datetime"; break; case "STRING": mysql_field_type = "string"; break; case "NATIVE": mysql_field_type = "string"; break; case "CDATETIME": mysql_field_type = "string"; break; case "PROMPT": mysql_field_type = "string"; break; case "SORT": mysql_field_type = "string"; break; case "MEDIA": mysql_field_type = "string"; break; case "SPFLAG": mysql_field_type = "flowsign"; break; case "IMAGE": mysql_field_type = "text"; break; case "TEXT": mysql_field_type = "text"; break; case "UNITCODE": mysql_field_type = "string"; break; case "FLOWCODE": mysql_field_type = "string"; break; case "GUID": mysql_field_type = "string"; break; default: throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type); } return mysql_field_type; } private synchronized void execute(String sql) throws BaseException { try { Connection connection = ConnectionManager.getInstance().getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.execute(); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); throw new BaseException(SystemCode.SQL_START_FAILED.getValue(), SystemCode.SQL_START_FAILED.getText() + e.getMessage()); } } }