YtiotVAlarmServiceImpl.java 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299
  1. package cn.com.usky.iot.alarm.service;
  2. import java.io.BufferedReader;
  3. import java.sql.SQLException;
  4. import java.text.NumberFormat;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.Iterator;
  10. import java.util.List;
  11. import java.util.Map;
  12. import cn.com.usky.iot.admin.dao.YtiotTAdminDao;
  13. import cn.com.usky.iot.admin.dao.YtiotVUserCompanyDao;
  14. import cn.com.usky.iot.admin.dao.YtiotVUserphoneDao;
  15. import cn.com.usky.iot.alarm.dao.YtiotVAlarmDao;
  16. import cn.com.usky.iot.entity.*;
  17. import cn.com.usky.utils.DaoQuery;
  18. import cn.com.usky.utils.HttpClientUtils;
  19. import cn.com.usky.utils.MD5Util;
  20. import net.sf.json.JSONArray;
  21. import net.sf.json.JSONObject;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.apache.http.HttpEntity;
  24. import org.apache.http.HttpResponse;
  25. import org.apache.http.client.entity.UrlEncodedFormEntity;
  26. import org.apache.http.client.methods.HttpPost;
  27. import org.apache.http.impl.client.CloseableHttpClient;
  28. import org.apache.http.impl.client.DefaultHttpClient;
  29. import org.hibernate.HibernateException;
  30. import org.hibernate.Query;
  31. import org.hibernate.Session;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.orm.hibernate3.HibernateCallback;
  34. import org.springframework.orm.hibernate3.HibernateTemplate;
  35. import org.apache.http.message.BasicNameValuePair;
  36. import org.apache.http.protocol.HTTP;
  37. public class YtiotVAlarmServiceImpl implements YtiotVAlarmService {
  38. private HibernateTemplate hibernateTemplate;
  39. public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
  40. this.hibernateTemplate = hibernateTemplate;
  41. }
  42. private YtiotVAlarmDao ytiotVAlarmDao;
  43. private YtiotVUserphoneDao ytiotVUserphoneDao;
  44. private YtiotTAdminDao ytiotTAdminDao;
  45. private YtiotVUserCompanyDao ytiotVUserCompanyDao;
  46. public YtiotVAlarmDao getYtiotVAlarmDao() {
  47. return ytiotVAlarmDao;
  48. }
  49. public void setYtiotVAlarmDao(YtiotVAlarmDao ytiotVAlarmDao) {
  50. this.ytiotVAlarmDao = ytiotVAlarmDao;
  51. }
  52. public YtiotVUserCompanyDao getYtiotVUserCompanyDao() {
  53. return ytiotVUserCompanyDao;
  54. }
  55. public void setYtiotVUserCompanyDao(YtiotVUserCompanyDao ytiotVUserCompanyDao) {
  56. this.ytiotVUserCompanyDao = ytiotVUserCompanyDao;
  57. }
  58. public YtiotVUserphoneDao getYtiotVUserphoneDao() {
  59. return ytiotVUserphoneDao;
  60. }
  61. public void setYtiotVUserphoneDao(YtiotVUserphoneDao ytiotVUserphoneDao) {
  62. this.ytiotVUserphoneDao = ytiotVUserphoneDao;
  63. }
  64. public YtiotTAdminDao getYtiotTAdminDao() {
  65. return ytiotTAdminDao;
  66. }
  67. public void setYtiotTAdminDao(YtiotTAdminDao ytiotTAdminDao) {
  68. this.ytiotTAdminDao = ytiotTAdminDao;
  69. }
  70. public boolean chk_string_param(String param) {
  71. if(param==null)
  72. return true;
  73. if(param.indexOf("=")>=0)
  74. return false;
  75. if(param.indexOf("\'")>=0)
  76. return false;
  77. if(param.indexOf("\"")>=0)
  78. return false;
  79. return true;
  80. }
  81. public String chkhw(String hqlwhere){
  82. if(hqlwhere==null)
  83. return " where ";
  84. else
  85. return hqlwhere+" and ";
  86. }
  87. public String fieldname(String name) {
  88. if(name.equals("company_code"))
  89. return "companyCode";
  90. if(name.equals("company_name"))
  91. return "companyName";
  92. if(name.equals("device_code"))
  93. return "deviuceCode";
  94. return name;
  95. }
  96. @Override
  97. public String getEFireVList(String queryJson, String page, String start, String limit, String sort) throws Exception {
  98. // TODO Auto-generated method stub
  99. String address = null;
  100. String clzt = null;
  101. String company_code = null;
  102. String company_code_list = null;
  103. String Company_Code_List = null;
  104. String company_name = null;
  105. String device_code = null;
  106. String device_code_list = null;
  107. String time_start = null;
  108. String time_end = null;
  109. String status = null;
  110. String COMMSTATUS = null;
  111. String V_LOGINNAME = null;
  112. String hqlwhere = null, hhwhere = null;
  113. String order = null;
  114. String dir = null;
  115. String Start = null;
  116. String Limit = null;
  117. String Page = null;
  118. String order_str = null;
  119. JSONObject q_json = null;
  120. JSONArray Sort = null;
  121. JSONArray jSONArray = new JSONArray();
  122. JSONObject json = new JSONObject();
  123. json.put("action", "getEFireVList");
  124. if(queryJson!=null) {
  125. q_json = JSONObject.fromObject(queryJson);
  126. address = q_json.has("address")?q_json.getString("address"):null;
  127. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  128. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  129. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  130. if(q_json.has("company_code")) {
  131. if((q_json.optJSONObject("company_code")!=null)
  132. &&(q_json.optJSONObject("company_code").isArray())) {
  133. JSONArray j_tmp = q_json.getJSONArray("company_code");
  134. for(int i=0;i<j_tmp.size();i++) {
  135. String tmp = j_tmp.getString(i);
  136. if(i==0)
  137. company_code_list = tmp;
  138. else
  139. company_code_list += ","+tmp;
  140. }
  141. }else
  142. company_code = q_json.getString("company_code");
  143. }
  144. // company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  145. if(q_json.has("device_code")) {
  146. if((q_json.optJSONObject("device_code")!=null)
  147. &&(q_json.optJSONObject("device_code").isArray())){
  148. JSONArray j_tmp = q_json.getJSONArray("device_code");
  149. for(int i=0;i<j_tmp.size();i++) {
  150. String tmp = j_tmp.getString(i);
  151. if(i==0)
  152. device_code_list = tmp;
  153. else
  154. device_code_list += ","+tmp;
  155. }
  156. }else
  157. device_code = q_json.getString("device_code");
  158. }
  159. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  160. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  161. }
  162. if(V_LOGINNAME.equals("ypsgec")) {
  163. return json.toString();
  164. }else {
  165. if(sort!=null) {
  166. Sort = JSONArray.fromObject(sort);
  167. if((Sort.isArray())&&(Sort.size()>0)) {
  168. JSONObject s_json = Sort.getJSONObject(0);
  169. order = s_json.has("property")?s_json.getString("property"):order;
  170. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  171. }
  172. json.put("sort", sort);
  173. }
  174. Start = start;
  175. Limit = limit;
  176. Page = page;
  177. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  178. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  179. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  180. if(list.size()>0) {
  181. for(int i=0;i<list.size();i++) {
  182. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  183. YtiotVUsercompanyId oid = o.getId();
  184. if(i==0)
  185. Company_Code_List = oid.getOwnerCode();
  186. else
  187. Company_Code_List += ","+oid.getOwnerCode();
  188. }
  189. }
  190. }
  191. if(address!=null) {
  192. hqlwhere = chkhw(hqlwhere) + " address like '%"+address+"%' ";
  193. hhwhere = chkhw(hhwhere) + " u.id.address like '%"+address+"%' ";
  194. }
  195. if((clzt!=null)&&(clzt.length()>0)) {
  196. hqlwhere = chkhw(hqlwhere) + " clzt = "+clzt+" ";
  197. hhwhere = chkhw(hhwhere) + " u.id.clzt = "+clzt+" ";
  198. }
  199. if(Company_Code_List!=null) {
  200. hqlwhere = chkhw(hqlwhere) + " company_code in ("+Company_Code_List+") ";
  201. hhwhere = chkhw(hhwhere) + " u.id.companyCode in ("+Company_Code_List+") ";
  202. }else {
  203. if(company_code!=null) {
  204. hqlwhere = chkhw(hqlwhere) + " company_code = "+company_code+" ";
  205. hhwhere = chkhw(hhwhere) + " u.id.companyCode = "+company_code+" ";
  206. }
  207. if(company_code_list!=null) {
  208. hqlwhere = chkhw(hqlwhere) + " company_code in ("+company_code_list+") ";
  209. hhwhere = chkhw(hhwhere) + " u.id.companyCode in ("+company_code_list+") ";
  210. }
  211. }
  212. if(device_code!=null) {
  213. hqlwhere = chkhw(hqlwhere) + " device_code = "+device_code+" ";
  214. hhwhere = chkhw(hhwhere) + " u.id.deviceCode = "+device_code+" ";
  215. }
  216. if(device_code_list!=null) {
  217. hqlwhere = chkhw(hqlwhere) + " device_code in ("+device_code_list+") ";
  218. hhwhere = chkhw(hhwhere) + " u.id.deviceCode in ("+device_code_list+") ";
  219. }
  220. if(time_start!=null) {
  221. hqlwhere = chkhw(hqlwhere) + " time >= '"+time_start+"' ";
  222. hhwhere = chkhw(hhwhere) + " u.id.time >= '"+time_start+"' ";
  223. }
  224. if(time_end!=null) {
  225. hqlwhere = chkhw(hqlwhere) + " time <= '"+time_end+"' ";
  226. hhwhere = chkhw(hhwhere) + " u.id.time <= '"+time_end+"' ";
  227. }
  228. if(COMMSTATUS!=null) {
  229. if(COMMSTATUS.equals("NO")) {
  230. hqlwhere = chkhw(hqlwhere)+" data1 <> 'EF9' ";
  231. hhwhere = chkhw(hhwhere)+" u.id.data1 <> 'EF9' ";
  232. }
  233. else if(COMMSTATUS.equals("ONLY")) {
  234. hqlwhere = chkhw(hqlwhere)+" data1 = 'EF9' ";
  235. hhwhere = chkhw(hhwhere)+" u.id.data1 = 'EF9' ";
  236. }
  237. }
  238. if(order!=null)
  239. order_str = " order by "+order;
  240. else
  241. order_str = " order by id ";
  242. int totalCount = ytiotVAlarmDao.getEFireCount(hhwhere);
  243. // System.out.print("shazi");
  244. // System.out.println(totalCount);
  245. json.put("totalCount", totalCount);
  246. if(Start!=null){
  247. if(Integer.parseInt(Start)>totalCount){
  248. Start = "0";
  249. Page = "0";
  250. }else if(page==null)
  251. Page="0";
  252. }else{
  253. Start = "0";
  254. Page = "0";
  255. }
  256. json.put("page", Page);
  257. json.put("start", Start);
  258. json.put("limit", Limit);
  259. if(totalCount>0) {
  260. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  261. List<?> list1 = ytiotVAlarmDao.EFireQuery(hhwhere, order_str, dir, Start, Limit);
  262. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  263. if(list1.size()>0) {
  264. for(int i=0;i<list1.size();i++) {
  265. YtiotVEfire o = (YtiotVEfire)list1.get(i);
  266. YtiotVEfireId oid = o.getId();
  267. String cl_name = "";
  268. Map<String, Comparable> map = new HashMap<String, Comparable>();
  269. if((company_code!=null)&&(i==0))
  270. json.put("company_name", oid.getCompanyName());
  271. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  272. map.put("address", oid.getAddress());
  273. map.put("cldh", oid.getCldh());
  274. map.put("cllx", oid.getCllx());
  275. map.put("cllxr", oid.getCllxr());
  276. map.put("clnr", oid.getClnr());
  277. map.put("clr", oid.getClr());
  278. map.put("clwb", oid.getClwb());
  279. map.put("clzt", oid.getClzt()==0?"未处理":"已处理");
  280. map.put("company_code", oid.getCompanyCode());
  281. map.put("company_name", oid.getCompanyName());
  282. map.put("compartment", "");
  283. map.put("data1", oid.getData1());
  284. map.put("data2", oid.getData2());
  285. map.put("data3", oid.getData3());
  286. map.put("data4", oid.getData4());
  287. map.put("data5", oid.getData5());
  288. String dv = "";
  289. if(oid.getData1().equals("EF0"))
  290. dv = "正常/报警撤销";
  291. else if(oid.getData1().equals("EF1"))
  292. dv = "欠压报警";
  293. else if(oid.getData1().equals("EF2"))
  294. dv = "过压报警";
  295. else if(oid.getData1().equals("EF3"))
  296. dv = "过流报警";
  297. else if(oid.getData1().equals("EF4"))
  298. dv = "漏电报警";
  299. else if(oid.getData1().equals("EF5"))
  300. dv = "温度1超高报警";
  301. else if(oid.getData1().equals("EF6"))
  302. dv = "温度2超高报警";
  303. else if(oid.getData1().equals("EF7"))
  304. dv = "温度3超高报警";
  305. else if(oid.getData1().equals("EF8"))
  306. dv = "温度4超高报警";
  307. else if(oid.getData1().equals("EF9"))
  308. dv = "离线";
  309. String dw = "";
  310. if(oid.getData1().equals("EF0"))
  311. dw = "";
  312. else if(oid.getData1().equals("EF1"))
  313. dw = "V";
  314. else if(oid.getData1().equals("EF2"))
  315. dw = "V";
  316. else if(oid.getData1().equals("EF3"))
  317. dw = "mA";
  318. else if(oid.getData1().equals("EF4"))
  319. dw = "mA";
  320. else if(oid.getData1().equals("EF5"))
  321. dw = "℃";
  322. else if(oid.getData1().equals("EF6"))
  323. dw = "℃";
  324. else if(oid.getData1().equals("EF7"))
  325. dw = "℃";
  326. else if(oid.getData1().equals("EF8"))
  327. dw = "℃";
  328. else if(oid.getData1().equals("EF9"))
  329. dw = "";
  330. map.put("fullname", oid.getName()+","+dv+","+"告警值:"+oid.getData2()+dw);
  331. map.put("data", oid.getData1());
  332. if(oid.getClzt()==1)
  333. map.put("clsj", df.format(oid.getClsj()));
  334. else
  335. map.put("clsj", "");
  336. map.put("device_code", oid.getDeviceCode());
  337. map.put("fireprocess", "");
  338. map.put("id", oid.getId());
  339. map.put("name", oid.getName());
  340. map.put("ncmd", oid.getNcmd());
  341. map.put("port", oid.getPort());
  342. map.put("position", oid.getPosition());
  343. map.put("status", dv);
  344. map.put("time", df.format(oid.getTime()));
  345. map.put("vidoe", oid.getVideo());
  346. if((oid.getClr().length()>0)
  347. &&(ulist.size()>0)){
  348. for(int j=0;j<ulist.size();j++) {
  349. YtiotVUserphone po = (YtiotVUserphone)ulist.get(j);
  350. YtiotVUserphoneId poid = po.getId();
  351. if(oid.getCldh().equals(poid.getPhone())) {
  352. cl_name = poid.getUsername();
  353. break;
  354. }
  355. }
  356. }
  357. map.put("clr_name", cl_name.length()>0?cl_name:oid.getClr());
  358. JSONObject jSONObject = JSONObject.fromObject(map);
  359. jSONArray.add(jSONObject);
  360. }
  361. json.put("RESULT", jSONArray);
  362. }
  363. }
  364. return json.toString();
  365. }
  366. }
  367. @Override
  368. public String getHjVList(String queryJson, String page, String start, String limit, String sort) throws Exception {
  369. // TODO Auto-generated method stub
  370. String address = null;
  371. String clzt = null;
  372. String company_code = null;
  373. String company_code_list = null;
  374. String Company_Code_List = null;
  375. String company_name = null;
  376. String device_code = null;
  377. String device_code_list = null;
  378. String time_start = null;
  379. String time_end = null;
  380. String status = null;
  381. String COMMSTATUS = null;
  382. String V_LOGINNAME = null;
  383. String hqlwhere = null;
  384. String order = null;
  385. String dir = null;
  386. String Start = null;
  387. String Limit = null;
  388. String Page = null;
  389. String order_str = null;
  390. JSONObject q_json = null;
  391. JSONArray Sort = null;
  392. JSONArray jSONArray = new JSONArray();
  393. JSONObject json = new JSONObject();
  394. json.put("action", "getHjVList");
  395. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  396. if(queryJson!=null) {
  397. q_json = JSONObject.fromObject(queryJson);
  398. address = q_json.has("address")?q_json.getString("address"):null;
  399. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  400. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  401. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  402. if(q_json.has("company_code")) {
  403. if((q_json.optJSONObject("company_code")!=null)
  404. &&(q_json.optJSONObject("company_code").isArray())) {
  405. JSONArray j_tmp = q_json.getJSONArray("company_code");
  406. for(int i=0;i<j_tmp.size();i++) {
  407. String tmp = j_tmp.getString(i);
  408. if(i==0)
  409. company_code_list = "'"+tmp+"'";
  410. else
  411. company_code_list += ","+"'"+tmp+"'";
  412. }
  413. }else
  414. company_code = q_json.getString("company_code");
  415. }
  416. company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  417. if(q_json.has("device_code")) {
  418. if((q_json.optJSONObject("device_code")!=null)
  419. &&(q_json.optJSONObject("device_code").isArray())){
  420. JSONArray j_tmp = q_json.getJSONArray("device_code");
  421. for(int i=0;i<j_tmp.size();i++) {
  422. String tmp = j_tmp.getString(i);
  423. if(i==0)
  424. device_code_list = tmp;
  425. else
  426. device_code_list += ","+tmp;
  427. }
  428. }else
  429. device_code = q_json.getString("device_code");
  430. }
  431. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  432. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  433. }
  434. if(V_LOGINNAME.equals("ypsgec")) {
  435. return json.toString();
  436. }else {
  437. if(sort!=null) {
  438. Sort = JSONArray.fromObject(sort);
  439. if((Sort.isArray())&&(Sort.size()>0)) {
  440. JSONObject s_json = Sort.getJSONObject(0);
  441. order = s_json.has("property")?s_json.getString("property"):order;
  442. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  443. }
  444. json.put("sort", sort);
  445. }
  446. Start = start;
  447. Limit = limit;
  448. Page = page;
  449. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  450. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  451. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  452. if(list.size()>0) {
  453. for(int i=0;i<list.size();i++) {
  454. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  455. YtiotVUsercompanyId oid = o.getId();
  456. if(i==0)
  457. Company_Code_List = "'"+oid.getOwnerCode()+"'";
  458. else
  459. Company_Code_List += ","+"'"+oid.getOwnerCode()+"'";
  460. }
  461. }
  462. }
  463. System.out.print("hanzhengyi"+df.format(new Date()));
  464. if(address!=null)
  465. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("address")+" like '%"+address+"%' ";
  466. if((clzt!=null)&&(clzt.length()>0))
  467. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("clzt")+" = "+clzt+" ";
  468. if(Company_Code_List!=null) {
  469. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  470. }else {
  471. if(company_code!=null)
  472. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = "+company_code+" ";
  473. if(company_code_list!=null)
  474. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  475. }
  476. if(company_name!=null)
  477. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_name")+" = '%"+company_name+"%' ";
  478. if(device_code!=null)
  479. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" = "+device_code+" ";
  480. if(device_code_list!=null)
  481. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" in ("+device_code_list+") ";
  482. if((time_start!=null)&&(time_start.length()>0))
  483. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" >= '"+time_start+"' ";
  484. if((time_end!=null)&&(time_end.length()>0))
  485. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" <= '"+time_end+"' ";
  486. System.out.print("hanzhengyi"+hqlwhere);
  487. if(COMMSTATUS!=null) {
  488. if(COMMSTATUS.equals("NO"))
  489. hqlwhere = chkhw(hqlwhere)+" u.id.data1 <> 'U44' ";
  490. else if(COMMSTATUS.equals("ONLY"))
  491. hqlwhere = chkhw(hqlwhere)+" u.id.data1 = 'U44' ";
  492. }
  493. if(order!=null)
  494. order_str = " order by u.id."+fieldname(order);
  495. else
  496. order_str = " order by u.id.id ";
  497. int totalCount = ytiotVAlarmDao.getHJCount(hqlwhere);
  498. json.put("totalCount", totalCount);
  499. if(Start!=null){
  500. if(Integer.parseInt(Start)>totalCount){
  501. Start = "0";
  502. Page = "0";
  503. }else if(page==null)
  504. Page="0";
  505. }else{
  506. Start = "0";
  507. Page = "0";
  508. }
  509. json.put("page", Page);
  510. json.put("start", Start);
  511. json.put("limit", Limit);
  512. if(totalCount>0) {
  513. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  514. List<?> list = ytiotVAlarmDao.HJQuery(hqlwhere, order_str, dir, Start, Limit);
  515. if(list.size()>0) {
  516. for(int i=0;i<list.size();i++) {
  517. YtiotVHj hj = (YtiotVHj)list.get(i);
  518. YtiotVHjId id = hj.getId();
  519. String cl_name = "";
  520. Map<String, Comparable> map = new HashMap<String, Comparable>();
  521. if((company_code!=null)&&(i==0))
  522. json.put("company_name", id.getCompanyName());
  523. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  524. map.put("address", id.getAddress());
  525. map.put("cldh", id.getCldh());
  526. map.put("cllx", id.getCllx());
  527. map.put("cllxr", id.getCllxr());
  528. map.put("clnr", id.getClnr());
  529. map.put("clr", id.getClr());
  530. map.put("clwb", id.getClwb());
  531. map.put("clzt", id.getClzt()==0?"未处理":"已处理");
  532. map.put("company_code", id.getCompanyCode());
  533. map.put("company_name", id.getCompanyName());
  534. map.put("compartment", id.getCompartment());
  535. map.put("data1", id.getData1());
  536. map.put("data2", id.getData2());
  537. map.put("data3", id.getData3());
  538. map.put("data4", id.getData4());
  539. map.put("data5", id.getData5());
  540. map.put("fullname", id.getName()+((id.getData4().length()>0) ?(","+id.getData4()):""));
  541. map.put("data", id.getData2());
  542. if(id.getClzt()==1)
  543. map.put("clsj", df.format(id.getClsj()));
  544. else
  545. map.put("clsj", "");
  546. map.put("device_code", id.getDeviceCode());
  547. map.put("fireprocess", id.getFireprocess());
  548. map.put("id", id.getId());
  549. map.put("name", id.getName());
  550. map.put("ncmd", id.getNcmd());
  551. map.put("port", id.getPort());
  552. map.put("position", id.getPosition());
  553. map.put("status", id.getStatus());
  554. map.put("time", df.format(id.getTime()));
  555. map.put("vidoe", id.getVideo());
  556. System.out.print("循环前"+i);
  557. if((id.getClr().length()>0)
  558. &&(ulist.size()>0)){
  559. for(int j=0;j<ulist.size();j++) {
  560. YtiotVUserphone po = (YtiotVUserphone)ulist.get(j);
  561. YtiotVUserphoneId poid = po.getId();
  562. if(id.getClr().equals(poid.getPhone())) {
  563. cl_name = poid.getUsername();
  564. break;
  565. }
  566. }
  567. }
  568. System.out.print("循环后"+i);
  569. map.put("clr_name", cl_name.length()>0?cl_name:id.getClr());
  570. JSONObject jSONObject = JSONObject.fromObject(map);
  571. jSONArray.add(jSONObject);
  572. }
  573. json.put("RESULT", jSONArray);
  574. // System.out.print("RESULT"+jSONArray);
  575. }
  576. }
  577. return json.toString();
  578. }
  579. }
  580. @Override
  581. public String getSyncfireAlarmFexcelList(String queryJson) throws Exception {
  582. // TODO Auto-generated method stub
  583. String address = null;
  584. String clzt = null;
  585. String company_code = null;
  586. String company_code_list = null;
  587. String Company_Code_List = null;
  588. String company_name = null;
  589. String device_code = null;
  590. String device_code_list = null;
  591. String time_start = null;
  592. String time_end = null;
  593. String status = null;
  594. String COMMSTATUS = null;
  595. String V_LOGINNAME = null;
  596. String hqlwhere = null;
  597. String order = null;
  598. String dir = null;
  599. String Start = null;
  600. String Limit = null;
  601. String Page = null;
  602. String order_str = null;
  603. JSONObject q_json = null;
  604. JSONArray Sort = null;
  605. JSONArray jSONArray = new JSONArray();
  606. JSONObject json = new JSONObject();
  607. json.put("action", "getHjVList");
  608. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  609. if(queryJson!=null) {
  610. q_json = JSONObject.fromObject(queryJson);
  611. address = q_json.has("address")?q_json.getString("address"):null;
  612. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  613. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  614. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  615. if(q_json.has("company_code")) {
  616. if((q_json.optJSONObject("company_code")!=null)
  617. &&(q_json.optJSONObject("company_code").isArray())) {
  618. JSONArray j_tmp = q_json.getJSONArray("company_code");
  619. for(int i=0;i<j_tmp.size();i++) {
  620. String tmp = j_tmp.getString(i);
  621. if(i==0)
  622. company_code_list = tmp;
  623. else
  624. company_code_list += ","+tmp;
  625. }
  626. }else if((q_json.getString("company_code").length()>0)) {
  627. company_code = q_json.getString("company_code");
  628. }
  629. }
  630. company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  631. if(q_json.has("device_code")) {
  632. if((q_json.optJSONObject("device_code")!=null)
  633. &&(q_json.optJSONObject("device_code").isArray())){
  634. JSONArray j_tmp = q_json.getJSONArray("device_code");
  635. for(int i=0;i<j_tmp.size();i++) {
  636. String tmp = j_tmp.getString(i);
  637. if(i==0)
  638. device_code_list = tmp;
  639. else
  640. device_code_list += ","+tmp;
  641. }
  642. }else
  643. device_code = q_json.getString("device_code");
  644. }
  645. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  646. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  647. }
  648. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  649. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  650. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  651. if(list.size()>0) {
  652. for(int i=0;i<list.size();i++) {
  653. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  654. YtiotVUsercompanyId oid = o.getId();
  655. if(i==0)
  656. Company_Code_List = oid.getOwnerCode();
  657. else
  658. Company_Code_List += ","+oid.getOwnerCode();
  659. }
  660. }
  661. }
  662. if(address!=null)
  663. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("address")+" like '%"+address+"%' ";
  664. if((clzt!=null)&&(clzt.length()>0))
  665. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("clzt")+" = "+clzt+" ";
  666. if(Company_Code_List!=null) {
  667. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  668. }else {
  669. if(company_code!=null)
  670. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = "+company_code+" ";
  671. if(company_code_list!=null)
  672. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  673. }
  674. if(company_name!=null)
  675. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_name")+" = '%"+company_name+"%' ";
  676. if(device_code!=null)
  677. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" = "+device_code+" ";
  678. if(device_code_list!=null)
  679. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" in ("+device_code_list+") ";
  680. if((time_start!=null)&&(time_start.length()>0))
  681. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" >= '"+time_start+"' ";
  682. if((time_end!=null)&&(time_end.length()>0))
  683. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" <= '"+time_end+"' ";
  684. System.out.print("hanzhengyi"+hqlwhere);
  685. if(COMMSTATUS!=null) {
  686. if(COMMSTATUS.equals("NO"))
  687. hqlwhere = chkhw(hqlwhere)+" u.id.data1 <> 'U44' ";
  688. else if(COMMSTATUS.equals("ONLY"))
  689. hqlwhere = chkhw(hqlwhere)+" u.id.data1 = 'U44' ";
  690. }
  691. if(order!=null)
  692. order_str = " order by u.id."+fieldname(order);
  693. else
  694. order_str = " order by u.id.id ";
  695. int totalCount = ytiotVAlarmDao.getHJCount(hqlwhere);
  696. json.put("totalCount", totalCount);
  697. if(totalCount>0) {
  698. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  699. List<?> list = ytiotVAlarmDao.HJQuery(hqlwhere, order_str, dir, Start, Limit);
  700. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  701. if(list.size()>0) {
  702. for(int i=0;i<list.size();i++) {
  703. YtiotVHj hj = (YtiotVHj)list.get(i);
  704. YtiotVHjId id = hj.getId();
  705. String cl_name = "";
  706. Map<String, Comparable> map = new HashMap<String, Comparable>();
  707. if((company_code!=null)&&(i==0))
  708. json.put("company_name", id.getCompanyName());
  709. map.put("address", id.getAddress());
  710. map.put("cldh", id.getCldh());
  711. map.put("cllx", id.getCllx());
  712. map.put("cllxr", id.getCllxr());
  713. map.put("clnr", id.getClnr());
  714. map.put("clr", id.getClr());
  715. if(id.getClwb().equals("0"))
  716. map.put("clwb", "未误报");
  717. else if(id.getClwb().equals("1"))
  718. map.put("clwb", "误报");
  719. else
  720. map.put("clwb", "");
  721. map.put("clzt", id.getClzt()==0?"未处理":"已处理");
  722. map.put("company_code", id.getCompanyCode());
  723. map.put("company_name", id.getCompanyName());
  724. map.put("compartment", id.getCompartment());
  725. map.put("data1", id.getData1());
  726. map.put("data2", id.getData2());
  727. map.put("data3", id.getData3());
  728. map.put("data4", id.getData4());
  729. map.put("data5", id.getData5());
  730. map.put("data", id.getData2());
  731. if(id.getClzt()==1)
  732. map.put("clsj", df.format(id.getClsj()));
  733. else
  734. map.put("clsj", "");
  735. map.put("device_code", id.getDeviceCode());
  736. map.put("fireprocess", id.getFireprocess());
  737. map.put("id", id.getId());
  738. map.put("name", id.getName());
  739. map.put("ncmd", id.getNcmd());
  740. map.put("port", id.getPort());
  741. map.put("position", id.getPosition());
  742. map.put("status", id.getStatus());
  743. map.put("time", df.format(id.getTime()));
  744. map.put("vidoe", id.getVideo());
  745. JSONObject jSONObject = JSONObject.fromObject(map);
  746. jSONArray.add(jSONObject);
  747. }
  748. json.put("result", jSONArray);
  749. }
  750. }
  751. return json.toString();
  752. }
  753. @Override
  754. public String getSyncEfireAlarmFexcelList(String queryJson) throws Exception {
  755. // TODO Auto-generated method stub
  756. String address = null;
  757. String clzt = null;
  758. String company_code = null;
  759. String company_code_list = null;
  760. String Company_Code_List = null;
  761. String company_name = null;
  762. String device_code = null;
  763. String device_code_list = null;
  764. String time_start = null;
  765. String time_end = null;
  766. String status = null;
  767. String COMMSTATUS = null;
  768. String V_LOGINNAME = null;
  769. String hqlwhere = null, hhwhere = null;
  770. String order = null;
  771. String dir = null;
  772. String Start = null;
  773. String Limit = null;
  774. String Page = null;
  775. String order_str = null;
  776. JSONObject q_json = null;
  777. JSONArray Sort = null;
  778. JSONArray jSONArray = new JSONArray();
  779. JSONObject json = new JSONObject();
  780. json.put("action", "getEFireVList");
  781. if(queryJson!=null) {
  782. q_json = JSONObject.fromObject(queryJson);
  783. address = q_json.has("address")?q_json.getString("address"):null;
  784. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  785. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  786. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  787. if(q_json.has("company_code")) {
  788. if((q_json.optJSONObject("company_code")!=null)
  789. &&(q_json.optJSONObject("company_code").isArray())) {
  790. JSONArray j_tmp = q_json.getJSONArray("company_code");
  791. for(int i=0;i<j_tmp.size();i++) {
  792. String tmp = j_tmp.getString(i);
  793. if(i==0)
  794. company_code_list = tmp;
  795. else
  796. company_code_list += ","+tmp;
  797. }
  798. }else if((q_json.getString("company_code").length()>0)) {
  799. company_code = q_json.getString("company_code");
  800. }
  801. }
  802. // company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  803. if(q_json.has("device_code")) {
  804. if((q_json.optJSONObject("device_code")!=null)
  805. &&(q_json.optJSONObject("device_code").isArray())){
  806. JSONArray j_tmp = q_json.getJSONArray("device_code");
  807. for(int i=0;i<j_tmp.size();i++) {
  808. String tmp = j_tmp.getString(i);
  809. if(i==0)
  810. device_code_list = tmp;
  811. else
  812. device_code_list += ","+tmp;
  813. }
  814. }else
  815. device_code = q_json.getString("device_code");
  816. }
  817. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  818. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  819. }
  820. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  821. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  822. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  823. if(list.size()>0) {
  824. for(int i=0;i<list.size();i++) {
  825. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  826. YtiotVUsercompanyId oid = o.getId();
  827. if(i==0)
  828. Company_Code_List = oid.getOwnerCode();
  829. else
  830. Company_Code_List += ","+oid.getOwnerCode();
  831. }
  832. }
  833. }
  834. if(address!=null) {
  835. hqlwhere = chkhw(hqlwhere) + " address like '%"+address+"%' ";
  836. hhwhere = chkhw(hhwhere) + " u.id.address like '%"+address+"%' ";
  837. }
  838. if((clzt!=null)&&(clzt.length()>0)) {
  839. hqlwhere = chkhw(hqlwhere) + " clzt = "+clzt+" ";
  840. hhwhere = chkhw(hhwhere) + " u.id.clzt = "+clzt+" ";
  841. }
  842. if(Company_Code_List!=null) {
  843. hqlwhere = chkhw(hqlwhere) + " company_code in ("+Company_Code_List+") ";
  844. hhwhere = chkhw(hhwhere) + " u.id.companyCode in ("+Company_Code_List+") ";
  845. }else {
  846. if(company_code!=null) {
  847. hqlwhere = chkhw(hqlwhere) + " company_code = "+company_code+" ";
  848. hhwhere = chkhw(hhwhere) + " u.id.companyCode = "+company_code+" ";
  849. }
  850. if(company_code_list!=null) {
  851. hqlwhere = chkhw(hqlwhere) + " company_code in ("+company_code_list+") ";
  852. hhwhere = chkhw(hhwhere) + " u.id.companyCode in ("+company_code_list+") ";
  853. }
  854. }
  855. if(device_code!=null) {
  856. hqlwhere = chkhw(hqlwhere) + " device_code = "+device_code+" ";
  857. hhwhere = chkhw(hhwhere) + " u.id.deviceCode = "+device_code+" ";
  858. }
  859. if(device_code_list!=null) {
  860. hqlwhere = chkhw(hqlwhere) + " device_code in ("+device_code_list+") ";
  861. hhwhere = chkhw(hhwhere) + " u.id.deviceCode in ("+device_code_list+") ";
  862. }
  863. if((time_start!=null)&&(time_start.length()>0)) {
  864. hqlwhere = chkhw(hqlwhere) + " time >= '"+time_start+"' ";
  865. hhwhere = chkhw(hhwhere) + " u.id.time >= '"+time_start+"' ";
  866. }
  867. if((time_end!=null)&&(time_start.length()>0)) {
  868. hqlwhere = chkhw(hqlwhere) + " time <= '"+time_end+"' ";
  869. hhwhere = chkhw(hhwhere) + " u.id.time <= '"+time_end+"' ";
  870. }
  871. if(COMMSTATUS!=null) {
  872. if(COMMSTATUS.equals("NO")) {
  873. hqlwhere = chkhw(hqlwhere)+" data1 <> 'EF9' ";
  874. hhwhere = chkhw(hhwhere)+" u.id.data1 <> 'EF9' ";
  875. }
  876. else if(COMMSTATUS.equals("ONLY")) {
  877. hqlwhere = chkhw(hqlwhere)+" data1 = 'EF9' ";
  878. hhwhere = chkhw(hhwhere)+" u.id.data1 = 'EF9' ";
  879. }
  880. }
  881. System.out.print("shazi"+hhwhere);
  882. if(order!=null)
  883. order_str = " order by "+order;
  884. else
  885. order_str = " order by id ";
  886. int totalCount = ytiotVAlarmDao.getEFireCount(hhwhere);
  887. // System.out.println(totalCount);
  888. json.put("totalCount", totalCount);
  889. if(totalCount>0) {
  890. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  891. List<?> list1 = ytiotVAlarmDao.EFireQuery(hhwhere, order_str, dir, Start, Limit);
  892. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  893. if(list1.size()>0) {
  894. for(int i=0;i<list1.size();i++) {
  895. YtiotVEfire o = (YtiotVEfire)list1.get(i);
  896. YtiotVEfireId oid = o.getId();
  897. String cl_name = "";
  898. Map<String, Comparable> map = new HashMap<String, Comparable>();
  899. if((company_code!=null)&&(i==0))
  900. json.put("company_name", oid.getCompanyName());
  901. map.put("address", oid.getAddress());
  902. map.put("cldh", oid.getCldh());
  903. map.put("cllx", oid.getCllx());
  904. map.put("cllxr", oid.getCllxr());
  905. map.put("clnr", oid.getClnr());
  906. map.put("clr", oid.getClr());
  907. if(oid.getClwb().equals("0"))
  908. map.put("clwb", "未误报");
  909. else if(oid.getClwb().equals("1"))
  910. map.put("clwb", "误报");
  911. else
  912. map.put("clwb", "");
  913. map.put("clzt", oid.getClzt()==0?"未处理":"已处理");
  914. map.put("company_code", oid.getCompanyCode());
  915. map.put("company_name", oid.getCompanyName());
  916. map.put("data2", oid.getData2());
  917. map.put("data3", oid.getData3());
  918. map.put("data4", oid.getData4());
  919. map.put("data5", oid.getData5());
  920. if(oid.getData1().equals("EF0"))
  921. map.put("data1", "正常/报警撤销");
  922. else if(oid.getData1().equals("EF1"))
  923. map.put("data1", "欠压报警");
  924. else if(oid.getData1().equals("EF2"))
  925. map.put("data1","过压报警");
  926. else if(oid.getData1().equals("EF3"))
  927. map.put("data1","过流报警");
  928. else if(oid.getData1().equals("EF4"))
  929. map.put("data1","漏电报警");
  930. else if(oid.getData1().equals("EF5"))
  931. map.put("data1","温度1超高报警");
  932. else if(oid.getData1().equals("EF6"))
  933. map.put("data1","温度2超高报警");
  934. else if(oid.getData1().equals("EF7"))
  935. map.put("data1","温度3超高报警");
  936. else if(oid.getData1().equals("EF8"))
  937. map.put("data1","温度4超高报警");
  938. else if(oid.getData1().equals("EF9"))
  939. map.put("data1","离线");
  940. // String dw = "";
  941. // if(oid.getData1().equals("EF0"))
  942. // dw = "";
  943. // else if(oid.getData1().equals("EF1"))
  944. // dw = "V";
  945. // else if(oid.getData1().equals("EF2"))
  946. // dw = "V";
  947. // else if(oid.getData1().equals("EF3"))
  948. // dw = "mA";
  949. // else if(oid.getData1().equals("EF4"))
  950. // dw = "mA";
  951. // else if(oid.getData1().equals("EF5"))
  952. // dw = "℃";
  953. // else if(oid.getData1().equals("EF6"))
  954. // dw = "℃";
  955. // else if(oid.getData1().equals("EF7"))
  956. // dw = "℃";
  957. // else if(oid.getData1().equals("EF8"))
  958. // dw = "℃";
  959. // else if(oid.getData1().equals("EF9"))
  960. // dw = "";
  961. map.put("data", oid.getData1());
  962. if(oid.getClzt()==1)
  963. map.put("clsj", df.format(oid.getClsj()));
  964. else
  965. map.put("clsj", "");
  966. map.put("device_code", oid.getDeviceCode());
  967. map.put("id", oid.getId());
  968. map.put("name", oid.getName());
  969. map.put("ncmd", oid.getNcmd());
  970. map.put("port", oid.getPort());
  971. map.put("position", oid.getPosition());
  972. map.put("time", df.format(oid.getTime()));
  973. map.put("vidoe", oid.getVideo());
  974. if((oid.getClr().length()>0)
  975. &&(ulist.size()>0)){
  976. for(int j=0;j<ulist.size();j++) {
  977. YtiotVUserphone po = (YtiotVUserphone)ulist.get(j);
  978. YtiotVUserphoneId poid = po.getId();
  979. if(oid.getCldh().equals(poid.getPhone())) {
  980. cl_name = poid.getUsername();
  981. break;
  982. }
  983. }
  984. }
  985. map.put("clr_name", cl_name.length()>0?cl_name:oid.getClr());
  986. JSONObject jSONObject = JSONObject.fromObject(map);
  987. jSONArray.add(jSONObject);
  988. }
  989. json.put("result", jSONArray);
  990. }
  991. }
  992. return json.toString();
  993. }
  994. @Override
  995. public String getSyncWaterAlarmFexcelList(String queryJson) throws Exception {
  996. // TODO Auto-generated method stub
  997. String address = null;
  998. String clzt = null;
  999. String company_code = null;
  1000. String company_code_list = null;
  1001. String Company_Code_List = null;
  1002. String company_name = null;
  1003. String device_code = null;
  1004. String device_code_list = null;
  1005. String time_start = null;
  1006. String time_end = null;
  1007. String COMMSTATUS = null;
  1008. String V_LOGINNAME = null;
  1009. String hqlwhere = null;
  1010. String order = null;
  1011. String dir = null;
  1012. String Start = null;
  1013. String Limit = null;
  1014. String Page = null;
  1015. String order_str = null;
  1016. JSONObject q_json = null;
  1017. JSONArray Sort = null;
  1018. JSONArray jSONArray = new JSONArray();
  1019. JSONObject json = new JSONObject();
  1020. json.put("action", "getSjVList");
  1021. if(queryJson!=null) {
  1022. q_json = JSONObject.fromObject(queryJson);
  1023. address = q_json.has("address")?q_json.getString("address"):null;
  1024. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1025. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  1026. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  1027. if(q_json.has("company_code")) {
  1028. if((q_json.optJSONObject("company_code")!=null)
  1029. &&(q_json.optJSONObject("company_code").isArray())) {
  1030. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1031. for(int i=0;i<j_tmp.size();i++) {
  1032. String tmp = j_tmp.getString(i);
  1033. if(i==0)
  1034. company_code_list = tmp;
  1035. else
  1036. company_code_list += ","+tmp;
  1037. }
  1038. }else if((q_json.getString("company_code").length()>0)) {
  1039. company_code = q_json.getString("company_code");
  1040. }
  1041. }
  1042. company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  1043. if(q_json.has("device_code")) {
  1044. if((q_json.optJSONObject("device_code")!=null)
  1045. &&(q_json.optJSONObject("device_code").isArray())){
  1046. JSONArray j_tmp = q_json.getJSONArray("device_code");
  1047. for(int i=0;i<j_tmp.size();i++) {
  1048. String tmp = j_tmp.getString(i);
  1049. if(i==0)
  1050. device_code_list = tmp;
  1051. else
  1052. device_code_list += ","+tmp;
  1053. }
  1054. }else
  1055. device_code = q_json.getString("device_code");
  1056. }
  1057. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  1058. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  1059. }
  1060. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  1061. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1062. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1063. if(list.size()>0) {
  1064. for(int i=0;i<list.size();i++) {
  1065. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1066. YtiotVUsercompanyId oid = o.getId();
  1067. if(i==0)
  1068. Company_Code_List = oid.getOwnerCode();
  1069. else
  1070. Company_Code_List += ","+oid.getOwnerCode();
  1071. }
  1072. }
  1073. }
  1074. if(address!=null)
  1075. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("address")+" like '%"+address+"' ";
  1076. if((clzt!=null)&&(clzt.length()>0))
  1077. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("clzt")+" = "+clzt+" ";
  1078. if(Company_Code_List!=null)
  1079. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1080. else {
  1081. if(company_code!=null)
  1082. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = "+company_code+" ";
  1083. if(company_code_list!=null)
  1084. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1085. }
  1086. // if(company_code!=null)
  1087. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = '"+company_code+"' ";
  1088. // if(company_code_list!=null)
  1089. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1090. if(company_name!=null)
  1091. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_name")+" like '%"+company_name+"%' ";
  1092. if(device_code!=null)
  1093. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" = '"+device_code+"' ";
  1094. if(device_code_list!=null)
  1095. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" in ("+device_code_list+") ";
  1096. if((time_start!=null)&&(time_start.length()>0))
  1097. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" >= '"+time_start+"' ";
  1098. if((time_end!=null)&&(time_end.length()>0))
  1099. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" <= '"+time_end+"' ";
  1100. if(COMMSTATUS!=null) {
  1101. if(COMMSTATUS.equals("NO"))
  1102. hqlwhere = chkhw(hqlwhere)+"( u.id.data1 <> 'WP4' and u.id.data1 <> 'LL4' ) ";
  1103. else if(COMMSTATUS.equals("ONLY"))
  1104. hqlwhere = chkhw(hqlwhere)+" ( u.id.data1 = 'WP4' or u.id.data1 = 'LL4' ) ";
  1105. }
  1106. if(order!=null)
  1107. order_str = " order by u.id."+fieldname(order);
  1108. else
  1109. order_str = " order by u.id.id ";
  1110. int totalCount = ytiotVAlarmDao.getSJCount(hqlwhere);
  1111. json.put("totalCount", totalCount);
  1112. if(totalCount>0) {
  1113. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  1114. List<?> list = ytiotVAlarmDao.SJQuery(hqlwhere, order_str, dir, Start, Limit);
  1115. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1116. if(list.size()>0) {
  1117. for(int i=0;i<list.size();i++) {
  1118. YtiotVSj hj = (YtiotVSj)list.get(i);
  1119. YtiotVSjId id = hj.getId();
  1120. String cl_name = "";
  1121. if((company_code!=null)&&(i==0))
  1122. json.put("company_name", id.getCompanyName());
  1123. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1124. map.put("address", id.getAddress());
  1125. map.put("cldh", id.getCldh());
  1126. map.put("cllx", id.getCllx());
  1127. map.put("cllxr", id.getCllxr());
  1128. map.put("clnr", id.getClnr());
  1129. map.put("clr", id.getClr());
  1130. if(id.getClwb().equals("0"))
  1131. map.put("clwb", "未误报");
  1132. else if(id.getClwb().equals("1"))
  1133. map.put("clwb", "误报");
  1134. else
  1135. map.put("clwb", "");
  1136. map.put("clzt", id.getClzt()==0?"未处理":"已处理");
  1137. map.put("clsj", df.format(id.getClsj()));
  1138. map.put("company_code", id.getCompanyCode());
  1139. map.put("company_name", id.getCompanyName());
  1140. map.put("data2", id.getData2());
  1141. map.put("data3", id.getData3());
  1142. map.put("data4", id.getData4()+(id.getData1().equals("WP1")?"MPa"
  1143. :(id.getData1().equals("WP2")?"MPa"
  1144. :(id.getData1().equals("WP3")?"MPa"
  1145. :(id.getData1().equals("WP4")?"MPa"
  1146. :(id.getData1().equals("WP0")?"MPa"
  1147. :(id.getData1().equals("LL1")?"m"
  1148. :(id.getData1().equals("LL2")?"m"
  1149. :(id.getData1().equals("LL3")?"m"
  1150. :(id.getData1().equals("LL0")?"m":""))))))))));
  1151. map.put("data5", id.getData5());
  1152. if(id.getClzt()==1)
  1153. map.put("clsj", df.format(id.getClsj()));
  1154. else
  1155. map.put("clsj", "");
  1156. map.put("device_code", id.getDeviceCode());
  1157. map.put("id", id.getId());
  1158. map.put("name", id.getName());
  1159. map.put("ncmd", id.getNcmd());
  1160. map.put("port", id.getPort());
  1161. map.put("position", id.getPosition());
  1162. map.put("status", id.getStatus());
  1163. map.put("time", df.format(id.getTime()));
  1164. map.put("vidoe", id.getVideo());
  1165. map.put("data1", id.getData1().equals("WP1")?"低压"
  1166. :(id.getData1().equals("WP2")?"高压"
  1167. :(id.getData1().equals("WP3")?"故障"
  1168. :(id.getData1().equals("WP4")?"离线"
  1169. :(id.getData1().equals("WP0")?"正常"
  1170. :(id.getData1().equals("LL1")?"低水位"
  1171. :(id.getData1().equals("LL2")?"高水位"
  1172. :(id.getData1().equals("LL3")?"故障"
  1173. :(id.getData1().equals("LL0")?"正常":id.getData1())))))))));
  1174. if((id.getClr().length()>0)
  1175. &&(ulist.size()>0)){
  1176. for(int j=0;j<ulist.size();j++) {
  1177. YtiotVUserphone po = (YtiotVUserphone)ulist.get(j);
  1178. YtiotVUserphoneId poid = po.getId();
  1179. if(id.getClr().equals(poid.getPhone())) {
  1180. cl_name = poid.getUsername();
  1181. break;
  1182. }
  1183. }
  1184. }
  1185. map.put("clr_name", cl_name.length()>0?cl_name:id.getClr());
  1186. JSONObject jSONObject = JSONObject.fromObject(map);
  1187. jSONArray.add(jSONObject);
  1188. }
  1189. json.put("result", jSONArray);
  1190. }
  1191. }
  1192. return json.toString();
  1193. }
  1194. @Override
  1195. public String getSyncRTUAlarmFexcelList(String queryJson) throws Exception {
  1196. // TODO Auto-generated method stub
  1197. String address = null;
  1198. String clzt = null;
  1199. String company_code = null;
  1200. String company_code_list = null;
  1201. String Company_Code_List = null;
  1202. String company_name = null;
  1203. String device_code = null;
  1204. String device_code_list = null;
  1205. String time_start = null;
  1206. String time_end = null;
  1207. String status = null;
  1208. String COMMSTATUS = null;
  1209. String V_LOGINNAME = null;
  1210. String hqlwhere = null;
  1211. String order = null;
  1212. String dir = null;
  1213. String Start = null;
  1214. String Limit = null;
  1215. String Page = null;
  1216. String order_str = null;
  1217. JSONObject q_json = null;
  1218. JSONArray Sort = null;
  1219. JSONArray jSONArray = new JSONArray();
  1220. JSONObject json = new JSONObject();
  1221. json.put("action", "getRTUVList");
  1222. if(queryJson!=null) {
  1223. q_json = JSONObject.fromObject(queryJson);
  1224. address = q_json.has("address")?q_json.getString("address"):null;
  1225. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1226. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  1227. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  1228. if(q_json.has("company_code")) {
  1229. if((q_json.optJSONObject("company_code")!=null)
  1230. &&(q_json.optJSONObject("company_code").isArray())) {
  1231. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1232. for(int i=0;i<j_tmp.size();i++) {
  1233. String tmp = j_tmp.getString(i);
  1234. if(i==0)
  1235. company_code_list = tmp;
  1236. else
  1237. company_code_list += ","+tmp;
  1238. }
  1239. }else if((q_json.getString("company_code").length()>0)) {
  1240. company_code = q_json.getString("company_code");
  1241. }
  1242. }
  1243. company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  1244. if(q_json.has("device_code")) {
  1245. if((q_json.optJSONObject("device_code")!=null)
  1246. &&(q_json.optJSONObject("device_code").isArray())){
  1247. JSONArray j_tmp = q_json.getJSONArray("device_code");
  1248. for(int i=0;i<j_tmp.size();i++) {
  1249. String tmp = j_tmp.getString(i);
  1250. if(i==0)
  1251. device_code_list = tmp;
  1252. else
  1253. device_code_list += ","+tmp;
  1254. }
  1255. }else
  1256. device_code = q_json.getString("device_code");
  1257. }
  1258. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  1259. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  1260. }
  1261. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  1262. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1263. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1264. if(list.size()>0) {
  1265. for(int i=0;i<list.size();i++) {
  1266. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1267. YtiotVUsercompanyId oid = o.getId();
  1268. if(i==0)
  1269. Company_Code_List = oid.getOwnerCode();
  1270. else
  1271. Company_Code_List += ","+oid.getOwnerCode();
  1272. }
  1273. }
  1274. }
  1275. if(address!=null)
  1276. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("address")+" like '%"+address+"%' ";
  1277. if((clzt!=null)&&(clzt.length()>0))
  1278. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("clzt")+" = "+clzt+" ";
  1279. if(Company_Code_List!=null) {
  1280. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1281. }else {
  1282. if((company_code!=null))
  1283. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = "+company_code+" ";
  1284. if(company_code_list!=null)
  1285. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1286. }
  1287. if(company_name!=null)
  1288. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_name")+" = '%"+company_name+"%' ";
  1289. if(device_code!=null)
  1290. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" = "+device_code+" ";
  1291. if(device_code_list!=null)
  1292. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" in ("+device_code_list+") ";
  1293. if((time_start!=null)&&(time_start.length()>0))
  1294. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" >= '"+time_start+"' ";
  1295. if((time_end!=null)&&(time_end.length()>0))
  1296. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" <= '"+time_end+"' ";
  1297. // System.out.print("hanzhengyi"+COMMSTATUS);
  1298. if(COMMSTATUS!=null) {
  1299. if(COMMSTATUS.equals("NO"))
  1300. hqlwhere = chkhw(hqlwhere)+" u.id.status <> '44' ";
  1301. else if(COMMSTATUS.equals("ONLY"))
  1302. hqlwhere = chkhw(hqlwhere)+" u.id.status = '44' ";
  1303. }
  1304. System.out.print("han"+hqlwhere);
  1305. if(order!=null)
  1306. order_str = " order by u.id."+fieldname(order);
  1307. else
  1308. order_str = " order by u.id.id ";
  1309. int totalCount = ytiotVAlarmDao.getRTUCount(hqlwhere);
  1310. json.put("totalCount", totalCount);
  1311. if(totalCount>0) {
  1312. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  1313. List<?> list = ytiotVAlarmDao.RTUQuery(hqlwhere, order_str, dir, Start, Limit);
  1314. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1315. if(list.size()>0) {
  1316. for(int i=0;i<list.size();i++) {
  1317. YtiotVRtu hj = (YtiotVRtu)list.get(i);
  1318. YtiotVRtuId id = hj.getId();
  1319. String cl_name = "";
  1320. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1321. if((company_code!=null)&&(i==0))
  1322. json.put("company_name", id.getCompanyName());
  1323. map.put("address", id.getAddress());
  1324. map.put("cldh", id.getCldh());
  1325. map.put("cllx", id.getCllx());
  1326. map.put("cllxr", id.getCllxr());
  1327. map.put("clnr", id.getClnr());
  1328. map.put("clr", id.getClr());
  1329. if(id.getClwb().equals("0"))
  1330. map.put("clwb", "未误报");
  1331. else if(id.getClwb().equals("1"))
  1332. map.put("clwb", "误报");
  1333. else
  1334. map.put("clwb", "");
  1335. map.put("clzt", id.getClzt()==0?"未处理":"已处理");
  1336. map.put("company_code", id.getCompanyCode());
  1337. map.put("company_name", id.getCompanyName());
  1338. map.put("data1", id.getData1());
  1339. map.put("data2", id.getData2());
  1340. map.put("data3", id.getData3());
  1341. map.put("data4", id.getData4());
  1342. map.put("data5", id.getData5());
  1343. map.put("data", id.getData2());
  1344. if(id.getClzt()==1)
  1345. map.put("clsj", df.format(id.getClsj()));
  1346. else
  1347. map.put("clsj", "");
  1348. map.put("device_code", id.getDeviceCode());
  1349. map.put("id", id.getId());
  1350. map.put("name", id.getName());
  1351. map.put("ncmd", id.getNcmd());
  1352. map.put("port", id.getPort());
  1353. map.put("position", id.getPosition());
  1354. map.put("status", id.getStatus());
  1355. map.put("time", df.format(id.getTime()));
  1356. map.put("vidoe", id.getVideo());
  1357. JSONObject jSONObject = JSONObject.fromObject(map);
  1358. jSONArray.add(jSONObject);
  1359. }
  1360. json.put("result", jSONArray);
  1361. }
  1362. }
  1363. return json.toString();
  1364. }
  1365. /**
  1366. * 获取监控视频告警信息
  1367. * @param queryJson
  1368. * @param page
  1369. * @param start
  1370. * @param limit
  1371. * @param sort
  1372. * @return
  1373. */
  1374. @Override
  1375. public String getVideoLists(String queryJson, String page, String start, String limit, String sort) {
  1376. {
  1377. String address = null;//地址
  1378. String clzt = null;//处理状态
  1379. String company_code = null;//公司编号
  1380. String company_code_list = null;//
  1381. String Company_Code_List = null;
  1382. String company_name = null;//公司名
  1383. String device_code = null;//设备代码
  1384. String device_code_list = null;
  1385. String time_start = null;//告警开始时间
  1386. String time_end = null;//告警结束时间
  1387. String COMMSTATUS = null;
  1388. String V_LOGINNAME = null;//用户名
  1389. String hqlwhere = null;
  1390. String order = null;
  1391. String dir = null;
  1392. String Start = null;
  1393. String Limit = null;
  1394. String Page = null;
  1395. String order_str = null;
  1396. JSONObject q_json = null;
  1397. JSONArray Sort = null;
  1398. JSONArray jSONArray = new JSONArray();
  1399. JSONObject json = new JSONObject();
  1400. json.put("action", "getVideoLists");
  1401. if(StringUtils.isNotBlank(queryJson)) {
  1402. q_json = JSONObject.fromObject(queryJson);
  1403. address = q_json.has("address")?q_json.getString("address"):null;
  1404. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1405. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  1406. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  1407. if(q_json.has("company_code")) {
  1408. if((q_json.optJSONObject("company_code")!=null)
  1409. &&(q_json.optJSONObject("company_code").isArray())) {
  1410. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1411. for(int i=0;i<j_tmp.size();i++) {
  1412. String tmp = j_tmp.getString(i);
  1413. if(i==0)
  1414. company_code_list = tmp;
  1415. else
  1416. company_code_list += ","+tmp;
  1417. }
  1418. }else
  1419. company_code = q_json.getString("company_code");
  1420. }
  1421. company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  1422. if(q_json.has("device_code")) {
  1423. if((q_json.optJSONObject("device_code")!=null)
  1424. &&(q_json.optJSONObject("device_code").isArray())){
  1425. JSONArray j_tmp = q_json.getJSONArray("device_code");
  1426. for(int i=0;i<j_tmp.size();i++) {
  1427. String tmp = j_tmp.getString(i);
  1428. if(i==0)
  1429. device_code_list = tmp;
  1430. else
  1431. device_code_list += ","+tmp;
  1432. }
  1433. }else
  1434. device_code = q_json.getString("device_code");
  1435. }
  1436. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  1437. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  1438. }
  1439. if(sort!=null) {
  1440. Sort = JSONArray.fromObject(sort);
  1441. if((Sort.isArray())&&(Sort.size()>0)) {
  1442. JSONObject s_json = Sort.getJSONObject(0);
  1443. order = s_json.has("property")?s_json.getString("property"):order;
  1444. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  1445. }
  1446. json.put("sort", sort);
  1447. }
  1448. Start = start;
  1449. Limit = limit;
  1450. Page = page;
  1451. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  1452. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1453. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1454. if(list!=null && list.size()>=0) {
  1455. for(int i=0;i<list.size();i++) {
  1456. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1457. YtiotVUsercompanyId oid = o.getId();
  1458. if(i==0)
  1459. Company_Code_List = oid.getOwnerCode();
  1460. else
  1461. Company_Code_List += ","+oid.getOwnerCode();
  1462. }
  1463. }
  1464. }
  1465. if(address!=null)
  1466. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("address")+" like '%"+address+"' ";
  1467. if((clzt!=null)&&(clzt.length()>0))
  1468. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("clzt")+" = "+clzt+" ";
  1469. if(Company_Code_List!=null)
  1470. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1471. else {
  1472. if(company_code!=null)
  1473. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = "+company_code+" ";
  1474. if(company_code_list!=null)
  1475. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1476. }
  1477. // if(company_code!=null)
  1478. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  1479. // if(company_code_list!=null)
  1480. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1481. if(company_name!=null)
  1482. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_name")+" like '%"+company_name+"%' ";
  1483. if(device_code!=null)
  1484. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" like '%"+device_code+"%' ";
  1485. if(device_code_list!=null)
  1486. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" in ("+device_code_list+") ";
  1487. if(time_start!=null)
  1488. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" >= '"+time_start+"' ";
  1489. if(time_end!=null)
  1490. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" <= '"+time_end+"' ";
  1491. if(COMMSTATUS!=null) {
  1492. if(COMMSTATUS.equals("NO"))
  1493. hqlwhere = chkhw(hqlwhere)+" u.id.status <> '44' ";
  1494. else if(COMMSTATUS.equals("ONLY"))
  1495. hqlwhere = chkhw(hqlwhere)+" u.id.data = '44' ";
  1496. }
  1497. if(order!=null)
  1498. order_str = " order by u.id."+fieldname(order);
  1499. else
  1500. order_str = " order by u.id.id ";
  1501. System.out.println(hqlwhere);
  1502. //int totalCount = ytiotVAlarmDao.getRTUCount(hqlwhere);
  1503. int totalCount = ytiotVAlarmDao.getVideoCount(hqlwhere);
  1504. json.put("totalCount", totalCount);
  1505. if(Start!=null){
  1506. if(Integer.parseInt(Start)>totalCount){
  1507. Start = "0";
  1508. Page = "0";
  1509. }else if(page==null)
  1510. Page="0";
  1511. }else{
  1512. Start = "0";
  1513. Page = "0";
  1514. }
  1515. json.put("page", Page);
  1516. json.put("start", Start);
  1517. json.put("limit", Limit);
  1518. if(totalCount>0) {
  1519. //获取用户手机号码
  1520. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  1521. //获取告警信息
  1522. List<?> list = ytiotVAlarmDao.VideoAlarmQuery(hqlwhere, order_str, dir, Start, Limit);
  1523. //ytiotVAlarmDao.RTUQuery(hqlwhere, order_str, dir, Start, Limit);
  1524. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1525. if(list.size()>0) {
  1526. for(int i=0;i<list.size();i++) {
  1527. YtiotVideoAlarm hj = (YtiotVideoAlarm)list.get(i);
  1528. YtiotVideoAlarmId id = hj.getId();
  1529. String cl_name = "";
  1530. if((company_code!=null)&&(i==0))
  1531. json.put("company_name", id.getCompanyName());
  1532. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1533. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  1534. map.put("address", id.getAddress());
  1535. map.put("cldh", id.getCldh());
  1536. map.put("cllx", id.getCllx());
  1537. map.put("cllxr", id.getCllxr());
  1538. map.put("clnr", id.getClnr());
  1539. map.put("clr", id.getClr());
  1540. map.put("clwb", id.getClwb());
  1541. map.put("clzt", id.getClzt()==0?"未处理":"已处理");
  1542. if(id.getClzt()==1)
  1543. map.put("clsj", df.format(id.getClsj()));
  1544. else
  1545. map.put("clsj", "");
  1546. map.put("company_code", id.getCompanyCode());
  1547. map.put("company_name", id.getCompanyName());
  1548. map.put("data1", id.getData1());
  1549. map.put("data2", id.getData2());
  1550. map.put("data3", id.getData3());
  1551. map.put("data4", id.getData4());
  1552. map.put("data5", id.getData5());
  1553. map.put("device_code", id.getDeviceCode());
  1554. map.put("id", id.getId());
  1555. map.put("name", id.getName());
  1556. map.put("ncmd", id.getNcmd());
  1557. map.put("port", id.getPort());
  1558. map.put("position", id.getPosition());
  1559. map.put("status", id.getStatus());
  1560. map.put("time", df.format(id.getTime()));
  1561. map.put("vidoe", id.getVideo());
  1562. map.put("fullname", id.getName()+","+((id.getPort().equals("E6")) ?"模拟量":"开关量")+","+((id.getNcmd().length()>0) ?("端口号:"+id.getNcmd()):"")
  1563. +((id.getPort().equals("E3")) ?"":(id.getData2().equals("高压")?(","+"告警值:"+id.getData1()+"MPa")
  1564. :(id.getData2().equals("低压")?(","+"告警值:"+id.getData1()+"MPa")
  1565. :(id.getData2().equals("高温")?(","+"告警值:"+id.getData1()+"℃")
  1566. :(id.getData2().equals("低温")?(","+"告警值:"+id.getData1()+"℃")
  1567. :(id.getData2().equals("高水位")?(","+"告警值:"+id.getData1()+"m")
  1568. :(id.getData2().equals("低水位")?(","+"告警值:"+id.getData1()+"m")
  1569. :(id.getData2().equals("高湿度")?(","+"告警值:"+id.getData1()+"%")
  1570. :(id.getData2().equals("低湿度")?(","+"告警值:"+id.getData1()+"%")
  1571. :""))))))))));
  1572. map.put("data", id.getData2());
  1573. if((id.getClr().length()>0)
  1574. &&(ulist.size()>0)){
  1575. for(int j=0;j<ulist.size();j++) {
  1576. YtiotVUserphone po = (YtiotVUserphone)ulist.get(j);
  1577. YtiotVUserphoneId poid = po.getId();
  1578. if(id.getClr().equals(poid.getPhone())) {
  1579. cl_name = poid.getUsername();
  1580. break;
  1581. }
  1582. }
  1583. }
  1584. map.put("clr_name", cl_name.length()>0?cl_name:id.getClr());
  1585. JSONObject jSONObject = JSONObject.fromObject(map);
  1586. jSONArray.add(jSONObject);
  1587. }
  1588. json.put("RESULT", jSONArray);
  1589. }
  1590. }
  1591. return json.toString();
  1592. }
  1593. }
  1594. /**
  1595. * 获取监控视频告警信息
  1596. * @param queryJson
  1597. * @param page
  1598. * @param start
  1599. * @param limit
  1600. * @param sort
  1601. * @return
  1602. */
  1603. @Override
  1604. public String getVideoOfflineList(String queryJson, String page, String start, String limit, String sort) {
  1605. {
  1606. String address = null;//地址
  1607. String clzt = null;//处理状态
  1608. String company_code = null;//公司编号
  1609. String company_code_list = null;//
  1610. String Company_Code_List = null;
  1611. String company_name = null;//公司名
  1612. String device_code = null;//设备代码
  1613. String device_code_list = null;
  1614. String time_start = null;//告警开始时间
  1615. String time_end = null;//告警结束时间
  1616. String COMMSTATUS = null;
  1617. String V_LOGINNAME = null;//用户名
  1618. String hqlwhere = null;
  1619. String order = null;
  1620. String dir = null;
  1621. String Start = null;
  1622. String Limit = null;
  1623. String Page = null;
  1624. String order_str = null;
  1625. JSONObject q_json = null;
  1626. JSONArray Sort = null;
  1627. JSONArray jSONArray = new JSONArray();
  1628. JSONObject json = new JSONObject();
  1629. json.put("action", "getVideoLists");
  1630. if(StringUtils.isNotBlank(queryJson)) {
  1631. q_json = JSONObject.fromObject(queryJson);
  1632. address = q_json.has("address")?q_json.getString("address"):null;
  1633. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1634. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  1635. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  1636. if(q_json.has("company_code")) {
  1637. if((q_json.optJSONObject("company_code")!=null)
  1638. &&(q_json.optJSONObject("company_code").isArray())) {
  1639. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1640. for(int i=0;i<j_tmp.size();i++) {
  1641. String tmp = j_tmp.getString(i);
  1642. if(i==0)
  1643. company_code_list = tmp;
  1644. else
  1645. company_code_list += ","+tmp;
  1646. }
  1647. }else
  1648. company_code = q_json.getString("company_code");
  1649. }
  1650. company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  1651. if(q_json.has("device_code")) {
  1652. if((q_json.optJSONObject("device_code")!=null)
  1653. &&(q_json.optJSONObject("device_code").isArray())){
  1654. JSONArray j_tmp = q_json.getJSONArray("device_code");
  1655. for(int i=0;i<j_tmp.size();i++) {
  1656. String tmp = j_tmp.getString(i);
  1657. if(i==0)
  1658. device_code_list = tmp;
  1659. else
  1660. device_code_list += ","+tmp;
  1661. }
  1662. }else
  1663. device_code = q_json.getString("device_code");
  1664. }
  1665. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  1666. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  1667. }
  1668. if(sort!=null) {
  1669. Sort = JSONArray.fromObject(sort);
  1670. if((Sort.isArray())&&(Sort.size()>0)) {
  1671. JSONObject s_json = Sort.getJSONObject(0);
  1672. order = s_json.has("property")?s_json.getString("property"):order;
  1673. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  1674. }
  1675. json.put("sort", sort);
  1676. }
  1677. Start = start;
  1678. Limit = limit;
  1679. Page = page;
  1680. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  1681. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1682. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1683. if(list!=null && list.size()>=0) {
  1684. for(int i=0;i<list.size();i++) {
  1685. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1686. YtiotVUsercompanyId oid = o.getId();
  1687. if(i==0)
  1688. Company_Code_List = oid.getOwnerCode();
  1689. else
  1690. Company_Code_List += ","+oid.getOwnerCode();
  1691. }
  1692. }
  1693. }
  1694. if(address!=null)
  1695. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("address")+" like '%"+address+"' ";
  1696. if((clzt!=null)&&(clzt.length()>0))
  1697. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("clzt")+" = "+clzt+" ";
  1698. if(Company_Code_List!=null)
  1699. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1700. else {
  1701. if(company_code!=null)
  1702. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = "+company_code+" ";
  1703. if(company_code_list!=null)
  1704. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1705. }
  1706. // if(company_code!=null)
  1707. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  1708. // if(company_code_list!=null)
  1709. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1710. if(company_name!=null)
  1711. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_name")+" like '%"+company_name+"%' ";
  1712. if(device_code!=null)
  1713. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" like '%"+device_code+"%' ";
  1714. if(device_code_list!=null)
  1715. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" in ("+device_code_list+") ";
  1716. if(time_start!=null)
  1717. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" >= '"+time_start+"' ";
  1718. if(time_end!=null)
  1719. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" <= '"+time_end+"' ";
  1720. if(COMMSTATUS!=null) {
  1721. if(COMMSTATUS.equals("NO"))
  1722. hqlwhere = chkhw(hqlwhere)+" u.id.status <> '上线' ";
  1723. else if(COMMSTATUS.equals("ONLY"))
  1724. hqlwhere = chkhw(hqlwhere)+" u.id.status = '离线' ";
  1725. }
  1726. if(order!=null)
  1727. order_str = " order by u.id."+fieldname(order);
  1728. else
  1729. order_str = " order by u.id.id ";
  1730. System.out.println(hqlwhere);
  1731. //int totalCount = ytiotVAlarmDao.getRTUCount(hqlwhere);
  1732. int totalCount = ytiotVAlarmDao.getVideoCount(hqlwhere);
  1733. json.put("totalCount", totalCount);
  1734. if(Start!=null){
  1735. if(Integer.parseInt(Start)>totalCount){
  1736. Start = "0";
  1737. Page = "0";
  1738. }else if(page==null)
  1739. Page="0";
  1740. }else{
  1741. Start = "0";
  1742. Page = "0";
  1743. }
  1744. json.put("page", Page);
  1745. json.put("start", Start);
  1746. json.put("limit", Limit);
  1747. if(totalCount>0) {
  1748. //获取用户手机号码
  1749. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  1750. //获取告警信息
  1751. List<?> list = ytiotVAlarmDao.videoOfflienQuery(hqlwhere, order_str, dir, Start, Limit);
  1752. //ytiotVAlarmDao.RTUQuery(hqlwhere, order_str, dir, Start, Limit);
  1753. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1754. if(list.size()>0) {
  1755. for(int i=0;i<list.size();i++) {
  1756. YtiotVideoOffline hj = (YtiotVideoOffline)list.get(i);
  1757. YtiotVideoOfflineId id = hj.getId();
  1758. String cl_name = "";
  1759. if((company_code!=null)&&(i==0))
  1760. json.put("company_name", id.getCompanyName());
  1761. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1762. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  1763. map.put("cllxr", id.getCllxr());
  1764. map.put("clnr", id.getClnr());
  1765. map.put("clr", id.getClr());
  1766. map.put("clwb", id.getClwb());
  1767. map.put("clzt", id.getClzt()==0?"未处理":"已处理");
  1768. if(id.getClzt()==1)
  1769. map.put("clsj", df.format(id.getClsj()));
  1770. else
  1771. map.put("clsj", "");
  1772. map.put("company_code", id.getCompanyCode());
  1773. map.put("company_name", id.getCompanyName());
  1774. map.put("device_code", id.getDeviceCode());
  1775. map.put("id", id.getId());
  1776. map.put("name", id.getName());
  1777. map.put("port", id.getPort());
  1778. map.put("position", id.getPosition());
  1779. map.put("status", id.getStatus());
  1780. map.put("time", df.format(id.getTime()));
  1781. /*map.put("fullname", id.getName()+","+((id.getPort().equals("E6")) ?"模拟量":"开关量")+","+((id.getNcmd().length()>0) ?("端口号:"+id.getNcmd()):"")
  1782. +((id.getPort().equals("E3")) ?"":(id.getData2().equals("高压")?(","+"告警值:"+id.getData1()+"MPa")
  1783. :(id.getData2().equals("低压")?(","+"告警值:"+id.getData1()+"MPa")
  1784. :(id.getData2().equals("高温")?(","+"告警值:"+id.getData1()+"℃")
  1785. :(id.getData2().equals("低温")?(","+"告警值:"+id.getData1()+"℃")
  1786. :(id.getData2().equals("高水位")?(","+"告警值:"+id.getData1()+"m")
  1787. :(id.getData2().equals("低水位")?(","+"告警值:"+id.getData1()+"m")
  1788. :(id.getData2().equals("高湿度")?(","+"告警值:"+id.getData1()+"%")
  1789. :(id.getData2().equals("低湿度")?(","+"告警值:"+id.getData1()+"%")
  1790. :""))))))))));*/
  1791. map.put("data", id.getData());
  1792. if((id.getClr().length()>0)
  1793. &&(ulist.size()>0)){
  1794. for(int j=0;j<ulist.size();j++) {
  1795. YtiotVUserphone po = (YtiotVUserphone)ulist.get(j);
  1796. YtiotVUserphoneId poid = po.getId();
  1797. if(id.getClr().equals(poid.getPhone())) {
  1798. cl_name = poid.getUsername();
  1799. break;
  1800. }
  1801. }
  1802. }
  1803. map.put("clr_name", cl_name.length()>0?cl_name:id.getClr());
  1804. JSONObject jSONObject = JSONObject.fromObject(map);
  1805. jSONArray.add(jSONObject);
  1806. }
  1807. json.put("RESULT", jSONArray);
  1808. }
  1809. }
  1810. return json.toString();
  1811. }
  1812. }
  1813. @Override
  1814. public String getSjVList(String queryJson, String page, String start, String limit, String sort) throws Exception {
  1815. // TODO Auto-generated method stub
  1816. String address = null;
  1817. String clzt = null;
  1818. String company_code = null;
  1819. String company_code_list = null;
  1820. String Company_Code_List = null;
  1821. String company_name = null;
  1822. String device_code = null;
  1823. String device_code_list = null;
  1824. String time_start = null;
  1825. String time_end = null;
  1826. String COMMSTATUS = null;
  1827. String V_LOGINNAME = null;
  1828. String hqlwhere = null;
  1829. String order = null;
  1830. String dir = null;
  1831. String Start = null;
  1832. String Limit = null;
  1833. String Page = null;
  1834. String order_str = null;
  1835. JSONObject q_json = null;
  1836. JSONArray Sort = null;
  1837. JSONArray jSONArray = new JSONArray();
  1838. JSONObject json = new JSONObject();
  1839. json.put("action", "getSjVList");
  1840. if(queryJson!=null) {
  1841. q_json = JSONObject.fromObject(queryJson);
  1842. address = q_json.has("address")?q_json.getString("address"):null;
  1843. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  1844. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  1845. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  1846. if(q_json.has("company_code")) {
  1847. if((q_json.optJSONObject("company_code")!=null)
  1848. &&(q_json.optJSONObject("company_code").isArray())) {
  1849. JSONArray j_tmp = q_json.getJSONArray("company_code");
  1850. for(int i=0;i<j_tmp.size();i++) {
  1851. String tmp = j_tmp.getString(i);
  1852. if(i==0)
  1853. company_code_list = tmp;
  1854. else
  1855. company_code_list += ","+tmp;
  1856. }
  1857. }else
  1858. company_code = q_json.getString("company_code");
  1859. }
  1860. company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  1861. if(q_json.has("device_code")) {
  1862. if((q_json.optJSONObject("device_code")!=null)
  1863. &&(q_json.optJSONObject("device_code").isArray())){
  1864. JSONArray j_tmp = q_json.getJSONArray("device_code");
  1865. for(int i=0;i<j_tmp.size();i++) {
  1866. String tmp = j_tmp.getString(i);
  1867. if(i==0)
  1868. device_code_list = tmp;
  1869. else
  1870. device_code_list += ","+tmp;
  1871. }
  1872. }else
  1873. device_code = q_json.getString("device_code");
  1874. }
  1875. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  1876. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  1877. }
  1878. if(V_LOGINNAME.equals("ypsgec")) {
  1879. return json.toString();
  1880. }else {
  1881. if(sort!=null) {
  1882. Sort = JSONArray.fromObject(sort);
  1883. if((Sort.isArray())&&(Sort.size()>0)) {
  1884. JSONObject s_json = Sort.getJSONObject(0);
  1885. order = s_json.has("property")?s_json.getString("property"):order;
  1886. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  1887. }
  1888. json.put("sort", sort);
  1889. }
  1890. Start = start;
  1891. Limit = limit;
  1892. Page = page;
  1893. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  1894. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  1895. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  1896. if(list.size()>0) {
  1897. for(int i=0;i<list.size();i++) {
  1898. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  1899. YtiotVUsercompanyId oid = o.getId();
  1900. if(i==0)
  1901. Company_Code_List = oid.getOwnerCode();
  1902. else
  1903. Company_Code_List += ","+oid.getOwnerCode();
  1904. }
  1905. }
  1906. }
  1907. if(address!=null)
  1908. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("address")+" like '%"+address+"' ";
  1909. if((clzt!=null)&&(clzt.length()>0))
  1910. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("clzt")+" = "+clzt+" ";
  1911. if(Company_Code_List!=null)
  1912. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  1913. else {
  1914. if(company_code!=null)
  1915. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = "+company_code+" ";
  1916. if(company_code_list!=null)
  1917. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1918. }
  1919. // if(company_code!=null)
  1920. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = '"+company_code+"' ";
  1921. // if(company_code_list!=null)
  1922. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  1923. if(company_name!=null)
  1924. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_name")+" like '%"+company_name+"%' ";
  1925. if(device_code!=null)
  1926. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" = '"+device_code+"' ";
  1927. if(device_code_list!=null)
  1928. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" in ("+device_code_list+") ";
  1929. if(time_start!=null)
  1930. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" >= '"+time_start+"' ";
  1931. if(time_end!=null)
  1932. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" <= '"+time_end+"' ";
  1933. if(COMMSTATUS!=null) {
  1934. if(COMMSTATUS.equals("NO"))
  1935. hqlwhere = chkhw(hqlwhere)+"( u.id.data1 <> 'WP4' and u.id.data1 <> 'LL4' ) ";
  1936. else if(COMMSTATUS.equals("ONLY"))
  1937. hqlwhere = chkhw(hqlwhere)+" ( u.id.data1 = 'WP4' or u.id.data1 = 'LL4' ) ";
  1938. }
  1939. if(order!=null)
  1940. order_str = " order by u.id."+fieldname(order);
  1941. else
  1942. order_str = " order by u.id.id ";
  1943. int totalCount = ytiotVAlarmDao.getSJCount(hqlwhere);
  1944. json.put("totalCount", totalCount);
  1945. if(Start!=null){
  1946. if(Integer.parseInt(Start)>totalCount){
  1947. Start = "0";
  1948. Page = "0";
  1949. }else if(page==null)
  1950. Page="0";
  1951. }else{
  1952. Start = "0";
  1953. Page = "0";
  1954. }
  1955. json.put("page", Page);
  1956. json.put("start", Start);
  1957. json.put("limit", Limit);
  1958. if(totalCount>0) {
  1959. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  1960. List<?> list = ytiotVAlarmDao.SJQuery(hqlwhere, order_str, dir, Start, Limit);
  1961. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1962. if(list.size()>0) {
  1963. for(int i=0;i<list.size();i++) {
  1964. YtiotVSj hj = (YtiotVSj)list.get(i);
  1965. YtiotVSjId id = hj.getId();
  1966. String cl_name = "";
  1967. if((company_code!=null)&&(i==0))
  1968. json.put("company_name", id.getCompanyName());
  1969. Map<String, Comparable> map = new HashMap<String, Comparable>();
  1970. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  1971. map.put("address", id.getAddress());
  1972. map.put("cldh", id.getCldh());
  1973. map.put("cllx", id.getCllx());
  1974. map.put("cllxr", id.getCllxr());
  1975. map.put("clnr", id.getClnr());
  1976. map.put("clr", id.getClr());
  1977. map.put("clwb", id.getClwb());
  1978. map.put("clzt", id.getClzt()==0?"未处理":"已处理");
  1979. map.put("clsj", df.format(id.getClsj()));
  1980. map.put("company_code", id.getCompanyCode());
  1981. map.put("company_name", id.getCompanyName());
  1982. map.put("data1", id.getData1());
  1983. map.put("data2", id.getData2());
  1984. map.put("data3", id.getData3());
  1985. map.put("data4", id.getData4()+(id.getData1().equals("WP1")?"MPa"
  1986. :(id.getData1().equals("WP2")?"MPa"
  1987. :(id.getData1().equals("WP3")?"MPa"
  1988. :(id.getData1().equals("WP4")?"MPa"
  1989. :(id.getData1().equals("WP0")?"MPa"
  1990. :(id.getData1().equals("LL1")?"m"
  1991. :(id.getData1().equals("LL2")?"m"
  1992. :(id.getData1().equals("LL3")?"m"
  1993. :(id.getData1().equals("LL0")?"m":""))))))))));
  1994. map.put("data5", id.getData5());
  1995. if(id.getClzt()==1)
  1996. map.put("clsj", df.format(id.getClsj()));
  1997. else
  1998. map.put("clsj", "");
  1999. map.put("device_code", id.getDeviceCode());
  2000. map.put("id", id.getId());
  2001. map.put("name", id.getName());
  2002. map.put("ncmd", id.getNcmd());
  2003. map.put("port", id.getPort());
  2004. map.put("position", id.getPosition());
  2005. map.put("status", id.getStatus());
  2006. map.put("time", df.format(id.getTime()));
  2007. map.put("vidoe", id.getVideo());
  2008. map.put("fullname", id.getName());
  2009. map.put("data", id.getData1().equals("WP1")?"低压"
  2010. :(id.getData1().equals("WP2")?"高压"
  2011. :(id.getData1().equals("WP3")?"故障"
  2012. :(id.getData1().equals("WP4")?"离线"
  2013. :(id.getData1().equals("WP0")?"正常"
  2014. :(id.getData1().equals("LL1")?"低压"
  2015. :(id.getData1().equals("LL2")?"高压"
  2016. :(id.getData1().equals("LL3")?"故障"
  2017. :(id.getData1().equals("LL0")?"正常":id.getData1())))))))));
  2018. if((id.getClr().length()>0)
  2019. &&(ulist.size()>0)){
  2020. for(int j=0;j<ulist.size();j++) {
  2021. YtiotVUserphone po = (YtiotVUserphone)ulist.get(j);
  2022. YtiotVUserphoneId poid = po.getId();
  2023. if(id.getClr().equals(poid.getPhone())) {
  2024. cl_name = poid.getUsername();
  2025. break;
  2026. }
  2027. }
  2028. }
  2029. map.put("clr_name", cl_name.length()>0?cl_name:id.getClr());
  2030. JSONObject jSONObject = JSONObject.fromObject(map);
  2031. jSONArray.add(jSONObject);
  2032. }
  2033. json.put("RESULT", jSONArray);
  2034. }
  2035. }
  2036. return json.toString();
  2037. }
  2038. }
  2039. @Override
  2040. public String getRtuVList(String queryJson, String page, String start, String limit, String sort) throws Exception {
  2041. // TODO Auto-generated method stub
  2042. String address = null;
  2043. String clzt = null;
  2044. String company_code = null;
  2045. String company_code_list = null;
  2046. String Company_Code_List = null;
  2047. String company_name = null;
  2048. String device_code = null;
  2049. String device_code_list = null;
  2050. String time_start = null;
  2051. String time_end = null;
  2052. String COMMSTATUS = null;
  2053. String V_LOGINNAME = null;
  2054. String hqlwhere = null;
  2055. String order = null;
  2056. String dir = null;
  2057. String Start = null;
  2058. String Limit = null;
  2059. String Page = null;
  2060. String order_str = null;
  2061. JSONObject q_json = null;
  2062. JSONArray Sort = null;
  2063. JSONArray jSONArray = new JSONArray();
  2064. JSONObject json = new JSONObject();
  2065. json.put("action", "getRtuVList");
  2066. if(queryJson!=null) {
  2067. q_json = JSONObject.fromObject(queryJson);
  2068. address = q_json.has("address")?q_json.getString("address"):null;
  2069. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  2070. clzt = q_json.has("clzt")?q_json.getString("clzt"):null;
  2071. COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null;
  2072. if(q_json.has("company_code")) {
  2073. if((q_json.optJSONObject("company_code")!=null)
  2074. &&(q_json.optJSONObject("company_code").isArray())) {
  2075. JSONArray j_tmp = q_json.getJSONArray("company_code");
  2076. for(int i=0;i<j_tmp.size();i++) {
  2077. String tmp = j_tmp.getString(i);
  2078. if(i==0)
  2079. company_code_list = tmp;
  2080. else
  2081. company_code_list += ","+tmp;
  2082. }
  2083. }else
  2084. company_code = q_json.getString("company_code");
  2085. }
  2086. company_name = q_json.has("company_name")?q_json.getString("company_name"):null;
  2087. if(q_json.has("device_code")) {
  2088. if((q_json.optJSONObject("device_code")!=null)
  2089. &&(q_json.optJSONObject("device_code").isArray())){
  2090. JSONArray j_tmp = q_json.getJSONArray("device_code");
  2091. for(int i=0;i<j_tmp.size();i++) {
  2092. String tmp = j_tmp.getString(i);
  2093. if(i==0)
  2094. device_code_list = tmp;
  2095. else
  2096. device_code_list += ","+tmp;
  2097. }
  2098. }else
  2099. device_code = q_json.getString("device_code");
  2100. }
  2101. time_start = q_json.has("time_start")?q_json.getString("time_start"):null;
  2102. time_end = q_json.has("time_end")?q_json.getString("time_end"):null;
  2103. }
  2104. if(V_LOGINNAME.equals("ypsgec")) {
  2105. return json.toString();
  2106. }else {
  2107. if(sort!=null) {
  2108. Sort = JSONArray.fromObject(sort);
  2109. if((Sort.isArray())&&(Sort.size()>0)) {
  2110. JSONObject s_json = Sort.getJSONObject(0);
  2111. order = s_json.has("property")?s_json.getString("property"):order;
  2112. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  2113. }
  2114. json.put("sort", sort);
  2115. }
  2116. Start = start;
  2117. Limit = limit;
  2118. Page = page;
  2119. if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) {
  2120. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  2121. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  2122. if(list.size()>0) {
  2123. for(int i=0;i<list.size();i++) {
  2124. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  2125. YtiotVUsercompanyId oid = o.getId();
  2126. if(i==0)
  2127. Company_Code_List = oid.getOwnerCode();
  2128. else
  2129. Company_Code_List += ","+oid.getOwnerCode();
  2130. }
  2131. }
  2132. }
  2133. if(address!=null)
  2134. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("address")+" like '%"+address+"' ";
  2135. if((clzt!=null)&&(clzt.length()>0))
  2136. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("clzt")+" = "+clzt+" ";
  2137. if(Company_Code_List!=null)
  2138. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  2139. else {
  2140. if(company_code!=null)
  2141. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" = "+company_code+" ";
  2142. if(company_code_list!=null)
  2143. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  2144. }
  2145. // if(company_code!=null)
  2146. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" like '%"+company_code+"%' ";
  2147. // if(company_code_list!=null)
  2148. // hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_code")+" in ("+company_code_list+") ";
  2149. if(company_name!=null)
  2150. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("company_name")+" like '%"+company_name+"%' ";
  2151. if(device_code!=null)
  2152. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" like '%"+device_code+"%' ";
  2153. if(device_code_list!=null)
  2154. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("device_code")+" in ("+device_code_list+") ";
  2155. if(time_start!=null)
  2156. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" >= '"+time_start+"' ";
  2157. if(time_end!=null)
  2158. hqlwhere = chkhw(hqlwhere) + " u.id."+fieldname("time")+" <= '"+time_end+"' ";
  2159. if(COMMSTATUS!=null) {
  2160. if(COMMSTATUS.equals("NO"))
  2161. hqlwhere = chkhw(hqlwhere)+" u.id.status <> '44' ";
  2162. else if(COMMSTATUS.equals("ONLY"))
  2163. hqlwhere = chkhw(hqlwhere)+" u.id.status = '44' ";
  2164. }
  2165. if(order!=null)
  2166. order_str = " order by u.id."+fieldname(order);
  2167. else
  2168. order_str = " order by u.id.id ";
  2169. System.out.println(hqlwhere);
  2170. int totalCount = ytiotVAlarmDao.getRTUCount(hqlwhere);
  2171. json.put("totalCount", totalCount);
  2172. if(Start!=null){
  2173. if(Integer.parseInt(Start)>totalCount){
  2174. Start = "0";
  2175. Page = "0";
  2176. }else if(page==null)
  2177. Page="0";
  2178. }else{
  2179. Start = "0";
  2180. Page = "0";
  2181. }
  2182. json.put("page", Page);
  2183. json.put("start", Start);
  2184. json.put("limit", Limit);
  2185. if(totalCount>0) {
  2186. List<?> ulist = ytiotVUserphoneDao.query(null, null, null, null, null);
  2187. List<?> list = ytiotVAlarmDao.RTUQuery(hqlwhere, order_str, dir, Start, Limit);
  2188. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2189. if(list.size()>0) {
  2190. for(int i=0;i<list.size();i++) {
  2191. YtiotVRtu hj = (YtiotVRtu)list.get(i);
  2192. YtiotVRtuId id = hj.getId();
  2193. String cl_name = "";
  2194. if((company_code!=null)&&(i==0))
  2195. json.put("company_name", id.getCompanyName());
  2196. Map<String, Comparable> map = new HashMap<String, Comparable>();
  2197. map.put("orderIdx", Integer.parseInt(Start)+i+1);
  2198. map.put("address", id.getAddress());
  2199. map.put("cldh", id.getCldh());
  2200. map.put("cllx", id.getCllx());
  2201. map.put("cllxr", id.getCllxr());
  2202. map.put("clnr", id.getClnr());
  2203. map.put("clr", id.getClr());
  2204. map.put("clwb", id.getClwb());
  2205. map.put("clzt", id.getClzt()==0?"未处理":"已处理");
  2206. if(id.getClzt()==1)
  2207. map.put("clsj", df.format(id.getClsj()));
  2208. else
  2209. map.put("clsj", "");
  2210. map.put("company_code", id.getCompanyCode());
  2211. map.put("company_name", id.getCompanyName());
  2212. map.put("data1", id.getData1());
  2213. map.put("data2", id.getData2());
  2214. map.put("data3", id.getData3());
  2215. map.put("data4", id.getData4());
  2216. map.put("data5", id.getData5());
  2217. map.put("device_code", id.getDeviceCode());
  2218. map.put("id", id.getId());
  2219. map.put("name", id.getName());
  2220. map.put("ncmd", id.getNcmd());
  2221. map.put("port", id.getPort());
  2222. map.put("position", id.getPosition());
  2223. map.put("status", id.getStatus());
  2224. map.put("time", df.format(id.getTime()));
  2225. map.put("vidoe", id.getVideo());
  2226. map.put("fullname", id.getName()+","+((id.getPort().equals("E6")) ?"模拟量":"开关量")+","+((id.getNcmd().length()>0) ?("端口号:"+id.getNcmd()):"")
  2227. +((id.getPort().equals("E3")) ?"":(id.getData2().equals("高压")?(","+"告警值:"+id.getData1()+"MPa")
  2228. :(id.getData2().equals("低压")?(","+"告警值:"+id.getData1()+"MPa")
  2229. :(id.getData2().equals("高温")?(","+"告警值:"+id.getData1()+"℃")
  2230. :(id.getData2().equals("低温")?(","+"告警值:"+id.getData1()+"℃")
  2231. :(id.getData2().equals("高水位")?(","+"告警值:"+id.getData1()+"m")
  2232. :(id.getData2().equals("低水位")?(","+"告警值:"+id.getData1()+"m")
  2233. :(id.getData2().equals("高湿度")?(","+"告警值:"+id.getData1()+"%")
  2234. :(id.getData2().equals("低湿度")?(","+"告警值:"+id.getData1()+"%")
  2235. :""))))))))));
  2236. map.put("data", id.getData2());
  2237. if((id.getClr().length()>0)
  2238. &&(ulist.size()>0)){
  2239. for(int j=0;j<ulist.size();j++) {
  2240. YtiotVUserphone po = (YtiotVUserphone)ulist.get(j);
  2241. YtiotVUserphoneId poid = po.getId();
  2242. if(id.getClr().equals(poid.getPhone())) {
  2243. cl_name = poid.getUsername();
  2244. break;
  2245. }
  2246. }
  2247. }
  2248. map.put("clr_name", cl_name.length()>0?cl_name:id.getClr());
  2249. JSONObject jSONObject = JSONObject.fromObject(map);
  2250. jSONArray.add(jSONObject);
  2251. }
  2252. json.put("RESULT", jSONArray);
  2253. }
  2254. }