WindturbinegoodhistoryAction.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. package com.hcks.cmfds.action.apdata;
  2. import java.text.SimpleDateFormat;
  3. import java.util.ArrayList;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import org.apache.struts2.convention.annotation.Action;
  10. import org.apache.struts2.convention.annotation.Namespace;
  11. import org.apache.struts2.convention.annotation.Result;
  12. import com.hcks.cmfds.commons.lang.QueryOrder;
  13. import com.hcks.cmfds.commons.util.DateUtils;
  14. import com.hcks.cmfds.commons.util.JsonUtils;
  15. import com.hcks.cmfds.commons.util.StringUtils;
  16. import com.hcks.cmfds.core.web.action.PaginationAction;
  17. import com.hcks.cmfds.model.Windpowerstation;
  18. import com.hcks.cmfds.model.Windturbine;
  19. import com.hcks.cmfds.model.Windturbineanalysisday;
  20. import com.hcks.cmfds.service.CacheContext;
  21. import com.hcks.cmfds.service.WindturbineanalysisdayService;
  22. @Namespace("/wtgoodness")
  23. @Result(name = "json", type = "json", params = { "textName", "json" })
  24. public class WindturbinegoodhistoryAction extends PaginationAction {
  25. private static final long serialVersionUID = 1L;
  26. private List<Windpowerstation> wps;
  27. private Date beginDate;
  28. private Date endDate;
  29. private String json;
  30. private String windfarm;
  31. private String windturbineid;
  32. private String wtId;;
  33. private Date recorddate;
  34. private String url1;
  35. private Map<String, List<Windturbine>> wtsmap;
  36. private List<Windturbineanalysisday> vos;
  37. private WindturbineanalysisdayService windturbineanalysisdayService;
  38. private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  39. @Action(value = "goodhistoryindex", results = { @Result(name = "success", location = "/pages/apdata/goodhistory.jsp") })
  40. public String goodhistoryindex() {
  41. initial();
  42. vos = new ArrayList<Windturbineanalysisday>();
  43. return SUCCESS;
  44. }
  45. @Action(value = "goodhistorylist")
  46. public String goodhistorylist() throws Exception {
  47. initial();
  48. Map<String, Object> params = new HashMap<String, Object>();
  49. if(StringUtils.notEmp(windturbineid))
  50. {
  51. params.put("windturbineid", windturbineid);
  52. }
  53. if(StringUtils.notEmp(beginDate))
  54. {
  55. params.put("@recorddate", DateUtils.truncate(beginDate));
  56. }
  57. if(StringUtils.notEmp(endDate))
  58. {
  59. params.put("$recorddate", DateUtils.truncate(endDate));
  60. }
  61. QueryOrder orders=new QueryOrder("recorddate", "desc");
  62. vos = windturbineanalysisdayService.findByProperties(params, orders);
  63. if (null != vos && !vos.isEmpty()) {
  64. json = JsonUtils.getJsons(vos);
  65. } else {
  66. json = JsonUtils.getJsons(new ArrayList<Windturbineanalysisday>());
  67. }
  68. return JSON;
  69. }
  70. // private String getJsons(Object object)
  71. // {
  72. // ObjectMapper mappers = new ObjectMapper();
  73. // String SIMPLE_DATETIME_FORMAT = "yyyy-MM-dd";
  74. // SimpleDateFormat df = new SimpleDateFormat(SIMPLE_DATETIME_FORMAT);
  75. // mappers.configure(org.codehaus.jackson.map.SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
  76. // mappers.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
  77. // mappers.getSerializationConfig().setDateFormat(df);
  78. // try {
  79. // return mappers.writeValueAsString(object);
  80. // } catch (Exception e) {
  81. // throw new RuntimeException(e);
  82. // }
  83. // }
  84. private void initial() {
  85. wps=new ArrayList<Windpowerstation>();
  86. for (Windpowerstation station : CacheContext.wpls) {
  87. if (station.getId().endsWith("FDC")) {
  88. wps.add(station);
  89. }
  90. }
  91. Map<String, List<Windturbine>> wtsmap = CacheContext.wtsmap;
  92. Map<String, Windturbine> wtmap = CacheContext.wtmap;
  93. if (StringUtils.empty(windturbineid)) {
  94. List<Windturbine> wtls = wtsmap.get(wps.get(0).getId());
  95. windturbineid = wtls.get(0).getId();
  96. }
  97. if (StringUtils.empty(windfarm)) {
  98. Windturbine wt = wtmap.get(windturbineid);
  99. windfarm = wt.getWindpowerstationid();
  100. }
  101. if (StringUtils.empty(beginDate)) {
  102. Calendar cal = Calendar.getInstance();
  103. String firstday = DateUtils.getCurrtenFirstDay();
  104. if (firstday.equals(format.format(cal.getTime()))) {
  105. cal.add(Calendar.MONTH, -1);
  106. cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
  107. beginDate = cal.getTime();
  108. } else {
  109. cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
  110. beginDate = cal.getTime();
  111. }
  112. }
  113. if (StringUtils.empty(endDate)) {
  114. Calendar cal = Calendar.getInstance();
  115. endDate = cal.getTime();
  116. }
  117. setUrlInfo();
  118. }
  119. private void setUrlInfo() {
  120. StringBuilder urlsb1 = new StringBuilder();
  121. urlsb1.append("goodhistorylist.action?1=1");
  122. StringBuilder sb = new StringBuilder();
  123. if (StringUtils.notEmp(windfarm)) {
  124. sb.append("&windfarm=");
  125. sb.append(windfarm);
  126. }
  127. if (StringUtils.notEmp(windturbineid)) {
  128. sb.append("&windturbineid=");
  129. sb.append(windturbineid);
  130. }
  131. if (StringUtils.notEmp(beginDate)) {
  132. sb.append("&beginDate=");
  133. sb.append(DateUtils.toDate1(beginDate));
  134. }
  135. if (StringUtils.notEmp(endDate)) {
  136. sb.append("&endDate=");
  137. sb.append(DateUtils.toDate1(endDate));
  138. }
  139. url1 = String.valueOf(urlsb1.append(sb));
  140. }
  141. public List<Windpowerstation> getWps() {
  142. return wps;
  143. }
  144. public void setWps(List<Windpowerstation> wps) {
  145. this.wps = wps;
  146. }
  147. public Date getBeginDate() {
  148. return beginDate;
  149. }
  150. public void setBeginDate(Date beginDate) {
  151. this.beginDate = beginDate;
  152. }
  153. public Date getEndDate() {
  154. return endDate;
  155. }
  156. public void setEndDate(Date endDate) {
  157. this.endDate = endDate;
  158. }
  159. public Map<String, List<Windturbine>> getWtsmap() {
  160. return wtsmap;
  161. }
  162. public void setWtsmap(Map<String, List<Windturbine>> wtsmap) {
  163. this.wtsmap = wtsmap;
  164. }
  165. public SimpleDateFormat getFormat() {
  166. return format;
  167. }
  168. public void setFormat(SimpleDateFormat format) {
  169. this.format = format;
  170. }
  171. public String getJson() {
  172. return json;
  173. }
  174. public void setJson(String json) {
  175. this.json = json;
  176. }
  177. public String getWindfarm() {
  178. return windfarm;
  179. }
  180. public void setWindfarm(String windfarm) {
  181. this.windfarm = windfarm;
  182. }
  183. public String getWindturbineid() {
  184. return windturbineid;
  185. }
  186. public void setWindturbineid(String windturbineid) {
  187. this.windturbineid = windturbineid;
  188. }
  189. public List<Windturbineanalysisday> getVos() {
  190. return vos;
  191. }
  192. public void setVos(List<Windturbineanalysisday> vos) {
  193. this.vos = vos;
  194. }
  195. public WindturbineanalysisdayService getWindturbineanalysisdayService() {
  196. return windturbineanalysisdayService;
  197. }
  198. public void setWindturbineanalysisdayService(WindturbineanalysisdayService windturbineanalysisdayService) {
  199. this.windturbineanalysisdayService = windturbineanalysisdayService;
  200. }
  201. public String getUrl1() {
  202. return url1;
  203. }
  204. public void setUrl1(String url1) {
  205. this.url1 = url1;
  206. }
  207. public Date getRecorddate() {
  208. return recorddate;
  209. }
  210. public void setRecorddate(Date recorddate) {
  211. this.recorddate = recorddate;
  212. }
  213. public String getWtId() {
  214. return wtId;
  215. }
  216. public void setWtId(String wtId) {
  217. this.wtId = wtId;
  218. }
  219. }