YtiotVAlarmServiceImpl.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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");