basic.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 workID=[];
  60. function firsttime_load_spots_data() {
  61. get_data("fcWorkScheduleLoad/list?scheduleId=" + scheduleId, 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,k,z;
  79. failnum=0;
  80. var x=0;
  81. var worksum=[];
  82. workID[0]=output.list[0].userId;
  83. passNumber[0]=0;
  84. failNumber[0]=0;
  85. stackeverynum[0]=0;
  86. z=0;
  87. for(i=1;i<output.list.length;i++){
  88. var thisUid = output.list[i].userId;
  89. x = 0;
  90. for(j=0;j<workID.length;j++){
  91. if(workID[j] === thisUid){
  92. x=1;
  93. break;
  94. }
  95. }
  96. if(x===0){
  97. workID.push(thisUid);
  98. }
  99. }
  100. j=0;
  101. for(k=0;k<workID.length;k++){
  102. var uid = workID[k];
  103. z=0;
  104. for(i=0;i<output.list.length;i++){
  105. if(uid===output.list[i].userId){
  106. passNumber[k]=output.list[i].passNum+passNumber[j];
  107. failNumber[k]=output.list[i].failNum+failNumber[j];
  108. stackeverynum[k]=output.list[i].due+stackeverynum[j];
  109. z++;
  110. }
  111. }
  112. if (failNumber[k] + passNumber[k] == 0) {
  113. failrate[k] = 0;
  114. }
  115. else {
  116. failrate[k] = failNumber[k] / (failNumber[k] + passNumber[k]) * 100;
  117. }
  118. stackeverynum[k]=stackeverynum[k]/z;
  119. ///
  120. }
  121. for(i=1;i<5;i++) {
  122. secondtime_load_spots_data();
  123. }
  124. chart_load_spots_data();
  125. chart1_load_spots_data();
  126. showChart();
  127. setInterval(function(){
  128. get_data("fcWorkScheduleLoad/list?scheduleId=" + scheduleId, realtime_success);
  129. },1000);
  130. }
  131. function second_success(obj, sta) {
  132. var history = first_parse(this, obj);
  133. var i, j;
  134. console.log(" history : ");
  135. console.log(history);
  136. hispass[t] = 0;
  137. hisfail[t] = 0;
  138. hisstack[t] = 0;
  139. hisrate[t]=0;
  140. for(i=0;i<history.length;i++){
  141. hispass[t] = history[i].passNum+hispass[t];
  142. hisfail[t] = history[i].failNum+hisfail[t];
  143. hisstack[t] = history[i].avgDue+hisstack[t];
  144. hisrate[t] = history[i].failRate;
  145. hisrate[t]=hisrate[t]/100;
  146. }
  147. if(history.length!=1){
  148. hisrate[t]=Math.floor(hisfail[t]/(hispass[t]+hisfail[t])*10000)/100;
  149. }
  150. if(hispass[t]+hisfail[t]==0){
  151. hisrate[t]=0;
  152. }
  153. t++;
  154. }
  155. function chart_success(obj, sta) {
  156. var redchart = first_parse(this, obj);
  157. var i, j;
  158. i=j=0;
  159. console.log(" redchart : ");
  160. console.log(redchart);
  161. for(i=0;i<3;i++){
  162. goodid[i]=redchart.list[i].workerId;
  163. goodpass[i]=redchart.list[i].passNum;
  164. goodfailrate[i]=redchart.list[i].failRate/100;
  165. }
  166. }
  167. function chart1_success(obj, sta) {
  168. var blackchart = first_parse(this, obj);
  169. var i, j;
  170. i=j=0;
  171. console.log(" black chart : ");
  172. console.log(blackchart);
  173. for(i=0;i<3;i++){
  174. badid[i]=blackchart.list[i].workerId;
  175. badpass[i]=blackchart.list[i].passNum;
  176. badfailrate[i]=blackchart.list[i].failRate/100;
  177. }
  178. }
  179. function realtime_success(obj, sta) {
  180. var output = first_parse(this, obj);
  181. //在这里排序 spo\
  182. console.log(" output : ");
  183. console.log(output);
  184. var i, j,k,z;
  185. failnum=0;
  186. var x=0;
  187. var worksum=[];
  188. workID[0]=output.list[0].userId;
  189. passNumber[0]=0;
  190. failNumber[0]=0;
  191. stackeverynum[0]=0;
  192. z=0;
  193. for(i=1;i<output.list.length;i++){
  194. var thisUid = output.list[i].userId;
  195. x = 0;
  196. for(j=0;j<workID.length;j++){
  197. if(workID[j] === thisUid){
  198. x=1;
  199. break;
  200. }
  201. }
  202. if(x===0){
  203. workID.push(thisUid);
  204. }
  205. }
  206. j=0;
  207. for(k=0;k<workID.length;k++){
  208. var uid = workID[k];
  209. z=0;
  210. for(i=0;i<output.list.length;i++){
  211. if(uid===output.list[i].userId){
  212. passNumber[k]=output.list[i].passNum+passNumber[j];
  213. failNumber[k]=output.list[i].failNum+failNumber[j];
  214. stackeverynum[k]=output.list[i].due+stackeverynum[j];
  215. z++;
  216. }
  217. }
  218. if (failNumber[k] + passNumber[k] == 0) {
  219. failrate[k] = 0;
  220. }
  221. else {
  222. failrate[k] = failNumber[k] / (failNumber[k] + passNumber[k]) * 100;
  223. }
  224. stackeverynum[k]=stackeverynum[k]/z;
  225. ///
  226. }
  227. updateChart();
  228. }
  229. /*function on_load_success_spots(obj, status) {
  230. var spotsList = first_parse(this, obj);
  231. //在这里排序 spo\
  232. console.log("spot List : ");
  233. console.log(spotsList);
  234. var i, j, temp;
  235. for (i = 0; i < spotsList.list.length - 1; i++) {
  236. for (j = 0; j < spotsList.list.length - i - 1; j++) {
  237. if (spotsList.list[j].orderNum > spotsList.list[j + 1].orderNum) {
  238. temp = spotsList.list[j];
  239. spotsList.list[j] = spotsList.list[j + 1];
  240. spotsList.list[j + 1] = temp;
  241. }
  242. }
  243. }
  244. flowData = spotsList.list;
  245. for (i = 0; i < spotsList.list.length ; i++) {
  246. sID[i] = spotsList.list[i].spotId;
  247. namedata[i] = spotsList.list[i].spotName;
  248. }
  249. firsttime_load_spots_data();
  250. }*/
  251. function on_document_load() {
  252. // First Step
  253. //get_data("fcSpot/list?flowId=" + scheduleId, on_load_success_spots)
  254. firsttime_load_spots_data();
  255. }
  256. var namedata = [];