package cn.com.usky.iot.outcrypackage.service; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import cn.com.usky.iot.entity.YtiotTcAlarmPackages; import cn.com.usky.iot.entity.YtiotTcAlarmPackagesZb; //import cn.com.usky.iot.entity.YtiotTcOutgoingAlarm; import cn.com.usky.iot.entity.YtiotVCompany; import cn.com.usky.iot.entity.YtiotVCompanyId; import cn.com.usky.iot.alarmpackages.dao.YtiotTcAlarmPackagesDao; import cn.com.usky.iot.alarmpackageszb.dao.YtiotTcAlarmPackagesZbDao; //import cn.com.usky.iot.outgoingalarm.dao.YtiotTcOutgoingAlarmDao; import cn.com.usky.iot.company.dao.YtiotVCompanyDao; import cn.com.usky.utils.DaoResult; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class YtiotTOutcryPackageServicesImpl implements YtiotTOutcryPackageService { private YtiotTcAlarmPackagesDao ytiotTcAlarmPackagesDao; private YtiotTcAlarmPackagesZbDao ytiotTcAlarmPackagesZbDao; // private YtiotTcOutgoingAlarmDao ytiotTcOutgoingAlarmDao; private YtiotVCompanyDao ytiotVCompanyDao; public YtiotVCompanyDao getYtiotVCompanyDao() { return ytiotVCompanyDao; } public void setYtiotVCompanyDao(YtiotVCompanyDao ytiotVCompanyDao) { this.ytiotVCompanyDao = ytiotVCompanyDao; } public YtiotTcAlarmPackagesDao getYtiotTcAlarmPackagesDao() { return ytiotTcAlarmPackagesDao; } public void setYtiotTcAlarmPackagesDao(YtiotTcAlarmPackagesDao ytiotTcAlarmPackagesDao) { this.ytiotTcAlarmPackagesDao = ytiotTcAlarmPackagesDao; } public YtiotTcAlarmPackagesZbDao getYtiotTcAlarmPackagesZbDao() { return ytiotTcAlarmPackagesZbDao; } public void setYtiotTcAlarmPackagesZbDao(YtiotTcAlarmPackagesZbDao ytiotTcAlarmPackagesZbDao) { this.ytiotTcAlarmPackagesZbDao = ytiotTcAlarmPackagesZbDao; } // public YtiotTcOutgoingAlarmDao getYtiotTcOutgoingAlarmDao() { // return ytiotTcOutgoingAlarmDao; // } // // public void setYtiotTcOutgoingAlarmDao(YtiotTcOutgoingAlarmDao ytiotTcOutgoingAlarmDao) { // this.ytiotTcOutgoingAlarmDao = ytiotTcOutgoingAlarmDao; // } 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 field){ if(field.equals("UQ_SETMREAL_ID")) return "uqSetmrealId"; if(field.equals("I_ORDER_IDX")) return "IOrderIdx"; if(field.equals("UQ_COMPANY_ID")) return "uqCompanyId"; if(field.equals("D_START_STORETIME")) return "DStartStoretime"; if(field.equals("D_END_STORETIME")) return "DEndStoretime"; if(field.equals("UQ_SETMREAL_ZB_ID")) return "uqSetmrealZbId"; if(field.equals("UQ_CATEGORY")) return "uqCategory"; if(field.equals("I_NUMBER_OF_BARS")) return "INumberOfBars"; if(field.equals("I_CYCLE")) return "ICycle"; if(field.equals("V_COMPANY_NAME")) return "VCompanyName"; if(field.equals("owner_id")) return "ownerId"; if(field.equals("owner_name")) return "ownerName"; if(field.equals("V_PHONE")) return "VPhone"; if(field.equals("E_STATUS")) return "EStatus"; return null; } @Override public String appendOutcryPackage(String queryJson) throws Exception { // TODO Auto-generated method stub SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String UQ_SETMREAL_ID = null; String UQ_COMPANY_ID = null; String D_START_STORETIME = null; String D_END_STORETIME = null; String UQ_SETMREAL_ZB_ID = null; String UQ_CATEGORY = null; String I_NUMBER_OF_BARS = null; String I_CYCLE = null; String V_PHONE = null; String E_STATUS = null; JSONObject q_json = null; JSONArray jSONArray = new JSONArray(); JSONObject json = new JSONObject(); json.put("action", "appendOutcryPackage"); if(queryJson!=null) { q_json = JSONObject.fromObject(queryJson); UQ_COMPANY_ID = q_json.has("UQ_COMPANY_ID")?q_json.getString("UQ_COMPANY_ID"):null; UQ_CATEGORY = q_json.has("UQ_CATEGORY")?q_json.getString("UQ_CATEGORY"):null; D_START_STORETIME = q_json.has("D_START_STORETIME")?q_json.getString("D_START_STORETIME"):null; D_END_STORETIME = q_json.has("D_END_STORETIME")?q_json.getString("D_END_STORETIME"):null; I_NUMBER_OF_BARS = q_json.has("I_NUMBER_OF_BARS")?q_json.getString("I_NUMBER_OF_BARS"):null; I_CYCLE = q_json.has("I_CYCLE")?q_json.getString("I_CYCLE"):null; V_PHONE = q_json.has("V_PHONE")?q_json.getString("V_PHONE"):null; //json.put("query", queryJson); } if(chk_string_param(UQ_COMPANY_ID)&&chk_string_param(UQ_CATEGORY)&&chk_string_param(D_START_STORETIME) &&chk_string_param(D_END_STORETIME)&&chk_string_param(I_NUMBER_OF_BARS) &&chk_string_param(I_CYCLE)) { YtiotTcAlarmPackages o = new YtiotTcAlarmPackages(); o.setUqCompanyId(UQ_COMPANY_ID); o.setVPhone(V_PHONE); o.setDStartStoretime(formatter.parse(D_START_STORETIME)); o.setDEndStoretime(formatter.parse(D_END_STORETIME)); DaoResult ret = ytiotTcAlarmPackagesDao.add(o); YtiotTcAlarmPackagesZb o1 = new YtiotTcAlarmPackagesZb(); o1.setUqSetmrealId(o.getUqSetmrealId()); o1.setUqCategory(UQ_CATEGORY); o1.setINumberOfBars(I_NUMBER_OF_BARS); o1.setICycle(I_CYCLE); o1.setEStatus("1"); DaoResult ret1 = ytiotTcAlarmPackagesZbDao.add(o1); json.put("success", ret1.isSuccess()); json.put("Msg", ret1.getResult()); }else { json.put("success", false); json.put("Msg", "参数验证错误"); } return json.toString(); } @Override public String updateOutcryPackage(String queryJson) throws Exception { // TODO Auto-generated method stub SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String UQ_SETMREAL_ID = null; String UQ_COMPANY_ID = null; String UQ_COMPANY_ID1 = null; String D_START_STORETIME = null; String D_END_STORETIME = null; String UQ_SETMREAL_ZB_ID = null; String UQ_CATEGORY = null; String I_NUMBER_OF_BARS = null; String I_CYCLE = null; String V_PHONE = null; String E_STATUS = null; JSONObject q_json = null; JSONArray jSONArray = new JSONArray(); JSONObject json = new JSONObject(); json.put("action", "updateOutcryPackage"); if(queryJson!=null) { q_json = JSONObject.fromObject(queryJson); UQ_SETMREAL_ID = q_json.has("UQ_SETMREAL_ID")?q_json.getString("UQ_SETMREAL_ID"):null; UQ_COMPANY_ID = q_json.has("UQ_COMPANY_ID")?q_json.getString("UQ_COMPANY_ID"):null; D_START_STORETIME = q_json.has("D_START_STORETIME")?q_json.getString("D_START_STORETIME"):null; D_END_STORETIME = q_json.has("D_END_STORETIME")?q_json.getString("D_END_STORETIME"):null; V_PHONE = q_json.has("V_PHONE")?q_json.getString("V_PHONE"):null; UQ_SETMREAL_ZB_ID = q_json.has("UQ_SETMREAL_ZB_ID")?q_json.getString("UQ_SETMREAL_ZB_ID"):null; UQ_CATEGORY = q_json.has("UQ_CATEGORY")?q_json.getString("UQ_CATEGORY"):null; I_NUMBER_OF_BARS = q_json.has("I_NUMBER_OF_BARS")?q_json.getString("I_NUMBER_OF_BARS"):null; I_CYCLE = q_json.has("I_CYCLE")?q_json.getString("I_CYCLE"):null; E_STATUS = q_json.has("E_STATUS")?q_json.getString("E_STATUS").toUpperCase():null; //json.put("query", queryJson); } if(chk_string_param(UQ_COMPANY_ID)&&chk_string_param(D_START_STORETIME)&&chk_string_param(D_END_STORETIME) &&chk_string_param(UQ_CATEGORY)&&chk_string_param(I_NUMBER_OF_BARS)&&chk_string_param(I_CYCLE) &&chk_string_param(UQ_SETMREAL_ID)&&chk_string_param(UQ_SETMREAL_ZB_ID)&&chk_string_param(V_PHONE)&&chk_string_param(E_STATUS)) { if(UQ_SETMREAL_ID!=null&&UQ_SETMREAL_ZB_ID!=null) { List list = ytiotTcAlarmPackagesDao.query(" where u."+fieldname("UQ_SETMREAL_ID")+" ='"+UQ_SETMREAL_ID+"' ", null, null, null, null); List list1 = ytiotTcAlarmPackagesZbDao.query(" where u."+fieldname("UQ_SETMREAL_ZB_ID")+" ='"+UQ_SETMREAL_ZB_ID+"' ", null, null, null, null); if(list.size()>0&&list1.size()>0) { // System.out.println("测试1"+UQ_SETMREAL_ID); // System.out.println("测试1"+UQ_SETMREAL_ZB_ID); YtiotTcAlarmPackages o = (YtiotTcAlarmPackages) list.get(0); YtiotTcAlarmPackagesZb o1 = (YtiotTcAlarmPackagesZb) list1.get(0); if(UQ_COMPANY_ID!=null) { List list3 = ytiotVCompanyDao.query(" where u.id."+fieldname("owner_name")+" ='"+UQ_COMPANY_ID+"' ", null, null, null, null); if(list3.size()>0) { YtiotVCompany o3 = (YtiotVCompany)list3.get(0); YtiotVCompanyId oid1 = o3.getId(); o.setUqCompanyId(oid1.getOwnerId()); } } if(D_START_STORETIME!=null) o.setDStartStoretime(formatter.parse(D_START_STORETIME)); if(D_END_STORETIME!=null) o.setDEndStoretime(formatter.parse(D_END_STORETIME)); if(V_PHONE!=null) o.setVPhone(V_PHONE); if(UQ_CATEGORY!=null) o1.setUqCategory(UQ_CATEGORY); if(I_NUMBER_OF_BARS!=null) o1.setINumberOfBars(I_NUMBER_OF_BARS); if(I_CYCLE!=null) o1.setICycle(I_CYCLE); o1.setEStatus(E_STATUS); DaoResult ret = ytiotTcAlarmPackagesDao.update(o); DaoResult ret1 = ytiotTcAlarmPackagesZbDao.update(o1); json.put("success", ret1.isSuccess()); json.put("MSG", ret1.getResult()); }else { json.put("success", false); json.put("MSG", "需要编辑的权限记录不存在"); } }else { json.put("success", false); json.put("MSG", "记录ID不能为空"); } }else { json.put("success", false); json.put("MSG", "参数验证错误"); } return json.toString(); } @Override public String deleteOutcryPackage(String queryJson) throws Exception { // TODO Auto-generated method stub //String UQ_COMPANY_ID = null; JSONObject q_json = null; JSONArray jSONArray = new JSONArray(); JSONArray jsonCompanyList = new JSONArray(); JSONObject json = new JSONObject(); json.put("action", "deleteOutcryPackage"); if(queryJson!=null) { q_json = JSONObject.fromObject(queryJson); if(q_json.has("UQ_SETMREAL_ZB_ID_LIST")) { jsonCompanyList = q_json.getJSONArray("UQ_SETMREAL_ZB_ID_LIST"); // System.out.println("测试:111111111111111"); for(int i=0;i0) { // System.out.println("测试:33333333333333"); for(int j=0;j0)) { 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(UQ_COMPANY_ID!=null) { List list3 = ytiotVCompanyDao.query(" where u.id."+fieldname("owner_name")+" ='"+UQ_COMPANY_ID+"' ", null, null, null, null); if(list3.size()>0) { YtiotVCompany o3 = (YtiotVCompany)list3.get(0); YtiotVCompanyId oid1 = o3.getId(); // System.out.println("测试2"); List list6 = ytiotTcAlarmPackagesDao.query(" where u."+fieldname("UQ_COMPANY_ID")+" ='"+oid1.getOwnerId()+"' ", null, null, null, null); if(list6.size()>0) { if(list6.size()==1) { YtiotTcAlarmPackages o6 = (YtiotTcAlarmPackages)list6.get(0); hqlwhere = chkhw(hqlwhere) + "u."+fieldname("UQ_SETMREAL_ID")+" ='"+o6.getUqSetmrealId()+"'"; }else { for(int i=0;i0) { if(list4.size()==1) { YtiotTcAlarmPackages o4 = (YtiotTcAlarmPackages)list4.get(0); hqlwhere = chkhw(hqlwhere) + "u."+fieldname("UQ_SETMREAL_ID")+"='"+o4.getUqSetmrealId()+"'"; }else { for(int i=0;i0) { if(list5.size()==1) { YtiotTcAlarmPackages o5 = (YtiotTcAlarmPackages)list5.get(0); hqlwhere = chkhw(hqlwhere) + "u."+fieldname("UQ_SETMREAL_ID")+"='"+o5.getUqSetmrealId()+"'"; }else { for(int i=0;i0) { if(list8.size()==1) { YtiotTcAlarmPackages o8 = (YtiotTcAlarmPackages)list8.get(0); hqlwhere = chkhw(hqlwhere) + "u."+fieldname("UQ_SETMREAL_ID")+"='"+o8.getUqSetmrealId()+"'"; }else { for(int i=0;itotalCount){ Start = "0"; Page = "0"; } if(page==null) Page="0"; }else{ Start = "0"; Page = "0"; } json.put("page", Page); json.put("start", Start); json.put("limit", Limit); if(totalCount>0) { List list = ytiotTcAlarmPackagesZbDao.query(hqlwhere, order_str, dir, Start, Limit); if(list.size()>0) { for(int i=0;i0) { YtiotTcAlarmPackages o1 = (YtiotTcAlarmPackages)list1.get(0); map.put("UQ_COMPANY_ID", o1.getUqCompanyId()); map.put("V_PHONE", o1.getVPhone()); map.put("D_START_STORETIME", formatter.format(o1.getDStartStoretime())); map.put("D_END_STORETIME",formatter.format(o1.getDEndStoretime())); if(o1.getUqCompanyId()!=null){ List list2 = ytiotVCompanyDao.query(" where u.id."+fieldname("owner_id")+" ='"+o1.getUqCompanyId()+"' ", null, null, null, null); if(list2.size()>0) { YtiotVCompany o2 = (YtiotVCompany)list2.get(0); YtiotVCompanyId oid = o2.getId(); map.put("V_COMPANY_NAME", oid.getOwnerName()); } } } } map.put("I_ORDER_IDX", o.getIOrderIdx()); map.put("UQ_SETMREAL_ZB_ID", o.getUqSetmrealZbId()); if(Integer.parseInt(o.getUqCategory())==1) { map.put("UQ_CATEGORY1", o.getUqCategory()); map.put("UQ_CATEGORY", "火系统报警"); }else if(Integer.parseInt(o.getUqCategory())==2) { map.put("UQ_CATEGORY1", o.getUqCategory()); map.put("UQ_CATEGORY", "水系统报警"); }else if(Integer.parseInt(o.getUqCategory())==3) { map.put("UQ_CATEGORY1", o.getUqCategory()); map.put("UQ_CATEGORY", "烟感报警"); }else if(Integer.parseInt(o.getUqCategory())==4) { map.put("UQ_CATEGORY1", o.getUqCategory()); map.put("UQ_CATEGORY", "消防栓报警"); }else if(Integer.parseInt(o.getUqCategory())==5) { map.put("UQ_CATEGORY1", o.getUqCategory()); map.put("UQ_CATEGORY", "液位报警"); }else if(Integer.parseInt(o.getUqCategory())==6) { map.put("UQ_CATEGORY1", o.getUqCategory()); map.put("UQ_CATEGORY", "RTU报警"); }else if(Integer.parseInt(o.getUqCategory())==7) { map.put("UQ_CATEGORY1", o.getUqCategory()); map.put("UQ_CATEGORY", "电气火灾报警"); }else if(Integer.parseInt(o.getUqCategory())==8) { map.put("UQ_CATEGORY", o.getUqCategory()); map.put("UQ_CATEGORY", "离线报警"); } if(Integer.parseInt(o.getICycle())==0) { map.put("I_CYCLE1", o.getICycle()); map.put("I_CYCLE", "天"); }else if(Integer.parseInt(o.getICycle())==1) { map.put("I_CYCLE1", o.getICycle()); map.put("I_CYCLE", "月"); }else if(Integer.parseInt(o.getICycle())==2) { map.put("I_CYCLE1", o.getICycle()); map.put("I_CYCLE", "年"); } int a=Integer.parseInt(o.getEStatus()); if(a==0) { map.put("E_STATUS", "待开通"); } if(a==1) { map.put("E_STATUS", "已开通"); } if(a==2) { map.put("E_STATUS", "已锁定"); } if(a==3) { map.put("E_STATUS", "注销"); } // map.put("UQ_CATEGORY", o.getUqCategory()); map.put("I_NUMBER_OF_BARS", o.getINumberOfBars()); map.put("UQ_SETMREAL_ID", o.getUqSetmrealId()); JSONObject jSONObject = JSONObject.fromObject(map); jSONArray.add(jSONObject); } json.put("RESULT", jSONArray); } } return json.toString(); } // @Override // public String getCompanyVerList(String queryJson, String page, String start, String limit, String sort) throws Exception { // // TODO Auto-generated method stub // SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // String UQ_COMPANY_ID = null; // String V_COMPANY_NAME = null; // String V_COMPANY_ADDRESS_0 = null; // String E_STATUS = null; //// String UQ_ADMIN_ID = null; // String D_STORETIME = null; // // String hqlwhere = 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", "getCompanyVerList"); // if(queryJson!=null) { // q_json = JSONObject.fromObject(queryJson); // UQ_COMPANY_ID = q_json.has("UQ_COMPANY_ID")?q_json.getString("UQ_COMPANY_ID"):null; // V_COMPANY_NAME = q_json.has("V_COMPANY_NAME")?q_json.getString("V_COMPANY_NAME"):null; //// UQ_ADMIN_ID = q_json.has("UQ_ADMIN_ID")?q_json.getString("UQ_ADMIN_ID"):null; // V_COMPANY_ADDRESS_0 = q_json.has("V_COMPANY_ADDRESS_0")?q_json.getString("V_COMPANY_ADDRESS_0"):null; // E_STATUS = q_json.has("E_STATUS")?q_json.getString("E_STATUS"):null; //// System.out.println("测试"+E_STATUS); //// int a=Integer.parseInt("E_STATUS"); //// if(a ==10) { //// E_STATUS=null; //// } //// System.out.println("测试1"+E_STATUS); // // order = q_json.has("order")?q_json.getString("order"):null; // dir = q_json.has("dir")?q_json.getString("dir"):null; // Start = q_json.has("start")?q_json.getString("start"):(start!=null)?start:"0"; // Limit = q_json.has("limit")?q_json.getString("limit"):(limit!=null)?limit:null; // Page = q_json.has("page")?q_json.getString("page"):(page!=null)?page:"0"; // json.put("query", queryJson); // } //// System.out.println(); // if(sort!=null) { // Sort = JSONArray.fromObject(sort); // if((Sort.isArray())&&(Sort.size()>0)) { // 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(UQ_COMPANY_ID!=null) // hqlwhere = chkhw(hqlwhere) + "u."+fieldname("UQ_COMPANY_ID")+"='"+UQ_COMPANY_ID+"'"; // if(V_COMPANY_NAME!=null) // hqlwhere = chkhw(hqlwhere) + "u."+fieldname("V_COMPANY_NAME")+" like '%"+V_COMPANY_NAME+"%'"; //// if(UQ_ADMIN_ID!=null) //// hqlwhere = chkhw(hqlwhere) + "u."+fieldname("UQ_ADMIN_ID")+"='"+UQ_ADMIN_ID+"'"; // if(V_COMPANY_ADDRESS_0!=null) // hqlwhere = chkhw(hqlwhere) + "u."+fieldname("V_COMPANY_ADDRESS_0")+" like '%"+V_COMPANY_ADDRESS_0+"%'"; //// if(E_STATUS!=null) //// hqlwhere = chkhw(hqlwhere) + "u."+fieldname("E_STATUS")+"='"+E_STATUS+"'"; // if(order!=null) // order_str = " order by u."+fieldname(order); // else // order_str = " order by u."+fieldname("I_COMPANYVER_ID"); // // //System.out.println(hqlwhere); //// System.out.println(order_str); // int totalCount = ytiotTCompanyVerDao.getCount(hqlwhere); // json.put("totalCount", totalCount); // if(Start!=null){ // if(Integer.parseInt(Start)>totalCount){ // Start = "0"; // Page = "0"; // }else if(page==null) // Page="0"; // }else{ // Start = "0"; // Page = "0"; // } // json.put("page", Page); // json.put("start", Start); // json.put("limit", Limit); // if(totalCount>0) { // List list = ytiotTCompanyVerDao.query(hqlwhere, order_str, dir, Start, Limit); //// System.out.println(list); // if(list.size()>0) { // for(int i=0;i