首页 > 其他分享 >低代码计划任务的实现方法

低代码计划任务的实现方法

时间:2023-02-17 02:44:32浏览次数:36  
标签:转正 代码 ids date 任务 计划 estr employee id

低代码计划任务的实现方法

1、新建计划(如下图)

2、新建任务(如下图)

3、编写脚本(模板如下)

import meta from "svr-api/metadata"; //元数据、模型表相关API
import sys from 'svr-api/sys';
import db from 'svr-api/db';
import security from 'svr-api/security';

/**
 * 员工转正处理
 */
function main() {
    //获取数据源
    let ds = db.getDataSource('default', false);
    if (!ds) {
        return;
    }
    //获取转正申请信息 条件:审批通过,申请单类型=1转正,转正日期<=now,员工状态=试用
    let sqlstr ="select a.id,a.list_type,a.apply_id,a.apply_name,a.positive_date,b.instance_state,b.instance_result,c.employee_status "+
                "from human_resources.hum_employee_list_apply a "+
                "left join succezbi.szsys_4_flow_insts b on a.list_code = b.business_key "+
                "left join human_resources.hum_employee_info c on a.apply_id = c.employee_id "+
                "where a.list_type = 1 and a.positive_date <= date_format(now(), '%Y-%m-%d') "+
                    "and b.instance_state = 'finished' and b.instance_result = 'normal'"+
                    "and c.employee_status = 2";
    let data = ds.executeQuery(sqlstr);
    print("data----"+data);
    let len = data.length;
    if (len === 0) {
        return;
    }
    //取所有符合条件的员工ids
    let ids="(";
    for(let i=0;i<len;++i){
        if(i>0){
            ids+=",";
        }
        ids+="'"+data[i].apply_id+"'";
    }
    ids+=")";
    print("ids="+ids)
    //调试用,检验员工信息表中【员工id】 in ids
    let estr="select employee_id,employee_name,employee_status "+
                "from human_resources.hum_employee_info "+
                "where employee_id in "+ids;
    print("estr="+estr);
    let edata=ds.executeQuery(estr);
    //修改员工信息表相关转正信息:员工状态、转正日期、实际转正日期
    let ustr = "update human_resources.hum_employee_info "+
                "set employee_status = 1, positive_date = date_format(now(), '%Y-%m-%d'), fact_postive_date = date_format(now(), '%Y-%m-%d') "+
                "where employee_id in "+ids;
    // ds.executeUpdate(ustr)
}

4、关联计划(如下图)

      选择步骤1的计划名称

通过以上四个步骤计划任务就完成了

标签:转正,代码,ids,date,任务,计划,estr,employee,id
From: https://www.cnblogs.com/wishit/p/17128805.html

相关文章