GoldenReport.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  1. //�첽��������
  2. ReportAnsnFuncNum = 0;
  3. //�첽������ɸ���
  4. ReportAnsnDoneNum = 0;
  5. //��ѯͳ��ֵ���б� ȫ���ռ����б��һ�β�ѯ
  6. var TagStasticSearchInfoList = new Array();
  7. //��ѯ��ʷʱ��ֵ���б�ȫ���ռ����б��һ�β�ѯ
  8. var ReportTagHisValueSearchInfoList = new Array();
  9. //�Ƿ��Զ��幫ʽ
  10. function IsCustumFormula(fromStr) {
  11. var index = fromStr.indexOf("GetTagSnapShort(");
  12. if (index >= 0)
  13. return true;
  14. index = fromStr.indexOf("GetTagHisValue(");
  15. if (index >= 0)
  16. return true;
  17. index = fromStr.indexOf("GetTagHisInterval(");
  18. if (index >= 0)
  19. return true;
  20. index = fromStr.indexOf("GetTimeInterval(");
  21. if (index >= 0)
  22. return true;
  23. index = fromStr.indexOf("GetTimeStastic(");
  24. if (index >= 0)
  25. return true;
  26. index = fromStr.indexOf("GetTagTimeStasticValue(");
  27. if (index >= 0)
  28. return true;
  29. index = fromStr.indexOf("GetTagTimeStasticValue2(");
  30. if (index >= 0)
  31. return true;
  32. index = fromStr.indexOf("GetTimeDisplayStr(");
  33. if (index >= 0)
  34. return true;
  35. return false;
  36. }
  37. //�Ƿ��Զ����첽����
  38. function IsAnsnFunc(funcName) {
  39. index = funcName.indexOf("GetTagHisInterval(");
  40. if (index >= 0)
  41. return true;
  42. index = funcName.indexOf("GetTimeInterval(");
  43. if (index >= 0)
  44. return true;
  45. return false;
  46. }
  47. //�Ƿ��Զ���ͬ������
  48. function IsCustomNoAnsnFunc(funcName) {
  49. index = funcName.indexOf("GetTimeDisplayStr(");
  50. if (index >= 0)
  51. return true;
  52. return false;
  53. }
  54. //ע���Զ��庯��
  55. function ApplyCustomFunc(spread) {
  56. var sheet = spread.getSheet(0);
  57. GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGSNAPSHORT", new goldenNameSpace.GetTagSnapShort());
  58. GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGHISVALUE", new goldenNameSpace.GetTagHisValue());
  59. GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGHISINTERVAL", new goldenNameSpace.GetTagHisInterval());
  60. GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEINTERVAL", new goldenNameSpace.GetTimeInterval());
  61. GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMESTASTIC", new goldenNameSpace.GetTimeStastic());
  62. GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGTIMESTASTICVALUE", new goldenNameSpace.GetTagTimeStasticValue());
  63. GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGTIMESTASTICVALUE2", new goldenNameSpace.GetTagTimeStasticValue2());
  64. GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEDISPLAYSTR", new goldenNameSpace.GetTimeDisplayStr());
  65. /*
  66. var getTagSnapShort = new goldenNameSpace.GetTagSnapShort();
  67. sheet.addCustomFunction(getTagSnapShort);
  68. var getTagHisValue = new goldenNameSpace.GetTagHisValue();
  69. sheet.addCustomFunction(getTagHisValue);
  70. var getTagHisInterval = new goldenNameSpace.GetTagHisInterval();
  71. sheet.addCustomFunction(getTagHisInterval);
  72. var getTimeInterval = new goldenNameSpace.GetTimeInterval();
  73. sheet.addCustomFunction(getTimeInterval);
  74. var getTimeStastic= new goldenNameSpace.GetTimeStastic();
  75. sheet.addCustomFunction(getTimeStastic);
  76. var getTagTimeStasticValue= new goldenNameSpace.GetTagTimeStasticValue();
  77. sheet.addCustomFunction(getTagTimeStasticValue);
  78. var getTagTimeStasticValue2= new goldenNameSpace.GetTagTimeStasticValue2();
  79. sheet.addCustomFunction(getTagTimeStasticValue2);
  80. var getTimeDisplayStr= new goldenNameSpace.GetTimeDisplayStr();
  81. sheet.addCustomFunction(getTimeDisplayStr);
  82. var getTagHisValue= new goldenNameSpace.GetTagHisValue();
  83. sheet.addCustomFunction(getTagHisValue);*/
  84. }
  85. //ִ���Զ���ͬ������
  86. function DoCustomNoAnsnFunc(spread) {
  87. var sheet = spread.getSheet(0);
  88. //ApplyCustomFunc(spread);
  89. var colNum = sheet.getColumnCount();
  90. var rowNum = sheet.getRowCount();
  91. for (var i = 0; i < colNum; i++) {
  92. for (var j = 0; j < rowNum; j++) {
  93. var calcu = sheet.getFormula(j, i);
  94. if (calcu != null) {
  95. if (IsCustomNoAnsnFunc(calcu))
  96. sheet.setFormula(j, i, "=" + calcu);
  97. }
  98. }
  99. }
  100. }
  101. //ִ�з��Զ��庯��
  102. function DoNoCustomFunc(spread) {
  103. var sheet = spread.getSheet(0);
  104. //ApplyCustomFunc(spread);
  105. var colNum = sheet.getColumnCount();
  106. var rowNum = sheet.getRowCount();
  107. for (var i = 0; i < colNum; i++) {
  108. for (var j = 0; j < rowNum; j++) {
  109. var calcu = sheet.getFormula(j, i);
  110. if (calcu != null) {
  111. if (!IsCustumFormula(calcu))
  112. sheet.setFormula(j, i, "=" + calcu);
  113. }
  114. }
  115. }
  116. }
  117. //���¼��ʽ
  118. function ResetFormular(spread) {
  119. var sheet = spread.getSheet(0);
  120. //ApplyCustomFunc(spread);
  121. var colNum = sheet.getColumnCount();
  122. var rowNum = sheet.getRowCount();
  123. ReportAnsnFuncNum = 0;
  124. for (var i = 0; i < colNum; i++) {
  125. for (var j = 0; j < rowNum; j++) {
  126. var calcu = sheet.getFormula(j, i);
  127. if (calcu != null) {
  128. //if(IsCustumFormula(calcu))
  129. //sheet.setFormula(j,i, "="+calcu);
  130. if (IsAnsnFunc(calcu)) {
  131. ReportAnsnFuncNum++;
  132. }
  133. }
  134. /* var valueStr=sheet.getValue(j,i);
  135. if(!valueStr)
  136. continue;
  137. try
  138. {
  139. if(valueStr.indexOf("&#10")>=0)
  140. {
  141. var myCellType = new MyCellType();
  142. sheet.getCell(j,i).cellType(myCellType)
  143. }
  144. }
  145. catch(e)
  146. {
  147. }*/
  148. }
  149. //sheet.autoFitColumn(i);
  150. }
  151. }
  152. //б�߱�ͷ
  153. function MyCellType() {
  154. }
  155. MyCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  156. MyCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  157. //Paints a cell on the canvas.
  158. if (!ctx) {
  159. return;
  160. }
  161. ctx.save();
  162. ctx.beginPath();
  163. ctx.moveTo(x, y);
  164. ctx.lineTo(x + w, y + h);
  165. ctx.stroke();
  166. ctx.font = style.font;
  167. var text = value ? value.split("&#10;") : ["", ""];
  168. ctx.fillText(text[0].trim(), x + w * 7 / 8, y + h / 3);
  169. ctx.fillText(text[1].trim(), x + w / 2, y + h * 3 / 4);
  170. ctx.restore();
  171. };
  172. var goldenNameSpace = {};
  173. (function () {
  174. // �Զ��幫ʽ����ȡͳ��ʱ���ֵ2��----------------------------------------------------------------------
  175. function GetTagTimeStasticValue2() {
  176. this.name = 'GetTagTimeStasticValue2';
  177. this.maxArgs = 5;
  178. this.minArgs = 5;
  179. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue2", 0, 0]);
  180. this.typeName = "goldenNameSpace.GetTagTimeStasticValue2";
  181. }
  182. //ͬ����ʽ
  183. goldenNameSpace.GetTagTimeStasticValue2 = GetTagTimeStasticValue2;
  184. GetTagTimeStasticValue2.prototype = new GC.Spread.CalcEngine.Functions.Function();
  185. GetTagTimeStasticValue2.prototype.evaluateMode = function () {
  186. return 0;
  187. };
  188. GetTagTimeStasticValue2.prototype.evaluate = function (arg) {
  189. if (arguments.length >= 4) {
  190. var ReportTag = arguments[0];
  191. var ReportStartTime = arguments[1];
  192. var ReportEndTime = arguments[2];
  193. var ReportSelectType = arguments[3];
  194. ReportStartTime = window[ReportStartTime];//��ȡ�ؼ��еı���ֵ
  195. if (!ReportStartTime)
  196. return "";
  197. ReportEndTime = window[ReportEndTime];//��ȡ�ؼ��еı���ֵ
  198. if (!ReportEndTime)
  199. return "";
  200. }
  201. else
  202. return "";
  203. var TempStartTime = new Date(Date.parse(ReportStartTime));
  204. var TempEndTime = new Date(Date.parse(ReportEndTime));
  205. //��ȡͳ��ֵ
  206. var vv = GetTagStasticSearchValue(TempStartTime, TempEndTime, ReportTag, ReportSelectType);
  207. if (!vv) {
  208. return 0;
  209. }
  210. else
  211. return parseFloat(vv);
  212. }
  213. /* //�첽��ʽ
  214. GetTagTimeStasticValue2.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  215. GetTagTimeStasticValue2.prototype.evaluateMode = function () {
  216. return 0;
  217. };
  218. goldenNameSpace.GetTagTimeStasticValue2=GetTagTimeStasticValue2;
  219. GetTagTimeStasticValue2.prototype.evaluateAsync = function (context)
  220. {
  221. if(arguments.length>=5)
  222. {
  223. var ReportTag=arguments[1];
  224. var ReportStartTime=arguments[2];
  225. var ReportEndTime=arguments[3];
  226. var ReportSelectType=arguments[4];
  227. ReportStartTime= window[ReportStartTime];//��ȡ�ؼ��еı���ֵ
  228. if(!ReportStartTime)
  229. {
  230. context.setAsyncResult(0);
  231. return;
  232. }
  233. ReportEndTime= window[ReportEndTime];//��ȡ�ؼ��еı���ֵ
  234. if(!ReportEndTime)
  235. {
  236. context.setAsyncResult(0);
  237. return;
  238. }
  239. }
  240. else
  241. {
  242. context.setAsyncResult(0);
  243. return;
  244. }
  245. var TempStartTime=new Date(Date.parse(ReportStartTime));
  246. var TempEndTime=new Date(Date.parse(ReportEndTime));
  247. //��ȡͳ��ֵ
  248. var vv=GetTagStasticSearchValue(TempStartTime,TempEndTime,ReportTag,ReportSelectType);
  249. if(!vv)
  250. {
  251. context.setAsyncResult(0);
  252. return;
  253. }
  254. else
  255. context.setAsyncResult(vv);
  256. } */
  257. // �Զ��幫ʽ����ȡͳ��ʱ���ֵ��----------------------------------------------------------------------
  258. function GetTagTimeStasticValue() {
  259. this.name = 'GetTagTimeStasticValue';
  260. this.maxArgs = 4;
  261. this.minArgs = 4;
  262. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue", 0, 0]);
  263. this.typeName = "goldenNameSpace.GetTagTimeStasticValue";
  264. }
  265. GetTagTimeStasticValue.prototype = new GC.Spread.CalcEngine.Functions.Function();
  266. GetTagTimeStasticValue.prototype.evaluateMode = function () {
  267. return 0;
  268. };
  269. goldenNameSpace.GetTagTimeStasticValue = GetTagTimeStasticValue;
  270. GetTagTimeStasticValue.prototype.evaluate = function (context) {
  271. if (arguments.length >= 4) {
  272. ReportTag = arguments[0];
  273. ReportSelectTime = arguments[1];
  274. ReportTimeType = arguments[2];
  275. ReportSelectType = arguments[3];
  276. ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ
  277. if (!ReportSelectTime)
  278. return "";
  279. }
  280. else
  281. return "";
  282. var TempStartTime = new Date(Date.parse(ReportSelectTime));
  283. var TempEndTime = new Date(Date.parse(ReportSelectTime));
  284. if (ReportTimeType == 'd' || ReportTimeType == 'D') {
  285. TempStartTime.setHours(0);
  286. TempStartTime.setMinutes(0);
  287. TempStartTime.setSeconds(0);
  288. TempEndTime.setHours(23);
  289. TempEndTime.setMinutes(59);
  290. TempEndTime.setSeconds(59);
  291. }
  292. else if (ReportTimeType == 'm' || ReportTimeType == 'M') {
  293. TempStartTime.setDate(1);
  294. TempStartTime.setHours(0);
  295. TempStartTime.setMinutes(0);
  296. TempStartTime.setSeconds(0);
  297. TempEndTime.setMonth(TempEndTime.getMonth() + 1);
  298. TempEndTime.setDate(0);
  299. TempEndTime.setHours(23);
  300. TempEndTime.setMinutes(59);
  301. TempEndTime.setSeconds(59);
  302. }
  303. else if (ReportTimeType == 'y' || ReportTimeType == 'Y') {
  304. TempStartTime.setMonth(0);
  305. TempStartTime.setDate(1);
  306. TempStartTime.setHours(0);
  307. TempStartTime.setMinutes(0);
  308. TempStartTime.setSeconds(0);
  309. var year = TempEndTime.getYear();
  310. TempEndTime.setYear(year + 1 + 1900);
  311. TempEndTime.setMonth(0);
  312. TempEndTime.setDate(0);
  313. TempEndTime.setHours(23);
  314. TempEndTime.setMinutes(59);
  315. TempEndTime.setSeconds(59);
  316. }
  317. //��ȡͳ��ֵ
  318. var vv = GetTagStasticSearchValue(TempStartTime, TempEndTime, ReportTag, ReportSelectType);
  319. if (!vv) {
  320. return 0;
  321. }
  322. else
  323. return parseFloat(vv);
  324. }
  325. // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��----------------------------------------------------------------------
  326. function GetTimeDisplayStr() {
  327. this.name = 'GetTimeDisplayStr';
  328. this.maxArgs = 2;
  329. this.minArgs = 2;
  330. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeDisplayStr", 0, 0]);
  331. this.typeName = "goldenNameSpace.GetTimeDisplayStr";
  332. }
  333. goldenNameSpace.GetTimeDisplayStr = GetTimeDisplayStr;
  334. GetTimeDisplayStr.prototype = new GC.Spread.CalcEngine.Functions.Function();
  335. GetTagTimeStasticValue2.prototype.evaluateMode = function () {
  336. return 0;
  337. };
  338. /*GetTimeDisplayStr.prototype.evaluateMode = function () {
  339. return 0;
  340. };*/
  341. GetTimeDisplayStr.prototype.evaluate = function (context) {
  342. //context.setAsyncResult("");
  343. //return;
  344. if (arguments.length >= 2) {
  345. ReportSelectTime = arguments[0];
  346. ReportTimeFormat = arguments[1];
  347. ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ
  348. if (!ReportSelectTime) {
  349. return "δ�ҵ�ʱ�����!";
  350. }
  351. }
  352. else {
  353. return "������������!";
  354. return;
  355. }
  356. ReportSelectTime = new Date(Date.parse(ReportSelectTime));
  357. var ReportSelectTimeStr = ReportSelectTime.Format(ReportTimeFormat);
  358. return ReportSelectTimeStr + "";
  359. }
  360. // �Զ��幫ʽ����ȡͳ��ʱ���ֵ��----------------------------------------------------------------------
  361. // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��----------------------------------------------------------------------
  362. function GetTimeStastic() {
  363. this.name = 'GetTimeStastic';
  364. this.maxArgs = 4;
  365. this.minArgs = 4;
  366. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeStastic", 0, 0]);
  367. this.typeName = "goldenNameSpace.GetTimeStastic";
  368. }
  369. goldenNameSpace.GetTimeStastic = GetTimeStastic;
  370. GetTimeStastic.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  371. GetTimeStastic.prototype.evaluateMode = function () {
  372. return 0;
  373. };
  374. GetTimeStastic.prototype.evaluateAsync = function (context) {
  375. if (arguments.length >= 5) {
  376. ReportSelectTime = arguments[1];
  377. ReportTimeType = arguments[2];
  378. ReportSelectType = arguments[3];
  379. ReportTimeFormat = arguments[4];
  380. ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ
  381. }
  382. else {
  383. context.setAsyncResult("error!");
  384. return;
  385. }
  386. ReportSelectTime = new Date(Date.parse(ReportSelectTime));
  387. if (ReportTimeType == 'd') {
  388. if (ReportSelectType == "start") {
  389. ReportSelectTime.setHours(0);
  390. ReportSelectTime.setMinutes(0);
  391. ReportSelectTime.setSeconds(0);
  392. }
  393. else {
  394. ReportSelectTime.setHours(23);
  395. ReportSelectTime.setMinutes(59);
  396. ReportSelectTime.setSeconds(59);
  397. }
  398. }
  399. else if (ReportTimeType == 'm') {
  400. if (ReportSelectType == "start") {
  401. ReportSelectTime.setSeconds(0);
  402. }
  403. else {
  404. ReportSelectTime.setSeconds(59);
  405. }
  406. }
  407. else if (ReportTimeType == 'h') {
  408. if (ReportSelectType == "start") {
  409. ReportSelectTime.setMinutes(0);
  410. ReportSelectTime.setSeconds(0);
  411. }
  412. else {
  413. ReportSelectTime.setMinutes(59);
  414. ReportSelectTime.setSeconds(59);
  415. }
  416. }
  417. else if (ReportTimeType == 'M') {
  418. if (ReportSelectType == "start") {
  419. ReportSelectTime.setDate(1);
  420. ReportSelectTime.setHours(0);
  421. ReportSelectTime.setMinutes(0);
  422. ReportSelectTime.setSeconds(0);
  423. }
  424. else {
  425. ReportSelectTime.setMonth(ReportSelectTime.getMonth() + 1);
  426. ReportSelectTime.setDate(0);
  427. ReportSelectTime.setHours(23);
  428. ReportSelectTime.setMinutes(59);
  429. ReportSelectTime.setSeconds(59);
  430. }
  431. }
  432. else if (ReportTimeType == 'y') {
  433. if (ReportSelectType == "start") {
  434. ReportSelectTime.setMonth(0);
  435. ReportSelectTime.setDate(1);
  436. ReportSelectTime.setHours(0);
  437. ReportSelectTime.setMinutes(0);
  438. ReportSelectTime.setSeconds(0);
  439. }
  440. else {
  441. var year = ReportSelectTime.getYear();
  442. ReportSelectTime.setYear(year + 1 + 1900);
  443. ReportSelectTime.setMonth(0);
  444. ReportSelectTime.setDate(0);
  445. ReportSelectTime.setHours(23);
  446. ReportSelectTime.setMinutes(59);
  447. ReportSelectTime.setSeconds(59);
  448. }
  449. }
  450. var ReportSelectTimeStr = ReportSelectTime.Format(ReportTimeFormat);
  451. context.setAsyncResult(ReportSelectTimeStr);
  452. }
  453. // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��----------------------------------------------------------------------
  454. // �Զ��幫ʽ����ȡʱ��εĵȼ����ʾ��----------------------------------------------------------------------
  455. function GetTimeInterval() {
  456. this.name = 'GetTimeInterval';
  457. this.maxArgs = 6;
  458. this.minArgs = 6;
  459. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeInterval", 0, 0]);
  460. this.typeName = "goldenNameSpace.GetTimeInterval";
  461. }
  462. GetTimeInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  463. GetTimeInterval.prototype.defaultValue = function () { return 'loading' };
  464. GetTimeInterval.prototype.evaluateMode = function () {
  465. return 0;
  466. };
  467. goldenNameSpace.GetTimeInterval = GetTimeInterval;
  468. //��ȡ��ʷ�ȼ������
  469. GetTimeInterval.prototype.evaluateAsync = function (context) {
  470. var args = arguments;
  471. var curCol = context.col;
  472. var curRow = context.row;
  473. if (args.length >= 6) {
  474. var ReportStartTime = args[1];
  475. var ReportEndTime = args[2];
  476. var ReportInterval = args[3];
  477. var ReportIntervalType = args[4];
  478. var ReportTimeFormat = args[5];
  479. var ReportVH = args[6];
  480. ReportStartTime = window[ReportStartTime];
  481. ReportEndTime = window[ReportEndTime];
  482. if (ReportStartTime == "")
  483. return;
  484. if (ReportEndTime == "")
  485. return;
  486. //ReportInterval= window[ReportInterval];
  487. //ReportIntervalType = window[ReportIntervalType];
  488. }
  489. else {
  490. context.setAsyncResult(0);
  491. return;
  492. }
  493. //清除原数据
  494. var clearNum = 0;
  495. var sheet = context.ctx.source;
  496. if (ReportIntervalType == 'd') {
  497. clearNum = 31;
  498. }
  499. else if (ReportIntervalType == 'm') {
  500. clearNum = 60;
  501. }
  502. else if (ReportIntervalType == 'h') {
  503. clearNum = 24;
  504. }
  505. var sheet = context.ctx.source;
  506. for (var kk = 0; kk < clearNum; kk++) {
  507. if (ReportVH == "v") {
  508. if (curRow + kk < sheet.getRowCount() && curCol < sheet.getColumnCount())
  509. sheet.setValue(curRow + kk, curCol, "");
  510. }
  511. else if (ReportVH == "h") {
  512. if (curRow < sheet.getRowCount() && curCol + kk < sheet.getColumnCount())
  513. sheet.setValue(curRow, curCol + kk, "");
  514. }
  515. }
  516. var tempDateTime = new Date(Date.parse(ReportStartTime));
  517. var tempEndTime = new Date(Date.parse(ReportEndTime));
  518. var sheet = context.ctx.source;
  519. for (var i = 0; i < 200; i++) {
  520. var tempDateStr = tempDateTime.Format(ReportTimeFormat);
  521. if (i == 0) {
  522. context.setAsyncResult(tempDateStr);
  523. //sheet.setValue(curRow,curCol,tempDateStr);
  524. }
  525. else if (ReportVH == "v") {
  526. if (curRow + i < sheet.getRowCount() && curCol < sheet.getColumnCount())
  527. sheet.setValue(curRow + i, curCol, tempDateStr);
  528. }
  529. else if (ReportVH == "h") {
  530. if (curRow < sheet.getRowCount() && curCol + i < sheet.getColumnCount())
  531. sheet.setValue(curRow, curCol + i, tempDateStr);
  532. }
  533. if (ReportIntervalType == 's') {
  534. tempDateTime.setSeconds(tempDateTime.getSeconds() + ReportInterval);
  535. }
  536. else if (ReportIntervalType == 'm') {
  537. tempDateTime.setMinutes(tempDateTime.getMinutes() + ReportInterval);
  538. }
  539. else if (ReportIntervalType == 'h') {
  540. tempDateTime.setHours(tempDateTime.getHours() + ReportInterval);
  541. }
  542. else if (ReportIntervalType == 'd') {
  543. tempDateTime.setDate(tempDateTime.getDate() + ReportInterval);
  544. }
  545. else if (ReportIntervalType == 'M') {
  546. tempDateTime.setMonth(tempDateTime.getMonth() + ReportInterval);
  547. }
  548. else if (ReportIntervalType == 'y') {
  549. tempDateTime.setYear(tempDateTime.getYear() + ReportInterval);
  550. }
  551. if (tempDateTime >= tempEndTime)
  552. break;
  553. }
  554. ReportAnsnDoneNum++;
  555. //tempDateTime=new Date(Date.parse(ReportStartTime));
  556. //tempDateStr=tempDateTime.Format(ReportTimeFormat);
  557. //context.setAsyncResult(tempDateStr);
  558. }
  559. // �Զ��幫ʽ����ȡʱ��εĵȼ����ʾ��----------------------------------------------------------------------
  560. // �Զ��幫ʽ����ȡ��ȡ��ʷ�ȼ�����ݣ�----------------------------------------------------------------------
  561. function GetTagHisInterval() {
  562. this.name = 'GetTagHisInterval';
  563. this.maxArgs = 6;
  564. this.minArgs = 6;
  565. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagHisInterval", 0, 0]);
  566. this.typeName = "goldenNameSpace.GetTagHisInterval";
  567. }
  568. goldenNameSpace.GetTagHisInterval = GetTagHisInterval;
  569. GetTagHisInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  570. GetTagHisInterval.prototype.defaultValue = function () { return 'loading' };
  571. GetTagHisInterval.prototype.evaluateMode = function () {
  572. return 0;
  573. };
  574. GetTagHisInterval.prototype.interval = function () {
  575. return 1000;
  576. };
  577. //��ȡ��ʷ�ȼ������
  578. GetTagHisInterval.prototype.evaluateAsync = function (context) {
  579. var args = arguments;
  580. var curCol = context.col;
  581. var curRow = context.row;
  582. var ReportIntervalSumType = "snap";
  583. var valueCount = 0;
  584. if (args.length >= 5) {
  585. var Reporttag = args[1];
  586. var ReportStartTime = args[2];
  587. var ReportEndTime = args[3];
  588. var ReportInterval = args[4];
  589. var ReportIntervalType = args[5];
  590. ReportIntervalSumType = args[6]; //ͳ������ ��min,max
  591. var ReportVH = args[7];
  592. ReportStartTime = window[ReportStartTime];
  593. ReportEndTime = window[ReportEndTime];
  594. if (ReportStartTime == "")
  595. {ReportAnsnDoneNum++;
  596. return;
  597. }
  598. if (ReportEndTime == "")
  599. {ReportAnsnDoneNum++;
  600. return;
  601. }
  602. //ReportInterval= window[ReportInterval];
  603. //ReportIntervalType= "0";// window[ReportIntervalType];
  604. }
  605. else
  606. {
  607. ReportAnsnDoneNum++;
  608. context.setAsyncResult(0);
  609. return;
  610. }
  611. var TempEndTime = new Date(Date.parse(ReportEndTime));
  612. var TempStartTime = new Date(Date.parse(ReportStartTime));
  613. var ReportIntervalSumTypeStr = "0";
  614. if (ReportIntervalSumType == "snap") {
  615. ReportIntervalSumTypeStr = "0";
  616. }
  617. else if (ReportIntervalSumType == "max") {
  618. ReportIntervalSumTypeStr = "1";
  619. }
  620. else if (ReportIntervalSumType == "min") {
  621. ReportIntervalSumTypeStr = "2";
  622. }
  623. else if (ReportIntervalSumType == "avg") {
  624. ReportIntervalSumTypeStr = "3";
  625. }
  626. else if (ReportIntervalSumType == "total") {
  627. ReportIntervalSumTypeStr = "4";
  628. }
  629. else {
  630. ReportIntervalSumTypeStr = "0";
  631. }
  632. if (ReportIntervalType == "m")//����
  633. {
  634. ReportInterval = ReportInterval * 60;
  635. valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 60;
  636. }
  637. else if (ReportIntervalType == "h")//Сʱ
  638. {
  639. ReportInterval = ReportInterval * 3600;
  640. valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 3600;
  641. }
  642. else if (ReportIntervalType == "d")//��
  643. {
  644. ReportInterval = ReportInterval * 3600 * 24;
  645. valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 24 / 3600;
  646. TempStartTime.setSeconds(TempStartTime.getSeconds() + 86399);//取每天23:59:59秒值
  647. }
  648. var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryInterval?tagName="; //+ cmdStr;
  649. pageIndex = 1;
  650. if (valueCount < 200)
  651. tagsCount = parseInt(valueCount + 0.5);
  652. else
  653. tagsCount = 200;
  654. urlStr += createSearchStr(Reporttag, TempStartTime, ReportEndTime, ReportInterval, ReportIntervalSumTypeStr, ReportInterval)
  655. + '&pageIndex=' + pageIndex + '&pageSize=' + tagsCount;
  656. // getTableHisData(shotTablePane,url,shotTableTableModel,shotTablecolumns,shotTablerows);
  657. $.ajax({
  658. type: 'GET',
  659. url: urlStr,
  660. dataType: 'json',
  661. cache: false,
  662. error:function(data)
  663. {
  664. ReportAnsnDoneNum++;
  665. return;
  666. },
  667. success: function (data) {
  668. if (!data.Datas && !data) {
  669. context.setAsyncResult("not find!");
  670. ReportAnsnDoneNum++;
  671. return;
  672. }
  673. var arr;
  674. if (data.Datas)
  675. arr = data.Datas;
  676. else if (data)
  677. arr = data;
  678. //清除原数据
  679. var clearNum = 0;
  680. if (ReportIntervalType == 'd') {
  681. clearNum = 31;
  682. }
  683. else if (ReportIntervalType == 'm') {
  684. clearNum = 60;
  685. }
  686. else if (ReportIntervalType == 'h') {
  687. clearNum = 24;
  688. }
  689. var sheet = context.ctx.source;
  690. for (var kk = 0; kk < clearNum; kk++) {
  691. if (ReportVH == "v") {
  692. if (curRow + kk < sheet.getRowCount() && curCol < sheet.getColumnCount())
  693. sheet.setValue(curRow + kk, curCol, "");
  694. }
  695. else if (ReportVH == "h") {
  696. if (curRow < sheet.getRowCount() && curCol + kk < sheet.getColumnCount())
  697. sheet.setValue(curRow, curCol + kk, "");
  698. }
  699. }
  700. for (var key in arr) {
  701. var tagData = arr[key];
  702. if (!tagData)
  703. continue;
  704. if (tagData.length > 0) {
  705. var showCount = 200;
  706. if (tagData.length < showCount)
  707. showCount = tagData.length;
  708. var actVal = 0;
  709. if (ReportIntervalSumType == "snap")
  710. actVal = GetDital(tagData[0].Value, 3);
  711. else if (ReportIntervalSumType == "min")
  712. actVal = GetDital(tagData[0].Min, 3);
  713. else if (ReportIntervalSumType == "max")
  714. actVal = GetDital(tagData[0].Max, 3);
  715. else if (ReportIntervalSumType == "avg")
  716. actVal = GetDital(tagData[0].CalcAvg, 3);
  717. else if (ReportIntervalSumType == "total")
  718. actVal = GetDital(tagData[0].Total, 3);
  719. context.setAsyncResult(actVal);
  720. for (var i = 0; i < showCount; i++) {
  721. if (ReportIntervalSumType == "snap")
  722. actVal = GetDital(tagData[i].Value, 3);
  723. else if (ReportIntervalSumType == "min")
  724. actVal = GetDital(tagData[i].Min, 3);
  725. else if (ReportIntervalSumType == "max")
  726. actVal = GetDital(tagData[i].Max, 3);
  727. else if (ReportIntervalSumType == "avg")
  728. actVal = GetDital(tagData[i].CalcAvg, 3);
  729. else if (ReportIntervalSumType == "total")
  730. actVal = GetDital(tagData[i].Total, 3);
  731. if (ReportVH == "v") {
  732. if (curRow + i < sheet.getRowCount() && curCol < sheet.getColumnCount())
  733. sheet.setValue(curRow + i, curCol, actVal);
  734. }
  735. else if (ReportVH == "h") {
  736. if (curRow < sheet.getRowCount() && curCol + i < sheet.getColumnCount())
  737. sheet.setValue(curRow, curCol + i, actVal);
  738. }
  739. }
  740. //sheet.autoFitColumn(curCol);
  741. ReportAnsnDoneNum++;
  742. sheet.refresh();
  743. return;
  744. }
  745. else {
  746. context.setAsyncResult("not find!");
  747. ReportAnsnDoneNum++;
  748. return;
  749. }
  750. break;
  751. }
  752. var sheet = context.ctx.source;
  753. sheet.refresh();
  754. ReportAnsnDoneNum++;
  755. }
  756. })
  757. }
  758. //�����ȼ����ʷ��ѯ�IJ�ѯ�ַ���
  759. function createSearchStr(tagNameStr, beginTime, endTime, interval, valueType, count) {
  760. beginTime = moment(new Date(beginTime)).format("YYYY-MM-DD H:mm:ss");
  761. endTime = moment(new Date(endTime)).format("YYYY-MM-DD H:mm:ss");
  762. interval = interval || 10;
  763. //valueType = valueType || 1;
  764. count = Math.floor((new Date(endTime) - new Date(beginTime)) / interval / 1000);
  765. var result = '';
  766. var tagsInfo = encodeURIComponent(tagNameStr);
  767. result = tagsInfo + '&beginTime=' + beginTime + '&endTime=' + endTime + '&interval=' + interval + '&count=' + count;
  768. if (valueType !== '0') {
  769. result += '&valueType=' + valueType;
  770. }
  771. return result;
  772. }
  773. // �Զ��幫ʽ����ȡ��ȡ��ʷ�ȼ�����ݣ�----------------------------------------------------------------------
  774. // �Զ��幫ʽ����ȡ����ֵ��----------------------------------------------------------------------
  775. function GetTagSnapShort() {
  776. this.name = 'GETTAGSNAPSHORT';
  777. this.maxArgs = 2;
  778. this.minArgs = 2;
  779. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagSnapShort", 0, 0]);
  780. this.typeName = "goldenNameSpace.GetTagSnapShort";
  781. }
  782. goldenNameSpace.GetTagSnapShort = GetTagSnapShort;
  783. GetTagSnapShort.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  784. GetTagSnapShort.prototype.defaultValue = function () { return 'loading' };
  785. GetTagSnapShort.prototype.evaluateMode = function () {
  786. return 0;
  787. };
  788. GetTagSnapShort.prototype.interval = function () {
  789. return 1000;
  790. };
  791. GetTagSnapShort.prototype.evaluateAsync = function (context) {
  792. var args = arguments;
  793. if (args.length > 1)
  794. tag = args[1];
  795. else {
  796. context.setAsyncResult(0);
  797. return;
  798. }
  799. var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot?tagName=";
  800. var para = tag;
  801. str = str + encodeURIComponent(para);
  802. $.ajax({
  803. url: str,
  804. type: 'GET',
  805. dataType: 'json',
  806. cache: false,
  807. success: function (data) {
  808. if (data === null) return;
  809. var snapshots = eval(data);
  810. //�жϿ����Ƿ�Ϊ��
  811. if (snapshots != null) {
  812. var value = 0;
  813. if (snapshots.length > 0)
  814. value = snapshots[0].Value;
  815. var actVal = GetDital(value, 3);
  816. context.setAsyncResult(actVal);
  817. }
  818. },
  819. complete: function (XHR, TS) {
  820. XHR = null;
  821. }
  822. }
  823. );
  824. }
  825. // �Զ��幫ʽ����ȡ����ֵ��----------------------------------------------------------------------
  826. // �Զ��幫ʽ����ȡ��ʷʱ��ֵ��----------------------------------------------------------------------
  827. function GetTagHisValue() {
  828. this.name = 'GETTAGHISVALUE';
  829. this.maxArgs = 3;
  830. this.minArgs = 2;
  831. GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagHisValue", 0, 0]);
  832. this.typeName = "goldenNameSpace.GetTagHisValue";
  833. }
  834. goldenNameSpace.GetTagHisValue = GetTagHisValue;
  835. //ͬ����ʽ
  836. GetTagHisValue.prototype = new GC.Spread.CalcEngine.Functions.Function();
  837. GetTagHisValue.prototype.defaultValue = function () { return 'loading' };
  838. GetTagHisValue.prototype.evaluateMode = function () {
  839. return 0;
  840. };
  841. GetTagHisValue.prototype.interval = function () {
  842. return 1000;
  843. };
  844. GetTagHisValue.prototype.evaluate = function (context) {
  845. var args = arguments;
  846. var tag = "";
  847. var hisTimeStr = "";
  848. if (args.length > 1) {
  849. tag = args[0];
  850. if (tag.indexOf("WT1.") >= 0) {
  851. var ssssss = 1;
  852. }
  853. hisTimeStr = args[1];
  854. if (!hisTimeStr) {
  855. //context.setAsyncResult(0);
  856. return 0;
  857. }
  858. hisTimeStr = window[hisTimeStr];
  859. if (!hisTimeStr) {
  860. // context.setAsyncResult(0);
  861. return 0;
  862. }
  863. var tempTime = new Date(Date.parse(hisTimeStr));
  864. if (!tempTime) {
  865. // context.setAsyncResult(0);
  866. return 0;
  867. }
  868. //偏移秒
  869. var addSec=0;
  870. if(args.length>=3)
  871. {
  872. addSec=parseInt(args[2]);
  873. tempTime.setSeconds( tempTime.getSeconds()+addSec);
  874. }
  875. var vv = GetReportTagHisValue(tempTime, tag);
  876. if (!vv) {
  877. //context.setAsyncResult(0);
  878. return 0;
  879. }
  880. else {
  881. // context.setAsyncResult( vv);
  882. return parseFloat(vv);
  883. }
  884. }
  885. else {
  886. // context.setAsyncResult(0);
  887. return 0;
  888. }
  889. }
  890. /* �첽��ʽ
  891. GetTagHisValue.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  892. GetTagHisValue.prototype.defaultValue = function () {return 'loading'};
  893. GetTagHisValue.prototype.evaluateMode = function () {
  894. return 0;
  895. };
  896. GetTagHisValue.prototype.interval = function () {
  897. return 1000;
  898. };
  899. GetTagHisValue.prototype.evaluateAsync = function (context)
  900. {
  901. var args = arguments;
  902. var tag="";
  903. var hisTimeStr="";
  904. if(args.length>1)
  905. {
  906. tag=args[1];
  907. if(tag.indexOf("WT1.")>=0)
  908. {
  909. var ssssss=1;
  910. }
  911. hisTimeStr=args[2];
  912. if(!hisTimeStr)
  913. {
  914. context.setAsyncResult(0);
  915. return;
  916. }
  917. hisTimeStr=window[hisTimeStr];
  918. if(!hisTimeStr)
  919. {
  920. context.setAsyncResult(0);
  921. return;
  922. }
  923. var tempTime=new Date(Date.parse(hisTimeStr));
  924. if(!tempTime)
  925. {
  926. context.setAsyncResult(0);
  927. return;
  928. }
  929. var vv=GetReportTagHisValue(tempTime,tag);
  930. if(!vv)
  931. {
  932. context.setAsyncResult(0);
  933. return;
  934. }
  935. else
  936. context.setAsyncResult( vv);
  937. }
  938. else
  939. {
  940. context.setAsyncResult(0);
  941. return;
  942. }
  943. }*/
  944. })();
  945. // ��Date����չ���� Date ת��Ϊָ����ʽ��String
  946. // ��(M)����(d)��Сʱ(h)����(m)����(s)������(q) ������ 1-2 ��ռλ����
  947. // ��(y)������ 1-4 ��ռλ��������(S)ֻ���� 1 ��ռλ��(�� 1-3 λ������)
  948. // ���ӣ�
  949. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  950. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  951. Date.prototype.Format = function (fmt) { //author: meizz
  952. var o = {
  953. "M+": this.getMonth() + 1, //�·�
  954. "d+": this.getDate(), //��
  955. "h+": this.getHours(), //Сʱ
  956. "m+": this.getMinutes(), //��
  957. "s+": this.getSeconds(), //��
  958. "q+": Math.floor((this.getMonth() + 3) / 3), //����
  959. "S": this.getMilliseconds() //����
  960. };
  961. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  962. for (var k in o)
  963. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  964. return fmt;
  965. }
  966. //��Ҫ��ѯ��ʱ��ֵ
  967. function TagHisValueInfo() {
  968. var time = "";
  969. var tagArray = new Array();
  970. }
  971. //��ǩ�ṹ
  972. function ReportTagHisValueObj() {
  973. var tag = "";
  974. var val = 0;
  975. }
  976. //��Ҫ��ѯ��ͳ����Ϣ
  977. function TagStasticSearchInfo() {
  978. var startTime;
  979. var endTime;
  980. var tagArray = new Array();
  981. }
  982. //��ǩ�ṹ
  983. function ReportTagStasticObj() {
  984. var tag = "";
  985. var Min = "";
  986. var Max = "";
  987. var Diff = "";
  988. var Avg = "";
  989. var Total = "";
  990. var CalcTotal = "";//算术求和
  991. }
  992. //��ȡ��ʷʱ��ֵ
  993. function GetReportTagHisValue(tTime, tagstr) {
  994. for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) {
  995. var tagInfo = ReportTagHisValueSearchInfoList[i];
  996. if (tagInfo.time.getTime() == tTime.getTime())//ʱ����ͬ
  997. {
  998. var ttTag = tagInfo.tagArray[tagstr];
  999. if (!ttTag)
  1000. return "";
  1001. return ttTag.val;
  1002. }
  1003. }
  1004. }
  1005. //��ȡͳ��ֵ
  1006. function GetTagStasticSearchValue(sTime, eTime, tag, tagType) {
  1007. for (var i = 0; i < TagStasticSearchInfoList.length; i++) {
  1008. var tagInfo = TagStasticSearchInfoList[i];
  1009. if (tagInfo.startTime.getTime() == sTime.getTime() && tagInfo.endTime.getTime() == eTime.getTime()) {
  1010. var tempTag = tag;
  1011. var dayNum = (tagInfo.endTime.getTime() - tagInfo.startTime.getTime()) / 1000 / 24 / 3600;//����
  1012. //if((tagInfo.endTime.getTime()-tagInfo.startTime.getTime())/1000/24/3600>0.5&&
  1013. if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //����2�죬��ȡ��С�����ƽ��ȡͳ��ֵ
  1014. {
  1015. tempTag = tempTag.replace(".", "_");
  1016. tempTag = "report." + tempTag + "_" + tagType;
  1017. }
  1018. else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ
  1019. {
  1020. tempTag = tempTag.replace(".", "_");
  1021. tempTag = "report." + tempTag + "_diff";
  1022. }
  1023. var ttTag = tagInfo.tagArray[tempTag];
  1024. if (!ttTag)
  1025. return "";
  1026. if (ttTag.tag == tempTag) {
  1027. if (tagType == "min")
  1028. return ttTag.Min;
  1029. else if (tagType == "max")
  1030. return ttTag.Max;
  1031. else if (tagType == "diff")
  1032. return ttTag.CalcTotal;//ƽ��ֵ*��������ʾÿ���ֵ�ĺͣ���Ϊ�ܲ�ֵ
  1033. else if (tagType == "sub")
  1034. return ttTag.CalcTotal;
  1035. else if (tagType == "dif")
  1036. return ttTag.CalcTotal;
  1037. else
  1038. return ttTag.Avg;
  1039. }
  1040. }
  1041. }
  1042. return "";
  1043. }
  1044. //��Ӱ�ʱ��ֵ��ѯ����
  1045. function AddToTagHisValueArray(time, tag) {
  1046. if (!time)
  1047. return;
  1048. if (!tag)
  1049. return;
  1050. for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) {
  1051. var tagInfo = ReportTagHisValueSearchInfoList[i];
  1052. if (tagInfo.time.getTime() == time.getTime())//ʱ����ͬ
  1053. {
  1054. var tagObj = tagInfo.tagArray[tag];
  1055. if (!tagObj) {
  1056. var tagObj = new ReportTagHisValueObj();
  1057. tagObj.tag = tag;
  1058. tagObj.val = 0;
  1059. tagInfo.tagArray[tag] = tagObj;
  1060. }
  1061. return;
  1062. }
  1063. }
  1064. var tempInfo = new TagHisValueInfo();
  1065. tempInfo.time = time;
  1066. tempInfo.tagArray = new Array();
  1067. ReportTagHisValueSearchInfoList.push(tempInfo);
  1068. var tagObj = new ReportTagHisValueObj();
  1069. tagObj.tag = tag;
  1070. tempInfo.tagArray[tag] = tagObj;
  1071. }
  1072. //��Ӳ�ѯ��Ϣ ��������ʼʱ�䣬����ʱ�䣬��ǩ��
  1073. function AddToTagStasticSearchArray(sTime, eTime, tag) {
  1074. for (var i = 0; i < TagStasticSearchInfoList.length; i++) {
  1075. var tagInfo = TagStasticSearchInfoList[i];
  1076. if (tagInfo.startTime.getTime() == sTime.getTime() && tagInfo.endTime.getTime() == eTime.getTime()) {
  1077. var tagObj = tagInfo.tagArray[tag];
  1078. if (!tagObj) {
  1079. var tagObj = new ReportTagStasticObj();
  1080. tagObj.tag = tag;
  1081. tagObj.Min = 0;
  1082. tagObj.Max = 0;
  1083. tagObj.Avg = 0;
  1084. tagObj.Total = 0;
  1085. tagObj.Diff = 0;
  1086. tagInfo.tagArray[tag] = tagObj;
  1087. }
  1088. return;
  1089. }
  1090. }
  1091. var tempInfo = new TagStasticSearchInfo();
  1092. tempInfo.startTime = sTime;
  1093. tempInfo.endTime = eTime;
  1094. tempInfo.tagArray = new Array();
  1095. TagStasticSearchInfoList.push(tempInfo);
  1096. var tagObj = new ReportTagStasticObj();
  1097. tagObj.tag = tag;
  1098. tempInfo.tagArray[tag] = tagObj;
  1099. }
  1100. //�������й�ʽ����ӵ����Ե��б�
  1101. function AnalysisAllFunc(funcArray) {
  1102. if (!funcArray)
  1103. return;
  1104. for (var i = 0; i < funcArray.length; i++) {
  1105. var calcu = funcArray[i];
  1106. if (!calcu)
  1107. continue;
  1108. if (calcu.funcName == "GetTagHisValue")//ͳ��ʱ��ֵ������
  1109. {
  1110. var parmArray = calcu.parmList;
  1111. if (!parmArray)
  1112. continue;
  1113. if (parmArray.length >= 2) {
  1114. var tagStr = parmArray[0];
  1115. var timeStr = parmArray[1];
  1116. var ReportTime = window[timeStr];
  1117. if (!ReportTime)
  1118. continue;
  1119. var tempTime = new Date(Date.parse(ReportTime));
  1120. if (!tempTime)
  1121. continue;
  1122. //偏移秒
  1123. var addSec=0;
  1124. if(parmArray.length>=3)
  1125. {
  1126. addSec=parseInt(parmArray[2]);
  1127. tempTime.setSeconds( tempTime.getSeconds()+addSec);
  1128. }
  1129. AddToTagHisValueArray(tempTime, tagStr);
  1130. }
  1131. }
  1132. else if (calcu.funcName == "GetTagTimeStasticValue")//ͳ��ʱ���ֵ����,���£����꣬����ʱ���
  1133. {
  1134. var parmArray = calcu.parmList;
  1135. if (!parmArray)
  1136. continue;
  1137. if (parmArray.length >= 4) {
  1138. var tagStr = parmArray[0];
  1139. var timeStr = parmArray[1];
  1140. var ReportTimeType = parmArray[2];
  1141. var tagType = parmArray[3];
  1142. var ReportTime = window[timeStr];
  1143. if (!ReportTime)
  1144. return 0;
  1145. var tempStartTime = new Date(Date.parse(ReportTime));;
  1146. var tempEndTime = new Date(Date.parse(ReportTime));;
  1147. if (ReportTimeType == 'd' || ReportTimeType == 'D') {
  1148. tempStartTime.setHours(0);
  1149. tempStartTime.setMinutes(0);
  1150. tempStartTime.setSeconds(0);
  1151. tempEndTime.setHours(23);
  1152. tempEndTime.setMinutes(59);
  1153. tempEndTime.setSeconds(59);
  1154. }
  1155. else if (ReportTimeType == 'm' || ReportTimeType == 'M') {
  1156. tempStartTime.setDate(1);
  1157. tempStartTime.setHours(0);
  1158. tempStartTime.setMinutes(0);
  1159. tempStartTime.setSeconds(0);
  1160. tempEndTime.setMonth(tempEndTime.getMonth() + 1);
  1161. tempEndTime.setDate(0);
  1162. tempEndTime.setHours(23);
  1163. tempEndTime.setMinutes(59);
  1164. tempEndTime.setSeconds(59);
  1165. }
  1166. else if (ReportTimeType == 'y' || ReportTimeType == 'Y') {
  1167. tempStartTime.setMonth(0);
  1168. tempStartTime.setDate(1);
  1169. tempStartTime.setHours(0);
  1170. tempStartTime.setMinutes(0);
  1171. tempStartTime.setSeconds(0);
  1172. var year = tempEndTime.getYear();
  1173. tempEndTime.setYear(year + 1 + 1900);
  1174. tempEndTime.setMonth(0);
  1175. tempEndTime.setDate(0);
  1176. tempEndTime.setHours(23);
  1177. tempEndTime.setMinutes(59);
  1178. tempEndTime.setSeconds(59);
  1179. }
  1180. if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //��С�����ƽ��ȡͳ��ֵ
  1181. {
  1182. tagStr = tagStr.replace(".", "_");
  1183. tagStr = "report." + tagStr + "_" + tagType;
  1184. AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr);
  1185. }
  1186. else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ
  1187. {
  1188. tagStr = tagStr.replace(".", "_");
  1189. tagStr = "report." + tagStr + "_diff";
  1190. AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr);
  1191. }
  1192. }
  1193. }
  1194. else if (calcu.funcName == "GetTagTimeStasticValue2")//ͳ��ʱ���ֵ����
  1195. {
  1196. var parmArray = calcu.parmList;
  1197. if (!parmArray)
  1198. continue;
  1199. if (parmArray.length >= 4) {
  1200. var tagStr = parmArray[0];
  1201. var startTimeStr = parmArray[1];
  1202. var endTimeStr = parmArray[2];
  1203. var tagType = parmArray[3];
  1204. tagStr = tagStr.replace("\"", "");
  1205. startTimeStr = startTimeStr.replace("\"", "");
  1206. endTimeStr = endTimeStr.replace("\"", "");
  1207. tagType = tagType.replace("\"", "");
  1208. tagStr = tagStr.replace("\"", "");
  1209. startTimeStr = startTimeStr.replace("\"", "");
  1210. endTimeStr = endTimeStr.replace("\"", "");
  1211. tagType = tagType.replace("\"", "");
  1212. var ReportStartTime = window[startTimeStr];
  1213. var ReportEndTime = window[endTimeStr];
  1214. var tempStartTime = new Date(Date.parse(ReportStartTime));
  1215. var tempEndTime = new Date(Date.parse(ReportEndTime));
  1216. //if((tempEndTime.getTime()-tempStartTime.getTime())/1000/24/3600>0.5&&
  1217. if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //��С�����ƽ��ȡͳ��ֵ
  1218. {
  1219. tagStr = tagStr.replace(".", "_");
  1220. tagStr = "report." + tagStr + "_" + tagType;
  1221. AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr);
  1222. }
  1223. else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ
  1224. {
  1225. tagStr = tagStr.replace(".", "_");
  1226. tagStr = "report." + tagStr + "_diff";
  1227. AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr);
  1228. }
  1229. }
  1230. }
  1231. }
  1232. }
  1233. //����spread��ʽ
  1234. function resetSpread(spread) {
  1235. var sheet = spread.getSheet(0);
  1236. sheet.options.colHeaderVisible = false;
  1237. sheet.options.rowHeaderVisible = false;
  1238. spread.options.newTabVisible = false;
  1239. spread.options.tabStripVisible = false;
  1240. spread.options.showHorizontalScrollbar = true;
  1241. //���ݱ�����������ʾ����������ֻ�ܻ�����β
  1242. spread.options.scrollbarMaxAlign = true;
  1243. //spread.options.scrollbarShowMax=true;
  1244. spread.verticalScrollBarWidth = 10;
  1245. }
  1246. //���뱨���json����
  1247. function importJSON(spread, jsonData) {
  1248. if (!spread)
  1249. return;
  1250. var start = new Date();
  1251. spread.suspendPaint();
  1252. //ApplyCustomFunc(spread);
  1253. ApplyCustomFunc(spread);
  1254. spread.fromJSON(jsonData);
  1255. //var json = spread.toJSON();
  1256. //spread.fromJSON(json);
  1257. resetSpread(spread);
  1258. spread.resumePaint();
  1259. //ResetFormular(spread);
  1260. var useTime = (new Date() - start);
  1261. console.log("import use time:" + useTime);
  1262. }
  1263. //ˢ�±���
  1264. function FreshReport(spread, exportFileName, isWhiteBackBlackFont, jsonFuncData) {
  1265. if (!spread)
  1266. return;
  1267. var fStartTime = new Date();
  1268. var curSheet = spread.getActiveSheet();
  1269. if (!curSheet)
  1270. return;
  1271. TagStasticSearchInfoList = new Array();//����б�
  1272. ReportTagHisValueSearchInfoList = new Array();////����б�
  1273. ReportAnsnDoneNum = 0;
  1274. setInterval(function()//����첽����ȫ����ɺ�ִ�з��Զ���ļ���
  1275. {
  1276. if(parseInt(ReportAnsnDoneNum)>=parseInt(ReportAnsnFuncNum))//����ȫ�����
  1277. {
  1278. ReportAnsnDoneNum=0;
  1279. DoNoCustomFunc(spread);
  1280. }
  1281. },500);
  1282. //spread.resumeCalcService();//ˢ�±�����ִ�����к�����
  1283. //GetAllTag(spread);//�����ѵĽ��������ٶ�,2018-1-27���޸ģ�������ʱ����������õ��ĺ���
  1284. //DoCustomNoAnsnFunc(spread);
  1285. //������ʽ������
  1286. AnalysisAllFunc(jsonFuncData);
  1287. //û��ͳ�Ʋ�ѯʱ
  1288. if (TagStasticSearchInfoList.length <= 0 && ReportTagHisValueSearchInfoList.length <= 0) {
  1289. spread.resumeCalcService();//ˢ�±�����ִ�����к�����
  1290. ResetFormular(spread)
  1291. spread.repaint();
  1292. if (exportFileName)
  1293. SpreadExport(spread, exportFileName);
  1294. isExporting = false;
  1295. return;
  1296. }
  1297. //�ܵIJ�ѯ����
  1298. var TotalSearchNum = TagStasticSearchInfoList.length + ReportTagHisValueSearchInfoList.length;
  1299. var ReceiveNum = 0;
  1300. //��ȡʱ���ͳ��ֵ������
  1301. var midTime = new Date();
  1302. console.log("analysis func use time:" + (midTime - fStartTime));
  1303. for (var i = 0; i < TagStasticSearchInfoList.length; i++)
  1304. {
  1305. (function ()//将请求和返回放入一个函数,保证变量对应
  1306. {
  1307. var tagSearch1 = TagStasticSearchInfoList[i];
  1308. if (!tagSearch1)
  1309. return;
  1310. var ssTime = tagSearch1.startTime;
  1311. var eeTime = tagSearch1.endTime;
  1312. var tagStr = "";
  1313. for (var key in tagSearch1.tagArray) {
  1314. tagStr += key + ",";
  1315. }
  1316. var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistorySummary?tagName=";
  1317. urlStr += tagStr + "&beginTime=" + ssTime.Format("yyyy-MM-dd hh:mm:ss") + "&endTime=" + eeTime.Format("yyyy-MM-dd hh:mm:ss") + "&dataType=snap";
  1318. $.ajax({
  1319. type: 'GET',
  1320. url: urlStr,
  1321. dataType: 'json',
  1322. cache: true,
  1323. error: function (data) {
  1324. console.log("HistorySummary error!");
  1325. },
  1326. success: function (data) {
  1327. if (!data)
  1328. return;
  1329. for (var key in data) {
  1330. //console.log("answer:"+key);
  1331. var tagData = data[key];
  1332. if (!tagData)
  1333. continue;
  1334. var ttTag = tagSearch1.tagArray[key];
  1335. if (!ttTag)
  1336. continue;
  1337. if (ttTag.tag == key) {
  1338. ttTag.Min = GetDital(tagData.Min, 3);
  1339. ttTag.Max = GetDital(tagData.Max, 3);
  1340. ttTag.Avg = GetDital(tagData.CalcAvg, 3);
  1341. ttTag.Diff = GetDital(tagData.Difference, 3);
  1342. ttTag.Total = GetDital(tagData.Total, 3);
  1343. ttTag.CalcTotal = GetDital(tagData.CalcTotal, 3);
  1344. }
  1345. }
  1346. ReceiveNum++;
  1347. if (ReceiveNum >= TotalSearchNum)//ȫ�����غ�ˢ��ҳ������
  1348. {
  1349. spread.resumeCalcService();//ˢ�±�����ִ�����к�����
  1350. ResetFormular(spread)
  1351. spread.repaint();
  1352. midTime = new Date();
  1353. console.log("get data use time:" + (midTime - fStartTime));
  1354. console.log("-----------------------------------");
  1355. if (exportFileName)
  1356. SpreadExport(spread, exportFileName, isWhiteBackBlackFont);
  1357. isExporting = false;
  1358. }
  1359. }
  1360. });
  1361. }());
  1362. }
  1363. //��ȡ��ʷʱ��ֵ
  1364. for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) {
  1365. (function ()//将请求和返回放入一个函数,保证变量对应
  1366. {
  1367. var tagSearch = ReportTagHisValueSearchInfoList[i];
  1368. if (!tagSearch)
  1369. return;
  1370. var ssTime = tagSearch.time;
  1371. var tagStr = "";
  1372. for (var keys in tagSearch.tagArray) {
  1373. tagStr += keys + ",";
  1374. }
  1375. var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/History?tagName=";
  1376. urlStr += tagStr + "&time=" + ssTime.Format("yyyy-MM-dd hh:mm:ss");
  1377. $.ajax({
  1378. type: 'GET',
  1379. url: urlStr,
  1380. dataType: 'json',
  1381. cache: true,
  1382. error: function (data) {
  1383. console.log("HistorySummary error!");
  1384. },
  1385. success: function (data) {
  1386. if (!data)
  1387. return;
  1388. for (var key in data) {
  1389. //console.log("answer:"+key);
  1390. var tagData = data[key];
  1391. if (!tagData)
  1392. return;
  1393. var ttTag = tagSearch.tagArray[key];
  1394. if (!ttTag)
  1395. return;
  1396. if (ttTag.tag == key) {
  1397. ttTag.val = GetDital(tagData.Value, 3);
  1398. }
  1399. }
  1400. ReceiveNum++;
  1401. if (ReceiveNum >= TotalSearchNum)//ȫ�����غ�ˢ��ҳ������
  1402. {
  1403. spread.resumeCalcService();//ˢ�±�����ִ�����к�����
  1404. ResetFormular(spread)
  1405. spread.repaint();
  1406. midTime = new Date();
  1407. console.log("get data use time:" + (midTime - fStartTime));
  1408. console.log("-----------------------------------");
  1409. if (exportFileName)
  1410. SpreadExport(spread, exportFileName, isWhiteBackBlackFont);
  1411. isExporting = false;
  1412. }
  1413. }
  1414. });
  1415. }());
  1416. }
  1417. var doneFreshTime = new Date();
  1418. console.log("done fresh report use time:" + (doneFreshTime - fStartTime));
  1419. }
  1420. function SpreadExport(spread, exportFileName, isChangeBackFont) {
  1421. var fileName = exportFileName + '.xlsx';
  1422. if (fileName.substr(-5, 5) !== '.xlsx') {
  1423. fileName += '.xlsx';
  1424. }
  1425. var json = spread.toJSON();
  1426. sheet1 = spread.getActiveSheet();
  1427. var spread2 = new GC.Spread.Sheets.Workbook();
  1428. spread2.fromJSON(json);
  1429. var sheet2 = spread2.getActiveSheet();
  1430. var array = sheet1.getArray(0, 0, sheet1.getRowCount(), sheet1.getColumnCount(), false);
  1431. sheet2.clear(0, 0, sheet2.getRowCount(), sheet2.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1432. sheet2.setArray(0, 0, array, false);
  1433. //����ǿ�ư׵׺���
  1434. if (parseInt(isChangeBackFont) > 0) {
  1435. var colNum = sheet2.getColumnCount();
  1436. var rowNum = sheet2.getRowCount();
  1437. spread2.options.backColor = "#ffffff";
  1438. sheet2.options.colHeaderVisible = true;
  1439. sheet2.options.rowHeaderVisible = true;
  1440. //spread2.options.grayAreaBackColor="#ffffff";
  1441. var rowstyle = new GC.Spread.Sheets.Style();
  1442. rowstyle.backColor = 'white';
  1443. rowstyle.foreColor = 'black';
  1444. rowstyle.borderColor = 'black';
  1445. for (var ii = 0; ii < rowNum; ii++) {
  1446. sheet2.setStyle(ii, -1, rowstyle, GC.Spread.Sheets.SheetArea.viewport);
  1447. }
  1448. sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).backColor("white");
  1449. sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).setBorder(new GC.Spread.Sheets.LineBorder("#aaaaaa", GC.Spread.Sheets.LineStyle.thin), { all: true }, 1);
  1450. sheet2.options.gridline = { color: "#aaaaaa", showVerticalGridline: false, showHorizontalGridline: false };
  1451. sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).foreColor('black');
  1452. }
  1453. //sheet2.options.gridline = {color:"#000000", showVerticalGridline: true, showHorizontalGridline: true};
  1454. ResetFormular(spread2);
  1455. json = spread2.toJSON();
  1456. // here is excel IO API
  1457. excelIo = new GC.Spread.Excel.IO();
  1458. excelIo.save(json, function (blob) {
  1459. saveAs(blob, fileName);
  1460. }, function (e) {
  1461. // process error
  1462. alert(e.message);
  1463. });
  1464. }