newData.js 15 KB

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