package cn.com.usky.iot.company.service; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Calendar; import java.text.NumberFormat; import cn.com.usky.iot.admin.dao.YtiotTAdminDao; import cn.com.usky.iot.admin.dao.YtiotVUserCompanyDao; import cn.com.usky.iot.company.dao.YtiotVCompanyDao; import cn.com.usky.iot.entity.YtiotTAdmin; import cn.com.usky.iot.entity.YtiotTInspectors; import cn.com.usky.iot.entity.YtiotVCompany; import cn.com.usky.iot.entity.YtiotVCompanyId; import cn.com.usky.iot.entity.YtiotVUsercompany; import cn.com.usky.iot.entity.YtiotVUsercompanyId; import cn.com.usky.iot.entity.YtiotTProjectDetails; import cn.com.usky.iot.entity.YtiotTProjectDevice; import cn.com.usky.iot.entity.YtiotTProjectMonitor; import cn.com.usky.iot.entity.YtiotVEfire; import cn.com.usky.iot.entity.YtiotVEfireId; import cn.com.usky.iot.entity.YtiotVHj; import cn.com.usky.iot.entity.YtiotVHjId; import cn.com.usky.iot.entity.YtiotVRtu; import cn.com.usky.iot.entity.YtiotVRtuId; import cn.com.usky.iot.entity.YtiotVSj; import cn.com.usky.iot.entity.YtiotVSjId; import cn.com.usky.iot.alarm.dao.YtiotVAlarmDao; import cn.com.usky.iot.data.dao.YtiotVDataDao; import cn.com.usky.iot.entity.YtiotVEfire; import cn.com.usky.iot.entity.YtiotVEfireId; import cn.com.usky.iot.entity.YtiotVHj; import cn.com.usky.iot.entity.YtiotVHjId; import cn.com.usky.iot.entity.YtiotVRtu; import cn.com.usky.iot.entity.YtiotVRtuId; import cn.com.usky.iot.entity.YtiotVSj; import cn.com.usky.iot.entity.YtiotVSjId; import cn.com.usky.utils.MD5Util; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; public class YtiotVCompanyServiceImpl implements YtiotVCompanyService { private YtiotVCompanyDao ytiotVCompanyDao; private YtiotTAdminDao ytiotTAdminDao; private YtiotVUserCompanyDao ytiotVUserCompanyDao; private YtiotVAlarmDao ytiotVAlarmDao; private YtiotVDataDao ytiotVDataDao; public YtiotVDataDao getYtiotVDataDao() { return ytiotVDataDao; } public void setYtiotVDataDao(YtiotVDataDao ytiotVDataDao) { this.ytiotVDataDao = ytiotVDataDao; } 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 YtiotVCompanyDao getYtiotVCompanyDao() { return ytiotVCompanyDao; } public void setYtiotVCompanyDao(YtiotVCompanyDao ytiotVCompanyDao) { this.ytiotVCompanyDao = ytiotVCompanyDao; } 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 field){ if(field.equals("building_id")) return "buildingId"; if(field.equals("building_name")) return "buildingName"; if(field.equals("create_man")) return "createMan"; if(field.equals("create_time")) return "createTime"; if(field.equals("owner_address")) return "ownerAddress"; if(field.equals("owner_id")) return "ownerId"; if(field.equals("owner_man")) return "ownerMan"; if(field.equals("owner_name")) return "ownerName"; if(field.equals("owner_office")) return "ownerOffice"; if(field.equals("company_code")) return "companyCode"; return field; } @Override public String getVCompanyList(String queryJson, String page, String start, String limit, String sort) throws Exception { // TODO Auto-generated method stub String addr1=null, addr2=null, addr3=null; String addr1list=null, addr2list=null, addr3list=null; String address=null, building_id=null, building_name=null, create_man=null; String data1=null, data2=null, data3=null, fulladdress=null; String h5=null, hls=null, id=null, owner_address=null; String owner_id=null, owner_man=null, owner_name=null; String owner_id_list=null, building_id_list=null; String owner_office=null, rtmp=null, xmlx=null, xmlx_list=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", "getVCompanyList"); if(queryJson!=null) { q_json = JSONObject.fromObject(queryJson); if(q_json.has("addr1")) { if(((JSONObject) q_json.get("addr1")).isArray()) { JSONArray j_tmp = q_json.getJSONArray("addr1"); 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(addr1!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("addr1")+" like '%"+addr1+"%' "; if(addr1list!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("addr1")+" in ("+addr1list+") "; if(addr2!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("addr2")+" like '%"+addr2+"%' "; if(addr2list!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("addr2")+" in ("+addr2list+") "; if(addr3!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("addr3")+" like '%"+addr3+"%' "; if(addr3list!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("addr3")+" in ("+addr3list+") "; if(address!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("address")+" like '%"+address+"%' "; if(building_id!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("building_id")+" like '%"+building_id+"%' "; if(building_id_list!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("building_id")+" in ("+building_id_list+") "; if(building_name!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("building_name")+" like '%"+building_name+"%' "; if(create_man!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("create_man")+" like '%"+create_man+"%' "; if(data1!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("data1")+" like '%"+data1+"%' "; if(data2!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("data2")+" like '%"+data2+"%' "; if(data3!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("data3")+" like '%"+data3+"%' "; if(fulladdress!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("fulladdress")+" like '%"+fulladdress+"%' "; if(id!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("id")+" = '"+id+"' "; if(owner_id!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("owner_id")+" = "+owner_id+" "; if(owner_id_list!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("owner_id")+" in ("+owner_id_list+") "; if(owner_address!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("owner_address")+" like '%"+owner_address+"%' "; if(owner_office!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("owner_office")+" like '%"+owner_office+"%' "; if(xmlx!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("xmlx")+" like '%"+xmlx+"%' "; if(xmlx_list!=null) hqlwhere = chkhw(hqlwhere)+"u.id."+fieldname("xmlx")+" in ("+xmlx_list+") "; if(order!=null) order_str = " order by u.id."+fieldname(order); else order_str = " order by u.id."+fieldname("id"); int totalCount = ytiotVCompanyDao.getCount(hqlwhere); json.put("totalCount", totalCount); if(Start!=null){ if(Integer.parseInt(Start)>totalCount){ 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 = ytiotVCompanyDao.query(hqlwhere, order_str, dir, Start, Limit); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if(list.size()>0) { for(int i=0;i0) { YtiotTAdmin o = (YtiotTAdmin)list.get(0); E_STATUS = Integer.parseInt(o.getEStatus()); } String where = " where u.id.agentid='"+V_LOGINNAME+"' "; List list1 = ytiotVUserCompanyDao.query(where, null, null, null, null); if(list1.size()>0) { for(int i=0;i0) { List list = ytiotVCompanyDao.query(hqlwhere, null, null, null, null); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if(list.size()>0) { for(int i=0;i0) { for(int i=0;i0) { for(int i=0;i '"+start_data+"' "; hswhere = chkhw(hswhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; hrwhere = chkhw(hrwhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; hewhere = chkhw(hewhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; efwhere = chkhw(efwhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; efrwhere = chkhw(efrwhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; videorwhere = chkhw(videorwhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; sjwhere = chkhw(sjwhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; sjrwhere = chkhw(sjrwhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; rtuwhere = chkhw(rtuwhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; rturwhere = chkhw(rturwhere)+"u.id."+fieldname("time")+" > '"+start_data+"' "; if(end_data!=null) hhwhere = chkhw(hhwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; hswhere = chkhw(hswhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; hrwhere = chkhw(hrwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; hewhere = chkhw(hewhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; efwhere = chkhw(efwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; efrwhere = chkhw(efrwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; videorwhere = chkhw(videorwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; sjwhere = chkhw(sjwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; sjrwhere = chkhw(sjrwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; rtuwhere = chkhw(rtuwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; rturwhere = chkhw(rturwhere)+"u.id."+fieldname("time")+" < '"+end_data+"' "; int hjtotalCount = ytiotVAlarmDao.getHJCount(hhwhere); int clhjtotalCount = ytiotVAlarmDao.getHJCount(hswhere); int lxhjtotalCount = ytiotVAlarmDao.getHJCount(hrwhere); int cllxhjtotalCount = ytiotVAlarmDao.getHJCount(hewhere); int eftotalCount = ytiotVAlarmDao.getEFireCount(hhwhere); int cleftotalCount = ytiotVAlarmDao.getEFireCount(hswhere); int lxeftotalCount = ytiotVAlarmDao.getEFireCount(efrwhere); int cllxeftotalCount = ytiotVAlarmDao.getEFireCount(efwhere); int sjtotalCount = ytiotVAlarmDao.getSJCount(hhwhere); int clsjtotalCount = ytiotVAlarmDao.getSJCount(hswhere); int lxsjtotalCount = ytiotVAlarmDao.getSJCount(sjrwhere); int cllxsjtotalCount = ytiotVAlarmDao.getSJCount(sjwhere); int rtutotalCount = ytiotVAlarmDao.getRTUCount(hhwhere); int clrtutotalCount = ytiotVAlarmDao.getRTUCount(hswhere); int lxrtutotalCount = ytiotVAlarmDao.getRTUCount(rturwhere); int cllxrtutotalCount = ytiotVAlarmDao.getRTUCount(rtuwhere); int dwhjtotalCount = ytiotVDataDao.getSyncStatusCount1(dwwhere); int dwsjtotalCount = ytiotVDataDao.getSyncStatusCount1(dwsjwhere); int dwrtutotalCount = ytiotVDataDao.getSyncStatusCount1(dwrtuwhere); int dweftotalCount = ytiotVDataDao.getSyncStatusCount1(dwefwhere); int dwvideototalCount = ytiotVDataDao.getSyncStatusCount1(dwvideowhere); int videototalCount = ytiotVAlarmDao.getCount("ytiot_v_video2017",hhwhere); int clvideototalCount = ytiotVAlarmDao.getCount("ytiot_v_video2017",hswhere); NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); if(hjtotalCount==0) { String result = "100"; json.put("hjbaifenbi", result); }else { String result = numberFormat.format((float)clhjtotalCount/(float)hjtotalCount*100); json.put("hjbaifenbi", result); // int clhjbaifenbi = Integer.parseInt( result ); // json.put("clhjbaifenbi", clhjbaifenbi); } if(lxhjtotalCount==0) { String result = "100"+"%"; json.put("lxhjbaifenbi", result); }else { String result = numberFormat.format((float)cllxhjtotalCount/(float)lxhjtotalCount*100); json.put("lxhjbaifenbi", result+"%"); } if(eftotalCount==0) { String result = "100"; json.put("efbaifenbi", result); }else { String result = numberFormat.format((float)cleftotalCount/(float)eftotalCount*100); json.put("efbaifenbi", result); } if(lxeftotalCount==0) { String result = "100"+"%"; json.put("lxefbaifenbi", result); }else { String result = numberFormat.format((float)cllxeftotalCount/(float)lxeftotalCount*100); json.put("lxefbaifenbi", result+"%"); } if(videototalCount==0) { String result = "100"; json.put("videobaifenbi", result); }else { String result = numberFormat.format((float)clvideototalCount/(float)videototalCount*100); json.put("videobaifenbi", result); } if(sjtotalCount==0) { String result = "100"; json.put("sjbaifenbi", result); }else { String result = numberFormat.format((float)clsjtotalCount/(float)sjtotalCount*100); json.put("sjbaifenbi", result); } if(lxsjtotalCount==0) { String result = "100"+"%"; json.put("lxsjbaifenbi", result); }else { String result = numberFormat.format((float)cllxsjtotalCount/(float)lxsjtotalCount*100); json.put("lxsjbaifenbi", result+"%"); } if(rtutotalCount==0) { String result = "100"; json.put("rtubaifenbi", result); }else { String result = numberFormat.format((float)clrtutotalCount/(float)rtutotalCount*100); json.put("rtubaifenbi", result); } if(lxrtutotalCount==0) { String result = "100"+"%"; json.put("lxrtubaifenbi", result); }else { String result = numberFormat.format((float)cllxrtutotalCount/(float)lxrtutotalCount*100); json.put("lxrtubaifenbi", result+"%"); } if(dwhjtotalCount==0) { hjresult = "0"; lxhjresult = "0"; }else { hjresult = numberFormat.format((float)hjtotalCount/(float)days/(float)dwhjtotalCount); lxhjresult = numberFormat.format((float)lxhjtotalCount/(float)days/(float)dwhjtotalCount); } if(dwsjtotalCount==0) { sjresult = "0"; lxsjresult = "0"; }else { sjresult = numberFormat.format((float)sjtotalCount/(float)days/(float)dwsjtotalCount); lxsjresult = numberFormat.format((float)lxsjtotalCount/(float)days/(float)dwsjtotalCount); } if(dwrtutotalCount==0) { rturesult = "0"; lxrturesult = "0"; }else { rturesult = numberFormat.format((float)rtutotalCount/(float)days/(float)dwrtutotalCount); lxrturesult = numberFormat.format((float)lxrtutotalCount/(float)days/(float)dwrtutotalCount); } if(dweftotalCount==0) { efresult = "0"; lxefresult = "0"; }else { efresult = numberFormat.format((float)eftotalCount/(float)days/(float)dweftotalCount); lxefresult = numberFormat.format((float)lxeftotalCount/(float)days/(float)dweftotalCount); } if(dwvideototalCount==0) { videoresult = "0"; }else { videoresult = numberFormat.format((float)videototalCount/(float)days/(float)dwvideototalCount); } int hjsjrtuCount = hjtotalCount+sjtotalCount+rtutotalCount+eftotalCount+videototalCount; String result1 = numberFormat.format((float)hjtotalCount/(float)hjsjrtuCount*100); String result2 = numberFormat.format((float)sjtotalCount/(float)hjsjrtuCount*100); String result3 = numberFormat.format((float)rtutotalCount/(float)hjsjrtuCount*100); String result4 = numberFormat.format((float)eftotalCount/(float)hjsjrtuCount*100); String result5 = numberFormat.format((float)videototalCount/(float)hjsjrtuCount*100); Map map4 = new HashMap(); map4.put("lxhjresult", lxhjresult); map4.put("lxsjresult", lxsjresult); map4.put("lxrturesult", lxrturesult); map4.put("lxefresult", lxefresult); map4.put("efresult", efresult); map4.put("videoresult", videoresult); map4.put("dweftotalCount", dweftotalCount); map4.put("dwvideototalCount", dwvideototalCount); map4.put("eftotalCount", eftotalCount); map4.put("cleftotalCount", cleftotalCount); map4.put("lxeftotalCount", lxeftotalCount); map4.put("cllxeftotalCount", cllxeftotalCount); map4.put("videototalCount", videototalCount); map4.put("clvideototalCount", clvideototalCount); map4.put("result1", result1); map4.put("result2", result2); map4.put("result3", result3); map4.put("result4", result4); map4.put("result5", result5); // map.put("xmlx", g.getXmlx()); JSONObject jSONObject4 = JSONObject.fromObject(map4); jSONArray4.add(jSONObject4); json.put("RESULT4", jSONArray4); json.put("hjtotalCount", hjtotalCount); json.put("clhjtotalCount", clhjtotalCount); json.put("lxhjtotalCount", lxhjtotalCount); json.put("cllxhjtotalCount", cllxhjtotalCount); json.put("sjtotalCount", sjtotalCount); json.put("clsjtotalCount", clsjtotalCount); json.put("lxsjtotalCount", lxsjtotalCount); json.put("cllxsjtotalCount", cllxsjtotalCount); json.put("rtutotalCount", rtutotalCount); json.put("clrtutotalCount", clrtutotalCount); json.put("lxrtutotalCount", lxrtutotalCount); json.put("cllxrtutotalCount", cllxrtutotalCount); json.put("dwhjtotalCount", dwhjtotalCount); json.put("dwsjtotalCount", dwsjtotalCount); json.put("dwrtutotalCount", dwrtutotalCount); json.put("days", days); json.put("hjresult", hjresult); json.put("sjresult", sjresult); json.put("rturesult", rturesult); List list = ytiotVCompanyDao.query1(hqlwhere, null, null, null, null); List list1 = ytiotVCompanyDao.query2(hqlwhere, null, null, null, null); List list2 = ytiotVCompanyDao.query3(hqlwhere, null, null, null, null); List list3 = ytiotVAlarmDao.HJQuery(hswhere, null, null, null, null); List list4 = ytiotVAlarmDao.SJQuery(hswhere, null, null, null, null); List list5 = ytiotVAlarmDao.RTUQuery(hswhere, null, null, null, null); if(list.size()>0) { for(int i=0;i0) { int device_num=0; for(int i=0;i0) { int device_num2=0; for(int i=0;i0) { for(int i=0;i0) { for(int i=0;i0) { for(int i=0;i