YtiotVDataServiceImpl.java 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269
  1. package cn.com.usky.iot.data.service;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Map;
  8. import cn.com.usky.iot.admin.dao.YtiotTAdminDao;
  9. import cn.com.usky.iot.admin.dao.YtiotVUserCompanyDao;
  10. import cn.com.usky.iot.alarm.dao.YtiotVAlarmDao;
  11. import cn.com.usky.iot.company.dao.YtiotVCompanyDao;
  12. import cn.com.usky.iot.data.dao.YtiotVDataDao;
  13. import cn.com.usky.iot.entity.YtiotTAdmin;
  14. import cn.com.usky.iot.entity.YtiotTArea;
  15. import cn.com.usky.iot.entity.YtiotVCompany;
  16. import cn.com.usky.iot.entity.YtiotVCompanyId;
  17. import cn.com.usky.iot.entity.YtiotVHj;
  18. import cn.com.usky.iot.entity.YtiotVHjId;
  19. import cn.com.usky.iot.entity.YtiotVRtu;
  20. import cn.com.usky.iot.entity.YtiotVRtuId;
  21. import cn.com.usky.iot.entity.YtiotVSj;
  22. import cn.com.usky.iot.entity.YtiotVSjId;
  23. import cn.com.usky.iot.entity.YtiotVSync;
  24. import cn.com.usky.iot.entity.YtiotVSyncData;
  25. import cn.com.usky.iot.entity.YtiotVSyncDataId;
  26. import cn.com.usky.iot.entity.YtiotVSyncId;
  27. import cn.com.usky.iot.entity.YtiotVSyncStatus;
  28. import cn.com.usky.iot.entity.YtiotVSyncStatusId;
  29. import cn.com.usky.iot.entity.YtiotVUsercompany;
  30. import cn.com.usky.iot.entity.YtiotVUsercompanyId;
  31. import cn.com.usky.utils.MD5Util;
  32. import net.sf.json.JSONArray;
  33. import net.sf.json.JSONObject;
  34. import java.util.Calendar;
  35. public class YtiotVDataServiceImpl implements YtiotVDataService {
  36. private YtiotVDataDao ytiotVDataDao;
  37. private YtiotVCompanyDao ytiotVCompanyDao;
  38. private YtiotVUserCompanyDao ytiotVUserCompanyDao;
  39. private YtiotVAlarmDao ytiotVAlarmDao;
  40. private YtiotTAdminDao ytiotTAdminDao;
  41. public YtiotVDataDao getYtiotVDataDao() {
  42. return ytiotVDataDao;
  43. }
  44. public void setYtiotVDataDao(YtiotVDataDao ytiotVDataDao) {
  45. this.ytiotVDataDao = ytiotVDataDao;
  46. }
  47. public YtiotVCompanyDao getYtiotVCompanyDao() {
  48. return ytiotVCompanyDao;
  49. }
  50. public void setYtiotVCompanyDao(YtiotVCompanyDao ytiotVCompanyDao) {
  51. this.ytiotVCompanyDao = ytiotVCompanyDao;
  52. }
  53. public YtiotVUserCompanyDao getYtiotVUserCompanyDao() {
  54. return ytiotVUserCompanyDao;
  55. }
  56. public void setYtiotVUserCompanyDao(YtiotVUserCompanyDao ytiotVUserCompanyDao) {
  57. this.ytiotVUserCompanyDao = ytiotVUserCompanyDao;
  58. }
  59. public YtiotTAdminDao getYtiotTAdminDao() {
  60. return ytiotTAdminDao;
  61. }
  62. public void setYtiotTAdminDao(YtiotTAdminDao ytiotTAdminDao) {
  63. this.ytiotTAdminDao = ytiotTAdminDao;
  64. }
  65. public YtiotVAlarmDao getYtiotVAlarmDao() {
  66. return ytiotVAlarmDao;
  67. }
  68. public void setYtiotVAlarmDao(YtiotVAlarmDao ytiotVAlarmDao) {
  69. this.ytiotVAlarmDao = ytiotVAlarmDao;
  70. }
  71. public boolean chk_string_param(String param) {
  72. if(param==null)
  73. return true;
  74. if(param.indexOf("=")>=0)
  75. return false;
  76. if(param.indexOf("\'")>=0)
  77. return false;
  78. if(param.indexOf("\"")>=0)
  79. return false;
  80. return true;
  81. }
  82. public String chkhw(String hqlwhere){
  83. if(hqlwhere==null)
  84. return " where ";
  85. else
  86. return hqlwhere+" and ";
  87. }
  88. public String fieldname(String name) {
  89. if(name.equals("company_code"))
  90. return "companyCode";
  91. if(name.equals("device_id"))
  92. return "deviceId";
  93. if(name.equals("device_name"))
  94. return "deviceName";
  95. if(name.equals("install_time"))
  96. return "installTime";
  97. if(name.equals("sync_id"))
  98. return "syncId";
  99. if(name.equals("table_name"))
  100. return "tableName";
  101. if(name.equals("data_time"))
  102. return "dataTime";
  103. if(name.equals("native_id"))
  104. return "nativeId";
  105. if(name.equals("point_code"))
  106. return "pointCode";
  107. if(name.equals("point_data"))
  108. return "pointData";
  109. if(name.equals("owner_name"))
  110. return "ownerName";
  111. if(name.equals("owner_id"))
  112. return "ownerId";
  113. return name;
  114. }
  115. @Override
  116. public String getSyncPointVList(String queryJson, String page, String start, String limit, String sort)
  117. throws Exception {
  118. // TODO Auto-generated method stub
  119. String company_code = null;
  120. String company_code_list = null;
  121. String device_id = null;
  122. String device_id_list = null;
  123. String device_name = null;
  124. String dwtype = null;
  125. String dwtype_list = null;
  126. String id = null;
  127. String id_list = null;
  128. String install_time_start = null;
  129. String install_time_end = null;
  130. String Company_Code_List = null;
  131. String V_LOGINNAME = null;
  132. String unitinfo = null;
  133. String hqlwhere = null;
  134. String order = null;
  135. String dir = null;
  136. String Start = null;
  137. String Limit = null;
  138. String Page = null;
  139. String order_str = null;
  140. JSONObject q_json = null;
  141. JSONArray Sort = null;
  142. JSONArray jSONArray = new JSONArray();
  143. JSONObject json = new JSONObject();
  144. json.put("action", "getSyncPointVList");
  145. if(queryJson!=null) {
  146. q_json = JSONObject.fromObject(queryJson);
  147. if(q_json.has("company_code")) {
  148. if(q_json.getJSONObject("company_code").isArray()) {
  149. JSONArray j_tmp = q_json.getJSONArray("company_code");
  150. for(int i=0;i<j_tmp.size();i++) {
  151. if(i==0)
  152. company_code_list = j_tmp.getString(i);
  153. else
  154. company_code_list += ","+j_tmp.getString(i);
  155. }
  156. }else
  157. company_code = q_json.getString("company_code");
  158. }
  159. if(q_json.has("device_id")) {
  160. if(q_json.getJSONObject("device_id").isArray()) {
  161. JSONArray j_tmp = q_json.getJSONArray("device_id");
  162. for(int i=0;i<j_tmp.size();i++) {
  163. if(i==0)
  164. device_id_list = j_tmp.getString(i);
  165. else
  166. device_id_list += ","+j_tmp.getString(i);
  167. }
  168. }else
  169. device_id = q_json.getString("device_id");
  170. }
  171. device_name = q_json.has("device_name")?q_json.getString("device_name"):null;
  172. if(q_json.has("dwtype")) {
  173. if(q_json.getJSONObject("dwtype").isArray()) {
  174. JSONArray j_tmp = q_json.getJSONArray("dwtype");
  175. for(int i=0;i<j_tmp.size();i++) {
  176. if(i==0)
  177. dwtype_list = j_tmp.getString(i);
  178. else
  179. dwtype_list += ","+j_tmp.getString(i);
  180. }
  181. }else
  182. dwtype = q_json.getString("dwtype");
  183. }
  184. if(q_json.has("id")) {
  185. if(q_json.getJSONObject("id").isArray()) {
  186. JSONArray j_tmp = q_json.getJSONArray("id");
  187. for(int i=0;i<j_tmp.size();i++) {
  188. if(i==0)
  189. id_list = j_tmp.getString(i);
  190. else
  191. id_list += ","+j_tmp.getString(i);
  192. }
  193. }else
  194. id = q_json.getString("id");
  195. }
  196. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  197. unitinfo = q_json.has("unitinfo")?q_json.getString("unitinfo"):null;
  198. install_time_start = q_json.has("install_time_start")?q_json.getString("install_time_start"):null;
  199. install_time_end = q_json.has("install_time_end")?q_json.getString("install_time_end"):null;
  200. }
  201. if(sort!=null) {
  202. Sort = JSONArray.fromObject(sort);
  203. if((Sort.isArray())&&(Sort.size()>0)) {
  204. JSONObject s_json = Sort.getJSONObject(0);
  205. order = s_json.has("property")?s_json.getString("property"):order;
  206. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  207. }
  208. json.put("sort", sort);
  209. }
  210. Start = start;
  211. Limit = limit;
  212. Page = page;
  213. if(V_LOGINNAME!=null) {
  214. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  215. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  216. if(list.size()>0) {
  217. for(int i=0;i<list.size();i++) {
  218. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  219. YtiotVUsercompanyId oid = o.getId();
  220. if(i==0)
  221. Company_Code_List = oid.getOwnerCode();
  222. else
  223. Company_Code_List += ","+oid.getOwnerCode();
  224. }
  225. }
  226. }
  227. if(Company_Code_List!=null)
  228. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  229. else {
  230. if(company_code!=null)
  231. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  232. if(company_code_list!=null)
  233. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  234. }
  235. if(device_id!=null)
  236. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_id")+" like '%"+device_id+"%' ";
  237. if(device_id_list!=null)
  238. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_id")+" in ("+device_id_list+") ";
  239. if(device_name!=null)
  240. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_name")+" like '%"+device_name+"%' ";
  241. if(dwtype!=null)
  242. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  243. if(dwtype_list!=null)
  244. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  245. if(id!=null)
  246. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("id")+" = "+id+" ";
  247. if(id_list!=null)
  248. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("id")+" in ("+id_list+") ";
  249. if(install_time_start!=null)
  250. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("install_time")+" >='"+install_time_start+"' ";
  251. if(install_time_end!=null)
  252. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("install_time")+" <='"+install_time_end+"' ";
  253. if(unitinfo!=null)
  254. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("unitinfo")+" like '%"+unitinfo+"%' ";
  255. int totalCount = ytiotVDataDao.getSyncPointCount(hqlwhere);
  256. json.put("totalCount", totalCount);
  257. if(Start!=null){
  258. if(Integer.parseInt(Start)>totalCount){
  259. Start = "0";
  260. Page = "0";
  261. }else if(page==null)
  262. Page="0";
  263. }else{
  264. Start = "0";
  265. Page = "0";
  266. }
  267. json.put("page", Page);
  268. json.put("start", Start);
  269. json.put("limit", Limit);
  270. if(totalCount>0) {
  271. List<?> list = ytiotVDataDao.SyncPointQuery(hqlwhere, order_str, dir, Start, Limit);
  272. if(list.size()>0) {
  273. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  274. for(int i=0;i<list.size();i++) {
  275. YtiotVSync o = (YtiotVSync)list.get(i);
  276. YtiotVSyncId oid = o.getId();
  277. @SuppressWarnings("rawtypes")
  278. Map<String, Comparable> map = new HashMap<String, Comparable>();
  279. map.put("company_code", oid.getCompanyCode());
  280. map.put("device_id", oid.getDeviceId());
  281. map.put("device_name", oid.getDeviceName());
  282. map.put("dwtype", oid.getDwtype());
  283. map.put("id", oid.getId());
  284. map.put("install_time", df.format(oid.getInstallTime()));
  285. map.put("rtmp", oid.getRtmp());
  286. map.put("sync_id", oid.getSyncId());
  287. map.put("tablename", oid.getTableName());
  288. map.put("unitinfo", oid.getUnitinfo());
  289. JSONObject jSONObject = JSONObject.fromObject(map);
  290. jSONArray.add(jSONObject);
  291. }
  292. json.put("RESULT", jSONArray);
  293. }
  294. }
  295. return json.toString();
  296. }
  297. @Override
  298. public String getSyncDataList(String queryJson)
  299. throws Exception {
  300. // TODO Auto-generated method stub
  301. String company_code = null;
  302. String company_code_list = null;
  303. String device_id = null;
  304. String device_id_list = null;
  305. String dwtype = null;
  306. String dwtype_list = null;
  307. String point_code = null;
  308. String point_code_list = null;
  309. String id = null;
  310. String id_list = null;
  311. String company = null;
  312. String data_time_start = null;
  313. String data_time_end = null;
  314. String name = null;
  315. String Company_Code_List = null;
  316. String V_LOGINNAME = null;
  317. String hqlwhere = null;
  318. String order = null;
  319. String dir = null;
  320. String Start = null;
  321. String Limit = null;
  322. String Page = null;
  323. String order_str = null;
  324. JSONObject q_json = null;
  325. JSONArray Sort = null;
  326. JSONArray jSONArray = new JSONArray();
  327. JSONObject json = new JSONObject();
  328. json.put("action", "getSyncDataVList");
  329. if(queryJson!=null) {
  330. q_json = JSONObject.fromObject(queryJson);
  331. if(q_json.has("company_code")) {
  332. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  333. JSONArray j_tmp = q_json.getJSONArray("company_code");
  334. for(int i=0;i<j_tmp.size();i++) {
  335. if(i==0)
  336. company_code_list = j_tmp.getString(i);
  337. else
  338. company_code_list += ","+j_tmp.getString(i);
  339. }
  340. }else
  341. company_code = q_json.getString("company_code");
  342. }
  343. if(q_json.has("device_id")) {
  344. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  345. JSONArray j_tmp = q_json.getJSONArray("device_id");
  346. for(int i=0;i<j_tmp.size();i++) {
  347. if(i==0)
  348. device_id_list = j_tmp.getString(i);
  349. else
  350. device_id_list += ","+j_tmp.getString(i);
  351. }
  352. }else
  353. device_id = q_json.getString("device_id");
  354. }
  355. if(q_json.has("dwtype")) {
  356. if((q_json.optJSONObject("dwtype")!=null)&&(q_json.optJSONObject("dwtype").isArray())) {
  357. JSONArray j_tmp = q_json.getJSONArray("dwtype");
  358. for(int i=0;i<j_tmp.size();i++) {
  359. if(i==0)
  360. dwtype_list = j_tmp.getString(i);
  361. else
  362. dwtype_list += ","+j_tmp.getString(i);
  363. }
  364. }else
  365. dwtype = q_json.getString("dwtype");
  366. }
  367. if(q_json.has("point_code")) {
  368. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  369. JSONArray j_tmp = q_json.getJSONArray("point_code");
  370. for(int i=0;i<j_tmp.size();i++) {
  371. if(i==0)
  372. point_code_list = j_tmp.getString(i);
  373. else
  374. point_code_list += ","+j_tmp.getString(i);
  375. }
  376. }else
  377. point_code = q_json.getString("point_code");
  378. }
  379. if(q_json.has("id")) {
  380. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  381. JSONArray j_tmp = q_json.getJSONArray("id");
  382. for(int i=0;i<j_tmp.size();i++) {
  383. if(i==0)
  384. id_list = j_tmp.getString(i);
  385. else
  386. id_list += ","+j_tmp.getString(i);
  387. }
  388. }else
  389. id = q_json.getString("id");
  390. }
  391. company = q_json.has("company")?q_json.getString("company"):null;
  392. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  393. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  394. name = q_json.has("name")?q_json.getString("name"):null;
  395. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  396. }
  397. // if(sort!=null) {
  398. // Sort = JSONArray.fromObject(sort);
  399. // if((Sort.isArray())&&(Sort.size()>0)) {
  400. // JSONObject s_json = Sort.getJSONObject(0);
  401. // order = s_json.has("property")?s_json.getString("property"):order;
  402. // dir = s_json.has("direction")?s_json.getString("direction"):dir;
  403. // }
  404. // json.put("sort", sort);
  405. // }
  406. // Start = start;
  407. // Limit = limit;
  408. // Page = page;
  409. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  410. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  411. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  412. if(list.size()>0) {
  413. for(int i=0;i<list.size();i++) {
  414. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  415. YtiotVUsercompanyId oid = o.getId();
  416. if(i==0)
  417. Company_Code_List = oid.getOwnerCode();
  418. else
  419. Company_Code_List += ","+oid.getOwnerCode();
  420. }
  421. }
  422. }
  423. if(device_id!=null)
  424. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  425. else {
  426. if(company!=null) {
  427. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  428. }
  429. if(Company_Code_List!=null)
  430. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  431. else {
  432. if(company_code!=null)
  433. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  434. if(company_code_list!=null)
  435. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  436. }
  437. }
  438. if(device_id_list!=null)
  439. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  440. if(dwtype!=null)
  441. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  442. if(dwtype_list!=null)
  443. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  444. if(point_code!=null)
  445. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  446. if(point_code_list!=null)
  447. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  448. if(id!=null)
  449. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  450. if(id_list!=null)
  451. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  452. if(data_time_start!=null)
  453. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  454. if(data_time_end!=null)
  455. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  456. if(name!=null)
  457. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  458. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  459. json.put("totalCount", totalCount);
  460. if(order!=null) {
  461. order_str = " order by "+fieldname(order)+" ";
  462. } else {
  463. order_str = " order by data_time ";
  464. dir = "DESC";
  465. }
  466. if(totalCount>0) {
  467. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  468. if(list.size()>0) {
  469. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  470. for(int i=0;i<list.size();i++) {
  471. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  472. YtiotVSyncDataId oid = o.getId();
  473. @SuppressWarnings("rawtypes")
  474. Map<String, Comparable> map = new HashMap<String, Comparable>();
  475. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  476. map.put("company", oid.getCompany());
  477. map.put("company_code", oid.getCompanyCode());
  478. map.put("content", oid.getContent());
  479. map.put("data_time", df.format(oid.getDataTime()));
  480. map.put("device_id", oid.getDeviceId());
  481. map.put("dwtype", oid.getDwtype());
  482. map.put("id", oid.getId());
  483. map.put("name", oid.getName());
  484. map.put("native_id", oid.getNativeId());
  485. map.put("point_code", oid.getPointCode());
  486. map.put("point_data", oid.getPointData());
  487. JSONObject jSONObject = JSONObject.fromObject(map);
  488. jSONArray.add(jSONObject);
  489. }
  490. json.put("RESULT", jSONArray);
  491. }
  492. }
  493. return json.toString();
  494. }
  495. @Override
  496. public String getSyncDataVList(String queryJson, String page, String start, String limit, String sort)
  497. throws Exception {
  498. // TODO Auto-generated method stub
  499. String company_code = null;
  500. String company_code_list = null;
  501. String device_id = null;
  502. String device_id_list = null;
  503. String dwtype = null;
  504. String dwtype_list = null;
  505. String point_code = null;
  506. String point_code_list = null;
  507. String id = null;
  508. String id_list = null;
  509. String company = null;
  510. String data_time_start = null;
  511. String data_time_end = null;
  512. String name = null;
  513. String Company_Code_List = null;
  514. String V_LOGINNAME = null;
  515. String hqlwhere = null;
  516. String order = null;
  517. String dir = null;
  518. String Start = null;
  519. String Limit = null;
  520. String Page = null;
  521. String order_str = null;
  522. JSONObject q_json = null;
  523. JSONArray Sort = null;
  524. JSONArray jSONArray = new JSONArray();
  525. JSONObject json = new JSONObject();
  526. json.put("action", "getSyncDataVList");
  527. if(queryJson!=null) {
  528. q_json = JSONObject.fromObject(queryJson);
  529. if(q_json.has("company_code")) {
  530. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  531. JSONArray j_tmp = q_json.getJSONArray("company_code");
  532. for(int i=0;i<j_tmp.size();i++) {
  533. if(i==0)
  534. company_code_list = j_tmp.getString(i);
  535. else
  536. company_code_list += ","+j_tmp.getString(i);
  537. }
  538. }else
  539. company_code = q_json.getString("company_code");
  540. }
  541. if(q_json.has("device_id")) {
  542. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  543. JSONArray j_tmp = q_json.getJSONArray("device_id");
  544. for(int i=0;i<j_tmp.size();i++) {
  545. if(i==0)
  546. device_id_list = j_tmp.getString(i);
  547. else
  548. device_id_list += ","+j_tmp.getString(i);
  549. }
  550. }else
  551. device_id = q_json.getString("device_id");
  552. }
  553. if(q_json.has("dwtype")) {
  554. if((q_json.optJSONObject("dwtype")!=null)&&(q_json.optJSONObject("dwtype").isArray())) {
  555. JSONArray j_tmp = q_json.getJSONArray("dwtype");
  556. for(int i=0;i<j_tmp.size();i++) {
  557. if(i==0)
  558. dwtype_list = j_tmp.getString(i);
  559. else
  560. dwtype_list += ","+j_tmp.getString(i);
  561. }
  562. }else
  563. dwtype = q_json.getString("dwtype");
  564. }
  565. if(q_json.has("point_code")) {
  566. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  567. JSONArray j_tmp = q_json.getJSONArray("point_code");
  568. for(int i=0;i<j_tmp.size();i++) {
  569. if(i==0)
  570. point_code_list = j_tmp.getString(i);
  571. else
  572. point_code_list += ","+j_tmp.getString(i);
  573. }
  574. }else
  575. point_code = q_json.getString("point_code");
  576. }
  577. if(q_json.has("id")) {
  578. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  579. JSONArray j_tmp = q_json.getJSONArray("id");
  580. for(int i=0;i<j_tmp.size();i++) {
  581. if(i==0)
  582. id_list = j_tmp.getString(i);
  583. else
  584. id_list += ","+j_tmp.getString(i);
  585. }
  586. }else
  587. id = q_json.getString("id");
  588. }
  589. company = q_json.has("company")?q_json.getString("company"):null;
  590. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  591. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  592. name = q_json.has("name")?q_json.getString("name"):null;
  593. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  594. }
  595. if(sort!=null) {
  596. Sort = JSONArray.fromObject(sort);
  597. if((Sort.isArray())&&(Sort.size()>0)) {
  598. JSONObject s_json = Sort.getJSONObject(0);
  599. order = s_json.has("property")?s_json.getString("property"):order;
  600. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  601. }
  602. json.put("sort", sort);
  603. }
  604. Start = start;
  605. Limit = limit;
  606. Page = page;
  607. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  608. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  609. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  610. if(list.size()>0) {
  611. for(int i=0;i<list.size();i++) {
  612. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  613. YtiotVUsercompanyId oid = o.getId();
  614. if(i==0)
  615. Company_Code_List = oid.getOwnerCode();
  616. else
  617. Company_Code_List += ","+oid.getOwnerCode();
  618. }
  619. }
  620. }
  621. if(device_id!=null)
  622. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  623. else {
  624. if(company!=null) {
  625. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  626. }
  627. if(Company_Code_List!=null)
  628. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  629. else {
  630. if(company_code!=null)
  631. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  632. if(company_code_list!=null)
  633. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  634. }
  635. }
  636. if(device_id_list!=null)
  637. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  638. if(dwtype!=null)
  639. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  640. if(dwtype_list!=null)
  641. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  642. if(point_code!=null)
  643. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  644. if(point_code_list!=null)
  645. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  646. if(id!=null)
  647. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  648. if(id_list!=null)
  649. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  650. if(data_time_start!=null)
  651. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  652. if(data_time_end!=null)
  653. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  654. if(name!=null)
  655. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  656. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  657. json.put("totalCount", totalCount);
  658. if(Start!=null){
  659. if(Integer.parseInt(Start)>totalCount){
  660. Start = "0";
  661. Page = "0";
  662. }else if(page==null)
  663. Page="0";
  664. }else{
  665. Start = "0";
  666. Page = "0";
  667. }
  668. json.put("page", Page);
  669. json.put("start", Start);
  670. json.put("limit", Limit);
  671. if(order!=null) {
  672. order_str = " order by "+fieldname(order)+" ";
  673. } else {
  674. order_str = " order by data_time ";
  675. dir = "DESC";
  676. }
  677. if(totalCount>0) {
  678. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  679. if(list.size()>0) {
  680. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  681. for(int i=0;i<list.size();i++) {
  682. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  683. YtiotVSyncDataId oid = o.getId();
  684. @SuppressWarnings("rawtypes")
  685. Map<String, Comparable> map = new HashMap<String, Comparable>();
  686. map.put("company", oid.getCompany());
  687. map.put("company_code", oid.getCompanyCode());
  688. map.put("content", oid.getContent());
  689. map.put("data_time", df.format(oid.getDataTime()));
  690. map.put("device_id", oid.getDeviceId());
  691. map.put("dwtype", oid.getDwtype());
  692. map.put("id", oid.getId());
  693. map.put("name", oid.getName());
  694. map.put("native_id", oid.getNativeId());
  695. map.put("point_code", oid.getPointCode());
  696. map.put("point_data", oid.getPointData());
  697. JSONObject jSONObject = JSONObject.fromObject(map);
  698. jSONArray.add(jSONObject);
  699. }
  700. json.put("RESULT", jSONArray);
  701. }
  702. }
  703. return json.toString();
  704. }
  705. @Override
  706. public String getSyncDataQList(String queryJson, String page, String start, String limit, String sort)
  707. throws Exception {
  708. // TODO Auto-generated method stub
  709. String company_code = null;
  710. String company_code_list = null;
  711. String device_id = null;
  712. String device_id_list = null;
  713. String dwtype = null;
  714. String dwtype_list = null;
  715. String point_code = null;
  716. String point_code_list = null;
  717. String id = null;
  718. String id_list = null;
  719. String company = null;
  720. String data_time_start = null;
  721. String data_time_end = null;
  722. String name = null;
  723. String Company_Code_List = null;
  724. String V_LOGINNAME = null;
  725. String hqlwhere = null;
  726. String order = null;
  727. String dir = null;
  728. String Start = null;
  729. String Limit = null;
  730. String Page = null;
  731. String order_str = null;
  732. JSONObject q_json = null;
  733. JSONArray Sort = null;
  734. JSONArray jSONArray = new JSONArray();
  735. JSONObject json = new JSONObject();
  736. json.put("action", "getSyncDataVList");
  737. if(queryJson!=null) {
  738. q_json = JSONObject.fromObject(queryJson);
  739. if(q_json.has("company_code")) {
  740. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  741. JSONArray j_tmp = q_json.getJSONArray("company_code");
  742. for(int i=0;i<j_tmp.size();i++) {
  743. if(i==0)
  744. company_code_list = j_tmp.getString(i);
  745. else
  746. company_code_list += ","+j_tmp.getString(i);
  747. }
  748. }else
  749. company_code = q_json.getString("company_code");
  750. }
  751. if(q_json.has("device_id")) {
  752. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  753. JSONArray j_tmp = q_json.getJSONArray("device_id");
  754. for(int i=0;i<j_tmp.size();i++) {
  755. if(i==0)
  756. device_id_list = j_tmp.getString(i);
  757. else
  758. device_id_list += ","+j_tmp.getString(i);
  759. }
  760. }else
  761. device_id = q_json.getString("device_id");
  762. }
  763. if(dwtype!=null) {
  764. if((dwtype.equals("2"))||(dwtype.equals("4"))||(dwtype.equals("5")))
  765. {
  766. dwtype_list = "2,4,5";
  767. dwtype=null;
  768. }
  769. // for(int i=0;i<2;i++) {
  770. // if(i==0)
  771. // dwtype_list = "2";
  772. // else
  773. // dwtype_list += ","+"5";
  774. // }
  775. }
  776. if(q_json.has("point_code")) {
  777. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  778. JSONArray j_tmp = q_json.getJSONArray("point_code");
  779. for(int i=0;i<j_tmp.size();i++) {
  780. if(i==0)
  781. point_code_list = j_tmp.getString(i);
  782. else
  783. point_code_list += ","+j_tmp.getString(i);
  784. }
  785. }else
  786. point_code = q_json.getString("point_code");
  787. }
  788. if(q_json.has("id")) {
  789. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  790. JSONArray j_tmp = q_json.getJSONArray("id");
  791. for(int i=0;i<j_tmp.size();i++) {
  792. if(i==0)
  793. id_list = j_tmp.getString(i);
  794. else
  795. id_list += ","+j_tmp.getString(i);
  796. }
  797. }else
  798. id = q_json.getString("id");
  799. }
  800. company = q_json.has("company")?q_json.getString("company"):null;
  801. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  802. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  803. name = q_json.has("name")?q_json.getString("name"):null;
  804. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  805. }
  806. if(sort!=null) {
  807. Sort = JSONArray.fromObject(sort);
  808. if((Sort.isArray())&&(Sort.size()>0)) {
  809. JSONObject s_json = Sort.getJSONObject(0);
  810. order = s_json.has("property")?s_json.getString("property"):order;
  811. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  812. }
  813. json.put("sort", sort);
  814. }
  815. Start = start;
  816. Limit = limit;
  817. Page = page;
  818. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  819. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  820. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  821. if(list.size()>0) {
  822. for(int i=0;i<list.size();i++) {
  823. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  824. YtiotVUsercompanyId oid = o.getId();
  825. if(i==0)
  826. Company_Code_List = oid.getOwnerCode();
  827. else
  828. Company_Code_List += ","+oid.getOwnerCode();
  829. }
  830. }
  831. }
  832. if(device_id!=null)
  833. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  834. else {
  835. if(company!=null) {
  836. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  837. }
  838. if(Company_Code_List!=null)
  839. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  840. else {
  841. if(company_code!=null)
  842. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  843. if(company_code_list!=null)
  844. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  845. }
  846. }
  847. if(device_id_list!=null)
  848. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  849. if(dwtype!=null)
  850. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  851. if(dwtype_list!=null)
  852. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  853. if(point_code!=null)
  854. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  855. if(point_code_list!=null)
  856. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  857. if(id!=null)
  858. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  859. if(id_list!=null)
  860. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  861. if(data_time_start!=null)
  862. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  863. if(data_time_end!=null)
  864. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  865. if(name!=null)
  866. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  867. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  868. json.put("totalCount", totalCount);
  869. if(Start!=null){
  870. if(Integer.parseInt(Start)>totalCount){
  871. Start = "0";
  872. Page = "0";
  873. }else if(page==null)
  874. Page="0";
  875. }else{
  876. Start = "0";
  877. Page = "0";
  878. }
  879. json.put("page", Page);
  880. json.put("start", Start);
  881. json.put("limit", Limit);
  882. if(order!=null) {
  883. order_str = " order by "+fieldname(order)+" ";
  884. } else {
  885. order_str = " order by data_time ";
  886. dir = "DESC";
  887. }
  888. if(totalCount>0) {
  889. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  890. if(list.size()>0) {
  891. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  892. for(int i=0;i<list.size();i++) {
  893. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  894. YtiotVSyncDataId oid = o.getId();
  895. @SuppressWarnings("rawtypes")
  896. Map<String, Comparable> map = new HashMap<String, Comparable>();
  897. map.put("company", oid.getCompany());
  898. map.put("company_code", oid.getCompanyCode());
  899. map.put("content", oid.getContent());
  900. map.put("data_time", df.format(oid.getDataTime()));
  901. map.put("device_id", oid.getDeviceId());
  902. map.put("dwtype", oid.getDwtype());
  903. map.put("id", oid.getId());
  904. map.put("name", oid.getName());
  905. map.put("native_id", oid.getNativeId());
  906. map.put("point_code", oid.getPointCode());
  907. map.put("point_data", oid.getPointData());
  908. JSONObject jSONObject = JSONObject.fromObject(map);
  909. jSONArray.add(jSONObject);
  910. }
  911. json.put("RESULT", jSONArray);
  912. }
  913. }
  914. return json.toString();
  915. }
  916. @Override
  917. public String getSyncwaterDataVList(String queryJson, String page, String start, String limit, String sort)
  918. throws Exception {
  919. // TODO Auto-generated method stub
  920. String company_code = null;
  921. String company_code_list = null;
  922. String device_id = null;
  923. String device_id_list = null;
  924. String device_type = null;
  925. String dwtype = null;
  926. String dwtype_list = null;
  927. String point_code = null;
  928. String point_code_list = null;
  929. String id = null;
  930. String id_list = null;
  931. String company = null;
  932. String data_time_start = null;
  933. String data_time_end = null;
  934. String name = null;
  935. String Company_Code_List = null;
  936. String V_LOGINNAME = null;
  937. String hqlwhere = null;
  938. String order = null;
  939. String dir = null;
  940. String Start = null;
  941. String Limit = null;
  942. String Page = null;
  943. String order_str = null;
  944. JSONObject q_json = null;
  945. JSONArray Sort = null;
  946. JSONArray jSONArray = new JSONArray();
  947. JSONObject json = new JSONObject();
  948. json.put("action", "getSyncDataVList");
  949. if(queryJson!=null) {
  950. q_json = JSONObject.fromObject(queryJson);
  951. if(q_json.has("company_code")) {
  952. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  953. JSONArray j_tmp = q_json.getJSONArray("company_code");
  954. for(int i=0;i<j_tmp.size();i++) {
  955. if(i==0)
  956. company_code_list = j_tmp.getString(i);
  957. else
  958. company_code_list += ","+j_tmp.getString(i);
  959. }
  960. }else
  961. company_code = q_json.getString("company_code");
  962. }
  963. if(q_json.has("device_id")) {
  964. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  965. JSONArray j_tmp = q_json.getJSONArray("device_id");
  966. for(int i=0;i<j_tmp.size();i++) {
  967. if(i==0)
  968. device_id_list = j_tmp.getString(i);
  969. else
  970. device_id_list += ","+j_tmp.getString(i);
  971. }
  972. }else
  973. device_id = q_json.getString("device_id");
  974. }
  975. for(int i=0;i<2;i++) {
  976. if(i==0)
  977. dwtype_list = "2";
  978. else
  979. dwtype_list += ","+"5";
  980. }
  981. for(int i=0;i<2;i++) {
  982. if(i==0)
  983. point_code_list = "2";
  984. else
  985. point_code_list += ","+"3"+","+"4";
  986. }
  987. if(q_json.has("id")) {
  988. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  989. JSONArray j_tmp = q_json.getJSONArray("id");
  990. for(int i=0;i<j_tmp.size();i++) {
  991. if(i==0)
  992. id_list = j_tmp.getString(i);
  993. else
  994. id_list += ","+j_tmp.getString(i);
  995. }
  996. }else
  997. id = q_json.getString("id");
  998. }
  999. company = q_json.has("company")?q_json.getString("company"):null;
  1000. data_time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  1001. data_time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  1002. name = q_json.has("name")?q_json.getString("name"):null;
  1003. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1004. }
  1005. if(sort!=null) {
  1006. Sort = JSONArray.fromObject(sort);
  1007. if((Sort.isArray())&&(Sort.size()>0)) {
  1008. JSONObject s_json = Sort.getJSONObject(0);
  1009. order = s_json.has("property")?s_json.getString("property"):order;
  1010. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  1011. }
  1012. json.put("sort", sort);
  1013. }
  1014. Start = start;
  1015. Limit = limit;
  1016. Page = page;
  1017. if((V_LOGINNAME!=null)&&(!V_LOGINNAME.equals("admin"))&&(company_code==null)&&(company_code_list==null)) {
  1018. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1019. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1020. if(list.size()>0) {
  1021. for(int i=0;i<list.size();i++) {
  1022. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1023. YtiotVUsercompanyId oid = o.getId();
  1024. if(i==0)
  1025. Company_Code_List = oid.getOwnerCode();
  1026. else
  1027. Company_Code_List += ","+oid.getOwnerCode();
  1028. }
  1029. }
  1030. }
  1031. if(device_id!=null)
  1032. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  1033. else {
  1034. if(company!=null) {
  1035. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  1036. }
  1037. if(Company_Code_List!=null)
  1038. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1039. else {
  1040. if(company_code!=null)
  1041. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  1042. if(company_code_list!=null)
  1043. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1044. }
  1045. }
  1046. if(device_id_list!=null)
  1047. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id_list+") ";
  1048. if(dwtype!=null)
  1049. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  1050. if(dwtype_list!=null)
  1051. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  1052. if(point_code!=null)
  1053. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  1054. if(point_code_list!=null)
  1055. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  1056. if(id!=null)
  1057. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  1058. if(id_list!=null)
  1059. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  1060. if(data_time_start!=null)
  1061. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  1062. if(data_time_end!=null)
  1063. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  1064. if(name!=null)
  1065. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  1066. int totalCount = ytiotVDataDao.getSyncStatusCount(hqlwhere);
  1067. json.put("totalCount", totalCount);
  1068. if(Start!=null){
  1069. if(Integer.parseInt(Start)>totalCount){
  1070. Start = "0";
  1071. Page = "0";
  1072. }else if(page==null)
  1073. Page="0";
  1074. }else{
  1075. Start = "0";
  1076. Page = "0";
  1077. }
  1078. json.put("page", Page);
  1079. json.put("start", Start);
  1080. json.put("limit", Limit);
  1081. if(order!=null) {
  1082. order_str = " order by data_time ";
  1083. } else {
  1084. order_str = " order by device_id ";
  1085. dir = "DESC";
  1086. }
  1087. if(totalCount>0) {
  1088. List<?> list = ytiotVDataDao.SyncStatusQuery(hqlwhere, order_str, dir, Start, Limit);
  1089. if(list.size()>0) {
  1090. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1091. for(int i=0;i<list.size();i++) {
  1092. YtiotVSyncStatus o = (YtiotVSyncStatus)list.get(i);
  1093. YtiotVSyncStatusId oid = o.getId();
  1094. @SuppressWarnings("rawtypes")
  1095. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1096. if(oid.getDwtype()==2) {
  1097. map.put("device_type", "水表");
  1098. }else {
  1099. map.put("device_type", "液位");
  1100. }
  1101. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  1102. map.put("company", oid.getCompany());
  1103. map.put("company_code", oid.getCompanyCode());
  1104. map.put("data_time", df.format(oid.getDataTime()));
  1105. map.put("device_id", oid.getDeviceId());
  1106. map.put("dwtype", oid.getDwtype());
  1107. map.put("id", oid.getId());
  1108. map.put("name", oid.getName());
  1109. // map.put("native_id", oid.getNativeId());
  1110. map.put("point_code", oid.getPointCode());
  1111. map.put("point_name", oid.getPointName());
  1112. map.put("point_data", oid.getPointData());
  1113. JSONObject jSONObject = JSONObject.fromObject(map);
  1114. jSONArray.add(jSONObject);
  1115. }
  1116. json.put("RESULT", jSONArray);
  1117. }
  1118. }
  1119. return json.toString();
  1120. }
  1121. @Override
  1122. public String getSyncDataRList(String queryJson, String page, String start, String limit, String sort)
  1123. throws Exception {
  1124. // TODO Auto-generated method stub
  1125. String company_code = null;
  1126. String company_code_list = null;
  1127. String device_id = null;
  1128. String device_id_list = null;
  1129. String dwtype = null;
  1130. String dwtype_list = null;
  1131. String point_code = null;
  1132. String point_code_list = null;
  1133. String id = null;
  1134. String id_list = null;
  1135. String company = null;
  1136. String data_time_start = null;
  1137. String data_time_end = null;
  1138. String name = null;
  1139. String Company_Code_List = null;
  1140. String V_LOGINNAME = null;
  1141. String hqlwhere = null;
  1142. String order = null;
  1143. String dir = null;
  1144. String Start = null;
  1145. String Limit = null;
  1146. String Page = null;
  1147. String order_str = null;
  1148. JSONObject q_json = null;
  1149. JSONArray Sort = null;
  1150. JSONArray jSONArray = new JSONArray();
  1151. JSONObject json = new JSONObject();
  1152. json.put("action", "getSyncDataVList");
  1153. if(queryJson!=null) {
  1154. q_json = JSONObject.fromObject(queryJson);
  1155. if(q_json.has("company_code")) {
  1156. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  1157. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1158. for(int i=0;i<j_tmp.size();i++) {
  1159. if(i==0)
  1160. company_code_list = j_tmp.getString(i);
  1161. else
  1162. company_code_list += ","+j_tmp.getString(i);
  1163. }
  1164. }else
  1165. company_code = q_json.getString("company_code");
  1166. }
  1167. if(q_json.has("device_id")) {
  1168. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  1169. JSONArray j_tmp = q_json.getJSONArray("device_id");
  1170. for(int i=0;i<j_tmp.size();i++) {
  1171. if(i==0)
  1172. device_id_list = j_tmp.getString(i);
  1173. else
  1174. device_id_list += ","+j_tmp.getString(i);
  1175. }
  1176. }else
  1177. device_id = q_json.getString("device_id");
  1178. }
  1179. dwtype= "6";
  1180. if(q_json.has("point_code")) {
  1181. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  1182. JSONArray j_tmp = q_json.getJSONArray("point_code");
  1183. for(int i=0;i<j_tmp.size();i++) {
  1184. if(i==0)
  1185. point_code_list = j_tmp.getString(i);
  1186. else
  1187. point_code_list += ","+j_tmp.getString(i);
  1188. }
  1189. }else
  1190. point_code = q_json.getString("point_code");
  1191. }
  1192. if(q_json.has("id")) {
  1193. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  1194. JSONArray j_tmp = q_json.getJSONArray("id");
  1195. for(int i=0;i<j_tmp.size();i++) {
  1196. if(i==0)
  1197. id_list = j_tmp.getString(i);
  1198. else
  1199. id_list += ","+j_tmp.getString(i);
  1200. }
  1201. }else
  1202. id = q_json.getString("id");
  1203. }
  1204. company = q_json.has("company")?q_json.getString("company"):null;
  1205. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  1206. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  1207. name = q_json.has("name")?q_json.getString("name"):null;
  1208. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1209. }
  1210. if(sort!=null) {
  1211. Sort = JSONArray.fromObject(sort);
  1212. if((Sort.isArray())&&(Sort.size()>0)) {
  1213. JSONObject s_json = Sort.getJSONObject(0);
  1214. order = s_json.has("property")?s_json.getString("property"):order;
  1215. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  1216. }
  1217. json.put("sort", sort);
  1218. }
  1219. Start = start;
  1220. Limit = limit;
  1221. Page = page;
  1222. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  1223. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1224. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1225. if(list.size()>0) {
  1226. for(int i=0;i<list.size();i++) {
  1227. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1228. YtiotVUsercompanyId oid = o.getId();
  1229. if(i==0)
  1230. Company_Code_List = oid.getOwnerCode();
  1231. else
  1232. Company_Code_List += ","+oid.getOwnerCode();
  1233. }
  1234. }
  1235. }
  1236. if(device_id!=null)
  1237. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  1238. else {
  1239. if(company!=null) {
  1240. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  1241. }
  1242. if(Company_Code_List!=null)
  1243. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1244. else {
  1245. if(company_code!=null)
  1246. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  1247. if(company_code_list!=null)
  1248. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1249. }
  1250. }
  1251. if(device_id_list!=null)
  1252. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  1253. if(dwtype!=null)
  1254. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  1255. if(dwtype_list!=null)
  1256. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  1257. if(point_code!=null)
  1258. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  1259. if(point_code_list!=null)
  1260. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  1261. if(id!=null)
  1262. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  1263. if(id_list!=null)
  1264. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  1265. if(data_time_start!=null)
  1266. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  1267. if(data_time_end!=null)
  1268. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  1269. if(name!=null)
  1270. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  1271. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  1272. json.put("totalCount", totalCount);
  1273. if(Start!=null){
  1274. if(Integer.parseInt(Start)>totalCount){
  1275. Start = "0";
  1276. Page = "0";
  1277. }else if(page==null)
  1278. Page="0";
  1279. }else{
  1280. Start = "0";
  1281. Page = "0";
  1282. }
  1283. json.put("page", Page);
  1284. json.put("start", Start);
  1285. json.put("limit", Limit);
  1286. if(order!=null) {
  1287. order_str = " order by "+fieldname(order)+" ";
  1288. } else {
  1289. order_str = " order by data_time ";
  1290. dir = "DESC";
  1291. }
  1292. if(totalCount>0) {
  1293. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  1294. if(list.size()>0) {
  1295. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1296. for(int i=0;i<list.size();i++) {
  1297. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  1298. YtiotVSyncDataId oid = o.getId();
  1299. @SuppressWarnings("rawtypes")
  1300. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1301. map.put("company", oid.getCompany());
  1302. map.put("company_code", oid.getCompanyCode());
  1303. map.put("content", oid.getContent());
  1304. map.put("data_time", df.format(oid.getDataTime()));
  1305. map.put("device_id", oid.getDeviceId());
  1306. map.put("dwtype", oid.getDwtype());
  1307. map.put("id", oid.getId());
  1308. map.put("name", oid.getName());
  1309. map.put("native_id", oid.getNativeId());
  1310. map.put("point_code", oid.getPointCode());
  1311. map.put("point_data", oid.getPointData());
  1312. JSONObject jSONObject = JSONObject.fromObject(map);
  1313. jSONArray.add(jSONObject);
  1314. }
  1315. json.put("RESULT", jSONArray);
  1316. }
  1317. }
  1318. return json.toString();
  1319. }
  1320. @Override
  1321. public String getSyncrtuDataVList(String queryJson, String page, String start, String limit, String sort)
  1322. throws Exception {
  1323. // TODO Auto-generated method stub
  1324. String company_code = null;
  1325. String company_code_list = null;
  1326. String device_id = null;
  1327. String device_id_list = null;
  1328. String device_type = null;
  1329. String dwtype = null;
  1330. String dwtype_list = null;
  1331. String point_code = null;
  1332. String point_code_list = null;
  1333. String id = null;
  1334. String id_list = null;
  1335. String company = null;
  1336. String data_time_start = null;
  1337. String data_time_end = null;
  1338. String name = null;
  1339. String Company_Code_List = null;
  1340. String V_LOGINNAME = null;
  1341. String hqlwhere = null;
  1342. String order = null;
  1343. String dir = null;
  1344. String Start = null;
  1345. String Limit = null;
  1346. String Page = null;
  1347. String order_str = null;
  1348. JSONObject q_json = null;
  1349. JSONArray Sort = null;
  1350. JSONArray jSONArray = new JSONArray();
  1351. JSONObject json = new JSONObject();
  1352. json.put("action", "getSyncDataVList");
  1353. if(queryJson!=null) {
  1354. q_json = JSONObject.fromObject(queryJson);
  1355. if(q_json.has("company_code")) {
  1356. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  1357. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1358. for(int i=0;i<j_tmp.size();i++) {
  1359. if(i==0)
  1360. company_code_list = j_tmp.getString(i);
  1361. else
  1362. company_code_list += ","+j_tmp.getString(i);
  1363. }
  1364. }else
  1365. company_code = q_json.getString("company_code");
  1366. }
  1367. if(q_json.has("device_id")) {
  1368. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  1369. JSONArray j_tmp = q_json.getJSONArray("device_id");
  1370. for(int i=0;i<j_tmp.size();i++) {
  1371. if(i==0)
  1372. device_id_list = j_tmp.getString(i);
  1373. else
  1374. device_id_list += ","+j_tmp.getString(i);
  1375. }
  1376. }else
  1377. device_id = q_json.getString("device_id");
  1378. }
  1379. // for(int i=0;i<2;i++) {
  1380. // if(i==0)
  1381. // dwtype_list = "2";
  1382. // else
  1383. // dwtype_list += ","+"5";
  1384. // }
  1385. dwtype = "6";
  1386. point_code = "64";
  1387. if(q_json.has("id")) {
  1388. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  1389. JSONArray j_tmp = q_json.getJSONArray("id");
  1390. for(int i=0;i<j_tmp.size();i++) {
  1391. if(i==0)
  1392. id_list = j_tmp.getString(i);
  1393. else
  1394. id_list += ","+j_tmp.getString(i);
  1395. }
  1396. }else
  1397. id = q_json.getString("id");
  1398. }
  1399. company = q_json.has("company")?q_json.getString("company"):null;
  1400. data_time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  1401. data_time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  1402. name = q_json.has("name")?q_json.getString("name"):null;
  1403. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1404. }
  1405. if(sort!=null) {
  1406. Sort = JSONArray.fromObject(sort);
  1407. if((Sort.isArray())&&(Sort.size()>0)) {
  1408. JSONObject s_json = Sort.getJSONObject(0);
  1409. order = s_json.has("property")?s_json.getString("property"):order;
  1410. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  1411. }
  1412. json.put("sort", sort);
  1413. }
  1414. Start = start;
  1415. Limit = limit;
  1416. Page = page;
  1417. if((V_LOGINNAME!=null)&&(!V_LOGINNAME.equals("admin"))&&(company_code==null)&&(company_code_list==null)) {
  1418. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1419. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1420. if(list.size()>0) {
  1421. for(int i=0;i<list.size();i++) {
  1422. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1423. YtiotVUsercompanyId oid = o.getId();
  1424. if(i==0)
  1425. Company_Code_List = oid.getOwnerCode();
  1426. else
  1427. Company_Code_List += ","+oid.getOwnerCode();
  1428. }
  1429. }
  1430. }
  1431. if(device_id!=null)
  1432. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  1433. else {
  1434. if(company!=null) {
  1435. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  1436. }
  1437. if(Company_Code_List!=null)
  1438. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1439. else {
  1440. if(company_code!=null)
  1441. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  1442. if(company_code_list!=null)
  1443. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1444. }
  1445. }
  1446. if(device_id_list!=null)
  1447. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id_list+") ";
  1448. if(dwtype!=null)
  1449. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  1450. if(dwtype_list!=null)
  1451. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  1452. if(point_code!=null)
  1453. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" > ("+point_code+") ";
  1454. if(point_code_list!=null)
  1455. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  1456. if(id!=null)
  1457. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  1458. if(id_list!=null)
  1459. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  1460. if(data_time_start!=null)
  1461. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  1462. if(data_time_end!=null)
  1463. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  1464. if(name!=null)
  1465. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  1466. int totalCount = ytiotVDataDao.getSyncStatusCount(hqlwhere);
  1467. json.put("totalCount", totalCount);
  1468. if(Start!=null){
  1469. if(Integer.parseInt(Start)>totalCount){
  1470. Start = "0";
  1471. Page = "0";
  1472. }else if(page==null)
  1473. Page="0";
  1474. }else{
  1475. Start = "0";
  1476. Page = "0";
  1477. }
  1478. json.put("page", Page);
  1479. json.put("start", Start);
  1480. json.put("limit", Limit);
  1481. if(order!=null) {
  1482. order_str = " order by data_time ";
  1483. } else {
  1484. order_str = " order by device_id ";
  1485. dir = "DESC";
  1486. }
  1487. if(totalCount>0) {
  1488. List<?> list = ytiotVDataDao.SyncStatusQuery(hqlwhere, order_str, dir, Start, Limit);
  1489. if(list.size()>0) {
  1490. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1491. for(int i=0;i<list.size();i++) {
  1492. YtiotVSyncStatus o = (YtiotVSyncStatus)list.get(i);
  1493. YtiotVSyncStatusId oid = o.getId();
  1494. @SuppressWarnings("rawtypes")
  1495. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1496. map.put("device_type", "RTU");
  1497. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  1498. map.put("company", oid.getCompany());
  1499. map.put("company_code", oid.getCompanyCode());
  1500. map.put("data_time", df.format(oid.getDataTime()));
  1501. map.put("device_id", oid.getDeviceId());
  1502. map.put("dwtype", oid.getDwtype());
  1503. map.put("id", oid.getId());
  1504. map.put("name", oid.getName());
  1505. // map.put("native_id", oid.getNativeId());
  1506. map.put("point_code", oid.getPointCode());
  1507. map.put("point_name", oid.getPointName());
  1508. map.put("point_data", oid.getPointData());
  1509. JSONObject jSONObject = JSONObject.fromObject(map);
  1510. jSONArray.add(jSONObject);
  1511. }
  1512. json.put("RESULT", jSONArray);
  1513. }
  1514. }
  1515. return json.toString();
  1516. }
  1517. @Override
  1518. public String getSyncDataFList(String queryJson, String page, String start, String limit, String sort)
  1519. throws Exception {
  1520. // TODO Auto-generated method stub
  1521. String company_code = null;
  1522. String company_code_list = null;
  1523. String device_id = null;
  1524. String device_id_list = null;
  1525. String dwtype = null;
  1526. String dwtype_list = null;
  1527. String point_code = null;
  1528. String point_code_list = null;
  1529. String id = null;
  1530. String id_list = null;
  1531. String company = null;
  1532. String data_time_start = null;
  1533. String data_time_end = null;
  1534. String name = null;
  1535. String Company_Code_List = null;
  1536. String V_LOGINNAME = null;
  1537. String hqlwhere = null;
  1538. String order = null;
  1539. String dir = null;
  1540. String Start = null;
  1541. String Limit = null;
  1542. String Page = null;
  1543. String order_str = null;
  1544. JSONObject q_json = null;
  1545. JSONArray Sort = null;
  1546. JSONArray jSONArray = new JSONArray();
  1547. JSONObject json = new JSONObject();
  1548. json.put("action", "getSyncDataVList");
  1549. if(queryJson!=null) {
  1550. q_json = JSONObject.fromObject(queryJson);
  1551. if(q_json.has("company_code")) {
  1552. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  1553. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1554. for(int i=0;i<j_tmp.size();i++) {
  1555. if(i==0)
  1556. company_code_list = j_tmp.getString(i);
  1557. else
  1558. company_code_list += ","+j_tmp.getString(i);
  1559. }
  1560. }else
  1561. company_code = q_json.getString("company_code");
  1562. }
  1563. if(q_json.has("device_id")) {
  1564. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  1565. JSONArray j_tmp = q_json.getJSONArray("device_id");
  1566. for(int i=0;i<j_tmp.size();i++) {
  1567. if(i==0)
  1568. device_id_list = j_tmp.getString(i);
  1569. else
  1570. device_id_list += ","+j_tmp.getString(i);
  1571. }
  1572. }else
  1573. device_id = q_json.getString("device_id");
  1574. }
  1575. dwtype= "7";
  1576. if(q_json.has("point_code")) {
  1577. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  1578. JSONArray j_tmp = q_json.getJSONArray("point_code");
  1579. for(int i=0;i<j_tmp.size();i++) {
  1580. if(i==0)
  1581. point_code_list = j_tmp.getString(i);
  1582. else
  1583. point_code_list += ","+j_tmp.getString(i);
  1584. }
  1585. }else
  1586. point_code = q_json.getString("point_code");
  1587. }
  1588. if(q_json.has("id")) {
  1589. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  1590. JSONArray j_tmp = q_json.getJSONArray("id");
  1591. for(int i=0;i<j_tmp.size();i++) {
  1592. if(i==0)
  1593. id_list = j_tmp.getString(i);
  1594. else
  1595. id_list += ","+j_tmp.getString(i);
  1596. }
  1597. }else
  1598. id = q_json.getString("id");
  1599. }
  1600. company = q_json.has("company")?q_json.getString("company"):null;
  1601. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  1602. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  1603. name = q_json.has("name")?q_json.getString("name"):null;
  1604. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1605. }
  1606. if(sort!=null) {
  1607. Sort = JSONArray.fromObject(sort);
  1608. if((Sort.isArray())&&(Sort.size()>0)) {
  1609. JSONObject s_json = Sort.getJSONObject(0);
  1610. order = s_json.has("property")?s_json.getString("property"):order;
  1611. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  1612. }
  1613. json.put("sort", sort);
  1614. }
  1615. Start = start;
  1616. Limit = limit;
  1617. Page = page;
  1618. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  1619. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1620. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1621. if(list.size()>0) {
  1622. for(int i=0;i<list.size();i++) {
  1623. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1624. YtiotVUsercompanyId oid = o.getId();
  1625. if(i==0)
  1626. Company_Code_List = oid.getOwnerCode();
  1627. else
  1628. Company_Code_List += ","+oid.getOwnerCode();
  1629. }
  1630. }
  1631. }
  1632. if(device_id!=null)
  1633. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  1634. else {
  1635. if(company!=null) {
  1636. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  1637. }
  1638. if(Company_Code_List!=null)
  1639. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1640. else {
  1641. if(company_code!=null)
  1642. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  1643. if(company_code_list!=null)
  1644. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1645. }
  1646. }
  1647. if(device_id_list!=null)
  1648. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  1649. if(dwtype!=null)
  1650. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  1651. if(dwtype_list!=null)
  1652. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  1653. if(point_code!=null)
  1654. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  1655. if(point_code_list!=null)
  1656. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  1657. if(id!=null)
  1658. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  1659. if(id_list!=null)
  1660. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  1661. if(data_time_start!=null)
  1662. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  1663. if(data_time_end!=null)
  1664. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  1665. if(name!=null)
  1666. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  1667. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  1668. json.put("totalCount", totalCount);
  1669. if(Start!=null){
  1670. if(Integer.parseInt(Start)>totalCount){
  1671. Start = "0";
  1672. Page = "0";
  1673. }else if(page==null)
  1674. Page="0";
  1675. }else{
  1676. Start = "0";
  1677. Page = "0";
  1678. }
  1679. json.put("page", Page);
  1680. json.put("start", Start);
  1681. json.put("limit", Limit);
  1682. if(order!=null) {
  1683. order_str = " order by "+fieldname(order)+" ";
  1684. } else {
  1685. order_str = " order by data_time ";
  1686. dir = "DESC";
  1687. }
  1688. if(totalCount>0) {
  1689. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  1690. if(list.size()>0) {
  1691. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1692. for(int i=0;i<list.size();i++) {
  1693. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  1694. YtiotVSyncDataId oid = o.getId();
  1695. @SuppressWarnings("rawtypes")
  1696. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1697. map.put("company", oid.getCompany());
  1698. map.put("company_code", oid.getCompanyCode());
  1699. map.put("content", oid.getContent());
  1700. map.put("data_time", df.format(oid.getDataTime()));
  1701. map.put("device_id", oid.getDeviceId());
  1702. map.put("dwtype", oid.getDwtype());
  1703. map.put("id", oid.getId());
  1704. map.put("name", oid.getName());
  1705. map.put("native_id", oid.getNativeId());
  1706. map.put("point_code", oid.getPointCode());
  1707. map.put("point_data", oid.getPointData());
  1708. JSONObject jSONObject = JSONObject.fromObject(map);
  1709. jSONArray.add(jSONObject);
  1710. }
  1711. json.put("RESULT", jSONArray);
  1712. }
  1713. }
  1714. return json.toString();
  1715. }
  1716. @Override
  1717. public String getSyncfileDataFexcelList(String queryJson)
  1718. throws Exception {
  1719. String company_code = null;
  1720. String company_code_list = null;
  1721. String device_id = null;
  1722. String device_id_list = null;
  1723. String dwtype = null;
  1724. String dwtype_list = null;
  1725. String point_code = null;
  1726. String point_code_list = null;
  1727. String id = null;
  1728. String id_list = null;
  1729. String company = null;
  1730. String data_time_start = null;
  1731. String data_time_end = null;
  1732. String name = null;
  1733. String Company_Code_List = null;
  1734. String V_LOGINNAME = null;
  1735. String hqlwhere = null;
  1736. String order = null;
  1737. String dir = null;
  1738. String Start = null;
  1739. String Limit = null;
  1740. String Page = null;
  1741. String order_str = null;
  1742. JSONObject q_json = null;
  1743. JSONArray Sort = null;
  1744. JSONArray jSONArray = new JSONArray();
  1745. JSONObject json = new JSONObject();
  1746. json.put("action", "getSyncDataVList");
  1747. if(queryJson!=null) {
  1748. q_json = JSONObject.fromObject(queryJson);
  1749. if(q_json.has("company_code")) {
  1750. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  1751. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1752. for(int i=0;i<j_tmp.size();i++) {
  1753. if(i==0)
  1754. company_code_list = j_tmp.getString(i);
  1755. else
  1756. company_code_list += ","+j_tmp.getString(i);
  1757. }
  1758. }else
  1759. company_code = q_json.getString("company_code");
  1760. }
  1761. if(q_json.has("device_id")) {
  1762. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  1763. JSONArray j_tmp = q_json.getJSONArray("device_id");
  1764. for(int i=0;i<j_tmp.size();i++) {
  1765. if(i==0)
  1766. device_id_list = j_tmp.getString(i);
  1767. else
  1768. device_id_list += ","+j_tmp.getString(i);
  1769. }
  1770. }else
  1771. device_id = q_json.getString("device_id");
  1772. }
  1773. dwtype= "7";
  1774. if(q_json.has("point_code")) {
  1775. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  1776. JSONArray j_tmp = q_json.getJSONArray("point_code");
  1777. for(int i=0;i<j_tmp.size();i++) {
  1778. if(i==0)
  1779. point_code_list = j_tmp.getString(i);
  1780. else
  1781. point_code_list += ","+j_tmp.getString(i);
  1782. }
  1783. }else
  1784. point_code = q_json.getString("point_code");
  1785. }
  1786. if(q_json.has("id")) {
  1787. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  1788. JSONArray j_tmp = q_json.getJSONArray("id");
  1789. for(int i=0;i<j_tmp.size();i++) {
  1790. if(i==0)
  1791. id_list = j_tmp.getString(i);
  1792. else
  1793. id_list += ","+j_tmp.getString(i);
  1794. }
  1795. }else
  1796. id = q_json.getString("id");
  1797. }
  1798. company = q_json.has("company")?q_json.getString("company"):null;
  1799. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  1800. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  1801. name = q_json.has("name")?q_json.getString("name"):null;
  1802. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1803. Page = q_json.has("page")?q_json.getString("page"):null;
  1804. order = q_json.has("order")?q_json.getString("order"):null;
  1805. dir = q_json.has("dir")?q_json.getString("dir"):null;
  1806. Start = q_json.has("start")?q_json.getString("start"):null;
  1807. Limit = q_json.has("limit")?q_json.getString("limit"):null;
  1808. }
  1809. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  1810. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1811. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1812. if(list.size()>0) {
  1813. for(int i=0;i<list.size();i++) {
  1814. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1815. YtiotVUsercompanyId oid = o.getId();
  1816. if(i==0)
  1817. Company_Code_List = oid.getOwnerCode();
  1818. else
  1819. Company_Code_List += ","+oid.getOwnerCode();
  1820. }
  1821. }
  1822. }
  1823. if(device_id!=null)
  1824. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  1825. else {
  1826. if(company!=null) {
  1827. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  1828. }
  1829. if(Company_Code_List!=null)
  1830. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1831. else {
  1832. if(company_code!=null)
  1833. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  1834. if(company_code_list!=null)
  1835. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1836. }
  1837. }
  1838. if(device_id_list!=null)
  1839. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  1840. if(dwtype!=null)
  1841. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  1842. if(dwtype_list!=null)
  1843. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  1844. if(point_code!=null)
  1845. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  1846. if(point_code_list!=null)
  1847. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  1848. if(id!=null)
  1849. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  1850. if(id_list!=null)
  1851. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  1852. if(data_time_start!=null)
  1853. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  1854. if(data_time_end!=null)
  1855. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  1856. if(name!=null)
  1857. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  1858. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  1859. json.put("totalCount", totalCount);
  1860. if(Start!=null){
  1861. if(Integer.parseInt(Start)>totalCount){
  1862. Start = "0";
  1863. Page = "0";
  1864. }else if(Page==null)
  1865. Page="0";
  1866. }else{
  1867. Start = "0";
  1868. Page = "0";
  1869. }
  1870. json.put("page", Page);
  1871. json.put("start", Start);
  1872. json.put("limit", Limit);
  1873. if(order!=null) {
  1874. order_str = " order by "+fieldname(order)+" ";
  1875. } else {
  1876. order_str = " order by data_time ";
  1877. dir = "DESC";
  1878. }
  1879. if(totalCount>0) {
  1880. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  1881. if(list.size()>0) {
  1882. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1883. for(int i=0;i<list.size();i++) {
  1884. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  1885. YtiotVSyncDataId oid = o.getId();
  1886. @SuppressWarnings("rawtypes")
  1887. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1888. map.put("company", oid.getCompany());
  1889. map.put("company_code", oid.getCompanyCode());
  1890. map.put("content", oid.getContent());
  1891. map.put("data_time", df.format(oid.getDataTime()));
  1892. map.put("device_id", oid.getDeviceId());
  1893. map.put("dwtype", oid.getDwtype());
  1894. map.put("id", oid.getId());
  1895. map.put("name", oid.getName());
  1896. map.put("native_id", oid.getNativeId());
  1897. map.put("point_code", oid.getPointCode());
  1898. map.put("point_data", oid.getPointData());
  1899. JSONObject jSONObject = JSONObject.fromObject(map);
  1900. jSONArray.add(jSONObject);
  1901. }
  1902. json.put("result", jSONArray);
  1903. }
  1904. }
  1905. return json.toString();
  1906. }
  1907. @Override
  1908. public String getSyncwaterDataFexcelList(String queryJson)
  1909. throws Exception {
  1910. String company_code = null;
  1911. String company_code_list = null;
  1912. String device_id = null;
  1913. String device_id_list = null;
  1914. String dwtype = null;
  1915. String dwtype_list = null;
  1916. String point_code = null;
  1917. String point_code_list = null;
  1918. String id = null;
  1919. String id_list = null;
  1920. String company = null;
  1921. String data_time_start = null;
  1922. String data_time_end = null;
  1923. String name = null;
  1924. String Company_Code_List = null;
  1925. String V_LOGINNAME = null;
  1926. String hqlwhere = null;
  1927. String order = null;
  1928. String dir = null;
  1929. String Start = null;
  1930. String Limit = null;
  1931. String Page = null;
  1932. String order_str = null;
  1933. JSONObject q_json = null;
  1934. JSONArray Sort = null;
  1935. JSONArray jSONArray = new JSONArray();
  1936. JSONObject json = new JSONObject();
  1937. json.put("action", "getSyncDataVList");
  1938. if(queryJson!=null) {
  1939. q_json = JSONObject.fromObject(queryJson);
  1940. if(q_json.has("company_code")) {
  1941. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  1942. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1943. for(int i=0;i<j_tmp.size();i++) {
  1944. if(i==0)
  1945. company_code_list = j_tmp.getString(i);
  1946. else
  1947. company_code_list += ","+j_tmp.getString(i);
  1948. }
  1949. }else
  1950. company_code = q_json.getString("company_code");
  1951. }
  1952. if(q_json.has("device_id")) {
  1953. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  1954. JSONArray j_tmp = q_json.getJSONArray("device_id");
  1955. for(int i=0;i<j_tmp.size();i++) {
  1956. if(i==0)
  1957. device_id_list = j_tmp.getString(i);
  1958. else
  1959. device_id_list += ","+j_tmp.getString(i);
  1960. }
  1961. }else
  1962. device_id = q_json.getString("device_id");
  1963. }
  1964. for(int i=0;i<2;i++) {
  1965. if(i==0)
  1966. dwtype_list = "2";
  1967. else
  1968. dwtype_list += ","+"5";
  1969. }
  1970. if(q_json.has("point_code")) {
  1971. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  1972. JSONArray j_tmp = q_json.getJSONArray("point_code");
  1973. for(int i=0;i<j_tmp.size();i++) {
  1974. if(i==0)
  1975. point_code_list = j_tmp.getString(i);
  1976. else
  1977. point_code_list += ","+j_tmp.getString(i);
  1978. }
  1979. }else
  1980. point_code = q_json.getString("point_code");
  1981. }
  1982. if(q_json.has("id")) {
  1983. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  1984. JSONArray j_tmp = q_json.getJSONArray("id");
  1985. for(int i=0;i<j_tmp.size();i++) {
  1986. if(i==0)
  1987. id_list = j_tmp.getString(i);
  1988. else
  1989. id_list += ","+j_tmp.getString(i);
  1990. }
  1991. }else
  1992. id = q_json.getString("id");
  1993. }
  1994. company = q_json.has("company")?q_json.getString("company"):null;
  1995. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  1996. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  1997. name = q_json.has("name")?q_json.getString("name"):null;
  1998. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1999. Page = q_json.has("page")?q_json.getString("page"):null;
  2000. order = q_json.has("order")?q_json.getString("order"):null;
  2001. dir = q_json.has("dir")?q_json.getString("dir"):null;
  2002. Start = q_json.has("start")?q_json.getString("start"):null;
  2003. Limit = q_json.has("limit")?q_json.getString("limit"):null;
  2004. }
  2005. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  2006. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  2007. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  2008. if(list.size()>0) {
  2009. for(int i=0;i<list.size();i++) {
  2010. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  2011. YtiotVUsercompanyId oid = o.getId();
  2012. if(i==0)
  2013. Company_Code_List = oid.getOwnerCode();
  2014. else
  2015. Company_Code_List += ","+oid.getOwnerCode();
  2016. }
  2017. }
  2018. }
  2019. if(device_id!=null)
  2020. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  2021. else {
  2022. if(company!=null) {
  2023. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  2024. }
  2025. if(Company_Code_List!=null)
  2026. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  2027. else {
  2028. if(company_code!=null)
  2029. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  2030. if(company_code_list!=null)
  2031. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  2032. }
  2033. }
  2034. if(device_id_list!=null)
  2035. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  2036. if(dwtype!=null)
  2037. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  2038. if(dwtype_list!=null)
  2039. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  2040. if(point_code!=null)
  2041. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  2042. if(point_code_list!=null)
  2043. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  2044. if(id!=null)
  2045. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  2046. if(id_list!=null)
  2047. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  2048. if(data_time_start!=null)
  2049. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  2050. if(data_time_end!=null)
  2051. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  2052. if(name!=null)
  2053. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  2054. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  2055. json.put("totalCount", totalCount);
  2056. if(Start!=null){
  2057. if(Integer.parseInt(Start)>totalCount){
  2058. Start = "0";
  2059. Page = "0";
  2060. }else if(Page==null)
  2061. Page="0";
  2062. }else{
  2063. Start = "0";
  2064. Page = "0";
  2065. }
  2066. json.put("page", Page);
  2067. json.put("start", Start);
  2068. json.put("limit", Limit);
  2069. if(order!=null) {
  2070. order_str = " order by "+fieldname(order)+" ";
  2071. } else {
  2072. order_str = " order by data_time ";
  2073. dir = "DESC";
  2074. }
  2075. if(totalCount>0) {
  2076. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  2077. if(list.size()>0) {
  2078. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2079. for(int i=0;i<list.size();i++) {
  2080. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  2081. YtiotVSyncDataId oid = o.getId();
  2082. @SuppressWarnings("rawtypes")
  2083. Map<String, Comparable> map = new HashMap<String, Comparable>();
  2084. map.put("company", oid.getCompany());
  2085. map.put("company_code", oid.getCompanyCode());
  2086. map.put("content", oid.getContent());
  2087. map.put("data_time", df.format(oid.getDataTime()));
  2088. map.put("device_id", oid.getDeviceId());
  2089. map.put("dwtype", oid.getDwtype());
  2090. map.put("id", oid.getId());
  2091. map.put("name", oid.getName());
  2092. map.put("native_id", oid.getNativeId());
  2093. map.put("point_code", oid.getPointCode());
  2094. map.put("point_data", oid.getPointData());
  2095. JSONObject jSONObject = JSONObject.fromObject(map);
  2096. jSONArray.add(jSONObject);
  2097. }
  2098. json.put("result", jSONArray);
  2099. }
  2100. }
  2101. return json.toString();
  2102. }
  2103. @Override
  2104. public String getSyncDataFexcelList(String queryJson)
  2105. throws Exception {
  2106. String company_code = null;
  2107. String company_code_list = null;
  2108. String device_id = null;
  2109. String device_id_list = null;
  2110. String dwtype = null;
  2111. String dwtype_list = null;
  2112. String point_code = null;
  2113. String point_code_list = null;
  2114. String id = null;
  2115. String id_list = null;
  2116. String company = null;
  2117. String data_time_start = null;
  2118. String data_time_end = null;
  2119. String name = null;
  2120. String Company_Code_List = null;
  2121. String V_LOGINNAME = null;
  2122. String hqlwhere = null;
  2123. String order = null;
  2124. String dir = null;
  2125. String Start = null;
  2126. String Limit = null;
  2127. String Page = null;
  2128. String order_str = null;
  2129. JSONObject q_json = null;
  2130. JSONArray Sort = null;
  2131. JSONArray jSONArray = new JSONArray();
  2132. JSONObject json = new JSONObject();
  2133. json.put("action", "getSyncDataVList");
  2134. if(queryJson!=null) {
  2135. q_json = JSONObject.fromObject(queryJson);
  2136. if(q_json.has("company_code")) {
  2137. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  2138. JSONArray j_tmp = q_json.getJSONArray("company_code");
  2139. for(int i=0;i<j_tmp.size();i++) {
  2140. if(i==0)
  2141. company_code_list = j_tmp.getString(i);
  2142. else
  2143. company_code_list += ","+j_tmp.getString(i);
  2144. }
  2145. }else
  2146. company_code = q_json.getString("company_code");
  2147. }
  2148. if(q_json.has("device_id")) {
  2149. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  2150. JSONArray j_tmp = q_json.getJSONArray("device_id");
  2151. for(int i=0;i<j_tmp.size();i++) {
  2152. if(i==0)
  2153. device_id_list = j_tmp.getString(i);
  2154. else
  2155. device_id_list += ","+j_tmp.getString(i);
  2156. }
  2157. }else
  2158. device_id = q_json.getString("device_id");
  2159. }
  2160. // for(int i=0;i<2;i++) {
  2161. // if(i==0)
  2162. // dwtype_list = "2";
  2163. // else
  2164. // dwtype_list += ","+"5";
  2165. // }
  2166. if(q_json.has("point_code")) {
  2167. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  2168. JSONArray j_tmp = q_json.getJSONArray("point_code");
  2169. for(int i=0;i<j_tmp.size();i++) {
  2170. if(i==0)
  2171. point_code_list = j_tmp.getString(i);
  2172. else
  2173. point_code_list += ","+j_tmp.getString(i);
  2174. }
  2175. }else
  2176. point_code = q_json.getString("point_code");
  2177. }
  2178. if(q_json.has("id")) {
  2179. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  2180. JSONArray j_tmp = q_json.getJSONArray("id");
  2181. for(int i=0;i<j_tmp.size();i++) {
  2182. if(i==0)
  2183. id_list = j_tmp.getString(i);
  2184. else
  2185. id_list += ","+j_tmp.getString(i);
  2186. }
  2187. }else
  2188. id = q_json.getString("id");
  2189. }
  2190. company = q_json.has("company")?q_json.getString("company"):null;
  2191. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  2192. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  2193. name = q_json.has("name")?q_json.getString("name"):null;
  2194. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  2195. Page = q_json.has("page")?q_json.getString("page"):null;
  2196. order = q_json.has("order")?q_json.getString("order"):null;
  2197. dir = q_json.has("dir")?q_json.getString("dir"):null;
  2198. Start = q_json.has("start")?q_json.getString("start"):null;
  2199. Limit = q_json.has("limit")?q_json.getString("limit"):null;
  2200. }
  2201. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  2202. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  2203. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  2204. if(list.size()>0) {
  2205. for(int i=0;i<list.size();i++) {
  2206. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  2207. YtiotVUsercompanyId oid = o.getId();
  2208. if(i==0)
  2209. Company_Code_List = oid.getOwnerCode();
  2210. else
  2211. Company_Code_List += ","+oid.getOwnerCode();
  2212. }
  2213. }
  2214. }
  2215. if(device_id!=null)
  2216. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  2217. else {
  2218. if(company!=null) {
  2219. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  2220. }
  2221. if(Company_Code_List!=null)
  2222. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  2223. else {
  2224. if(company_code!=null)
  2225. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  2226. if(company_code_list!=null)
  2227. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  2228. }
  2229. }
  2230. if(device_id_list!=null)
  2231. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  2232. if(dwtype!=null)
  2233. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  2234. if(dwtype_list!=null)
  2235. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  2236. if(point_code!=null)
  2237. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  2238. if(point_code_list!=null)
  2239. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  2240. if(id!=null)
  2241. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  2242. if(id_list!=null)
  2243. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  2244. if(data_time_start!=null)
  2245. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  2246. if(data_time_end!=null)
  2247. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  2248. if(name!=null)
  2249. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  2250. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  2251. json.put("totalCount", totalCount);
  2252. if(Start!=null){
  2253. if(Integer.parseInt(Start)>totalCount){
  2254. Start = "0";
  2255. Page = "0";
  2256. }else if(Page==null)
  2257. Page="0";
  2258. }else{
  2259. Start = "0";
  2260. Page = "0";
  2261. }
  2262. json.put("page", Page);
  2263. json.put("start", Start);
  2264. json.put("limit", Limit);
  2265. if(order!=null) {
  2266. order_str = " order by "+fieldname(order)+" ";
  2267. } else {
  2268. order_str = " order by data_time ";
  2269. dir = "DESC";
  2270. }
  2271. if(totalCount>0) {
  2272. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  2273. if(list.size()>0) {
  2274. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2275. for(int i=0;i<list.size();i++) {
  2276. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  2277. YtiotVSyncDataId oid = o.getId();
  2278. @SuppressWarnings("rawtypes")
  2279. Map<String, Comparable> map = new HashMap<String, Comparable>();
  2280. map.put("company", oid.getCompany());
  2281. map.put("company_code", oid.getCompanyCode());
  2282. map.put("content", oid.getContent());
  2283. map.put("data_time", df.format(oid.getDataTime()));
  2284. map.put("device_id", oid.getDeviceId());
  2285. map.put("dwtype", oid.getDwtype());
  2286. map.put("id", oid.getId());
  2287. map.put("name", oid.getName());
  2288. map.put("native_id", oid.getNativeId());
  2289. map.put("point_code", oid.getPointCode());
  2290. map.put("point_data", oid.getPointData());
  2291. JSONObject jSONObject = JSONObject.fromObject(map);
  2292. jSONArray.add(jSONObject);
  2293. }
  2294. json.put("result", jSONArray);
  2295. }
  2296. }
  2297. return json.toString();
  2298. }
  2299. @Override
  2300. public String getSyncrtuDataFexcelList(String queryJson)
  2301. throws Exception {
  2302. String company_code = null;
  2303. String company_code_list = null;
  2304. String device_id = null;
  2305. String device_id_list = null;
  2306. String dwtype = null;
  2307. String dwtype_list = null;
  2308. String point_code = null;
  2309. String point_code_list = null;
  2310. String id = null;
  2311. String id_list = null;
  2312. String company = null;
  2313. String data_time_start = null;
  2314. String data_time_end = null;
  2315. String name = null;
  2316. String Company_Code_List = null;
  2317. String V_LOGINNAME = null;
  2318. String hqlwhere = null;
  2319. String order = null;
  2320. String dir = null;
  2321. String Start = null;
  2322. String Limit = null;
  2323. String Page = null;
  2324. String order_str = null;
  2325. JSONObject q_json = null;
  2326. JSONArray Sort = null;
  2327. JSONArray jSONArray = new JSONArray();
  2328. JSONObject json = new JSONObject();
  2329. json.put("action", "getSyncDataVList");
  2330. if(queryJson!=null) {
  2331. q_json = JSONObject.fromObject(queryJson);
  2332. if(q_json.has("company_code")) {
  2333. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  2334. JSONArray j_tmp = q_json.getJSONArray("company_code");
  2335. for(int i=0;i<j_tmp.size();i++) {
  2336. if(i==0)
  2337. company_code_list = j_tmp.getString(i);
  2338. else
  2339. company_code_list += ","+j_tmp.getString(i);
  2340. }
  2341. }else
  2342. company_code = q_json.getString("company_code");
  2343. }
  2344. if(q_json.has("device_id")) {
  2345. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  2346. JSONArray j_tmp = q_json.getJSONArray("device_id");
  2347. for(int i=0;i<j_tmp.size();i++) {
  2348. if(i==0)
  2349. device_id_list = j_tmp.getString(i);
  2350. else
  2351. device_id_list += ","+j_tmp.getString(i);
  2352. }
  2353. }else
  2354. device_id = q_json.getString("device_id");
  2355. }
  2356. dwtype= "6";
  2357. if(q_json.has("point_code")) {
  2358. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray())) {
  2359. JSONArray j_tmp = q_json.getJSONArray("point_code");
  2360. for(int i=0;i<j_tmp.size();i++) {
  2361. if(i==0)
  2362. point_code_list = j_tmp.getString(i);
  2363. else
  2364. point_code_list += ","+j_tmp.getString(i);
  2365. }
  2366. }else
  2367. point_code = q_json.getString("point_code");
  2368. }
  2369. if(q_json.has("id")) {
  2370. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  2371. JSONArray j_tmp = q_json.getJSONArray("id");
  2372. for(int i=0;i<j_tmp.size();i++) {
  2373. if(i==0)
  2374. id_list = j_tmp.getString(i);
  2375. else
  2376. id_list += ","+j_tmp.getString(i);
  2377. }
  2378. }else
  2379. id = q_json.getString("id");
  2380. }
  2381. company = q_json.has("company")?q_json.getString("company"):null;
  2382. data_time_start = q_json.has("data_time_start")?q_json.getString("data_time_start"):null;
  2383. data_time_end = q_json.has("data_time_end")?q_json.getString("data_time_end"):null;
  2384. name = q_json.has("name")?q_json.getString("name"):null;
  2385. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  2386. Page = q_json.has("page")?q_json.getString("page"):null;
  2387. order = q_json.has("order")?q_json.getString("order"):null;
  2388. dir = q_json.has("dir")?q_json.getString("dir"):null;
  2389. Start = q_json.has("start")?q_json.getString("start"):null;
  2390. Limit = q_json.has("limit")?q_json.getString("limit"):null;
  2391. }
  2392. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  2393. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  2394. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  2395. if(list.size()>0) {
  2396. for(int i=0;i<list.size();i++) {
  2397. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  2398. YtiotVUsercompanyId oid = o.getId();
  2399. if(i==0)
  2400. Company_Code_List = oid.getOwnerCode();
  2401. else
  2402. Company_Code_List += ","+oid.getOwnerCode();
  2403. }
  2404. }
  2405. }
  2406. if(device_id!=null)
  2407. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  2408. else {
  2409. if(company!=null) {
  2410. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  2411. }
  2412. if(Company_Code_List!=null)
  2413. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  2414. else {
  2415. if(company_code!=null)
  2416. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  2417. if(company_code_list!=null)
  2418. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  2419. }
  2420. }
  2421. if(device_id_list!=null)
  2422. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id+") ";
  2423. if(dwtype!=null)
  2424. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  2425. if(dwtype_list!=null)
  2426. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  2427. if(point_code!=null)
  2428. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  2429. if(point_code_list!=null)
  2430. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  2431. if(id!=null)
  2432. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  2433. if(id_list!=null)
  2434. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  2435. if(data_time_start!=null)
  2436. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  2437. if(data_time_end!=null)
  2438. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  2439. if(name!=null)
  2440. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  2441. int totalCount = ytiotVDataDao.getSyncDataCount(hqlwhere);
  2442. json.put("totalCount", totalCount);
  2443. if(Start!=null){
  2444. if(Integer.parseInt(Start)>totalCount){
  2445. Start = "0";
  2446. Page = "0";
  2447. }else if(Page==null)
  2448. Page="0";
  2449. }else{
  2450. Start = "0";
  2451. Page = "0";
  2452. }
  2453. json.put("page", Page);
  2454. json.put("start", Start);
  2455. json.put("limit", Limit);
  2456. if(order!=null) {
  2457. order_str = " order by "+fieldname(order)+" ";
  2458. } else {
  2459. order_str = " order by data_time ";
  2460. dir = "DESC";
  2461. }
  2462. if(totalCount>0) {
  2463. List<?> list = ytiotVDataDao.SyncDataQuery(hqlwhere, order_str, dir, Start, Limit);
  2464. if(list.size()>0) {
  2465. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2466. for(int i=0;i<list.size();i++) {
  2467. YtiotVSyncData o = (YtiotVSyncData)list.get(i);
  2468. YtiotVSyncDataId oid = o.getId();
  2469. @SuppressWarnings("rawtypes")
  2470. Map<String, Comparable> map = new HashMap<String, Comparable>();
  2471. map.put("company", oid.getCompany());
  2472. map.put("company_code", oid.getCompanyCode());
  2473. map.put("content", oid.getContent());
  2474. map.put("data_time", df.format(oid.getDataTime()));
  2475. map.put("device_id", oid.getDeviceId());
  2476. map.put("dwtype", oid.getDwtype());
  2477. map.put("id", oid.getId());
  2478. map.put("name", oid.getName());
  2479. map.put("native_id", oid.getNativeId());
  2480. map.put("point_code", oid.getPointCode());
  2481. map.put("point_data", oid.getPointData());
  2482. JSONObject jSONObject = JSONObject.fromObject(map);
  2483. jSONArray.add(jSONObject);
  2484. }
  2485. json.put("result", jSONArray);
  2486. }
  2487. }
  2488. return json.toString();
  2489. }
  2490. @Override
  2491. public String getSyncfireDataVList(String queryJson, String page, String start, String limit, String sort)
  2492. throws Exception {
  2493. // TODO Auto-generated method stub
  2494. String company_code = null;
  2495. String company_code_list = null;
  2496. String device_id = null;
  2497. String device_id_list = null;
  2498. String device_type = null;
  2499. String dwtype = null;
  2500. String dwtype_list = null;
  2501. String point_code = null;
  2502. String point_code_list = null;
  2503. String id = null;
  2504. String id_list = null;
  2505. String company = null;
  2506. String data_time_start = null;
  2507. String data_time_end = null;
  2508. String name = null;
  2509. String Company_Code_List = null;
  2510. String V_LOGINNAME = null;
  2511. String hqlwhere = null;
  2512. String order = null;
  2513. String dir = null;
  2514. String Start = null;
  2515. String Limit = null;
  2516. String Page = null;
  2517. String order_str = null;
  2518. JSONObject q_json = null;
  2519. JSONArray Sort = null;
  2520. JSONArray jSONArray = new JSONArray();
  2521. JSONObject json = new JSONObject();
  2522. json.put("action", "getSyncDataVList");
  2523. if(queryJson!=null) {
  2524. q_json = JSONObject.fromObject(queryJson);
  2525. if(q_json.has("company_code")) {
  2526. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  2527. JSONArray j_tmp = q_json.getJSONArray("company_code");
  2528. for(int i=0;i<j_tmp.size();i++) {
  2529. if(i==0)
  2530. company_code_list = j_tmp.getString(i);
  2531. else
  2532. company_code_list += ","+j_tmp.getString(i);
  2533. }
  2534. }else
  2535. company_code = q_json.getString("company_code");
  2536. }
  2537. if(q_json.has("device_id")) {
  2538. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  2539. JSONArray j_tmp = q_json.getJSONArray("device_id");
  2540. for(int i=0;i<j_tmp.size();i++) {
  2541. if(i==0)
  2542. device_id_list = j_tmp.getString(i);
  2543. else
  2544. device_id_list += ","+j_tmp.getString(i);
  2545. }
  2546. }else
  2547. device_id = q_json.getString("device_id");
  2548. }
  2549. // for(int i=0;i<2;i++) {
  2550. // if(i==0)
  2551. // dwtype_list = "2";
  2552. // else
  2553. // dwtype_list += ","+"5";
  2554. // }
  2555. dwtype = "7";
  2556. point_code = "64";
  2557. if(q_json.has("id")) {
  2558. if((q_json.optJSONObject("id")!=null)&&(q_json.optJSONObject("id").isArray())) {
  2559. JSONArray j_tmp = q_json.getJSONArray("id");
  2560. for(int i=0;i<j_tmp.size();i++) {
  2561. if(i==0)
  2562. id_list = j_tmp.getString(i);
  2563. else
  2564. id_list += ","+j_tmp.getString(i);
  2565. }
  2566. }else
  2567. id = q_json.getString("id");
  2568. }
  2569. company = q_json.has("company")?q_json.getString("company"):null;
  2570. data_time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  2571. data_time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  2572. name = q_json.has("name")?q_json.getString("name"):null;
  2573. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  2574. }
  2575. if(sort!=null) {
  2576. Sort = JSONArray.fromObject(sort);
  2577. if((Sort.isArray())&&(Sort.size()>0)) {
  2578. JSONObject s_json = Sort.getJSONObject(0);
  2579. order = s_json.has("property")?s_json.getString("property"):order;
  2580. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  2581. }
  2582. json.put("sort", sort);
  2583. }
  2584. Start = start;
  2585. Limit = limit;
  2586. Page = page;
  2587. if(!V_LOGINNAME.equals("admin")) {
  2588. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  2589. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  2590. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  2591. if(list.size()>0) {
  2592. for(int i=0;i<list.size();i++) {
  2593. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  2594. YtiotVUsercompanyId oid = o.getId();
  2595. if(i==0)
  2596. Company_Code_List = oid.getOwnerCode();
  2597. else
  2598. Company_Code_List += ","+oid.getOwnerCode();
  2599. }
  2600. }
  2601. }
  2602. }
  2603. if(device_id!=null)
  2604. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" = '"+device_id+"' ";
  2605. else {
  2606. if(company!=null) {
  2607. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  2608. }
  2609. if(Company_Code_List!=null)
  2610. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  2611. else {
  2612. if(company_code!=null)
  2613. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  2614. if(company_code_list!=null)
  2615. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  2616. }
  2617. }
  2618. if(device_id_list!=null)
  2619. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" in ("+device_id_list+") ";
  2620. if(dwtype!=null)
  2621. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  2622. if(dwtype_list!=null)
  2623. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype_list+") ";
  2624. if(point_code!=null)
  2625. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" > ("+point_code+") ";
  2626. if(point_code_list!=null)
  2627. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code_list+") ";
  2628. if(id!=null)
  2629. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" = "+id+" ";
  2630. if(id_list!=null)
  2631. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("id")+" in ("+id_list+") ";
  2632. if(data_time_start!=null)
  2633. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" >= '"+data_time_start+"' ";
  2634. if(data_time_end!=null)
  2635. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("data_time")+" <= '"+data_time_end+"' ";
  2636. if(name!=null)
  2637. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("name")+" like '%"+name+"%' ";
  2638. int totalCount = ytiotVDataDao.getSyncStatusCount(hqlwhere);
  2639. json.put("totalCount", totalCount);
  2640. if(Start!=null){
  2641. if(Integer.parseInt(Start)>totalCount){
  2642. Start = "0";
  2643. Page = "0";
  2644. }else if(page==null)
  2645. Page="0";
  2646. }else{
  2647. Start = "0";
  2648. Page = "0";
  2649. }
  2650. json.put("page", Page);
  2651. json.put("start", Start);
  2652. json.put("limit", Limit);
  2653. if(order!=null) {
  2654. order_str = " order by data_time ";
  2655. } else {
  2656. order_str = " order by device_id ";
  2657. dir = "DESC";
  2658. }
  2659. if(totalCount>0) {
  2660. List<?> list = ytiotVDataDao.SyncStatusQuery(hqlwhere, order_str, dir, Start, Limit);
  2661. if(list.size()>0) {
  2662. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2663. for(int i=0;i<list.size();i++) {
  2664. YtiotVSyncStatus o = (YtiotVSyncStatus)list.get(i);
  2665. YtiotVSyncStatusId oid = o.getId();
  2666. @SuppressWarnings("rawtypes")
  2667. Map<String, Comparable> map = new HashMap<String, Comparable>();
  2668. map.put("device_type", "电气火灾");
  2669. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  2670. map.put("company", oid.getCompany());
  2671. map.put("company_code", oid.getCompanyCode());
  2672. map.put("data_time", df.format(oid.getDataTime()));
  2673. map.put("device_id", oid.getDeviceId());
  2674. map.put("dwtype", oid.getDwtype());
  2675. map.put("id", oid.getId());
  2676. map.put("name", oid.getName());
  2677. // map.put("native_id", oid.getNativeId());
  2678. map.put("point_code", oid.getPointCode());
  2679. map.put("point_name", oid.getPointName());
  2680. map.put("point_data", oid.getPointData());
  2681. JSONObject jSONObject = JSONObject.fromObject(map);
  2682. jSONArray.add(jSONObject);
  2683. }
  2684. json.put("RESULT", jSONArray);
  2685. }
  2686. }
  2687. return json.toString();
  2688. }
  2689. @Override
  2690. public String getSyncStatusVList(String queryJson, String page, String start, String limit, String sort)
  2691. throws Exception {
  2692. // TODO Auto-generated method stub
  2693. String company = null;
  2694. String company_code = null;
  2695. String company_code_list = null;
  2696. String device_id = null;
  2697. String device_id_list = null;
  2698. String dwtype = null;
  2699. String dwtype_list = null;
  2700. String point_code = null;
  2701. String point_code_list = null;
  2702. String Company_Code_List = null;
  2703. String V_LOGINNAME = null;
  2704. String hqlwhere = null;
  2705. String order = null;
  2706. String dir = null;
  2707. String Start = null;
  2708. String Limit = null;
  2709. String Page = null;
  2710. String order_str = null;
  2711. JSONObject q_json = null;
  2712. JSONArray Sort = null;
  2713. JSONArray jSONArray = new JSONArray();
  2714. JSONObject json = new JSONObject();
  2715. json.put("action", "getSyncStatusVList");
  2716. if(queryJson!=null) {
  2717. q_json = JSONObject.fromObject(queryJson);
  2718. company = q_json.has("company")?q_json.getString("company"):null;
  2719. if(q_json.has("company_code")) {
  2720. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  2721. JSONArray j_tmp = q_json.getJSONArray("company_code");
  2722. for(int i=0;i<j_tmp.size();i++) {
  2723. if(i==0)
  2724. company_code_list = j_tmp.getString(i);
  2725. else
  2726. company_code_list += ","+j_tmp.getString(i);
  2727. }
  2728. }else
  2729. company_code = q_json.getString("company_code");
  2730. }
  2731. if(q_json.has("device_id")) {
  2732. if((q_json.optJSONObject("device_id")!=null)&&(q_json.optJSONObject("device_id").isArray())) {
  2733. JSONArray j_tmp = q_json.getJSONArray("device_id");
  2734. for(int i=0;i<j_tmp.size();i++) {
  2735. if(i==0)
  2736. device_id_list = j_tmp.getString(i);
  2737. else
  2738. device_id_list += ","+j_tmp.getString(i);
  2739. }
  2740. }else
  2741. device_id = q_json.getString("device_id");
  2742. }
  2743. if(q_json.has("dwtype")) {
  2744. if((q_json.optJSONObject("dwtype")!=null)&&(q_json.optJSONObject("dwtype").isArray())) {
  2745. JSONArray j_tmp = q_json.getJSONArray("dwtype");
  2746. for(int i=0;i<j_tmp.size();i++) {
  2747. if(i==0)
  2748. dwtype_list = j_tmp.getString(i);
  2749. else
  2750. dwtype_list += ","+j_tmp.getString(i);
  2751. }
  2752. }else
  2753. dwtype = q_json.getString("dwtype");
  2754. }
  2755. if(q_json.has("point_code")) {
  2756. if((q_json.optJSONObject("point_code")!=null)&&(q_json.optJSONObject("point_code").isArray()) ){
  2757. JSONArray j_tmp = q_json.getJSONArray("point_code");
  2758. for(int i=0;i<j_tmp.size();i++) {
  2759. if(i==0)
  2760. point_code_list = j_tmp.getString(i);
  2761. else
  2762. point_code_list += j_tmp.getString(i);
  2763. }
  2764. }else
  2765. point_code = q_json.getString("point_code");
  2766. }
  2767. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  2768. }
  2769. if(sort!=null) {
  2770. Sort = JSONArray.fromObject(sort);
  2771. if((Sort.isArray())&&(Sort.size()>0)) {
  2772. JSONObject s_json = Sort.getJSONObject(0);
  2773. order = s_json.has("property")?s_json.getString("property"):order;
  2774. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  2775. }
  2776. json.put("sort", sort);
  2777. }
  2778. Start = start;
  2779. Limit = limit;
  2780. Page = page;
  2781. if(V_LOGINNAME!=null) {
  2782. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  2783. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  2784. if(list.size()>0) {
  2785. for(int i=0;i<list.size();i++) {
  2786. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  2787. YtiotVUsercompanyId oid = o.getId();
  2788. if(i==0)
  2789. Company_Code_List = oid.getOwnerCode();
  2790. else
  2791. Company_Code_List += ","+oid.getOwnerCode();
  2792. }
  2793. }
  2794. }
  2795. if(company!=null) {
  2796. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  2797. }
  2798. if(Company_Code_List!=null)
  2799. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  2800. if(company_code!=null)
  2801. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  2802. if(company_code_list!=null)
  2803. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  2804. if(device_id!=null)
  2805. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" like '%"+device_id+"%' ";
  2806. if(device_id_list!=null)
  2807. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("device_id")+" ("+device_id_list+") ";
  2808. if(dwtype!=null) {
  2809. if(dwtype.equals("2")||dwtype.equals("5"))
  2810. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in (2,5) ";
  2811. else
  2812. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" = "+dwtype+" ";
  2813. }
  2814. if(dwtype_list!=null)
  2815. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("dwtype")+" in ("+dwtype+") ";
  2816. if(point_code!=null)
  2817. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" = "+point_code+" ";
  2818. if(point_code_list!=null)
  2819. hqlwhere = chkhw(hqlwhere)+" u.id."+fieldname("point_code")+" in ("+point_code+") ";
  2820. int totalCount = ytiotVDataDao.getSyncStatusCount(hqlwhere);
  2821. json.put("totalCount", totalCount);
  2822. if(Start!=null){
  2823. if(Integer.parseInt(Start)>totalCount){
  2824. Start = "0";
  2825. Page = "0";
  2826. }else if(page==null)
  2827. Page="0";
  2828. }else{
  2829. Start = "0";
  2830. Page = "0";
  2831. }
  2832. if(totalCount>0) {
  2833. List<?> list = ytiotVDataDao.SyncStatusQuery(hqlwhere, order_str, dir, Start, Limit);
  2834. if(list.size()>0) {
  2835. Date date = new Date();
  2836. Calendar calendar = Calendar.getInstance();
  2837. calendar.setTime(date);
  2838. calendar.add(Calendar.DATE, -1);
  2839. date = calendar.getTime();
  2840. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2841. String datime =df.format(date);
  2842. for(int i=0;i<list.size();i++) {
  2843. YtiotVSyncStatus o = (YtiotVSyncStatus)list.get(i);
  2844. YtiotVSyncStatusId oid = o.getId();
  2845. String bzsql15 = null;
  2846. bzsql15 = "SELECT device_id,IF((data_time<'"+datime+"'),0,1) AS connected FROM ytiot_v_sync_status WHERE device_id = '"+oid.getDeviceId().toString()+"' AND point_code = 2";
  2847. List bzlist15 = ytiotVAlarmDao.queryBySQL(bzsql15);
  2848. Object [] bzrow = (Object [])bzlist15.get(0);
  2849. @SuppressWarnings("rawtypes")
  2850. Map<String, Comparable> map = new HashMap<String, Comparable>();
  2851. map.put("ordIdx", Integer.parseInt(Start)+i+1);
  2852. map.put("company", oid.getCompany());
  2853. map.put("company_code", oid.getCompanyCode());
  2854. map.put("content", oid.getContent());
  2855. map.put("data_time", df.format(oid.getDataTime()));
  2856. map.put("device_id", oid.getDeviceId());
  2857. map.put("dwtype", oid.getDwtype());
  2858. map.put("id", oid.getId());
  2859. map.put("name", oid.getName());
  2860. map.put("point_code", oid.getPointCode());
  2861. map.put("point_data", oid.getPointData());
  2862. map.put("connected", Integer.parseInt(bzrow[1].toString())==1?"正常":"离线");
  2863. JSONObject jSONObject = JSONObject.fromObject(map);
  2864. jSONArray.add(jSONObject);
  2865. }
  2866. json.put("RESULT", jSONArray);
  2867. }
  2868. }
  2869. json.put("page", Page);
  2870. json.put("start", Start);
  2871. json.put("limit", Limit);
  2872. return json.toString();
  2873. }
  2874. @Override
  2875. public String getSyncStatusVListByCompany(String queryJson) throws Exception {
  2876. // TODO Auto-generated method stub
  2877. String company = null;
  2878. String company_code = null;
  2879. String company_code_list = null;
  2880. String Company_Code_List = null;
  2881. String dwtype = null;
  2882. String point_code = null;
  2883. String V_LOGINNAME = null;
  2884. String V_PASSWORD = null;
  2885. String QUERY_FROM = null;
  2886. String COMMSTATUS = null;
  2887. String hqlwhere = null;
  2888. String cqlwhere = null;
  2889. int E_STATUS=-1;
  2890. JSONObject q_json = null;
  2891. JSONArray jSONArray = new JSONArray();
  2892. JSONObject json = new JSONObject();
  2893. json.put("action", "getSyncStatusVListByCompany");
  2894. if(queryJson!=null) {
  2895. q_json = JSONObject.fromObject(queryJson);
  2896. company = q_json.has("company")?q_json.getString("company"):null;
  2897. dwtype = q_json.has("dwtype")?q_json.getString("dwtype"):null;
  2898. point_code = q_json.has("point_code")?q_json.getString("point_code"):null;
  2899. QUERY_FROM = q_json.has("QUERY_FROM")?q_json.getString("QUERY_FROM"):null;
  2900. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  2901. if(q_json.has("company_code")) {
  2902. if((q_json.optJSONObject("company_code")!=null)&&(q_json.optJSONObject("company_code").isArray())) {
  2903. if(q_json.getJSONObject("company_code").isArray()) {
  2904. JSONArray j_tmp = q_json.getJSONArray("company_code");
  2905. for(int i=0;i<j_tmp.size();i++) {
  2906. if(i==0)
  2907. company_code_list = j_tmp.getString(i);
  2908. else
  2909. company_code_list += ","+j_tmp.getString(i);
  2910. }
  2911. }else
  2912. company_code = q_json.getString("company_code");
  2913. }else
  2914. company_code = q_json.getString("company_code");
  2915. }
  2916. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  2917. V_PASSWORD = q_json.has("V_PASSWORD")?q_json.getString("V_PASSWORD"):null;
  2918. }
  2919. if((V_LOGINNAME!=null)&&(V_PASSWORD!=null)) {
  2920. List list = ytiotTAdminDao.query(" where u.VLoginname='"+V_LOGINNAME+"' and u.VPassword='"
  2921. +MD5Util.EncoderByMd5(MD5Util.EncoderByMd5(V_PASSWORD))+"' ", null, null, null, null);
  2922. if(list.size()>0) {
  2923. YtiotTAdmin o = (YtiotTAdmin)list.get(0);
  2924. E_STATUS = Integer.parseInt(o.getEStatus());
  2925. }
  2926. }
  2927. if(E_STATUS==1) {
  2928. if(company!=null) {
  2929. cqlwhere = chkhw(cqlwhere)+" u.id."+fieldname("owner_name")+" like '%"+company+"%' ";
  2930. }
  2931. if(!V_LOGINNAME.equals("admin")) {
  2932. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  2933. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  2934. if(list.size()>0) {
  2935. for(int i=0;i<list.size();i++) {
  2936. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  2937. YtiotVUsercompanyId oid = o.getId();
  2938. if(i==0)
  2939. Company_Code_List = oid.getOwnerCode();
  2940. else
  2941. Company_Code_List += ","+oid.getOwnerCode();
  2942. }
  2943. }
  2944. }
  2945. List vlist = ytiotVAlarmDao.queryBySQL("select count(*) as count, company_code from ytiot_v_video group by company_code");
  2946. if(company_code!=null)
  2947. cqlwhere = chkhw(cqlwhere) + " u.id."+fieldname("owner_id")+" like '%"+company_code+"%' ";
  2948. if(company_code_list!=null)
  2949. cqlwhere = chkhw(cqlwhere) + " u.id."+fieldname("owner_id")+" in ("+company_code_list+") ";
  2950. else if(Company_Code_List!=null)
  2951. cqlwhere = chkhw(cqlwhere) + " u.id."+fieldname("owner_id")+" in ("+Company_Code_List+") ";
  2952. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2953. // if((QUERY_FROM!=null)&&(COMMSTATUS!=null)&&(QUERY_FROM.equals("FRONTPAGE")&&(COMMSTATUS.equals("NO")))) {
  2954. // @SuppressWarnings("rawtypes")
  2955. // List c_list = ytiotVCompanyDao.query(cqlwhere, null, null, null, null);
  2956. //
  2957. // }else {
  2958. Company_Code_List = null;
  2959. @SuppressWarnings("rawtypes")
  2960. List c_list = ytiotVCompanyDao.query(cqlwhere, null, null, null, null);
  2961. float maxlng=0,minlng=0,maxlat=0,minlat=0;
  2962. int count=0;
  2963. if(c_list.size()>0) {
  2964. for(int i=0;i<c_list.size();i++) {
  2965. boolean fireAlarm=false,waterAlarm=false,rtuAlarm=false,efireAlarm=false,otherAlarm=false;
  2966. YtiotVCompany com = (YtiotVCompany)c_list.get(i);
  2967. YtiotVCompanyId ComId = com.getId();
  2968. if(i==0)
  2969. Company_Code_List = ComId.getOwnerId();
  2970. else
  2971. Company_Code_List += ","+ComId.getOwnerId();
  2972. Map<String, Comparable> cmap = new HashMap<String, Comparable>();
  2973. cmap.put("id", i+1);
  2974. cmap.put("company_name", ComId.getOwnerName());
  2975. cmap.put("fulladdress", ComId.getFulladdress());
  2976. cmap.put("xmlx", ComId.getXmlx());
  2977. cmap.put("username", ComId.getUsername());
  2978. cmap.put("phone", ComId.getPhone());
  2979. if(dwtype==null) {
  2980. String[] gis = ComId.getPosition().split(",");
  2981. if(gis.length==2) {
  2982. float lng = Float.parseFloat(gis[0]);
  2983. float lat = Float.parseFloat(gis[1]);
  2984. if((lng>100)&&(lng<150)&&(lat>20)&&(lat<70)) {
  2985. if(count==0) {
  2986. maxlng = lng;
  2987. minlng = lng;
  2988. maxlat = lat;
  2989. minlat = lat;
  2990. }else {
  2991. if(maxlng<lng)
  2992. maxlng=lng;
  2993. if(minlng>lng)
  2994. minlng=lng;
  2995. if(maxlat<lat)
  2996. maxlat=lat;
  2997. if(minlat>lat)
  2998. minlat=lat;
  2999. }
  3000. count++;
  3001. }
  3002. cmap.put("lng", lng);
  3003. cmap.put("lat", lat);
  3004. }else {
  3005. cmap.put("lng", 0.0);
  3006. cmap.put("lat", 0.0);
  3007. }
  3008. }
  3009. cmap.put("company_code", ComId.getOwnerId());
  3010. cmap.put("building_name", ComId.getBuildingName());
  3011. cmap.put("rtmp", ComId.getRtmp());
  3012. if(dwtype!=null) {
  3013. JSONArray a_point = new JSONArray();
  3014. hqlwhere = " where u.id."+fieldname("company_code")+" ='"+ComId.getOwnerId()+"' ";
  3015. if(dwtype.equals("2")||dwtype.equals("5"))
  3016. hqlwhere += " and ( u.id.dwtype='2' or u.id.dwtype='5' ) ";
  3017. else
  3018. hqlwhere += " and u.id.dwtype='"+dwtype+"' ";
  3019. if(point_code!=null)
  3020. hqlwhere += " and u.id.pointCode="+point_code+" ";
  3021. List list = ytiotVDataDao.SyncStatusQuery(hqlwhere, null, null, null, null);
  3022. cmap.put("list_count", list.size());
  3023. if(list.size()>0) {
  3024. for(int j=0;j<list.size();j++) {
  3025. YtiotVSyncStatus o = (YtiotVSyncStatus)list.get(j);
  3026. YtiotVSyncStatusId oid = o.getId();
  3027. @SuppressWarnings("rawtypes")
  3028. Map<String, Comparable> map = new HashMap<String, Comparable>();
  3029. map.put("content", oid.getContent());
  3030. map.put("data_time", df.format(oid.getDataTime()));
  3031. map.put("device_id", oid.getDeviceId());
  3032. map.put("dwtype", oid.getDwtype());
  3033. map.put("name", oid.getName());
  3034. map.put("point_code", oid.getPointCode());
  3035. map.put("point_data", oid.getPointData());
  3036. JSONObject JObject = JSONObject.fromObject(map);
  3037. a_point.add(JObject);
  3038. if(dwtype==null) {
  3039. if(oid.getPointCode().equals("0")) {
  3040. if(!oid.getPointData().equals("0")) {
  3041. if(oid.getDwtype()==1)
  3042. fireAlarm = true;
  3043. else if(oid.getDwtype()==2)
  3044. waterAlarm = true;
  3045. else if(oid.getDwtype()==5)
  3046. waterAlarm = true;
  3047. else if(oid.getDwtype()==6)
  3048. rtuAlarm = true;
  3049. else if(oid.getDwtype()==7)
  3050. efireAlarm = true;
  3051. else
  3052. otherAlarm = true;
  3053. }
  3054. }
  3055. }
  3056. }
  3057. }
  3058. cmap.put("point_list", a_point);
  3059. }else {
  3060. if(ComId.getD1a()>ComId.getD1ac())
  3061. fireAlarm = true;
  3062. if((ComId.getD0a()+ComId.getD2a())>(ComId.getD0ac()+ComId.getD2ac()))
  3063. waterAlarm = true;
  3064. if(ComId.getD6a()>ComId.getD6ac())
  3065. otherAlarm = true;
  3066. }
  3067. cmap.put("fire_alarm", fireAlarm);
  3068. cmap.put("water_alarm", waterAlarm);
  3069. cmap.put("rtu_alarm", rtuAlarm);
  3070. cmap.put("efire_alarm", efireAlarm);
  3071. cmap.put("other_alarm", otherAlarm);
  3072. if(ComId.getOwnerId().equals("10122"))
  3073. cmap.put("has_video", true);
  3074. else
  3075. cmap.put("has_video", false);
  3076. JSONObject jSONObject = JSONObject.fromObject(cmap);
  3077. jSONArray.add(jSONObject);
  3078. }
  3079. if(dwtype==null) {
  3080. json.put("avelng", (maxlng+minlng)/2);
  3081. json.put("avelat", (maxlat+minlat)/2);
  3082. }
  3083. json.put("RESULT", jSONArray);
  3084. }
  3085. // }
  3086. if((QUERY_FROM!=null)&&(COMMSTATUS!=null)&&(QUERY_FROM.equals("FRONTPAGE")&&(COMMSTATUS.equals("NO")))) {
  3087. String sql = "select count(*) as count, sum(clzt) as sum from ytiot_v_hj where data1<>'U44' "+((Company_Code_List!=null)?" and company_code in ("+Company_Code_List+")":"");
  3088. List list2 = null, list3 = null, list4 = null, list5 = null;
  3089. JSONArray jSONArray2 = new JSONArray();
  3090. JSONArray jSONArray3 = new JSONArray();
  3091. JSONArray jSONArray4 = new JSONArray();
  3092. sql = "select sum(d0) as d0, sum(d0o) as d0o, sum(d0oc) as d0oc, sum(d0a) as d0a, sum(d0ac) as d0ac, "
  3093. + " sum(d1) as d1, sum(d1o) as d1o, sum(d1oc) as d1oc, sum(d1a) as d1a, sum(d1ac) as d1ac,"
  3094. + " sum(d2) as d2, sum(d2o) as d2o, sum(d2oc) as d2oc, sum(d2a) as d2a, sum(d2ac) as d2ac,"
  3095. + " sum(d6) as d6, sum(d6o) as d6o, sum(d6oc) as d6oc, sum(d6a) as d6a, sum(d6ac) as d6ac, "
  3096. + " sum(d7) as d7, sum(d7o) as d7o, sum(d7oc) as d7oc, sum(d7a) as d7a, sum(d7ac) as d7ac "
  3097. + " from ytiot_v_company "+((Company_Code_List!=null)?" where owner_id in ("+Company_Code_List+") ":"");
  3098. List list = ytiotVAlarmDao.queryBySQL(sql);
  3099. if(list.size()>0) {
  3100. Object[] objects = (Object[]) list.get(0);
  3101. if(Integer.parseInt(objects[8].toString())>Integer.parseInt(objects[9].toString()))
  3102. list2 = ytiotVAlarmDao.HJQuery(" where u.id.data1<>'U44' "+((Company_Code_List!=null)?" and u.id.companyCode in ("+Company_Code_List+") ":""), "order by u.id.id", "desc", "0", "1");
  3103. if((Integer.parseInt(objects[3].toString())+Integer.parseInt(objects[13].toString()))
  3104. >(Integer.parseInt(objects[4].toString())+Integer.parseInt(objects[14].toString())))
  3105. list3 = ytiotVAlarmDao.SJQuery(" where u.id.data1<>'U44'"+((Company_Code_List!=null)?" and u.id.companyCode in ("+Company_Code_List+") ":""), " order by u.id.id ", "desc", "0", "1");
  3106. if(Integer.parseInt(objects[18].toString())>Integer.parseInt(objects[19].toString()))
  3107. list4 = ytiotVAlarmDao.RTUQuery(" where u.id.data1<>'U44'"+((Company_Code_List!=null)?" and u.id.companyCode in ("+Company_Code_List+") ":" "), " order by u.id.id ", "desc", "0", "1");
  3108. if(Integer.parseInt(objects[23].toString())>Integer.parseInt(objects[24].toString()))
  3109. list5 = ytiotVAlarmDao.queryBySQL("select id, company_name, name, data1, time, clzt from ytiot_v_efire where data1<>'EF9' "+((Company_Code_List!=null)?" and company_code in ("+Company_Code_List+")":"")+" order by id desc limit 0, 1");
  3110. Map map = new HashMap();
  3111. map.put("id", "fire_info");
  3112. map.put("device", Integer.parseInt(objects[5].toString()));
  3113. map.put("out", Integer.parseInt(objects[6].toString()));
  3114. map.put("outConfirm", Integer.parseInt(objects[7].toString()));
  3115. map.put("alarm", Integer.parseInt(objects[8].toString()));
  3116. map.put("alarmConfirm", Integer.parseInt(objects[9].toString()));
  3117. JSONObject jSONObject = JSONObject.fromObject(map);
  3118. jSONArray2.add(jSONObject);
  3119. Map map2 = new HashMap();
  3120. map2.put("id", "water_info");
  3121. map2.put("device", Integer.parseInt(objects[0].toString())+Integer.parseInt(objects[10].toString()));
  3122. map2.put("out", Integer.parseInt(objects[1].toString())+Integer.parseInt(objects[11].toString()));
  3123. map2.put("outConfirm", Integer.parseInt(objects[2].toString())+Integer.parseInt(objects[12].toString()));
  3124. map2.put("alarm", Integer.parseInt(objects[3].toString())+Integer.parseInt(objects[13].toString()));
  3125. map2.put("alarmConfirm", Integer.parseInt(objects[4].toString())+Integer.parseInt(objects[14].toString()));
  3126. JSONObject jSONObject2 = JSONObject.fromObject(map2);
  3127. jSONArray2.add(jSONObject2);
  3128. Map map3 = new HashMap();
  3129. map3.put("id", "rtu_info");
  3130. map3.put("device", Integer.parseInt(objects[15].toString()));
  3131. map3.put("out", Integer.parseInt(objects[16].toString()));
  3132. map3.put("outConfirm", Integer.parseInt(objects[17].toString()));
  3133. map3.put("alarm", Integer.parseInt(objects[18].toString()));
  3134. map3.put("alarmConfirm", Integer.parseInt(objects[19].toString()));
  3135. JSONObject jSONObject3 = JSONObject.fromObject(map3);
  3136. jSONArray2.add(jSONObject3);
  3137. Map map4 = new HashMap();
  3138. map4.put("id","efire_info");
  3139. map4.put("device", Integer.parseInt(objects[20].toString()));
  3140. map4.put("out", Integer.parseInt(objects[21].toString()));
  3141. map4.put("outConfirm", Integer.parseInt(objects[22].toString()));
  3142. map4.put("alarm", Integer.parseInt(objects[23].toString()));
  3143. map4.put("alarmConfirm", Integer.parseInt(objects[24].toString()));
  3144. JSONObject jSONObject4 = JSONObject.fromObject(map4);
  3145. jSONArray2.add(jSONObject4);
  3146. list.clear();
  3147. }
  3148. json.put("confirm_status", jSONArray2);
  3149. // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  3150. YtiotVHjId HJid = new YtiotVHjId();
  3151. int maxIdx = 0;
  3152. Date dTmp = df.parse("1970-01-01 00:00:00");
  3153. HJid.setTime(df.parse("1970-01-01 00:00:00"));
  3154. if((list2!=null)&&(list2.size()>0)) {
  3155. YtiotVHj hj = (YtiotVHj)list2.get(0);
  3156. HJid = hj.getId();
  3157. if(HJid.getTime().getTime()>=dTmp.getTime())
  3158. maxIdx = 2;
  3159. }
  3160. YtiotVSjId SJid = new YtiotVSjId();
  3161. SJid.setTime(df.parse("1970-01-01 00:00:00"));
  3162. if((list3!=null)&&(list3.size()>0)) {
  3163. YtiotVSj sj = (YtiotVSj)list3.get(0);
  3164. SJid = sj.getId();
  3165. if(SJid.getTime().getTime()>=dTmp.getTime())
  3166. maxIdx = 3;
  3167. }
  3168. YtiotVRtuId RTUid = new YtiotVRtuId();
  3169. RTUid.setTime(df.parse("1970-01-01 00:00:00"));
  3170. if((list4!=null)&&(list4.size()>0)) {
  3171. YtiotVRtu rtu = (YtiotVRtu)list4.get(0);
  3172. RTUid = rtu.getId();
  3173. if(RTUid.getTime().getTime()>=dTmp.getTime())
  3174. maxIdx = 4;
  3175. }
  3176. if(list5!=null) {
  3177. Object[] objects = (Object[]) list5.get(0);
  3178. if(df.parse(objects[4].toString()).getTime()>=dTmp.getTime())
  3179. maxIdx = 5;
  3180. }
  3181. switch(maxIdx) {
  3182. case 2:
  3183. {
  3184. Map map = new HashMap();
  3185. map.put("id", 1);
  3186. map.put("company", HJid.getCompanyName());
  3187. map.put("name", HJid.getName()+((HJid.getData4().length()>0) ?(","+HJid.getData4()):""));
  3188. map.put("data", HJid.getData2());
  3189. map.put("time", df.format(HJid.getTime()));
  3190. map.put("clzt", HJid.getClzt()==1?"已处理":"未处理");
  3191. JSONObject jSONObject = JSONObject.fromObject(map);