岗位自动任务

This commit is contained in:
“wyx12345678” 2024-05-09 16:35:04 +08:00
parent eaf7329bf0
commit 373519684d
2 changed files with 104 additions and 39 deletions

View File

@ -0,0 +1,25 @@
package shkd.cosmic.cxkg.task.DTO;
import com.alibaba.fastjson.annotation.JSONField;
/**
* @projectName: shkd-cosmic-root-project
* @package: shkd.cosmic.cxkg.task.DTO
* @className: Query
* @author: wenyx
* @description: TODO
* @date: 2024/5/9 16:06
* @version: 1.0
*/
public class Query {
@JSONField(name = "params")
private QueryDTO queryDTO;
public QueryDTO getQueryDTO() {
return queryDTO;
}
public void setQueryDTO(QueryDTO queryDTO) {
this.queryDTO = queryDTO;
}
}

View File

@ -4,69 +4,109 @@ 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.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.exception.KDException;
import kd.bos.org.model.OrgParam;
import kd.bos.orm.ORM;
import kd.bos.orm.query.QFilter;
import kd.bos.schedule.executor.AbstractTask;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import shkd.cosmic.cxkg.task.DTO.Query;
import shkd.cosmic.cxkg.task.DTO.QueryDTO;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;
/**
* @projectName: shkd-cosmic-root-project
* @package: shkd.cosmic.cxkg.task
* @className: JobtitleTaskImpl
* @author: wenyx
* @description: TODO
* @description: 获取岗位信息的定时任务
* @date: 2024/5/7 16:09
* @version: 1.0
*/
public class JobtitleTaskImpl {
public class JobtitleTaskImpl extends AbstractTask {
private static int PAGESIZE = 20;
private static final int PAGESIZE = 20;
private int CURPAGE = 1;
public void getJobtitleInfo(){
/**
* 获取岗位信息
*/
public void getJobtitleInfo() {
try {
QFilter numberFilter = new QFilter("number", "=", "aurogp");
DynamicObject bosAdminorg = BusinessDataServiceHelper.loadSingle("bos_adminorg", new QFilter[]{numberFilter});
String oaUrl = System.getProperty("OaUrl");
//一次请求20条
QueryDTO queryDTO = new QueryDTO();
queryDTO.setCurpage(CURPAGE);
queryDTO.setPagesize(PAGESIZE);
String s = JSON.toJSONString(queryDTO);
String json = HttpRequest.post("http://"+oaUrl+"/api/hrm/resful/getHrmUserInfoWithPage")
.body(s)
.execute().body();
String oaUrl = System.getProperty("OaUrl");
JSONObject jsonObject = JSONObject.parseObject(json);
JSONObject data = jsonObject.getJSONObject("data");
JSONArray dataList = data.getJSONArray("dataList");
BigDecimal totalSize = jsonObject.getBigDecimal("totalSize");
BigDecimal sise = new BigDecimal(PAGESIZE);
//计算分多少页
BigDecimal page = totalSize.divide(sise, 0, RoundingMode.UP); //一共多少页
CURPAGE = page.intValue();
QueryDTO queryDTO = new QueryDTO();
queryDTO.setCurpage(1);
queryDTO.setPagesize(2);
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)
.execute().body();
queryDTO.setCurpage(CURPAGE);
queryDTO.setPagesize(PAGESIZE);
String s1 = JSON.toJSONString(queryDTO);
String jsonString = HttpRequest.post("http://"+oaUrl+"/api/hrm/resful/getHrmUserInfoWithPage")
.body(s1)
.execute().body();
JSONObject jsonObject = JSONObject.parseObject(jsonResponse);
JSONObject data = jsonObject.getJSONObject("data");
JSONArray dataList = data.getJSONArray("dataList");
BigDecimal totalSize = jsonObject.getBigDecimal("totalSize");
BigDecimal pageSizeDecimal = new BigDecimal(PAGESIZE);
JSONObject jsonObject1 = JSONObject.parseObject(jsonString);
JSONObject data1 = jsonObject.getJSONObject("data");
JSONArray dataList1 = data.getJSONArray("dataList");
// 遍历解析结果
for (int i = 0; i < dataList1.size(); i++) {
JSONObject item = dataList.getJSONObject(i);
String jobTitleName = item.getString("jobtitlename"); //岗位名称
String created = item.getString("created"); //创建时间
String modified = item.getString("modified"); //修改时间
String id = item.getString("id"); //岗位ID
// 计算总页数
// BigDecimal totalPages = totalSize.divide(pageSizeDecimal, 0, RoundingMode.UP);
// CURPAGE = totalPages.intValue();
//
// queryDTO.setCurpage(CURPAGE);
// String nextRequestBody = JSON.toJSONString(queryDTO);
//
// String nextJsonResponse = HttpRequest.post("http://" + oaUrl + "/api/hrm/resful/getHrmUserInfoWithPage")
// .body(nextRequestBody)
// .execute().body();
//
// JSONObject nextJsonObject = JSONObject.parseObject(nextJsonResponse);
// JSONObject nextData = nextJsonObject.getJSONObject("data");
// JSONArray nextDataList = nextData.getJSONArray("dataList");
// 遍历解析结果
for (int i = 0; i < dataList.size(); i++) {
OperateOption option = OperateOption.create();
JSONObject item = dataList.getJSONObject(i);
String jobTitleName = item.getString("jobtitlename");
String created = item.getString("created");
String modified = item.getString("modified");
String id = item.getString("id");
String jobTitleMark = item.getString("jobtitlemark");
String number = "0" + id;
ORM orm = ORM.create();
DynamicObject job = orm.newDynamicObject("bos_position");
job.set("name", jobTitleName);
job.set("dpt", bosAdminorg);
job.set("remarks", jobTitleMark);
job.set("enable", 1);
OperationServiceHelper.executeOperate("save", "bos_position", new DynamicObject[]{job}, option);
}
} catch (Exception e) {
// 处理异常
e.printStackTrace();
// 可根据实际情况选择是否抛出异常或记录日志
// throw new KDException("An error occurred while getting job title information.", e);
}
}
@Override
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
this.getJobtitleInfo();
}
}