从泛微同步人员信息0.1
This commit is contained in:
parent
5ee1dae72a
commit
2da61bee0b
|
@ -0,0 +1,114 @@
|
||||||
|
package shkd.cosmic.cxkg.task;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import kd.bos.context.RequestContext;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.exception.KDException;
|
||||||
|
import kd.bos.permission.model.UserParam;
|
||||||
|
import kd.bos.schedule.executor.AbstractTask;
|
||||||
|
import kd.bos.service.ServiceFactory;
|
||||||
|
|
||||||
|
import kd.bos.servicehelper.QueryServiceHelper;
|
||||||
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import shkd.cosmic.cxkg.task.DTO.Query;
|
||||||
|
import shkd.cosmic.cxkg.task.DTO.QueryDTO;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class UserTaskImpl extends AbstractTask {
|
||||||
|
|
||||||
|
private static final int PAGESIZE = 20;
|
||||||
|
private int CURPAGE = 1;
|
||||||
|
private DynamicObjectCollection queryOrges;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
||||||
|
DynamicObjectCollection queryOrges = QueryServiceHelper.query("bos_adminorg",
|
||||||
|
"id,number,shkd_oaid", null);//查询星瀚系统部门集合
|
||||||
|
Map<Object, String> orgIds = new HashMap<Object, String>();//存放系统中已经存在的用户id集合
|
||||||
|
for (DynamicObject queryOrg : queryOrges) {
|
||||||
|
orgIds.put(queryOrg.getString("number"), (queryOrg.getLong("id") + ""));//存放已经存在的部门的id以及oaid
|
||||||
|
}
|
||||||
|
|
||||||
|
//bos_base_user_syn_weaver2kd
|
||||||
|
QueryDTO queryDTO = new QueryDTO();
|
||||||
|
queryDTO.setCurpage(4);
|
||||||
|
queryDTO.setPagesize(1);
|
||||||
|
Query query = new Query();
|
||||||
|
query.setQueryDTO(queryDTO);
|
||||||
|
String requestBody = JSON.toJSONString(query);
|
||||||
|
String jsonResponse = HttpRequest.post("http://" + "10.157.226.9:8088" + "/api/hrm/resful/getHrmUserInfoWithPage")
|
||||||
|
.body(requestBody).timeout(20000) //20s 超时
|
||||||
|
.execute().body();
|
||||||
|
JSONObject resultJson = JSONObject.parseObject(jsonResponse);
|
||||||
|
JSONArray dataList = resultJson.getJSONObject("data").getJSONArray("dataList");
|
||||||
|
|
||||||
|
List<UserParam> paramList = new ArrayList<>();
|
||||||
|
UserParam user = null;
|
||||||
|
for (int i = 0; i < dataList.size(); i++) {
|
||||||
|
JSONObject userData = dataList.getJSONObject(i);
|
||||||
|
System.out.println(i + "-----------" + userData);
|
||||||
|
user = new UserParam();
|
||||||
|
// user.setCustomUserId(123456780L);
|
||||||
|
Map<String, Object> dataMap = new HashMap<>();
|
||||||
|
dataMap.put("number", userData.getString("workcode")); //工号
|
||||||
|
dataMap.put("name", userData.getString("lastname")); // 姓名
|
||||||
|
dataMap.put("username", userData.getString("loginid")); //用户名
|
||||||
|
dataMap.put("usertype", "1");
|
||||||
|
dataMap.put("phone", userData.getString("mobile"));
|
||||||
|
dataMap.put("email", userData.getString("email"));
|
||||||
|
// dataMap.put("idcard", userData.getString("certificatenum")); //身份证
|
||||||
|
dataMap.put("birthday", userData.getString("birthday"));
|
||||||
|
dataMap.put("gender", userData.getString("sex")); //int
|
||||||
|
// dataMap.put("picturefield", ""); //头像
|
||||||
|
|
||||||
|
// 职位分录
|
||||||
|
List<Map<String, Object>> posList = new ArrayList<>();
|
||||||
|
Map<String, Object> entryentity = new HashMap<>();
|
||||||
|
// 设置部门ID
|
||||||
|
entryentity.put("dpt", orgIds.get(userData.getString("departmentcode"))); // 部门
|
||||||
|
entryentity.put("position", userData.getString("jobactivityname")); // 职位
|
||||||
|
//entryentity.put("isincharge", false); //负责人
|
||||||
|
//entryentity.put("ispartjob", false); //兼职
|
||||||
|
entryentity.put("superior", userData.getString("managerid")); // 直接上级
|
||||||
|
entryentity.put("seq", 1);
|
||||||
|
posList.add(entryentity);
|
||||||
|
|
||||||
|
dataMap.put("entryentity", posList);
|
||||||
|
user.setDataMap(dataMap);
|
||||||
|
user.setCustomUserId(userData.getInteger("id"));
|
||||||
|
// user.setId(293);
|
||||||
|
paramList.add(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务调用可以参照接口名,以下举例说明微服务调用方式
|
||||||
|
// IUserService userService = (IUserService) ServiceFactory.getService(IUserService.class);
|
||||||
|
//kd.bos.servicehelper.user.UserServiceHelper.addOrUpdate(List userList)
|
||||||
|
// userService.addOrUpdate(paramList);
|
||||||
|
UserServiceHelper.addOrUpdate(paramList);
|
||||||
|
// SaveServiceHelper.save();
|
||||||
|
|
||||||
|
|
||||||
|
List<UserParam> paramList2 = new ArrayList<>();
|
||||||
|
// 判断执行结果
|
||||||
|
for (UserParam result : paramList) {
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
//
|
||||||
|
System.out.println(result.getId() + "-----------" + result.getMsg());
|
||||||
|
paramList2.add(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue