成本中心定时任务添加维护组织分录,人员非新增取消更新部门

This commit is contained in:
zengweihai 2024-06-27 17:59:37 +08:00
parent 4bb5f6f8ec
commit d716d27dd5
2 changed files with 97 additions and 48 deletions

View File

@ -24,6 +24,9 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
/**
* 定时任务更新成本中心和部门信息
*/
public class CostCenterTaskImpl extends AbstractTask { public class CostCenterTaskImpl extends AbstractTask {
private static Logger logger = LoggerFactory.getLogger(HrmDepartmentTaskImpl.class); private static Logger logger = LoggerFactory.getLogger(HrmDepartmentTaskImpl.class);
@ -55,8 +58,8 @@ public class CostCenterTaskImpl extends AbstractTask {
queryDTO.setCreated(time.toString()); queryDTO.setCreated(time.toString());
} }
//创建人员对应成本中心集合 //创建人员对应成本中心部门集合
HashMap<String, String> orgMap = new HashMap<>(); HashMap<String, HashMap<String,String>> orgMap = new HashMap<>();
JSONObject data = this.getOAUserData(query,oaUrl); JSONObject data = this.getOAUserData(query,oaUrl);
this.importOrgMap(orgMap,data);//填充人员数据人员编码成本中心编码 this.importOrgMap(orgMap,data);//填充人员数据人员编码成本中心编码
@ -81,8 +84,13 @@ public class CostCenterTaskImpl extends AbstractTask {
QFilter userQF = new QFilter("number", QCP.equals, key); QFilter userQF = new QFilter("number", QCP.equals, key);
DynamicObject bos_user = BusinessDataServiceHelper.loadSingle("bos_user", userQF.toArray());//查找星瀚对应人员 DynamicObject bos_user = BusinessDataServiceHelper.loadSingle("bos_user", userQF.toArray());//查找星瀚对应人员
if (bos_user != null){//当人员数据不为空时 if (bos_user != null){//当人员数据不为空时
String costNumber = orgMap.get(key);//对应的成本中心编码 boolean changeFlag = false;
QFilter costQFr = new QFilter("number", QCP.equals, costNumber); HashMap<String,String> valueMap = orgMap.get(key);//部门及成本中心数据集合
String departmentcode = valueMap.get("departmentcode");//部门编码
String costCenterNumber = valueMap.get("costCenterNumber");//成本中心编码
if (!"".equals(costCenterNumber)){
//对应的成本中心编码
QFilter costQFr = new QFilter("number", QCP.equals, costCenterNumber);
DynamicObject bos_costCenter = BusinessDataServiceHelper.loadSingle("bos_costcenter", costQFr.toArray()); DynamicObject bos_costCenter = BusinessDataServiceHelper.loadSingle("bos_costcenter", costQFr.toArray());
if (bos_costCenter != null){//当成本中心不为空时 if (bos_costCenter != null){//当成本中心不为空时
//获取用户的成本中心信息分录 //获取用户的成本中心信息分录
@ -99,9 +107,37 @@ public class CostCenterTaskImpl extends AbstractTask {
DynamicObject newObject = costEntity.addNew(); DynamicObject newObject = costEntity.addNew();
newObject.set("shkd_e_cost",bos_costCenter); newObject.set("shkd_e_cost",bos_costCenter);
newObject.set("shkd_e_source","B"); newObject.set("shkd_e_source","B");
OperationResult operationResult = OperationServiceHelper.executeOperate("save", "bos_user", new DynamicObject[]{bos_user}, option); changeFlag = true;
} }
} }
if (!"".equals(departmentcode)){
//对应的部门编码
QFilter deptQFr = new QFilter("number", QCP.equals, departmentcode);
DynamicObject bos_adminorg = BusinessDataServiceHelper.loadSingle("bos_adminorg", deptQFr.toArray());
if (bos_adminorg != null){//当行政组织不为空时
//获取人员的组织分录
DynamicObjectCollection entryentity = bos_user.getDynamicObjectCollection("entryentity");//组织分录
//首先遍历移除已存在的来源为泛微的数据
for (int i = 0;i < entryentity.size();i++){
DynamicObject dynamicObject = entryentity.get(i);
String shkd_deptsource = dynamicObject.getString("shkd_deptsource");
if ("2".equals(shkd_deptsource)){
int index = entryentity.indexOf(dynamicObject);
entryentity.remove(index);
}
}
DynamicObject newObject = entryentity.addNew();
newObject.set("dpt",bos_adminorg);//部门
newObject.set("position", valueMap.get("position"));//职位
newObject.set("isincharge",false);
newObject.set("ispartjob",false);
newObject.set("shkd_deptsource","2");
changeFlag = true;
}
}
OperationResult operationResult = OperationServiceHelper.executeOperate("save", "bos_user", new DynamicObject[]{bos_user}, option);
}
} }
} }
@ -122,17 +158,26 @@ public class CostCenterTaskImpl extends AbstractTask {
return data ; return data ;
} }
private void importOrgMap(HashMap<String, String> orgMap,JSONObject data){
/**
* 根据人员接口返回的数据填充创建人员对应成本中心部门集合
* sh
* @param orgMap
* @param data
*/
private void importOrgMap(HashMap<String, HashMap<String,String>> orgMap,JSONObject data){
JSONArray dataList = data.getJSONArray("dataList");//oa人员数据集合 JSONArray dataList = data.getJSONArray("dataList");//oa人员数据集合
for (int i = 0; i < dataList.size(); i++) { for (int i = 0; i < dataList.size(); i++) {//遍历
JSONObject userData = dataList.getJSONObject(i); JSONObject userData = dataList.getJSONObject(i);
JSONObject base_custom_data = userData.getJSONObject("base_custom_data"); HashMap<String, String> valueMap = new HashMap<>();
if (base_custom_data != null){ valueMap.put("departmentcode",userData.getString("departmentcode"));//设置部门信息
String field0 = base_custom_data.getString("field0"); valueMap.put("position", userData.getString("jobactivityname"));// 职位
if (!"".equals(field0)){ valueMap.put("superior", userData.getString("managerid"));//直接上级
orgMap.put(userData.getString("workcode"),field0); JSONObject base_custom_data = userData.getJSONObject("base_custom_data");//获取自定义数据包
} if (base_custom_data != null){//设置成本中心数据
} valueMap.put("costCenterNumber",base_custom_data.getString("field0"));
}
orgMap.put(userData.getString("workcode"), valueMap);
} }
} }
} }

View File

@ -190,17 +190,20 @@ public class UserTaskImpl extends AbstractTask {
} }
// 职位分 // 职位分
if(workid == null){//若人不存在则更新部门 if(workid == null){//若人不存在则更新部门
}
List<Map<String, Object>> posList = new ArrayList<>(); List<Map<String, Object>> posList = new ArrayList<>();
Map<String, Object> entryentity = new HashMap<>(); Map<String, Object> entryentity = new HashMap<>();
// 通过编码设置部门 // 通过编码设置部门
Map<String, Object> dptNumMap = new HashMap<>(); Map<String, Object> dptNumMap = new HashMap<>();
dptNumMap.put("number", userData.getString("departmentcode")); String departmentcode = userData.getString("departmentcode");
if (departmentcode.isEmpty()){
logger.info("人员:"+userData.getString("lastname")+",所属部门编码未携带,新增用户时会导致失败");
}
dptNumMap.put("number", departmentcode);
entryentity.put("dpt",dptNumMap ); // 部门 entryentity.put("dpt",dptNumMap ); // 部门
entryentity.put("position", userData.getString("jobactivityname")); // 职位 entryentity.put("position", userData.getString("jobactivityname")); // 职位
entryentity.put("isincharge", false); //负责人 entryentity.put("isincharge", false); //负责人
entryentity.put("ispartjob", false); //兼职 entryentity.put("ispartjob", false); //兼职
entryentity.put("shkd_deptsource","2");//来源设置为泛微
String managerId_oa = userData.getString("managerid");//获取上级人员id(oa) String managerId_oa = userData.getString("managerid");//获取上级人员id(oa)
Long managerId = userIds.get(managerId_oa);//直接上级id Long managerId = userIds.get(managerId_oa);//直接上级id
if (managerId != null){ if (managerId != null){
@ -213,6 +216,7 @@ public class UserTaskImpl extends AbstractTask {
entryentity.put("seq", 1); entryentity.put("seq", 1);
posList.add(entryentity); posList.add(entryentity);
dataMap.put("entryentity", posList); dataMap.put("entryentity", posList);
}
user.setDataMap(dataMap); user.setDataMap(dataMap);
paramList.add(user); paramList.add(user);
} }