sql数据统计
这个新需求就是上个sql总结查询的需求改进,先上效果图在说需求:
一个任务表(m_mtask)、一个已开会议表(m_meeting)、一张组织表(m_mparty)。
先来说说这个组织表吧有三级数据一级是县级、二级是组织部管理人员、三级就是村级的了
这个请求就是统计下发的任务到每个村子的开展情况,然后会议表只存储已开会议。当然了还要适应上面的几个select框查询条件的查询
这个需求看着不难,也许我太笨的过。哈哈哈哈
还是跟之前一样jsp就不上了就上后台代码了都差不多的反正都是一个controller
MeetingController.java
*/ @Controller @RequestMapping(value="/meeting") public class MeetingController extends BaseController { String menuUrl = "meeting/list.do"; //菜单地址(权限用) @Resource(name="meetingService") private MeetingManager meetingService; @Resource(name="tqhService") private TqhManager tqhService; @Resource(name="dictionariesService") private DictionariesManager dictionariesService; @Resource(name="userService") private UserManager userService; @Resource(name="mpartyService") private MpartyManager mpartyService; @Resource(name="mtaskService") private MtaskManager mtaskService; @Resource(name="mnotificationService") private MnotificationManager mnotifcationService;
@RequestMapping("stat")
public ModelAndView stat(Page page) throws Exception {
//获取用户信息
User user= (User) Jurisdiction.getSession().getAttribute(Const.SESSION_USER);
String mparty_ID = user.getMPARTY_ID();
ModelAndView mv = new ModelAndView();
PageData pd = this.getPageData();
pd.put("MPARTY_ID", mparty_ID);
page.setPd(pd);
List<PageData> disk =null;
List<PageData> map = new ArrayList<PageData>();
// if(user.getUSERNAME().equals("admin")){
// disk = meetingService.disk(page);
// }else{
disk=mpartyService.fisk(page);
// }
List<PageData> find = mtaskService.total(page);
for (PageData qh : disk) {
PageData gj = new PageData();
gj.put("PARTY_NAME", qh.getString("PARTY_NAME"));//党组织名字
gj.put("MPARTY_ID", qh.getString("MPARTY_ID"));//党组织名字
int dy = 0;
int dy1=0;
int dw = 0;
int dw1 = 0;
int dx = 0;
int dx1 = 0;
int dr = 0;
int dr1 = 0;
int dk = 0;
int dk1 = 0;
for (PageData task : find) {
String url = task.getString("TASK_TYPE");
if(url.equals("24ae801282b94fe49968dc2f65552876")){//党员大会
dy=task.getInt("total");
dy1=1;
}
else if(url.equals("3b0023ed99e94fadbafb1f54a70515a9")){//支部委员会
dw=task.getInt("total");
dw1=1;
}
else if(url.equals("5ee66abb1e554cf791f3c184c3aa4565")){//固定党日
dr=task.getInt("total");
dr=1;
}
else if(url.equals("5f5381321c2640b1bbeb228d4fca360a")){//党课
dk=task.getInt("total");
dk=1;
}
else if(url.equals("c546b755cb1e464f93ccf65805371a5b")){//党小组会议
dx=task.getInt("total");
dx=1;
}
}
pd.put("MPARTY_ID",qh.getString("MPARTY_ID"));
List<PageData> total = meetingService.total(page);
for (PageData pageData : total) {
if(qh.getString("MPARTY_ID").equals(pageData.getString("MPARTY_ID"))){
String type = pageData.getString("TYPE");//会议名字
if(type.equals("24ae801282b94fe49968dc2f65552876")&&dy1==1){//党员大会
gj.put("dydh", pageData.getInt("total"));
dy=dy-pageData.getInt("total");
}
else if(type.equals("3b0023ed99e94fadbafb1f54a70515a9")&&dw1==1){//支部委员会
gj.put("dwhy", pageData.getInt("total"));
dw=dw-pageData.getInt("total");
}
else if(type.equals("c546b755cb1e464f93ccf65805371a5b")&&dx==1){//党小组会议
gj.put("dxzhy", pageData.getInt("total"));
dx=dx-pageData.getInt("total");
}
else if(type.equals("5ee66abb1e554cf791f3c184c3aa4565")&&dr==1){//固定党日
gj.put("dr", pageData.getInt("total"));
dr=dr-pageData.getInt("total");
}
else if(type.equals("5f5381321c2640b1bbeb228d4fca360a")&&dk==1){//党课
gj.put("dk", pageData.getInt("total"));
dk=dk-pageData.getInt("total");
}
}
}
gj.put("dydh1",dy);
gj.put("dwhy1",dw);
gj.put("dxzhy1",dx);
gj.put("dr1",dr);
gj.put("dk1",dk);
// map.add(pageData);
map.add(gj);
}
mv.addObject("map",map);
List<PageData> dy = mtaskService.dy(page);
List<PageData> dw = mtaskService.dw(page);
List<PageData> dx = mtaskService.dx(page);
List<PageData> dk = mtaskService.dk(page);
List<PageData> dr = mtaskService.dr(page);
mv.addObject("dy",dy);
mv.addObject("dw",dw);
mv.addObject("dx",dx);
mv.addObject("dk",dk);
mv.addObject("dr",dr);
mv.setViewName("meeting/mstat/meeting_stat");
mv.addObject("msg", "updatesave");
return mv;
}
}
meetingService.java
public interface MeetingManager { /** * 统计 * * @param page * @return * @throws Exception */ public List<PageData> total(Page page) throws Exception; }
meetingMapper.xml
<select id="total" parameterType="page" resultType="pd"> select count(*) as total,p.PARTY_NAME,m.TYPE,m.MPARTY_ID from <include refid="tableName"></include> m left join m_mparty p ON m.MPARTY_ID = p.MPARTY_ID left join m_mtask t on t.MTASK_ID = m.TYPE where m.MPARTY_ID=#{pd.MPARTY_ID} group by m.MTASK_ID; </select>
mtaskService.java
public interface MtaskManager { /** * 统计任务下的会议总数 * * @param page * @return * @throws Exception */ public List<PageData> total(Page page) throws Exception; /** * 列出党员大会的任务 * * @param pd * @return * @throws Exception */ public List<PageData> dy(Page page) throws Exception; public List<PageData> dw(Page page) throws Exception; public List<PageData> dx(Page page) throws Exception; public List<PageData> dk(Page page) throws Exception; public List<PageData> dr(Page page) throws Exception; }
mtaskMapper.xml
<select id="total" parameterType="page" resultType="pd"> select count(*) as total,MTASK_ID,TASK_TYPE from <include refid="tableName"></include> where 1=1 <choose> <when test="pd.dy!=null and pd.dy!='' and pd.dw!=null and pd.dw!='' and pd.dk!=null and pd.dk!='' and pd.dr!=null and pd.dr!=''"> AND TASK_NAME in ('${pd.dy}','${pd.dw}','${pd.dr}','${pd.dk}') </when> <when test="pd.dy!=null and pd.dy!='' and pd.dw!=null and pd.dw!='' and pd.dk!=null and pd.dk!=''"> AND TASK_NAME in ('${pd.dy}','${pd.dw}','${pd.dk}') </when> <when test="pd.dy!=null and pd.dy!='' and pd.dw!=null and pd.dw!=''"> AND TASK_NAME in ('${pd.dy}','${pd.dw}') </when> <when test="pd.dy!=null and pd.dy!=''"> AND TASK_NAME in ('${pd.dy}') </when> <otherwise> AND 1=1 </otherwise> </choose> group by TASK_TYPE; </select> <select id="dy" parameterType="pd" resultType="pd"> select * from <include refid="tableName"></include> where TASK_TYPE='24ae801282b94fe49968dc2f65552876'; </select> <select id="dw" parameterType="pd" resultType="pd"> select * from <include refid="tableName"></include> where TASK_TYPE='3b0023ed99e94fadbafb1f54a70515a9'; </select> <select id="dx" parameterType="pd" resultType="pd"> select * from <include refid="tableName"></include> where TASK_TYPE='c546b755cb1e464f93ccf65805371a5b'; </select> <select id="dk" parameterType="pd" resultType="pd"> select * from <include refid="tableName"></include> where TASK_TYPE='5f5381321c2640b1bbeb228d4fca360a'; </select> <select id="dr" parameterType="pd" resultType="pd"> select * from <include refid="tableName"></include> where TASK_TYPE='5ee66abb1e554cf791f3c184c3aa4565'; </select>
mpartyService.jalva
public interface MpartyManager { /** * 列出党委下的党支部 * * @param page * @return * @throws Exception */ public List<PageData> fisk(Page page) throws Exception; }
mpartyMapper.xml
<select id="fisk" parameterType="page" resultType="pd"> select MPARTY_ID,PARTY_NAME from <include refid="tableName"></include> where PID=#{pd.MPARTY_ID} </select>
代码完了然后说说我的想法吧!
·1.每个管理人员下的村子组成一个list
·2.查任务表中没种任务的总数和个别字段的值然后用变量把每种会议的总数记录并且有这个会议的我又定了一个变量。(又定义一个变量是作为上面select条件查询使用有这个会议我才去查这个村子已开的会议)
·3.从管理人员下的村子查询该村子已开的会议
整体就是双层循环内循环俩个循环
首先把党组织中党支部遍历出来内层1循环任务每种会议类型的总数
内层循环2遍历出会议表中已开会议并且用任务总数减去已开的会议