예제 #1
0
  /**
   * 将消息和确定的被通知人插入到rel_ntc_user表
   *
   * @param map
   * @param result
   * @return
   */
  @RequestMapping(value = Module.NEWS_MODULE + "/saveNtcUser")
  public String saveNoticeUserInfo(
      @RequestParam Map<String, Object> map, Map<String, Object> result) {

    String id = (String) map.get("id");
    String way = (String) map.get("way");
    String ntcId = (String) map.get("ntcId");
    String[] ids = id.split(",");

    // 按照角色选择
    if ("1".equals(way)) {
      if (ids != null && (ids.length > 1 || (ids.length == 1 && !"".equals(ids[0])))) {
        relNoticeUserMapper.deleteRoleIdsNotNull(ntcId);
        for (int i = 0; i < ids.length; i++) {
          // 根据一个roleId 选择所有符合该id的用户
          List<String> userList = relUserRoleService.selectUserList(ids[i]);

          if (userList != null) {
            RelNoticeUserKey key = new RelNoticeUserKey();
            key.setNtcId(ntcId);
            key.setRoleId(ids[i]);
            for (String userId : userList) {
              key.setUserId(userId);
              relNoticeUserMapper.insertSelective(key);
            }
          }
        }
      } else {
        // 返回信息,提示数据库中不存在roleId
        relNoticeUserMapper.deleteRoleIdsNotNull(ntcId);
      }

    } else if ("2".equals(way)) {
      if (ids != null && (ids.length > 1 || (ids.length == 1 && !"".equals(ids[0])))) {
        relNoticeUserMapper.deleteClassIdsNotNull(ntcId);
        for (int i = 0; i < ids.length; i++) {
          // 根据classId 获得一个班级的学生信息
          List<Student> stuList = studentService.selectByClassId(ids[i]);
          if (stuList != null && !stuList.isEmpty()) {
            String[] stuIds = new String[stuList.size()];
            for (int j = 0; j < stuList.size(); j++) {
              stuIds[j] = stuList.get(j).getStuId();
            }
            // 根据学生的id获得监护人的信息
            List<StuGuardian> guardianList = stuGuardianService.selectByStuIds(stuIds);
            if (guardianList != null) {
              // 对所选班级中所有的监护人进行通知
              for (int j = 0; j < guardianList.size(); j++) {
                RelNoticeUserKey key = new RelNoticeUserKey();
                key.setNtcId(ntcId);
                key.setUserId(guardianList.get(j).getuserId());
                key.setClassId(ids[i]);
                relNoticeUserMapper.insertSelective(key);
              }
            }
          }
        }
      } else {
        relNoticeUserMapper.deleteClassIdsNotNull(ntcId);
      }
    }
    result.put("map", map);

    return "redirect:selectNoticeList.action";
  }