YtiotVDataServiceImpl.java 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  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)