d941062ffff9f692414d19bd2fe68e91e1930603.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. BemsWebApplication.GreenEnergy = function (params, viewInfo) {
  2. "use strict";
  3. var factorCo2 = null;
  4. var factorCo2DataSource = BemsWebApplication.db.createDataSource('BemsFactorCo2');
  5. var factorToe = null;
  6. var factorToeDataSource = BemsWebApplication.db.createDataSource('BemsFactorToe');
  7. var initialized = false,
  8. shouldReload = false,
  9. datagrid = null,
  10. currentTabIndex = ko.observable(0),
  11. facilityViewModel = new BWA.CmFacilityViewModel(),
  12. dataSource;
  13. var multiViewItems = [{
  14. template: 'mainCharts'
  15. }, {
  16. template: 'subCharts'
  17. }
  18. ];
  19. var facilityDataSource = BWA.db.createDataSource('CmFacility'),
  20. facilitiesForSearch = ko.observableArray(),
  21. facilityCodeForSearch = ko.observable(0),
  22. deferredForSearch = new $.Deferred();
  23. var visiblePopup = ko.observable(false);
  24. var m_Facility;
  25. var dataCalorie = ko.observableArray(),
  26. dataAtfw = ko.observableArray(),
  27. dataTemperatureCalorie = ko.observableArray(),
  28. dataTemperatureElectricity = ko.observableArray();
  29. var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
  30. var timeBoxForSearch = BWA.SearchView.createDateTimeBox();
  31. var chartElec = BWA.Chart.Instance('chartGreenElec', 'dxChart');
  32. var chartElecConsume = BWA.Chart.Instance('chartGreenElecConsume', 'dxChart');
  33. var measureSelect = BWA.Chart.Instance('measureSelect', 'dxSelectBox');
  34. var chartLayout = new BWA.ChartLayout({
  35. divs: [{
  36. id: 'GreenEnergyDetail'
  37. }, {
  38. id: 'elec',
  39. chartId: 'chartGreenElec'
  40. }, {
  41. id: 'elec',
  42. chartId: 'chartGreenElecConsume'
  43. },
  44. {
  45. id: 'elec',
  46. chartId: 'measureSelect'
  47. }
  48. ],
  49. multiViewOptions: {
  50. viewIndex: currentTabIndex,
  51. viewCount: 1,
  52. swipeEnabled: false,
  53. }
  54. });
  55. var m = moment();
  56. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  57. // 팝업창뷰 보이기 속성 제어용 변수 선언
  58. var DataGridPopup_Visible = ko.observable(false);
  59. // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언
  60. var dataArrayresult = ko.observableArray();
  61. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  62. dataCalorie([
  63. { DateTime: new Date(m.year(), m.month(), 1), Value: 50 },
  64. { DateTime: new Date(m.year(), m.month(), 2), Value: 50 },
  65. { DateTime: new Date(m.year(), m.month(), 3), Value: 60 },
  66. { DateTime: new Date(m.year(), m.month(), 4), Value: 80 },
  67. { DateTime: new Date(m.year(), m.month(), 5), Value: 100 },
  68. { DateTime: new Date(m.year(), m.month(), 6), Value: 40, },
  69. { DateTime: new Date(m.year(), m.month(), 7), Value: 120 },
  70. { DateTime: new Date(m.year(), m.month(), 31), Value: 120 }
  71. ]);
  72. // 추가 2015 04 20 hcLee ->
  73. var CODE = $Code,
  74. FuelType = CODE.FuelType,
  75. FT = CODE.FacilityType,
  76. FC = CODE.FacilityCode,
  77. F = CODE.Formula,
  78. TIT = CODE.TimeIntervalType;
  79. // 추가 2015 04 20 hcLee <-
  80. //dataMonthForBar(dataDayForBar());
  81. //dataDayForPie([
  82. // { FuelTypeName: '전기', Value: 320 },
  83. // { FuelTypeName: '가스', Value: 350 },
  84. // { FuelTypeName: '수도', Value: 360 },
  85. //]);
  86. //dataMonthForPie(dataDayForPie());
  87. function handleViewShown() {
  88. if (initialized === false) {
  89. var chartOption = BWA.ChartOptions.GreenEnergy;
  90. //chartElec = chartElec(chartOption.getChartElecOptions($Code.TimeType.HOUR));
  91. chartElec = chartElec(chartOption.getChartElecOptions(timeBoxForSearch.type()));
  92. chartElecConsume = chartElecConsume(chartOption.getChartElecConsumeOptions(timeBoxForSearch.type()));
  93. measureSelect = measureSelect(chartOption.getMeasureSelectOptions());
  94. $("#measureSelect").dxSelectBox("instance").option('value', '생산량');
  95. //$("#chartGreenElecConsume").hide();
  96. //var options = BWA.ChartOptions.GreenEnergy.getChartElecOptions(timeBoxForSearch.type());
  97. initialized = true;
  98. }
  99. var eq = BWA.DataUtil.constructEqualFilter;
  100. facilityDataSource.filter([
  101. eq('SiteId', BWA.UserInfo.SiteId()),
  102. 'and',
  103. [eq('FacilityTypeId', $Code.FacilityType.GREEN_ENERGY), 'or', eq('FacilityTypeId', 22)] // GREEN_ENERGY -> 22(신재생 발전)
  104. ]);
  105. var whenPromise = $.when(factorCo2DataSource.load(), facilityDataSource.load(), factorToeDataSource.load())
  106. .then(function (dbfactorsCo2, facilities, dbfactorsToe) {
  107. factorCo2 = BWA.Bems.refineFactorCo2DataArray(dbfactorsCo2[0]);
  108. factorToe = BWA.Bems.refineFactorToeDataArray(dbfactorsToe[0]);
  109. var arrayRV = [];
  110. for (var i = facilities[0].length - 1; i >= 0; i--)
  111. arrayRV.push(facilities[0][i])
  112. //facilitiesForSearch(facilities[0]);
  113. //if (_.isEmpty(facilities[0]) === false) {
  114. facilitiesForSearch(arrayRV);
  115. if (_.isEmpty(arrayRV) === false) {
  116. var f = arrayRV[0];
  117. handleSelectedFacilityInSearchView(f);
  118. handleSearchInSearchView();
  119. var datagrid = $('#GreenEnergyDataGridViewInSearchView').dxDataGrid('instance');
  120. if (_.has(datagrid, 'selectRows')) {
  121. datagrid.selectRows(f);
  122. }
  123. }
  124. });
  125. /*
  126. facilityDataSource.load().done(function(facilities) {
  127. facilitiesForSearch(facilities);
  128. if (_.isEmpty(facilities) === false) {
  129. var f = facilities[0];
  130. handleSelectedFacilityInSearchView(f);
  131. handleSearchInSearchView();
  132. var datagrid = $('#GreenEnergyDataGridViewInSearchView').dxDataGrid('instance');
  133. if (_.has(datagrid, 'selectRows')) {
  134. datagrid.selectRows(f);
  135. }
  136. }
  137. });*/
  138. }
  139. if (shouldReload) {
  140. //shouldReload = false;
  141. //dataSource.pageIndex(0);
  142. //dataSource.load();
  143. }
  144. function handleViewHidden() {
  145. $SearchView.visibleObservable(false); // hcLee 2015 03 23
  146. //hideOverlay();
  147. // var dataGrid = $('#gridContainer').dxDataGrid('instance');
  148. // dataGrid.clearSelection();
  149. }
  150. function handleViewShowing() {
  151. }
  152. function refreshList() {
  153. //dataSource.pageIndex(0);
  154. //dataSource.load();
  155. }
  156. var searchViewOptions = {
  157. searchViewItems: [
  158. { id: 'FacilityCode', ignoreValue: 0, defaultValue: 0, value: facilityCodeForSearch, dataSource: facilitiesForSearch },
  159. ],
  160. promiseDataInSearchView: deferredForSearch.promise()
  161. };
  162. function handleSelectedFacilityInSearchView(facility) {
  163. m_Facility = facility;
  164. return;
  165. }
  166. function Process7() {
  167. var f = m_Facility.toJS();
  168. facilityViewModel.fromJS(f);
  169. var timeIntervalType = timeBoxForSearch.type();
  170. var formula = $Code.Formula[$Code.FacilityType.EARTH];
  171. var formulaIds = _.values(formula);
  172. var date = timeBoxForSearch.getDate();
  173. //utils.toast.displayTime=1000000;
  174. //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요');
  175. visiblePopup(true);
  176. // var startDate = moment().
  177. var promises = [];
  178. _.each(formulaIds, function (formulaId) {
  179. var p = formulaGet.apiGet({
  180. FacilityTypeId: f.FacilityTypeId,
  181. FacilityCode: f.FacilityCode,
  182. FormulaId: formulaId,
  183. TimeIntervalType: timeIntervalType,
  184. StartDate: date.startDate,
  185. EndDate: date.endDate
  186. });
  187. promises.push(p);
  188. });
  189. /*
  190. // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 ->
  191. var commonParameters = {
  192. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  193. StartDate: date.startDate,
  194. EndDate: date.endDate
  195. };
  196. var temperatureParameters = {
  197. FacilityTypeId: FT.OUTDOOR,
  198. FacilityCode: FC.OUTDOOR,
  199. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  200. };
  201. promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
  202. */ // 보일러는 필요 없다
  203. $.when.apply(this, promises)
  204. .done(function (E1, E2, E3, E4, E5, green) {
  205. // chart 1
  206. var ElecDataArray = [];
  207. var ElecDataArray_temp = [];
  208. _.each(green[0], function (x) {
  209. ElecDataArray.push({
  210. //DateTime: moment(x.DateTime).toDate(),
  211. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  212. kcal: x.Value,
  213. //co2: factorCo2.calculate((x.Value / factorToe[$Code.FuelType.GAS].KCAL), $Code.FuelType.GAS) * 1000, // 2016 04 12 추가
  214. });
  215. });
  216. _.each(green[0], function (x) {
  217. ElecDataArray_temp.push({
  218. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  219. kcal: x.Value,
  220. });
  221. });
  222. //chartElec().option('dataSource', ElecDataArray);
  223. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  224. dataArrayresult = ElecDataArray_temp;
  225. var options = BWA.ChartOptions.GreenEnergy.getChartKcalOptions(timeBoxForSearch.type());
  226. //chartElec().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
  227. //chart().cle
  228. //chart().option(null);
  229. //options.dataSource = null;
  230. //chart().option(options);
  231. options.dataSource = ElecDataArray;
  232. chartElec().option(options);
  233. chartElecConsume().option(options);
  234. visiblePopup(false);
  235. })
  236. .fail(function (error) {
  237. //alert(error);
  238. visiblePopup(false);
  239. });
  240. }
  241. function handleSearchInSearchView(filter, searchViewItems) {
  242. console.log(filter);
  243. console.log(searchViewItems);
  244. //alert(m_Facility.FacilityTypeId());
  245. var f = m_Facility.toJS();
  246. facilityViewModel.fromJS(f);
  247. // 지열시스템은 아래 함수에서 리턴
  248. if (m_Facility.FacilityTypeId() == $Code.FacilityType.EARTH) {
  249. Process7();
  250. return;
  251. }
  252. //var timeIntervalType = $Code.TimeIntervalType.HOUR;
  253. var timeIntervalType = timeBoxForSearch.type();
  254. var formula = $Code.Formula[$Code.FacilityType.GREEN_ENERGY];
  255. var formulaIds = _.values(formula);
  256. var date = timeBoxForSearch.getDate();
  257. //utils.toast.displayTime=1000000;
  258. //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요');
  259. visiblePopup(true);
  260. // var startDate = moment().
  261. var promises = [];
  262. _.each(formulaIds, function (formulaId) {
  263. var p = formulaGet.apiGet({
  264. FacilityTypeId: f.FacilityTypeId,
  265. FacilityCode: f.FacilityCode,
  266. FormulaId: formulaId,
  267. TimeIntervalType: timeIntervalType,
  268. StartDate: date.startDate,
  269. EndDate: date.endDate
  270. });
  271. promises.push(p);
  272. });
  273. /*
  274. // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 ->
  275. var commonParameters = {
  276. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  277. StartDate: date.startDate,
  278. EndDate: date.endDate
  279. };
  280. var temperatureParameters = {
  281. FacilityTypeId: FT.OUTDOOR,
  282. FacilityCode: FC.OUTDOOR,
  283. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  284. };
  285. promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
  286. */ // 보일러는 필요 없다
  287. $.when.apply(this, promises)
  288. .done(function (elec) {
  289. //sw = sw[0];
  290. //rw = rw[0];
  291. // chart 1
  292. var ElecDataArray = [];
  293. var ElecDataArray_temp = [];
  294. _.each(elec, function (x) {
  295. ElecDataArray.push({
  296. //DateTime: moment(x.DateTime).toDate(),
  297. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  298. elec: x.Value,
  299. //co2: factorCo2.calculate(x.Value, $Code.FuelType.ELECTRICITY) * 1000,
  300. });
  301. });
  302. _.each(elec, function (x) {
  303. ElecDataArray_temp.push({
  304. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  305. elec: x.Value,
  306. });
  307. });
  308. //chartElec().option('dataSource', ElecDataArray);
  309. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  310. dataArrayresult = ElecDataArray_temp;
  311. var options = BWA.ChartOptions.GreenEnergy.getChartElecOptions(timeBoxForSearch.type());
  312. var optionsConsume = BWA.ChartOptions.GreenEnergy.getChartElecConsumeOptions(timeBoxForSearch.type());
  313. //chartElec().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
  314. //chart().cle
  315. //chart().option(null);
  316. //options.dataSource = null;
  317. //chart().option(options);
  318. options.dataSource = ElecDataArray;
  319. optionsConsume.dataSource = ElecDataArray;
  320. chartElec().option(options);
  321. chartElecConsume().option(optionsConsume);
  322. visiblePopup(false);
  323. })
  324. .fail(function (error) {
  325. //alert(error);
  326. visiblePopup(false);
  327. });
  328. }
  329. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  330. function DataGridPopup_ButtonClick() {
  331. DataGridPopup_Visible(true);
  332. }
  333. function handlePopupShown() {
  334. // 데이타소스 업데이트
  335. $("#GreenEnergyDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
  336. // 팝업창 갱신
  337. DataGridPopup_Visible(true);
  338. }
  339. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  340. var viewModel = $.extend(BWA.CommonView.create(
  341. params, viewInfo, searchViewOptions, ko.observable(null),
  342. handleViewShown, null, handleSearchInSearchView, undefined,
  343. chartLayout), {
  344. // facility: facilityViewModel,
  345. refreshList: refreshList,
  346. viewShowing: handleViewShowing,
  347. viewHidden: handleViewHidden, // hcLee 2015 03 23
  348. scrolling: { mode: 'infinite' },
  349. GreenEnergyDataGridOptions_menu: {
  350. dataSource: facilitiesForSearch,
  351. columns: [
  352. { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' }
  353. ],
  354. filterRow: {
  355. visible: true,
  356. showOperationChooser: false
  357. },
  358. selection: {
  359. mode: 'single'
  360. },
  361. rowClick: function (clickRow) {
  362. handleSelectedFacilityInSearchView(clickRow.data);
  363. }
  364. },
  365. contentReadyAction: function (e) {
  366. datagrid = e.component;
  367. }
  368. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  369. , GreenEnergyDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick
  370. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  371. });
  372. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  373. viewModel.GreenEnergyDataGridPopupOptions = {
  374. width: '480px',
  375. height: '750px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨
  376. contentTemplate: "content",
  377. showTitle: true,
  378. title: "도표",
  379. visible: DataGridPopup_Visible,
  380. dragEnabled: true,
  381. closeOnOutsideClick: true,
  382. shownAction: handlePopupShown,
  383. animation: window.utils.popup.createAnimation()
  384. };
  385. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  386. timeBoxForSearch.type($Code.TimeType.HOUR);
  387. viewModel.timeBoxForSearch = timeBoxForSearch;
  388. viewModel.currentTabIndex = currentTabIndex;
  389. viewModel.multiViewItems = [{
  390. facility: facilityViewModel,
  391. template: 'mainCharts',
  392. viewCount: 1
  393. },
  394. /*{
  395. template: 'subCharts'
  396. }*/
  397. ];
  398. $HourGlassPopup(viewModel, visiblePopup);
  399. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  400. // 주석이 너무 없음. 나중에 변경 작업을 진행하는 누군가가 시간 소비를 하지 않기 위해...남김
  401. // 시간 포맷은 그래프에 귀속해야 되므로 포맷은 변경하지 않는 것이 유리함
  402. // 전기,가스,수도 와 같이 선택적으로 변경해야 된다면 아래와 같이 캡션은 고정하지 말것
  403. viewModel.GreenEnergyDataGridOptions = {
  404. dataSource: dataArrayresult,
  405. paging: { pageSize: 17 },
  406. columns: [
  407. { dataField: 'DateTime', caption: "날짜", width: '50%', alignment: 'center', },// dataType: 'date', format: 'yyyy-MM-dd HH:mm' },
  408. { dataField: 'elec', caption: "생산열량", width: '50%', alignment: 'center', format: 'fixedPoint', precision: 2 }
  409. ],
  410. // 엑셀 출력
  411. "export": {
  412. enabled: true,
  413. fileName: '신재생에너지'
  414. }
  415. };
  416. // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
  417. return viewModel;
  418. };