basic1.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. var SVR_URL = "/server/"; //http://172.30.84.3:8803
  2. if(location.host.indexOf("niimei") === -1){
  3. SVR_URL = "http://172.30.84.3:8803/server/";
  4. }
  5. function get_data(url, callback) {
  6. $.ajax({
  7. url: SVR_URL + url,
  8. apiName: url,
  9. sendTime: new Date()
  10. }).done(callback).fail(on_fail);
  11. }
  12. var faileverynum=[];
  13. var passeverynum=[];
  14. var stackeverynum=[];
  15. var failrate=[];
  16. var flowID=1;
  17. var num=0;
  18. var hispass=[];
  19. var hisfail=[];
  20. var hisstack=[];
  21. var hisrate=[];
  22. var goodpass=[];
  23. var goodid=[];
  24. var goodfailrate=[];
  25. var badpass=[];
  26. var badid=[];
  27. var badfailrate=[];
  28. var t=0;
  29. var n=0;
  30. var flownum=[];
  31. function on_fail(msg) {
  32. alert("很抱歉,网络错误,请查看Console");
  33. console.log("----- 网络请求失败 ---------")
  34. console.log(JSON.stringify(this));
  35. console.log("----------------------------")
  36. }
  37. function secondtime_load_spots_data() {
  38. get_data("fcBiFactoryDaily/list?type=" + num +"&flowId="+flowID, second_success);
  39. num++;
  40. }
  41. function chart_load_spots_data() {
  42. get_data("fcBiWorkerDaily/get?type=0&limit=3", chart_success);
  43. }
  44. function chart1_load_spots_data() {
  45. get_data("fcBiWorkerDaily/get?type=4&limit=3", chart1_success);
  46. }
  47. function first_parse(ajax, obj) {
  48. if (typeof obj === "string") {
  49. obj = JSON.parse(obj);
  50. }
  51. if (typeof obj !== "object") {
  52. console.log(ajax);
  53. throw "Error ! Parsing JSON failed ." + JSON.stringify(obj);
  54. }
  55. if (obj.ret == "10000" || obj.ret == 10000 || obj.ret == 1000) {
  56. return obj.model;
  57. } else {
  58. console.log(ajax);
  59. throw "Error ! Server returned error." + JSON.stringify(obj);
  60. }
  61. }
  62. function on_document_load() {
  63. get_data("fcWorkScheduleLoad/get" , on_load_success_spots)
  64. }
  65. function on_load_success_spots(obj, status) {
  66. var spotsList = first_parse(this, obj);
  67. //在这里排序 spo\
  68. console.log("spot List : ");
  69. console.log(spotsList);
  70. var i, j, temp=[];
  71. for (i = 0; i < spotsList.length ; i++) {
  72. passeverynum[i] = spotsList[i].passNum;
  73. faileverynum[i] = spotsList[i].failNum;
  74. stackeverynum[i] = spotsList[i].due;
  75. flownum[i]=spotsList[i].scheduleId;
  76. }
  77. for (i = 0; i < spotsList.length ; i++) {
  78. if (passeverynum[i] + faileverynum[i] == 0) {
  79. failrate[i] = 0;
  80. }
  81. else {
  82. failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
  83. }
  84. }
  85. for(i=1;i<5;i++) {
  86. secondtime_load_spots_data();
  87. }
  88. chart_load_spots_data();
  89. chart1_load_spots_data();
  90. showChart();
  91. setInterval(function(){
  92. get_data("fcWorkScheduleLoad/get" , realtime_success);
  93. },1000);
  94. }
  95. function second_success(obj, sta) {
  96. var history = first_parse(this, obj);
  97. var i, j;
  98. console.log(" history : ");
  99. console.log(history);
  100. hispass[t] = 0;
  101. hisfail[t] = 0;
  102. hisstack[t] = 0;
  103. hisrate[t]=0;
  104. for(i=0;i<history.length;i++){
  105. hispass[t] = history[i].passNum+hispass[t];
  106. hisfail[t] = history[i].failNum+hisfail[t];
  107. hisstack[t] = history[i].avgDue+hisstack[t];
  108. hisrate[t] = history[i].failRate;
  109. hisrate[t]=hisrate[t]/100;
  110. }
  111. if(history.length!=1){
  112. hisrate[t]=hisfail[t]/(hispass[t]+hisfail[t]);
  113. }
  114. if(hispass[t]+hisfail[t]==0){
  115. hisrate[t]=0;
  116. }
  117. t++;
  118. }
  119. function chart_success(obj, sta) {
  120. var redchart = first_parse(this, obj);
  121. var i, j;
  122. i=j=0;
  123. console.log(" redchart : ");
  124. console.log(redchart);
  125. for(i=0;i<3;i++){
  126. goodid[i]=redchart.list[i].workerId;
  127. goodpass[i]=redchart.list[i].passNum;
  128. goodfailrate[i]=redchart.list[i].failRate/100;
  129. }
  130. }
  131. function chart1_success(obj, sta) {
  132. var blackchart = first_parse(this, obj);
  133. var i, j;
  134. i=j=0;
  135. console.log(" black chart : ");
  136. console.log(blackchart);
  137. for(i=0;i<3;i++){
  138. badid[i]=blackchart.list[i].workerId;
  139. badpass[i]=blackchart.list[i].passNum;
  140. badfailrate[i]=blackchart.list[i].failRate/100;
  141. }
  142. }
  143. function realtime_success(obj, sta) {
  144. var output = first_parse(this, obj);
  145. var i, j;
  146. for (i = 0; i < output.length ; i++) {
  147. passeverynum[i] = output[i].passNum;
  148. faileverynum[i] = output[i].failNum;
  149. stackeverynum[i] = output[i].due;
  150. flownum[i]=output[i].scheduleId;
  151. }
  152. for (i = 0; i < output.length ; i++) {
  153. if (passeverynum[i] + faileverynum[i] == 0) {
  154. failrate[i] = 0;
  155. }
  156. else {
  157. failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
  158. }
  159. }
  160. updateChart();
  161. }