YtiotTWaterAnalysisServicesImpl.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. package cn.com.usky.iot.EfAnalysis.service;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import cn.com.usky.iot.entity.YtiotTEfAnalysis;
  8. import cn.com.usky.iot.entity.YtiotTWaterAnalysis;
  9. import cn.com.usky.iot.EfAnalysis.dao.YtiotTEfAnalysisDao;
  10. import cn.com.usky.utils.DaoResult;
  11. import net.sf.json.JSONArray;
  12. import net.sf.json.JSONObject;
  13. public class YtiotTEfAnalysisServicesImpl implements YtiotTEfAnalysisService {
  14. private YtiotTEfAnalysisDao ytiotTEfAnalysisDao;
  15. public YtiotTEfAnalysisDao getYtiotTEfAnalysisDao() {
  16. return ytiotTEfAnalysisDao;
  17. }
  18. public void setYtiotTEfAnalysisDao(YtiotTEfAnalysisDao ytiotTEfAnalysisDao) {
  19. this.ytiotTEfAnalysisDao = ytiotTEfAnalysisDao;
  20. }
  21. public boolean chk_string_param(String param) {
  22. if(param==null)
  23. return true;
  24. if(param.indexOf("=")>=0)
  25. return false;
  26. if(param.indexOf("\'")>=0)
  27. return false;
  28. if(param.indexOf("\"")>=0)
  29. return false;
  30. return true;
  31. }
  32. public String chkhw(String hqlwhere){
  33. if(hqlwhere==null)
  34. return " where ";
  35. else
  36. return hqlwhere+" and ";
  37. }
  38. public String fieldname(String field){
  39. if(field.equals("company_code"))
  40. return "companyCode";
  41. if(field.equals("generation_time"))
  42. return "generationTime";
  43. if(field.equals("I_ORDER_IDX"))
  44. return "IOrderIdx";
  45. if(field.equals("UQ_PARENT_ID"))
  46. return "uqParentId";
  47. if(field.equals("UQ_PARENT_COMPANY_ID"))
  48. return "uqParentCompanyId";
  49. if(field.equals("V_COMPANY_NAME"))
  50. return "VCompanyName";
  51. if(field.equals("V_COMPANY_ADDRESS_0"))
  52. return "VCompanyAddress0";
  53. if(field.equals("V_COMPANY_ADDRESS_1"))
  54. return "VCompanyAddress1";
  55. if(field.equals("V_COMPANY_ADDRESS_2"))
  56. return "VCompanyAddress2";
  57. if(field.equals("E_STATUS"))
  58. return "EStatus";
  59. if(field.equals("UQ_ADMIN_ID"))
  60. return "uqAdminId";
  61. if(field.equals("I_VERSION"))
  62. return "IVersion";
  63. if(field.equals("D_STORETIME"))
  64. return "DStoretime";
  65. if(field.equals("V_COMMENT"))
  66. return "VComment";
  67. return null;
  68. }
  69. @Override
  70. public String getEfAnalysisList(String queryJson, String page, String start, String limit, String sort) throws Exception {
  71. // TODO Auto-generated method stub
  72. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  73. String generation_time = null;
  74. String V_COMPANY_NAME=null;//单位名称
  75. String V_COMPANY_ADDRESS_0=null;//单位地址_1
  76. String I_VERSION=null;//当前记录版本
  77. String D_STORETIME=null;//记录存储时间
  78. String UQ_ADMIN_ID=null;//信息录入人ID\
  79. String E_STATUS=null;//当前状态,0为待开通服务,1为已开通服务,2为服务锁定,3为已注销,4、5留用
  80. String V_COMMENT = null;//注册/修改说明
  81. String company_code = null;//单位编号
  82. String Page = null;
  83. String Start = null;
  84. JSONArray Sort = null;
  85. String Limit = null;
  86. String hqlwhere = null;
  87. String order = null;
  88. String dir = null;
  89. String order_str = null;
  90. JSONObject q_json = null;
  91. JSONArray jSONArray = new JSONArray();
  92. JSONObject json = new JSONObject();
  93. json.put("action", "getEfAnalysisList");
  94. if(queryJson!=null) {
  95. q_json = JSONObject.fromObject(queryJson);
  96. company_code= q_json.has("company_code")?q_json.getString("company_code"):null;
  97. generation_time = q_json.has("generation_time")?q_json.getString("generation_time"):null;
  98. order = q_json.has("order")?q_json.getString("order"):null;
  99. dir = q_json.has("dir")?q_json.getString("dir"):null;
  100. Start = q_json.has("start")?q_json.getString("start"):(start!=null)?start:"0";
  101. Limit = q_json.has("limit")?q_json.getString("limit"):(limit!=null)?limit:null;
  102. Page = q_json.has("page")?q_json.getString("page"):(page!=null)?page:"0";
  103. }
  104. // System.out.println();
  105. if(sort!=null) {
  106. Sort = JSONArray.fromObject(sort);
  107. if((Sort.isArray())&&(Sort.size()>0)) {
  108. JSONObject s_json = Sort.getJSONObject(0);
  109. order = s_json.has("property")?s_json.getString("property"):order;
  110. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  111. }
  112. json.put("sort", sort);
  113. }
  114. Start = start;
  115. Limit = limit;
  116. Page = page;
  117. if(company_code!=null)
  118. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+"='"+company_code+"'";
  119. if(generation_time!=null)
  120. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("generation_time")+"='"+generation_time+"'";
  121. int totalCount = ytiotTEfAnalysisDao.getCount(hqlwhere);
  122. //System.out.println(totalCount);
  123. json.put("totalCount", totalCount);
  124. if(Start!=null){
  125. if(Integer.parseInt(Start)>totalCount){
  126. Start = "0";
  127. Page = "0";
  128. }
  129. if(page==null)
  130. Page="0";
  131. }else{
  132. Start = "0";
  133. Page = "0";
  134. }
  135. json.put("page", Page);
  136. json.put("start", Start);
  137. json.put("limit", Limit);
  138. if(totalCount>0) {
  139. List list = ytiotTEfAnalysisDao.query(hqlwhere, order_str, dir, Start, Limit);
  140. if(list.size()>0) {
  141. for(int i=0;i<list.size();i++) {
  142. YtiotTEfAnalysis o = (YtiotTEfAnalysis)list.get(i);
  143. Map map = new HashMap();
  144. map.put("data_statistics", o.getDataStatistics());
  145. map.put("dispersion_rate", o.getDispersionRate());
  146. map.put("electrical_aging", o.getElectricalAging());
  147. map.put("equipment_list", o.getEquipmentList());
  148. map.put("project_situation", o.getProjectSituation());
  149. map.put("statistical_period", o.getStatisticalPeriod());
  150. map.put("thermal_aging", o.getThermalAging());
  151. map.put("creat_time", formatter.format(o.getCreatTime()));
  152. map.put("generation_time", o.getGenerationTime());
  153. JSONObject jSONObject = JSONObject.fromObject(map);
  154. jSONArray.add(jSONObject);
  155. }
  156. json.put("RESULT", jSONArray);
  157. }
  158. }
  159. return json.toString();
  160. }
  161. @Override
  162. public String getWaterAnalysisList(String queryJson, String page, String start, String limit, String sort) throws Exception {
  163. // TODO Auto-generated method stub
  164. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  165. String company_code = null;
  166. String generation_time=null;//单位名称
  167. String V_COMPANY_ADDRESS_0=null;//单位地址_1
  168. String I_VERSION=null;//当前记录版本
  169. String D_STORETIME=null;//记录存储时间
  170. String UQ_ADMIN_ID=null;//信息录入人ID\
  171. String E_STATUS=null;//当前状态,0为待开通服务,1为已开通服务,2为服务锁定,3为已注销,4、5留用
  172. String V_COMMENT = null;//注册/修改说明
  173. String I_ORDER_IDX = null;//序号
  174. String Page = null;
  175. String Start = null;
  176. JSONArray Sort = null;
  177. String Limit = null;
  178. String hqlwhere = null;
  179. String order = null;
  180. String dir = null;
  181. String order_str = null;
  182. JSONObject q_json = null;
  183. JSONArray jSONArray = new JSONArray();
  184. JSONObject json = new JSONObject();
  185. json.put("action", "getCompanyList");
  186. if(queryJson!=null) {
  187. q_json = JSONObject.fromObject(queryJson);
  188. company_code= q_json.has("company_code")?q_json.getString("company_code"):null;
  189. generation_time = q_json.has("generation_time")?q_json.getString("generation_time"):null;
  190. order = q_json.has("order")?q_json.getString("order"):null;
  191. dir = q_json.has("dir")?q_json.getString("dir"):null;
  192. Start = q_json.has("start")?q_json.getString("start"):(start!=null)?start:"0";
  193. Limit = q_json.has("limit")?q_json.getString("limit"):(limit!=null)?limit:null;
  194. Page = q_json.has("page")?q_json.getString("page"):(page!=null)?page:"0";
  195. json.put("query", queryJson);
  196. }
  197. // System.out.println();
  198. if(sort!=null) {
  199. Sort = JSONArray.fromObject(sort);
  200. if((Sort.isArray())&&(Sort.size()>0)) {
  201. JSONObject s_json = Sort.getJSONObject(0);
  202. order = s_json.has("property")?s_json.getString("property"):order;
  203. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  204. }
  205. json.put("sort", sort);
  206. }
  207. Start = start;
  208. Limit = limit;
  209. Page = page;
  210. if(company_code!=null)
  211. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+"='"+company_code+"'";
  212. // if(generation_time!=null)
  213. // hqlwhere = chkhw(hqlwhere) + "u."+fieldname("generation_time")+"='"+generation_time+"'";
  214. int totalCount = ytiotTEfAnalysisDao.getWaterCount(hqlwhere);
  215. //System.out.println(totalCount);
  216. json.put("totalCount", totalCount);
  217. if(Start!=null){
  218. if(Integer.parseInt(Start)>totalCount){
  219. Start = "0";
  220. Page = "0";
  221. }
  222. if(page==null)
  223. Page="0";
  224. }else{
  225. Start = "0";
  226. Page = "0";
  227. }
  228. json.put("page", Page);
  229. json.put("start", Start);
  230. json.put("limit", Limit);
  231. if(totalCount>0) {
  232. List list = ytiotTEfAnalysisDao.queryWater(hqlwhere, order_str, dir, Start, Limit);
  233. if(list.size()>0) {
  234. for(int i=0;i<list.size();i++) {
  235. YtiotTWaterAnalysis o = (YtiotTWaterAnalysis)list.get(i);
  236. Map map = new HashMap();
  237. map.put("data_statistics", o.getDataStatistics());
  238. map.put("dispersion_rate", o.getDispersionRate());
  239. map.put("leakage_investigation", o.getLeakageInvestigation());
  240. map.put("equipment_list", o.getEquipmentList());
  241. map.put("project_situation", o.getProjectSituation());
  242. map.put("statistical_period", o.getStatisticalPeriod());
  243. map.put("device_association", o.getDeviceAssociation());
  244. map.put("data_fluctuation", o.getDataFluctuation());
  245. map.put("creat_time", formatter.format(o.getCreatTime()));
  246. map.put("generation_time", o.getGenerationTime());
  247. JSONObject jSONObject = JSONObject.fromObject(map);
  248. jSONArray.add(jSONObject);
  249. }
  250. json.put("RESULT", jSONArray);
  251. }
  252. }
  253. return json.toString();
  254. }
  255. }