GoldenReport - 副本.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. //是否自定义公式
  2. function IsCustumFormula( fromStr)
  3. {
  4. var index=fromStr.indexOf("GETTAGSNAPSHORT(");
  5. if(index>=0)
  6. return true;
  7. index=fromStr.indexOf("GETTAGHISINTERVAL(");
  8. if(index>=0)
  9. return true;
  10. index=fromStr.indexOf("GETTIMEINTERVAL(");
  11. if(index>=0)
  12. return true;
  13. index=fromStr.indexOf("GETTIMESTASTIC(");
  14. if(index>=0)
  15. return true;
  16. return false;
  17. }
  18. function ApplyCustomFunc(spread)
  19. {
  20. var sheet = spread.getSheet(0);
  21. var getTagSnapShort = new goldenNameSpace.GetTagSnapShort();
  22. sheet.addCustomFunction(getTagSnapShort);
  23. var getTagHisInterval = new goldenNameSpace.GetTagHisInterval();
  24. sheet.addCustomFunction(getTagHisInterval);
  25. var getTimeInterval = new goldenNameSpace.GetTimeInterval();
  26. sheet.addCustomFunction(getTimeInterval);
  27. var getTimeStastic= new goldenNameSpace.GetTimeStastic();
  28. sheet.addCustomFunction(getTimeStastic);
  29. var getTagTimeStasticValue= new goldenNameSpace.GetTagTimeStasticValue();
  30. sheet.addCustomFunction(getTagTimeStasticValue);
  31. var getTagTimeStasticValue2= new goldenNameSpace.GetTagTimeStasticValue2();
  32. sheet.addCustomFunction(getTagTimeStasticValue2);
  33. var getTimeDisplayStr= new goldenNameSpace.GetTimeDisplayStr();
  34. sheet.addCustomFunction(getTimeDisplayStr);
  35. }
  36. //重新激活公式
  37. function ResetFormular(spread)
  38. {
  39. var sheet = spread.getSheet(0);
  40. //ApplyCustomFunc(spread);
  41. var colNum=sheet.getColumnCount();
  42. var rowNum=sheet.getRowCount();
  43. for( var i =0;i<colNum;i++)
  44. {
  45. for(var j=0;j<rowNum;j++)
  46. {
  47. var calcu=sheet.getFormula(j,i);
  48. if(calcu!=null)
  49. {
  50. //if(IsCustumFormula(calcu))
  51. //sheet.setFormula(j,i, "="+calcu);
  52. }
  53. /* var valueStr=sheet.getValue(j,i);
  54. if(!valueStr)
  55. continue;
  56. try
  57. {
  58. if(valueStr.indexOf("&#10")>=0)
  59. {
  60. var myCellType = new MyCellType();
  61. sheet.getCell(j,i).cellType(myCellType)
  62. }
  63. }
  64. catch(e)
  65. {
  66. }*/
  67. }
  68. sheet.autoFitColumn(i);
  69. }
  70. }
  71. //斜线表头
  72. function MyCellType() {
  73. }
  74. MyCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  75. MyCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  76. //Paints a cell on the canvas.
  77. if (!ctx) {
  78. return;
  79. }
  80. ctx.save();
  81. ctx.beginPath();
  82. ctx.moveTo(x,y);
  83. ctx.lineTo(x+w,y+h);
  84. ctx.stroke();
  85. ctx.font = style.font;
  86. var text = value ? value.split("&#10;") : ["",""];
  87. ctx.fillText(text[0].trim() ,x + w *7/8, y + h/3);
  88. ctx.fillText(text[1].trim(),x + w /2, y + h*3/4);
  89. ctx.restore();
  90. };
  91. var goldenNameSpace = {};
  92. (function () {
  93. // 自定义公式(获取统计时间段值2)----------------------------------------------------------------------
  94. function GetTagTimeStasticValue2 ()
  95. {
  96. this.name = 'GetTagTimeStasticValue2';
  97. this.maxArgs = 4;
  98. this.minArgs = 4;
  99. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue2", 0, 0]);
  100. this.typeName = "goldenNameSpace.GetTagTimeStasticValue2";
  101. }
  102. GetTagTimeStasticValue2.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  103. GetTagTimeStasticValue2.prototype.evaluateMode = function () {
  104. return 0;
  105. };
  106. goldenNameSpace.GetTagTimeStasticValue2=GetTagTimeStasticValue2;
  107. GetTagTimeStasticValue2.prototype.evaluateAsync = function (context)
  108. {
  109. if(arguments.length>=5)
  110. {
  111. var ReportTag=arguments[1];
  112. var ReportStartTime=arguments[2];
  113. var ReportEndTime=arguments[3];
  114. var ReportSelectType=arguments[4];
  115. ReportStartTime= window[ReportStartTime];//获取控件中的变量值
  116. if(!ReportStartTime)
  117. return "";
  118. ReportEndTime= window[ReportEndTime];//获取控件中的变量值
  119. if(!ReportEndTime)
  120. return "";
  121. }
  122. else
  123. return "";
  124. var TempStartTime=new Date(Date.parse(ReportStartTime));
  125. var TempEndTime=new Date(Date.parse(ReportEndTime));
  126. console.log("ask:"+ReportTag);
  127. var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistorySummary?tagName=";
  128. urlStr+=ReportTag+"&beginTime="+TempStartTime.Format("yyyy-MM-dd hh:mm:ss")+"&endTime="+TempEndTime.Format("yyyy-MM-dd hh:mm:ss")+"&dataType=snap";
  129. $.ajax({
  130. type: 'GET',
  131. url: urlStr,
  132. dataType: 'json',
  133. cache: false,
  134. error:function(data)
  135. {
  136. context.setAsyncResult(data.responseText);
  137. },
  138. success: function (data)
  139. {
  140. if(!data)
  141. return;
  142. for (var key in data)
  143. {
  144. console.log("answer:"+key);
  145. var tagData= data[key];
  146. if(!tagData)
  147. continue;
  148. if(ReportSelectType=="avg")
  149. {
  150. var actVal=GetDital(tagData.CalcAvg,3);
  151. context.setAsyncResult(actVal);
  152. }
  153. else if(ReportSelectType=="max")
  154. {
  155. var actVal=GetDital(tagData.Max,3);
  156. context.setAsyncResult(actVal);
  157. }
  158. else if(ReportSelectType=="min")
  159. {
  160. var actVal=GetDital(tagData.Min,3);
  161. context.setAsyncResult(actVal);
  162. }
  163. else if(ReportSelectType=="sub")
  164. {
  165. var actVal=GetDital(tagData.Difference,3);
  166. context.setAsyncResult(actVal);
  167. }
  168. }
  169. }
  170. });
  171. }
  172. // 自定义公式(获取统计时间段值)----------------------------------------------------------------------
  173. function GetTagTimeStasticValue ()
  174. {
  175. this.name = 'GetTagTimeStasticValue';
  176. this.maxArgs = 4;
  177. this.minArgs = 4;
  178. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue", 0, 0]);
  179. this.typeName = "goldenNameSpace.GetTagTimeStasticValue";
  180. }
  181. GetTagTimeStasticValue.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  182. GetTagTimeStasticValue.prototype.evaluateMode = function () {
  183. return 0;
  184. };
  185. goldenNameSpace.GetTagTimeStasticValue=GetTagTimeStasticValue;
  186. GetTagTimeStasticValue.prototype.evaluateAsync = function (context)
  187. {
  188. if(arguments.length>=5)
  189. {
  190. ReportTag=arguments[1];
  191. ReportSelectTime=arguments[2];
  192. ReportTimeType=arguments[3];
  193. ReportSelectType=arguments[4];
  194. ReportSelectTime= window[ReportSelectTime];//获取控件中的变量值
  195. if(!ReportSelectTime)
  196. return "";
  197. }
  198. else
  199. return "";
  200. var TempStartTime=new Date(Date.parse(ReportSelectTime));
  201. var TempEndTime=new Date(Date.parse(ReportSelectTime));
  202. if(ReportTimeType=='d'||ReportTimeType=='D')
  203. {
  204. TempStartTime.setHours(0);
  205. TempStartTime.setMinutes(0);
  206. TempStartTime.setSeconds(0);
  207. TempEndTime.setHours(23);
  208. TempEndTime.setMinutes(59);
  209. TempEndTime.setSeconds(59);
  210. }
  211. else if(ReportTimeType=='m'||ReportTimeType=='M')
  212. {
  213. TempStartTime.setDate(1);
  214. TempStartTime.setHours(0);
  215. TempStartTime.setMinutes(0);
  216. TempStartTime.setSeconds(0);
  217. TempEndTime.setMonth( TempEndTime.getMonth()+1);
  218. TempEndTime.setHours(23);
  219. TempEndTime.setMinutes(59);
  220. TempEndTime.setSeconds(59);
  221. }
  222. else if(ReportTimeType=='y'||ReportTimeType=='Y')
  223. {
  224. TempStartTime.setMonth(0);
  225. TempStartTime.setDate(1);
  226. TempStartTime.setHours(0);
  227. TempStartTime.setMinutes(0);
  228. TempStartTime.setSeconds(0);
  229. var year= ReportSelectTime.getYear();
  230. TempEndTime.setYear(year+1+1900);
  231. TempEndTime.setMonth(0);
  232. TempEndTime.setDate(0);
  233. TempEndTime.setHours(23);
  234. TempEndTime.setMinutes(59);
  235. TempEndTime.setSeconds(59);
  236. }
  237. console.log("ask:"+ReportTag);
  238. var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistorySummary?tagName=";
  239. urlStr+=ReportTag+"&beginTime="+TempStartTime.Format("yyyy-MM-dd hh:mm:ss")+"&endTime="+TempEndTime.Format("yyyy-MM-dd hh:mm:ss")+"&dataType=snap";
  240. $.ajax({
  241. type: 'GET',
  242. url: urlStr,
  243. dataType: 'json',
  244. cache: false,
  245. error:function(data)
  246. {
  247. context.setAsyncResult(data.responseText);
  248. },
  249. success: function (data)
  250. {
  251. if(!data)
  252. return;
  253. for (var key in data)
  254. {
  255. console.log("answer:"+key);
  256. var tagData= data[key];
  257. if(!tagData)
  258. continue;
  259. if(ReportSelectType=="avg")
  260. {
  261. var actVal=GetDital(tagData.CalcAvg,3);
  262. context.setAsyncResult(actVal);
  263. }
  264. else if(ReportSelectType=="max")
  265. {
  266. var actVal=GetDital(tagData.Max,3);
  267. context.setAsyncResult(actVal);
  268. }
  269. else if(ReportSelectType=="min")
  270. {
  271. var actVal=GetDital(tagData.Min,3);
  272. context.setAsyncResult(actVal);
  273. }
  274. else if(ReportSelectType=="sub")
  275. {
  276. var actVal=GetDital(tagData.Difference,3);
  277. context.setAsyncResult(actVal);
  278. }
  279. else if(ReportSelectType=="start")
  280. {
  281. context.setAsyncResult(tagData.StartTime);
  282. }
  283. else if(ReportSelectType=="end")
  284. {
  285. context.setAsyncResult(tagData.EndTime);
  286. }
  287. }
  288. }
  289. });
  290. }
  291. // 自定义公式(获取统计时间段时间值)----------------------------------------------------------------------
  292. function GetTimeDisplayStr ()
  293. {
  294. this.name = 'GetTimeDisplayStr';
  295. this.maxArgs = 2;
  296. this.minArgs = 2;
  297. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeDisplayStr", 0, 0]);
  298. this.typeName = "goldenNameSpace.GetTimeDisplayStr";
  299. }
  300. goldenNameSpace.GetTimeDisplayStr=GetTimeDisplayStr;
  301. GetTimeDisplayStr.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  302. GetTimeDisplayStr.prototype.evaluateMode = function () {
  303. return 0;
  304. };
  305. GetTimeDisplayStr.prototype.evaluateAsync = function (context)
  306. {
  307. //context.setAsyncResult("");
  308. //return;
  309. if(arguments.length>=2)
  310. {
  311. ReportSelectTime=arguments[1];
  312. ReportTimeFormat=arguments[2];
  313. ReportSelectTime= window[ReportSelectTime];//获取控件中的变量值
  314. if(!ReportSelectTime)
  315. {
  316. context.setAsyncResult("未找到时间变量!");
  317. return;
  318. }
  319. }
  320. else
  321. {
  322. context.setAsyncResult("参数数量不足!");
  323. return;
  324. }
  325. ReportSelectTime=new Date(Date.parse(ReportSelectTime));
  326. var ReportSelectTimeStr=ReportSelectTime.Format(ReportTimeFormat);
  327. context.setAsyncResult(ReportSelectTimeStr);
  328. }
  329. // 自定义公式(获取统计时间段值)----------------------------------------------------------------------
  330. // 自定义公式(获取统计时间段时间值)----------------------------------------------------------------------
  331. function GetTimeStastic ()
  332. {
  333. this.name = 'GetTimeStastic';
  334. this.maxArgs = 4;
  335. this.minArgs = 4;
  336. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeStastic", 0, 0]);
  337. this.typeName = "goldenNameSpace.GetTimeStastic";
  338. }
  339. goldenNameSpace.GetTimeStastic=GetTimeStastic;
  340. GetTimeStastic.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  341. GetTimeStastic.prototype.evaluateMode = function () {
  342. return 0;
  343. };
  344. GetTimeStastic.prototype.evaluateAsync = function (context)
  345. {
  346. if(arguments.length>=5)
  347. {
  348. ReportSelectTime=arguments[1];
  349. ReportTimeType=arguments[2];
  350. ReportSelectType=arguments[3];
  351. ReportTimeFormat=arguments[4];
  352. ReportSelectTime= window[ReportSelectTime];//获取控件中的变量值
  353. }
  354. else
  355. {
  356. context.setAsyncResult("error!");
  357. return;
  358. }
  359. ReportSelectTime=new Date(Date.parse(ReportSelectTime));
  360. if(ReportTimeType=='d')
  361. {
  362. if(ReportSelectType=="start")
  363. {
  364. ReportSelectTime.setHours(0);
  365. ReportSelectTime.setMinutes(0);
  366. ReportSelectTime.setSeconds(0);
  367. }
  368. else
  369. {
  370. ReportSelectTime.setHours(23);
  371. ReportSelectTime.setMinutes(59);
  372. ReportSelectTime.setSeconds(59);
  373. }
  374. }
  375. else if(ReportTimeType=='m')
  376. {
  377. if(ReportSelectType=="start")
  378. {
  379. ReportSelectTime.setSeconds(0);
  380. }
  381. else
  382. {
  383. ReportSelectTime.setSeconds(59);
  384. }
  385. }
  386. else if(ReportTimeType=='h')
  387. {
  388. if(ReportSelectType=="start")
  389. {
  390. ReportSelectTime.setMinutes(0);
  391. ReportSelectTime.setSeconds(0);
  392. }
  393. else
  394. {
  395. ReportSelectTime.setMinutes(59);
  396. ReportSelectTime.setSeconds(59);
  397. }
  398. }
  399. else if(ReportTimeType=='M')
  400. {
  401. if(ReportSelectType=="start")
  402. {
  403. ReportSelectTime.setDate(1);
  404. ReportSelectTime.setHours(0);
  405. ReportSelectTime.setMinutes(0);
  406. ReportSelectTime.setSeconds(0);
  407. }
  408. else
  409. {
  410. ReportSelectTime.setMonth( ReportSelectTime.getMonth()+1);
  411. ReportSelectTime.setDate(0);
  412. ReportSelectTime.setHours(23);
  413. ReportSelectTime.setMinutes(59);
  414. ReportSelectTime.setSeconds(59);
  415. }
  416. }
  417. else if(ReportTimeType=='y')
  418. {
  419. if(ReportSelectType=="start")
  420. {
  421. ReportSelectTime.setMonth(0);
  422. ReportSelectTime.setDate(1);
  423. ReportSelectTime.setHours(0);
  424. ReportSelectTime.setMinutes(0);
  425. ReportSelectTime.setSeconds(0);
  426. }
  427. else
  428. {
  429. var year= ReportSelectTime.getYear();
  430. ReportSelectTime.setYear(year+1+1900);
  431. ReportSelectTime.setMonth(0);
  432. ReportSelectTime.setDate(0);
  433. ReportSelectTime.setHours(23);
  434. ReportSelectTime.setMinutes(59);
  435. ReportSelectTime.setSeconds(59);
  436. }
  437. }
  438. var ReportSelectTimeStr=ReportSelectTime.Format(ReportTimeFormat);
  439. context.setAsyncResult(ReportSelectTimeStr);
  440. }
  441. // 自定义公式(获取统计时间段时间值)----------------------------------------------------------------------
  442. // 自定义公式(获取时间段的等间隔显示)----------------------------------------------------------------------
  443. function GetTimeInterval () {
  444. this.name = 'GetTimeInterval';
  445. this.maxArgs = 6;
  446. this.minArgs = 6;
  447. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeInterval", 0, 0]);
  448. this.typeName = "goldenNameSpace.GetTimeInterval";
  449. }
  450. GetTimeInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  451. GetTimeInterval.prototype.defaultValue = function () {return 'loading'};
  452. GetTimeInterval.prototype.evaluateMode = function () {
  453. return 0;
  454. };
  455. goldenNameSpace.GetTimeInterval=GetTimeInterval;
  456. //获取历史等间隔数据
  457. GetTimeInterval.prototype.evaluateAsync = function (context)
  458. {
  459. var args = arguments;
  460. var curCol=context.col;
  461. var curRow=context.row;
  462. if(args.length>=6)
  463. {
  464. var ReportStartTime=args[1];
  465. var ReportEndTime=args[2];
  466. var ReportInterval=args[3];
  467. var ReportIntervalType=args[4];
  468. var ReportTimeFormat=args[5];
  469. var ReportVH=args[6];
  470. ReportStartTime= window[ReportStartTime];
  471. ReportEndTime= window[ReportEndTime];
  472. //ReportInterval= window[ReportInterval];
  473. //ReportIntervalType = window[ReportIntervalType];
  474. }
  475. else
  476. {
  477. context.setAsyncResult(0);
  478. return;
  479. }
  480. var tempDateTime=new Date(Date.parse(ReportStartTime));
  481. var tempEndTime=new Date(Date.parse(ReportEndTime));
  482. var sheet =context.ctx.source;
  483. for(var i=1;i<200;i++)
  484. {
  485. if(ReportIntervalType=='s')
  486. {
  487. tempDateTime.setSeconds(tempDateTime.getSeconds()+ReportInterval);
  488. }
  489. else if(ReportIntervalType=='m')
  490. {
  491. tempDateTime.setMinutes(tempDateTime.getMinutes()+ReportInterval);
  492. }
  493. else if(ReportIntervalType=='h')
  494. {
  495. tempDateTime.setHours(tempDateTime.getHours()+ReportInterval);
  496. }
  497. else if(ReportIntervalType=='d')
  498. {
  499. tempDateTime.setDate(tempDateTime.getDate()+ReportInterval);
  500. }
  501. else if(ReportIntervalType=='M')
  502. {
  503. tempDateTime.setMonth(tempDateTime.getMonth()+ReportInterval);
  504. }
  505. else if(ReportIntervalType=='y')
  506. {
  507. tempDateTime.setYear(tempDateTime.getYear()+ReportInterval);
  508. }
  509. var tempDateStr=tempDateTime.Format(ReportTimeFormat);
  510. if(ReportVH=="v")
  511. {
  512. if(curRow+i<sheet.getRowCount()&&curCol<sheet.getColumnCount())
  513. sheet.setValue(curRow+i,curCol,tempDateStr);
  514. }
  515. else if(ReportVH=="h")
  516. {
  517. if(curRow<sheet.getRowCount()&&curCol+i<sheet.getColumnCount())
  518. sheet.setValue(curRow,curCol+i,tempDateStr);
  519. }
  520. if(tempDateTime>=tempEndTime)
  521. break;
  522. }
  523. tempDateTime=new Date(Date.parse(ReportStartTime));
  524. tempDateStr=tempDateTime.Format(ReportTimeFormat);
  525. context.setAsyncResult(tempDateStr);
  526. }
  527. // 自定义公式(获取时间段的等间隔显示)----------------------------------------------------------------------
  528. // 自定义公式(获取获取历史等间隔数据)----------------------------------------------------------------------
  529. function GetTagHisInterval () {
  530. this.name = 'GetTagHisInterval';
  531. this.maxArgs = 6;
  532. this.minArgs = 6;
  533. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagHisInterval", 0, 0]);
  534. this.typeName = "goldenNameSpace.GetTagHisInterval";
  535. }
  536. goldenNameSpace.GetTagHisInterval=GetTagHisInterval;
  537. GetTagHisInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  538. GetTagHisInterval.prototype.defaultValue = function () {return 'loading'};
  539. GetTagHisInterval.prototype.evaluateMode = function () {
  540. return 0;
  541. };
  542. GetTagHisInterval.prototype.interval = function () {
  543. return 1000;
  544. };
  545. //获取历史等间隔数据
  546. GetTagHisInterval.prototype.evaluateAsync = function (context)
  547. {
  548. var args = arguments;
  549. var curCol=context.col;
  550. var curRow=context.row;
  551. if(args.length>=5)
  552. {
  553. var Reporttag=args[1];
  554. var ReportStartTime=args[2];
  555. var ReportEndTime=args[3];
  556. var ReportInterval=args[4];
  557. var ReportIntervalType=args[5];
  558. var ReportVH=args[6];
  559. ReportStartTime= window[ReportStartTime];
  560. ReportEndTime= window[ReportEndTime];
  561. //ReportInterval= window[ReportInterval];
  562. ReportIntervalType= "0";// window[ReportIntervalType];
  563. }
  564. else
  565. {
  566. context.setAsyncResult(0);
  567. return;
  568. }
  569. if(ReportIntervalType=="m")//分钟
  570. {
  571. ReportInterval=ReportInterval*60;
  572. }
  573. else if(ReportIntervalType=="h")//小时
  574. {
  575. ReportInterval=ReportInterval*3600;
  576. }
  577. else if(ReportIntervalType=="d")//天
  578. {
  579. ReportInterval=ReportInterval*3600*24;
  580. }
  581. var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryInterval?tagName="; //+ cmdStr;
  582. pageIndex=1;
  583. tagsCount=200;
  584. urlStr += createSearchStr(Reporttag,ReportStartTime, ReportEndTime, ReportInterval, ReportIntervalType, ReportInterval)
  585. + '&pageIndex=' + pageIndex + '&pageSize='+ tagsCount;
  586. // getTableHisData(shotTablePane,url,shotTableTableModel,shotTablecolumns,shotTablerows);
  587. $.ajax({
  588. type: 'GET',
  589. url: urlStr,
  590. dataType: 'json',
  591. cache: false,
  592. success: function (data) {
  593. if(!data.Datas)
  594. {
  595. context.setAsyncResult("not find!");
  596. return;
  597. }
  598. for (var key in data.Datas)
  599. {
  600. var tagData= data.Datas[key];
  601. if(!tagData)
  602. continue;
  603. if(tagData.length>0)
  604. {
  605. var showCount=200;
  606. if(tagData.length<showCount)
  607. showCount=tagData.length;
  608. var actVal=GetDital(tagData[0].Value,3)
  609. context.setAsyncResult(actVal);
  610. var sheet =context.ctx.source;
  611. for(var i=0;i<showCount;i++)
  612. {
  613. actVal=GetDital(tagData[i].Value,3);
  614. if(ReportVH=="v")
  615. {
  616. if(curRow+i<sheet.getRowCount()&&curCol<sheet.getColumnCount())
  617. sheet.setValue(curRow+i,curCol,actVal);
  618. }
  619. else if(ReportVH=="h")
  620. {
  621. if(curRow<sheet.getRowCount()&&curCol+i<sheet.getColumnCount())
  622. sheet.setValue(curRow,curCol+i,actVal);
  623. }
  624. }
  625. //sheet.autoFitColumn(curCol);
  626. return;
  627. }
  628. else
  629. {
  630. context.setAsyncResult("not find!");
  631. return;
  632. }
  633. break;
  634. }
  635. var sheet =context.ctx.source;
  636. sheet.refresh();
  637. }
  638. })
  639. }
  640. //创建等间隔历史查询的查询字符串
  641. function createSearchStr (tagNameStr,beginTime, endTime, interval, valueType, count)
  642. {
  643. beginTime = beginTime || moment(new Date()).format("YYYY-MM-DD H:mm:ss");
  644. endTime = endTime || moment(new Date(beginTime)).add(30,'seconds').format("YYYY-MM-DD H:mm:ss");
  645. interval = interval || 10;
  646. valueType = valueType || 1;
  647. count = Math.floor((new Date(endTime) - new Date(beginTime)) / interval / 1000);
  648. var result = '';
  649. var tagsInfo = encodeURIComponent(tagNameStr);
  650. result = tagsInfo + '&beginTime=' + beginTime + '&endTime=' + endTime + '&interval=' + interval + '&count=' + count;
  651. if (valueType !== '0') {
  652. result += '&valueType=' + valueType;
  653. }
  654. return result;
  655. }
  656. // 自定义公式(获取获取历史等间隔数据)----------------------------------------------------------------------
  657. // 自定义公式(获取快照值)----------------------------------------------------------------------
  658. function GetTagSnapShort () {
  659. this.name = 'GETTAGSNAPSHORT';
  660. this.maxArgs = 2;
  661. this.minArgs = 2;
  662. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagSnapShort", 0, 0]);
  663. this.typeName = "goldenNameSpace.GetTagSnapShort";
  664. }
  665. goldenNameSpace.GetTagSnapShort=GetTagSnapShort;
  666. GetTagSnapShort.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  667. GetTagSnapShort.prototype.defaultValue = function () {return 'loading'};
  668. GetTagSnapShort.prototype.evaluateMode = function () {
  669. return 2;
  670. };
  671. GetTagSnapShort.prototype.interval = function () {
  672. return 1000;
  673. };
  674. GetTagSnapShort.prototype.evaluateAsync = function (context) {
  675. var args = arguments;
  676. if(args.length>1)
  677. tag=args[1];
  678. else
  679. {
  680. context.setAsyncResult(0);
  681. return;
  682. }
  683. var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot?tagName=";
  684. var para = tag;
  685. str = str + encodeURIComponent(para);
  686. $.ajax({
  687. url: str ,
  688. type: 'GET',
  689. dataType: 'json',
  690. cache: false,
  691. success: function (data) {
  692. if (data === null) return;
  693. var snapshots = eval(data);
  694. //判断快照是否为空
  695. if (snapshots != null) {
  696. var value=0;
  697. if(snapshots.length>0)
  698. value= snapshots[0].Value;
  699. var actVal= GetDital(value,3);
  700. context.setAsyncResult(actVal);
  701. }
  702. },
  703. complete: function (XHR, TS) {
  704. XHR = null;
  705. }
  706. }
  707. );
  708. }
  709. })();
  710. // 自定义公式(获取快照值)----------------------------------------------------------------------
  711. // 对Date的扩展,将 Date 转化为指定格式的String
  712. // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  713. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  714. // 例子:
  715. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  716. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  717. Date.prototype.Format = function (fmt) { //author: meizz
  718. var o = {
  719. "M+": this.getMonth() + 1, //月份
  720. "d+": this.getDate(), //日
  721. "h+": this.getHours(), //小时
  722. "m+": this.getMinutes(), //分
  723. "s+": this.getSeconds(), //秒
  724. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  725. "S": this.getMilliseconds() //毫秒
  726. };
  727. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  728. for (var k in o)
  729. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  730. return fmt;
  731. }