优化同步岗位消耗数据库连接
This commit is contained in:
parent
e20f385f08
commit
aa316e1c05
@ -1,5 +1,8 @@
|
||||
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.repository.cache.PALRepositoryCache;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory;
|
||||
@ -25,6 +28,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import jodd.util.StringUtil;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
@ -34,8 +38,6 @@ import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* 同步部门、岗位数据
|
||||
*/
|
||||
public class SynchronousOrgJob implements IJob {
|
||||
@ -52,12 +54,12 @@ public class SynchronousOrgJob implements IJob {
|
||||
|
||||
|
||||
String wsIdParams = SDK.getJobAPI().getJobParameter(jobExecutionContext);
|
||||
wsId=wsIdParams;
|
||||
wsId = wsIdParams;
|
||||
|
||||
|
||||
//先执行新建操作产生plid
|
||||
PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel();
|
||||
String parentId="process";
|
||||
String parentId = "process";
|
||||
int orderIndex = getChildrenMaxOrderIndexByPidAndWsId(parentId, wsId) + 1;
|
||||
|
||||
String plRid1 = UUIDGener.getUUID();
|
||||
@ -65,34 +67,39 @@ public class SynchronousOrgJob implements IJob {
|
||||
|
||||
Timestamp nowTime = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
String modeldefaultId=Createfolder(orderIndex);
|
||||
|
||||
String modeldefaultId = Createfolder(orderIndex);
|
||||
|
||||
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, "内蒙古伊利实业集团股份有限公司",
|
||||
"", orderIndex, modeldefaultId, "org", true, 1,
|
||||
id1, false, "org.normal", "0", 1, null,
|
||||
null, "admin", "admin", nowTime, "0", null,
|
||||
null, null, null, null, null, null, null, 1);
|
||||
coeProcessLevel.insert(model);
|
||||
PALRepositoryModelImpl model = CoeProcessLevelUtil.createPALRepositoryModel(id1, plRid1, wsId, "内蒙古伊利实业集团股份有限公司",
|
||||
"", orderIndex, modeldefaultId, "org", true, 1,
|
||||
id1, false, "org.normal", "0", 1, null,
|
||||
null, "admin", "admin", nowTime, "0", null,
|
||||
null, null, null, null, null, null, null, 1);
|
||||
coeProcessLevel.insert(model);
|
||||
|
||||
|
||||
parentModelId=model.getId();
|
||||
orgindex = 0;
|
||||
createTree();
|
||||
DBSql.close(open);
|
||||
parentModelId = model.getId();
|
||||
orgindex = 0;
|
||||
createTree(open);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
DBSql.close(open);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建岗位模型文件夹
|
||||
*
|
||||
* @param orderIndex
|
||||
* @return
|
||||
*/
|
||||
public String Createfolder(int orderIndex){
|
||||
public String Createfolder(int orderIndex) {
|
||||
PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel();
|
||||
String plRid1 = UUIDGener.getUUID();
|
||||
String id1 = UUIDGener.getUUID();
|
||||
@ -106,59 +113,59 @@ public class SynchronousOrgJob implements IJob {
|
||||
null, "admin", "admin", nowTime, null, null,
|
||||
null, null, null, null, null, null, null, 1);
|
||||
coeProcessLevel.insert(modeldefault);
|
||||
return modeldefault.getId();
|
||||
return modeldefault.getId();
|
||||
}
|
||||
|
||||
public void createTree() {
|
||||
public void createTree(Connection open) {
|
||||
|
||||
for (RowMap oneData : orgdepartmentList) {
|
||||
orgindex++;
|
||||
creatNode(oneData);
|
||||
creatNode(oneData, open);
|
||||
}
|
||||
System.out.println("同步完成,数据" + orgindex);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String creatNode(RowMap org) {
|
||||
public String creatNode(RowMap org, Connection conn) {
|
||||
//先执行新建操作产生plid
|
||||
PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel();
|
||||
|
||||
String modelId="";
|
||||
String modelId = "";
|
||||
String plRid1 = UUIDGener.getUUID();
|
||||
String id1 = UUIDGener.getUUID();
|
||||
Timestamp nowTime = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
|
||||
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 parentPalOrgId1 = DBSql.getString(sql1);
|
||||
if(StringUtil.isEmpty(parentPalOrgId1)){
|
||||
String sql1 = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='" + wsId + "' and EXT1='" + org.getString("ID") + "'";
|
||||
String parentPalOrgId1 = DBSql.getString(conn, sql1);
|
||||
if (StringUtil.isEmpty(parentPalOrgId1)) {
|
||||
PALRepositoryModelImpl model1 = CoeProcessLevelUtil.createPALRepositoryModel(id1, plRid1, wsId, org.getString("DEPARTMENTNAME"),
|
||||
"", 1, parentModelId, "org", true, 1,
|
||||
id1, false, "org.normal", "0", Integer.valueOf(org.getString("ORDERINDEX")), null,
|
||||
null, "admin", "admin", nowTime, org.getString("ID"), null,
|
||||
null, null, null, null, null, null, null, 1);
|
||||
coeProcessLevel.insert(model1);
|
||||
createPostData(model1.getId(),org.getString("ID"),model1);
|
||||
return modelId=model1.getId();
|
||||
createPostData(model1.getId(), org.getString("ID"), model1, conn);
|
||||
return modelId = model1.getId();
|
||||
}
|
||||
|
||||
} 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"),
|
||||
"", 1, getParentPalOrgId(org), "org", true, 1,
|
||||
"", 1, getParentPalOrgId(org, conn), "org", true, 1,
|
||||
id1, false, "org.normal", "0", Integer.valueOf(org.getString("ORDERINDEX")), null,
|
||||
null, "admin", "admin", nowTime, org.getString("ID"), null,
|
||||
null, null, null, null, null, null, null, 1);
|
||||
coeProcessLevel.insert(model2);
|
||||
|
||||
createPostData(model2.getId(),org.getString("ID"),model2);
|
||||
return modelId=model2.getId();
|
||||
createPostData(model2.getId(), org.getString("ID"), model2, conn);
|
||||
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 parentPalOrgId = DBSql.getString(sql);
|
||||
String sql = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='" + wsId + "' and EXT1='" + org.getString("PARENTDEPARTMENTID") + "'";
|
||||
String parentPalOrgId = DBSql.getString(conn, sql);
|
||||
|
||||
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") + "'");
|
||||
creatNode(parentOrg);
|
||||
RowMap parentOrg = DBSql.getMap(conn, "select DEPARTMENTNAME,ID,LAYER,PARENTDEPARTMENTID,ORDERINDEX from ORGDEPARTMENT where id = '" + org.getString("PARENTDEPARTMENTID") + "'");
|
||||
creatNode(parentOrg, conn);
|
||||
}
|
||||
|
||||
return parentPalOrgId;
|
||||
}
|
||||
|
||||
|
||||
public String getParentPallevel(RowMap org) {
|
||||
String sql = "SELECT ID FROM APP_ACT_COE_PAL_REPOSITORY WHERE wsId='"+wsId+"' and EXT1='" + org.getString("PARENTDEPARTMENTID") + "'";
|
||||
String parentPalOrgId = DBSql.getString(sql);
|
||||
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 parentPalOrgId = DBSql.getString(conn, sql);
|
||||
|
||||
if (parentPalOrgId.equals("0") || parentPalOrgId.equals("") || parentPalOrgId == null) {
|
||||
RowMap parentOrg = DBSql.getMap("select DEPARTMENTNAME,ID,LAYER,PARENTDEPARTMENTID from ORGDEPARTMENT where id = '" + org.getString("PARENTDEPARTMENTID") + "'");
|
||||
|
||||
creatNode(parentOrg);
|
||||
creatNode(parentOrg, conn);
|
||||
}
|
||||
|
||||
return parentPalOrgId;
|
||||
@ -200,16 +207,17 @@ public class SynchronousOrgJob implements IJob {
|
||||
|
||||
/**
|
||||
* 创建岗位图形
|
||||
*
|
||||
* @param uuid
|
||||
* @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<>();
|
||||
|
||||
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(model.getId(), 0);
|
||||
if(defineModel ==null ){
|
||||
defineModel = CoeDesignerUtil.createModel(model.getId(),0);
|
||||
if (defineModel == null) {
|
||||
defineModel = CoeDesignerUtil.createModel(model.getId(), 0);
|
||||
defineModel.setCreateHistory(false);
|
||||
}
|
||||
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();
|
||||
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
|
||||
String shapeId1 = UUIDGener.getObjectId();
|
||||
//拿到基础结构
|
||||
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());
|
||||
newShape.put("id", shapeId1);
|
||||
@ -262,7 +270,6 @@ public class SynchronousOrgJob implements IJob {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设置画布大小
|
||||
DiagramsUtil.setDiagramHeightWidth(definition, elements);
|
||||
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) {
|
||||
return name == null ? "" : name;
|
||||
}
|
||||
@ -341,17 +345,17 @@ public class SynchronousOrgJob implements IJob {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取文件的下级文件的最大orderIndex
|
||||
* 在不同的资产库根节点(palId)都相同,增加资产库避免统计时错误
|
||||
*
|
||||
* @param palId
|
||||
* @param wsId
|
||||
* @return
|
||||
* @author sunlh
|
||||
*/
|
||||
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");
|
||||
return maxOrderIndex;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user