岗位自动任务
This commit is contained in:
parent
eaf7329bf0
commit
373519684d
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,69 +4,109 @@ import cn.hutool.http.HttpRequest;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.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 shkd.cosmic.cxkg.task.DTO.QueryDTO;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @projectName: shkd-cosmic-root-project
|
* @projectName: shkd-cosmic-root-project
|
||||||
* @package: shkd.cosmic.cxkg.task
|
* @package: shkd.cosmic.cxkg.task
|
||||||
* @className: JobtitleTaskImpl
|
* @className: JobtitleTaskImpl
|
||||||
* @author: wenyx
|
* @author: wenyx
|
||||||
* @description: TODO
|
* @description: 获取岗位信息的定时任务
|
||||||
* @date: 2024/5/7 16:09
|
* @date: 2024/5/7 16:09
|
||||||
* @version: 1.0
|
* @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;
|
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");
|
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();
|
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(json);
|
QueryDTO queryDTO = new QueryDTO();
|
||||||
JSONObject data = jsonObject.getJSONObject("data");
|
queryDTO.setCurpage(1);
|
||||||
JSONArray dataList = data.getJSONArray("dataList");
|
queryDTO.setPagesize(2);
|
||||||
BigDecimal totalSize = jsonObject.getBigDecimal("totalSize");
|
Query query = new Query();
|
||||||
BigDecimal sise = new BigDecimal(PAGESIZE);
|
query.setQueryDTO(queryDTO);
|
||||||
//计算分多少页
|
String requestBody = JSON.toJSONString(query);
|
||||||
BigDecimal page = totalSize.divide(sise, 0, RoundingMode.UP); //一共多少页
|
String jsonResponse = HttpRequest.post("http://" + "10.157.226.9:8088" + "/api/hrm/resful/getHrmUserInfoWithPage")
|
||||||
CURPAGE = page.intValue();
|
.body(requestBody)
|
||||||
|
.execute().body();
|
||||||
|
|
||||||
queryDTO.setCurpage(CURPAGE);
|
JSONObject jsonObject = JSONObject.parseObject(jsonResponse);
|
||||||
queryDTO.setPagesize(PAGESIZE);
|
JSONObject data = jsonObject.getJSONObject("data");
|
||||||
String s1 = JSON.toJSONString(queryDTO);
|
JSONArray dataList = data.getJSONArray("dataList");
|
||||||
String jsonString = HttpRequest.post("http://"+oaUrl+"/api/hrm/resful/getHrmUserInfoWithPage")
|
BigDecimal totalSize = jsonObject.getBigDecimal("totalSize");
|
||||||
.body(s1)
|
BigDecimal pageSizeDecimal = new BigDecimal(PAGESIZE);
|
||||||
.execute().body();
|
|
||||||
|
|
||||||
JSONObject jsonObject1 = JSONObject.parseObject(jsonString);
|
// 计算总页数
|
||||||
JSONObject data1 = jsonObject.getJSONObject("data");
|
// BigDecimal totalPages = totalSize.divide(pageSizeDecimal, 0, RoundingMode.UP);
|
||||||
JSONArray dataList1 = data.getJSONArray("dataList");
|
// CURPAGE = totalPages.intValue();
|
||||||
// 遍历解析结果
|
//
|
||||||
for (int i = 0; i < dataList1.size(); i++) {
|
// queryDTO.setCurpage(CURPAGE);
|
||||||
JSONObject item = dataList.getJSONObject(i);
|
// String nextRequestBody = JSON.toJSONString(queryDTO);
|
||||||
String jobTitleName = item.getString("jobtitlename"); //岗位名称
|
//
|
||||||
String created = item.getString("created"); //创建时间
|
// String nextJsonResponse = HttpRequest.post("http://" + oaUrl + "/api/hrm/resful/getHrmUserInfoWithPage")
|
||||||
String modified = item.getString("modified"); //修改时间
|
// .body(nextRequestBody)
|
||||||
String id = item.getString("id"); //岗位ID
|
// .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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue