我用的是springMVC+myBatis框架
mapper.xml中
<select id="getAccount" parameterType="map" resultMap="getMap">
select * from (
select sum(price) price,'today' dateType from scf_pay where to_days(operation_time) = to_days(now())
union all
select sum(price) price,'week' dateType from scf_pay where YEARWEEK(date_format(operation_time,'%Y-%m-%d')) = YEARWEEK(now())
union all
select sum(price) price,'yestweek' dateType from scf_pay where YEARWEEK(date_format(operation_time,'%Y-%m-%d')) = YEARWEEK(now())-1
union all
select sum(price) price,'month' dateType from scf_pay where date_format(operation_time,'%Y-%m')=date_format(now(),'%Y-%m')
union all
select sum(price) price,'yestmonth' dateType from scf_pay where date_format(operation_time,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')
union all
select sum(price) price,'benjidu' dateType from scf_pay where QUARTER(operation_time)=QUARTER(now())
union all
select sum(price) price,'shangjidu' dateType from scf_pay where QUARTER(operation_time)=QUARTER(DATE_SUB(now(),interval 1 QUARTER))
union all
select sum(price) price,'bennian' dateType from scf_pay where YEAR(operation_time)=YEAR(NOW())
union all
select sum(price) price,'shangnian' dateType from scf_pay where YEAR(operation_time)=year(date_sub(now(),interval 1 year))
) a;
</select>
dao层public List<Map<String,Object>> getAccount();
service层public Map<String, Object> getAccount();
serviceImpl层
@Overridepublic Map<String,Object> getAccount(){
if(logger.isDebugEnabled()){
logger.debug(" in ScfPayServiceImpl.getAccount() - start ");
}
List<Map<String,Object>> list = scfPayDao.getAccount();Map<String,Object> returnMap = new HashMap<String, Object>();for(int i=0; i<list.size(); i++){
Map<String,Object> map = list.get(i);returnMap.put((String)map.get("tender_state"), map.get("num"));
}
if(logger.isDebugEnabled()){logger.debug(" in ScfPayServiceImpl.getAccount() - end ");}
Controller层 Map<String, Object> account = payService.getAccount();return returnMap;}