查看: 2607|回复: 1

定时任务推送消息

升级   33.2%

116

主题

108

回帖

666

积分

高级会员

Rank: 4

积分
666
发表于 2021-6-4 09:19:15 | 显示全部楼层 |阅读模式
管理员大大,定时任务给指定部门的员工推送消息,每天执行一次的话如果待办人今天未登录,第二天可以收到消息吗,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方法,麻烦帮忙看一下,是不是会出现每天执行一次,如果员工未登录,就不会收到消息的情况,如果有的话,能不能给推荐一下如果要实现这个需求的话有什么好的方法吗
回复

使用道具 举报

升级   100%

138

主题

1万

回帖

3万

积分

超级版主

Rank: 8Rank: 8

积分
37299
发表于 2021-6-7 15:54:26 | 显示全部楼层
您是问这个是不是每天定时执行吗?
定时执行,您设置固定的一个执行时间即可
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

联系客服 关注微信 下载APP 返回顶部 返回列表
viewthread