YtiotVAlarmServiceImpl.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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. }