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

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.util.*;
/**
* 定时任务更新成本中心和部门信息
*/
public class CostCenterTaskImpl extends AbstractTask {
private static Logger logger = LoggerFactory.getLogger(HrmDepartmentTaskImpl.class);
@ -55,8 +58,8 @@ public class CostCenterTaskImpl extends AbstractTask {
queryDTO.setCreated(time.toString());
}
//创建人员对应成本中心集合
HashMap<String, String> orgMap = new HashMap<>();
//创建人员对应成本中心部门集合
HashMap<String, HashMap<String,String>> orgMap = new HashMap<>();
JSONObject data = this.getOAUserData(query,oaUrl);
this.importOrgMap(orgMap,data);//填充人员数据人员编码成本中心编码
@ -81,26 +84,59 @@ public class CostCenterTaskImpl extends AbstractTask {
QFilter userQF = new QFilter("number", QCP.equals, key);
DynamicObject bos_user = BusinessDataServiceHelper.loadSingle("bos_user", userQF.toArray());//查找星瀚对应人员
if (bos_user != null){//当人员数据不为空时
String costNumber = orgMap.get(key);//对应的成本中心编码
QFilter costQFr = new QFilter("number", QCP.equals, costNumber);
DynamicObject bos_costCenter = BusinessDataServiceHelper.loadSingle("bos_costcenter", costQFr.toArray());
if (bos_costCenter != null){//当成本中心不为空时
//获取用户的成本中心信息分录
DynamicObjectCollection costEntity = bos_user.getDynamicObjectCollection("shkd_costentity");
//首先遍历移除已存在的来源为泛微的数据
for (int i = 0;i < costEntity.size();i++){
DynamicObject dynamicObject = costEntity.get(i);
String shkd_e_source = dynamicObject.getString("shkd_e_source");
if ("B".equals(shkd_e_source)){
int index = costEntity.indexOf(dynamicObject);
costEntity.remove(index);
boolean changeFlag = false;
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());
if (bos_costCenter != null){//当成本中心不为空时
//获取用户的成本中心信息分录
DynamicObjectCollection costEntity = bos_user.getDynamicObjectCollection("shkd_costentity");
//首先遍历移除已存在的来源为泛微的数据
for (int i = 0;i < costEntity.size();i++){
DynamicObject dynamicObject = costEntity.get(i);
String shkd_e_source = dynamicObject.getString("shkd_e_source");
if ("B".equals(shkd_e_source)){
int index = costEntity.indexOf(dynamicObject);
costEntity.remove(index);
}
}
DynamicObject newObject = costEntity.addNew();
newObject.set("shkd_e_cost",bos_costCenter);
newObject.set("shkd_e_source","B");
changeFlag = true;
}
DynamicObject newObject = costEntity.addNew();
newObject.set("shkd_e_cost",bos_costCenter);
newObject.set("shkd_e_source","B");
OperationResult operationResult = OperationServiceHelper.executeOperate("save", "bos_user", new DynamicObject[]{bos_user}, option);
}
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 ;
}
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人员数据集合
for (int i = 0; i < dataList.size(); i++) {
for (int i = 0; i < dataList.size(); i++) {//遍历
JSONObject userData = dataList.getJSONObject(i);
JSONObject base_custom_data = userData.getJSONObject("base_custom_data");
if (base_custom_data != null){
String field0 = base_custom_data.getString("field0");
if (!"".equals(field0)){
orgMap.put(userData.getString("workcode"),field0);
}
HashMap<String, String> valueMap = new HashMap<>();
valueMap.put("departmentcode",userData.getString("departmentcode"));//设置部门信息
valueMap.put("position", userData.getString("jobactivityname"));// 职位
valueMap.put("superior", userData.getString("managerid"));//直接上级
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,29 +190,33 @@ public class UserTaskImpl extends AbstractTask {
}
// 职位分
if(workid == null){//若人不存在则更新部门
}
List<Map<String, Object>> posList = new ArrayList<>();
Map<String, Object> entryentity = new HashMap<>();
// 通过编码设置部门
Map<String, Object> dptNumMap = new HashMap<>();
dptNumMap.put("number", userData.getString("departmentcode"));
entryentity.put("dpt",dptNumMap ); // 部门
entryentity.put("position", userData.getString("jobactivityname")); // 职位
entryentity.put("isincharge", false); //负责人
entryentity.put("ispartjob", false); //兼职
String managerId_oa = userData.getString("managerid");//获取上级人员id(oa)
Long managerId = userIds.get(managerId_oa);//直接上级id
if (managerId != null){
entryentity.put("superior", managerId); // 赋值直接上级
}else {
if (!"".equals(managerId_oa)){//当上级人员idoa存在且未在星瀚系统检索成功时修改参数flag,接口将重新构造人员类更新数据
flag = true;
List<Map<String, Object>> posList = new ArrayList<>();
Map<String, Object> entryentity = new HashMap<>();
// 通过编码设置部门
Map<String, Object> dptNumMap = new HashMap<>();
String departmentcode = userData.getString("departmentcode");
if (departmentcode.isEmpty()){
logger.info("人员:"+userData.getString("lastname")+",所属部门编码未携带,新增用户时会导致失败");
}
dptNumMap.put("number", departmentcode);
entryentity.put("dpt",dptNumMap ); // 部门
entryentity.put("position", userData.getString("jobactivityname")); // 职位
entryentity.put("isincharge", false); //负责人
entryentity.put("ispartjob", false); //兼职
entryentity.put("shkd_deptsource","2");//来源设置为泛微
String managerId_oa = userData.getString("managerid");//获取上级人员id(oa)
Long managerId = userIds.get(managerId_oa);//直接上级id
if (managerId != null){
entryentity.put("superior", managerId); // 赋值直接上级
}else {
if (!"".equals(managerId_oa)){//当上级人员idoa存在且未在星瀚系统检索成功时修改参数flag,接口将重新构造人员类更新数据
flag = true;
}
}
entryentity.put("seq", 1);
posList.add(entryentity);
dataMap.put("entryentity", posList);
}
entryentity.put("seq", 1);
posList.add(entryentity);
dataMap.put("entryentity", posList);
user.setDataMap(dataMap);
paramList.add(user);
}