130 lines
4.1 KiB
Java
130 lines
4.1 KiB
Java
package com.yili.org;
|
|
|
|
import java.sql.Connection;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.quartz.JobExecutionContext;
|
|
import org.quartz.JobExecutionException;
|
|
|
|
import com.actionsoft.bpms.bo.engine.BO;
|
|
import com.actionsoft.bpms.commons.database.RowMap;
|
|
import com.actionsoft.bpms.org.cache.OrgCache;
|
|
import com.actionsoft.bpms.org.model.DepartmentModel;
|
|
import com.actionsoft.bpms.schedule.IJob;
|
|
import com.actionsoft.bpms.server.UserContext;
|
|
import com.actionsoft.bpms.util.DBSql;
|
|
import com.actionsoft.bpms.util.UtilString;
|
|
import com.actionsoft.sdk.local.SDK;
|
|
import com.actionsoft.sdk.local.api.ORGAPI;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
/**
|
|
* 同步岗位
|
|
* @PackageName: com.awspaas.user.apps.yili.integration.job
|
|
* @ClassName: Integration
|
|
* @author: yujh
|
|
* @date: 2022/5/18 21:38
|
|
*/
|
|
public class SynPostJob2 implements IJob {
|
|
public static boolean init_flag = false;
|
|
public static String role_id = "";
|
|
|
|
|
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
init_flag = Boolean.parseBoolean(SDK.getJobAPI().getJobParameter(jobExecutionContext));
|
|
SDK.getLogAPI().consoleInfo(">>>>>job执行开始");
|
|
SDK.getLogAPI().consoleInfo(">>>>>init岗位执行开始");
|
|
long startTime = System.currentTimeMillis(); //获取开始时间
|
|
long endTime = System.currentTimeMillis(); //获取结束时间
|
|
System.out.println("程序运行时间:" + (endTime - startTime)/1000/60 + "min"); //输出程序运行时间
|
|
SDK.getLogAPI().consoleInfo(">>>>>init岗位执行结束");
|
|
SDK.getLogAPI().consoleInfo(">>>>>job执行结束");
|
|
OrgCache.reloadOrgCahce();
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 新增或更新岗位
|
|
*
|
|
* @param resultArray
|
|
* @param conn
|
|
*/
|
|
public static int createUser(JSONArray resultArray, Connection conn) {
|
|
List<RowMap> maps = DBSql.getMaps("SELECT * FROM BO_EU_ORG_POSTS");
|
|
for (RowMap rowMap : maps) {
|
|
String deptId = rowMap.getString("DEPTID");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
ORGAPI orgapi = SDK.getORGAPI();
|
|
int count = 0;
|
|
for (Object o : resultArray) {
|
|
BO bo = new BO();
|
|
JSONObject resultJson = JSONObject.parseObject(o.toString());
|
|
String postId = resultJson.getString("POSITION_NBR");//职位编码
|
|
String sqt = "SELECT ID FROM BO_EU_ORG_POSTS WHERE POSITION_NBR ='"+postId+"'";
|
|
if(UtilString.isEmpty(DBSql.getString(sqt))) {
|
|
String outerId = resultJson.getString("DEPTID");// 部门id
|
|
Map<String, Object> innerMap = resultJson.getInnerMap();
|
|
String sql = "SELECT ID FROM ORGDEPARTMENT WHERE OUTERID = '"+outerId+"'";
|
|
String deId = DBSql.getString(sql);
|
|
innerMap.remove("DEPTID");
|
|
innerMap.put("OUTERID", outerId);
|
|
if(UtilString.isNotEmpty(deId)) {
|
|
innerMap.put("DEPTID",deId);
|
|
DepartmentModel departmentById = orgapi.getDepartmentById(deId);
|
|
if (null!=departmentById) {
|
|
innerMap.put("DEPTNAME", departmentById.getName());
|
|
String parentDepartmentId = departmentById.getParentDepartmentId();
|
|
innerMap.put("DEPTPEID", parentDepartmentId);
|
|
if ("0".equals(parentDepartmentId)) {
|
|
innerMap.put("DEPTPENAME", "内蒙古伊利实业集团股份有限公司");
|
|
} else {
|
|
innerMap.put("DEPTPENAME", orgapi.getDepartmentById(parentDepartmentId).getName());
|
|
}
|
|
}
|
|
}
|
|
bo.setAll(innerMap);
|
|
SDK.getBOAPI().createDataBO("BO_EU_ORG_POSTS", bo, UserContext.fromUID("admin"));
|
|
}
|
|
|
|
}
|
|
return count;
|
|
|
|
}
|
|
|
|
/**
|
|
* 岗位是否存在
|
|
* @return
|
|
*/
|
|
public static String getPost(String postId, Connection conn){
|
|
String selectUserSql = " SELECT ID FROM ORGROLE WHERE ROLENO = ? ";
|
|
String userId = DBSql.getString(conn, selectUserSql, new Object[]{postId});
|
|
return userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 根据外部Id获取部门Id
|
|
*
|
|
* @return
|
|
*/
|
|
public static String getDeptIdByOuterId(String org_code, Connection conn) {
|
|
String selectDeptSql = " SELECT ID FROM ORGDEPARTMENT WHERE OUTERID = ? ";
|
|
String currentId = DBSql.getString(conn, selectDeptSql, new Object[]{org_code});
|
|
return currentId;
|
|
}
|
|
|
|
|
|
}
|