Пример #1
0
  /**
   * 通过对象查询数量
   *
   * @param role
   * @param response
   */
  @RequestMapping(
      value = "/queryCountByObj",
      method = {RequestMethod.POST, RequestMethod.GET})
  public void queryCountByObj(Resource res, HttpServletResponse response) {
    int infoMsg = 0;
    try {
      List<Resource> list = resourceService.queryResourceByObj(res);
      if (list.size() > 0) { // 加入只有一条的话,则为本身。
        infoMsg = list.size();
      }
    } catch (Exception e) {
      log.error("queryCountByObj error通过对象查询数量出错");
    }

    response.setContentType("text/html;charset=utf-8");
    PrintWriter pw = null;
    try {
      pw = response.getWriter();
      pw.write(infoMsg + "");
      pw.flush();
    } catch (IOException e) {
      log.error("pw.write(jsonData.toString())  error");
    } finally {
      if (pw != null) {
        pw.close();
      }
    }
  }
Пример #2
0
  /**
   * 添加资源的实现
   *
   * @param resource要添加的资源
   * @return
   */
  @RequestMapping(
      value = "/resInsertAction",
      method = {RequestMethod.POST, RequestMethod.GET})
  public void resInsertAction(Resource res, HttpServletResponse response) {
    // resourceService.addResource(resource);
    String uuid = UUID.randomUUID().toString().replace("-", "");
    res.setResid(uuid);
    String infoMsg = "";
    try {
      boolean b = resourceService.insertRes(res);
      if (b) {
        infoMsg = "addSuc";
        getResMap().put(res.getResid(), res);
      }
    } catch (Exception e) {
      infoMsg = "addError";
      log.error("resAddAction error 添加资源错误 ");
    }

    response.setContentType("text/html;charset=utf-8");
    PrintWriter pw = null;
    try {
      pw = response.getWriter();
      pw.write(infoMsg);
      pw.flush();
    } catch (IOException e) {
      log.error("pw.write(jsonData.toString())  error");
    } finally {
      if (pw != null) {
        pw.close();
      }
    }
    // return "redirect:/resource/queryAllResource.do";
  }
Пример #3
0
  /**
   * 资源修改实现
   *
   * @param res传入修改的资源
   * @return 返回资源显示页面
   */
  @RequestMapping(
      value = "/updateResAction",
      method = {RequestMethod.POST, RequestMethod.GET})
  public void updateRoleAction(Resource res, HttpServletResponse response) {
    boolean b = true;
    String infoMsg = "";
    try {
      b = resourceService.updateRes(res);
      if (b) {
        infoMsg = "updateSuc";
        getResMap().remove(res.getResid());
        getResMap().put(res.getResid(), res);
      }
    } catch (Exception e) {
      b = false;
      infoMsg = "updateError";
      log.error("updateRoleAction error 资源修改出错");
    }

    response.setContentType("text/html;charset=utf-8");
    PrintWriter pw = null;
    try {
      pw = response.getWriter();
      pw.write(infoMsg);
      pw.flush();
    } catch (IOException e) {
      log.error("pw.write(jsonData.toString())  error");
    } finally {
      if (pw != null) {
        pw.close();
      }
    }

    // return "redirect:/resource/queryAllResource.do";
  }
Пример #4
0
  /**
   * 批量删除
   *
   * @param request 获取页面参数
   * @return
   */
  @RequestMapping(
      value = "/deleteRessById",
      method = {RequestMethod.POST, RequestMethod.GET})
  public void deleteRessById(HttpServletRequest request, HttpServletResponse response) {

    String resids = request.getParameter("resids");
    String infoMsg = ""; // 记录用户操作是否得成功的信息
    try {
      String[] idsArray = resids.split(",");
      for (int i = 0; i < idsArray.length; i++) {
        int privlgCount =
            privilegeService.queryCountByObj(
                new Privilege(null, idsArray[i], null, true, null, null));
        if (privlgCount > 0) { // 一旦查询出来,有用户在用该权限,则返回
          infoMsg = "isUsed";
          break;
        }

        int columnCount =
            columnService.queryCountByObj(new Column(null, null, null, idsArray[i], null));
        if (columnCount > 0) {
          infoMsg = "isUsed";
          break;
        }
      }
      if (!"isUsed".equals(infoMsg)) { // 没有被使用
        boolean b = resourceService.deleteRessById(resids);
        if (b) {
          infoMsg = "delSuc";
          for (int i = 0; i < idsArray.length; i++) {
            getResMap().remove(idsArray[i]);
          }
        } else {
          infoMsg = "delError";
        }
      }

    } catch (Exception e) {
      infoMsg = "delError";
      log.error("deleteUsersById error 批量删除出错");
    }

    response.setContentType("text/html;charset=utf-8");
    PrintWriter pw = null;
    try {
      pw = response.getWriter();
      pw.write(infoMsg);
      pw.flush();
    } catch (IOException e) {
      log.error("pw.write(jsonData.toString())  error");
    } finally {
      if (pw != null) {
        pw.close();
      }
    }

    // return "redirect:/resource/queryAllResource.do";
  }
Пример #5
0
 /**
  * 删除资源
  *
  * @param res要删除的资源
  * @return 返回到资源的显示页面
  */
 @RequestMapping(
     value = "/deleteRes",
     method = {RequestMethod.POST, RequestMethod.GET})
 public String deleteRes(Resource res) {
   try {
     boolean b = resourceService.deleteRes(res);
     if (b) {
       getResMap().remove(res.getResid());
     }
   } catch (Exception e) {
     log.error("deleteRes error 删除资源错误");
   }
   return "redirect:/resource/queryAllResource.do";
 }
Пример #6
0
  /**
   * 分页查询资源(带模糊查询)
   *
   * @param page 分页对象
   * @param request
   * @param response
   */
  @RequestMapping(value = "/queryAllResourceAction")
  public void queryAllResourceAction(
      Resource resource, HttpServletRequest request, HttpServletResponse response) {

    // 分页查询数据
    List<Resource> resourceList = new ArrayList<Resource>();
    try {
      resourceList = resourceService.queryAllResource(resource); // 分页查询
    } catch (Exception e1) {
      log.error("分页查询所有资源出错");
    }

    int count = 0;
    try {
      count = resourceService.queryResourceCount(resource);
    } catch (Exception e1) {
      log.error("查询资源数量出错");
    }

    Map<String, Object> resEasyUIMap =
        new HashMap<String, Object>(); // map中放入rows,total便于esayUI前端展示
    resEasyUIMap.put("rows", resourceList);
    resEasyUIMap.put("total", count);
    response.setContentType("text/html;charset=utf-8");
    PrintWriter pw = null;
    try {
      pw = response.getWriter();
      pw.write(JSONObject.fromObject(resEasyUIMap).toString()); // 输入的是json key Object的字符串
      pw.flush();
    } catch (IOException e) {
      log.error("输出json出错");
    } finally {
      if (pw != null) {
        pw.close();
      }
    }
  }