layui 复选框选中学员推送给老师 controller代码
当前页面加载时传过去数据,多条件查询
@ResponseBody
@RequestMapping("queryalllists")
public Object queryalllists(Model model,Integer page,Integer limit,HttpServletRequest request,String username,Integer times) {
//根据用户名字查询出teacher表中的id 再根据id查询出student
CookieUtils cookieUtils = new CookieUtils();
String teaid =(String) CookieUtils.getCookieValue(request, "teaid");
long ttid = Long.parseLong(teaid);
List<EduTeacher> tlist = eduTeacherMapper.querytyteacherByid(ttid);
if(tlist.size()==0) {
Map<String, Object> json = new HashMap<String, Object>();
json.put("code", 0);
json.put("msg", "");
json.put("count",0);
json.put("data", null);
return json;
}
PageHelper.startPage(page, limit);
List<Student> mm=new ArrayList<Student>();
if(times==-1)
{
mm = tystudentMapper.queryStudentByusername(ttid,username);
}
else{
mm=tystudentMapper.queryStudentBytime(ttid, username, times);
}
PageInfo<Student> info=new PageInfo<Student>(mm);
Map<String, Object> json = new HashMap<String, Object>();
json.put("code", 0);
json.put("msg", "");
json.put("count",info.getTotal());
json.put("data", info.getList());
return json;
}
点击推送 调用存入cookie的老师id
//推送
@RequestMapping("/push")
@ResponseBody
public Object queryTyteacher(HttpServletRequest request,Integer page,Integer limit) {
//点击推送时弹框
//这是自己的ccookie方法
CookieUtils cookieUtils = new CookieUtils();
String uname =(String) cookieUtils.getCookieValue(request, "uname");
String teaid =(String) CookieUtils.getCookieValue(request, "teaid");
long ttid = Long.parseLong(teaid);
//根据父类id查询出它下面的子类tlist.get(0).getTid()
PageHelper.startPage(page, limit);
List<Tyteacher> tulist = tyteacherMapper.querytyeatherBytidAndtype(ttid, ttid);
PageInfo<Tyteacher> info=new PageInfo<Tyteacher>(tulist);
Map<String, Object> json = new HashMap<String, Object>();
json.put("code", 0);
json.put("msg", "");
json.put("count",info.getTotal());
json.put("data", info.getList());
return json;
}
添加
@ResponseBody
@RequestMapping("/insetteacherstudent")
public Integer insetteacherstudent( String stuid,String teachid) {
//学员推送
Integer ids=null;
if(stuid!=null&&stuid!=""&&teachid!=null&&teachid!="") {
String[] stuidarr=stuid.split(",");
String[] teacheidarr=teachid.split(",");
for (int i = 0; i < teacheidarr.length; i++) {
for (int j = 0; j < stuidarr.length; j++) {
//如果已加入
List<Tyteacherstudent> querylist = tyteacherstudentMapper.queryteacherstudentBystuid(stuidarr[j]);
if(querylist.size()>0) {
return 0;
}
else{
//推送成功之后加入中间表
ids = tyteacherstudentMapper.addteacherstudentBystuidAndteachid(stuidarr[j], teacheidarr[i]);
//根据学生id查teachid
List<Tyteacherstudent> tslist = tyteacherstudentMapper.queryteacherstudentBystuid(stuidarr[j]);
long teach_id = tslist.get(0).getTeach_id();
//根据teachid查询出分配到哪个老师下面 并添加到student表
List<Tyteacher> teacherlist = tyteacherMapper.querytyteacherByiid(teach_id);
String name = teacherlist.get(0).getTname();
Student stu = new Student();
stu.setId(Long.parseLong(stuidarr[j]));
stu.setPush_teacher(name);
tystudentMapper.updateByStudent(stu);
}
}
}
}
return ids;
}