123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- package cn.com.usky.iot.EfAnalysis.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.YtiotTEfAnalysis;
- import cn.com.usky.iot.entity.YtiotTWaterAnalysis;
- import cn.com.usky.iot.EfAnalysis.dao.YtiotTEfAnalysisDao;
- import cn.com.usky.utils.DaoResult;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- public class YtiotTEfAnalysisServicesImpl implements YtiotTEfAnalysisService {
- private YtiotTEfAnalysisDao ytiotTEfAnalysisDao;
- public YtiotTEfAnalysisDao getYtiotTEfAnalysisDao() {
- return ytiotTEfAnalysisDao;
- }
- public void setYtiotTEfAnalysisDao(YtiotTEfAnalysisDao ytiotTEfAnalysisDao) {
- this.ytiotTEfAnalysisDao = ytiotTEfAnalysisDao;
- }
- 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("company_code"))
- return "companyCode";
- if(field.equals("generation_time"))
- return "generationTime";
- if(field.equals("I_ORDER_IDX"))
- return "IOrderIdx";
- if(field.equals("UQ_PARENT_ID"))
- return "uqParentId";
- if(field.equals("UQ_PARENT_COMPANY_ID"))
- return "uqParentCompanyId";
- if(field.equals("V_COMPANY_NAME"))
- return "VCompanyName";
- if(field.equals("V_COMPANY_ADDRESS_0"))
- return "VCompanyAddress0";
- if(field.equals("V_COMPANY_ADDRESS_1"))
- return "VCompanyAddress1";
- if(field.equals("V_COMPANY_ADDRESS_2"))
- return "VCompanyAddress2";
- if(field.equals("E_STATUS"))
- return "EStatus";
- if(field.equals("UQ_ADMIN_ID"))
- return "uqAdminId";
- if(field.equals("I_VERSION"))
- return "IVersion";
- if(field.equals("D_STORETIME"))
- return "DStoretime";
- if(field.equals("V_COMMENT"))
- return "VComment";
- return null;
- }
- @Override
- public String getEfAnalysisList(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 generation_time = null;
-
- String V_COMPANY_NAME=null;//单位名称
- String V_COMPANY_ADDRESS_0=null;//单位地址_1
- String I_VERSION=null;//当前记录版本
- String D_STORETIME=null;//记录存储时间
- String UQ_ADMIN_ID=null;//信息录入人ID\
- String E_STATUS=null;//当前状态,0为待开通服务,1为已开通服务,2为服务锁定,3为已注销,4、5留用
- String V_COMMENT = null;//注册/修改说明
- String company_code = null;//单位编号
- String Page = null;
- String Start = null;
- JSONArray Sort = null;
- String Limit = null;
-
- String hqlwhere = null;
- String order = null;
- String dir = null;
- String order_str = null;
- JSONObject q_json = null;
- JSONArray jSONArray = new JSONArray();
- JSONObject json = new JSONObject();
- json.put("action", "getEfAnalysisList");
- if(queryJson!=null) {
- q_json = JSONObject.fromObject(queryJson);
- company_code= q_json.has("company_code")?q_json.getString("company_code"):null;
- generation_time = q_json.has("generation_time")?q_json.getString("generation_time"):null;
-
- 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";
- }
- // 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(company_code!=null)
- hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+"='"+company_code+"'";
- if(generation_time!=null)
- hqlwhere = chkhw(hqlwhere) + "u."+fieldname("generation_time")+"='"+generation_time+"'";
-
- int totalCount = ytiotTEfAnalysisDao.getCount(hqlwhere);
- //System.out.println(totalCount);
- 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 = ytiotTEfAnalysisDao.query(hqlwhere, order_str, dir, Start, Limit);
- if(list.size()>0) {
- for(int i=0;i<list.size();i++) {
- YtiotTEfAnalysis o = (YtiotTEfAnalysis)list.get(i);
- Map map = new HashMap();
- map.put("data_statistics", o.getDataStatistics());
- map.put("dispersion_rate", o.getDispersionRate());
- map.put("electrical_aging", o.getElectricalAging());
- map.put("equipment_list", o.getEquipmentList());
- map.put("project_situation", o.getProjectSituation());
- map.put("statistical_period", o.getStatisticalPeriod());
- map.put("thermal_aging", o.getThermalAging());
- map.put("creat_time", formatter.format(o.getCreatTime()));
- map.put("generation_time", o.getGenerationTime());
- JSONObject jSONObject = JSONObject.fromObject(map);
- jSONArray.add(jSONObject);
- }
- json.put("RESULT", jSONArray);
- }
- }
- return json.toString();
- }
-
- @Override
- public String getWaterAnalysisList(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 company_code = null;
-
- String generation_time=null;//单位名称
- String V_COMPANY_ADDRESS_0=null;//单位地址_1
- String I_VERSION=null;//当前记录版本
- String D_STORETIME=null;//记录存储时间
- String UQ_ADMIN_ID=null;//信息录入人ID\
- String E_STATUS=null;//当前状态,0为待开通服务,1为已开通服务,2为服务锁定,3为已注销,4、5留用
- String V_COMMENT = null;//注册/修改说明
- String I_ORDER_IDX = null;//序号
- String Page = null;
- String Start = null;
- JSONArray Sort = null;
- String Limit = null;
-
- String hqlwhere = null;
- String order = null;
- String dir = null;
- String order_str = null;
- JSONObject q_json = null;
- JSONArray jSONArray = new JSONArray();
- JSONObject json = new JSONObject();
- json.put("action", "getCompanyList");
- if(queryJson!=null) {
- q_json = JSONObject.fromObject(queryJson);
- company_code= q_json.has("company_code")?q_json.getString("company_code"):null;
- generation_time = q_json.has("generation_time")?q_json.getString("generation_time"):null;
-
- 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(company_code!=null)
- hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+"='"+company_code+"'";
- // if(generation_time!=null)
- // hqlwhere = chkhw(hqlwhere) + "u."+fieldname("generation_time")+"='"+generation_time+"'";
- int totalCount = ytiotTEfAnalysisDao.getWaterCount(hqlwhere);
- //System.out.println(totalCount);
- 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 = ytiotTEfAnalysisDao.queryWater(hqlwhere, order_str, dir, Start, Limit);
- if(list.size()>0) {
- for(int i=0;i<list.size();i++) {
- YtiotTWaterAnalysis o = (YtiotTWaterAnalysis)list.get(i);
- Map map = new HashMap();
- map.put("data_statistics", o.getDataStatistics());
- map.put("dispersion_rate", o.getDispersionRate());
- map.put("leakage_investigation", o.getLeakageInvestigation());
- map.put("equipment_list", o.getEquipmentList());
- map.put("project_situation", o.getProjectSituation());
- map.put("statistical_period", o.getStatisticalPeriod());
- map.put("device_association", o.getDeviceAssociation());
- map.put("data_fluctuation", o.getDataFluctuation());
- map.put("creat_time", formatter.format(o.getCreatTime()));
- map.put("generation_time", o.getGenerationTime());
- JSONObject jSONObject = JSONObject.fromObject(map);
- jSONArray.add(jSONObject);
- }
- json.put("RESULT", jSONArray);
- }
- }
- return json.toString();
- }
- }
|