目录
登录xx账号,就要查出凡是xx是参与者、列席这、主持人中的一员,那么都要查出来
查询条件:登录用户 id 2
会议信息表:t_oa_meeting_info
会议反馈表:t_oa_meeting_feedback
例: 1、查询出带xx id=2 的会议信息:
SELECT * from t_oa_meeting_info where FIND_IN_SET(2,CONCAT(canyuze,',',liexize,',',zhuchiren)) and state=4运行SQL结果:
2、不管会议是否得到反馈,都要查询出来,所以选外连接,会议信息表为主:
SELECT IFNULL(f.result,-1) result,t1.* FROM (SELECT * from t_oa_meeting_info where FIND_IN_SET(2,CONCAT(canyuze,',',liexize,',',zhuchiren)) and state=4) t1 LEFT JOIN t_oa_meeting_feedback f on t1.id=f.meetingId and f.personId=2 ORDER BY result;运行SQL结果:
用户表:t_oa_user
会议信息表:t_oa_meeting_info
会议反馈表:t_oa_meeting_feedback
查询条件:会议 id 12
1) 先拿到所有的参与人员 id
SELECT CONCAT(canyuze,',',liexize,',',zhuchiren) from t_oa_meeting_info where id=12SQL运行结果:
2) 再拿到对应参与人员的姓名
SELECT * from t_oa_user where FIND_IN_SET(id, (SELECT CONCAT(canyuze,',',liexize,',',zhuchiren) from t_oa_meeting_info where id=12))SQL运行结果:
SELECT * from t_oa_user where FIND_IN_SET(id, (SELECT CONCAT(canyuze,',',liexize,',',zhuchiren) from t_oa_meeting_info where id=12))SQL运行结果:
select t.result,GROUP_CONCAT(t.name) names from (select t1.name,IFNULL(f.result,-1) result from (SELECT * from t_oa_user where FIND_IN_SET(id, (SELECT CONCAT(canyuze,',',liexize,',',zhuchiren) from t_oa_meeting_info where id=12))) t1 left join t_oa_meeting_feedback f on t1.id=f.personId and f.meetingId=12) t GROUP BY t.resultSQL运行结果:
这里简单提及一下前端代码:
header.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> DOCTYPE html> <link rel="stylesheet" href="${pageContext.request.contextPath }/static/js/layui/css/layui.css"> <script src="${pageContext.request.contextPath }/static/js/layui/layui.js">script> <base href="${pageContext.request.contextPath }/"/> <script src="${pageContext.request.contextPath }/static/js/layui/config.js">script> <input id="ctx" value="${pageContext.request.contextPath }" type="hidden"/> <title>玉渊工作室title>
前面SQL语句都已编写完毕,接下来就开始实现后台代码了:
- package com.zking.entity;
-
- import java.io.Serializable;
- /**
- * t_oa_meeting_feedback 会议反馈表
- * 实体类:会议反馈
- * @author 杨总
- *
- */
- public class MeetingFeedBack implements Serializable {
-
- private String id;
- private Long meetingId;
- private Integer personType;
- private Long personId;
- private Integer result;
- private String reason;
-
- // 会议标题
- private String title;
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public Long getMeetingId() {
- return meetingId;
- }
-
- public void setMeetingId(Long meetingId) {
- this.meetingId = meetingId;
- }
-
- public Integer getPersonType() {
- return personType;
- }
-
- public void setPersonType(Integer personType) {
- this.personType = personType;
- }
-
- public Long getPersonId() {
- return personId;
- }
-
- public void setPersonId(Long personId) {
- this.personId = personId;
- }
-
- public Integer getResult() {
- return result;
- }
-
- public void setResult(Integer result) {
- this.result = result;
- }
-
- public String getReason() {
- return reason;
- }
-
- public void setReason(String reason) {
- this.reason = reason;
- }
-
- public MeetingFeedBack() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- @Override
- public String toString() {
- return "MeetingFeedBack [id=" + id + ", meetingId=" + meetingId + ", personType=" + personType + ", personId="
- + personId + ", result=" + result + ", reason=" + reason + "]";
- }
-
- }
- package com.zking.dao;
-
- import java.sql.SQLException;
- import java.util.List;
- import java.util.Map;
-
- import com.zking.entity.MeetingFeedBack;
- import com.zking.util.BaseDao;
- import com.zking.util.PageBean;
-
- public class MeetingFeedBackDao extends BaseDao<MeetingFeedBack>{
-
- //会议通知查询
- public List<Map<String, Object>> queryMeetingFeedBackByUserId(MeetingFeedBack back, PageBean pageBean)
- throws SQLException, InstantiationException, IllegalAccessException {
- String sql="SELECT\r\n" +
- " IFNULL(f.result,-1) result,t1.*\r\n" +
- " FROM\r\n" +
- " (SELECT * from t_oa_meeting_info where FIND_IN_SET("+back.getPersonId()+",CONCAT(canyuze,',',liexize,',',zhuchiren)) and state=4) t1\r\n" +
- " LEFT JOIN t_oa_meeting_feedback f on t1.id=f.meetingId\r\n" +
- " and f.personId="+back.getPersonId()+"\r\n" +
- " ORDER BY result";
-
- return super.executeQuery(sql, pageBean);
- }
- // back.getPersonId()
- }
- package com.zking.web;
-
- import java.util.List;
- import java.util.Map;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import com.zking.dao.MeetingFeedBackDao;
- import com.zking.entity.MeetingFeedBack;
- import com.zking.framework.ActionSupport;
- import com.zking.framework.ModelDriver;
- import com.zking.util.PageBean;
- import com.zking.util.R;
- import com.zking.util.ResponseUtil;
-
- public class MeetingFeedBackAction extends ActionSupport implements ModelDriver<MeetingFeedBack>{
- private MeetingFeedBack back=new MeetingFeedBack();
- private MeetingFeedBackDao backDao=new MeetingFeedBackDao();
- @Override
- public MeetingFeedBack getModel() {
- return back;
- }
-
- // 会议通知查询
- public String queryMeetingFeedBackByUserId(HttpServletRequest req, HttpServletResponse resp) {
- try {
- PageBean pageBean=new PageBean();
- pageBean.setRequest(req);
- List<Map<String, Object>> infos = backDao.queryMeetingFeedBackByUserId(back, pageBean);
- // 注意:layui中的数据表格的格式
- ResponseUtil.writeJson(resp, R.ok(0, "会议通知数据查询成功",pageBean.getTotal(),infos));
- } catch (Exception e) {
- e.printStackTrace();
- try {
- ResponseUtil.writeJson(resp, R.error(0, "会议通知数据查询失败"));
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- return null;
- }
-
- }
"/feedBack" type="com.zking.web.MeetingFeedBackAction"> -
运行效果如下:
MeetingFeedBackDao:
- // 会议反馈
- public int add(MeetingFeedBack back) throws Exception {
- String sql="insert into t_oa_meeting_feedback values (?,?,?,?,?,?)";
- //前台没有传递id到后台,所以自己生成id
- back.setId(UUID.randomUUID().toString().replace("-", ""));
- return super.executeUpdate(sql, back, new String [] {"id","meetingId","personType","personId","result","reason"});
- }
MeetingFeedBackAction:
- //会议反馈
- public String add(HttpServletRequest req, HttpServletResponse resp) {
- try {
- // rs是sql语句执行的影响行数
- int rs = backDao.add(back);
- if(rs>0) {
- ResponseUtil.writeJson(resp, R.ok(200, "会议反馈信息成功"));
- }else {
- ResponseUtil.writeJson(resp, R.error(0, "会议反馈信息失败"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- try {
- ResponseUtil.writeJson(resp, R.error(0, "会议反馈信息失败"));
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- return null;
- }
接下来运行:
点击会议反馈按钮之后:
我们会发现第16条数据已经没有了,进数据库查询 会议信息反馈表(t_oa_meeting_feedback):
会议反馈功能已实现~
MeetingFeedBackDao:
- // 会议反馈详情
- public List<Map<String, Object>> queryMeetingBackByMeetingId(MeetingFeedBack back, PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException {
- String sql="select \r\n" +
- " t.result,GROUP_CONCAT(t.name) names\r\n" +
- " from\r\n" +
- " (select \r\n" +
- " t1.name,IFNULL(f.result,-1) result\r\n" +
- " from\r\n" +
- " (SELECT * from t_oa_user where FIND_IN_SET(id, (SELECT CONCAT(canyuze,',',liexize,',',zhuchiren) from\r\n" +
- " t_oa_meeting_info \r\n" +
- " where id="+back.getMeetingId()+"))) t1\r\n" +
- " left join t_oa_meeting_feedback f on t1.id=f.personId and f.meetingId="+back.getMeetingId()+") t\r\n" +
- " GROUP BY t.result";
- return super.executeQuery(sql, pageBean);
- }
MeetingFeedBackAction:
- //会议反馈详情
- public String queryMeetingBackByMeetingId(HttpServletRequest req, HttpServletResponse resp) {
- try {
- PageBean pageBean=new PageBean();
- pageBean.setRequest(req);
- List<Map<String, Object>> lst = backDao.queryMeetingBackByMeetingId(back, pageBean);
- // 注意:layui中的数据表格的格式
- ResponseUtil.writeJson(resp, R.ok(0, "会议反馈详情数据查询成功",pageBean.getTotal(),lst));
- } catch (Exception e) {
- e.printStackTrace();
- try {
- ResponseUtil.writeJson(resp, R.error(0, "会议反馈详情数据查询失败"));
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- return null;
- }
运行效果:
比如登录此(张强)账号,对 第8条 做出反馈:
说明张强是缺席的。
接着换登录 admin 账号:
在我的会议中查看 反馈详情:
我们就可以看到张强在缺席人员的列表中了!
为了准确性,接着我们测试 添加一些参会人员,比如张三,
我们登录 张三 账号:
现在是未读状态,点击参会:
会议反馈成功之后,再次切换 admin 账号,
在我的会议中查看 反馈详情:
那么 张三就出现在参会人员的列表中啦~