我正在从事Spring MVC应用程序,其中我需要明智地说明每月工资的图形数据,为此我使用了高级图表,在高级图表中,我们需要指定系列'
我决定选择像 每个月 毛收入, 毛扣除额 和净薪
我已经准备好了,可以显示每月计数, 但是我只想要一个月的时间,我想对现有查询进行修改,以便可以将三个序列全部绑定到sing对象中。
这是Java服务代码,目前仅获取计数。
public AttOfficerDashboardDTO getDashboardCount(final String yearMonth, String refId) {
String query = "SELECT "
+ "Count(DISTINCT EMPLOYEE_ID) tot_emp, "
+ "SUM(NET_SALARY)net_salary, "
+ "SUM(GROSS_EARNING) gross_earn, "
+ "SUM(GROSS_DEDUCTION)gros_deduct "
+ "FROM EMPLOYEE_SALARY_SUMMARY "
+ "WHERE REFERENCE_ID= :REFERENCE_ID "
+ "AND YEAR_MONTH= :YEAR_MONTH ";
MapSqlParameterSource param = new MapSqlParameterSource();
param.addValue("YEAR_MONTH", yearMonth);
param.addValue("REFERENCE_ID", refId);
AttOfficerDashboardDTO dto = getNamedParameterJdbcTemplate().queryForObject(query, param, new RowMapper<AttOfficerDashboardDTO>() {
@Override
public AttOfficerDashboardDTO mapRow(ResultSet rs, int i) throws SQLException {
AttOfficerDashboardDTO dto = new AttOfficerDashboardDTO();
dto.setTotEmp(rs.getInt("tot_emp"));
dto.setGrossEarning(rs.getDouble("gross_earn"));
dto.setGrossDeduction(rs.getDouble("gros_deduct"));
dto.setGrossDeduction(rs.getDouble("gros_deduct"));
dto.setNetPay(rs.getDouble("net_salary"));
dto.setYearMonth(yearMonth);
return dto;
}
});
return dto;
查询:
SELECT
COUNT(DISTINCT employee_id) tot_emp,
SUM(net_salary) net_salary,
SUM(gross_earning) gross_earn,
SUM(gross_deduction) gros_deduct
FROM
employee_salary_summary
WHERE
reference_id =:reference_id
AND
year_month =:year_month