浏览 2639 次
锁定老帖子 主题:二维柱状图/饼状图统计分析组件
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2013-02-27
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import com.css.bean.TXtDm; import com.css.dao.TZddqZddqDao; import org.springframework.stereotype.Service; import org.apache.commons.lang.StringUtils; import com.css.service.TjfxService; import com.css.sys.service.TXtDmService; /** * @function 统计分析业务组件 * @description * @version 1.0 * @author liangbo time at 29/1/2013 */ @Service("tjfxService") public class TjfxServiceImpl implements TjfxService { @Resource private TXtDmService tXtDmService; @Resource private TZddqZddqDao tZddqZddqDao; final String monthNames[] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}; /** * @function 重点地区区域统计业务方法 * @param area 区域行政编码 * @param fromdate 开始时间 * @param todate 结束时间 * @return 返回统计xml数据 */ public String showAreaCharts(String area, String fromdate, String todate) { StringBuilder result=new StringBuilder(""); if(!StringUtils.isEmpty(area)){ StringBuilder dmsql =new StringBuilder("WHERE 1=1 AND CODETYPE = 'XZQH'"); //省级统计 if(area.matches("[1-9]{2}0000")) { dmsql.append(" AND code like '13%00' and code <> '130000'"); } //市级统计 if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")) { dmsql.append(" AND code like '" + area.substring(0, 4) + "%'"); } List<TXtDm> xzqhList = tXtDmService.getTXtDmList(dmsql.toString()); dmsql.delete(0, dmsql.length()); if(xzqhList!=null&&xzqhList.size()>0){ //省级统计 if(area.matches("[1-9]{2}0000")){ for (TXtDm tXtDm : xzqhList) { StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a where 1=1 "); String code=tXtDm.getCode(); if(!StringUtils.isEmpty(code)&&code.matches("[1-9]{2}[0-9]{4}")){ hql.append(" and a.xzqh like '"+code.substring(0, 4)+"%' "); } if(!StringUtils.isEmpty(fromdate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)>='"+fromdate+"'" ); } if(!StringUtils.isEmpty(todate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)<='"+todate+"'" ); } String count=tZddqZddqDao.queryCount(hql.toString()); hql.delete(0, hql.length()); result.append(" <set value='"+count+"' label='"+tXtDm.getCodename()+"' />"); } }else if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")){ for (TXtDm tXtDm : xzqhList) { StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a where 1=1 "); String code=tXtDm.getCode(); if(!StringUtils.isEmpty(code)&&code.matches("[1-9]{2}[0-9]{4}")){ hql.append(" and a.xzqh = '"+code+"' "); } if(!StringUtils.isEmpty(fromdate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)>='"+fromdate+"'" ); } if(!StringUtils.isEmpty(todate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)<='"+todate+"'" ); } String count=tZddqZddqDao.queryCount(hql.toString()); hql.delete(0, hql.length()); result.append(" <set value='"+count+"' label='"+tXtDm.getCodename()+"' />"); } } } } return result.toString(); } /** * @function 重点地区按月统计业务方法 统计以开始时间年份为统计基础 * @param area 区域行政编码 * @param fromdate 开始时间 * @return 返回统计xml数据 */ public String showMouthCharts(String area, String fromdate) { StringBuilder result=new StringBuilder(""); if(!StringUtils.isEmpty(area)){ if(StringUtils.isEmpty(fromdate)){ Calendar cal = Calendar.getInstance(); fromdate=new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); } StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a where 1=1 "); //省级统计 if(area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh like '13%' "); } //市级统计 if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")) { hql.append(" AND a.xzqh like '" + area.substring(0, 4) + "%' "); } if(area.matches("[1-9]{2}[0-9]{4}") && !area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00") && !area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh = '" + area + "' "); } String date = fromdate.substring(0, 4); getTimeLabel(result,hql,date); } return result.toString(); } /** * @function 重点地区分类统计业务方法 * @param area 区域行政编码 * @param fromdate 开始时间 * @param todate 结束时间 * @param type 统计类型 * @return 返回统计xml数据 */ public String showCharts(String area, String fromdate, String todate,String type) { StringBuilder result=new StringBuilder(""); if(!StringUtils.isEmpty(area) && !StringUtils.isEmpty(type)){ StringBuilder dmsql = new StringBuilder(""); if(type.contains("SF")) { dmsql.append("WHERE 1=1 AND CODETYPE = '" + type.substring(0, 2) + "' "); } else { dmsql.append("WHERE 1=1 AND CODETYPE = '" + type + "' "); } List<TXtDm> codeTypeList = tXtDmService.getTXtDmList(dmsql.toString()); dmsql.delete(0, dmsql.length()); if(codeTypeList!=null && codeTypeList.size()>0){ //如果统计类型为GPLB或zzqx查询条件以B表为基准,否则以a表为基准 if(type.equalsIgnoreCase("GPLB") || type.equalsIgnoreCase("ZZQX")) { for (TXtDm tXtDm : codeTypeList) { StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a , ZDDQ.T_ZDDQ_GPDB b where 1=1 AND a.id = b.zddqid "); String code=tXtDm.getCode(); String bType = "b." + type; hql.append(" AND " + bType + "='" + code + "' "); if(!StringUtils.isEmpty(fromdate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)>='"+fromdate+"'" ); } if(!StringUtils.isEmpty(todate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)<='"+todate+"'" ); } //省级统计 if(area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh like '13%' "); } //市级统计 if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")) { hql.append(" AND a.xzqh like '" + area.substring(0, 4) + "%' "); } if(area.matches("[1-9]{2}[0-9]{4}") && !area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00") && !area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh = '" + area + "' "); } String count=tZddqZddqDao.queryCount(hql.toString()); hql.delete(0, hql.length()); result.append(" <set value='"+count+"' label='"+tXtDm.getCodename()+"' />"); } } else { for (TXtDm tXtDm : codeTypeList) { StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a , ZDDQ.T_ZDDQ_GPDB b where 1=1 AND a.id = b.zddqid "); String code=tXtDm.getCode(); String aType = "a." + type; hql.append(" AND " + aType + "='" + code + "' "); if(!StringUtils.isEmpty(fromdate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)>='"+fromdate+"'" ); } if(!StringUtils.isEmpty(todate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)<='"+todate+"'" ); } //省级统计 if(area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh like '13%' "); } //市级统计 if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")) { hql.append(" AND a.xzqh like '" + area.substring(0, 4) + "%' "); } if(area.matches("[1-9]{2}[0-9]{4}") && !area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00") && !area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh = '" + area + "' "); } String count=tZddqZddqDao.queryCount(hql.toString()); hql.delete(0, hql.length()); result.append(" <set value='"+count+"' label='"+tXtDm.getCodename()+"' />"); } } } } return result.toString(); } public void getTimeLabel(StringBuilder result,StringBuilder where,String date) { if(where != null && !StringUtils.isEmpty(date)) { for(int i=0; i<=11;i++) { String sql = where.toString(); int j = i + 1; String mDate = ""; if(j < 10) { mDate = date + "-0" + j; } else if( j >= 10){ mDate = date + "-" + j; } sql = sql + " AND SUBSTRING(convert(varchar,a.cjsj),0,7) = '" + mDate + "' "; //System.out.println(sql.toString()); String count=tZddqZddqDao.queryCount(sql); result.append(" <set value='"+count+"' label='"+monthNames[i] +"' />"); } } } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |