basic1.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. var SVR_URL = "/server/"; //http://172.30.84.3:8803
  2. if(location.host.indexOf("niimei") === -1){
  3. SVR_URL = "http://127.0.0.1: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. send_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 addtime_load_spots_data() {
  48. num++;
  49. get_data("fcBiFlowDaily/list?type=" + num +"&flowId="+flowId, add_success);
  50. }
  51. function first_parse(ajax, obj) {
  52. if (typeof obj === "string") {
  53. obj = JSON.parse(obj);
  54. }
  55. if (typeof obj !== "object") {
  56. console.log(ajax);
  57. throw "Error ! Parsing JSON failed ." + JSON.stringify(obj);
  58. }
  59. if (obj.ret == "10000" || obj.ret == 10000 || obj.ret == 1000) {
  60. return obj.model;
  61. } else {
  62. console.log(ajax);
  63. throw "Error ! Server returned error." + JSON.stringify(obj);
  64. }
  65. }
  66. function on_document_load() {
  67. get_data("fcWorkScheduleLoad/get" , on_load_success_spots)
  68. }
  69. function on_load_success_spots(obj, status) {
  70. var spotsList = first_parse(this, obj);
  71. //在这里排序 spo\
  72. console.log("spot List : ");
  73. console.log(spotsList);
  74. var i, j, temp=[];
  75. for (i = 0; i < spotsList.length ; i++) {
  76. passeverynum[i] = spotsList[i].passNum;
  77. faileverynum[i] = spotsList[i].failNum;
  78. stackeverynum[i] = spotsList[i].due;
  79. flownum[i]=spotsList[i].scheduleId;
  80. }
  81. for (i = 0; i < spotsList.length ; i++) {
  82. if (passeverynum[i] + faileverynum[i] == 0) {
  83. failrate[i] = 0;
  84. }
  85. else {
  86. failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
  87. }
  88. }
  89. addtime_load_spots_data();
  90. for(i=2;i<5;i++) {
  91. secondtime_load_spots_data();
  92. }
  93. chart_load_spots_data();
  94. chart1_load_spots_data();
  95. showChart();
  96. setInterval(function(){
  97. get_data("fcWorkScheduleLoad/get" , realtime_success);
  98. },1000);
  99. }
  100. function add_success(obj, sta) {
  101. var history1 = first_parse(this, obj);
  102. var i, j;
  103. console.log(" history1 : ");
  104. console.log(history1);
  105. hispass[t] = 0;
  106. hisfail[t] = 0;
  107. hisstack[t] = 0;
  108. hisrate[t]=0;
  109. var lengthnum=history1.length-1;
  110. for(i=lengthnum;i<history1.length;i++){
  111. hispass[t] = history1[i].passNum+hispass[t];
  112. hisfail[t] = history1[i].failNum+hisfail[t];
  113. hisstack[t] = history1[i].avgDue+hisstack[t];
  114. hisrate[t] = history1[i].failRate;
  115. hisrate[t]=hisrate[t]/100;
  116. }
  117. if(hispass[t]+hisfail[t]==0){
  118. hisrate[t]=0;
  119. }
  120. t++;
  121. }
  122. function second_success(obj, sta) {
  123. var history = first_parse(this, obj);
  124. var i, j;
  125. console.log(" history : ");
  126. console.log(history);
  127. hispass[t] = 0;
  128. hisfail[t] = 0;
  129. hisstack[t] = 0;
  130. hisrate[t]=0;
  131. for(i=0;i<history.length;i++){
  132. hispass[t] = history[i].passNum+hispass[t];
  133. hisfail[t] = history[i].failNum+hisfail[t];
  134. hisstack[t] = history[i].avgDue+hisstack[t];
  135. hisrate[t] = history[i].failRate;
  136. hisrate[t]=hisrate[t]/100;
  137. }
  138. if(history.length!=1){
  139. hisrate[t]=hisfail[t]/(hispass[t]+hisfail[t]);
  140. }
  141. if(hispass[t]+hisfail[t]==0){
  142. hisrate[t]=0;
  143. }
  144. t++;
  145. }
  146. function chart_success(obj, sta) {
  147. var redchart = first_parse(this, obj);
  148. var i, j;
  149. i=j=0;
  150. console.log(" redchart : ");
  151. console.log(redchart);
  152. for(i=0;i<3;i++){
  153. goodid[i]=getUserName(redchart.list[i].workerId);
  154. goodpass[i]=redchart.list[i].passNum;
  155. goodfailrate[i]=redchart.list[i].failRate/100;
  156. }
  157. }
  158. function chart1_success(obj, sta) {
  159. var blackchart = first_parse(this, obj);
  160. var i, j;
  161. i=j=0;
  162. console.log(" black chart : ");
  163. console.log(blackchart);
  164. for(i=0;i<3;i++){
  165. badid[i] = getUserName(blackchart.list[i].workerId);
  166. badpass[i]=blackchart.list[i].passNum;
  167. badfailrate[i]=blackchart.list[i].failRate/100;
  168. }
  169. }
  170. function realtime_success(obj, sta) {
  171. var output = first_parse(this, obj);
  172. var i, j;
  173. for (i = 0; i < output.length ; i++) {
  174. passeverynum[i] = output[i].passNum;
  175. faileverynum[i] = output[i].failNum;
  176. stackeverynum[i] = output[i].due;
  177. flownum[i]=output[i].scheduleId;
  178. }
  179. for (i = 0; i < output.length ; i++) {
  180. if (passeverynum[i] + faileverynum[i] == 0) {
  181. failrate[i] = 0;
  182. }
  183. else {
  184. failrate[i] = faileverynum[i] / (faileverynum[i] + passeverynum[i]) * 100;
  185. }
  186. }
  187. updateChart();
  188. }