a17636b580a7ec8ce5e91a582ce09cc36387b195.svn-base 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data.Entity;
  5. using System.Data.Entity.Infrastructure;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Web;
  9. using System.Web.Http;
  10. using System.Web.Http.Description;
  11. using DevExpress.Office.Utils;
  12. using iBemsDataService.Model;
  13. using iBemsDataService.Util;
  14. using iBemsDataService.Controllers.Bems.Common;
  15. using iBemsDataService.Controllers.Bems.ScheduledTask;
  16. using System.Diagnostics;
  17. using System.Transactions;
  18. using System.Collections.Specialized;
  19. namespace iBemsDataService.Controllers
  20. {
  21. public class BemsMonitoringPointHistoryController : ApiController
  22. {
  23. private iBemsEntities db;
  24. private PointHistoryValueManager pointHistoryValueManager;
  25. private Boolean IS_DEBUG = false;
  26. //static private List<MonitoringPointSType> m_listSType = new List<MonitoringPointSType>(); // 2016 09 19
  27. //private List<MonitoringPointSType> m_listSType;
  28. //static private List<CalculationValueSType[]> m_valuesListMonth = new List<CalculationValueSType[]>();
  29. //static private List<CalculationValueSType[]> m_valuesListDay = new List<CalculationValueSType[]>();
  30. //private String debugPath = "e:\\monitoring.txt";
  31. public BemsMonitoringPointHistoryController()
  32. {
  33. db = new iBemsEntities();
  34. pointHistoryValueManager = new PointHistoryValueManager( db );
  35. debug();
  36. }
  37. private void debug()
  38. {
  39. if (IS_DEBUG)
  40. {
  41. //var listener = new TextWriterTraceListener(debugPath);
  42. //Trace.Listeners.Add(listener);
  43. //Trace.AutoFlush = true;
  44. }
  45. }
  46. [ActionName( "Location" )]
  47. public CalculationValue[] GetBemsMonitoringPointHistory()
  48. {
  49. /* ControlBems bemsJob = new ControlBems();
  50. bemsJob.Execute(null); */
  51. Uri uri = Request.RequestUri;
  52. var uriQuery = HttpUtility.ParseQueryString( uri.Query );
  53. string uriTimeIntervalType = uriQuery.Get( "TimeIntervalType" );
  54. string uriStartDate = uriQuery.Get( "StartDate" );
  55. string uriEndDate = uriQuery.Get( "EndDate" );
  56. int siteId;
  57. int buildingId = -1; int fuelTypeId = -1;
  58. int floorId, zoneId, timeInterval = -1;
  59. DateTime startDate, endDate;
  60. if( int.TryParse( uriQuery.Get( "SiteId" ) , out siteId ) == false ||
  61. int.TryParse( uriQuery.Get( "BuildingId" ) , out buildingId ) == false ||
  62. int.TryParse( uriTimeIntervalType , out timeInterval ) == false ||
  63. DateTime.TryParse( uriStartDate , out startDate ) == false ||
  64. DateTime.TryParse( uriEndDate , out endDate ) == false ||
  65. int.TryParse( uriQuery.Get( "FuelTypeId" ) , out fuelTypeId ) == false )
  66. {
  67. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4},{5}",
  68. siteId, buildingId, uriTimeIntervalType, uriStartDate, uriEndDate, fuelTypeId));
  69. }
  70. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  71. int? nullableFloorId = null;
  72. int? nullableZoneId = null;
  73. if( int.TryParse( uriQuery.Get( "FloorId" ) , out floorId ) )
  74. {
  75. nullableFloorId = floorId;
  76. if( int.TryParse( uriQuery.Get( "ZoneId" ) , out zoneId ) )
  77. {
  78. nullableZoneId = zoneId;
  79. }
  80. }
  81. List<MonitoringPoint> list = new List<MonitoringPoint>();
  82. if (buildingId == 0) // 사이트 전체면 사이트 전체가 있는 지 먼저 확인 하고 아닌 경우 건물들 합을 구한다.
  83. {
  84. IQueryable<MonitoringPoint> querySite;
  85. querySite = from p in db.BemsMonitoringPoint where p.SiteId == siteId && p.BuildingId == 0 && p.FuelTypeId == fuelTypeId
  86. select new MonitoringPoint
  87. {
  88. SiteId = p.SiteId,
  89. FacilityCode = p.FacilityCode ,
  90. PropertyId = p.PropertyId ,
  91. };
  92. if (querySite != null && querySite.Count() > 0)
  93. {
  94. list = querySite.ToList();
  95. }
  96. else
  97. {
  98. IQueryable<CmBuilding> query;
  99. query = from x in db.CmBuilding where x.SiteId == siteId select x;
  100. foreach (CmBuilding b in query)
  101. {
  102. AddPointToListInLocation(list, siteId, fuelTypeId, b.BuildingId, null, null);
  103. }
  104. }
  105. }
  106. else
  107. {
  108. AddPointToListInLocation(list, siteId, fuelTypeId, buildingId, nullableFloorId, nullableZoneId);
  109. }
  110. try
  111. {
  112. //AddPointToListInLocation( list , siteId, fuelTypeId , buildingId , nullableFloorId , nullableZoneId );
  113. var values = CreateCalculationValues( startDate , endDate , timeIntervalType );
  114. foreach( var point in list )
  115. {
  116. var pointValues = pointHistoryValueManager.GetPointValues(
  117. siteId , point.FacilityCode , point.PropertyId ,
  118. timeIntervalType , startDate , endDate );
  119. if( pointValues == null )
  120. continue;
  121. int index = 0;
  122. CalculationValue p = null;
  123. CalculationValue v = null;
  124. for( var i = 0 ; i < values.Length ; i++ )
  125. {
  126. v = values[i];
  127. if( p == null )
  128. {
  129. if( pointValues.Length <= index ) break;
  130. p = pointValues[index];
  131. }
  132. if( p.DateTime == v.DateTime )
  133. {
  134. v.Value += p.Value;
  135. p = null;
  136. index++;
  137. if( pointValues.Length <= index ) break;
  138. }
  139. }
  140. }
  141. return values;
  142. }
  143. catch( Exception )
  144. {
  145. throw;
  146. }
  147. }
  148. //[ActionName("ServiceType")] //
  149. /*public CalculationValueSType[] GetBemsMonitoringPointHistoryService()
  150. {
  151. Uri uri = Request.RequestUri;
  152. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  153. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  154. string uriStartDate = uriQuery.Get("StartDate");
  155. string uriEndDate = uriQuery.Get("EndDate");
  156. int siteId;
  157. int buildingId, floorId, zoneId, fuelTypeId, timeInterval = -1;
  158. DateTime startDate, endDate;
  159. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  160. int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  161. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  162. DateTime.TryParse(uriStartDate, out startDate) == false ||
  163. DateTime.TryParse(uriEndDate, out endDate) == false ||
  164. int.TryParse(uriQuery.Get("FuelTypeId"), out fuelTypeId) == false)
  165. {
  166. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2}",
  167. uriTimeIntervalType, uriStartDate, uriEndDate));
  168. }
  169. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  170. int? nullableFloorId = null;
  171. int? nullableZoneId = null;
  172. if (int.TryParse(uriQuery.Get("FloorId"), out floorId))
  173. {
  174. nullableFloorId = floorId;
  175. if (int.TryParse(uriQuery.Get("ZoneId"), out zoneId))
  176. {
  177. nullableZoneId = zoneId;
  178. }
  179. }
  180. List<MonitoringPointSType> list = new List<MonitoringPointSType>();
  181. if (buildingId == 0)
  182. {
  183. IQueryable<CmBuilding> query;
  184. query = from x in db.CmBuilding where x.SiteId == siteId select x;
  185. foreach (CmBuilding b in query)
  186. {
  187. //AddPointToListInLocationSType(list, siteId, fuelTypeId, b.BuildingId, null, null);
  188. AddPointToListInLocationSType_New(list, siteId, fuelTypeId, b.BuildingId);
  189. }
  190. }
  191. else
  192. {
  193. //AddPointToListInLocationSType(list, siteId, fuelTypeId, buildingId, nullableFloorId, nullableZoneId);
  194. AddPointToListInLocationSType_New(list, siteId, fuelTypeId, buildingId);
  195. }
  196. try
  197. {
  198. var values = CreateCalculationValuesSType(startDate, endDate, timeIntervalType);
  199. foreach (var point in list)
  200. {
  201. var pointValues = pointHistoryValueManager.GetPointValues(siteId, point.FacilityCode, point.PropertyId, timeIntervalType, startDate, endDate);
  202. if (pointValues == null)
  203. continue;
  204. int index = 0;
  205. CalculationValue p = null;
  206. CalculationValueSType v = null;
  207. for (var i = point.ServiceTypeId - 1; i < values.Length; i +=12)
  208. {
  209. v = values[i];
  210. if (p == null)
  211. {
  212. if (pointValues.Length <= index)
  213. break;
  214. p = pointValues[index];
  215. }
  216. //if (p.DateTime == v.DateTime && point.ServiceTypeId == v.ServiceType)
  217. if (p.DateTime == v.DateTime)
  218. {
  219. //if
  220. v.Value += p.Value;
  221. p = null;
  222. index++;
  223. if (pointValues.Length <= index)
  224. break;
  225. }
  226. }
  227. }
  228. return values;
  229. }
  230. catch (Exception)
  231. {
  232. throw;
  233. }
  234. }
  235. */
  236. //DB update
  237. //private void MakeMonthCalcData(int siteId, TimeInterval timeIntervalType, DateTime startDate, DateTime endDate, List<CalculationValueSType[]> valuesListReturn)
  238. private void SaveCalcData(int siteId, TimeInterval timeIntervalType, DateTime startDate, DateTime endDate, CalculationValueSType[] valuesList)
  239. {
  240. using (var transaction = new TransactionScope())
  241. {
  242. try
  243. {
  244. string sqlDel = (timeIntervalType == TimeInterval.Month) ?
  245. String.Format("delete from CmServiceEnergyCalcMonth where SiteId = {0} and calDate >= '{1}' and calDate < '{2}'", siteId, startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd")) :
  246. String.Format("delete from CmServiceEnergyCalcDay where SiteId = {0} and calDate >= '{1}' and calDate < '{2}'", siteId, startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));
  247. db.Database.ExecuteSqlCommand(sqlDel);
  248. //db.Database.ExecuteSqlCommand("delete from CmServiceEnergyCalcMonth where SiteId = @siteId and calDate >= @start and calDate <= @end",
  249. //new SqlParameter ("@siteId", siteId), startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));
  250. if (timeIntervalType == TimeInterval.Month) // Month처리
  251. {
  252. foreach (var k in valuesList)
  253. {
  254. var newData = new CmServiceEnergyCalcMonth
  255. {
  256. SiteId = siteId,
  257. calDate = k.DateTime,
  258. ServiceTypeId = (short)k.ServiceType,
  259. Value = k.Value
  260. };
  261. db.CmServiceEnergyCalcMonth.Add(newData);
  262. }
  263. db.SaveChanges();
  264. }
  265. else // day 처리
  266. {
  267. foreach (var k in valuesList)
  268. {
  269. var newData = new CmServiceEnergyCalcDay
  270. {
  271. SiteId = siteId,
  272. calDate = k.DateTime,
  273. ServiceTypeId = (short)k.ServiceType,
  274. Value = k.Value
  275. };
  276. db.CmServiceEnergyCalcDay.Add(newData);
  277. }
  278. db.SaveChanges();
  279. }
  280. }
  281. catch (Exception) { throw; }
  282. transaction.Complete();
  283. }
  284. }
  285. //private List<CalculationValueSType[]> LoadCalcData(int siteId, TimeInterval timeIntervalType, DateTime startDate, DateTime endDate)
  286. private CalculationValueSType[] LoadCalcData(int siteId, TimeInterval timeIntervalType, DateTime startDate, DateTime endDate)
  287. {
  288. //List<CalculationValueSType[]> valuesListDB = new List<CalculationValueSType[]>();
  289. CalculationValueSType[] list;
  290. if (timeIntervalType == TimeInterval.Month)
  291. {
  292. list =
  293. (from x in db.CmServiceEnergyCalcMonth
  294. where x.SiteId == siteId && x.calDate >= startDate && x.calDate <= endDate
  295. select new CalculationValueSType
  296. {
  297. DateTime = x.calDate,
  298. ServiceType = x.ServiceTypeId,
  299. Value = (double)x.Value
  300. }).ToArray<CalculationValueSType>();
  301. }
  302. else
  303. {
  304. list =
  305. (from x in db.CmServiceEnergyCalcDay
  306. where x.SiteId == siteId && x.calDate >= startDate && x.calDate <= endDate
  307. select new CalculationValueSType
  308. {
  309. DateTime = x.calDate,
  310. ServiceType = x.ServiceTypeId,
  311. Value = (double)x.Value
  312. }).ToArray<CalculationValueSType>();
  313. }
  314. //valuesListDB.Add(list);
  315. //return valuesListDB;
  316. return list;
  317. }
  318. //private CalculationValueSType[] MakeCalcData(int siteId, int buildingId, TimeInterval timeIntervalType, DateTime startDate, DateTime endDate, List<CalculationValueSType[]> valuesListReturn)
  319. private CalculationValueSType[] MakeCalcData(List<MonitoringPointSType> listSType, int siteId, int buildingId, TimeInterval timeIntervalType, DateTime startDate, DateTime endDate) // 2017 02 22 listSType 로컬로 변경
  320. {
  321. //if (m_listSType.Count() <= 0)
  322. {
  323. if (buildingId == 0)
  324. {
  325. IQueryable<CmBuilding> query;
  326. query = from x in db.CmBuilding where x.SiteId == siteId select x;
  327. foreach (CmBuilding b in query)
  328. {
  329. AddPointToListInLocationSType_New2(listSType, siteId, b.BuildingId);
  330. }
  331. }
  332. else
  333. {
  334. AddPointToListInLocationSType_New2(listSType, siteId, buildingId);
  335. }
  336. }
  337. List<CalculationValueSType[]> valuesListReturn = new List<CalculationValueSType[]>();
  338. if (timeIntervalType == TimeInterval.Month)
  339. valuesListReturn.Add(CreateCalculationValuesSType(startDate, startDate, timeIntervalType)); // startDate 2개가 맞다. 한달씩, 하기 떄문이다
  340. else
  341. valuesListReturn.Add(CreateCalculationValuesSType(startDate, endDate, timeIntervalType));
  342. List<CalculationValueSType[]> valuesList = new List<CalculationValueSType[]>();
  343. IQueryable<BemsFactorToe> queryTOE;
  344. queryTOE = from x in db.BemsFactorToe where x.FuelTypeId < 3 select x;
  345. foreach (BemsFactorToe TOE in queryTOE)
  346. {
  347. if (timeIntervalType == TimeInterval.Month)
  348. valuesList.Add(CreateCalculationValuesSType(startDate, startDate, timeIntervalType)); // startDate 2개가 맞다. 한달씩, 또는 하루씩 하기 떄문이다
  349. else
  350. valuesList.Add(CreateCalculationValuesSType(startDate, endDate, timeIntervalType));
  351. }
  352. try
  353. {
  354. foreach (var point in listSType)
  355. {
  356. if (point.FuelTypeId <= 0) continue; // 2017 02 17 방어코드 추가
  357. var pointValues = pointHistoryValueManager.GetPointValues(siteId, point.FacilityCode, point.PropertyId, timeIntervalType, startDate, endDate);
  358. if (pointValues == null)
  359. continue;
  360. var values = valuesList[point.FuelTypeId - 1];
  361. int index = 0;
  362. CalculationValue p = null;
  363. CalculationValueSType v = null;
  364. for (var i = point.ServiceTypeId - 1; i < values.Length; i += 12)
  365. {
  366. v = values[i];
  367. if (p == null)
  368. {
  369. if (pointValues.Length <= index)
  370. break;
  371. p = pointValues[index];
  372. }
  373. if (p.DateTime == v.DateTime)
  374. {
  375. v.Value += p.Value;
  376. p = null;
  377. index++;
  378. if (pointValues.Length <= index)
  379. break;
  380. }
  381. }
  382. }
  383. foreach (BemsFactorToe TOE in queryTOE)
  384. {
  385. int r = 0;
  386. foreach (var k in valuesList[TOE.FuelTypeId - 1])
  387. {
  388. k.Value = k.Value * (double)TOE.kcal;
  389. valuesListReturn[0][r].Value += k.Value; // 연료별이 kcal로 환산되어 합쳐졌기에 리스트 하나만 가면 된다, DB저장을 위해서도 하나가 편리하다.
  390. r++;
  391. }
  392. }
  393. //DB update
  394. DateTime currentTime = DateTime.Now;
  395. if (timeIntervalType == TimeInterval.Month) // 이번달이나
  396. {
  397. currentTime = new DateTime(currentTime.Year, currentTime.Month, 1, 0, 0, 0);
  398. if (startDate < currentTime)
  399. SaveCalcData(siteId, timeIntervalType, startDate, endDate, valuesListReturn[0]);
  400. }
  401. else // 오늘은 DB에 쓰지 않는다. 오늘은 불려지지 않는다. -> 아예 현재달은 쓰지 않는다.
  402. {
  403. if (currentTime.Year == startDate.Year && currentTime.Month == startDate.Month)
  404. { }
  405. else
  406. SaveCalcData(siteId, timeIntervalType, startDate, endDate, valuesListReturn[0]);
  407. }
  408. return valuesListReturn[0]; // 연료별이 kcal로 환산되어 합쳐졌기에 리스트 하나만 가면 된다, DB저장을 위해서도 하나가 편리하다.
  409. }
  410. catch (Exception)
  411. {
  412. throw;
  413. }
  414. }
  415. private CalculationValueSType[] MakeCalcDataToday(List<MonitoringPointSType> listSType, int siteId, int buildingId)
  416. {
  417. //if (m_listSType.Count() <= 0)
  418. {
  419. if (buildingId == 0)
  420. {
  421. IQueryable<CmBuilding> query;
  422. query = from x in db.CmBuilding where x.SiteId == siteId select x;
  423. foreach (CmBuilding b in query)
  424. {
  425. AddPointToListInLocationSType_New2(listSType, siteId, b.BuildingId);
  426. }
  427. }
  428. else
  429. {
  430. AddPointToListInLocationSType_New2(listSType, siteId, buildingId);
  431. }
  432. }
  433. //DB update
  434. DateTime currentTime = DateTime.Now;
  435. DateTime startDate = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 0, 0, 0);
  436. DateTime endDate = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 23, 59, 59);
  437. List<CalculationValueSType[]> valuesListReturn = new List<CalculationValueSType[]>();
  438. valuesListReturn.Add(CreateCalculationValuesSType(startDate, endDate, TimeInterval.Day));
  439. List<CalculationValueSType[]> valuesList = new List<CalculationValueSType[]>();
  440. IQueryable<BemsFactorToe> queryTOE;
  441. queryTOE = from x in db.BemsFactorToe where x.FuelTypeId < 3 select x;
  442. foreach (BemsFactorToe TOE in queryTOE)
  443. {
  444. valuesList.Add(CreateCalculationValuesSType(startDate, endDate, TimeInterval.Day));
  445. }
  446. try
  447. {
  448. foreach (var point in listSType)
  449. {
  450. if (point.FuelTypeId <= 0) continue; // 2017 02 17 방어코드 추가
  451. var pointValues = pointHistoryValueManager.GetPointValues(siteId, point.FacilityCode, point.PropertyId, TimeInterval.Day, startDate, endDate);
  452. if (pointValues == null)
  453. continue;
  454. var values = valuesList[point.FuelTypeId - 1];
  455. int index = 0;
  456. CalculationValue p = null;
  457. CalculationValueSType v = null;
  458. for (var i = point.ServiceTypeId - 1; i < values.Length; i += 12)
  459. {
  460. v = values[i];
  461. if (p == null)
  462. {
  463. if (pointValues.Length <= index)
  464. break;
  465. p = pointValues[index];
  466. }
  467. if (p.DateTime == v.DateTime)
  468. {
  469. v.Value += p.Value;
  470. p = null;
  471. index++;
  472. if (pointValues.Length <= index)
  473. break;
  474. }
  475. }
  476. }
  477. foreach (BemsFactorToe TOE in queryTOE)
  478. {
  479. int r = 0;
  480. foreach (var k in valuesList[TOE.FuelTypeId - 1])
  481. {
  482. k.Value = k.Value * (double)TOE.kcal;
  483. valuesListReturn[0][r].Value += k.Value; // 연료별이 kcal로 환산되어 합쳐졌기에 리스트 하나만 가면 된다, DB저장을 위해서도 하나가 편리하다.
  484. r++;
  485. }
  486. }
  487. return valuesListReturn[0]; // 연료별이 kcal로 환산되어 합쳐졌기에 리스트 하나만 가면 된다, DB저장을 위해서도 하나가 편리하다.
  488. }
  489. catch (Exception)
  490. {
  491. throw;
  492. }
  493. }
  494. [ActionName("ServiceType")] //
  495. //public CalculationValueSType[] GetBemsMonitoringPointHistoryService()
  496. public List<CalculationValueSType[]> GetBemsMonitoringPointHistoryService()
  497. {
  498. Uri uri = Request.RequestUri;
  499. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  500. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  501. string uriStartDate = uriQuery.Get("StartDate");
  502. string uriEndDate = uriQuery.Get("EndDate");
  503. int siteId;
  504. int buildingId, floorId, zoneId, fuelTypeId, timeInterval = -1;
  505. DateTime startDate, endDate;
  506. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  507. int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  508. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  509. DateTime.TryParse(uriStartDate, out startDate) == false ||
  510. DateTime.TryParse(uriEndDate, out endDate) == false ||
  511. int.TryParse(uriQuery.Get("FuelTypeId"), out fuelTypeId) == false)
  512. {
  513. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2}",
  514. uriTimeIntervalType, uriStartDate, uriEndDate));
  515. }
  516. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  517. int? nullableFloorId = null;
  518. int? nullableZoneId = null;
  519. if (int.TryParse(uriQuery.Get("FloorId"), out floorId))
  520. {
  521. nullableFloorId = floorId;
  522. if (int.TryParse(uriQuery.Get("ZoneId"), out zoneId))
  523. {
  524. nullableZoneId = zoneId;
  525. }
  526. }
  527. List<MonitoringPointSType> listSType = new List<MonitoringPointSType>(); // 2017 02 22 로컬로 변경
  528. List<CalculationValueSType[]> valuesListReturn = new List<CalculationValueSType[]>();
  529. CalculationValueSType[] cv = CreateCalculationValuesSType(startDate, endDate, timeIntervalType);
  530. // 있는지 판단해서 있으면 보낸다
  531. // 이번달 또는 오늘은 제외
  532. //
  533. DateTime dtStart = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0);
  534. DateTime dtEnd = new DateTime(startDate.Year, startDate.Month, startDate.Day, 23, 59, 59);
  535. if (timeIntervalType == TimeInterval.Month)
  536. {
  537. CalculationValueSType[] list;
  538. while (dtEnd < endDate)
  539. {
  540. // 먼저 이미 DB에 있는지 보고 있으면 바로 받고
  541. list = LoadCalcData(siteId, timeIntervalType, dtStart, dtEnd);
  542. if (list.Length <= 0) list = MakeCalcData(listSType, siteId, buildingId, timeIntervalType, dtStart, dtStart.AddMonths(1)); // 없으면 만들고 받는다
  543. foreach (CalculationValueSType s in list)
  544. {
  545. foreach (CalculationValueSType v in cv)
  546. {
  547. if (v.ServiceType == s.ServiceType && v.DateTime == s.DateTime)
  548. {
  549. v.Value = s.Value;
  550. break;
  551. }
  552. }
  553. }
  554. dtStart = dtStart.AddMonths(1);
  555. dtEnd = dtEnd.AddMonths(1);
  556. }
  557. valuesListReturn.Add(cv);
  558. return valuesListReturn;
  559. }
  560. else
  561. {
  562. DateTime current= DateTime.Now;
  563. CalculationValueSType[] list;
  564. // 현재달이면 오늘은 제외한다
  565. //dtEnd = (endDate.Year == current.Year && endDate.Month == current.Month) ? current.AddDays(-1) : endDate; 현재달의 day는 아예 안쓰기로 하면서 오늘처리는 필요 없어진다
  566. dtEnd = endDate;
  567. list = LoadCalcData(siteId, timeIntervalType, dtStart, dtEnd);
  568. if (list.Length <= 0) list = MakeCalcData(listSType, siteId, buildingId, timeIntervalType, dtStart, dtEnd); // 없으면 만들고 받는다. 이떄 현재달이며 오늘은 만들지 않는다.
  569. foreach (CalculationValueSType s in list)
  570. {
  571. foreach (CalculationValueSType v in cv)
  572. {
  573. if (v.ServiceType == s.ServiceType && v.DateTime == s.DateTime)
  574. {
  575. v.Value = s.Value;
  576. break;
  577. }
  578. }
  579. }
  580. /*
  581. if (endDate.Year == current.Year && endDate.Month == current.Month)
  582. {
  583. list = MakeCalcDataToday(siteId, buildingId);
  584. foreach (CalculationValueSType s in list)
  585. {
  586. foreach (CalculationValueSType v in cv)
  587. {
  588. if (v.ServiceType == s.ServiceType && v.DateTime == s.DateTime)
  589. {
  590. v.Value = s.Value;
  591. break;
  592. }
  593. }
  594. }
  595. } */
  596. //if (dtStart >= current)
  597. //break;
  598. //}
  599. valuesListReturn.Add(cv);
  600. return valuesListReturn;
  601. }
  602. //return valuesListReturn;
  603. }
  604. [ActionName("Location_ZoneTempHumi")]
  605. //public CalculationValue[] GetBemsMonitoringPointHistoryZoneTempHumi()
  606. public List<CalculationValue[]> GetBemsMonitoringPointHistoryZoneTempHumi()
  607. {
  608. Uri uri = Request.RequestUri;
  609. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  610. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  611. string uriStartDate = uriQuery.Get("StartDate");
  612. string uriEndDate = uriQuery.Get("EndDate");
  613. int siteId;
  614. int buildingId = -1; int fuelTypeId = -1;
  615. int floorId, zoneId, timeInterval = -1;
  616. DateTime startDate, endDate;
  617. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  618. int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  619. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  620. DateTime.TryParse(uriStartDate, out startDate) == false ||
  621. DateTime.TryParse(uriEndDate, out endDate) == false ||
  622. int.TryParse(uriQuery.Get("FuelTypeId"), out fuelTypeId) == false)
  623. {
  624. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4},{5}",
  625. siteId, buildingId, uriTimeIntervalType, uriStartDate, uriEndDate, fuelTypeId));
  626. }
  627. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  628. int? nullableFloorId = null;
  629. int? nullableZoneId = null;
  630. if (int.TryParse(uriQuery.Get("FloorId"), out floorId))
  631. {
  632. nullableFloorId = floorId;
  633. if (int.TryParse(uriQuery.Get("ZoneId"), out zoneId))
  634. {
  635. nullableZoneId = zoneId;
  636. }
  637. }
  638. List<MonitoringPoint> list = new List<MonitoringPoint>();
  639. AddPointToListInLocation_ZoneTempHumi(list, siteId, buildingId, nullableFloorId, nullableZoneId); // 2015 08 03 FType 91,92로 가려야 한다.
  640. // 온도를 습도들 CO2 들로 따로 처리하는 것으로 변경한다 2016 05 23
  641. List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  642. try
  643. {
  644. /*var THSetQuery = from x in db.CmZoneTempHumiSet
  645. where x.SiteId == siteId && x.BuildingId == buildingId && x.FloorId == floorId && x.ZoneId == nullableZoneId
  646. select x;
  647. ControlBems cb = new ControlBems();
  648. cb.GetTempSetValue(1, */
  649. foreach (var point in list) // 온도,습도 2개가 존재해야 한다. + CO2 농도 (2016 04 18 추가됨 즉 3개
  650. {
  651. var pointValues = pointHistoryValueManager.GetPointValues(
  652. siteId, point.FacilityCode, point.PropertyId,
  653. timeIntervalType, startDate, endDate);
  654. if (pointValues == null)
  655. continue;
  656. int index = 0;
  657. CalculationValue p = null;
  658. CalculationValue v = null;
  659. var values = CreateCalculationValues(startDate, endDate, timeIntervalType); // 위치 안으로 이동 2015 08 04 hcLee
  660. for (var i = 0; i < values.Length; i++)
  661. {
  662. v = values[i];
  663. if (p == null)
  664. {
  665. if (pointValues.Length <= index) break;
  666. p = pointValues[index];
  667. }
  668. if (p.DateTime == v.DateTime)
  669. {
  670. //v.Value += p.Value;
  671. v.Value = p.Value;
  672. p = null;
  673. index++;
  674. if (pointValues.Length <= index) break;
  675. }
  676. }
  677. listCalc.Add(values);
  678. }
  679. //return values;
  680. return listCalc;
  681. }
  682. catch (Exception)
  683. {
  684. throw;
  685. }
  686. }
  687. [ActionName("FacilityRunTime")]
  688. //public CalculationValue[] GetBemsMonitoringPointHistoryZoneTempHumi()
  689. public List<CalculationValue[]> GetBemsMonitoringPointHistoryRunTime()
  690. {
  691. Uri uri = Request.RequestUri;
  692. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  693. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  694. string uriStartDate = uriQuery.Get("StartDate");
  695. string uriEndDate = uriQuery.Get("EndDate");
  696. int siteId;
  697. int facilityCode = -1, timeInterval = -1;
  698. DateTime startDate, endDate;
  699. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  700. int.TryParse(uriQuery.Get("FacilityCode"), out facilityCode) == false ||
  701. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  702. DateTime.TryParse(uriStartDate, out startDate) == false ||
  703. DateTime.TryParse(uriEndDate, out endDate) == false)
  704. {
  705. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4}",
  706. siteId, facilityCode, uriTimeIntervalType, uriStartDate, uriEndDate));
  707. }
  708. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  709. List<MonitoringPoint> list = new List<MonitoringPoint>();
  710. AddPointToList_RunTime(list, siteId, facilityCode); // 2015 08 03 FType 91,92로 가려야 한다.
  711. List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  712. try
  713. {
  714. foreach (var point in list) // 가동시간 point 한개가 존재한다.
  715. {
  716. var pointValues = pointHistoryValueManager.GetPointValues(
  717. siteId, point.FacilityCode, point.PropertyId,
  718. timeIntervalType, startDate, endDate);
  719. if (pointValues == null)
  720. continue;
  721. int index = 0;
  722. CalculationValue p = null;
  723. CalculationValue v = null;
  724. var values = CreateCalculationValues(startDate, endDate, timeIntervalType);
  725. for (var i = 0; i < values.Length; i++)
  726. {
  727. v = values[i];
  728. if (p == null)
  729. {
  730. if (pointValues.Length <= index) break;
  731. p = pointValues[index];
  732. }
  733. if (p.DateTime == v.DateTime)
  734. {
  735. //v.Value += p.Value;
  736. v.Value = p.Value;
  737. p = null;
  738. index++;
  739. if (pointValues.Length <= index) break;
  740. }
  741. }
  742. listCalc.Add(values);
  743. }
  744. //return values;
  745. return listCalc;
  746. }
  747. catch (Exception)
  748. {
  749. throw;
  750. }
  751. }
  752. // jhLee 2016-04-22
  753. [ActionName("FacilityCostRunTime")]
  754. public List<CalculationValue> GetBemsMonitoringPointHistoryCostRunTime()
  755. {
  756. Uri uri = Request.RequestUri;
  757. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  758. int siteId, facilityCode = -1, timeInterval = -1;
  759. DateTime startDate, endDate;
  760. SetFacilityRunTimeParam(uriQuery, ref facilityCode, ref timeInterval, out siteId, out startDate, out endDate);
  761. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  762. try
  763. {
  764. FacilityCostInfo facilityCostInfo = GetFacilityCostInfo(siteId, facilityCode);
  765. List<int> propertyIdList = GetPropertyIdList(siteId, facilityCode, (short)facilityCostInfo.FuelTypeId);
  766. var resultGroupByHour = GetHourRunTimeCostValues(siteId, facilityCode, propertyIdList, startDate, endDate, facilityCostInfo);
  767. var result = GetGroupedRuntimeCostValue(resultGroupByHour, timeIntervalType);
  768. return result == null ? new List<CalculationValue>() : result.ToList();
  769. }
  770. catch
  771. {
  772. return new List<CalculationValue>();
  773. }
  774. }
  775. private FacilityCostInfo GetFacilityCostInfo(int siteId, int facilityCode)
  776. {
  777. FacilityCostInfo facilityCostInfo
  778. = (from x in db.CmFacility
  779. where x.SiteId == siteId && x.FacilityCode == facilityCode
  780. select new FacilityCostInfo
  781. {
  782. SiteId = x.SiteId,
  783. FacilityCode = x.FacilityCode,
  784. FuelTypeId = x.FuelTypeId,
  785. ContractType = x.ContractType,
  786. RatedPowerConsumption = x.RatedPowerConsumption
  787. }).First();
  788. CheckFacilityCostInfo(facilityCostInfo);
  789. return facilityCostInfo;
  790. }
  791. private static void CheckFacilityCostInfo(FacilityCostInfo facilityCostInfo)
  792. {
  793. if (facilityCostInfo.FuelTypeId == null)
  794. {
  795. throw new Exception("FuelTypeId is null");
  796. }
  797. if (facilityCostInfo.ContractType == null)
  798. {
  799. throw new Exception("ContractType is null");
  800. }
  801. }
  802. private void SetFacilityRunTimeParam(NameValueCollection uriQuery, ref int facilityCode, ref int timeInterval, out int siteId, out DateTime startDate, out DateTime endDate)
  803. {
  804. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  805. string uriStartDate = uriQuery.Get("StartDate");
  806. string uriEndDate = uriQuery.Get("EndDate");
  807. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  808. int.TryParse(uriQuery.Get("FacilityCode"), out facilityCode) == false ||
  809. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  810. DateTime.TryParse(uriStartDate, out startDate) == false ||
  811. DateTime.TryParse(uriEndDate, out endDate) == false)
  812. {
  813. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4}",
  814. siteId, facilityCode, uriTimeIntervalType, uriStartDate, uriEndDate));
  815. }
  816. }
  817. private List<int> GetPropertyIdList(int siteId, int facilityCode, Nullable<short> fuelTypeId)
  818. {
  819. return (from x in db.BemsMonitoringPoint
  820. where x.SiteId == siteId &&
  821. x.FacilityCode == facilityCode &&
  822. x.FuelTypeId == fuelTypeId // 원래방식인 가동시간을 이용할려면 fuelTypeId는 사용하지말고 ServiceTypeId = 120 만 이용해야 한다.
  823. //hcLee 2016 07 11 두소장 요청 가동시간계산이 아닌 전력량 계산으로 변경
  824. && x.ServiceTypeId > 0 && x.ServiceTypeId < 100 && x.BuildingId > 0
  825. select x.PropertyId).ToList();
  826. }
  827. private IQueryable<CalculationValue> GetHourRunTimeCostValues(int siteId, int facilityCode, List<int> propertyIdList, DateTime startDate, DateTime endDate, FacilityCostInfo facilityCostInfo)
  828. {
  829. short fuelTypeId = (short)facilityCostInfo.FuelTypeId;
  830. short contractType = (short)facilityCostInfo.ContractType;
  831. string ratedPowerConsumption = facilityCostInfo.RatedPowerConsumption == null ? "" : facilityCostInfo.RatedPowerConsumption;
  832. // DateTime기준으로 묶은 시간별 모니터링 관제점 기록
  833. var query
  834. = (from x in db.BemsMonitoringPointHistoryHourly
  835. where
  836. x.SiteId == siteId &&
  837. x.FacilityCode == facilityCode &&
  838. propertyIdList.Contains(x.PropertyId) &&
  839. startDate <= x.CreatedDateTime && x.CreatedDateTime <= endDate
  840. select new CalculationValue
  841. {
  842. DateTime = x.CreatedDateTime,
  843. Value = x.CurrentValue
  844. })
  845. .GroupBy(x => x.DateTime).Select(y => new CalculationValue
  846. {
  847. DateTime = y.Key,
  848. //Value = y.Sum(item => item.Value) * ratedPowerConsumption / 60
  849. Value = y.Sum(item => item.Value) // 2016 07 11 hcLee
  850. }).OrderBy(x => x.DateTime);
  851. var bemsNoticePriceDetail
  852. = from x in db.BemsNoticePriceDetail
  853. where x.SiteId == siteId &&
  854. x.FuelTypeId == fuelTypeId &&
  855. x.ContractType == contractType
  856. select x;
  857. // 관제점 기록의 시간값을 기준으로 비용을 곱한값
  858. var resultGroupByHour = query
  859. .AsEnumerable()
  860. .Select(x => new CalculationValue
  861. {
  862. DateTime = x.DateTime,
  863. Value = x.Value * GetNoticePriceFromDateTime(bemsNoticePriceDetail, x.DateTime, fuelTypeId) // 2016 07 11 hcLee
  864. });
  865. return resultGroupByHour.AsQueryable();
  866. }
  867. // timeInterval 기준으로 Group by 한다
  868. private IQueryable<CalculationValue> GetGroupedRuntimeCostValue(IQueryable<CalculationValue> resultGroupByHour, TimeInterval timeInterval)
  869. {
  870. switch (timeInterval)
  871. {
  872. case TimeInterval.Year:
  873. return from x in resultGroupByHour
  874. group x by new { Year = x.DateTime.Year }
  875. into g
  876. select new CalculationValue
  877. {
  878. DateTime = new DateTime(g.Key.Year, 1, 1),
  879. Value = g.Sum(x => x.Value)
  880. };
  881. case TimeInterval.Month:
  882. return from x in resultGroupByHour
  883. group x by new { Year = x.DateTime.Year, Month = x.DateTime.Month }
  884. into g
  885. select new CalculationValue
  886. {
  887. DateTime = new DateTime(g.Key.Year, g.Key.Month, 1),
  888. Value = g.Sum(x => x.Value)
  889. };
  890. case TimeInterval.Day:
  891. return from x in resultGroupByHour
  892. group x by new { Year = x.DateTime.Year, Month = x.DateTime.Month, Day = x.DateTime.Day }
  893. into g
  894. select new CalculationValue
  895. {
  896. DateTime = new DateTime(g.Key.Year, g.Key.Month, g.Key.Day),
  897. Value = g.Sum(x => x.Value)
  898. };
  899. case TimeInterval.Hour:
  900. return resultGroupByHour;
  901. default:
  902. return null;
  903. }
  904. }
  905. // 해당 dateTime보다 작은 Max 값을 하나 가져와서 시간 / 월에 해당하는 가격을 리턴
  906. private double GetNoticePriceFromDateTime(IQueryable<BemsNoticePriceDetail> bemsNoticePriceDetail, DateTime datetime, short fuelTypeId) // hcLee 2016 07 11
  907. {
  908. int hour = 0;
  909. if (fuelTypeId == 1)
  910. {
  911. hour = datetime.Hour;
  912. }
  913. BemsNoticePriceDetail noticePrice
  914. = (from x in bemsNoticePriceDetail
  915. where x.DataId == hour
  916. && x.ApplyDate <= datetime
  917. orderby x.ApplyDate descending
  918. select x).First();
  919. if (noticePrice == null) return 0;
  920. String columnNameFromMonth = String.Format("P{0:D2}", datetime.Month);
  921. Nullable<Double> price = (Nullable<Double>)noticePrice.GetType().GetProperty(columnNameFromMonth).GetValue(noticePrice, null);
  922. return price == null ? 0 : (double)price;
  923. }
  924. // hcLee 2016 05 25
  925. [ActionName("FloorPointValue")]
  926. public List<double> GetBemsMonitoringPointHistoryFloorPointValue()
  927. //public List<CalculationValue[]> GetBemsMonitoringPointHistoryZoneTempHumi()
  928. {
  929. Uri uri = Request.RequestUri;
  930. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  931. //string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  932. //string uriStartDate = uriQuery.Get("StartDate");
  933. //string uriEndDate = uriQuery.Get("EndDate");
  934. int siteId;
  935. int buildingId = -1; int floorId = -1;
  936. //DateTime startDate, endDate;
  937. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  938. int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  939. int.TryParse(uriQuery.Get("FloorId"), out floorId) == false )
  940. {
  941. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2}", siteId, buildingId, floorId));
  942. }
  943. List<MonitoringPoint> list = new List<MonitoringPoint>();
  944. AddPointToListInLocation_FloorTempHumi(list, siteId, buildingId, floorId);
  945. List<double> listValue = new List<double>();
  946. //List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  947. try
  948. {
  949. foreach (var point in list)
  950. {
  951. IEnumerable<BemsMonitoringPointHistory15min> lastData = (from data in db.BemsMonitoringPointHistory15min
  952. where data.SiteId == siteId && data.FacilityCode == point.FacilityCode && data.PropertyId == point.PropertyId
  953. orderby data.CreatedDateTime descending select data).Take(1);
  954. if (lastData == null || lastData.Count() == 0)
  955. {
  956. //instance.cd = string.Format("{0:D10}", 1);
  957. listValue.Add(-9999); // 데이터가 없는 경우 처리
  958. }
  959. else
  960. {
  961. BemsMonitoringPointHistory15min current = lastData.First();
  962. listValue.Add(current.CurrentValue);
  963. }
  964. }
  965. //return values;
  966. return listValue;
  967. }
  968. catch (Exception)
  969. {
  970. throw;
  971. }
  972. }
  973. // kgpark 2019 06 26
  974. [ActionName("FloorEachPointValue")]
  975. public List<double> GetBemsMonitoringPointHistoryFloorEachPointValue()
  976. //public List<CalculationValue[]> GetBemsMonitoringPointHistoryZoneTempHumi()
  977. {
  978. Uri uri = Request.RequestUri;
  979. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  980. //string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  981. //string uriStartDate = uriQuery.Get("StartDate");
  982. //string uriEndDate = uriQuery.Get("EndDate");
  983. int siteId; int floorId = -1;
  984. //DateTime startDate, endDate;
  985. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  986. int.TryParse(uriQuery.Get("FloorId"), out floorId) == false)
  987. {
  988. throw new Exception(string.Format("Not Found Parameters: {0},{1}", siteId, floorId));
  989. }
  990. List<MonitoringPoint> list = new List<MonitoringPoint>();
  991. AddEachPointToListInLocation_FloorTempHumi(list, siteId, floorId);
  992. List<double> listValue = new List<double>();
  993. //List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  994. try
  995. {
  996. foreach (var point in list)
  997. {
  998. IEnumerable<BemsMonitoringPointHistory15min> lastData = (from data in db.BemsMonitoringPointHistory15min
  999. where data.SiteId == siteId && data.FacilityCode == point.FacilityCode && data.PropertyId == point.PropertyId
  1000. orderby data.CreatedDateTime descending
  1001. select data).Take(1);
  1002. if (lastData == null || lastData.Count() == 0)
  1003. {
  1004. //instance.cd = string.Format("{0:D10}", 1);
  1005. listValue.Add(-9999); // 데이터가 없는 경우 처리
  1006. }
  1007. else
  1008. {
  1009. BemsMonitoringPointHistory15min current = lastData.First();
  1010. listValue.Add(current.CurrentValue);
  1011. }
  1012. }
  1013. //return values;
  1014. return listValue;
  1015. }
  1016. catch (Exception)
  1017. {
  1018. throw;
  1019. }
  1020. }
  1021. [ActionName("RuntimeREFRIGERATOR")]
  1022. public List<CalculationValue[]> GetBemsMonitoringPointHistoryRumtimeREFRIGERATOR()
  1023. {
  1024. Uri uri = Request.RequestUri;
  1025. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1026. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  1027. string uriStartDate = uriQuery.Get("StartDate");
  1028. string uriEndDate = uriQuery.Get("EndDate");
  1029. int siteId;
  1030. int buildingId = -1; int fuelTypeId = -1;
  1031. int floorId, zoneId, timeInterval = -1;
  1032. DateTime startDate, endDate;
  1033. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  1034. int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  1035. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  1036. DateTime.TryParse(uriStartDate, out startDate) == false ||
  1037. DateTime.TryParse(uriEndDate, out endDate) == false ||
  1038. int.TryParse(uriQuery.Get("FuelTypeId"), out fuelTypeId) == false)
  1039. {
  1040. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4},{5}",
  1041. siteId, buildingId, uriTimeIntervalType, uriStartDate, uriEndDate, fuelTypeId));
  1042. }
  1043. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  1044. int? nullableFloorId = null;
  1045. int? nullableZoneId = null;
  1046. if (int.TryParse(uriQuery.Get("FloorId"), out floorId))
  1047. {
  1048. nullableFloorId = floorId;
  1049. if (int.TryParse(uriQuery.Get("ZoneId"), out zoneId))
  1050. {
  1051. nullableZoneId = zoneId;
  1052. }
  1053. }
  1054. List<MonitoringPoint> list = new List<MonitoringPoint>();
  1055. AddPointToList_Runtime_REFRIGERATOR(list, siteId); // 냉동기 가동시간
  1056. List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  1057. try
  1058. {
  1059. var values = CreateCalculationValues(startDate, endDate, timeIntervalType);
  1060. foreach (var point in list)
  1061. {
  1062. var pointValues = pointHistoryValueManager.GetPointValues(
  1063. siteId, point.FacilityCode, point.PropertyId,
  1064. timeIntervalType, startDate, endDate);
  1065. if (pointValues == null)
  1066. continue;
  1067. int index = 0;
  1068. CalculationValue p = null;
  1069. CalculationValue v = null;
  1070. for (var i = 0; i < values.Length; i++)
  1071. {
  1072. v = values[i];
  1073. if (p == null)
  1074. {
  1075. if (pointValues.Length <= index) break;
  1076. p = pointValues[index];
  1077. }
  1078. if (p.DateTime == v.DateTime)
  1079. {
  1080. v.Value += p.Value;
  1081. p = null;
  1082. index++;
  1083. if (pointValues.Length <= index) break;
  1084. }
  1085. }
  1086. listCalc.Add(values);
  1087. }
  1088. return listCalc;
  1089. }
  1090. catch (Exception)
  1091. {
  1092. throw;
  1093. }
  1094. }
  1095. [ActionName("RuntimeBOILER")]
  1096. public List<CalculationValue[]> GetBemsMonitoringPointHistoryRumtimeBOILER()
  1097. {
  1098. Uri uri = Request.RequestUri;
  1099. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1100. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  1101. string uriStartDate = uriQuery.Get("StartDate");
  1102. string uriEndDate = uriQuery.Get("EndDate");
  1103. int siteId;
  1104. int buildingId = -1; int fuelTypeId = -1;
  1105. int floorId, zoneId, timeInterval = -1;
  1106. DateTime startDate, endDate;
  1107. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  1108. int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  1109. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  1110. DateTime.TryParse(uriStartDate, out startDate) == false ||
  1111. DateTime.TryParse(uriEndDate, out endDate) == false ||
  1112. int.TryParse(uriQuery.Get("FuelTypeId"), out fuelTypeId) == false)
  1113. {
  1114. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4},{5}",
  1115. siteId, buildingId, uriTimeIntervalType, uriStartDate, uriEndDate, fuelTypeId));
  1116. }
  1117. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  1118. int? nullableFloorId = null;
  1119. int? nullableZoneId = null;
  1120. if (int.TryParse(uriQuery.Get("FloorId"), out floorId))
  1121. {
  1122. nullableFloorId = floorId;
  1123. if (int.TryParse(uriQuery.Get("ZoneId"), out zoneId))
  1124. {
  1125. nullableZoneId = zoneId;
  1126. }
  1127. }
  1128. List<MonitoringPoint> list = new List<MonitoringPoint>();
  1129. AddPointToList_Runtime_BOILER(list, siteId); // 보일러 가동시간
  1130. List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  1131. try
  1132. {
  1133. var values = CreateCalculationValues(startDate, endDate, timeIntervalType);
  1134. foreach (var point in list)
  1135. {
  1136. var pointValues = pointHistoryValueManager.GetPointValues(
  1137. siteId, point.FacilityCode, point.PropertyId,
  1138. timeIntervalType, startDate, endDate);
  1139. if (pointValues == null)
  1140. continue;
  1141. int index = 0;
  1142. CalculationValue p = null;
  1143. CalculationValue v = null;
  1144. for (var i = 0; i < values.Length; i++)
  1145. {
  1146. v = values[i];
  1147. if (p == null)
  1148. {
  1149. if (pointValues.Length <= index) break;
  1150. p = pointValues[index];
  1151. }
  1152. if (p.DateTime == v.DateTime)
  1153. {
  1154. v.Value += p.Value;
  1155. p = null;
  1156. index++;
  1157. if (pointValues.Length <= index) break;
  1158. }
  1159. }
  1160. listCalc.Add(values);
  1161. }
  1162. return listCalc;
  1163. }
  1164. catch (Exception)
  1165. {
  1166. throw;
  1167. }
  1168. }
  1169. [ActionName("MonthMoney")]
  1170. //public CalculationValue[] GetBemsMonitoringPointHistoryZoneTempHumi()
  1171. public List<CalculationValue[]> GetBemsMonitoringPointHistoryMonthMoney()
  1172. {
  1173. Uri uri = Request.RequestUri;
  1174. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1175. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  1176. string uriStartDate = uriQuery.Get("StartDate");
  1177. string uriEndDate = uriQuery.Get("EndDate");
  1178. string uriType = uriQuery.Get("Type"); // 10 전기 11 수도 12 가스
  1179. int siteId;
  1180. int timeInterval = -1; int nType = -1;
  1181. DateTime startDate, endDate;
  1182. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  1183. //int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  1184. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  1185. DateTime.TryParse(uriStartDate, out startDate) == false ||
  1186. DateTime.TryParse(uriEndDate, out endDate) == false ||
  1187. int.TryParse(uriType, out nType) == false)
  1188. {
  1189. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4}",
  1190. siteId, uriTimeIntervalType, uriStartDate, uriEndDate, uriType));
  1191. }
  1192. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  1193. List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  1194. try
  1195. {
  1196. var MM = from x in db.FmsBudgetDetailExecution
  1197. where x.SiteId == siteId && x.BudgetClassId == nType && (x.Year >= startDate.Year || x.Month >= startDate.Month) &&
  1198. (x.Year <= endDate.Year || x.Month <= endDate.Month)
  1199. select x;
  1200. var values = CreateCalculationValues(startDate, endDate, timeIntervalType); // 위치 안으로 이동 2015 08 04 hcLee
  1201. foreach (var point in MM)
  1202. {
  1203. CalculationValue v = null;
  1204. for (var i = 0; i < values.Length; i++)
  1205. {
  1206. v = values[i];
  1207. if (point.Year == v.DateTime.Year && point.Month == v.DateTime.Month)
  1208. {
  1209. //v.Value += p.Value;
  1210. v.Value = point.MonthlyExecution;
  1211. //p = null;
  1212. //index++;
  1213. listCalc.Add(values);
  1214. break;
  1215. //if (pointValues.Length <= index) break;
  1216. }
  1217. }
  1218. }
  1219. //return values;
  1220. }
  1221. catch (Exception)
  1222. {
  1223. throw;
  1224. }
  1225. return listCalc;
  1226. }
  1227. [ActionName("CurrentValueFrom15min")]
  1228. public List<CalculationValue[]> GetBemsMonitoringPointHistoryCurrentValue()
  1229. {
  1230. Uri uri = Request.RequestUri;
  1231. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1232. List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  1233. //string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  1234. //string uriStartDate = uriQuery.Get("StartDate");
  1235. //string uriEndDate = uriQuery.Get("EndDate");
  1236. int siteId;
  1237. int ValueType = -1;
  1238. //DateTime startDate, endDate;
  1239. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  1240. int.TryParse(uriQuery.Get("ValueType"), out ValueType) == false)
  1241. {
  1242. throw new Exception(string.Format("Not Found Parameters: {0},{1}", siteId, ValueType));
  1243. //return listCalc;
  1244. }
  1245. List<MonitoringPoint> list = new List<MonitoringPoint>();
  1246. AddPointToList_ControlPoint(list, siteId, ValueType); // valueType이 특정인 포인트들만 (설정제어용)
  1247. try
  1248. {
  1249. //var values = CreateCalculationValues(startDate, endDate, timeIntervalType);
  1250. //int v = 0;
  1251. foreach (var point in list)
  1252. {
  1253. CalculationValue[] values = new CalculationValue[2];
  1254. IEnumerable<BemsMonitoringPointHistory15min> lastData = (from data in db.BemsMonitoringPointHistory15min
  1255. where data.SiteId == siteId && data.FacilityCode == point.FacilityCode && data.PropertyId == point.PropertyId
  1256. orderby data.CreatedDateTime descending select data).Take(1);
  1257. values[0] = new CalculationValue
  1258. {
  1259. DateTime = new DateTime(),
  1260. Value = -9999
  1261. };
  1262. if (lastData == null || lastData.Count() == 0)
  1263. {
  1264. //instance.cd = string.Format("{0:D10}", 1);
  1265. }
  1266. else
  1267. {
  1268. BemsMonitoringPointHistory15min current = lastData.First();
  1269. values[0].Value = current.CurrentValue;
  1270. }
  1271. IEnumerable<BemsControlPointHistory> lastData2 = (from data in db.BemsControlPointHistory
  1272. where data.SiteId == siteId && data.FacilityCode == point.FacilityCode && data.PropertyId == point.PropertyId
  1273. orderby data.CreateDateTime descending select data).Take(1);
  1274. values[1] = new CalculationValue
  1275. {
  1276. DateTime = new DateTime(),
  1277. Value = -9999
  1278. };
  1279. if (lastData2 == null || lastData2.Count() == 0)
  1280. {
  1281. //instance.cd = string.Format("{0:D10}", 1);
  1282. }
  1283. else
  1284. {
  1285. BemsControlPointHistory current = lastData2.First();
  1286. values[1].Value = current.ControlValue;
  1287. }
  1288. listCalc.Add(values);
  1289. }
  1290. return listCalc;
  1291. }
  1292. catch (Exception)
  1293. {
  1294. throw;
  1295. }
  1296. //return listCalc;
  1297. }
  1298. //**************** 2019.05.30. 가상설비, 일반설비 데이터 가져오기******************//
  1299. [ActionName("VirtualNormalFacilityData")]
  1300. public List<CalculationValue[]> GetBemsMonitoringPointHistoryVirtualNormalCurrentValue()
  1301. {
  1302. Uri uri = Request.RequestUri;
  1303. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1304. string uriSiteId = uriQuery.Get("SiteId");
  1305. string uriFacilityTypeId = uriQuery.Get("FacilityTypeId");
  1306. string uriFacilityCode = uriQuery.Get("FacilityCode");
  1307. string uriPropertyId = uriQuery.Get("PropertyId");
  1308. string uriTimeInterval = uriQuery.Get("TimeIntervalType");
  1309. string uriStartDate = uriQuery.Get("StartDate");
  1310. string uriEndDate = uriQuery.Get("EndDate");
  1311. int siteId = -1, facilityTypeId = -1, propertyId = -1, timeInterval = -1, facilityCode = -1;
  1312. DateTime startDate, endDate;
  1313. if (int.TryParse(uriSiteId, out siteId) == false ||
  1314. int.TryParse(uriFacilityTypeId, out facilityTypeId) == false ||
  1315. int.TryParse(uriPropertyId, out propertyId) == false ||
  1316. int.TryParse(uriTimeInterval, out timeInterval) == false ||
  1317. int.TryParse(uriFacilityCode, out facilityCode) == false ||
  1318. DateTime.TryParse(uriStartDate, out startDate) == false ||
  1319. DateTime.TryParse(uriEndDate, out endDate) == false)
  1320. {
  1321. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4},{5}",
  1322. siteId, facilityTypeId, propertyId, uriTimeInterval, uriStartDate, uriEndDate));
  1323. }
  1324. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  1325. List<MonitoringPoint> list = new List<MonitoringPoint>();
  1326. AddPointToList_ControlPoint2(list, siteId, propertyId, facilityTypeId, facilityCode); // 2019.05.30.
  1327. List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  1328. try
  1329. {
  1330. var values = CreateCalculationValues(startDate, endDate, timeIntervalType);
  1331. foreach (var point in list)
  1332. {
  1333. var pointValues = pointHistoryValueManager.GetPointValues(
  1334. siteId, point.FacilityCode, point.PropertyId,
  1335. timeIntervalType, startDate, endDate);
  1336. if (pointValues == null)
  1337. continue;
  1338. int index = 0;
  1339. CalculationValue p = null;
  1340. CalculationValue v = null;
  1341. for (var i = 0; i < values.Length; i++)
  1342. {
  1343. v = values[i];
  1344. if (p == null)
  1345. {
  1346. if (pointValues.Length <= index) break;
  1347. p = pointValues[index];
  1348. }
  1349. if (p.DateTime == v.DateTime)
  1350. {
  1351. v.Value += p.Value;
  1352. p = null;
  1353. index++;
  1354. if (pointValues.Length <= index) break;
  1355. }
  1356. }
  1357. listCalc.Add(values);
  1358. }
  1359. return listCalc;
  1360. }
  1361. catch (Exception)
  1362. {
  1363. throw;
  1364. }
  1365. }
  1366. //**************** 2019.05.30. 가상설비, 일반설비 데이터 가져오기******************//
  1367. [ResponseType(typeof(void))]
  1368. [ActionName("ControlPoint")]
  1369. public IHttpActionResult PostControlPoint()
  1370. {
  1371. Uri uri = Request.RequestUri;
  1372. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1373. string uriSiteId = uriQuery.Get("SiteId");
  1374. string uriFacilityTypeId = uriQuery.Get("FacilityTypeId");
  1375. string uriFacilityCode = uriQuery.Get("FacilityCode");
  1376. string uriPropertyId = uriQuery.Get("PropertyId");
  1377. string uriControlValue = uriQuery.Get("ControlValue");
  1378. int siteId = -1, facilityTypeId = -1, propertyId = -1, facilityCode = -1;
  1379. double controlValue = 0;
  1380. if (int.TryParse(uriSiteId, out siteId) == false ||
  1381. int.TryParse(uriFacilityTypeId, out facilityTypeId) == false ||
  1382. int.TryParse(uriPropertyId, out propertyId) == false ||
  1383. int.TryParse(uriFacilityCode, out facilityCode) == false ||
  1384. double.TryParse(uriControlValue, out controlValue) == false)
  1385. {
  1386. throw new Exception(string.Format("Not Found FFFF Parameters: {0},{1},{2},{3},{4} ", uriSiteId, uriFacilityTypeId, facilityCode, uriPropertyId, uriControlValue));
  1387. }
  1388. DateTime currentTime = DateTime.Now;
  1389. using (var transaction = new TransactionScope())
  1390. {
  1391. try
  1392. {
  1393. {
  1394. var control = new BemsControlPointHistory
  1395. {
  1396. SiteId = siteId,
  1397. FacilityTypeId = facilityTypeId, // 2015 08 05 DB 문제로 일단 99로 테스트함, 정상코드는 아래줄이다.
  1398. FacilityCode = facilityCode,
  1399. PropertyId = propertyId, // ???? hcLee
  1400. CreateDateTime = currentTime,
  1401. ControlValue = controlValue,
  1402. WriteServiceName = null,
  1403. ActionDateTime = null
  1404. };
  1405. db.BemsControlPointHistory.Add(control);
  1406. db.SaveChanges();
  1407. }
  1408. }
  1409. catch (Exception e)
  1410. {
  1411. Trace.WriteLine(e.Message);
  1412. //throw e;
  1413. throw;
  1414. }
  1415. transaction.Complete();
  1416. }
  1417. return StatusCode(HttpStatusCode.NoContent);
  1418. }
  1419. [ActionName("LCCViewPreSum")]
  1420. public List<double> GetBemsMonitoringPointHistoryLCCViewPreSum()
  1421. {
  1422. Uri uri = Request.RequestUri;
  1423. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1424. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  1425. string uriStartDate = uriQuery.Get("StartDate");
  1426. string uriEndDate = uriQuery.Get("EndDate");
  1427. //string uriType = uriQuery.Get("Type"); // 10 전기 11 수도 12 가스
  1428. int siteId;
  1429. int timeInterval = -1;
  1430. DateTime startDate, endDate;
  1431. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  1432. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  1433. DateTime.TryParse(uriStartDate, out startDate) == false ||
  1434. DateTime.TryParse(uriEndDate, out endDate) == false)
  1435. {
  1436. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3}", siteId, uriTimeIntervalType, uriStartDate, uriEndDate));
  1437. }
  1438. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  1439. List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  1440. List<FmsBudgetCodeClass> listCode = new List<FmsBudgetCodeClass>();
  1441. var dd = from x in db.FmsBudgetCodeClass where x.Depth == 0 select x;
  1442. listCode = dd.ToList();
  1443. List<double> listTotalSum = new List<double>();
  1444. foreach (FmsBudgetCodeClass code in listCode)
  1445. {
  1446. var MM = from x in db.FmsBudgetDetailExecution
  1447. where x.SiteId == siteId && x.Year >= 1000 && x.Month >= 0 && // 최초부터
  1448. x.Year < startDate.Year || (x.Year == startDate.Year && x.Month < startDate.Month)
  1449. from c in db.FmsBudgetCodeClass
  1450. where c.BudgetSeq.Substring(0, 2) == code.BudgetSeq && x.BudgetClassId == c.BudgetClassId
  1451. select x;
  1452. double sum = new double();
  1453. foreach (var point in MM)
  1454. {
  1455. sum += point.MonthlyExecution;
  1456. }
  1457. listTotalSum.Add(sum);
  1458. }
  1459. return listTotalSum;
  1460. }
  1461. [ActionName("LCCView")]
  1462. public List<CalculationValueBudget[]> GetBemsMonitoringPointHistoryLCCView()
  1463. {
  1464. Uri uri = Request.RequestUri;
  1465. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1466. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  1467. string uriStartDate = uriQuery.Get("StartDate");
  1468. string uriEndDate = uriQuery.Get("EndDate");
  1469. //string uriType = uriQuery.Get("Type"); // 10 전기 11 수도 12 가스
  1470. int siteId;
  1471. int timeInterval = -1;
  1472. DateTime startDate, endDate;
  1473. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  1474. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  1475. DateTime.TryParse(uriStartDate, out startDate) == false ||
  1476. DateTime.TryParse(uriEndDate, out endDate) == false)
  1477. {
  1478. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3}", siteId, uriTimeIntervalType, uriStartDate, uriEndDate));
  1479. }
  1480. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  1481. List<CalculationValueBudget[]> listCalc = new List<CalculationValueBudget[]>();
  1482. List<FmsBudgetCodeClass> listCode = new List<FmsBudgetCodeClass>();
  1483. var dd = from x in db.FmsBudgetCodeClass where x.Depth == 0 select x;
  1484. listCode = dd.ToList();
  1485. foreach (FmsBudgetCodeClass code in listCode)
  1486. {
  1487. var MM = from x in db.FmsBudgetDetailExecution
  1488. where x.SiteId == siteId && x.Year >= startDate.Year && x.Month >= startDate.Month &&
  1489. x.Year < endDate.Year || (x.Year == endDate.Year && x.Month <= endDate.Month)
  1490. from c in db.FmsBudgetCodeClass
  1491. where c.BudgetSeq.Substring(0, 2) == code.BudgetSeq && x.BudgetClassId == c.BudgetClassId
  1492. select x;
  1493. var values = CreateCalculationValuesBudget(startDate, endDate, timeIntervalType); // 위치 안으로 이동 2015 08 04 hcLee
  1494. foreach (var point in MM)
  1495. {
  1496. CalculationValueBudget v = null;
  1497. for (var i = 0; i < values.Length; i++)
  1498. {
  1499. v = values[i];
  1500. if (point.Year == v.DateTime.Year && point.Month == v.DateTime.Month)
  1501. {
  1502. v.Value += point.MonthlyExecution;
  1503. v.Value2 += point.MonthlyBudget;
  1504. break;
  1505. }
  1506. }
  1507. }
  1508. listCalc.Add(values);
  1509. }
  1510. return listCalc;
  1511. }
  1512. [ActionName("FmsHouseStock")]
  1513. public List<FmsHouseStockEx> GetBemsMonitoringFmsHouseStock()
  1514. {
  1515. Uri uri = Request.RequestUri;
  1516. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1517. string uriBusinessId = uriQuery.Get("BusinessId");
  1518. int siteId;
  1519. int BusinessId = -1;
  1520. //DateTime startDate, endDate;
  1521. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  1522. int.TryParse(uriBusinessId, out BusinessId) == false)
  1523. {
  1524. throw new Exception(string.Format("Not Found Parameters: {0},{1}", siteId, uriBusinessId));
  1525. }
  1526. List<FmsMaterialWarehouse> listHouse = new List<FmsMaterialWarehouse>();
  1527. var hh = from h in db.FmsMaterialWarehouse where h.SiteId == siteId select h;
  1528. listHouse = hh.ToList();
  1529. List<FmsHouseStockEx> listEx = new List<FmsHouseStockEx>();
  1530. foreach (FmsMaterialWarehouse h in listHouse)
  1531. {
  1532. var query = from data in db.FmsMaterialStored
  1533. //var query = from data in db.FmsMaterialEx
  1534. //where (data.SiteId == siteId && data.WarehouseId == h.WarehouseId && M.MaterialId == data.MaterialId)
  1535. where (data.SiteId == siteId && data.WarehouseId == h.WarehouseId)
  1536. from M in db.FmsMaterial
  1537. where M.SiteId == siteId && M.MaterialId == data.MaterialId
  1538. group data by new { data.MaterialId, M.MaterialCode, M.Name } into g
  1539. select new
  1540. {
  1541. HouseName = h.Name,
  1542. MaterialId = g.Key.MaterialId,
  1543. StockCnt = g.Sum(data => data.RemainStoredCount),
  1544. MName = g.Key.Name,
  1545. MaterialCode = g.Key.MaterialCode
  1546. };
  1547. foreach (var v in query)
  1548. {
  1549. FmsHouseStockEx ex = new FmsHouseStockEx();
  1550. ex.MaterialId = v.MaterialId;
  1551. ex.MaterialCode= v.MaterialCode;
  1552. ex.MName = v.MName;
  1553. ex.HouseName = v.HouseName;
  1554. ex.StockCnt = v.StockCnt;
  1555. listEx.Add(ex);
  1556. }
  1557. }
  1558. return listEx;
  1559. /*
  1560. List<double> listTotalSum = new List<double>();
  1561. foreach (FmsBudgetCodeClass code in listCode)
  1562. {
  1563. var MM = from x in db.FmsBudgetDetailExecution
  1564. where x.SiteId == siteId && x.Year >= 1000 && x.Month >= 0 && // 최초부터
  1565. x.Year < startDate.Year || (x.Year == startDate.Year && x.Month < startDate.Month)
  1566. from c in db.FmsBudgetCodeClass
  1567. where c.BudgetSeq.Substring(0, 2) == code.BudgetSeq && x.BudgetClassId == c.BudgetClassId
  1568. select x;
  1569. double sum = new double();
  1570. foreach (var point in MM)
  1571. {
  1572. sum += point.MonthlyExecution;
  1573. }
  1574. listTotalSum.Add(sum);
  1575. }
  1576. return listTotalSum;*/
  1577. }
  1578. [ActionName("GetCenterSiteData")]
  1579. public List<CenterSiteData> PostGetCenterSiteData(GetCenterSiteData_Param param)
  1580. {
  1581. int timeIntervalType = param.TimeIntervalType;
  1582. DateTime startDate = param.startDate, endDate = param.endDate;
  1583. DateTime currentTime = DateTime.Now;
  1584. DateTime todayStart = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 0, 0, 0);
  1585. List<CenterSiteData> list = new List<CenterSiteData>();
  1586. IEnumerable<CmSite> sites = from data in db.CmSite where data.SiteId > 0 select data;
  1587. BemsFormulaController FC = new BemsFormulaController();
  1588. //1.100.1.1 3
  1589. foreach (CmSite s in sites)
  1590. {
  1591. CenterSiteData cd = new CenterSiteData();
  1592. cd.siteid = s.SiteId;
  1593. cd.name = s.Name;
  1594. //List<CalculationValue> listC = new List<CalculationValue>();
  1595. //listC.Add(new CalculationValue());
  1596. cd.e_value_list = FC.GetBemsFormulaReal(s.SiteId, 100, 1, 1, todayStart, currentTime, 2); // hour
  1597. cd.g_value_list = FC.GetBemsFormulaReal(s.SiteId, 101, 2, 1, todayStart, currentTime, 2); // hour
  1598. List<CalculationResult> listEYear = FC.GetBemsFormulaReal(s.SiteId, 100, 1, 1, startDate, endDate, timeIntervalType);
  1599. cd.elec_current = (listEYear.Count() <= 0) ? 0 : listEYear[0].Value;
  1600. List<CalculationResult> listGYear = FC.GetBemsFormulaReal(s.SiteId, 101, 2, 1, startDate, endDate, timeIntervalType);
  1601. cd.gas_current = (listGYear.Count() <= 0) ? 0 : listGYear[0].Value;
  1602. //cd.kcal_target = 300;
  1603. var G = from x in db.BemsEnergyDaily
  1604. where (x.SiteId == s.SiteId && x.FuelTypeId == 1 && x.CreatedDate >= startDate && x.CreatedDate <= endDate)
  1605. group x by new { x.SiteId } into g
  1606. select new { P = g.Sum(x => x.Goal) };
  1607. //listPrediction.Add(G.Count() > 0 ? (double)G.FirstOrDefault().P : 0);
  1608. cd.elec_target = G.Count() > 0 ? (double)G.FirstOrDefault().P : 0;
  1609. G = from x in db.BemsEnergyDaily
  1610. where (x.SiteId == s.SiteId && x.FuelTypeId == 2 && x.CreatedDate >= startDate && x.CreatedDate <= endDate)
  1611. group x by new { x.SiteId } into g
  1612. select new { P = g.Sum(x => x.Goal) };
  1613. cd.gas_target = G.Count() > 0 ? (double)G.FirstOrDefault().P : 0;
  1614. list.Add(cd);
  1615. }
  1616. return list;
  1617. }
  1618. // 차후를 생각해 BuildingId와 FuelType, 날짜를 받지만 현재 의미는 없다 hcLee 2016 03 18
  1619. [ActionName("GetPrediction")]
  1620. public List<double> PostGetPrediction(GetPrediction_Param param)
  1621. {
  1622. /* Uri uri = Request.RequestUri;
  1623. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  1624. //string uriBuildingId = uriQuery.Get("BuildingId");
  1625. string uriFuelType = uriQuery.Get("FuelType");
  1626. string uriStartDate = uriQuery.Get("StartDate");
  1627. string uriEndDate = uriQuery.Get("EndDate");
  1628. //string uriType = uriQuery.Get("Type"); // 10 전기 11 수도 12 가스
  1629. int siteId;
  1630. int fueltype = -1; int buildingId = 0;
  1631. DateTime startDate, endDate;
  1632. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  1633. int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  1634. int.TryParse(uriFuelType, out fueltype) == false ||
  1635. DateTime.TryParse(uriStartDate, out startDate) == false ||
  1636. DateTime.TryParse(uriEndDate, out endDate) == false)
  1637. {
  1638. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2},{3},{4},{5}", siteId, buildingId, uriFuelType, uriStartDate, uriEndDate));
  1639. }*/
  1640. //int timeIntervalType = (TimeInterval)timeInterval;
  1641. //List<CalculationValue[]> listCalc = new List<CalculationValue[]>();
  1642. List<double> listPrediction = new List<double>();
  1643. DateTime startDate, endDate;
  1644. int siteId = param.SiteId;
  1645. DateTime currentTime = DateTime.Now;
  1646. startDate = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 0, 0, 0);
  1647. endDate = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 23, 59, 59);
  1648. for (int i = 0; i < 3; i++)
  1649. {
  1650. // 오늘의 전기 가스 수도 TOE
  1651. var G = from x in db.BemsEnergyDaily
  1652. where (x.SiteId == siteId && x.FuelTypeId == 1 && x.CreatedDate >= startDate && x.CreatedDate <= endDate)
  1653. group x by new { x.SiteId } into g
  1654. select new { P = g.Sum(x => x.Goal) };
  1655. listPrediction.Add(G.Count() > 0 ? (double)G.FirstOrDefault().P : 0);
  1656. G = from x in db.BemsEnergyDaily
  1657. where (x.SiteId == siteId && x.FuelTypeId == 2 && x.CreatedDate >= startDate && x.CreatedDate <= endDate)
  1658. group x by new { x.SiteId } into g
  1659. select new { P = g.Sum(x => x.Goal) };
  1660. listPrediction.Add(G.Count() > 0 ? (double)G.FirstOrDefault().P : 0);
  1661. G = from x in db.BemsEnergyDaily
  1662. where (x.SiteId == siteId && x.FuelTypeId == 3 && x.CreatedDate >= startDate && x.CreatedDate <= endDate)
  1663. group x by new { x.SiteId } into g
  1664. select new { P = g.Sum(x => x.Goal) };
  1665. listPrediction.Add(G.Count() > 0 ? (double)G.FirstOrDefault().P : 0);
  1666. /*
  1667. G = from x in db.BemsEnergyGoalDaily
  1668. where (x.SiteId == siteId && x.CreatedDate >= startDate && x.CreatedDate <= endDate)
  1669. group x by new { x.SiteId } into g select new { P = g.Sum(x => x.Goal) };
  1670. listPrediction.Add(G.Count() > 0 ? (double)G.FirstOrDefault().P : 0); */
  1671. //Why(listPrediction, siteId, startDate, endDate); 2016 07 15 테이블 삭제
  1672. if (i == 0) // 두번쨰 루프시작전 이번달
  1673. {
  1674. startDate = new DateTime(currentTime.Year, currentTime.Month, 1, 0, 0, 0);
  1675. endDate = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 23, 59, 59);
  1676. }
  1677. else if (i == 1) // 세번쨰 루프시작전 금년
  1678. {
  1679. startDate = new DateTime(currentTime.Year, 1, 1, 0, 0, 0);
  1680. endDate = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 23, 59, 59);
  1681. }
  1682. }
  1683. return listPrediction; // 4 x 3 12개의 값 -> 9
  1684. }
  1685. /* {}
  1686. private void Why(List<double> list, int siteId, DateTime startDate, DateTime endDate)
  1687. {
  1688. //var G = from x in db.BemsEnergyGoalDaily 2016 07 15
  1689. var G = from x in db.BemsEnergyDaily
  1690. where (x.SiteId == siteId && x.CreatedDate >= startDate && x.CreatedDate <= endDate)
  1691. group x by new { x.SiteId } into g select new { P = g.Sum(x => x.Goal) };
  1692. list.Add(G.Count() > 0 ? (double)G.FirstOrDefault().P : 0);
  1693. } */
  1694. private void NextTimeFromTimeInterval( ref DateTime datetime, TimeInterval timeIntervalType )
  1695. {
  1696. switch( timeIntervalType )
  1697. {
  1698. case TimeInterval.QuarterMin:
  1699. datetime = datetime.AddMinutes( 15 );
  1700. break;
  1701. case TimeInterval.Hour:
  1702. datetime = datetime.AddHours( 1 );
  1703. break;
  1704. case TimeInterval.Day:
  1705. datetime = datetime.AddDays( 1 );
  1706. break;
  1707. case TimeInterval.Month:
  1708. datetime = datetime.AddMonths( 1 );
  1709. break;
  1710. default: // TimeInterval.Year:
  1711. datetime = datetime.AddYears( 1 );
  1712. break;
  1713. }
  1714. }
  1715. private int GetCountInTimeRange( DateTime startDate , DateTime endDate , TimeInterval timeIntervalType )
  1716. {
  1717. TimeSpan ts = endDate - startDate;
  1718. switch( timeIntervalType )
  1719. {
  1720. case TimeInterval.QuarterMin:
  1721. return (int)ts.TotalMinutes / 15 + 1;
  1722. case TimeInterval.Hour:
  1723. return (int)ts.TotalHours + 1;
  1724. case TimeInterval.Day:
  1725. return (int)ts.TotalDays + 1;
  1726. case TimeInterval.Month:
  1727. {
  1728. int count = 0;
  1729. DateTime date = startDate;
  1730. //while (date.Year <= endDate.Year && date.Month <= endDate.Month) // hcLee 헐~
  1731. while (date <= endDate) // hcLee
  1732. {
  1733. count++;
  1734. date = date.AddMonths( 1 );
  1735. }
  1736. return count;
  1737. }
  1738. default: // TimeInterval.Year:
  1739. {
  1740. int count = 0;
  1741. DateTime date = startDate;
  1742. while( date.Year <= endDate.Year)
  1743. {
  1744. count++;
  1745. date = date.AddYears( 1 );
  1746. }
  1747. return count;
  1748. }
  1749. }
  1750. }
  1751. private CalculationValue[] CreateCalculationValues( DateTime startDate , DateTime endDate , TimeInterval timeIntervalType )
  1752. {
  1753. DateTime datetime = startDate;
  1754. int count = GetCountInTimeRange( startDate , endDate , timeIntervalType );
  1755. CalculationValue[] values = new CalculationValue[count];
  1756. for( var i = 0 ; i < values.Length ; i++ )
  1757. {
  1758. values[i] = new CalculationValue
  1759. {
  1760. DateTime = datetime ,
  1761. Value = 0
  1762. };
  1763. NextTimeFromTimeInterval( ref datetime , timeIntervalType );
  1764. }
  1765. return values;
  1766. }
  1767. private CalculationValueBudget[] CreateCalculationValuesBudget(DateTime startDate, DateTime endDate, TimeInterval timeIntervalType)
  1768. {
  1769. DateTime datetime = startDate;
  1770. int count = GetCountInTimeRange(startDate, endDate, timeIntervalType);
  1771. CalculationValueBudget[] values = new CalculationValueBudget[count];
  1772. for (var i = 0; i < values.Length; i++)
  1773. {
  1774. values[i] = new CalculationValueBudget
  1775. {
  1776. DateTime = datetime,
  1777. Value = 0,
  1778. Value2 = 0
  1779. };
  1780. NextTimeFromTimeInterval(ref datetime, timeIntervalType);
  1781. }
  1782. return values;
  1783. }
  1784. private CalculationValueSType[] CreateCalculationValuesSType(DateTime startDate, DateTime endDate, TimeInterval timeIntervalType)
  1785. {
  1786. DateTime datetime = startDate;
  1787. int count = GetCountInTimeRange(startDate, endDate, timeIntervalType);
  1788. var query = from x in db.BemsServiceType where x.ServiceTypeId < 100 && x.ServiceTypeId > 0 select x;
  1789. //foreach (CmBuilding b in query)
  1790. CalculationValueSType[] values = new CalculationValueSType[count * query.Count()];
  1791. //CalculationValueSType[] values = new CalculationValueSType[count][query.Count()];
  1792. int j = 0;
  1793. for (var i = 0; i < count; i++)
  1794. {
  1795. foreach (BemsServiceType S in query)
  1796. {
  1797. values[j] = new CalculationValueSType
  1798. {
  1799. DateTime = datetime,
  1800. Value = 0,
  1801. ServiceType = S.ServiceTypeId
  1802. };
  1803. j++;
  1804. }
  1805. NextTimeFromTimeInterval(ref datetime, timeIntervalType);
  1806. //j += query.Count();
  1807. }
  1808. return values;
  1809. }
  1810. private void AddPointToListInLocation( List<MonitoringPoint> list ,
  1811. int siteId , int fuelTypeId , int buildingId , int? floorId , int? zoneId )
  1812. {
  1813. {
  1814. bool bEnd = false;
  1815. IQueryable<MonitoringPoint> query;
  1816. // floorId 나 zoneId 가 null를 가지고 있어도, 비교시에는 null로 비교하지 않는다.
  1817. // 그래서 강제적으로 조건에 따라 null를 비교하도록 수정
  1818. if( floorId == null && zoneId == null ) // 건물처리
  1819. {
  1820. query = from x in db.BemsMonitoringPoint
  1821. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId &&
  1822. x.BuildingId == buildingId && x.FloorId == null && x.ZoneId == null
  1823. select new MonitoringPoint
  1824. {
  1825. SiteId = x.SiteId,
  1826. FacilityCode = x.FacilityCode,
  1827. PropertyId = x.PropertyId,
  1828. };
  1829. //throw new Exception(string.Format("case1"));
  1830. }
  1831. else if (floorId != null && zoneId == null) // 층처리 층이고 zone이 null인 즉 층전체포인트가 있으면
  1832. {
  1833. query = from x in db.BemsMonitoringPoint
  1834. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId &&
  1835. x.BuildingId == buildingId && x.FloorId == floorId && x.ZoneId == null
  1836. select new MonitoringPoint
  1837. {
  1838. SiteId = x.SiteId,
  1839. FacilityCode = x.FacilityCode,
  1840. PropertyId = x.PropertyId,
  1841. };
  1842. }
  1843. else // 구역처리
  1844. {
  1845. query = from x in db.BemsMonitoringPoint
  1846. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId &&
  1847. x.BuildingId == buildingId && x.FloorId == floorId && x.ZoneId == zoneId
  1848. select new MonitoringPoint
  1849. {
  1850. SiteId = x.SiteId ,
  1851. FacilityCode = x.FacilityCode ,
  1852. PropertyId = x.PropertyId ,
  1853. };
  1854. bEnd = true;
  1855. //throw new Exception(string.Format("case4"));
  1856. }
  1857. //int n = query.Count();
  1858. if( query.Any() )
  1859. {
  1860. foreach( var data in query )
  1861. {
  1862. list.Add( data );
  1863. }
  1864. return; // 있으면 끝
  1865. }
  1866. if (bEnd) return;
  1867. }
  1868. {
  1869. if( floorId == null ) //
  1870. {
  1871. var query = from x in db.CmFloor
  1872. where x.SiteId == siteId && x.BuildingId == buildingId
  1873. select x.FloorId;
  1874. if (query.Any())
  1875. {
  1876. foreach (var floor in query)
  1877. {
  1878. AddPointToListInLocation(list, siteId, fuelTypeId, buildingId, floor, null);
  1879. }
  1880. }
  1881. }
  1882. //else if( zoneId == null )
  1883. //if( zoneId == null )
  1884. if (zoneId == null)
  1885. //else
  1886. {
  1887. var query = from x in db.CmZone
  1888. where x.SiteId == siteId && x.BuildingId == buildingId && x.FloorId == floorId
  1889. select x.ZoneId;
  1890. if (query.Any())
  1891. {
  1892. foreach (var zone in query)
  1893. {
  1894. AddPointToListInLocation(list, siteId, fuelTypeId, buildingId, floorId, zone);
  1895. }
  1896. }
  1897. }
  1898. }
  1899. }
  1900. private void AddPointToListInLocationSType_New(List<MonitoringPointSType> list, int siteId, int buildingId, int fuelTypeId)
  1901. {
  1902. var q = from x in db.BemsServiceType
  1903. where x.ServiceTypeId > 0 && x.ServiceTypeId < 100
  1904. select x;
  1905. IQueryable<MonitoringPointSType> query;
  1906. foreach (var stype in q)
  1907. {
  1908. //AddPointToListInLocation(list, siteId, fuelTypeId, buildingId, floorId, zone);
  1909. query = from x in db.BemsMonitoringPoint
  1910. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId == stype.ServiceTypeId &&
  1911. x.BuildingId == buildingId && x.FloorId == null
  1912. select new MonitoringPointSType
  1913. {
  1914. SiteId = x.SiteId,
  1915. FacilityCode = x.FacilityCode,
  1916. PropertyId = x.PropertyId,
  1917. ServiceTypeId = (int)x.ServiceTypeId,
  1918. };
  1919. //int n = query.Count();
  1920. if (query.Any())
  1921. {
  1922. foreach (var data in query)
  1923. {
  1924. list.Add(data);
  1925. }
  1926. }
  1927. else // 빌딩만 매핑이 없으면 각 층
  1928. {
  1929. IQueryable<CmFloor> qF;
  1930. qF = from x in db.CmFloor
  1931. where x.SiteId == siteId && x.BuildingId == buildingId
  1932. select x;
  1933. foreach (var floor in qF)
  1934. {
  1935. query = from x in db.BemsMonitoringPoint
  1936. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId == stype.ServiceTypeId &&
  1937. x.BuildingId == buildingId && x.FloorId == floor.FloorId && x.ZoneId == null
  1938. select new MonitoringPointSType
  1939. {
  1940. SiteId = x.SiteId,
  1941. FacilityCode = x.FacilityCode,
  1942. PropertyId = x.PropertyId,
  1943. ServiceTypeId = (int)x.ServiceTypeId,
  1944. };
  1945. //n = query.Count();
  1946. if (query.Any())
  1947. {
  1948. foreach (var data in query)
  1949. {
  1950. list.Add(data);
  1951. }
  1952. }
  1953. else
  1954. {
  1955. query = from x in db.BemsMonitoringPoint
  1956. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId == stype.ServiceTypeId &&
  1957. x.BuildingId == buildingId && x.FloorId == floor.FloorId && x.ZoneId != null
  1958. select new MonitoringPointSType
  1959. {
  1960. SiteId = x.SiteId,
  1961. FacilityCode = x.FacilityCode,
  1962. PropertyId = x.PropertyId,
  1963. ServiceTypeId = (int)x.ServiceTypeId,
  1964. };
  1965. if (query.Any())
  1966. {
  1967. foreach (var data in query)
  1968. {
  1969. list.Add(data);
  1970. }
  1971. }
  1972. }
  1973. }
  1974. }
  1975. }
  1976. }
  1977. private void AddPointToListInLocationSType_New2(List<MonitoringPointSType> list, int siteId, int buildingId)
  1978. {
  1979. var q = from x in db.BemsServiceType
  1980. where x.ServiceTypeId > 0 && x.ServiceTypeId < 100 select x;
  1981. IQueryable<MonitoringPointSType> query;
  1982. foreach (var stype in q)
  1983. {
  1984. query = from x in db.BemsMonitoringPoint
  1985. where x.SiteId == siteId && x.ServiceTypeId == stype.ServiceTypeId &&
  1986. x.FuelTypeId > 0 && // 2017 02 17 hcLee 방어코드 추가, 보라매현장 DB입력 오류 (서비스타입은 있는데 Fuel이 0인 포인트 존재) 회피코드
  1987. x.BuildingId == buildingId && x.FloorId == null
  1988. select new MonitoringPointSType
  1989. {
  1990. SiteId = x.SiteId,
  1991. FacilityCode = x.FacilityCode,
  1992. PropertyId = x.PropertyId,
  1993. ServiceTypeId = (int)x.ServiceTypeId,
  1994. FuelTypeId = (int)x.FuelTypeId,
  1995. };
  1996. //int n = query.Count();
  1997. if (query.Any())
  1998. {
  1999. foreach (var data in query)
  2000. {
  2001. list.Add(data);
  2002. }
  2003. }
  2004. else // 빌딩만 매핑이 없으면 각 층
  2005. {
  2006. IQueryable<CmFloor> qF;
  2007. qF = from x in db.CmFloor
  2008. where x.SiteId == siteId && x.BuildingId == buildingId select x;
  2009. foreach (var floor in qF)
  2010. {
  2011. query = from x in db.BemsMonitoringPoint
  2012. //where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId == stype.ServiceTypeId &&
  2013. where x.SiteId == siteId && x.ServiceTypeId == stype.ServiceTypeId &&
  2014. x.BuildingId == buildingId && x.FloorId == floor.FloorId && x.ZoneId == null
  2015. select new MonitoringPointSType
  2016. {
  2017. SiteId = x.SiteId,
  2018. FacilityCode = x.FacilityCode,
  2019. PropertyId = x.PropertyId,
  2020. ServiceTypeId = (int)x.ServiceTypeId,
  2021. FuelTypeId = (int)x.FuelTypeId,
  2022. };
  2023. //n = query.Count();
  2024. if (query.Any())
  2025. {
  2026. foreach (var data in query)
  2027. {
  2028. list.Add(data);
  2029. }
  2030. }
  2031. else
  2032. {
  2033. query = from x in db.BemsMonitoringPoint
  2034. //where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId == stype.ServiceTypeId &&
  2035. where x.SiteId == siteId && x.ServiceTypeId == stype.ServiceTypeId &&
  2036. x.BuildingId == buildingId && x.FloorId == floor.FloorId && x.ZoneId != null
  2037. select new MonitoringPointSType
  2038. {
  2039. SiteId = x.SiteId,
  2040. FacilityCode = x.FacilityCode,
  2041. PropertyId = x.PropertyId,
  2042. ServiceTypeId = (int)x.ServiceTypeId,
  2043. FuelTypeId = (int)x.FuelTypeId,
  2044. };
  2045. if (query.Any())
  2046. {
  2047. foreach (var data in query)
  2048. {
  2049. list.Add(data);
  2050. }
  2051. }
  2052. }
  2053. }
  2054. }
  2055. }
  2056. }
  2057. private void AddPointToListInLocationSType(List<MonitoringPointSType> list,
  2058. int siteId, int fuelTypeId, int buildingId, int? floorId, int? zoneId)
  2059. {
  2060. {
  2061. IQueryable<MonitoringPointSType> query;
  2062. // floorId 나 zoneId 가 null를 가지고 있어도, 비교시에는 null로 비교하지 않는다.
  2063. // 그래서 강제적으로 조건에 따라 null를 비교하도록 수정
  2064. if (floorId != null && zoneId == null) // 층처리 층이고 zone이 null인 즉 층전체포인트가 있으면
  2065. {
  2066. query = from x in db.BemsMonitoringPoint
  2067. //where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId != 0 && 2015 08 04 추가 ServiceType에 온도와 습도가 포함되면서 아래로 변경함.
  2068. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId != 0 && x.ServiceTypeId < 100 &&
  2069. x.BuildingId == buildingId && x.FloorId == floorId && x.ZoneId == null
  2070. select new MonitoringPointSType
  2071. {
  2072. SiteId = x.SiteId,
  2073. FacilityCode = x.FacilityCode,
  2074. PropertyId = x.PropertyId,
  2075. ServiceTypeId = (int)x.ServiceTypeId,
  2076. };
  2077. //throw new Exception(string.Format("case1"));
  2078. }
  2079. else if (floorId == null && zoneId == null) // 건물처리
  2080. {
  2081. query = from x in db.BemsMonitoringPoint
  2082. //where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId != 0 &&
  2083. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId != 0 && x.ServiceTypeId < 100 &&
  2084. x.BuildingId == buildingId && x.FloorId == null && x.ZoneId == null
  2085. select new MonitoringPointSType
  2086. {
  2087. SiteId = x.SiteId,
  2088. FacilityCode = x.FacilityCode,
  2089. PropertyId = x.PropertyId,
  2090. ServiceTypeId = (int)x.ServiceTypeId,
  2091. };
  2092. }
  2093. else // 구역처리
  2094. {
  2095. query = from x in db.BemsMonitoringPoint
  2096. //where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId != 0 &&
  2097. where x.SiteId == siteId && x.FuelTypeId == fuelTypeId && x.ServiceTypeId != 0 && x.ServiceTypeId < 100 &&
  2098. x.BuildingId == buildingId && x.FloorId == floorId && x.ZoneId == zoneId
  2099. select new MonitoringPointSType
  2100. {
  2101. SiteId = x.SiteId,
  2102. FacilityCode = x.FacilityCode,
  2103. PropertyId = x.PropertyId,
  2104. ServiceTypeId = (int)x.ServiceTypeId,
  2105. };
  2106. //throw new Exception(string.Format("case4"));
  2107. }
  2108. //int n = query.Count();
  2109. if (query.Any())
  2110. {
  2111. foreach (var data in query)
  2112. {
  2113. list.Add(data);
  2114. }
  2115. return; // 있으면 끝
  2116. }
  2117. }
  2118. {
  2119. if (floorId == null) //
  2120. {
  2121. var query = from x in db.CmFloor
  2122. where x.SiteId == siteId && x.BuildingId == buildingId
  2123. select x.FloorId;
  2124. foreach (var floor in query)
  2125. {
  2126. AddPointToListInLocationSType(list, siteId, fuelTypeId, buildingId, floor, null);
  2127. }
  2128. }
  2129. //else if( zoneId == null )
  2130. if (zoneId == null)
  2131. //else
  2132. {
  2133. var query = from x in db.CmZone
  2134. where x.SiteId == siteId && x.BuildingId == buildingId && x.FloorId == floorId
  2135. select x.ZoneId;
  2136. foreach (var zone in query)
  2137. {
  2138. AddPointToListInLocationSType(list, siteId, fuelTypeId, buildingId, floorId, zone);
  2139. }
  2140. }
  2141. }
  2142. }
  2143. //구역에 맵핑된 온도, 습도 포인트만 찾아낸다. // 한가지씩찾아서 평균으로 수정필요함
  2144. private void AddPointToListInLocation_ZoneTempHumi(List<MonitoringPoint> list,
  2145. int siteId, int buildingId, int? floorId, int? zoneId)
  2146. {
  2147. {
  2148. IQueryable<MonitoringPoint> query;
  2149. // floorId 나 zoneId 가 null를 가지고 있어도, 비교시에는 null로 비교하지 않는다.
  2150. // 그래서 강제적으로 조건에 따라 null를 비교하도록 수정
  2151. // x.FacilityTypeId 91, 92로 가려야 한다. 2015 08 03 hcLee -> x
  2152. {
  2153. query = from x in db.BemsMonitoringPoint
  2154. //where x.SiteId == siteId && (x.PropertyId == 1000 ||x.PropertyId == 1001) && 2015 08 04 hcLee 서비스타입으로 변경함.
  2155. //where x.SiteId == siteId && (x.ServiceTypeId == 100 || x.ServiceTypeId == 110) && // 2016 04 18 co2농도도 추가
  2156. where x.SiteId == siteId && (x.ServiceTypeId == 100 || x.ServiceTypeId == 110 || x.ServiceTypeId == 130) &&
  2157. x.BuildingId == buildingId && x.FloorId == floorId && x.ZoneId == zoneId
  2158. select new MonitoringPoint
  2159. {
  2160. SiteId = x.SiteId,
  2161. FacilityCode = x.FacilityCode,
  2162. PropertyId = x.PropertyId,
  2163. };
  2164. //throw new Exception(string.Format("case4"));
  2165. }
  2166. //int n = query.Count();
  2167. if (query.Any())
  2168. {
  2169. foreach (var data in query)
  2170. {
  2171. list.Add(data);
  2172. }
  2173. return; // 있으면 끝
  2174. }
  2175. }
  2176. }
  2177. //2016 05 25 hcLee
  2178. //층에 맵핑된 온도(100), 습도(110), CO2(130), CO(140) 포인트만 찾아낸다. 평면도 그리는 화면 에너지현황/실내온습도 상태감시 화면에서 사용
  2179. private void AddPointToListInLocation_FloorTempHumi(List<MonitoringPoint> list, int siteId, int buildingId, int? floorId)
  2180. {
  2181. {
  2182. IQueryable<MonitoringPoint> query;
  2183. {
  2184. query = from x in db.BemsMonitoringPoint
  2185. where x.SiteId == siteId && x.FacilityTypeId == 99 && (x.ServiceTypeId == 100 || x.ServiceTypeId == 110 || x.ServiceTypeId == 130 || x.ServiceTypeId == 140 || x.ServiceTypeId == 150 || x.ServiceTypeId == 160) &&
  2186. x.BuildingId == buildingId && x.FloorId == floorId orderby x.Name
  2187. select new MonitoringPoint
  2188. {
  2189. SiteId = x.SiteId,
  2190. FacilityCode = x.FacilityCode,
  2191. PropertyId = x.PropertyId,
  2192. };
  2193. //throw new Exception(string.Format("case4"));
  2194. }
  2195. //int n = query.Count();
  2196. if (query.Any())
  2197. {
  2198. foreach (var data in query)
  2199. {
  2200. list.Add(data);
  2201. }
  2202. return; // 있으면 끝
  2203. }
  2204. }
  2205. }
  2206. //2019 06 26 kgpark
  2207. //층에 맵핑된 온도(100), 습도(110), CO2(130), CO(140), 미세먼지(150), O3(160) 포인트만 찾아낸다. 평면도 그리는 화면 에너지현황/실내온습도 상태감시 화면에서 사용
  2208. private void AddEachPointToListInLocation_FloorTempHumi(List<MonitoringPoint> list, int siteId, int? floorId)
  2209. {
  2210. {
  2211. IQueryable<MonitoringPoint> query;
  2212. {
  2213. query = from x in db.BemsFloorStatus
  2214. where x.SiteId == siteId && x.FacilityTypeId == 99 && x.FloorId == floorId
  2215. select new MonitoringPoint
  2216. {
  2217. SiteId = x.SiteId,
  2218. FacilityCode = x.FacilityCode,
  2219. PropertyId = x.PropertyId,
  2220. };
  2221. //throw new Exception(string.Format("case4"));
  2222. }
  2223. //int n = query.Count();
  2224. if (query.Any())
  2225. {
  2226. foreach (var data in query)
  2227. {
  2228. list.Add(data);
  2229. }
  2230. return; // 있으면 끝
  2231. }
  2232. }
  2233. }
  2234. private void AddPointToList_RunTime(List<MonitoringPoint> list, int siteId, int facilityCode)
  2235. {
  2236. {
  2237. IQueryable<MonitoringPoint> query;
  2238. // floorId 나 zoneId 가 null를 가지고 있어도, 비교시에는 null로 비교하지 않는다.
  2239. // 그래서 강제적으로 조건에 따라 null를 비교하도록 수정
  2240. // x.FacilityTypeId 91, 92로 가려야 한다. 2015 08 03 hcLee -> x
  2241. {
  2242. query = from x in db.BemsMonitoringPoint
  2243. //where x.SiteId == siteId && (x.PropertyId == 1000 ||x.PropertyId == 1001) && 2015 08 04 hcLee 서비스타입으로 변경함.
  2244. where x.SiteId == siteId && x.ServiceTypeId == 120 && x.FacilityCode == facilityCode
  2245. select new MonitoringPoint
  2246. {
  2247. SiteId = x.SiteId,
  2248. FacilityCode = x.FacilityCode,
  2249. PropertyId = x.PropertyId,
  2250. };
  2251. //throw new Exception(string.Format("case4"));
  2252. }
  2253. //int n = query.Count();
  2254. if (query.Any())
  2255. {
  2256. foreach (var data in query)
  2257. {
  2258. list.Add(data);
  2259. }
  2260. return; // 있으면 끝
  2261. }
  2262. }
  2263. }
  2264. private void AddPointToList_Runtime_REFRIGERATOR(List<MonitoringPoint> list, int siteId)
  2265. {
  2266. {
  2267. IQueryable<MonitoringPoint> query;
  2268. {
  2269. query = from x in db.BemsMonitoringPoint
  2270. where x.SiteId == siteId && x.FacilityTypeId == 2 && x.PropertyId == 17
  2271. select new MonitoringPoint
  2272. {
  2273. SiteId = x.SiteId,
  2274. FacilityCode = x.FacilityCode,
  2275. PropertyId = x.PropertyId,
  2276. };
  2277. //throw new Exception(string.Format("case4"));
  2278. }
  2279. //int n = query.Count();
  2280. if (query.Any())
  2281. {
  2282. foreach (var data in query)
  2283. {
  2284. list.Add(data);
  2285. }
  2286. return; // 있으면 끝
  2287. }
  2288. }
  2289. }
  2290. private void AddPointToList_Runtime_BOILER(List<MonitoringPoint> list, int siteId)
  2291. {
  2292. {
  2293. IQueryable<MonitoringPoint> query;
  2294. {
  2295. query = from x in db.BemsMonitoringPoint
  2296. where x.SiteId == siteId && ((x.FacilityTypeId == 8 && x.PropertyId == 9) || (x.FacilityTypeId == 14 && x.PropertyId == 7))
  2297. select new MonitoringPoint
  2298. {
  2299. SiteId = x.SiteId,
  2300. FacilityCode = x.FacilityCode,
  2301. PropertyId = x.PropertyId,
  2302. };
  2303. //throw new Exception(string.Format("case4"));
  2304. }
  2305. //int n = query.Count();
  2306. if (query.Any())
  2307. {
  2308. foreach (var data in query)
  2309. {
  2310. list.Add(data);
  2311. }
  2312. return; // 있으면 끝
  2313. }
  2314. }
  2315. }
  2316. private void AddPointToList_ControlPoint(List<MonitoringPoint> list, int siteId, int ValueType)
  2317. {
  2318. {
  2319. IQueryable<MonitoringPoint> query;
  2320. {
  2321. query = from x in db.BemsMonitoringPoint
  2322. //2016 01 18
  2323. //where x.SiteId == siteId && x.ValueType == ValueType
  2324. where x.SiteId == siteId && (x.ValueType == 1 || x.ValueType == 3)
  2325. select new MonitoringPoint
  2326. {
  2327. SiteId = x.SiteId,
  2328. FacilityCode = x.FacilityCode,
  2329. PropertyId = x.PropertyId,
  2330. };
  2331. //throw new Exception(string.Format("case4"));
  2332. }
  2333. //int n = query.Count();
  2334. if (query.Any())
  2335. {
  2336. foreach (var data in query)
  2337. {
  2338. list.Add(data);
  2339. }
  2340. return; // 있으면 끝
  2341. }
  2342. }
  2343. }
  2344. //2019.05.****************
  2345. private void AddPointToList_ControlPoint2(List<MonitoringPoint> list, int siteId, int propertyId, int facilityTypeId, int facilitycode)
  2346. {
  2347. {
  2348. IQueryable<MonitoringPoint> query;
  2349. {
  2350. query = from x in db.BemsMonitoringPoint
  2351. where x.SiteId == siteId && x.PropertyId == propertyId && x.FacilityTypeId == facilityTypeId && x.FacilityCode == facilitycode
  2352. select new MonitoringPoint
  2353. {
  2354. SiteId = x.SiteId,
  2355. FacilityCode = x.FacilityCode,
  2356. PropertyId = x.PropertyId,
  2357. };
  2358. //throw new Exception(string.Format("case4"));
  2359. }
  2360. //int n = query.Count();
  2361. if (query.Any())
  2362. {
  2363. foreach (var data in query)
  2364. {
  2365. list.Add(data);
  2366. }
  2367. return; // 있으면 끝
  2368. }
  2369. }
  2370. }
  2371. //*******************2019.05.
  2372. /*
  2373. [ActionName("ServiceType")]
  2374. public CalculationValue[] GetBemsMonitoringPointHistoryServiceType()
  2375. {
  2376. Uri uri = Request.RequestUri;
  2377. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  2378. string uriTimeIntervalType = uriQuery.Get("TimeIntervalType");
  2379. string uriStartDate = uriQuery.Get("StartDate");
  2380. string uriEndDate = uriQuery.Get("EndDate");
  2381. int siteId;
  2382. int buildingId, floorId, zoneId, fuelTypeId, timeInterval = -1;
  2383. buildingId = 1;
  2384. DateTime startDate, endDate;
  2385. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  2386. // int.TryParse(uriQuery.Get("BuildingId"), out buildingId) == false ||
  2387. int.TryParse(uriTimeIntervalType, out timeInterval) == false ||
  2388. DateTime.TryParse(uriStartDate, out startDate) == false ||
  2389. DateTime.TryParse(uriEndDate, out endDate) == false ||
  2390. int.TryParse(uriQuery.Get("FuelTypeId"), out fuelTypeId) == false)
  2391. {
  2392. throw new Exception(string.Format("Not Found Parameters: {0},{1},{2}",
  2393. uriTimeIntervalType, uriStartDate, uriEndDate));
  2394. }
  2395. TimeInterval timeIntervalType = (TimeInterval)timeInterval;
  2396. int? nullableFloorId = null;
  2397. int? nullableZoneId = null;
  2398. if (int.TryParse(uriQuery.Get("FloorId"), out floorId))
  2399. {
  2400. nullableFloorId = floorId;
  2401. if (int.TryParse(uriQuery.Get("ZoneId"), out zoneId))
  2402. {
  2403. nullableZoneId = zoneId;
  2404. }
  2405. }
  2406. List<MonitoringPoint> list = new List<MonitoringPoint>();
  2407. try
  2408. {
  2409. AddPointToListInLocation(list, siteId, fuelTypeId, buildingId, nullableFloorId, nullableZoneId);
  2410. var values = CreateCalculationValues(startDate, endDate, timeIntervalType);
  2411. foreach (var point in list)
  2412. {
  2413. var pointValues = pointHistoryValueManager.GetPointValues(
  2414. siteId, point.FacilityCode, point.PropertyId,
  2415. timeIntervalType, startDate, endDate);
  2416. if (pointValues == null)
  2417. continue;
  2418. int index = 0;
  2419. CalculationValue p = null;
  2420. CalculationValue v = null;
  2421. for (var i = 0; i < values.Length; i++)
  2422. {
  2423. v = values[i];
  2424. if (p == null)
  2425. {
  2426. if (pointValues.Length <= index) break;
  2427. p = pointValues[index];
  2428. }
  2429. if (p.DateTime == v.DateTime)
  2430. {
  2431. v.Value += p.Value;
  2432. p = null;
  2433. index++;
  2434. if (pointValues.Length <= index) break;
  2435. }
  2436. }
  2437. }
  2438. return values;
  2439. }
  2440. catch (Exception)
  2441. {
  2442. throw;
  2443. }
  2444. }
  2445. */
  2446. }
  2447. // hcLee 2015 03 30
  2448. /*
  2449. public class Building
  2450. {
  2451. public int SiteId { get; set; }
  2452. public int BuildingId { get; set; }
  2453. public int Name { get; set; }
  2454. }; */
  2455. public class MonitoringPoint
  2456. {
  2457. public int SiteId { get; set; }
  2458. public int FacilityCode { get; set; }
  2459. public int PropertyId { get; set; }
  2460. };
  2461. // hcLee 2015 03 31
  2462. public class MonitoringPointSType
  2463. {
  2464. public int SiteId { get; set; }
  2465. public int FacilityCode { get; set; }
  2466. public int PropertyId { get; set; }
  2467. public int ServiceTypeId { get; set; }
  2468. public int FuelTypeId { get; set; } // 2016 09 18 hcLee 추가
  2469. };
  2470. public class PointToLocation
  2471. {
  2472. public int SiteId { get; set; }
  2473. public int FacilityCode { get; set; }
  2474. public int PropertyId { get; set; }
  2475. public int? BuildingId { get; set; }
  2476. public int? FloorId { get; set; }
  2477. public int? ZoneId { get; set; }
  2478. };
  2479. /*
  2480. //hcLee 2015 07 16
  2481. public class ZoneTempHumiData
  2482. {
  2483. public int SiteId { get; set; }
  2484. public int? BuildingId { get; set; }
  2485. public int? FloorId { get; set; }
  2486. public int? ZoneId { get; set; }
  2487. };
  2488. */
  2489. public class GetCenterSiteData_Param
  2490. {
  2491. public int TimeIntervalType { get; set; }
  2492. public DateTime startDate { get; set; }
  2493. public DateTime endDate { get; set; }
  2494. //public Nullable<int> FacilityCode { get; set; }
  2495. //public int FacilityCode { get; set; }
  2496. };
  2497. public class GetPrediction_Param
  2498. {
  2499. public int SiteId { get; set; }
  2500. public int BuildingId { get; set; }
  2501. public int FuelType { get; set; }
  2502. public DateTime startDate { get; set; }
  2503. public DateTime endDate{ get; set; }
  2504. //public Nullable<int> FacilityCode { get; set; }
  2505. //public int FacilityCode { get; set; }
  2506. };
  2507. // jhLee 2016-04-22
  2508. public class FacilityCostInfo
  2509. {
  2510. public int SiteId { get; set; }
  2511. public int FacilityCode { get; set; }
  2512. public string RatedPowerConsumption { get; set; }
  2513. public Nullable<short> FuelTypeId { get; set; }
  2514. public Nullable<short> ContractType { get; set; }
  2515. };
  2516. //2016 07 01 hcLee
  2517. public class CenterSiteData
  2518. {
  2519. public int siteid { get; set; }
  2520. public string name { get; set; }
  2521. public List<CalculationResult> e_value_list { get; set; } // 오늘 전기
  2522. public List<CalculationResult> g_value_list { get; set; } // 오늘 가스
  2523. public Nullable<double> elec_current { get; set; } // 현재전기사용량
  2524. public Nullable<double> elec_target { get; set; } // 현재전기목표
  2525. public Nullable<double> gas_current { get; set; } // 현재가스사용량
  2526. public Nullable<double> gas_target { get; set; } // 현재가스목표
  2527. //public Nullable<double> kcal_target { get; set; } // 현재기준목표 kcal(전기+가스)
  2528. };
  2529. }