流程人员同步中间表
parent
912b805911
commit
70680ee176
@ -0,0 +1,112 @@
|
|||||||
|
package com.customization.intercept;
|
||||||
|
|
||||||
|
import com.engine.core.cfg.annotation.CommandDynamicProxy;
|
||||||
|
import com.engine.core.interceptor.AbstractCommandProxy;
|
||||||
|
import com.engine.core.interceptor.Command;
|
||||||
|
import com.engine.workflow.cmd.workflowPath.node.operatorSetting.DoSaveOperatorGroupInfoCmd;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
|
import weaver.general.TimeUtil;
|
||||||
|
import weaver.interfaces.dito.comInfo.PropBean;
|
||||||
|
import weaver.workflow.request.RequestCheckUser;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lee
|
||||||
|
*/
|
||||||
|
@CommandDynamicProxy(target = DoSaveOperatorGroupInfoCmd.class, desc = "流程创建权限保存后将有权限人员插入到新表")
|
||||||
|
public class NodeSetCmdIntercept extends AbstractCommandProxy<Map<String, Object>> {
|
||||||
|
private final Log log = LogFactory.getLog(NodeSetCmdIntercept.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> execute(Command<Map<String, Object>> command) {
|
||||||
|
DoSaveOperatorGroupInfoCmd cmd = (DoSaveOperatorGroupInfoCmd) command;
|
||||||
|
String workflowIdString = (String) cmd.getParams().get("workflowId");
|
||||||
|
int workflowId = Integer.parseInt(workflowIdString);
|
||||||
|
Map<String, Object> result = nextExecute(cmd);
|
||||||
|
try {
|
||||||
|
//启动线程同步人员到中间表
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
log.info(workflowId + "-DoSaveOperatorGroupInfoCmd-start-" + TimeUtil.getCurrentTimeString());
|
||||||
|
|
||||||
|
String userStatus = PropBean.getUfPropValue("userStatus");
|
||||||
|
String tableName = PropBean.getUfPropValue("workflowCreatorTableName");
|
||||||
|
// String userStatus = "0,1,2,3";
|
||||||
|
// String tableName = "uf_workflowcreator";
|
||||||
|
|
||||||
|
RecordSet rs = new RecordSet();
|
||||||
|
//先查出该流程已经插入的人员
|
||||||
|
String createrSql = "SELECT userid FROM " + tableName + " where workflowid=" + workflowId;
|
||||||
|
HashSet<Integer> existUserSet = new HashSet<>();
|
||||||
|
rs.execute(createrSql);
|
||||||
|
while (rs.next()) {
|
||||||
|
existUserSet.add(rs.getInt("userid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询所有人员sql
|
||||||
|
String userSql = "SELECT id FROM HrmResource WHERE status IN (" + userStatus + ")";
|
||||||
|
//插入中间表sql
|
||||||
|
String insertSql = "INSERT INTO " + tableName + " (workflowid,userid)VALUES(?,?)";
|
||||||
|
|
||||||
|
HashSet<Integer> userIdSet = new HashSet<>();
|
||||||
|
rs.execute(userSql);
|
||||||
|
while (rs.next()) {
|
||||||
|
userIdSet.add(rs.getInt("id"));
|
||||||
|
}
|
||||||
|
//有权限创建该流程的人员集合
|
||||||
|
HashSet<Integer> rightUserSet = new HashSet<>();
|
||||||
|
RequestCheckUser rcu = new RequestCheckUser();
|
||||||
|
userIdSet.forEach(userId -> {
|
||||||
|
rcu.resetParameter();
|
||||||
|
rcu.setUserid(userId);
|
||||||
|
rcu.setWorkflowid(workflowId);
|
||||||
|
rcu.setLogintype("1");
|
||||||
|
try {
|
||||||
|
rcu.checkUser();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
int hasRight = rcu.getHasright();
|
||||||
|
if (1 == hasRight) {
|
||||||
|
rightUserSet.add(userId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//本次需要删除的中间表人员
|
||||||
|
HashSet<Integer> set = new HashSet<>(existUserSet);
|
||||||
|
HashSet<Integer> set2 = new HashSet<>(existUserSet);
|
||||||
|
set.retainAll(rightUserSet);
|
||||||
|
set2.removeAll(set);
|
||||||
|
String deleteSql = "delete from " + tableName + " where workflowid=? and userid=?";
|
||||||
|
for (Integer creator : set2) {
|
||||||
|
rs.executeUpdate(deleteSql, workflowId, creator);
|
||||||
|
}
|
||||||
|
|
||||||
|
//集合移除已经插入的人员,避免重复插入
|
||||||
|
rightUserSet.removeAll(existUserSet);
|
||||||
|
List<List> batchList = new ArrayList<>();
|
||||||
|
for (Integer creator : rightUserSet) {
|
||||||
|
List<Integer> list = new ArrayList<>();
|
||||||
|
list.add(workflowId);
|
||||||
|
list.add(creator);
|
||||||
|
batchList.add(list);
|
||||||
|
}
|
||||||
|
rs.executeBatchSql(insertSql, batchList);
|
||||||
|
log.info(workflowId + "-DoSaveOperatorGroupInfoCmd-end-" + TimeUtil.getCurrentTimeString());
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("DoSaveOperatorGroupInfoCmd-error-" + e.getMessage());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue