/**
* 格式化日期为 年 月 日
*
* @param date
* @return [年 月 日]
*/
protected static String[] formatDate(Date date) {
String[] s = new String[3];
Calendar c = Calendar.getInstance();
if (date == null)
date = new Date();
c.setTime(date);
s[0] = String.valueOf(c.get(Calendar.YEAR));
s[1] = String.format("%02d", c.get(Calendar.MONTH) + 1);
s[2] = String.format("%02d", c.get(Calendar.DATE));
return s;
}
public int getAvgCheckValue(Long proId,Date year) {
String[] yearStr = formatDate(year);
Integer startYear = Integer.valueOf(yearStr[0]) - 3;
Integer endYear = Integer.valueOf(yearStr[0]) + 2;
ProjectOrg org = projectService.getOrg(proId);
if (org != null) {
String sql = "SELECT ROUND(AVG(VALUE),0) AS AVGVALUE FROM HDS.T_CHECK_VALUE WHERE YEAR BETWEEN " + startYear
+ " AND " + endYear + " AND ORG_ID='" + org.getOrg() + "'";
List<CheckValue> strList = MapToBean.convert2List(dao.queryForMapList(sql), CheckValue.class);
if (strList.size() > 0) {
return strList.get(0).getAvgValue();
}
}
return 0;
}
以这种方式去取数组中的年月日数据