123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- package com.hcks.cmfds.action.apdata;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.apache.struts2.convention.annotation.Action;
- import org.apache.struts2.convention.annotation.Namespace;
- import org.apache.struts2.convention.annotation.Result;
- import com.hcks.cmfds.commons.lang.QueryOrder;
- import com.hcks.cmfds.commons.util.DateUtils;
- import com.hcks.cmfds.commons.util.JsonUtils;
- import com.hcks.cmfds.commons.util.StringUtils;
- import com.hcks.cmfds.core.web.action.PaginationAction;
- import com.hcks.cmfds.model.Windpowerstation;
- import com.hcks.cmfds.model.Windturbine;
- import com.hcks.cmfds.model.Windturbineanalysisday;
- import com.hcks.cmfds.service.CacheContext;
- import com.hcks.cmfds.service.WindturbineanalysisdayService;
- @Namespace("/wtgoodness")
- @Result(name = "json", type = "json", params = { "textName", "json" })
- public class WindturbinegoodhistoryAction extends PaginationAction {
- private static final long serialVersionUID = 1L;
- private List<Windpowerstation> wps;
- private Date beginDate;
- private Date endDate;
- private String json;
- private String windfarm;
- private String windturbineid;
- private String wtId;;
- private Date recorddate;
- private String url1;
- private Map<String, List<Windturbine>> wtsmap;
- private List<Windturbineanalysisday> vos;
- private WindturbineanalysisdayService windturbineanalysisdayService;
- private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- @Action(value = "goodhistoryindex", results = { @Result(name = "success", location = "/pages/apdata/goodhistory.jsp") })
- public String goodhistoryindex() {
- initial();
- vos = new ArrayList<Windturbineanalysisday>();
- return SUCCESS;
- }
- @Action(value = "goodhistorylist")
- public String goodhistorylist() throws Exception {
- initial();
- Map<String, Object> params = new HashMap<String, Object>();
- if(StringUtils.notEmp(windturbineid))
- {
- params.put("windturbineid", windturbineid);
- }
- if(StringUtils.notEmp(beginDate))
- {
- params.put("@recorddate", DateUtils.truncate(beginDate));
- }
- if(StringUtils.notEmp(endDate))
- {
- params.put("$recorddate", DateUtils.truncate(endDate));
- }
-
-
- QueryOrder orders=new QueryOrder("recorddate", "desc");
- vos = windturbineanalysisdayService.findByProperties(params, orders);
- if (null != vos && !vos.isEmpty()) {
- json = JsonUtils.getJsons(vos);
- } else {
- json = JsonUtils.getJsons(new ArrayList<Windturbineanalysisday>());
- }
- return JSON;
- }
-
- // private String getJsons(Object object)
- // {
- // ObjectMapper mappers = new ObjectMapper();
- // String SIMPLE_DATETIME_FORMAT = "yyyy-MM-dd";
- // SimpleDateFormat df = new SimpleDateFormat(SIMPLE_DATETIME_FORMAT);
- // mappers.configure(org.codehaus.jackson.map.SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
- // mappers.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
- // mappers.getSerializationConfig().setDateFormat(df);
- // try {
- // return mappers.writeValueAsString(object);
- // } catch (Exception e) {
- // throw new RuntimeException(e);
- // }
- // }
-
- private void initial() {
- wps=new ArrayList<Windpowerstation>();
- for (Windpowerstation station : CacheContext.wpls) {
- if (station.getId().endsWith("FDC")) {
- wps.add(station);
- }
- }
- Map<String, List<Windturbine>> wtsmap = CacheContext.wtsmap;
- Map<String, Windturbine> wtmap = CacheContext.wtmap;
- if (StringUtils.empty(windturbineid)) {
- List<Windturbine> wtls = wtsmap.get(wps.get(0).getId());
- windturbineid = wtls.get(0).getId();
- }
- if (StringUtils.empty(windfarm)) {
- Windturbine wt = wtmap.get(windturbineid);
- windfarm = wt.getWindpowerstationid();
- }
- if (StringUtils.empty(beginDate)) {
- Calendar cal = Calendar.getInstance();
- String firstday = DateUtils.getCurrtenFirstDay();
- if (firstday.equals(format.format(cal.getTime()))) {
- cal.add(Calendar.MONTH, -1);
- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
- beginDate = cal.getTime();
- } else {
- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
- beginDate = cal.getTime();
- }
- }
- if (StringUtils.empty(endDate)) {
- Calendar cal = Calendar.getInstance();
- endDate = cal.getTime();
- }
- setUrlInfo();
- }
-
- private void setUrlInfo() {
- StringBuilder urlsb1 = new StringBuilder();
- urlsb1.append("goodhistorylist.action?1=1");
-
-
- StringBuilder sb = new StringBuilder();
- if (StringUtils.notEmp(windfarm)) {
- sb.append("&windfarm=");
- sb.append(windfarm);
- }
- if (StringUtils.notEmp(windturbineid)) {
- sb.append("&windturbineid=");
- sb.append(windturbineid);
- }
- if (StringUtils.notEmp(beginDate)) {
- sb.append("&beginDate=");
- sb.append(DateUtils.toDate1(beginDate));
- }
- if (StringUtils.notEmp(endDate)) {
- sb.append("&endDate=");
- sb.append(DateUtils.toDate1(endDate));
- }
- url1 = String.valueOf(urlsb1.append(sb));
-
- }
- public List<Windpowerstation> getWps() {
- return wps;
- }
- public void setWps(List<Windpowerstation> wps) {
- this.wps = wps;
- }
- public Date getBeginDate() {
- return beginDate;
- }
- public void setBeginDate(Date beginDate) {
- this.beginDate = beginDate;
- }
- public Date getEndDate() {
- return endDate;
- }
- public void setEndDate(Date endDate) {
- this.endDate = endDate;
- }
- public Map<String, List<Windturbine>> getWtsmap() {
- return wtsmap;
- }
- public void setWtsmap(Map<String, List<Windturbine>> wtsmap) {
- this.wtsmap = wtsmap;
- }
- public SimpleDateFormat getFormat() {
- return format;
- }
- public void setFormat(SimpleDateFormat format) {
- this.format = format;
- }
- public String getJson() {
- return json;
- }
- public void setJson(String json) {
- this.json = json;
- }
- public String getWindfarm() {
- return windfarm;
- }
- public void setWindfarm(String windfarm) {
- this.windfarm = windfarm;
- }
- public String getWindturbineid() {
- return windturbineid;
- }
- public void setWindturbineid(String windturbineid) {
- this.windturbineid = windturbineid;
- }
- public List<Windturbineanalysisday> getVos() {
- return vos;
- }
- public void setVos(List<Windturbineanalysisday> vos) {
- this.vos = vos;
- }
- public WindturbineanalysisdayService getWindturbineanalysisdayService() {
- return windturbineanalysisdayService;
- }
- public void setWindturbineanalysisdayService(WindturbineanalysisdayService windturbineanalysisdayService) {
- this.windturbineanalysisdayService = windturbineanalysisdayService;
- }
- public String getUrl1() {
- return url1;
- }
- public void setUrl1(String url1) {
- this.url1 = url1;
- }
- public Date getRecorddate() {
- return recorddate;
- }
- public void setRecorddate(Date recorddate) {
- this.recorddate = recorddate;
- }
- public String getWtId() {
- return wtId;
- }
- public void setWtId(String wtId) {
- this.wtId = wtId;
- }
-
-
- }
|