package cn.com.usky.iot.alarm.service; import java.io.BufferedReader; import java.sql.SQLException; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import cn.com.usky.iot.admin.dao.YtiotTAdminDao; import cn.com.usky.iot.admin.dao.YtiotVUserCompanyDao; import cn.com.usky.iot.admin.dao.YtiotVUserphoneDao; import cn.com.usky.iot.alarm.dao.YtiotVAlarmDao; import cn.com.usky.iot.entity.*; import cn.com.usky.utils.DaoQuery; import cn.com.usky.utils.HttpClientUtils; import cn.com.usky.utils.MD5Util; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate3.HibernateCallback; import org.springframework.orm.hibernate3.HibernateTemplate; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; public class YtiotVAlarmServiceImpl implements YtiotVAlarmService { private HibernateTemplate hibernateTemplate; public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { this.hibernateTemplate = hibernateTemplate; } private YtiotVAlarmDao ytiotVAlarmDao; private YtiotVUserphoneDao ytiotVUserphoneDao; private YtiotTAdminDao ytiotTAdminDao; private YtiotVUserCompanyDao ytiotVUserCompanyDao; public YtiotVAlarmDao getYtiotVAlarmDao() { return ytiotVAlarmDao; } public void setYtiotVAlarmDao(YtiotVAlarmDao ytiotVAlarmDao) { this.ytiotVAlarmDao = ytiotVAlarmDao; } public YtiotVUserCompanyDao getYtiotVUserCompanyDao() { return ytiotVUserCompanyDao; } public void setYtiotVUserCompanyDao(YtiotVUserCompanyDao ytiotVUserCompanyDao) { this.ytiotVUserCompanyDao = ytiotVUserCompanyDao; } public YtiotVUserphoneDao getYtiotVUserphoneDao() { return ytiotVUserphoneDao; } public void setYtiotVUserphoneDao(YtiotVUserphoneDao ytiotVUserphoneDao) { this.ytiotVUserphoneDao = ytiotVUserphoneDao; } public YtiotTAdminDao getYtiotTAdminDao() { return ytiotTAdminDao; } public void setYtiotTAdminDao(YtiotTAdminDao ytiotTAdminDao) { this.ytiotTAdminDao = ytiotTAdminDao; } public boolean chk_string_param(String param) { if(param==null) return true; if(param.indexOf("=")>=0) return false; if(param.indexOf("\'")>=0) return false; if(param.indexOf("\"")>=0) return false; return true; } public String chkhw(String hqlwhere){ if(hqlwhere==null) return " where "; else return hqlwhere+" and "; } public String fieldname(String name) { if(name.equals("company_code")) return "companyCode"; if(name.equals("company_name")) return "companyName"; if(name.equals("device_code")) return "deviuceCode"; return name; } @Override public String getEFireVList(String queryJson, String page, String start, String limit, String sort) throws Exception { // TODO Auto-generated method stub String address = null; String clzt = null; String company_code = null; String company_code_list = null; String Company_Code_List = null; String company_name = null; String device_code = null; String device_code_list = null; String time_start = null; String time_end = null; String status = null; String COMMSTATUS = null; String V_LOGINNAME = null; String hqlwhere = null, hhwhere = null; String order = null; String dir = null; String Start = null; String Limit = null; String Page = null; String order_str = null; JSONObject q_json = null; JSONArray Sort = null; JSONArray jSONArray = new JSONArray(); JSONObject json = new JSONObject(); json.put("action", "getEFireVList"); if(queryJson!=null) { q_json = JSONObject.fromObject(queryJson); address = q_json.has("address")?q_json.getString("address"):null; clzt = q_json.has("clzt")?q_json.getString("clzt"):null; COMMSTATUS = q_json.has("COMMSTATUS")?q_json.getString("COMMSTATUS"):null; V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null; if(q_json.has("company_code")) { if((q_json.optJSONObject("company_code")!=null) &&(q_json.optJSONObject("company_code").isArray())) { JSONArray j_tmp = q_json.getJSONArray("company_code"); for(int i=0;i0)) { JSONObject s_json = Sort.getJSONObject(0); order = s_json.has("property")?s_json.getString("property"):order; dir = s_json.has("direction")?s_json.getString("direction"):dir; } json.put("sort", sort); } Start = start; Limit = limit; Page = page; if((V_LOGINNAME!=null)&&(company_code==null)&&(company_code_list==null)) { String where = " where u.id.agentid='"+V_LOGINNAME+"' "; List list = ytiotVUserCompanyDao.query(where, null, null, null, null); if(list.size()>0) { for(int i=0;i0)) { hqlwhere = chkhw(hqlwhere) + " clzt = "+clzt+" "; hhwhere = chkhw(hhwhere) + " u.id.clzt = "+clzt+" "; } if(Company_Code_List!=null) { hqlwhere = chkhw(hqlwhere) + " company_code in ("+Company_Code_List+") "; hhwhere = chkhw(hhwhere) + " u.id.companyCode in ("+Company_Code_List+") "; }else { if(company_code!=null) { hqlwhere = chkhw(hqlwhere) + " company_code = "+company_code+" "; hhwhere = chkhw(hhwhere) + " u.id.companyCode = "+company_code+" "; } if(company_code_list!=null) { hqlwhere = chkhw(hqlwhere) + " company_code in ("+company_code_list+") "; hhwhere = chkhw(hhwhere) + " u.id.companyCode in ("+company_code_list+") "; } } if(device_code!=null) { hqlwhere = chkhw(hqlwhere) + " device_code = "+device_code+" "; hhwhere = chkhw(hhwhere) + " u.id.deviceCode = "+device_code+" "; } if(device_code_list!=null) { hqlwhere = chkhw(hqlwhere) + " device_code in ("+device_code_list+") "; hhwhere = chkhw(hhwhere) + " u.id.deviceCode in ("+device_code_list+") "; } if(time_start!=null) { hqlwhere = chkhw(hqlwhere) + " time >= '"+time_start+"' "; hhwhere = chkhw(hhwhere) + " u.id.time >= '"+time_start+"' "; } if(time_end!=null) { hqlwhere = chkhw(hqlwhere) + " time <= '"+time_end+"' "; hhwhere = chkhw(hhwhere) + " u.id.time <= '"+time_end+"' "; } if(COMMSTATUS!=null) { if(COMMSTATUS.equals("NO")) { hqlwhere = chkhw(hqlwhere)+" data1 <> 'EF9' "; hhwhere = chkhw(hhwhere)+" u.id.data1 <> 'EF9' "; } else if(COMMSTATUS.equals("ONLY")) { hqlwhere = chkhw(hqlwhere)+" data1 = 'EF9' "; hhwhere = chkhw(hhwhere)+" u.id.data1 = 'EF9' "; } } if(order!=null) order_str = " order by "+order; else order_str = " order by id "; int totalCount = ytiotVAlarmDao.getEFireCount(hhwhere); // System.out.print("shazi");