优化同步岗位消耗数据库连接

This commit is contained in:
zhal 2022-07-21 10:30:52 +08:00
parent e20f385f08
commit aa316e1c05

View File

@ -1,5 +1,8 @@
package com.actionsoft.apps.coe.pal.pal.repository.job; package com.actionsoft.apps.coe.pal.pal.repository.job;
import com.actionsoft.apps.coe.pal.pal.backup.dao.CoEPALBackup;
import com.actionsoft.apps.coe.pal.pal.backup.extend.CoEPALBackupProcessor;
import com.actionsoft.apps.coe.pal.pal.backup.model.CoEPALBackupModel;
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel; import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel;
import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache;
import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory; import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory;
@ -25,6 +28,7 @@ import com.alibaba.fastjson.JSONObject;
import jodd.util.StringUtil; import jodd.util.StringUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
@ -34,8 +38,6 @@ import java.util.*;
/** /**
*
*
* 同步部门岗位数据 * 同步部门岗位数据
*/ */
public class SynchronousOrgJob implements IJob { public class SynchronousOrgJob implements IJob {
@ -52,12 +54,12 @@ public class SynchronousOrgJob implements IJob {
String wsIdParams = SDK.getJobAPI().getJobParameter(jobExecutionContext); String wsIdParams = SDK.getJobAPI().getJobParameter(jobExecutionContext);
wsId=wsIdParams; wsId = wsIdParams;
//先执行新建操作产生plid //先执行新建操作产生plid
PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel(); PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel();
String parentId="process"; String parentId = "process";
int orderIndex = getChildrenMaxOrderIndexByPidAndWsId(parentId, wsId) + 1; int orderIndex = getChildrenMaxOrderIndexByPidAndWsId(parentId, wsId) + 1;
String plRid1 = UUIDGener.getUUID(); String plRid1 = UUIDGener.getUUID();
@ -65,34 +67,39 @@ public class SynchronousOrgJob implements IJob {
Timestamp nowTime = new Timestamp(System.currentTimeMillis()); Timestamp nowTime = new Timestamp(System.currentTimeMillis());
String modeldefaultId=Createfolder(orderIndex);
String modeldefaultId = Createfolder(orderIndex);
Connection open = DBSql.open(); Connection open = DBSql.open();
orgdepartmentList = DBSql.getMaps(open,"select DEPARTMENTNAME,ID,LAYER,PARENTDEPARTMENTID,ORDERINDEX from ORGDEPARTMENT"); try {
orgdepartmentList = DBSql.getMaps(open, "select DEPARTMENTNAME,ID,LAYER,PARENTDEPARTMENTID,ORDERINDEX from ORGDEPARTMENT");
PALRepositoryModelImpl model = CoeProcessLevelUtil.createPALRepositoryModel(id1, plRid1, wsId, "内蒙古伊利实业集团股份有限公司", PALRepositoryModelImpl model = CoeProcessLevelUtil.createPALRepositoryModel(id1, plRid1, wsId, "内蒙古伊利实业集团股份有限公司",
"", orderIndex, modeldefaultId, "org", true, 1, "", orderIndex, modeldefaultId, "org", true, 1,
id1, false, "org.normal", "0", 1, null, id1, false, "org.normal", "0", 1, null,
null, "admin", "admin", nowTime, "0", null, null, "admin", "admin", nowTime, "0", null,
null, null, null, null, null, null, null, 1); null, null, null, null, null, null, null, 1);
coeProcessLevel.insert(model); coeProcessLevel.insert(model);
parentModelId = model.getId();
parentModelId=model.getId(); orgindex = 0;
orgindex = 0; createTree(open);
createTree(); } catch (Exception e) {
DBSql.close(open); e.printStackTrace();
} finally {
DBSql.close(open);
}
} }
/** /**
* 创建岗位模型文件夹 * 创建岗位模型文件夹
*
* @param orderIndex * @param orderIndex
* @return * @return
*/ */
public String Createfolder(int orderIndex){ public String Createfolder(int orderIndex) {
PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel(); PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel();
String plRid1 = UUIDGener.getUUID(); String plRid1 = UUIDGener.getUUID();
String id1 = UUIDGener.getUUID(); String id1 = UUIDGener.getUUID();
@ -106,59 +113,59 @@ public class SynchronousOrgJob implements IJob {
null, "admin", "admin", nowTime, null, null, null, "admin", "admin", nowTime, null, null,
null, null, null, null, null, null, null, 1); null, null, null, null, null, null, null, 1);
coeProcessLevel.insert(modeldefault); coeProcessLevel.insert(modeldefault);
return modeldefault.getId(); return modeldefault.getId();
} }
public void createTree() { public void createTree(Connection open) {
for (RowMap oneData : orgdepartmentList) { for (RowMap oneData : orgdepartmentList) {
orgindex++; orgindex++;
creatNode(oneData); creatNode(oneData, open);
} }
System.out.println("同步完成,数据" + orgindex); System.out.println("同步完成,数据" + orgindex);
} }
public String creatNode(RowMap org) { public String creatNode(RowMap org, Connection conn) {
//先执行新建操作产生plid //先执行新建操作产生plid
PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel(); PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel();
String modelId=""; String modelId = "";
String plRid1 = UUIDGener.getUUID(); String plRid1 = UUIDGener.getUUID();
String id1 = UUIDGener.getUUID(); String id1 = UUIDGener.getUUID();
Timestamp nowTime = new Timestamp(System.currentTimeMillis()); Timestamp nowTime = new Timestamp(System.currentTimeMillis());
if (org.getString("PARENTDEPARTMENTID").equals("0")) { if (org.getString("PARENTDEPARTMENTID").equals("0")) {
String sql1 = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='"+wsId+"' and EXT1='" + org.getString("ID") + "'"; String sql1 = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='" + wsId + "' and EXT1='" + org.getString("ID") + "'";
String parentPalOrgId1 = DBSql.getString(sql1); String parentPalOrgId1 = DBSql.getString(conn, sql1);
if(StringUtil.isEmpty(parentPalOrgId1)){ if (StringUtil.isEmpty(parentPalOrgId1)) {
PALRepositoryModelImpl model1 = CoeProcessLevelUtil.createPALRepositoryModel(id1, plRid1, wsId, org.getString("DEPARTMENTNAME"), PALRepositoryModelImpl model1 = CoeProcessLevelUtil.createPALRepositoryModel(id1, plRid1, wsId, org.getString("DEPARTMENTNAME"),
"", 1, parentModelId, "org", true, 1, "", 1, parentModelId, "org", true, 1,
id1, false, "org.normal", "0", Integer.valueOf(org.getString("ORDERINDEX")), null, id1, false, "org.normal", "0", Integer.valueOf(org.getString("ORDERINDEX")), null,
null, "admin", "admin", nowTime, org.getString("ID"), null, null, "admin", "admin", nowTime, org.getString("ID"), null,
null, null, null, null, null, null, null, 1); null, null, null, null, null, null, null, 1);
coeProcessLevel.insert(model1); coeProcessLevel.insert(model1);
createPostData(model1.getId(),org.getString("ID"),model1); createPostData(model1.getId(), org.getString("ID"), model1, conn);
return modelId=model1.getId(); return modelId = model1.getId();
} }
} else { } else {
String parentPalOrgId = getParentPalOrgId(org); String parentPalOrgId = getParentPalOrgId(org, conn);
if(StringUtil.isNotEmpty(parentPalOrgId)){ if (StringUtil.isNotEmpty(parentPalOrgId)) {
PALRepositoryModelImpl model2 = CoeProcessLevelUtil.createPALRepositoryModel(id1, plRid1, wsId, org.getString("DEPARTMENTNAME"), PALRepositoryModelImpl model2 = CoeProcessLevelUtil.createPALRepositoryModel(id1, plRid1, wsId, org.getString("DEPARTMENTNAME"),
"", 1, getParentPalOrgId(org), "org", true, 1, "", 1, getParentPalOrgId(org, conn), "org", true, 1,
id1, false, "org.normal", "0", Integer.valueOf(org.getString("ORDERINDEX")), null, id1, false, "org.normal", "0", Integer.valueOf(org.getString("ORDERINDEX")), null,
null, "admin", "admin", nowTime, org.getString("ID"), null, null, "admin", "admin", nowTime, org.getString("ID"), null,
null, null, null, null, null, null, null, 1); null, null, null, null, null, null, null, 1);
coeProcessLevel.insert(model2); coeProcessLevel.insert(model2);
createPostData(model2.getId(),org.getString("ID"),model2); createPostData(model2.getId(), org.getString("ID"), model2, conn);
return modelId=model2.getId(); return modelId = model2.getId();
} }
@ -170,28 +177,28 @@ public class SynchronousOrgJob implements IJob {
} }
public String getParentPalOrgId(RowMap org) { public String getParentPalOrgId(RowMap org, Connection conn) {
String sql = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='"+wsId+"' and EXT1='" + org.getString("PARENTDEPARTMENTID") + "'"; String sql = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='" + wsId + "' and EXT1='" + org.getString("PARENTDEPARTMENTID") + "'";
String parentPalOrgId = DBSql.getString(sql); String parentPalOrgId = DBSql.getString(conn, sql);
if (parentPalOrgId.equals("0") || parentPalOrgId.equals("") || parentPalOrgId == null) { if (parentPalOrgId.equals("0") || parentPalOrgId.equals("") || parentPalOrgId == null) {
RowMap parentOrg = DBSql.getMap("select DEPARTMENTNAME,ID,LAYER,PARENTDEPARTMENTID,ORDERINDEX from ORGDEPARTMENT where id = '" + org.getString("PARENTDEPARTMENTID") + "'"); RowMap parentOrg = DBSql.getMap(conn, "select DEPARTMENTNAME,ID,LAYER,PARENTDEPARTMENTID,ORDERINDEX from ORGDEPARTMENT where id = '" + org.getString("PARENTDEPARTMENTID") + "'");
creatNode(parentOrg); creatNode(parentOrg, conn);
} }
return parentPalOrgId; return parentPalOrgId;
} }
public String getParentPallevel(RowMap org) { public String getParentPallevel(RowMap org, Connection conn) {
String sql = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='"+wsId+"' and EXT1='" + org.getString("PARENTDEPARTMENTID") + "'"; String sql = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='" + wsId + "' and EXT1='" + org.getString("PARENTDEPARTMENTID") + "'";
String parentPalOrgId = DBSql.getString(sql); String parentPalOrgId = DBSql.getString(conn, sql);
if (parentPalOrgId.equals("0") || parentPalOrgId.equals("") || parentPalOrgId == null) { if (parentPalOrgId.equals("0") || parentPalOrgId.equals("") || parentPalOrgId == null) {
RowMap parentOrg = DBSql.getMap("select DEPARTMENTNAME,ID,LAYER,PARENTDEPARTMENTID from ORGDEPARTMENT where id = '" + org.getString("PARENTDEPARTMENTID") + "'"); RowMap parentOrg = DBSql.getMap("select DEPARTMENTNAME,ID,LAYER,PARENTDEPARTMENTID from ORGDEPARTMENT where id = '" + org.getString("PARENTDEPARTMENTID") + "'");
creatNode(parentOrg); creatNode(parentOrg, conn);
} }
return parentPalOrgId; return parentPalOrgId;
@ -200,16 +207,17 @@ public class SynchronousOrgJob implements IJob {
/** /**
* 创建岗位图形 * 创建岗位图形
*
* @param uuid * @param uuid
* @return * @return
*/ */
public void createPostData(String uuid,String departmentId,PALRepositoryModelImpl model){ public void createPostData(String uuid, String departmentId, PALRepositoryModelImpl model, Connection conn) {
Map<String, String> idRelationMap = new HashMap<>(); Map<String, String> idRelationMap = new HashMap<>();
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(model.getId(), 0); BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(model.getId(), 0);
if(defineModel ==null ){ if (defineModel == null) {
defineModel = CoeDesignerUtil.createModel(model.getId(),0); defineModel = CoeDesignerUtil.createModel(model.getId(), 0);
defineModel.setCreateHistory(false); defineModel.setCreateHistory(false);
} }
String define = defineModel.getDefinition(); String define = defineModel.getDefinition();
@ -227,20 +235,20 @@ public class SynchronousOrgJob implements IJob {
} }
List<RowMap> orgdepartmentList=DBSql.getMaps("select DISTINCT(POSITION_NAME) from ORGUSER WHERE DEPARTMENTID=?",departmentId); List<RowMap> orgdepartmentList = DBSql.getMaps(conn, "select DISTINCT(POSITION_NAME) from ORGUSER WHERE DEPARTMENTID=?", departmentId);
JSONArray shapes = new JSONArray(); JSONArray shapes = new JSONArray();
if(orgdepartmentList.size()>0){ if (orgdepartmentList.size() > 0) {
for(int i=0;i<orgdepartmentList.size();i++){ for (int i = 0; i < orgdepartmentList.size(); i++) {
//新建一个uuid //新建一个uuid
String shapeId1 = UUIDGener.getObjectId(); String shapeId1 = UUIDGener.getObjectId();
//拿到基础结构 //拿到基础结构
JSONObject shape1 = ShapeUtil.getProcessShapeDefinitionByName("org.normal", "position"); JSONObject shape1 = ShapeUtil.getProcessShapeDefinitionByName("org.normal", "position");
String positionName=orgdepartmentList.get(i).getString("POSITION_NAME"); String positionName = orgdepartmentList.get(i).getString("POSITION_NAME");
if(StringUtil.isNotEmpty(positionName)){ if (StringUtil.isNotEmpty(positionName)) {
JSONObject newShape = JSONObject.parseObject(shape1.toString()); JSONObject newShape = JSONObject.parseObject(shape1.toString());
newShape.put("id", shapeId1); newShape.put("id", shapeId1);
@ -262,7 +270,6 @@ public class SynchronousOrgJob implements IJob {
} }
// 设置画布大小 // 设置画布大小
DiagramsUtil.setDiagramHeightWidth(definition, elements); DiagramsUtil.setDiagramHeightWidth(definition, elements);
defineModel.setDefinition(definition.toString()); defineModel.setDefinition(definition.toString());
@ -272,8 +279,6 @@ public class SynchronousOrgJob implements IJob {
} }
/** /**
* 创建具有合理位置的节点数据 * 创建具有合理位置的节点数据
* *
@ -331,7 +336,6 @@ public class SynchronousOrgJob implements IJob {
} }
private String validateJson(String name) { private String validateJson(String name) {
return name == null ? "" : name; return name == null ? "" : name;
} }
@ -341,17 +345,17 @@ public class SynchronousOrgJob implements IJob {
} }
/** /**
* 获取文件的下级文件的最大orderIndex * 获取文件的下级文件的最大orderIndex
* 在不同的资产库根节点(palId)都相同增加资产库避免统计时错误 * 在不同的资产库根节点(palId)都相同增加资产库避免统计时错误
*
* @param palId * @param palId
* @param wsId * @param wsId
* @return * @return
* @author sunlh * @author sunlh
*/ */
public int getChildrenMaxOrderIndexByPidAndWsId(String palId, String wsId) { public int getChildrenMaxOrderIndexByPidAndWsId(String palId, String wsId) {
String sql = "SELECT MAX(PLORDERINDEX) AS orderIndex FROM APP_ACT_COE_PAL_REPOSITORY WHERE (PLPARENTID IN " + "(SELECT r1.id FROM APP_ACT_COE_PAL_REPOSITORY r1, APP_ACT_COE_PAL_REPOSITORY r2 WHERE r1.PLVERSIONID = r2.PLVERSIONID AND r2.id='" + palId + "')" + " OR PLPARENTID = '" + palId + "') AND wsid='" + wsId +"'"; String sql = "SELECT MAX(PLORDERINDEX) AS orderIndex FROM APP_ACT_COE_PAL_REPOSITORY WHERE (PLPARENTID IN " + "(SELECT r1.id FROM APP_ACT_COE_PAL_REPOSITORY r1, APP_ACT_COE_PAL_REPOSITORY r2 WHERE r1.PLVERSIONID = r2.PLVERSIONID AND r2.id='" + palId + "')" + " OR PLPARENTID = '" + palId + "') AND wsid='" + wsId + "'";
int maxOrderIndex = DBSql.getInt(sql, "orderIndex"); int maxOrderIndex = DBSql.getInt(sql, "orderIndex");
return maxOrderIndex; return maxOrderIndex;
} }