ICE服务

  1. 非主服务上的服务脚本调用serv:commandStr方法可能会报nil错误,可以使用主服务ice去调用commandStr方法。

    --查询班次范围内平均节拍 -- by Chen
    function get_avg_beat(sLineID, sStart, sEnd)
     local sStartDate = cutil:substr(sStart, 0, 10);
     local sEndDate = cutil:substr(sEnd, 0, 10);
     local sEqptID = m_itEqptOut:get(sLineID);
     local sVarName = 'cyc_time1';
     if sLineID == '1214' or sLineID == '1215' or sLineID == '1216' then
         sVarName = 'cyc_time2';
     end
     local help = CSelectHelp();
     local itIn = CIntent();
     local sql = [[SELECT count(1) as qty,sum(value) as value FROM dc_data 
         where var_name='%s' and eqpt_id='%s'  and pick_time>='%s' and pick_time <='%s']];
     if sStartDate == sEndDate then--不跨天
         itIn:set('date', sStartDate..' 00:00:00');
         itIn:set('sql', string.format(sql, sVarName, sEqptID, sStart, sEnd));
         local str = CTNString();
         local ice = LuaICE();
         ice:setServer('127.0.0.1', '8801');--ice设置主服务IP和端口
         ice:commandStr('plugin.dc_server.query_tech', itIn:toString(), str);
         help:fromString(str:get());
         local iBeat = 0;
         if help:vf(0, 'qty') > 0 then
             iBeat = help:vf(0, 'value') / help:vf(0, 'qty');
         end
         return iBeat;
     else --跨天
         itIn:set('date', sStartDate..' 00:00:00');
         itIn:set('sql', string.format(sql, sVarName, sEqptID, sStart, sStartDate..' 23:59:59'));
         local str = CTNString();
         local ice = LuaICE();
         ice:setServer('127.0.0.1', '8801');
         ice:commandStr('plugin.dc_server.query_tech', itIn:toString(), str);
         help:fromString(str:get());
         local iBeat = 0;
         local iValue1 = help:vf(0, 'value');
         local iQty1 = help:vf(0, 'qty');
    
         itIn:set('date', sEndDate..' 00:00:00');
         itIn:set('sql', string.format(sql, sVarName, sEqptID, sEndDate..' 00:00:00', sEnd));
         local str = CTNString();
         ice:commandStr('plugin.dc_server.query_tech', itIn:toString(), str);
         help:fromString(str:get());
         local iValue2 = help:vf(0, 'value');
         local iQty2 = help:vf(0, 'qty');
         if iQty1 + iQty2 > 0 then
             iBeat = (iValue1 + iValue2) / (iQty1 + iQty2);
         end
         return iBeat;
     end
    end
    
Copyright © TouchNet 2015 all right reserved,powered by Gitbook最后修订时间: 2022-06-21 09:21:02

results matching ""

    No results matching ""