YtiotVDataServiceImpl.java 77 KB

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