组织和人员同步数仓代码调整

This commit is contained in:
yuxueliang0813 2024-09-06 17:40:58 +08:00
parent f9af43a4d3
commit 7014c3b7f0
3 changed files with 27 additions and 8 deletions

View File

@ -50,7 +50,7 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
try { try {
response = client.newCall(request).execute(); response = client.newCall(request).execute();
resultData = response.body().string(); resultData = response.body().string();
log.info("组织接口返回结果:\n{}", resultData); // log.info("组织接口返回结果:\n{}", resultData);
} catch (IOException e) { } catch (IOException e) {
log.info(String.format("组织接口异常:%s", e.getMessage())); log.info(String.format("组织接口异常:%s", e.getMessage()));
throw new RuntimeException(e); throw new RuntimeException(e);
@ -72,7 +72,7 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
try { try {
response = client.newCall(request).execute(); response = client.newCall(request).execute();
resultData = response.body().string(); resultData = response.body().string();
log.info("组织接口返回结果:\n{}", resultData); // log.info("组织接口返回结果:\n{}", resultData);
} catch (IOException e) { } catch (IOException e) {
log.info(String.format("组织接口异常:%s", e.getMessage())); log.info(String.format("组织接口异常:%s", e.getMessage()));
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -8,10 +8,13 @@ import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.exception.KDException; import kd.bos.exception.KDException;
import kd.bos.logging.Log; import kd.bos.logging.Log;
import kd.bos.logging.LogFactory; import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter; import kd.bos.orm.query.QFilter;
import kd.bos.permission.model.UserParam; import kd.bos.permission.model.UserParam;
import kd.bos.schedule.executor.AbstractTask; import kd.bos.schedule.executor.AbstractTask;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.servicehelper.user.UserServiceHelper; import kd.bos.servicehelper.user.UserServiceHelper;
import kd.sdk.plugin.Plugin; import kd.sdk.plugin.Plugin;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
@ -47,7 +50,7 @@ public class DobeDWpersonTask extends AbstractTask implements Plugin {
try { try {
response = client.newCall(request).execute(); response = client.newCall(request).execute();
resultData = response.body().string(); resultData = response.body().string();
log.info("人员接口返回结果:\n{}", resultData); // log.info("人员接口返回结果:\n{}", resultData);
} catch (IOException e) { } catch (IOException e) {
log.info(String.format("人员接口异常:%s", e.getMessage())); log.info(String.format("人员接口异常:%s", e.getMessage()));
throw new RuntimeException(e); throw new RuntimeException(e);
@ -55,7 +58,8 @@ public class DobeDWpersonTask extends AbstractTask implements Plugin {
JSONObject json_body = JSON.parseObject(resultData); JSONObject json_body = JSON.parseObject(resultData);
//接口返回的数据进行了分页 //接口返回的数据进行了分页
int totalNum = json_body.getIntValue("totalNum");//分页-SQL查询总数据量 int totalNum = json_body.getIntValue("totalNum");//分页-SQL查询总数据量
handleUser(json_body); List<String> exprtNumber = new ArrayList<>();//存储此次入参的所有工号用于后续排除
handleUser(json_body,exprtNumber);
int queryCount = DobeDWUtils.getQueryCount(totalNum); int queryCount = DobeDWUtils.getQueryCount(totalNum);
if(queryCount > 1){ if(queryCount > 1){
//查询次数不止一次需要分页查询 //查询次数不止一次需要分页查询
@ -68,18 +72,32 @@ public class DobeDWpersonTask extends AbstractTask implements Plugin {
try { try {
response = client.newCall(request).execute(); response = client.newCall(request).execute();
resultData = response.body().string(); resultData = response.body().string();
log.info("人员接口返回结果:\n{}", resultData); // log.info("人员接口返回结果:\n{}", resultData);
} catch (IOException e) { } catch (IOException e) {
log.info(String.format("人员接口异常:%s", e.getMessage())); log.info(String.format("人员接口异常:%s", e.getMessage()));
throw new RuntimeException(e); throw new RuntimeException(e);
} }
json_body = JSON.parseObject(resultData); json_body = JSON.parseObject(resultData);
handleUser(json_body); handleUser(json_body,exprtNumber);
} }
} }
//处理离职人员
QFilter exprtFilter = new QFilter("number", QCP.not_in, exprtNumber);
QFilter dwFilter = new QFilter("source", QCP.equals, "dw");
DynamicObject[] dos = BusinessDataServiceHelper.load("bos_user","id,enable,isforbidden",new QFilter[]{exprtFilter.and(dwFilter)});
if(dos.length > 0){
DynamicObject currentUser = null;
for (int i = 0; i < dos.length; i++) {
currentUser = dos[i];
currentUser.set("enable", "0");//人员禁用
currentUser.set("isforbidden", true);//用户禁用
}
//保存数据直接保存入库不走操作校验
SaveServiceHelper.save(dos);
}
} }
private void handleUser(JSONObject json_body) { private void handleUser(JSONObject json_body,List<String> exprtNumber) {
//解析接口返回值与系统数据比较 //解析接口返回值与系统数据比较
JSONArray detailsJson = json_body.getJSONArray("data"); JSONArray detailsJson = json_body.getJSONArray("data");
String userID = null; String userID = null;
@ -110,6 +128,7 @@ public class DobeDWpersonTask extends AbstractTask implements Plugin {
log.info(String.format("人员入参为空异常:%s", json_body.toJSONString())); log.info(String.format("人员入参为空异常:%s", json_body.toJSONString()));
continue; continue;
} }
exprtNumber.add(number);
currentUser = QueryServiceHelper.queryOne(entityName,"id,number,name",new QFilter[]{new QFilter("number","=",number)}); currentUser = QueryServiceHelper.queryOne(entityName,"id,number,name",new QFilter[]{new QFilter("number","=",number)});
user = new UserParam();//常用或者重要的参数详情请查看参数对象UserParam user = new UserParam();//常用或者重要的参数详情请查看参数对象UserParam
dataMap = new HashMap<>(); dataMap = new HashMap<>();

View File

@ -70,7 +70,7 @@ public class DobeDWUtils {
ps.add(psjson); ps.add(psjson);
json_body.put("params",ps); json_body.put("params",ps);
}else{ }else{
json_body.put("params","[]"); json_body.put("params",new JSONArray());
} }
return RequestBody.create(ByteString.encodeUtf8(json_body.toJSONString()), MTJSON); return RequestBody.create(ByteString.encodeUtf8(json_body.toJSONString()), MTJSON);