/**加载页面*/
@RequestMapping(value = "dwView", method = RequestMethod.GET)
public String dwView(HttpServletRequest request,
HttpServletResponse response) {
return "dwView";
}
/**
* 表头年份处理
*/
@SuppressWarnings({ "deprecation" })
@ResponseBody
@RequestMapping(value = "/getYearHead", method = RequestMethod.POST, produces = { "text/plain;charset=UTF-8" })
public String getYearHead(HttpServletRequest request) {
/** 获取查询时间 */
String startTime = request.getParameter("startTime");
String endTime = request.getParameter("endTime");
Date startDate = DateUtil.stringToDate(startTime,
DateUtil.DATE_FORMAT_MONTH);
Date endDate = DateUtil.stringToDate(endTime,
DateUtil.DATE_FORMAT_MONTH);
Integer startYear = startDate.getYear() + 1900;
Integer endYear = endDate.getYear() + 1900;
/** 获取年份表头 */
List<ColumnVO> list = new ArrayList<ColumnVO>();
for (int i = startYear; i <= endYear; i++) {
ColumnVO vo = new ColumnVO();
vo.setTitle(String.valueOf(i));
if (startYear.intValue() == endYear.intValue()) {// 同一年合并列处理
int startMonth = startDate.getMonth() + 1;
int endMonth = endDate.getMonth() + 1;
vo.setColspan(endMonth - startMonth + 1);
} else if (i == startYear) {// 起始月是合并列处理
vo.setColspan(12 - startDate.getMonth());
} else if (i == endYear) {// 结束年合并列处理
vo.setColspan(endDate.getMonth() + 1);
} else {// 中间年份合并列处理
vo.setColspan(12);
}
list.add(vo);
}
ColumnVO[] array1 = list.toArray(new ColumnVO[list.size()]);
return JSON.toJSONString(array1);
}
/**
* 获取月份
*/
@ResponseBody
@RequestMapping(value = "/getMonthHead", method = RequestMethod.POST, produces = { "text/plain;charset=UTF-8" })
public String getMonthHead(HttpServletRequest request) {
/** 获取查询时间 */
String startTime = request.getParameter("startTime");
String endTime = request.getParameter("endTime");
String type = request.getParameter("type");
Date startDate = DateUtil.stringToDate(startTime,
DateUtil.DATE_FORMAT_MONTH);
Date endDate = DateUtil.stringToDate(endTime,
DateUtil.DATE_FORMAT_MONTH);
List<ColumnVO> list = procMonth(startDate, endDate);
ColumnVO[] array1 = list.toArray(new ColumnVO[list.size()]);
if ("0".equals(type)) {
return StringUtil.removeHistoryId(JSON.toJSONString(array1),
"title");
} else {
return StringUtil.removeHistoryId(JSON.toJSONString(array1),
new String[] { "field", "id" });
}
}
/**
* 表头月份处理
*/
@SuppressWarnings("deprecation")
public List<ColumnVO> procMonth(Date startDate, Date endDate) {
List<ColumnVO> list = new ArrayList<ColumnVO>();
Integer startYear = startDate.getYear() + 1900;
Integer endYear = endDate.getYear() + 1900;
for (int i = startYear; i <= endYear; i++) {
if (startYear.intValue() == endYear.intValue()) {
int startMonth = startDate.getMonth() + 1;
int endMonth = endDate.getMonth() + 1;
for (int m = startMonth; m <= endMonth; m++) {
ColumnVO vo = createColumnVo(i, m);
list.add(vo);
}
} else if (i == startYear) {
int startMonth = startDate.getMonth() + 1;
for (int k = startMonth; k <= 12; k++) {
ColumnVO vo = createColumnVo(i, k);
list.add(vo);
}
} else if (i == endYear) {
int endMonth = endDate.getMonth() + 1;
for (int n = 1; n <= endMonth; n++) {
ColumnVO vo = createColumnVo(i, n);
list.add(vo);
}
} else {
for (int j = 1; j <= 12; j++) {
ColumnVO vo = createColumnVo(i, j);
list.add(vo);
}
}
}
return list;
}
/**
* 创建新列
*/
public ColumnVO createColumnVo(Integer year, Integer month) {
ColumnVO column = new ColumnVO();
column.setId("del_" + String.valueOf(year) + String.valueOf(month));
column.setTitle(String.valueOf(month));
column.setField(String.valueOf(year) + String.valueOf(month));
column.setRowspan(1);
column.setWidth(50);
return column;
}