<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<activity id="__1XRaKFr4fPerqDeYOu4">
  <name>定时任务分账</name>
  <parentId>__TguP7KZtUDBVC1gHr6k</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <type>13</type>
  <onActionFlow></onActionFlow>
  <onActionPrint></onActionPrint>
  <colorType>default</colorType>
  <beforeActionScript><![CDATA[
(function(){
  var process = getDocumentProcess();
  var examInfoDomainId=""
  var examInfoId=""
  var examInfoSql="select id,domainid from tlk_system_exam_info where item_exam_pay_over='0' and ITEM_COMPUTERENDDATE<NOW() ORDER BY LASTMODIFIED limit 1 "
  var examInfodatas = queryByDSName("tms",examInfoSql);
  if(examInfodatas.size()>0){
    for(var examInfoiterator = examInfodatas.iterator();examInfoiterator.hasNext();){
      var examInfomap1 = examInfoiterator.next();//取值
      var examInfoDomainId= examInfomap1.get("domainid");
      var examInfoId = examInfomap1.get("id");
    }
    if(isNotNull(examInfoDomainId)&&isNotNull(examInfoId)){
      var checkExamPersonSql="select 1 from tlk_system_exam_person where item_signin='0' and item_examid='"+examInfoId+"' "
      var checkExamPersondatas = queryByDSName("tms",checkExamPersonSql);
      if(!checkExamPersondatas.size()>0){

        var examPersonSql="select item_applyid from tlk_system_exam_person where item_signin='1' and item_examid='"+examInfoId+"' "
        var examPersondatas = queryByDSName("tms",examPersonSql);


        if(examPersondatas.size()>0){
          //查出所有的报名记录id
          var applyIds="('";
          for(var examPersoniterator = examPersondatas.iterator();examPersoniterator.hasNext();){
            var examPersonmap1 = examPersoniterator.next();//取值
            var applyid= examPersonmap1.get("item_applyid");
            if(examPersoniterator.hasNext()){
              applyIds+=applyid+"','"
            }else {
              applyIds+=applyid+"')"
            }
          }
          //查出所有的订单记录id
          var ordersql="select item_orderid from tlk_qualify_person_apply where id in "+applyIds
          var orderdatas = queryByDSName("tms",ordersql);
          if(orderdatas.size()>0){
            //查出所有的报名记录id
            var orderIds="('";
            for(var orderiterator = orderdatas.iterator();orderiterator.hasNext();){
              var ordermap1 = orderiterator.next();//取值
              var orderid= ordermap1.get("item_orderid");
              if(orderiterator.hasNext()){
                orderIds+=orderid+"','"
              }else {
                orderIds+=orderid+"')"
              }
            }
            //查出所有的订单号
            var orderNoSql="select item_order_no from tlk_learn_order_person where id in "+orderIds+" and ITEM_ORDER_NO_REFUND_STATUS='3' and item_order_no!='' "
            var orderNodatas = queryByDSName("tms",orderNoSql);
            if(orderNodatas.size()>0){
              var orderNoIds="";
              for(var orderNoiterator = orderNodatas.iterator();orderNoiterator.hasNext();){
                var orderNomap1 = orderNoiterator.next();//取值
                var order_no= orderNomap1.get("item_order_no");
                if(orderNoiterator.hasNext()){
                  orderNoIds+=order_no+","
                }else {
                  orderNoIds+=order_no
                }
              }
              //开始交易
              var bodyMap = new Packages.java.util.HashMap(); //创建指定类对象
              var orgdomainid = 'org_'+examInfoDomainId;
              var accessToken = Packages.cn.myapps.common.util.Security.getToken(orgdomainid);
              var shopUrl = getSettingValueByCategoryAndKeyWithExpired("商城url", "shopUrl", 60);
              bodyMap.put("virtualOrderNos",orderNoIds)
              bodyMap.put("sourceId",examInfoId)
              try{
                var url=shopUrl+"/api/front/order/health/create"
                var logformService = getFormProcess();
                var logsubform = logformService.doView("__njIBinWdtOwylDk4AE6");
                var logdoc = process.doNew(logsubform,getWebUser(),createParamsTable());
                var strBody = Packages.com.alibaba.fastjson.JSON.toJSONString(bodyMap);
                logdoc.findItem("request_body").setValue(strBody);
                logdoc.findItem("request_url").setValue(url);
                logdoc.findItem("request_header").setValue("accessToken="+accessToken);
                logdoc.findItem("exam_info_id").setValue(examInfoId);
                var responseStr = Packages.cn.hutool.http.HttpRequest.post(url).header("bcxToken",accessToken).body(strBody).execute();
                logdoc.findItem("response").setValue(responseStr.body());
                var response = JSON.parse(responseStr.body());
                println(responseStr.body())
                var responseCode=response["code"]
                if("200".equals(responseCode)){
                  var updateOrdersql="update tlk_learn_order_person set ITEM_ORDER_NO_REFUND_STATUS='4',LASTMODIFIED=now() where  id in "+orderIds ;
                  updateByDSName("tms",updateOrdersql);
                  var updateExamInfo = "update tlk_system_exam_info set LASTMODIFIED=now(),item_exam_pay_over='1' where id='"+examInfoId+"' "
                  updateByDSName("tms",updateExamInfo);
                  logdoc.findItem("result_code").setValue('1');
                  process.doCreate(logdoc);
                }else{
                  logdoc.findItem("result_code").setValue('0');
                  process.doCreate(logdoc);
                }
              }catch(e){
                println("e--->"+e)
                logdoc.findItem("exam_info_id").setValue(e);
                logdoc.findItem("result_code").setValue('0');
                process.doCreate(logdoc);
              }
            }else {
              var updateExamInfo = "update tlk_system_exam_info set LASTMODIFIED=now(),item_exam_pay_over='3' where id='"+examInfoId+"' "
              updateByDSName("tms",updateExamInfo);
            }

          }
        }else {
          var updateExamInfo = "update tlk_system_exam_info set LASTMODIFIED=now() where id='"+examInfoId+"' "
          updateByDSName("tms",updateExamInfo);
        }
      }
    }
  }
})()
]]></beforeActionScript>
  <afterActionScript><![CDATA[]]></afterActionScript>
  <retractBeforeActionScript><![CDATA[]]></retractBeforeActionScript>
  <retractAfterActionScript><![CDATA[]]></retractAfterActionScript>
  <hiddenScript><![CDATA[]]></hiddenScript>
  <readonlyScript><![CDATA[]]></readonlyScript>
  <startFlowScript><![CDATA[]]></startFlowScript>
  <editMode>0</editMode>
  <fileNameScript><![CDATA[]]></fileNameScript>
  <iconurl></iconurl>
  <orderno>3</orderno>
  <stateToShow></stateToShow>
  <parentForm>__TguP7KZtUDBVC1gHr6k</parentForm>
  <jumpType>0</jumpType>
  <expSub>false</expSub>
  <icon></icon>
  <disableFlowNode>false</disableFlowNode>
  <changeFlowOperator>false</changeFlowOperator>
  <changeFlowCc>false</changeFlowCc>
  <multiLanguageLabel></multiLanguageLabel>
  <dispatcherMode>0</dispatcherMode>
  <dispatcherUrl><![CDATA[]]></dispatcherUrl>
  <dispatcherParams><![CDATA[[{"paramKey":"","paramValue":""}]]]></dispatcherParams>
  <jumpMode>0</jumpMode>
  <jumpActOpenType>0</jumpActOpenType>
  <withOld>false</withOld>
  <actionType>0</actionType>
  <actionDispatcherUrlScript><![CDATA[]]></actionDispatcherUrlScript>
  <actionSelection>0</actionSelection>
  <relatedFormId></relatedFormId>
  <actionScript><![CDATA[]]></actionScript>
  <workFlowType>0</workFlowType>
  <contextMenu>false</contextMenu>
  <showInToolbar>true</showInToolbar>
  <transpond></transpond>
  <targetList>|</targetList>
  <label><![CDATA[]]></label>
</activity>