msgSendResult.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /**
  2. * admin/msgSendResult
  3. */
  4. var mcare_admin_msgSendResult = function(){
  5. //상속
  6. mcare_admin.call(this);
  7. var self = this;
  8. //변수
  9. var $search = $("#search"),
  10. $endDate = $("#endDate"),
  11. $selectOption = $("#select-option"),
  12. $strDate = $("#strDate"),
  13. $grid = $("#grid"),
  14. $chart = $("#chart"),
  15. $legend = $("#chart_legend"),
  16. $crudServiceBaseUrl = contextPath + "/admin/stats";
  17. /**
  18. * 초기화
  19. */
  20. this.init = function(){
  21. initDatePicker();
  22. initDropDownList();
  23. initGrid();
  24. addEvent();
  25. };
  26. /**
  27. * 이벤트 등록
  28. */
  29. var addEvent = function(){
  30. // 검색 이벤트
  31. $search.on("click", function(e){
  32. //mcare_admin 상속
  33. self.search( dataSource, false );
  34. });
  35. };
  36. /**
  37. * datepicker 초기화
  38. */
  39. var initDatePicker = function(){
  40. //mcare_admin 상속
  41. self.datePicker( $endDate, $strDate, $selectOption );
  42. };
  43. /**
  44. * 검색 조건 dropdown 초기화
  45. */
  46. var initDropDownList = function(){
  47. //mcare_admin 상속
  48. self.dropDownList( $selectOption );
  49. };
  50. //데이터소스
  51. var aggDt = [],
  52. totalCnt = [],
  53. successCnt = [];
  54. /**
  55. * 데이터소스 설정
  56. */
  57. var setDataSource = function(){
  58. var dataSource = new kendo.data.DataSource({
  59. transport: {
  60. read: {
  61. url: $crudServiceBaseUrl + "/getMsgResultLogList.json",
  62. method: "post",
  63. dataType: "json",
  64. contentType: "application/json"
  65. },
  66. parameterMap: getParameterMap
  67. },
  68. schema: {
  69. data : getSchemaData
  70. },
  71. change: function(e) {
  72. // update chart
  73. }
  74. });
  75. /**
  76. * 데이터소스 파라미터맵
  77. * @private
  78. */
  79. function getParameterMap( options, operation ){
  80. var param = $.extend(true, {}, options, {
  81. strDate : new Date( self.getStartDatePickerValue() ).setHours(0, 0, 0, 0),
  82. endDate : new Date( +self.getEndDatePickerValue() ).setHours(0, 0, 0, 0),
  83. }, null);
  84. return self.util.stringifyJson( param );
  85. };
  86. /**
  87. * 데이터소스 스키마설정
  88. * @private
  89. */
  90. function getSchemaData(e){
  91. if( e.msg !== undefined ){
  92. alert(e.msg);
  93. return [];
  94. }
  95. var dataList = e.aggMsgSendResultLogList;
  96. var accessDateArr = aggDt = new Array(),
  97. totalCntArr = totalCnt = new Array(),
  98. successCntArr = successCnt = new Array();
  99. var startNum = Number( self.getStartDatePickerValue() ),
  100. endNum = Number( +self.getEndDatePickerValue() + (60*60*24*1000) );
  101. for( var d = startNum, i = 0 ; d < endNum ; d += (60*60*24*1000), i++ ) {
  102. var strDate = kendo.toString( new Date(d), "yyyy-MM-dd" );
  103. accessDateArr.push( strDate );
  104. totalCntArr.push(0);
  105. successCntArr.push(0);
  106. for( var n = 0 ; n < dataList.length ; n ++ ) {
  107. if( strDate === dataList[n].aggDt.split(" ")[0] ) {
  108. totalCntArr[i] = dataList[n].totalCnt;
  109. successCntArr[i] = dataList[n].successCnt;
  110. }
  111. }
  112. }
  113. var param = [];
  114. for( var n = 0, size = accessDateArr.length ; n < size ; n ++ ) {
  115. param.push({
  116. "accessDate" : accessDateArr[n],
  117. "totalCnt" : totalCntArr[n],
  118. "successCnt" : successCntArr[n]
  119. });
  120. }
  121. return param;
  122. };
  123. return dataSource;
  124. };
  125. var dataSource = setDataSource();
  126. /**
  127. * 그리드 초기화
  128. */
  129. var initGrid = function(){
  130. // 그리드 옵션
  131. var option = {
  132. dataSource: dataSource,
  133. //그리드 데이터 받아온 뒤 차트 초기화
  134. dataBound: function(){
  135. initChart();
  136. //전송실패 없으면 실패 원인 버튼을 임의로 숨기기 - kendo template 으로 처리가 안되서 임의로 숨김
  137. var failBtnSet = $(".failBtn");
  138. for( var i = 0; i < failBtnSet.length; i++ ){
  139. var item = $( failBtnSet[i] ),
  140. data = item.data(),
  141. total = data["total"],
  142. success = data["success"];
  143. if( total === success ){
  144. item.hide();
  145. }
  146. }
  147. //버튼 이벤트 등록 - 동적으로 생성했으므로
  148. $(".failBtn").on("click",function(e){
  149. var date = $(this).attr("data-date");
  150. //동적으로 그리드 초기화 시켜서 화면에 표시 - api 트리 선택하면 그리드 생기는 것 처럼
  151. viewDetail(date);
  152. });
  153. },
  154. pageable: false,
  155. selectable: false,
  156. height : 215,
  157. columns : [
  158. {
  159. field : "accessDate",
  160. title : "날짜",
  161. width: 200,
  162. attributes: {
  163. "class": "table-cell",
  164. style: "text-align: center;"
  165. }
  166. },
  167. {
  168. field : "totalCnt",
  169. title : "전체전송수",
  170. width: 200,
  171. template: "#= kendo.toString(data.totalCnt,'n0')# 건",
  172. attributes: {
  173. "class": "table-cell",
  174. style: "text-align: center;"
  175. }
  176. },
  177. {
  178. field : "successCnt",
  179. title : "성공전송수",
  180. width: 200,
  181. template: "#= kendo.toString(data.successCnt,'n0')# 건",
  182. attributes: {
  183. "class": "table-cell",
  184. style: "text-align: center;"
  185. }
  186. },
  187. {
  188. title : "",
  189. width: 100,
  190. template: "<button class='failBtn k-button' data-total='#:data.totalCnt#' data-success='#:data.successCnt#' data-date='#=accessDate#' >실패원인</button>",
  191. attributes: {
  192. "class": "table-cell",
  193. style: "text-align: center;"
  194. }
  195. }
  196. ]
  197. };
  198. //그리드 초기화 - mcare_admin
  199. self.grid( $grid, option );
  200. };
  201. /**
  202. * 차트 초기화
  203. */
  204. var initChart = function(){
  205. // 차트 옵션 TODO: chartjs로 변경한다
  206. var data = { labels: aggDt,
  207. datasets: [
  208. {
  209. label: "전체전송수",
  210. fillColor: "rgba(220,220,220,0.2)",
  211. strokeColor: "rgba(220,220,220,1)",
  212. pointColor: "rgba(220,220,220,1)",
  213. pointStrokeColor: "#fff",
  214. pointHighlightFill: "#fff",
  215. pointHighlightStroke: "rgba(220,220,220,1)",
  216. data: totalCnt
  217. },
  218. {
  219. label: "성공전송수",
  220. fillColor: "rgba(151,187,205,0.0)",
  221. strokeColor: "rgba(151,187,205,1)",
  222. pointColor: "rgba(151,187,205,1)",
  223. pointStrokeColor: "#fff",
  224. pointHighlightFill: "#fff",
  225. pointHighlightStroke: "rgba(151,187,205,1)",
  226. data: successCnt
  227. }
  228. ]
  229. };
  230. var option = {
  231. tooltipTemplate: "<%= value %>건"
  232. };
  233. //차트 초기화 mcare_admin
  234. self.chart( $chart, "line", option, data, $legend );
  235. };
  236. var viewDetail = function(date){
  237. kendo.ui.progress($(".main-wrapper"), true);
  238. // $.ajax({
  239. // url : $crudServiceBaseUrl + "/getMsgResultErrorTypeList.json",
  240. // method : "POST",
  241. // data : self.util.stringifyJson({strDate:date}),
  242. // contentType : "application/json",
  243. // success:function(data){
  244. // if( data.msg !== undefined ){
  245. // alert( data.msg );
  246. // } else {
  247. // displayErrorType(data.aggDailyMsgSendErrorLogList, date);
  248. // }
  249. // },
  250. // error:function(xhr){
  251. // console.log( xhr );
  252. // },
  253. // complete : function(){
  254. // kendo.ui.progress($(".main-wrapper"), false);
  255. // }
  256. // });
  257. var opt = {
  258. url : $crudServiceBaseUrl + "/getMsgResultErrorTypeList.json",
  259. method : "POST",
  260. data : self.util.stringifyJson({strDate:date}),
  261. contentType : "application/json",
  262. complete : function(){
  263. kendo.ui.progress( $(".main-wrapper"), false );
  264. }
  265. };
  266. var success = function(data){
  267. displayErrorType(data.aggDailyMsgSendErrorLogList, date);
  268. };
  269. var error = function(xhr,d,t){
  270. console.log( xhr );
  271. };
  272. self.ajaxAdmin( opt, success, error );
  273. };
  274. var displayErrorType = function(result, date){
  275. var option = {
  276. dataSource: {
  277. data: result,
  278. schema : {
  279. model : {
  280. fields : {
  281. errorType : { type : "string" },
  282. failCnt : { type : "number" }
  283. }
  284. }
  285. },
  286. pageSize : 20
  287. },
  288. dataBound: function(){
  289. },
  290. pageable: true,
  291. selectable: false,
  292. height : 300,
  293. columns : [
  294. {
  295. field : "errorType",
  296. title : "유형",
  297. width: 200,
  298. attributes: {
  299. "class": "table-cell",
  300. style: "text-align: center;"
  301. }
  302. },
  303. {
  304. field : "failCnt",
  305. title : "건수",
  306. width: 200,
  307. attributes: {
  308. "class": "table-cell",
  309. style: "text-align: center;"
  310. }
  311. }
  312. ]
  313. };
  314. $( "<div></div>" ).html( "<div style='font-weight:bold;margin:10px;'>"+date+"</div>" ).append( $("<div class='errorGrid'></div>" )).kendoWindow({
  315. width : 600,
  316. height : 400,
  317. title : "메시지 전송 실패원인",
  318. close : function() {
  319. this.destroy();
  320. }
  321. }).data("kendoWindow").open().center();
  322. $(".errorGrid").kendoGrid(option).data("kendoGrid") ;
  323. };
  324. };