dobe_comic8/main/java/shkd/repc/task/DobePersonOARealtionTask.java

72 lines
3.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package shkd.repc.task;
import com.alibaba.fastjson.JSONObject;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.exception.KDException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.schedule.executor.AbstractTask;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import shkd.utils.DobeDWUtils;
import shkd.utils.OAUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 金蝶人员与OA用户绑定后台任务插件 yxl 20250409
*/
public class DobePersonOARealtionTask extends AbstractTask implements Plugin {
private static final String entityName = "bos_user";//系统库 表名 t_sec_user
private static Log logger = LogFactory.getLog(DobePersonOARealtionTask.class);
//更新人员绑定OA成功的标记
private static final String updateFlag = "update t_sec_user set fk_qeug_flag='1' where fnumber=?;";
@Override
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
//查找未绑定成功的人员
QFilter dwFilter = new QFilter("source", QCP.equals, "dw");//来自数仓
QFilter flagFilter = new QFilter("qeug_flag", QCP.equals, "0");//未与OA绑定
QFilter enableFilter = new QFilter("enable", QCP.equals, "1");//用户未禁用
DynamicObject[] dos = BusinessDataServiceHelper.load(entityName,"id,number,name",new QFilter[]{dwFilter,enableFilter,flagFilter});
if(dos.length > 0){
logger.info("本次需要绑定用户个数"+dos.length);
DynamicObject userinfo;
List<DynamicObject> userinfos = new ArrayList<>(1);
String thirdPostjson;//OA绑定返回结果
JSONObject jsonObject;//OA绑定返回结果json对象
String billNo = "person-task-bid";
//获取token调用OA人员绑定接口
String oaToken = OAUtils.getOaToken(billNo);
for (int i = 0; i < dos.length; i++) {
userinfo = dos[i];
userinfos.clear();
userinfos.add(userinfo);
if (!DobeDWUtils.isEmpty(oaToken)) {
thirdPostjson = OAUtils.thirdpartyUser(userinfos, oaToken, billNo);
//处理OA绑定结果将处理成功的人员打上标记
if (!DobeDWUtils.isEmpty(thirdPostjson)) {
jsonObject = JSONObject.parseObject(thirdPostjson);
if(jsonObject.getBoolean("success")){
DB.update(DBRoute.of("sys"), updateFlag, new Object[]{userinfo.getString("number")});
}
}else{
logger.info("OA绑定返回值为空人员编号"+userinfo.getString("number"));
}
}
}
}else{
logger.info("现有用户已全部绑定,无需处理");
}
}
}