cdceaae30277dc373d4f4fa0c941507f61b46597.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. BemsWebApplication.UsekindUsageCompare = function (params, viewInfo) {
  2. "use strict";
  3. var endpointSelector = "";
  4. if (BemsWebApplication.config.mode == "production") {
  5. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  6. } else {
  7. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  8. }
  9. var kcalTokWh;
  10. var CODE = $Code,
  11. FuelType = CODE.g_fuelTypes,
  12. FacilityType = CODE.FacilityType,
  13. FacilityCode = CODE.FacilityCode,
  14. F = CODE.Formula,
  15. TIT = CODE.TimeIntervalType;
  16. var curMonthData = [{
  17. month: "0",
  18. beforeYear: null,
  19. curYear: null
  20. }];
  21. // 2019.04.16 : 그리드 도표 작업 : 팝업창 추가 ~~~
  22. // 팝업창뷰 보이기 속성 제어용 변수 선언
  23. var DataGridPopup_Visible = ko.observable(false);
  24. // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언
  25. var dataArrayresult = ko.observableArray();
  26. // ~~~ 2019.04.16 : 그리드 도표 작업 : 팝업창 추가
  27. var energyUsageStatusGet = new BWA.Chart.PointHistoryServiceTypeGet(BWA.UserInfo.SiteId());
  28. var chartDataSource = [{
  29. month: "1",
  30. beforeYear: null,
  31. curYear: null
  32. }, {
  33. month: "2",
  34. beforeYear: null,
  35. curYear: null
  36. }, {
  37. month: "3",
  38. beforeYear: null,
  39. curYear: null
  40. }, {
  41. month: "4",
  42. beforeYear: null,
  43. curYear: null
  44. }, {
  45. month: "5",
  46. beforeYear: null,
  47. curYear: null
  48. }, {
  49. month: "6",
  50. beforeYear: null,
  51. curYear: null
  52. }, {
  53. month: "7",
  54. beforeYear: null,
  55. curYear: null
  56. }, {
  57. month: "8",
  58. beforeYear: null,
  59. curYear: null
  60. }, {
  61. month: "9",
  62. beforeYear: null,
  63. curYear: null
  64. }, {
  65. month: "10",
  66. beforeYear: null,
  67. curYear: null
  68. }, {
  69. month: "11",
  70. beforeYear: null,
  71. curYear: null
  72. }, {
  73. month: "12",
  74. beforeYear: null,
  75. curYear: null
  76. }];
  77. function numberWithCommas(x) {
  78. return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  79. }
  80. function GetUsekindSelectData() {
  81. var now = new Date();
  82. var selectDate = $("#standardDatePicker").dxDateBox("instance").option("value");
  83. var dataSource = new DevExpress.data.DataSource({
  84. store: {
  85. type: "odata",
  86. url: endpointSelector + "/CmServiceEnergyCalcMonth"
  87. },
  88. requireTotalCount: true,
  89. pageSize: 1000
  90. });
  91. dataSource.filter([
  92. ["SiteId", "=", BWA.UserInfo.SiteId()],
  93. "and",
  94. ["calDate", ">=", new Date(selectDate.getFullYear() - 1, 0, 1)],
  95. "and",
  96. ["calDate", "<=", new Date(selectDate.getFullYear(), 11, 31)]
  97. ]);
  98. dataSource.sort({ getter: "calDate", asc: true });
  99. dataSource.load()
  100. .done(function (result) {
  101. var tmpArray = new Array();
  102. for (var i = 0; i < result.length; i++) {
  103. var checkDulp = false;
  104. if (tmpArray.length == 0) {
  105. tmpArray[0] = new Array("ServiceTypeId","Name");
  106. tmpArray[0].ServiceTypeId = result[i].ServiceTypeId;
  107. continue;
  108. }
  109. for (var j = 0; j < tmpArray.length; j++) {
  110. if (result[i].ServiceTypeId == tmpArray[j].ServiceTypeId)
  111. checkDulp = true;
  112. }
  113. if (!checkDulp){
  114. tmpArray[j] = new Array("ServiceTypeId", "Name");
  115. tmpArray[j].ServiceTypeId = result[i].ServiceTypeId;
  116. }
  117. }
  118. var dataSourceServiceType = new DevExpress.data.DataSource({
  119. store: {
  120. type: "odata",
  121. url: endpointSelector + "/BemsServiceType"
  122. },
  123. requireTotalCount: true,
  124. pageSize: 100
  125. });
  126. dataSourceServiceType.sort({ getter: "ServiceTypeId", asc: true });
  127. dataSourceServiceType.load()
  128. .done(function (resultServiceType) {
  129. for (var i = 0; i < tmpArray.length; i++) {
  130. for(var j = 0; j < resultServiceType.length; j++){
  131. if (tmpArray[i].ServiceTypeId == resultServiceType[j].ServiceTypeId) {
  132. tmpArray[i].Name = resultServiceType[j].Name;
  133. }
  134. }
  135. }
  136. $("#usekindSelect").dxSelectBox("instance").option('dataSource', tmpArray);
  137. $("#usekindSelect").dxSelectBox("instance").option('displayExpr', "Name");
  138. $("#usekindSelect").dxSelectBox("instance").option('valueExpr', "ServiceTypeId");
  139. if(tmpArray.length > 0) {
  140. $("#usekindSelect").dxSelectBox("instance").option('value', tmpArray[0].ServiceTypeId);
  141. }
  142. })
  143. .fail(function (error) {
  144. utils.toast.show(error);
  145. });
  146. })
  147. .fail(function (error) {
  148. utils.toast.show(error);
  149. });
  150. }
  151. function GetChartData(serviceTypeId) {
  152. var now = new Date();
  153. var selectDate = $("#standardDatePicker").dxDateBox("instance").option("value");
  154. var dataSourceBeforeYear = new DevExpress.data.DataSource({
  155. store: {
  156. type: "odata",
  157. url: endpointSelector + "/CmServiceEnergyCalcMonth"
  158. },
  159. requireTotalCount: true,
  160. pageSize: 1000
  161. });
  162. dataSourceBeforeYear.filter([
  163. ["SiteId", "=", BWA.UserInfo.SiteId()],
  164. "and",
  165. ["calDate", ">=", new Date(selectDate.getFullYear() - 1, 0, 1)],
  166. "and",
  167. ["calDate", "<=", new Date(selectDate.getFullYear() - 1, 11, 31)],
  168. "and",
  169. ["ServiceTypeId", "=", serviceTypeId]
  170. ]);
  171. dataSourceBeforeYear.sort({ getter: "calDate", asc: true });
  172. dataSourceBeforeYear.load()
  173. .done(function (resultBeforeYear) {
  174. for (var j = 0; j < chartDataSource.length; j++) {
  175. chartDataSource[j].beforeYear = null;
  176. }
  177. for (var i = 0; i < resultBeforeYear.length; i++) {
  178. chartDataSource[i].beforeYear = resultBeforeYear[i].Value / kcalTokWh;
  179. }
  180. var dataSourceCurYear = new DevExpress.data.DataSource({
  181. store: {
  182. type: "odata",
  183. url: endpointSelector + "/CmServiceEnergyCalcMonth"
  184. },
  185. requireTotalCount: true,
  186. pageSize: 1000
  187. });
  188. dataSourceCurYear.filter([
  189. ["SiteId", "=", BWA.UserInfo.SiteId()],
  190. "and",
  191. ["calDate", ">=", new Date(selectDate.getFullYear(), 0, 1)],
  192. "and",
  193. ["calDate", "<=", new Date(selectDate.getFullYear(), 11, 31)],
  194. "and",
  195. ["ServiceTypeId", "=", serviceTypeId]
  196. ]);
  197. dataSourceCurYear.sort({ getter: "calDate", asc: true });
  198. dataSourceCurYear.load()
  199. .done(function (resultCurYear) {
  200. for (var j = 0; j < chartDataSource.length; j++) {
  201. chartDataSource[j].curYear = null;
  202. }
  203. for (var i = 0; i < resultCurYear.length; i++) {
  204. chartDataSource[i].curYear = resultCurYear[i].Value / kcalTokWh;
  205. }
  206. if (selectDate.getMonth() == now.getMonth()) {
  207. for (var i = 0; i < curMonthData[0].length;i++){
  208. if (serviceTypeId == curMonthData[0][i].ServiceType) {
  209. chartDataSource[now.getMonth()].curYear = chartDataSource[now.getMonth()].curYear + curMonthData[0][i].Value / kcalTokWh;
  210. }
  211. }
  212. }
  213. $("#chartMonth").dxChart("instance").option('dataSource', chartDataSource);
  214. })
  215. .fail(function (error) {
  216. utils.toast.show(error);
  217. });
  218. })
  219. .fail(function (error) {
  220. utils.toast.show(error);
  221. });
  222. }
  223. function GetkcalTokWh() {
  224. var dataSource = new DevExpress.data.DataSource({
  225. store: {
  226. type: "odata",
  227. url: endpointSelector + "/BemsFactorToe"
  228. },
  229. requireTotalCount: true,
  230. pageSize: 100
  231. });
  232. dataSource.filter([
  233. ["FuelTypeId", "=", 1]
  234. ]);
  235. dataSource.load()
  236. .done(function (result) {
  237. kcalTokWh = result[0].kcal;
  238. })
  239. .fail(function (error) {
  240. utils.toast.show(error);
  241. });
  242. }
  243. function loadDailyEnergyUsage(year, month) {
  244. /*
  245. var startDate, endDate;
  246. var monthMoment;
  247. if (_.isUndefined(month)) {
  248. monthMoment = moment();
  249. }
  250. else {
  251. monthMoment = moment().month(month - 1);
  252. }
  253. startDate = monthMoment.startOf('month');
  254. endDate = monthMoment.clone().endOf('month'); */
  255. //2016 02 26
  256. var startDate, endDate;
  257. var monthMoment;
  258. monthMoment = moment(year).month(month - 1);
  259. startDate = monthMoment.startOf('month');
  260. endDate = monthMoment.clone().endOf('month');
  261. var commonParameters = {
  262. TimeIntervalType: TIT.DAY,
  263. StartDate: startDate,
  264. EndDate: endDate
  265. };
  266. var pointHistoryParameters = {
  267. BuildingId: 0,
  268. FloorId: null,
  269. ZoneId: null,
  270. //FuelTypeId: fuelTypeIdForSearch()
  271. FuelTypeId: null
  272. };
  273. var promises = [];
  274. /* _.each(FuelType, function (x) {
  275. if (x.FuelTypeId() < 3) {
  276. pointHistoryParameters.FuelTypeId = x.FuelTypeId();
  277. promises.push(energyUsageStatusGet.apiGet(_.extend(pointHistoryParameters, commonParameters)));
  278. }
  279. //promises.push(energyUsageStatusGet.requestGetForEnergyService(x, TIT.DAY,7)
  280. //(startDate, endDate));
  281. });*/
  282. pointHistoryParameters.FuelTypeId = -1;
  283. promises.push(energyUsageStatusGet.apiGet(_.extend(pointHistoryParameters, commonParameters)));
  284. $.when.apply(this, promises).done(function (v) {
  285. curMonthData = v;
  286. })
  287. .fail(function (error) {
  288. utils.toast.show(error);
  289. });
  290. }
  291. // 2019.04.15 : 그리드 도표 작업 : 팝업창 추가 ~~~
  292. function DataGridPopup_ButtonClick() {
  293. // DevExpress.ui.notify("날짜가 일치하지 않는 데이타가 존재합니다", "fail", 1000);
  294. DataGridPopup_Visible(true);
  295. }
  296. function handlePopupShown() {
  297. dataArrayresult = chartDataSource;
  298. // 데이타소스 업데이트
  299. $("#UsekindUsageCompare_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
  300. // 팝업창 갱신
  301. DataGridPopup_Visible(true);
  302. }
  303. // ~~~ 2019.04.15 : 그리드 도표 작업 : 팝업창 추가
  304. function handleViewShowing() {
  305. GetkcalTokWh();
  306. var now = new Date();
  307. loadDailyEnergyUsage(now.getFullYear().toString(), (now.getMonth() + 1).toString());
  308. }
  309. function handleViewShown() {
  310. $("#loadIndicator").dxLoadIndicator("instance").option('visible', true);
  311. setTimeout(function () {
  312. GetUsekindSelectData();
  313. $("#loadIndicator").dxLoadIndicator("instance").option('visible', false);
  314. }, 1000);
  315. }
  316. var searchViewOptions = {
  317. };
  318. function handleSearchInSearchView() {
  319. }
  320. var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
  321. {
  322. viewShowing: handleViewShowing,
  323. usekindSelect: {
  324. //value : 2,
  325. onSelectionChanged: function () {
  326. var serviceTypeId = $("#usekindSelect").dxSelectBox("instance").option('value');
  327. GetChartData(serviceTypeId);
  328. }
  329. },
  330. chartMonth: {
  331. //dataSource: monthDataSource,
  332. commonSeriesSettings: {
  333. argumentField: "month",
  334. type: "line"
  335. },
  336. series: [
  337. { valueField: "beforeYear", name: "전년" },
  338. { valueField: "curYear", name: "금년" },
  339. ],
  340. legend: {
  341. position: 'outside',
  342. verticalAlignment: "top",
  343. horizontalAlignment: "center",
  344. itemTextPosition: 'bottom'
  345. },
  346. valueAxis: {
  347. title: {
  348. text: "에너지 사용량(kWh)"
  349. },
  350. position: "left"
  351. },
  352. argumentAxis: {
  353. type: "line",
  354. position: 'bottom',
  355. grid: { visible: true }
  356. },
  357. "export": {
  358. enabled: true
  359. },
  360. /*title: {
  361. font: { size: 15 },
  362. text: '전년 대비 금년도 에너지 사용량 비교'
  363. },*/
  364. tooltip: {
  365. enabled: true,
  366. //format: 'largeNumber',
  367. customizeTooltip: function (point) {
  368. return {
  369. text: numberWithCommas(point.value.toFixed(2))
  370. };
  371. }
  372. }
  373. },
  374. standardDatePicker: {
  375. pickerType: "calendar",
  376. value: new Date(),
  377. formatString: "yyyy년",
  378. maxZoomLevel: "decade",
  379. width: "8%",
  380. onValueChanged: function () {
  381. GetUsekindSelectData();
  382. }
  383. },
  384. loadIndicator: {
  385. visible: false
  386. },
  387. // 2019.04.16 : 그리드 도표 작업 : 팝업창 추가
  388. UsekindUsageComparePopup_ButtonClicked: DataGridPopup_ButtonClick
  389. // 2019.04.16 : 그리드 도표 작업 : 팝업창 추가
  390. });
  391. // 2019.04.16 : 그리드 도표 작업 : 팝업창 추가 ~~~
  392. // 그래프 도표 팝업창
  393. viewModel.UsekindUsageComparePopupOptions = {
  394. width: '480px',
  395. height: '750px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨
  396. contentTemplate: "content",
  397. showTitle: true,
  398. title: "도표",
  399. visible: DataGridPopup_Visible,
  400. dragEnabled: true,
  401. closeOnOutsideClick: true,
  402. shownAction: handlePopupShown,
  403. animation: window.utils.popup.createAnimation()
  404. };
  405. // 주석이 너무 없음. 나중에 변경 작업을 진행하는 누군가가 시간 소비를 하지 않기 위해...남김
  406. // 시간 포맷은 그래프에 귀속해야 되므로 포맷은 변경하지 않는 것이 유리함
  407. // 전기,가스,수도 와 같이 선택적으로 변경해야 된다면 아래와 같이 캡션은 고정하지 말것
  408. viewModel.UsekindUsageCompareOptions = {
  409. dataSource: dataArrayresult,
  410. paging: { pageSize: 17 },
  411. columns: [
  412. { dataField: 'month', caption: "월", width: '10%', alignment: 'center', },// dataType: 'date', format: 'yyyy-MM-dd HH:mm' },
  413. { dataField: 'beforeYear', caption: "전년 에너지 사용량(kWh)", width: '45%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  414. { dataField: 'curYear', caption: "금년 에너지 사용량(kWh)", width: '45%', alignment: 'center', format: 'fixedPoint', precision: 2 }
  415. ],
  416. // 엑셀 출력
  417. "export": {
  418. enabled: true,
  419. fileName: '용도별 전년 동월대비 에너지사용량 증감 분석'
  420. }
  421. };
  422. // ~~~ 2019.04.16 : 그리드 도표 작업 : 팝업창 추가
  423. return viewModel;
  424. };