newData.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. getUserId();
  2. const DEFAULT = 2;
  3. const ONDEMAND = 4;
  4. const AUTO = 8;
  5. const FAST = 16;
  6. const PASSIVE = 32;
  7. var RANK_TBL_ROW_COUNT = 4;
  8. var lastTimeRank0 = "";
  9. var lastTimeRank1 = "";
  10. var lastTimeRank2 = "";
  11. var lastTimeRank3 = "";
  12. var lastTimeRank4 = "";
  13. /***
  14. * DataObject DO
  15. * @param cname
  16. * @param serverJsonObj
  17. * @constructor
  18. */
  19. var DataObject = function(cname, serverJsonObj){
  20. this.ctlName = cname;
  21. this.jsonObj = serverJsonObj;
  22. this.getVal = function (key) {
  23. return jsonObj[key];
  24. };
  25. this.serVal = function (key, val) {
  26. jsonObj[key] = val;
  27. };
  28. };
  29. /***
  30. * DataObjectList
  31. * @param name
  32. * @constructor
  33. */
  34. var DataObjectList = function(name){
  35. this.ctlName = name;
  36. this.list = null;
  37. this.isSorted = false;
  38. this.preSort = [];
  39. /***
  40. * sorting
  41. * @param comparator (a,b) =====> a - b
  42. */
  43. this.sortBy = function(comparator){
  44. preSort = new Array();
  45. for (let i = 0; i < list.length; i++) preSort.push(list[i]);
  46. quickSort(preSort, 0, preSort.length - 1, function(l, r){});
  47. };
  48. function clearData() {
  49. isSorted = false;
  50. preSort = null;
  51. list = null;
  52. }
  53. this.len = function() {
  54. if(list == null) return 0;
  55. return list.length;
  56. };
  57. this.mergeJsonData = function (data, extdata) {
  58. list = new Array();
  59. for (let i = 0; i < data.length; i++) this.addObject(data[i]);
  60. };
  61. this.addObject = function (jsonObj) {
  62. list.push(new DataObject(ctlName, jsonObj));
  63. };
  64. this.assignJsonData = function (data) {
  65. clearData();
  66. mergeJsonData(data);
  67. };
  68. this.getRaw = function (index) {
  69. return list[index];
  70. };
  71. this.getSorted = function (index) {
  72. if(!isSorted) return null;
  73. return preSort[index];
  74. };
  75. this.quickSort = function (a,left,right,comp){
  76. if(left>right){ //一定要有这个判断,因为有递归left和i-1,若没有这个判断条件,该函数会进入无限死错位递归
  77. return;
  78. }
  79. var i=left,
  80. j=right,
  81. pivot=a[left]; //基准总是取序列开头的元素
  82. while(i!=j){
  83. while((comp(a[j],pivot) > 0)&&i<j){j--}
  84. while((comp(a[j],pivot) <= 0)&&i<j){i++}
  85. if(i<j){ //如果i==j跳出外层while
  86. var t=a[i];
  87. a[i]=a[j];
  88. a[j]=t;
  89. }
  90. }
  91. a[left]=a[i];//交换基准数和k位置上的数
  92. a[i]=pivot;
  93. quicksort(a,left,i-1,comp);
  94. quicksort(a,i+1,right,comp);
  95. };
  96. };
  97. /***
  98. * DOService
  99. * @param controlName
  100. * @constructor
  101. */
  102. var DataObjectService = function(controlName, syncType, extparm){
  103. this.ctlName = controlName;
  104. // 2=default 4=on-demand, 8=auto, 16:fast, 32=passive
  105. this.syncType = syncType;
  106. this.extParm = extparm;
  107. this.isDefault = ((syncType & DEFAULT) !== 0);
  108. this.isOnDemand = ((syncType & ONDEMAND) !== 0);
  109. this.isAuto = ((syncType & AUTO) !== 0);
  110. this.isFast = ((syncType & FAST) !== 0);
  111. this.isPassive = ((syncType & PASSIVE) !== 0);
  112. this.failedCount = 0;
  113. this.list = new DataObjectList(controlName);
  114. this.autoUpdateTimer = 0;
  115. this.autoInterval = 1000;
  116. function setUpInterval() {
  117. //URL + exparm
  118. if(this.autoUpdateTimer != 0) clearInterval(this.autoUpdateTimer);
  119. this.autoUpdateTimer = setInterval(this.selfUpdateTick, this.autoInterval);
  120. setTimeout(this.selfUpdateTick, 100);
  121. }
  122. this.init = function(){
  123. this.appUrl = "/server/"+ controlName + "/list" + extparm;
  124. if(!this.isFast || this.isOnDemand){
  125. this.autoInterval = 30000;
  126. }
  127. if(this.isFast) {
  128. this.appUrl = "/server/"+ controlName + "/get" + extparm;
  129. }
  130. if(this.isAuto){
  131. // timer
  132. setUpInterval();
  133. }
  134. };
  135. this.stopTimers = function () {
  136. clearInterval(this.autoUpdateTimer);
  137. this.autoUpdateTimer = 0;
  138. };
  139. this.selfUpdateTick = function(){
  140. get_data(this.appUrl, this.onDataReceived);
  141. };
  142. this.onDemandUpdate = function(){
  143. get_data(this.appUrl, this.onDataReceived);
  144. };
  145. this.onDataReceived = function(data, sta){
  146. let output = first_parse(this, obj);
  147. if (output.list == undefined || output.list.length == 0) {
  148. this.failedCount++;
  149. if(this.failedCount > 100){
  150. this.failedCount = 0;
  151. this.stopTimers();
  152. console.log("【错误次数过多");
  153. setTimeout(this.setUpInterval, 10000);
  154. }
  155. if(this.failedCount == 2) {
  156. send_alert("没有数据,请尝试重新加载!【DataService】: ctlName[" + controlName + "], extParm[" + extparm + "]");
  157. }
  158. }else{
  159. this.list.assignJsonData(output.list);
  160. }
  161. };
  162. this.passiveUpdate = function(data){
  163. this.failedCount = 0;
  164. this.list.assignJsonData(data);
  165. };
  166. this.init();
  167. };
  168. var SinglePage = function () {
  169. this.modules = [];
  170. };
  171. var Module = function(chartContainerSelector, dataCtlName){
  172. this.selector = chartContainerSelector;
  173. this.dataCtl = dataCtlName;
  174. this.activeData = null;
  175. this.lastActive = 0;
  176. this.tickInterval = 1000;
  177. /***
  178. * bindData to UI
  179. * @param data DataObjectList
  180. */
  181. this.setData = function (data) {
  182. if(data.ctlName == this.dataCtl){
  183. console.log(`-------- Module ${this.selector} got data ----------- `);
  184. this.activeData = data;
  185. this.drawData(this.activeData);
  186. }else{
  187. console.log(`-------- Module ${this.selector} cannot use data of ${data.ctlName} ----------- `);
  188. }
  189. };
  190. this.init = function () {
  191. // do init
  192. this.setupInterval();
  193. };
  194. this.tick = function () {
  195. // do tick
  196. };
  197. this.setupInterval = function () {
  198. // do tick
  199. if(this.tickInterval != 0) clearInterval(this.tickInterval);
  200. this.tickInterval = setInterval(this.tick, this.tickInterval);
  201. };
  202. this.drawData = function () {
  203. // do drawData
  204. };
  205. };
  206. var RedRankTable = new Module("#table-rank", "fcBiWorkerDaily");
  207. RedRankTable.slideLen = 16;
  208. RedRankTable.slides = 0;
  209. RedRankTable.parts = 4;
  210. RedRankTable.partLen = 4;
  211. RedRankTable.curSlide = 0;
  212. RedRankTable.drawData = function (data) {
  213. // showSlide
  214. this.showSlide(this.curSlide, data);
  215. };
  216. RedRankTable.showSlide = function (slide, data) {
  217. this.parts = 3;
  218. for(var part = 0; part < this.parts; part++){
  219. this.showPart(slide, part, data);
  220. }
  221. };
  222. RedRankTable.showPart = function(slide, part, data){
  223. var htmlbody = "", row;
  224. var lpos = this.slide * this.slideLen + part * this.partLen;
  225. var rpos = this.slide * this.slideLen + (part+1) * this.partLen;
  226. for (var i = lpos; i < rpos; i++) {
  227. row = this.getDataRow(htmlbody, data.getRaw(i));
  228. htmlbody += row;
  229. }
  230. //if (localCache() !== htmlbody) {
  231. $(this.selector + "-" + part).html(htmlbody);
  232. // lastTimeRank1 = htmlbody;
  233. //}
  234. //console.log(htmlbody);
  235. };
  236. RedRankTable.tickInterval = 10000;
  237. RedRankTable.tick = function(){
  238. var totalDataLen = this.activeData != null ? this.activeData.len() : 0;
  239. if(this.slides != Math.ceil(totalDataLen / this.slideLen)){
  240. this.slides = Math.ceil(totalDataLen / this.slideLen);
  241. this.curSlide = 0;
  242. } else {
  243. this.curSlide = (this.curSlide + 1) % this.slides;
  244. }
  245. };
  246. RedRankTable.getDataRow = function(htmlbody, dataObj) {
  247. if (dataObj == null || typeof dataObj === "undefined") {
  248. htmlbody += "<tr>";
  249. htmlbody += `<tr>
  250. <td> - </td>
  251. <td> 0 </td>
  252. <td> 0 </td>
  253. <td> 0 </td>
  254. </tr>`;
  255. htmlbody += "</tr>";
  256. return htmlbody;
  257. }
  258. htmlbody += "<tr>";
  259. htmlbody += `<tr>
  260. <td style="background-color: ${dataObj.getVal("color")}">${getUserName(dataObj.getVal("id"))}</td>
  261. <td style="background-color: ${dataObj.getVal("color")}">${dataObj.getVal("failNum")}</td>
  262. <td style="background-color: ${dataObj.getVal("color")}">${dataObj.getVal("passNum")}</td>
  263. <td style="background-color: ${dataObj.getVal("color")}">${dataObj.getVal("failRate") + '%'}</td>
  264. </tr>`;
  265. htmlbody += "</tr>";
  266. return htmlbody;
  267. }
  268. RedRankTable.init();
  269. var FlowRealTime = new (function () {
  270. this.pgName = "flowDashBoard";
  271. this.page = new SinglePage(this.pgName);
  272. this.scheduleId = utils_get_param("scheduleId");
  273. this.flowId = utils_get_param("flowId");
  274. if(scheduleId == null || flowId == null)
  275. {
  276. send_alert(`清重新进入本页面!<a href='denglu.html'> 返回主页 </a>`);
  277. return;
  278. }
  279. this.flowPlace = " % flowPlace %";
  280. this.flowName = " % flowPlace %";
  281. this.scheduleLoadDataService = new DataObjectService("fcWorkScheduleLoad", ONDEMAND /*AUTO & FAST*/, "?scheduleId=" + scheduleId);
  282. this.oaStaffService = new DataObjectService("fcWorkScheduleLoad", ONDEMAND, "");
  283. this.sectorService = new DataObjectService("fcWorkScheduleLoad", ONDEMAND, "");
  284. this.flowService = new DataObjectService("fcFlow", ONDEMAND, "");
  285. this.rankData = new DataObjectService("fcBiWorkerDaily", ONDEMAND & AUTO & FAST, "?type=1");
  286. this.MeduimData = new (function () {
  287. this.initializeUsers = function(list){
  288. list.forEach(function (val, it, arr) {
  289. var isExist = false;
  290. userIDs.forEach(function (vals) {
  291. if (vals == val.userId) {
  292. isExist = true;
  293. }
  294. });
  295. if (!isExist) userIDs.push(val.userId);
  296. });
  297. };
  298. })();
  299. this.initPage = function() {
  300. setInterval(this.tick, 1000);
  301. };
  302. this.tick = function(){
  303. RedRankTable.setData(this.rankData.list);
  304. };
  305. this.Action = new (function () {
  306. this.doStopSchedule = function () {
  307. get_data("fcWorkSchedule/stopSchedule?userId=" + userId + "&scheduleId=" + scheduleId, UI.showStopSuccess);
  308. };
  309. this.confirmStopSchedule = function () {
  310. var out = confirm("真的要下班吗?");
  311. if (out == true) {
  312. doStopSchedule();
  313. } else {
  314. }
  315. };
  316. })();
  317. this.UI = new (function () {
  318. this.showClearPanel = function () {
  319. $("#clearModal").modal('show');
  320. };
  321. this.showStopSuccess = function (obj, sta) {
  322. send_alert("下班操作成功! <a href='denglu.html'> 点击这里返回控制主页 </a>");
  323. };
  324. this.bind = function () {
  325. $(".confirm-clear-data").click(function(){
  326. FlowRealTime.ClearDataControl.clearDataOfDeviceId($('#handInput').val());
  327. });
  328. $(".open-clear-panel").click(function () {
  329. FlowRealTime.UI.showClearPanel();
  330. })
  331. $(".close-schedule").click(function () {
  332. FlowRealTime.Action.confirmStopSchedule();
  333. })
  334. }
  335. })();
  336. var ClearDataControl = new (function () {
  337. this.finished = true;
  338. this.executed = false;
  339. this.directCount = -1;
  340. this.clearDataOfDeviceId = function (handId) {
  341. this.executed = false;
  342. this.directCount = -1;
  343. this.finished = true;
  344. var hand = handId;
  345. var hd = 0;
  346. if (hand.length > 0) {
  347. hd = parseInt(hand);
  348. }
  349. get_data("endpoint/clearBoard?flowId=" + flowId + "&handheldId=" + hd, this.clearSuccess);
  350. };
  351. this.clearSuccess = function (obj, sta) {
  352. console.warn("------- 手持设备清空 ----------");
  353. console.warn(obj);
  354. send_alert("发送清空请求成功, 正在等待采集端进行处理...");
  355. this.finished = false;
  356. setTimeout(this.resultVerifyTimeout, 8000);
  357. setTimeout(this.getVerify, 300);
  358. }
  359. this.getVerify = function () {
  360. if (this.finished) return;
  361. get_data("endpoint/heartbeat?flowId=" + flowId, this.onVerifyResult);
  362. setTimeout(this.getVerify, 100);
  363. };
  364. this.onVerifyResult = function (obj, sta) {
  365. var parsed = {};
  366. if (typeof(obj) === "string") {
  367. parsed = JSON.parse(obj);
  368. } else {
  369. parsed = obj;
  370. }
  371. if (typeof(parsed) === "object") {
  372. if (parsed.ret === "10000") {
  373. //ok
  374. if (parsed.model == null || parsed.model === undefined) {
  375. executed = true;
  376. finished = true;
  377. } else if (typeof(obj.model) === "object") {
  378. // 没有拿到,继续
  379. if (obj.model.list != null && obj.model.list.length > 0) {
  380. var direct = obj.model.list[0];
  381. if (direct.eventType + "" !== "500") {
  382. // OK
  383. executed = true;
  384. finished = true;
  385. } else if (direct.arg2 + "" !== "" + $("#handInput").val()) {
  386. // OK
  387. executed = true;
  388. finished = true;
  389. } else {
  390. directCount = direct.counter;
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }
  397. this.resultVerifyTimeout = function () {
  398. finished = true;
  399. if (executed) {
  400. // 执行成功
  401. } else {
  402. if (directCount >= 0) {
  403. get_data("endpoint/ack?counter=" + directCount, function () {
  404. console.log("撤销操作成功");
  405. console.log(this);
  406. });
  407. directCount = -1;
  408. send_alert("请求已经超时!请注意,采集端可能没有执行成功。即将撤销您的请求。");
  409. } else {
  410. send_alert("请求已经超时!请注意,采集端可能没有执行成功。");
  411. }
  412. }
  413. }
  414. })();
  415. })();
  416. $(document).ready(function(){
  417. FlowRealTime.UI.bind();
  418. });