basic.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. function on_fail(msg) {
  13. alert("很抱歉,网络错误,请查看Console");
  14. console.log("----- 网络请求失败 ---------")
  15. console.log(JSON.stringify(this));
  16. console.log("----------------------------")
  17. }
  18. function on_data_success(obj, status) {
  19. }
  20. function first_parse(ajax, obj) {
  21. if (typeof obj === "string") {
  22. obj = JSON.parse(obj);
  23. }
  24. if (typeof obj !== "object") {
  25. console.log(ajax);
  26. throw "Error ! Parsing JSON failed ." + JSON.stringify(obj);
  27. }
  28. if (obj.ret == "10000" || obj.ret == 10000 || obj.ret == 1000) {
  29. return obj.model;
  30. } else {
  31. console.log(ajax);
  32. throw "Error ! Server returned error." + JSON.stringify(obj);
  33. }
  34. }
  35. var flowData;
  36. var sID = [];
  37. var passNumber = [];
  38. var failNumber = [];
  39. var failrate = [];
  40. var stacknum = 0;
  41. var stackeverynum = [];
  42. var failnum=0;
  43. var passnum=0
  44. var passdata=[];
  45. var faildata=[];
  46. var num=0;
  47. var hispass=[];
  48. var hisfail=[];
  49. var hisstack=[];
  50. var hisrate=[];
  51. var goodpass=[];
  52. var goodid=[];
  53. var goodfailrate=[];
  54. var badpass=[];
  55. var badid=[];
  56. var badfailrate=[];
  57. var t=0;
  58. var n=0;
  59. var flowID=1;
  60. function firsttime_load_spots_data() {
  61. get_data("fcWorkRaw/allSpots?flowId=" + thisPageFlow, first_success)
  62. }
  63. function secondtime_load_spots_data() {
  64. get_data("fcBiFlowDaily/list?type=" + num +"&flowId="+flowID, second_success);
  65. num++;
  66. }
  67. function chart_load_spots_data() {
  68. get_data("fcBiWorkerDaily/get?type=0&limit=3", chart_success);
  69. }
  70. function chart1_load_spots_data() {
  71. get_data("fcBiWorkerDaily/get?type=4&limit=3", chart1_success);
  72. }
  73. function first_success(obj, sta) {
  74. var output = first_parse(this, obj);
  75. //在这里排序 spo\
  76. console.log(" output : ");
  77. console.log(output);
  78. var i, j;
  79. failnum=0;
  80. for (i = 0; i < output.length ; i++) {
  81. passNumber[i] = output[i].passNum;
  82. passnum=passNumber[i]
  83. }
  84. for (i = 0; i < output.length ; i++) {
  85. failNumber[i] = output[i].failNum;
  86. failnum=failNumber[i]+failnum;
  87. }
  88. for (i = 0; i < output.length ; i++) {
  89. if (failNumber[i] + passNumber[i] == 0) {
  90. failrate[i] = 0;
  91. }
  92. else {
  93. failrate[i] = failNumber[i] / (failNumber[i] + passNumber[i]) * 100;
  94. }
  95. }
  96. stackeverynum[0] = 0;
  97. for (i = 1; i < output.length ; i++) {
  98. stackeverynum[i] = passNumber[i - 1] - passNumber[i] - failNumber[i];
  99. stacknum = stackeverynum[i] + stacknum;
  100. }
  101. for(i=1;i<5;i++) {
  102. secondtime_load_spots_data();
  103. }
  104. chart_load_spots_data();
  105. chart1_load_spots_data();
  106. showChart();
  107. setInterval(function(){
  108. get_data("fcWorkRaw/allSpots?flowId=" + thisPageFlow, realtime_success);
  109. },1000);
  110. }
  111. function second_success(obj, sta) {
  112. var history = first_parse(this, obj);
  113. var i, j;
  114. console.log(" history : ");
  115. console.log(history);
  116. hispass[t] = 0;
  117. hisfail[t] = 0;
  118. hisstack[t] = 0;
  119. hisrate[t]=0;
  120. for(i=0;i<history.length;i++){
  121. hispass[t] = history[i].passNum+hispass[t];
  122. hisfail[t] = history[i].failNum+hisfail[t];
  123. hisstack[t] = history[i].avgDue+hisstack[t];
  124. hisrate[t] = history[i].failRate;
  125. hisrate[t]=hisrate[t]/100;
  126. }
  127. if(history.length!=1){
  128. hisrate[t]=Math.floor(hisfail[t]/(hispass[t]+hisfail[t])*10000)/100;
  129. }
  130. if(hispass[t]+hisfail[t]==0){
  131. hisrate[t]=0;
  132. }
  133. t++;
  134. }
  135. function chart_success(obj, sta) {
  136. var redchart = first_parse(this, obj);
  137. var i, j;
  138. i=j=0;
  139. console.log(" redchart : ");
  140. console.log(redchart);
  141. for(i=0;i<3;i++){
  142. goodid[i]=redchart.list[i].workerId;
  143. goodpass[i]=redchart.list[i].passNum;
  144. goodfailrate[i]=redchart.list[i].failRate/100;
  145. }
  146. }
  147. function chart1_success(obj, sta) {
  148. var blackchart = first_parse(this, obj);
  149. var i, j;
  150. i=j=0;
  151. console.log(" black chart : ");
  152. console.log(blackchart);
  153. for(i=0;i<3;i++){
  154. badid[i]=blackchart.list[i].workerId;
  155. badpass[i]=blackchart.list[i].passNum;
  156. badfailrate[i]=blackchart.list[i].failRate/100;
  157. }
  158. }
  159. function realtime_success(obj, sta) {
  160. var output = first_parse(this, obj);
  161. var i, j;
  162. for (i = 0; i < output.length ; i++) {
  163. passNumber[i] = output[i].passNum;
  164. }
  165. for (i = 0; i < output.length ; i++) {
  166. failNumber[i] = output[i].failNum;
  167. }
  168. for (i = 0; i < output.length ; i++) {
  169. if (failNumber[i] + passNumber[i] == 0) {
  170. failrate[i] = 0;
  171. }
  172. else {
  173. failrate[i] = failNumber[i] / (failNumber[i] + passNumber[i]) * 100;
  174. }
  175. }
  176. stackeverynum[0] = 0;
  177. for (i = 1; i < output.length ; i++) {
  178. stackeverynum[i] = passNumber[i - 1] - passNumber[i] - failNumber[i];
  179. stacknum = stackeverynum[i] + stacknum;
  180. }
  181. updateChart();
  182. }
  183. function on_load_success_spots(obj, status) {
  184. var spotsList = first_parse(this, obj);
  185. //在这里排序 spo\
  186. console.log("spot List : ");
  187. console.log(spotsList);
  188. var i, j, temp;
  189. for (i = 0; i < spotsList.list.length - 1; i++) {
  190. for (j = 0; j < spotsList.list.length - i - 1; j++) {
  191. if (spotsList.list[j].orderNum > spotsList.list[j + 1].orderNum) {
  192. temp = spotsList.list[j];
  193. spotsList.list[j] = spotsList.list[j + 1];
  194. spotsList.list[j + 1] = temp;
  195. }
  196. }
  197. }
  198. flowData = spotsList.list;
  199. for (i = 0; i < spotsList.list.length ; i++) {
  200. sID[i] = spotsList.list[i].spotId;
  201. namedata[i] = spotsList.list[i].spotName;
  202. }
  203. firsttime_load_spots_data();
  204. }
  205. function on_document_load() {
  206. // First Step
  207. get_data("fcSpot/list?flowId=" + thisPageFlow, on_load_success_spots)
  208. }
  209. var namedata = [];