YtiotVDataServiceImpl.java 101 KB

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