爱游戏

 
 注册成为天翎用户
热搜:
查看: 622|回复: 0

【5.0】【定时任务】定时任务生成主子表单据-爱游戏

[复制链接]
chain 发表于 2022-1-22 11:04:53 | |
业务场景:由用户自己的第三方系统发起订单,订单通过接口生成数据到中间表,而平台根据中间表的单号做匹配,没有的数据则在平台中生成。用定时任务的方法,每十分钟执行一次。

参考脚本如下
  1. #include"baselibrary";
  2. (function(){
  3.         /*因为定时任务是通过线程跑,所以获取不到平台封装的前端方法,只能用源生写法获取方法*/
  4.         /*企业域id和软件id可以将固定的id值封装在函数库内调用,也可以直接写出来*/
  5.        
  6.         var domainid = "pfqrtkz2khbjbu9w0xc";
  7.         var applicationid = "__dpdtviiboq60pcmb7ky";  
  8.         var process = getdocprocess(applicationid);
  9.        
  10.         var userprocess = createprocess("cn.myapps.authtime.user.service.userprocess"); //获取用户业务处理类  
  11.         var uservo = userprocess.login("jmcadmin", domainid);
  12.         var user = new packages.cn.myapps.base.web.webuser(uservo);
  13.         var userid = user.getid();
  14.        
  15.         var formprocess = new packages.cn.myapps.designtime.form.service.formdesigntimeserviceimpl();        //4.4或5.0版本
  16.         var newform = formprocess.doviewbyformname("material_requisition_form", applicationid);                 //创建零星领料单
  17.         var newform2 = formprocess.doviewbyformname("material_requisition_detail", applicationid);                 //创建零星领料单明细
  18.        
  19.            var docprocess = getdocprocess(applicationid);               
  20.            var params = createparamstable();
  21.        
  22.         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";
  23.         var query = process.querybysql(sql,domainid).datas;
  24.        
  25.         if(query!=null && query.size()>0){
  26.                    for(var iter = query.iterator();iter.hasnext();){
  27.                         var docs = iter.next();
  28.                         var jsontext = docs.getitemvalueasstring("items");        //子表参数
  29.                        
  30.                            var newdoc = docprocess.donew(newform,user,params);                  
  31.                            var uuid = new packages.cn.myapps.util.sequence.sequence();               
  32.                            var uid = uuid.getsequence();                 
  33.                            var formid = "__mziv2egn3stlgbvgwoq";                 
  34.                            var newdocid = uid "--" formid;                 
  35.       
  36.                            newdoc.setid(newdocid);         
  37.                            newdoc.setauthor(userid);                                                   
  38.                            newdoc.setistmp(false);
  39.                        
  40.                            newdoc.addstringitem("pickingno",docs.getitemvalueasstring("pickingno"));
  41.                         newdoc.addstringitem("sap",docs.getitemvalueasstring("engineersap"));
  42.                         newdoc.adddateitem("applydate",docs.getitemvalueasdate("credate"));
  43.                         newdoc.addstringitem("name",docs.getitemvalueasstring("engineername"));
  44.                         newdoc.addstringitem("source",docs.getitemvalueasstring("source"));
  45.                         newdoc.addstringitem("warehouse",docs.getitemvalueasstring("warehouse"));
  46.                         newdoc.addstringitem("purpose",docs.getitemvalueasstring("use"));
  47.                         newdoc.addstringitem("iswholevehicle",docs.getitemvalueasstring("isrdcar"));                       
  48.                         newdoc.addstringitem("type",docs.getitemvalueasstring("type"));

  49.                         newdoc.addstringitem("projectno",docs.getitemvalueasstring("projectno"));
  50.                         newdoc.addstringitem("projectname",docs.getitemvalueasstring("projectname"));
  51.                         docprocess.docreate(newdoc);
  52.                         if(jsontext!=""){
  53.                                 var jsonarray = new packages.org.json.jsonarray(jsontext);  
  54.                                 for(var i = 0;i
  55.                                         var jsonobject = jsonarray.getjsonobject(i);            
  56.                                         materialname = jsonobject.getstring("materialname");

  57.                                         var newdoc2 = docprocess.donew(newform2,user,params);                  
  58.                                         var uuid2 = new packages.cn.myapps.util.sequence.sequence();               
  59.                                         var uid2 = uuid2.getsequence();                 
  60.                                         var formid2 = "__5ptscix9qwsckpzhj4v";

  61.                                         var newdocid2 = uid2 "--" formid2;                 

  62.                                         newdoc2.setid(newdocid2);
  63.                                         newdoc2.setparent(newdocid);
  64.                                         newdoc2.setauthor(userid);                                                   
  65.                                         newdoc2.setistmp(false);

  66.                                         newdoc2.addstringitem("materialname",jsonobject.getstring("materialname"));
  67.                                         newdoc2.addstringitem("materialcode",jsonobject.getstring("materialcode"));
  68.                                         newdoc2.addstringitem("unit",jsonobject.getstring("unit"));
  69.                                         newdoc2.adddoubleitem("demand",jsonobject.getdouble("quantity"));


  70.                                         var sptype = jsonobject.getstring("sptype");                               
  71.                                         if(sptype!=null||sptype!=""){
  72.                                                 var type ="sptype";
  73.                                                 sptype = gettruevaluebyshowvalue(sptype,type);
  74.                                         }

  75.                                         newdoc2.addstringitem("sptype",sptype);
  76.                                         newdoc2.addstringitem("remarks",jsonobject.getstring("remake"));
  77.                                         docprocess.docreate(newdoc2);  
  78.                                 }   
  79.                         }
  80.                 }
  81.         }
  82. })();
复制代码


您需要登录后才可以回帖 登录 | 注册成为天翎用户

本版积分规则

||爱游戏 ( )

gmt 8, 2023-9-30 12:47

powered by x3.4

爱游戏 copyright © 2001-2020, tencent cloud.

返回列表
网站地图