|
管理员大大,定时任务给指定部门的员工推送消息,每天执行一次的话如果待办人今天未登录,第二天可以收到消息吗,PC端,我写的逻辑是这样的
/********************
this.entityManager; //实体管理器
this.applications; //访问系统内服务
this.organization; //组织访问
this.org; //组织快速访问方法
this.service; ///webSerivces客户端
*******************/
print("========转正待办推送服务扫描开始========");
// print(personList);
// 获取人员登记完成视图中的所有数据已提交数据
function getJobId(){
//serviceRoot 服务根
//path 路径
//string 数据字符串,json转字符串可以用 JSON.stringify( json )
var json = {filterList: []};
var resp = applications.putQuery( "x_query_assemble_surface", "/jaxrs/view/7b71c72a-2866-4a13-86c9-7d5eac89383a/bundle", JSON.stringify(json) );
// print( resp.toString() );
var result = JSON.parse( resp.toString() );
return result.data.valueList;
}
// 获取视图数据
function getViewData(){
var idList = getJobId();
var json = {filterList: [], bundleList : idList };
var resp = applications.putQuery( "x_query_assemble_surface", "/jaxrs/view/7b71c72a-2866-4a13-86c9-7d5eac89383a/execute", JSON.stringify(json) );
// print( resp.toString() );
var result = JSON.parse( resp.toString() );
return result.data.grid;
}
//获取数据字典数据
function getDictData(dictId,applicationId){
var data = {};
var serviceRoot = "x_processplatform_assemble_surface";
var path = "applicationdict/"+dictId+"/application/"+applicationId;
var resp = applications.getQuery( serviceRoot, path );
var json = JSON.parse( resp.toString() );
var result = {};
if(json.type == "success" && json.data){
result = json.data;
}
return result;
}
// 获取某个人所在的组织
function getCurrentUserInOrg(name) {
var data = {};
data["personList"] = [name];
var string = JSON.stringify(data);
var apps = this.applications;
var serviceRoot = "x_organization_assemble_express";
var path = "unit/list/person";
var resp = apps.postQuery( serviceRoot, path , string);
var json = JSON.parse( resp.toString() );
var result = {};
if(json.type == "success" && json.data) {
result = json.data;
}
return result;
}
// 发送消息
function sendMessage(type, person, title, body) {
var data = {};
data["type"] = type;
data["person"] = person;
data["title"] = title;
data["body"] = body;
var string = JSON.stringify(data);
var apps = this.applications;
var serviceRoot = "x_message_assemble_communicate";
var path = "ws";
var resp = apps.postQuery( serviceRoot, path , string);
var json = JSON.parse( resp.toString() );
var result = {};
if(json.type == "success" && json.data) {
result = json.data;
print("发消息结果 : " + result);
}
return result;
}
for(var i = 0; i < getViewData().length; i++) {
// 获取开始时间
var start = getViewData()[i].data.PROBATION_PERIOD_START;
// 获取结束时间
var end = getViewData()[i].data.PROBATION_PERIOD_END;
// 获取待转正人姓名
var positivePersonName = getViewData()[i].data.subject;
// // 获取拟稿人
// var person = getViewData()[i].data.PERSON;
var startDate = new Date(Date.parse(start.replace(/-/g, "/")));
var endDate = new Date(Date.parse(end.replace(/-/g, "/")));
// 当前时间
var now = new Date();
var period = endDate - now;
period = period / 1000 / 60 / 60 / 24;
period = period.toFixed(0);
print(period);
// 获取拟稿人组织
var result = getCurrentUserInOrg(person);
var unitArr = result.unitList;
// 获取消息发送配置的岗位
// 查询数据字典
var dict = getDictData("2fed4681-94f2-4e3f-88f7-940d16a60f73", "5214c863-df98-4ff4-914b-a35f3126f923");
var positiveOrg = dict.data.positiveOrg;
// print(getViewData()[i].data.IS_COMPLETED == true);
// 获取字典中配置的组织下的所有成员
if(getViewData()[i].data.IS_COMPLETED == true && period == 14) { // 已提交的快到期的
print("-----出现匹配人员------");
for(var j = 0; j < positiveOrg.length; j++) {
print("获取人员组织: " + positiveOrg[j]);
var personList = this.org.listPersonWithUnit(positiveOrg[j]);
for(k = 0; k < personList.length; k++) {
var person = personList[k].distinguishedName;
print("需要发送消息人员:" + person);
sendMessage("task_press", person, positivePersonName + " 距离转正日期还有两周,请注意", {applicationName : "人员管理", processName : "外部人员转正"});
print("给 " + person + " 发送消息成功");
}
}
}
}
print("========转正待办推动服务扫描结束========");
发送消息用的是sendMessage方法,麻烦帮忙看一下,是不是会出现每天执行一次,如果员工未登录,就不会收到消息的情况,如果有的话,能不能给推荐一下如果要实现这个需求的话有什么好的方法吗 |
|