//常量定义 public class Constant { public static Integer PM_YEAR_NO = 5;}
//action
public class ZhiBiaoPmAction extends BaseAction { private static final long serialVersionUID = 1L; @Autowired ZhiBiaoPmService zbser; public String cn_pm25() { Integer year = Integer.valueOf(Tool.getCurDateByType("yyyy")); List
//Service
@Servicepublic class ZhiBiaoPmService { @Autowired ZhiBiaoPmDao pmdao; public List
//Dao
@Repositorypublic class ZhiBiaoPmDao extends BaseDao{ public List > getPM25lt(Integer year) { StringBuffer sql = new StringBuffer(); sql.append(" select t2.regionname"); for (int i = year - Constant.PM_YEAR_NO; i < year; i++) { sql.append(" ,isnull([").append(i).append("],0) as 'y").append(i) .append("'"); } sql.append(" from ("); sql.append(" select qyregion_code"); for (int i = year - Constant.PM_YEAR_NO; i < year; i++) { sql.append(" ,[").append(i).append("] as '").append(i).append("'"); } sql.append(" from ("); sql.append(" select qynianfen,qyregion_code,cast (qyzbvalue as numeric(18, 2)) qyzbvalue"); sql.append(" from t_zhiqy where qyzbtype = 'pm'"); sql.append(" ) t"); sql.append(" pivot ("); sql.append(" sum ([qyzbvalue]) for [qynianfen] in ("); for (int i = year - Constant.PM_YEAR_NO; i < year; i++) { sql.append("[").append(i).append("]"); sql.append(i != year - 1 ? "," : ""); } sql.append(")"); sql.append(" ) vpt)"); sql.append(" t1 right join (select regioncode,regionname from t_cod_region where parentcode = '0') t2"); sql.append(" on t1.qyregion_code = t2.regioncode"); return this.search(sql.toString(), new Object[] {}); }}
//数据库
//数据处理后
//Jsp
//最终效果