定时任务生成表及明细表

定时任务脚本内容,执行时间为5分钟一次,根据接口返回到中间表数据生成对应得单据

#include"baselibrary";
(function(){
    /*因为定时任务是通过线程跑,所以获取不到平台封装的前端方法,只能用源生写法获取方法*/
    /*企业域ID和软件ID可以将固定的ID值封装在函数库内调用,也可以直接写出来*/
    var domainid = "PfqrTkZ2khbjbU9w0Xc"; 
    var applicationId = "__DPDtViiBoQ60PcmB7kY";  
    var Process = getDocProcess(applicationId);
    var userProcess = createProcess("cn.myapps.authtime.user.service.UserProcess"); //获取用户业务处理类  
    var userVo = userProcess.login("jmcadmin", domainid); 
    var user = new Packages.cn.myapps.base.web.WebUser(userVo); 
    var userId = user.getId();
    var formProcess = new Packages.cn.myapps.designtime.form.service.FormDesignTimeServiceImpl();	//4.4或5.0版本
    var newForm = formProcess.doViewByFormName("MATERIAL_REQUISITION_FORM", applicationId); 		//创建零星领料单
    var newForm2 = formProcess.doViewByFormName("MATERIAL_REQUISITION_DETAIL", applicationId); 		//创建零星领料单明细
    var docProcess = getDocProcess(applicationId);
    var params = createParamsTable(); 
    var sql = "SELECT t.*,'"+domainid+"' domainid from (SELECT ID as item_ID, CREDATE as item_credate, PICKINGNO as item_pickingno, ENGINEERSAP as item_engineersap, ENGINEERNAME as item_engineername, SOURCE as item_source, WAREHOUSE as item_warehouse, USE as item_use, ISRDCAR as item_isrdcar, NODE as item_node, TYPE as item_type, PROJECTNO as item_projectno, PROJECTNAME as item_projectname, PROJECTMANAGER as item_projectmanager, PICKINGTIME as item_pickingtime, ITEMS as item_items FROM  OFFICE_MATERIAL_REQUISITION where 1 = 1 and PICKINGNO not in(SELECT ITEM_PICKINGNO from tlk_MATERIAL_REQUISITION_FORM)) t";
    var query = Process.queryBySQL(sql,domainid).datas;
    if(query!=null && query.size()>0){
        for(var iter = query.iterator();iter.hasNext();){
            var docs = iter.next();
            var jsonText = docs.getItemValueAsString("items");	//子表参数
            var newDoc = docProcess.doNew(newForm,user,params);                   
            var uuid = new Packages.cn.myapps.util.sequence.Sequence();                
            var uid = uuid.getSequence();                 
            var formid = "__mzIv2eGn3StLgBVGwOQ";                 
            var newDocid = uid + "--" + formid;                 
            newDoc.setId(newDocid);         
            newDoc.setAuthor(userId);                                                   
            newDoc.setIstmp(false);
            newDoc.addStringItem("pickingNo",docs.getItemValueAsString("pickingno")); 
            newDoc.addStringItem("SAP",docs.getItemValueAsString("engineersap"));
            newDoc.addDateItem("ApplyDate",docs.getItemValueAsDate("credate"));
            newDoc.addStringItem("Name",docs.getItemValueAsString("engineername"));
            newDoc.addStringItem("Source",docs.getItemValueAsString("source"));			                                      
            newDoc.addStringItem("Warehouse",docs.getItemValueAsString("warehouse"));			            
            newDoc.addStringItem("Purpose",docs.getItemValueAsString("use"));	
            newDoc.addStringItem("IsWholeVehicle",docs.getItemValueAsString("ISRDCAR"));			
            newDoc.addStringItem("Type",docs.getItemValueAsString("type"));	
            newDoc.addStringItem("projectNo",docs.getItemValueAsString("projectno"));	
            newDoc.addStringItem("projectName",docs.getItemValueAsString("projectname"));
            docProcess.doCreate(newDoc);
            if(jsonText!=""){
                var jsonArray = new Packages.org.json.JSONArray(jsonText);  
                for(var i = 0;i<jsonArray.length();i++){      
                    var jsonObject = jsonArray.getJSONObject(i);            
                    materialName = jsonObject.getString("materialName");
                    var newDoc2 = docProcess.doNew(newForm2,user,params);                   
                    var uuid2 = new Packages.cn.myapps.util.sequence.Sequence();                
                    var uid2 = uuid2.getSequence();                 
                    var formid2 = "__5ptSCIX9qwSCkPZHJ4v";
                    var newDocid2 = uid2 + "--" + formid2;                 
                    newDoc2.setId(newDocid2);
                    newDoc2.setParent(newDocid);
                    newDoc2.setAuthor(userId);                                                   
                    newDoc2.setIstmp(false);
                    newDoc2.addStringItem("materialName",jsonObject.getString("materialName")); 
                    newDoc2.addStringItem("materialCode",jsonObject.getString("materialCode")); 
                    newDoc2.addStringItem("unit",jsonObject.getString("unit")); 
                    newDoc2.addDoubleItem("Demand",jsonObject.getDouble("quantity")); 
                    var spType = jsonObject.getString("spType");				
                    if(spType!=null||spType!=""){
                        var Type ="spType";
                        spType = getTrueValueByShowValue(spType,Type);
                    }
                    newDoc2.addStringItem("spType",spType); 
                    newDoc2.addStringItem("Remarks",jsonObject.getString("remake")); 
                    docProcess.doCreate(newDoc2);  
                   }   
            }
      }
}
})();

发布者:chain,转转请注明出处:https://chain996.top/?p=4133

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-19 10:48
下一篇 2022-06-08 15:24

相关推荐

发表回复

您的电子邮箱地址不会被公开。