lazhang-data.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. getUserId();
  2. var RedRank = (function() {
  3. this.fetchPos = 0;
  4. this.loader = (function () {
  5. this.load = function(pos) {
  6. get_data(`fcBiWorkerDaily/get?type=${RedRank.fetchPos}`, RedRank.loader.onSuccess);
  7. };
  8. this.consecutiveLoad = function(){
  9. RedRank.fetchPos = (RedRank.fetchPos + 1) % 8;
  10. load(RedRank.fetchPos);
  11. };
  12. this.onSuccess = function(res, code){
  13. };
  14. })();
  15. })();
  16. var RANK_TBL_ROW_COUNT = 4;
  17. var goodColor = [];
  18. var badColor = [];
  19. var goodColor1 = [];
  20. var badColor1 = [];
  21. var userIDs = [];
  22. var schedulepass = 0, schedulefail = 0, schedulestack = 0;
  23. var todayotherpass = 0, todayotherfail = 0, todayotherstack = 0;
  24. var lastTimeHistory = "";
  25. var histoires = [];
  26. var hispass = [];
  27. var hisfail = [];
  28. var hisstack = [];
  29. var hisrate = [];
  30. var goodpass = [];
  31. var goodid = [];
  32. var goodfailrate = [];
  33. var goodpass1 = [];
  34. var goodid1 = [];
  35. var goodfailrate1 = [];
  36. var badpass = [];
  37. var badid = [];
  38. var badfailrate = [];
  39. var badpass1 = [];
  40. var badid1 = [];
  41. var badfailrate1 = [];
  42. function history_success(obj, sta) {
  43. var histoire = first_parse(this, obj);
  44. var i, j, t;
  45. console.log(" histoire : ");
  46. console.log(histoire);
  47. if (this.url.indexOf("type=1") >= 0) {
  48. t = 1;
  49. } else if (this.url.indexOf("type=2") >= 0) {
  50. t = 2;
  51. } else if (this.url.indexOf("type=3") >= 0) {
  52. t = 3;
  53. } else {
  54. t = 0;
  55. return;
  56. }
  57. histoires[t] = histoire;
  58. if (t === 2 || t === 3) {
  59. hispass[t] = 0;
  60. hisfail[t] = 0;
  61. hisstack[t] = 0;
  62. hisrate[t] = 0;
  63. for (i = 0; i < histoire.length - 1; i++) { //除了今日
  64. hispass[t] = histoire[i].passNum + hispass[t];
  65. hisfail[t] = histoire[i].failNum + hisfail[t];
  66. hisstack[t] = histoire[i].avgDue + hisstack[t];
  67. }
  68. orighispass[t] = hispass[t];
  69. orighisfail[t] = hisfail[t];
  70. orighisstack[t] = hisstack[t];
  71. hispass[t] += hispass[0];
  72. hisfail[t] += hisfail[0];
  73. hisstack[t] += hisstack[0];
  74. hisrate[t] = get_factor(hispass[t], hisfail[t]);
  75. } else if (t === 1) {
  76. hispass[1] = histoire[0].passNum;
  77. hisfail[1] = histoire[0].failNum;
  78. hisstack[1] = histoire[0].avgDue;
  79. hisrate[t] = get_factor(hispass[1], hisfail[1]);
  80. }
  81. todayotherpass = histoire[histoire.length - 1].passNum;
  82. todayotherfail = histoire[histoire.length - 1].failNum;
  83. todayotherstack = histoire[histoire.length - 1].avgDue;
  84. update_all_history();
  85. }
  86. function update_all_history() {
  87. hispass[0] = todayotherpass + schedulepass;
  88. hisfail[0] = todayotherfail + schedulefail;
  89. hisstack[0] = todayotherstack + schedulestack;
  90. hisrate[0] = get_factor(hispass[0], hisfail[0]);
  91. if (typeof hisrate[0] == "undefined" || isNaN(hisrate[0])) {
  92. send_alert("请重试!");
  93. }
  94. for (i = 2; i <= 3; i++) {
  95. hispass[i] = orighispass[i] + hispass[0];
  96. hisfail[i] = orighisfail[i] + hisfail[0];
  97. hisstack[i] = orighisstack[i] + hisstack[0];
  98. hisrate[i] = get_factor(hispass[i], hisfail[i]);
  99. }
  100. }
  101. var todayotherpass, todayotherfail, todayotherstack;
  102. var orighisfail = [], orighispass = [], orighisstack = [];
  103. function isUserOfThisFlow(uid) {
  104. var isExist = false;
  105. userIDs.forEach(function (vals) {
  106. if (vals == uid) {
  107. isExist = true;
  108. }
  109. });
  110. return isExist;
  111. }
  112. function on_red_rank_success(obj, sta) {
  113. var redchart = first_parse(this, obj);
  114. var i, j;
  115. i = j = 0;
  116. console.log(" redchart : ");
  117. console.log(redchart);
  118. for (i = 0; i < redchart.list.length; i++) {
  119. goodid[i] = getUserName(redchart.list[i].workerId);
  120. goodpass[i] = redchart.list[i].passNum;
  121. if (redchart.list[i].passNum + redchart.list[i].failNum > 0) {
  122. goodfailrate[i] = Math.floor(redchart.list[i].failNum * 10000 / (redchart.list[i].passNum + redchart.list[i].failNum)) / 100;
  123. } else {
  124. goodfailrate[i] = 0;
  125. }
  126. if (isUserOfThisFlow(redchart.list[i].workerId)) {
  127. goodColor[i] = 'red';
  128. } else {
  129. goodColor[i] = '';
  130. }
  131. }
  132. }
  133. function on_red_rank_success1(obj, sta) {
  134. var redchart = first_parse(this, obj);
  135. var i, j;
  136. i = j = 0;
  137. console.log(" redchart : ");
  138. console.log(redchart);
  139. for (i = 0; i < redchart.list.length; i++) {
  140. goodid1[i] = getUserName(redchart.list[i].workerId);
  141. goodpass1[i] = redchart.list[i].passNum;
  142. if (redchart.list[i].passNum + redchart.list[i].failNum > 0) {
  143. goodfailrate1[i] = Math.floor(redchart.list[i].failNum * 10000 / (redchart.list[i].passNum + redchart.list[i].failNum)) / 100;
  144. } else {
  145. goodfailrate1[i] = 0;
  146. }
  147. if (isUserOfThisFlow(redchart.list[i].workerId)) {
  148. goodColor1[i] = 'red';
  149. } else {
  150. goodColor1[i] = '';
  151. }
  152. }
  153. }
  154. function on_black_rank_success(obj, sta) {
  155. var blackchart = first_parse(this, obj);
  156. var i, j;
  157. i = j = 0;
  158. console.log(" black chart : ");
  159. console.log(blackchart);
  160. for (i = 0; i < blackchart.list.length; i++) {
  161. badid[i] = getUserName(blackchart.list[i].workerId);
  162. badpass[i] = blackchart.list[i].passNum;
  163. //badfailrate[i] = blackchart.list[i].failRate / 100;
  164. if (blackchart.list[i].passNum + blackchart.list[i].failNum > 0) {
  165. badfailrate[i] = Math.floor(blackchart.list[i].failNum * 10000 / (blackchart.list[i].passNum + blackchart.list[i].failNum)) / 100;
  166. } else {
  167. badfailrate[i] = 0;
  168. }
  169. if (isUserOfThisFlow(blackchart.list[i].workerId)) {
  170. badColor[i] = 'green';
  171. } else {
  172. badColor[i] = '';
  173. }
  174. }
  175. }
  176. function on_black_rank_success1(obj, sta) {
  177. var blackchart = first_parse(this, obj);
  178. var i, j;
  179. i = j = 0;
  180. console.log(" black chart : ");
  181. console.log(blackchart);
  182. for (i = 0; i < blackchart.list.length; i++) {
  183. badid1[i] = getUserName(blackchart.list[i].workerId);
  184. badpass1[i] = blackchart.list[i].passNum;
  185. //badfailrate[i] = blackchart.list[i].failRate / 100;
  186. if (blackchart.list[i].passNum + blackchart.list[i].failNum > 0) {
  187. badfailrate1[i] = Math.floor(blackchart.list[i].failNum * 10000 / (blackchart.list[i].passNum + blackchart.list[i].failNum)) / 100;
  188. } else {
  189. badfailrate1[i] = 0;
  190. }
  191. if (isUserOfThisFlow(blackchart.list[i].workerId)) {
  192. badColor1[i] = 'green';
  193. } else {
  194. badColor1[i] = '';
  195. }
  196. }
  197. }
  198. function getHistoryTableBody(htmlbody, i) {
  199. if (typeof hispass[i] === "undefined") {
  200. htmlbody += "<tr>";
  201. htmlbody += `<tr>
  202. <td> - </td>
  203. <td> - </td>
  204. <td> - </td>
  205. <td> - </td>
  206. <td> - </td>
  207. </tr>`;
  208. htmlbody += "</tr>";
  209. return htmlbody;
  210. }
  211. htmlbody += "<tr>";
  212. htmlbody += `<tr>
  213. <td>${timeday[i]}</td>
  214. <td>${hispass[i]}</td>
  215. <td>${hisfail[i]}</td>
  216. <td>${hisstack[i]}</td>
  217. <td>${hisrate[i] + '%'}</td>
  218. </tr>`;
  219. htmlbody += "</tr>";
  220. return htmlbody;
  221. }
  222. function getRankingTableBody(htmlbody, i) {
  223. if (typeof goodRank === "undefined" || typeof goodRank[i] === "undefined") {
  224. htmlbody += "<tr>";
  225. htmlbody += `<tr>
  226. <td> - </td>
  227. <td> 0 </td>
  228. <td> 0 </td>
  229. <td> 0 </td>
  230. </tr>`;
  231. htmlbody += "</tr>";
  232. return htmlbody;
  233. }
  234. htmlbody += "<tr>";
  235. htmlbody += `<tr ">
  236. <td style="background-color: ${goodRank[i].color}">${goodRank[i].id}</td>
  237. <td style="background-color: ${goodRank[i].color}">${goodRank[i].pass}</td>
  238. <td style="background-color: ${goodRank[i].color}">${goodRank[i].fail}</td>
  239. <td style="background-color: ${goodRank[i].color}">${goodRank[i].failRate + '%'}</td>
  240. </tr>`;
  241. htmlbody += "</tr>";
  242. return htmlbody;
  243. }
  244. var lastTimeRank0 = "";
  245. var lastTimeRank1 = "";
  246. var lastTimeRank2 = "";
  247. var lastTimeRank3 = "";
  248. var lastTimeRank4 = "";
  249. function showHistoryData() {
  250. var htmlbody = "", one_person = "";
  251. var i = 0;
  252. var triGap = 4;
  253. htmlbody = "";
  254. for (i = 0; i < triGap; i++) {
  255. htmlbody = getHistoryTableBody(htmlbody, i);
  256. }
  257. if (lastTimeRank0 !== htmlbody) {
  258. $("#rank-one").html(htmlbody);
  259. lastTimeRank0 = htmlbody;
  260. }
  261. //console.log(htmlbody);
  262. }
  263. function showRedRanking() {
  264. var htmlbody = "", one_person = "";
  265. var i = 0;
  266. var triGap = RANK_TBL_ROW_COUNT;
  267. htmlbody = "";
  268. for (i = 0; i < triGap; i++) {
  269. htmlbody = getRankingTableBody(htmlbody, i);
  270. }
  271. if (lastTimeRank1 !== htmlbody) {
  272. $("#rank-two").html(htmlbody);
  273. lastTimeRank1 = htmlbody;
  274. }
  275. //console.log(htmlbody);
  276. }
  277. /***
  278. * DataObject DO
  279. * @param cname
  280. * @param serverJsonObj
  281. * @constructor
  282. */
  283. var DataObject = function(cname, serverJsonObj){
  284. this.ctlName = cname;
  285. this.jsonObj = serverJsonObj;
  286. this.getVal = function (key) {
  287. return jsonObj[key];
  288. };
  289. this.serVal = function (key, val) {
  290. jsonObj[key] = val;
  291. };
  292. };
  293. /***
  294. * DataObjectList
  295. * @param name
  296. * @constructor
  297. */
  298. var DataObjectList = function(name){
  299. this.ctlName = name;
  300. this.list = null;
  301. this.isSorted = false;
  302. this.preSort = [];
  303. /***
  304. * sorting
  305. * @param comparator (a,b) =====> a - b
  306. */
  307. this.sortBy = function(comparator){
  308. preSort = new Array();
  309. for (let i = 0; i < list.length; i++) preSort.push(list[i]);
  310. quickSort(preSort, 0, preSort.length - 1, function(l, r){});
  311. };
  312. function clearData() {
  313. isSorted = false;
  314. preSort = null;
  315. list = null;
  316. }
  317. this.len = function() {
  318. if(list == null) return 0;
  319. return list.length;
  320. };
  321. this.assignJsonData = function (data) {
  322. clearData();
  323. list = new Array();
  324. for (let i = 0; i < list.length; i++) list.push(new DataObject(ctlName, data[i]));
  325. };
  326. this.getRaw = function (index) {
  327. return list[index];
  328. };
  329. this.getSorted = function (index) {
  330. if(!isSorted) return null;
  331. return preSort[index];
  332. };
  333. this.quickSort = function (a,left,right,comp){
  334. if(left>right){ //一定要有这个判断,因为有递归left和i-1,若没有这个判断条件,该函数会进入无限死错位递归
  335. return;
  336. }
  337. var i=left,
  338. j=right,
  339. pivot=a[left]; //基准总是取序列开头的元素
  340. while(i!=j){
  341. while((comp(a[j],pivot) > 0)&&i<j){j--}
  342. while((comp(a[j],pivot) <= 0)&&i<j){i++}
  343. if(i<j){ //如果i==j跳出外层while
  344. var t=a[i];
  345. a[i]=a[j];
  346. a[j]=t;
  347. }
  348. }
  349. a[left]=a[i];//交换基准数和k位置上的数
  350. a[i]=pivot;
  351. quicksort(a,left,i-1,comp);
  352. quicksort(a,i+1,right,comp);
  353. };
  354. };
  355. /***
  356. * DOService
  357. * @param controlName
  358. * @constructor
  359. */
  360. var DataObjectService = function(controlName, syncType, extparm){
  361. this.ctlName = controlName;
  362. // 2=default 4=on-demand, 8=auto, 16:fast, 32=passive
  363. this.syncType = syncType;
  364. this.extParm = extparm;
  365. this.isDefault = ((syncType & 2) !== 0);
  366. this.isOnDemand = ((syncType & 4) !== 0);
  367. this.isAuto = ((syncType & 8) !== 0);
  368. this.isFast = ((syncType & 16) !== 0);
  369. this.isPassive = ((syncType & 32) !== 0);
  370. this.failedCount = 0;
  371. this.list = new DataObjectList(controlName);
  372. this.autoUpdateTimer = 0;
  373. this.autoInterval = 1000;
  374. function setUpInterval() {
  375. //URL + exparm
  376. if(this.autoUpdateTimer != 0) clearInterval(this.autoUpdateTimer);
  377. this.autoUpdateTimer = setInterval(this.selfUpdateTick, this.autoInterval);
  378. }
  379. this.init = function(){
  380. if(isAuto){
  381. // timer
  382. if(!isFast){
  383. this.autoInterval = 5000;
  384. }
  385. setUpInterval();
  386. selfUpdate();
  387. }
  388. };
  389. this.stopTimers = function () {
  390. clearInterval(this.autoUpdateTimer);
  391. this.autoUpdateTimer = 0;
  392. };
  393. this.selfUpdateTick = function(){
  394. get_data(controlName+"/list"+extParm, this.onDataReceived);
  395. };
  396. this.onDemandUpdate = function(){
  397. get_data(controlName+"/list"+extParm, this.onDataReceived);
  398. };
  399. this.onDataReceived = function(data, sta){
  400. let output = first_parse(this, obj);
  401. if (output.list == undefined || output.list.length == 0) {
  402. this.failedCount++;
  403. if(this.failedCount > 100){
  404. this.failedCount = 0;
  405. this.stopTimers();
  406. console.log("【错误次数过多");
  407. setTimeout(this.setUpInterval, 10000);
  408. }
  409. if(this.failedCount == 2) {
  410. send_alert("没有数据,请尝试重新加载!【DataService】: ctlName[" + controlName + "], extParm[" + extparm + "]");
  411. }
  412. }else{
  413. this.list.assignJsonData(output.list);
  414. }
  415. };
  416. this.passiveUpdate = function(data){
  417. this.failedCount = 0;
  418. this.list.assignJsonData(data);
  419. };
  420. this.init();
  421. };
  422. var SinglePage = function () {
  423. this.modules = [];
  424. };
  425. var Module = function(chartContainerSelector, dataCtlName){
  426. this.selector = chartContainerSelector;
  427. this.dataCtl = dataCtlName;
  428. this.activeData = null;
  429. this.lastActive = 0;
  430. /***
  431. * bindData to UI
  432. * @param data DataObjectList
  433. */
  434. this.setData = function (data) {
  435. if(data.ctlName == this.dataCtl){
  436. //ok
  437. console.log(`-------- Module ${this.selector} got data ----------- `);
  438. this.activeData = data;
  439. //cache
  440. this.drawData();
  441. }else{
  442. console.log(`-------- Module ${this.selector} cannot use data of ${data.ctlName} ----------- `);
  443. }
  444. };
  445. this.drawData = function () {
  446. // do nothing
  447. }
  448. };
  449. var RealTimeGraph = new Module("", "fcBiSectorLoad");
  450. RealTimeGraph.drawData = function (data) {
  451. var tempo = this.activeData;
  452. };
  453. var FlowRealTime = (function () {
  454. this.pgName = "flowDashBoard";
  455. this.page = new SinglePage(this.pgName);
  456. this.scheduleId = utils_get_param("scheduleId");
  457. this.flowId = utils_get_param("flowId");
  458. if(scheduleId == null || flowId == null)
  459. {
  460. send_alert(`清重新进入本页面!<a href='denglu.html'> 返回主页 </a>`);
  461. return;
  462. }
  463. this.flowPlace = " % flowPlace %";
  464. this.flowName = " % flowPlace %";
  465. this.HistoryBaseURL = "fcBiFlowDaily/list?scheduleId=" + scheduleId + "&flowId=" + flowId;
  466. this.scheduleLoadDataService = new DataObjectService("fcScheduleLoadService", 2 & 4);
  467. this.biFlowDailyService = null;
  468. this.oaStaffService = null;
  469. this.sectorService = null;
  470. this.flowService = null;
  471. this.initializeUsers = function(list){
  472. list.forEach(function (val, it, arr) {
  473. var isExist = false;
  474. userIDs.forEach(function (vals) {
  475. if (vals == val.userId) {
  476. isExist = true;
  477. }
  478. });
  479. if (!isExist) userIDs.push(val.userId);
  480. });
  481. };
  482. this.initPage = function(){
  483. showHistoryData();
  484. showRedRanking();
  485. showBlackRanking();
  486. };
  487. /***
  488. * On
  489. * @param obj
  490. * @param sta
  491. */
  492. this.onFirstTimeSuccess = function (obj, sta) {
  493. let output = first_parse(this, obj);
  494. let i, j, k, z = 0, x = 0, worksum = [];
  495. if (output.list == undefined || output.list.length == 0) {
  496. send_alert("没有数据 | 请重新加载页面 ! ");
  497. }else{
  498. DataLogic.onScheduleData(output.list);
  499. }
  500. initializeUsers(output.list);
  501. Action.loadMultiHistory();
  502. showChart();
  503. };
  504. /**
  505. * DataLogic
  506. */
  507. this.DataLogic = (function () {
  508. this.combineAsSector = function(sectorList, scheduleDoList) {
  509. var output = new DataObjectList("sectorLoad");
  510. output.assignJsonData("");
  511. return output;
  512. };
  513. this.onScheduleData = function (scheduleDoList) {
  514. sectorID[0] = getSectorId(scheduleDoList[0].spotId);
  515. for (let i = 1; i < scheduleDoList.length; i++) {
  516. let loadDO = new ScheduleDO(scheduleDoList[i]);
  517. x = 0;
  518. for (j = 0; j < sectorID.length; j++) {
  519. if (sectorID[j] === thisUid) {
  520. x = 1;
  521. break;
  522. }
  523. }
  524. if (x === 0) {
  525. sectorID.push(thisUid);
  526. }
  527. }
  528. DataLogic.CountBySector();
  529. }
  530. this.CountBySector = function (sectors, spotData) {
  531. sectorId, passNumber, failNumber
  532. let j = 0, k = 0, z = 0;
  533. for (k = 0; k < sectors.length; k++) {
  534. var uid = sectors[k].getUid();
  535. z = 0;
  536. passNumber[k] = 0;
  537. failNumber[k] = 0;
  538. stackeverynum[k] = 0;
  539. for (i = 0; i < output.list.length; i++) {
  540. if (uid === getSectorId(output.list[i].spotId)) {
  541. passNumber[k] = output.list[i].passNum + passNumber[j];
  542. failNumber[k] = output.list[i].failNum + failNumber[j];
  543. stackeverynum[k] = output.list[i].due + stackeverynum[j];
  544. z++;
  545. }
  546. }
  547. if (failNumber[k] + passNumber[k] == 0) {
  548. failrate[k] = 0;
  549. } else {
  550. failrate[k] = failNumber[k] / (failNumber[k] + passNumber[k]) * 100;
  551. }
  552. // z is the number of data in one sector
  553. }
  554. }
  555. })();
  556. this.NameLoader = (function(){
  557. this.onNameRetrieved = function (obj, sta) {
  558. var factory = first_parse(this, obj);
  559. var i, j, t;
  560. console.log(" factory : ");
  561. console.log(factory);
  562. flowPlace = factory.list[0].flowPlace;
  563. flowName = factory.list[0].flowName;
  564. $("#flow_title").html(flowPlace + "-" + flowName + " 度彼科技");
  565. document.title = flowPlace + " " + flowName + " | 流水线管理 | 度彼科技";
  566. };
  567. this.load = function(){
  568. get_data("fcFlow/list?flowId=" + flowId, onNameRetrieved);
  569. };
  570. })();
  571. this.mainLoopFunc = function () {
  572. get_data("fcWorkScheduleLoad/list?scheduleId=" + scheduleId, realtime_success);
  573. HistoryData.update();
  574. };
  575. this.Action = (function () {
  576. this.clearDataOfDeviceId = function (handId) {
  577. executed = false;
  578. directCount = -1;
  579. finished = true;
  580. var hand = handId;
  581. var hd = 0;
  582. if (hand.length > 0) {
  583. hd = parseInt(hand);
  584. }
  585. get_data("endpoint/clearBoard?flowId=" + flowId + "&handheldId=" + hd, clearSuccess);
  586. };
  587. this.doStopSchedule = function () {
  588. get_data("fcWorkSchedule/stopSchedule?userId=" + userId + "&scheduleId=" + scheduleId, UI.showStopSuccess);
  589. };
  590. this.confirmStopSchedule = function () {
  591. var out = confirm("真的要下班吗?");
  592. if (out == true) {
  593. doStopSchedule();
  594. } else {
  595. }
  596. };
  597. })();
  598. this.UI = (function () {
  599. this.showClearPanel = function () {
  600. $("#clearModal").modal('show');
  601. };
  602. this.showStopSuccess = function (obj, sta) {
  603. send_alert("下班操作成功! <a href='denglu.html'> 点击这里返回控制主页 </a>");
  604. };
  605. })();
  606. this.HistoryData = (function (){
  607. this.update = function () {
  608. // 请注意type必须在结尾
  609. get_data("fcBiFlowDaily/list?flowId=" + flowId + "&type=1", history_success);
  610. };
  611. this.loadHistroyOnce = function (nnm) {
  612. // 请注意type必须在结尾
  613. get_data(HistoryBaseURL + "&type=" + nnm, history_success);
  614. };
  615. this.loadMultiHistory = function(){
  616. for (i = 1; i <= 3; i++) loadHistroyOnce(i);
  617. };
  618. this.add_success = function(obj, sta) {
  619. var history1 = first_parse(this, obj);
  620. var i, j;
  621. console.log(" history1 : ");
  622. console.log(history1);
  623. hispass[t] = 0;
  624. hisfail[t] = 0;
  625. hisstack[t] = 0;
  626. hisrate[t] = 0;
  627. var lengthnum = history1.length - 1;
  628. for (i = lengthnum; i < history1.length; i++) {
  629. hispass[t] = history1[i].passNum + hispass[t];
  630. hisfail[t] = history1[i].failNum + hisfail[t];
  631. hisstack[t] = history1[i].avgDue + hisstack[t];
  632. }
  633. if (hispass[t] + hisfail[t] == 0) {
  634. hisrate[t] = 0;
  635. }
  636. t++;
  637. }
  638. })();
  639. function realtime_success(obj, sta) {
  640. var output = first_parse(this, obj);
  641. //在这里排序 spo\
  642. console.log(" output : ");
  643. console.log(output);
  644. var i, j, k, z;
  645. failnum = 0;
  646. var x = 0;
  647. var worksum = [];
  648. var hhp = 0, hhf = 0, hhs = 0;
  649. if (output.list.length > 0) {
  650. sectorID[0] = getSectorId(output.list[0].spotId);
  651. passNumber[0] = 0;
  652. failNumber[0] = 0;
  653. stackeverynum[0] = 0;
  654. z = 0;
  655. for (i = 1; i < output.list.length; i++) {
  656. var thisUid = getSectorId(output.list[i].spotId);
  657. x = 0;
  658. for (j = 0; j < sectorID.length; j++) {
  659. if (sectorID[j] === thisUid) {
  660. x = 1;
  661. break;
  662. }
  663. }
  664. if (x === 0) {
  665. sectorID.push(thisUid);
  666. }
  667. }
  668. j = 0;
  669. for (k = 0; k < sectorID.length; k++) {
  670. var uid = sectorID[k];
  671. z = 0;
  672. passNumber[k] = 0;
  673. failNumber[k] = 0;
  674. stackeverynum[k] = 0;
  675. for (i = 0; i < output.list.length; i++) {
  676. if (uid === getSectorId(output.list[i].spotId)) {
  677. passNumber[k] = output.list[i].passNum + passNumber[k];
  678. failNumber[k] = output.list[i].failNum + failNumber[k];
  679. stackeverynum[k] = output.list[i].due + stackeverynum[k];
  680. z++;
  681. }
  682. }
  683. failrate[k] = get_factor(passNumber[k], failNumber[k]);
  684. }
  685. output.list.forEach(function (val, fid, arr) {
  686. hhp += val.passNum;
  687. hhf += val.failNum;
  688. hhs += val.due;
  689. })
  690. }
  691. schedulepass = hhp;
  692. schedulefail = hhf;
  693. if (output.list.length > 0) {
  694. schedulestack = hhs / output.list.length;
  695. } else {
  696. schedulestack = 0;
  697. }
  698. update_all_history();
  699. updateChart();
  700. };
  701. })();
  702. var ClearDataControl = (function () {
  703. this.finished = true;
  704. this.executed = false;
  705. this.directCount = -1;
  706. this.Action = (function () {
  707. })();
  708. this.clearSuccess = function (obj, sta) {
  709. console.warn("------- 手持设备清空 ----------");
  710. console.warn(this);
  711. send_alert("发送清空请求成功, 正在等待采集端进行处理...");
  712. ClearDataControl.finished = false;
  713. setTimeout(resultVerifyTimeout, 8000);
  714. setTimeout(getVerify, 300);
  715. }
  716. this.getVerify = function () {
  717. if (ClearDataControl.finished) return;
  718. get_data("endpoint/heartbeat?flowId=" + flowId, onVerifyResult);
  719. setTimeout(getVerify, 100);
  720. };
  721. this.onVerifyResult = function (obj, sta) {
  722. var parsed = {};
  723. if (typeof(obj) === "string") {
  724. parsed = JSON.parse(obj);
  725. } else {
  726. parsed = obj;
  727. }
  728. if (typeof(parsed) === "object") {
  729. if (parsed.ret === "10000") {
  730. //ok
  731. if (parsed.model == null || parsed.model === undefined) {
  732. executed = true;
  733. finished = true;
  734. } else if (typeof(obj.model) === "object") {
  735. // 没有拿到,继续
  736. if (obj.model.list != null && obj.model.list.length > 0) {
  737. var direct = obj.model.list[0];
  738. if (direct.eventType + "" !== "500") {
  739. // OK
  740. executed = true;
  741. finished = true;
  742. } else if (direct.arg2 + "" !== "" + $("#handInput").val()) {
  743. // OK
  744. executed = true;
  745. finished = true;
  746. } else {
  747. directCount = direct.counter;
  748. }
  749. }
  750. }
  751. }
  752. }
  753. }
  754. this.resultVerifyTimeout = function () {
  755. finished = true;
  756. if (executed) {
  757. // 执行成功
  758. } else {
  759. if (directCount >= 0) {
  760. get_data("endpoint/ack?counter=" + directCount, function () {
  761. console.log("撤销操作成功");
  762. console.log(this);
  763. });
  764. directCount = -1;
  765. send_alert("请求已经超时!请注意,采集端可能没有执行成功。即将撤销您的请求。");
  766. } else {
  767. send_alert("请求已经超时!请注意,采集端可能没有执行成功。");
  768. }
  769. }
  770. }
  771. })();
  772. $(document).ready(function(){
  773. });
  774. var RealTimeCharts = (function() {
  775. var timeday = ["今日", "昨日", "本周", "本月"];
  776. if (flowId == null || scheduleId == null) {
  777. send_alert("出错啦!请检查参数完整性");
  778. }
  779. function page_document_load() {
  780. get_data("fcWorkScheduleLoad/list?scheduleId=" + scheduleId, onFirstTimeSuccess);
  781. }
  782. var compAxis = {
  783. categories: namedata,
  784. crosshair: true,
  785. title: {
  786. text: '工位',
  787. style: {
  788. fontSize: '1.5em'
  789. }
  790. },
  791. labels: {
  792. style: {
  793. fontSize: '1.5em'
  794. }
  795. }
  796. };
  797. var getSeperateArrays = function (sectorLoadData){
  798. this.data = [];
  799. this.len = sectorLoadData.len();
  800. this.stackmax = 0;
  801. this.failmax = 0;
  802. this.passmax = 0;
  803. this.failratemax = 0;
  804. this.ratedata = [];
  805. this.passdata = [];
  806. this.faildata = [];
  807. for (i = 0; i < len; i++) {
  808. var one = sectorLoadData.getRaw(i);
  809. if (stackmax < one[i].getVal("stack")) {
  810. stackmax = one[i].getVal("stack")
  811. }
  812. if (failmax < one[i].getVal("failNum")) {
  813. failmax = one[i].getVal("failNum");
  814. }
  815. if (failratemax < one[i].getVal("failRate")) {
  816. failratemax = one[i].getVal("failRate");
  817. }
  818. if (passmax < one[i].getVal("passNum")) {
  819. passmax = one[i].getVal("passNum");
  820. }
  821. data.push(one[i].getVal("stack"));
  822. this.ratedata.push(Math.floor(one[i].getVal("failRate")));
  823. this.passdata.push(one[i].getVal("passNum"));
  824. this.faildata.push(one[i].getVal("failNum"));
  825. }
  826. };
  827. this.dataArrays = null;
  828. function showChart(sectorLoadData) {
  829. dataArrays = new getSeperateArrays(sectorLoadData);
  830. failratemax = Math.max(failratemax, 5);
  831. stackmax = Math.max(stackmax, 5);
  832. failmax = Math.max(failmax, 5);
  833. passmax = Math.max(passmax, failmax, stackmax);
  834. stackAndFailChart = Highcharts.chart('graph-1', {
  835. chart: {
  836. zoomType: 'xy',
  837. //height: (4 / 16 * 100) + '%' // 16:9 ratio
  838. },
  839. title: {text: '各工位今日产能'},
  840. credits: {enabled: false},
  841. exporting: {enabled: false},
  842. xAxis: [compAxis],
  843. yAxis: [{
  844. labels: {
  845. format: '{value}',
  846. style: {
  847. color: "#ffffff",
  848. fontSize: '1.5em'
  849. }
  850. },
  851. min: 0,
  852. max: passmax * 1.5,
  853. title: {
  854. text: '数量',
  855. style: {
  856. color: '#ffffff',
  857. fontSize: '1em'
  858. },
  859. rotation: 270,
  860. }
  861. },],
  862. tooltip: {shared: true},
  863. legend: {
  864. layout: 'vertical',
  865. align: 'right',
  866. x: 0,
  867. verticalAlign: 'top',
  868. y: 0,
  869. floating: true,
  870. backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
  871. },
  872. series: [{
  873. name: '良品数',
  874. type: 'column',
  875. data: passdata,
  876. }, {
  877. name: '不良品数',
  878. type: 'column',
  879. data: faildata,
  880. },
  881. {
  882. name: '堆积数',
  883. type: 'column',
  884. data: data,
  885. }]
  886. });
  887. FailChart = Highcharts.chart('graph-2', {
  888. chart: {
  889. //height: (4 / 16 * 100) + '%' // 16:9 ratio
  890. },
  891. title: {
  892. text: '各工位今日不良率'
  893. },
  894. credits: {
  895. enabled: false // 禁用版权信息
  896. },
  897. exporting: {
  898. enabled: false
  899. },
  900. xAxis: [compAxis],
  901. yAxis: [{ // Secondary yAxis
  902. title: {
  903. text: '不良率',
  904. style: {
  905. color: '#ffffff',
  906. fontSize: '1em'
  907. }
  908. },
  909. min: 0,
  910. max: 1.5 * failratemax,
  911. labels: {
  912. formatter: function () {
  913. return Math.floor(this.value) + "%";
  914. },
  915. style: {
  916. color: '#ffffff',
  917. fontSize: '20px'
  918. },
  919. rotation: 270,
  920. },
  921. }],
  922. tooltip: {
  923. shared: true
  924. },
  925. legend: {
  926. layout: 'vertical',
  927. align: 'right',
  928. x: 0,
  929. verticalAlign: 'top',
  930. y: 0,
  931. floating: true,
  932. backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
  933. },
  934. series: [{
  935. name: '不良率',
  936. type: 'spline',
  937. data: ratedata,
  938. color: 'red',
  939. tooltip: {
  940. valueSuffix: '%'
  941. }
  942. }]
  943. });
  944. }
  945. function updateChart() {
  946. var data = [];
  947. var ratedata = [];
  948. var stackmax = 0;
  949. var failmax = 0;
  950. var passdata = [];
  951. var faildata = [];
  952. var passmax = 0;
  953. var failratemax = 0;
  954. for (i = 0; i < passNumber.length; i++) {
  955. if (stackmax < stackeverynum[i]) {
  956. stackmax = stackeverynum[i];
  957. }
  958. if (failmax < failNumber[i]) {
  959. failmax = failNumber[i];
  960. }
  961. if (failratemax < failrate[i]) {
  962. failratemax = failrate[i];
  963. }
  964. if (passmax < passNumber[i]) {
  965. passmax = passNumber[i];
  966. }
  967. data.push(stackeverynum[i]);
  968. ratedata.push(Math.floor(failrate[i]));
  969. passdata.push(passNumber[i]);
  970. faildata.push(failNumber[i])
  971. }
  972. failratemax = Math.max(failratemax, 5);
  973. stackmax = Math.max(stackmax, 5);
  974. failmax = Math.max(failmax, 5);
  975. passmax = Math.max(passmax, failmax, stackmax);
  976. // https://api.hcharts.cn/highcharts#Series.addPoint;
  977. stackAndFailChart.series[0].setData(passdata);
  978. stackAndFailChart.series[1].setData(faildata);
  979. stackAndFailChart.series[2].setData(data);
  980. FailChart.series[0].setData(ratedata);
  981. if (failratemax > FailChart.yAxis[0].getExtremes().max * 1.3 || failratemax < FailChart.yAxis[0].getExtremes().max * 0.5) {
  982. FailChart.yAxis[0].setExtremes(0, failratemax * 1.5);
  983. }
  984. if (passmax > stackAndFailChart.yAxis[0].getExtremes().max * 1.3 || passmax < stackAndFailChart.yAxis[0].getExtremes().max * 0.5) {
  985. stackAndFailChart.yAxis[0].setExtremes(0, passmax * 1.5);
  986. }
  987. showHistoryData();
  988. showRedRanking();
  989. showBlackRanking();
  990. var secNames = [];
  991. sectorID.forEach(function (val) {
  992. secNames.push(getSectorName(val));
  993. });
  994. if (JSON.stringify(secNames) !== lastTimeSecNames) {
  995. lastTimeSecNames = JSON.stringify(secNames);
  996. FailChart.xAxis[0].setCategories(secNames);
  997. stackAndFailChart.xAxis[0].setCategories(secNames);
  998. }
  999. }
  1000. var lastTimeSecNames = "";
  1001. var stackAndFailChart = null;
  1002. var FailChart = null;
  1003. })();