lazhang-data.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. var passNumber = [];
  2. var failNumber = [];
  3. var failrate = [];
  4. var stackeverynum = [];
  5. var failnum = 0;
  6. var num = 0;
  7. var n = 0;
  8. var sectorID = [];
  9. var namedata = [];
  10. var lazhang = {};
  11. var scheduleId = utils_get_param("scheduleId");
  12. var flowId = utils_get_param("flowId");
  13. var name1,name2;
  14. function first_success(obj, sta) {
  15. let output = first_parse(this, obj);
  16. let i, j, k, z;
  17. failnum = 0;
  18. let x = 0;
  19. let worksum = [];
  20. z = 0;
  21. if (output.list == undefined || output.list.length == 0) {
  22. send_alert("没有数据");
  23. }
  24. output.list.forEach(function(val,it,arr){
  25. var isExist = false;
  26. userIDs.forEach(function(vals){
  27. if(vals == val.userId){
  28. isExist = true;
  29. }
  30. });
  31. if(!isExist) userIDs.push(val.userId);
  32. });
  33. if (output.list.length > 0) {
  34. sectorID[0] = getSectorId(output.list[0].spotId);
  35. for (i = 1; i < output.list.length; i++) {
  36. var thisUid = getSectorId(output.list[i].spotId);
  37. x = 0;
  38. for (j = 0; j < sectorID.length; j++) {
  39. if (sectorID[j] === thisUid) {
  40. x = 1;
  41. break;
  42. }
  43. }
  44. if (x === 0) {
  45. sectorID.push(thisUid);
  46. }
  47. }
  48. j = 0;
  49. for (k = 0; k < sectorID.length; k++) {
  50. var uid = sectorID[k];
  51. z = 0;
  52. passNumber[k] = 0;
  53. failNumber[k] = 0;
  54. stackeverynum[k] = 0;
  55. for (i = 0; i < output.list.length; i++) {
  56. if (uid === getSectorId(output.list[i].spotId)) {
  57. passNumber[k] = output.list[i].passNum + passNumber[j];
  58. failNumber[k] = output.list[i].failNum + failNumber[j];
  59. stackeverynum[k] = output.list[i].due + stackeverynum[j];
  60. z++;
  61. }
  62. }
  63. if (failNumber[k] + passNumber[k] == 0) {
  64. failrate[k] = 0;
  65. }
  66. else {
  67. failrate[k] = failNumber[k] / (failNumber[k] + passNumber[k]) * 100;
  68. }
  69. /*stackeverynum[k]=stackeverynum[k]/z;*/
  70. ///
  71. }
  72. }
  73. get_data("fcFlow/list?flowId="+ flowId,name_Success);
  74. for (i = 1; i <= 3; i++) {
  75. load_flows_history_data(i);
  76. }
  77. showChart();
  78. lazhang.timer = setInterval(request_data_realtime, 1000);
  79. }
  80. function name_Success(obj, sta) {
  81. var factory = first_parse(this, obj);
  82. var i, j, t;
  83. console.log(" factory : ");
  84. console.log(factory);
  85. name1=factory.list[0].flowPlace;
  86. name2=factory.list[0].flowName;
  87. document.getElementById("test1").innerHTML = name1+"-"+name2;
  88. }
  89. function request_data_realtime() {
  90. get_data("fcWorkScheduleLoad/list?scheduleId=" + scheduleId, realtime_success);
  91. //load_flows_history_realtime_data();
  92. load_table_red_rank();
  93. load_table_red_rank1();
  94. load_table_black_rank();
  95. load_table_black_rank1();
  96. }
  97. function load_flows_history_data(nnm) {
  98. // 请注意type必须在结尾
  99. get_data("fcBiFlowDaily/list?scheduleId="+scheduleId+ "&flowId=" + flowId+"&type=" + nnm , history_success);
  100. }
  101. function load_flows_history_realtime_data() {
  102. // 请注意type必须在结尾
  103. get_data("fcBiFlowDaily/list?flowId=" + flowId +"&type=1", history_success);
  104. }
  105. function get_stop_scheudle1() {
  106. var out = confirm("真的要下班吗?");
  107. if(out == true){
  108. get_stop_scheudle();
  109. }
  110. else{
  111. }
  112. }
  113. function show_clear_panel(){
  114. $("#clearModal").modal('show');
  115. }
  116. var executed = false;
  117. var finished = true;
  118. var directCount = -1;
  119. function clear_one_data(){
  120. executed = false;
  121. directCount = -1;
  122. finished = true;
  123. var hand = $("#handInput").val();
  124. if(hand.length > 0){
  125. var hd = parseInt(hand);
  126. }
  127. get_data("endpoint/clearBoard?flowId="+flowId+"&handheldId=" + hd, clearSuccess);
  128. }
  129. function clearSuccess(obj, sta){
  130. console.warn("------- 手持设备清空 ----------");
  131. console.warn(this);
  132. send_alert("发送清空请求成功, 正在等待采集端进行处理...");
  133. finished = false;
  134. setTimeout(on_timeout_clear, 5000);
  135. setTimeout(recurseget,300);
  136. //var output = first_success(this, obj);
  137. }
  138. function recurseget(){
  139. if(finished) return;
  140. get_data("endpoint/heartbeat?flowId=" + flowId, onheart);
  141. setTimeout(recurseget,100);
  142. }
  143. function onheart(obj,sta){
  144. var ouy = {};
  145. if(typeof(obj) === "string"){
  146. ouy = JSON.parse(obj);
  147. }
  148. if(typeof(obj) === "object"){
  149. if(ouy.ret === "10000"){
  150. //ok
  151. if(ouy.model == null || ouy.model === undefined){
  152. executed = true;
  153. finished = true;
  154. }else if(typeof(obj.model) === "object"){
  155. // 没有拿到,继续
  156. if(obj.model.list != null && obj.model.list.length > 0){
  157. var direct = obj.model.list[0];
  158. if(direct.eventType+"" !== "500"){
  159. // OK
  160. executed = true;
  161. finished = true;
  162. }else if(direct.arg2+"" !== ""+$("#handInput").val()){
  163. // OK
  164. executed = true;
  165. finished = true;
  166. }else{
  167. directCount = direct.counter;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. function on_timeout_clear(){
  175. finished = true;
  176. if(executed){
  177. // 执行成功
  178. }else{
  179. if(directCount >= 0){
  180. get_data("endpoint/ack?counter="+directCount,function(){console.log("撤销操作成功");console.log(this);});
  181. directCount = -1;
  182. send_alert("请求已经超时!请注意,采集端可能没有执行成功。即将撤销您的请求。");
  183. }else{
  184. send_alert("请求已经超时!请注意,采集端可能没有执行成功。");
  185. }
  186. }
  187. }
  188. function get_stop_scheudle() {
  189. get_data("fcWorkSchedule/stopSchedule?userId="+userId+"scheduleId=" + scheduleId, stopSuccess);
  190. }
  191. function stopSuccess(obj, sta) {
  192. send_alert("下班操作成功! <a href='denglu.html'> 点击这里返回控制主页 </a>");
  193. }
  194. function add_success(obj, sta) {
  195. var history1 = first_parse(this, obj);
  196. var i, j;
  197. console.log(" history1 : ");
  198. console.log(history1);
  199. hispass[t] = 0;
  200. hisfail[t] = 0;
  201. hisstack[t] = 0;
  202. hisrate[t] = 0;
  203. var lengthnum = history1.length - 1;
  204. for (i = lengthnum; i < history1.length; i++) {
  205. hispass[t] = history1[i].passNum + hispass[t];
  206. hisfail[t] = history1[i].failNum + hisfail[t];
  207. hisstack[t] = history1[i].avgDue + hisstack[t];
  208. }
  209. if (hispass[t] + hisfail[t] == 0) {
  210. hisrate[t] = 0;
  211. }
  212. t++;
  213. }
  214. function realtime_success(obj, sta) {
  215. var output = first_parse(this, obj);
  216. //在这里排序 spo\
  217. console.log(" output : ");
  218. console.log(output);
  219. var i, j, k, z;
  220. failnum = 0;
  221. var x = 0;
  222. var worksum = [];
  223. var hhp = 0, hhf = 0, hhs = 0;
  224. if (output.list.length > 0) {
  225. sectorID[0] = getSectorId(output.list[0].spotId);
  226. passNumber[0] = 0;
  227. failNumber[0] = 0;
  228. stackeverynum[0] = 0;
  229. z = 0;
  230. for (i = 1; i < output.list.length; i++) {
  231. var thisUid = getSectorId(output.list[i].spotId);
  232. x = 0;
  233. for (j = 0; j < sectorID.length; j++) {
  234. if (sectorID[j] === thisUid) {
  235. x = 1;
  236. break;
  237. }
  238. }
  239. if (x === 0) {
  240. sectorID.push(thisUid);
  241. }
  242. }
  243. j = 0;
  244. for (k = 0; k < sectorID.length; k++) {
  245. var uid = sectorID[k];
  246. z = 0;
  247. passNumber[k] = 0;
  248. failNumber[k] = 0;
  249. stackeverynum[k] = 0;
  250. for (i = 0; i < output.list.length; i++) {
  251. if (uid === getSectorId(output.list[i].spotId)) {
  252. passNumber[k] = output.list[i].passNum + passNumber[k];
  253. failNumber[k] = output.list[i].failNum + failNumber[k];
  254. stackeverynum[k] = output.list[i].due + stackeverynum[k];
  255. z++;
  256. }
  257. }
  258. failrate[k] = get_factor(passNumber[k], failNumber[k]);
  259. }
  260. output.list.forEach(function (val, fid, arr) {
  261. hhp += val.passNum;
  262. hhf += val.failNum;
  263. hhs += val.due;
  264. })
  265. }
  266. schedulepass = hhp;
  267. schedulefail = hhf;
  268. if (output.list.length > 0) {
  269. schedulestack = hhs / output.list.length;
  270. } else {
  271. schedulestack = 0;
  272. }
  273. update_all_history();
  274. updateChart();
  275. }