Example #1
0
  @RequestMapping(params = "p=add")
  public @ResponseBody Map<String, Object> add(SYS_Role entity, HttpSession session) {
    SYS_User user = (SYS_User) session.getAttribute(Const.SESSION_USER);
    try {
      checkEntity(entity);

      entity.setRoleID(UUIDUtil.get32UUID());
      entity.setInputName(user.getUserName());
      entity.setInputDate(DateUtil.getDateTimeString());

      if (CheckUtil.isNullStr(entity.getCompanyID())) {
        entity.setCompanyID(user.getCompanyID());
        entity.setCompanyName(user.getCompanyName());
      }

      SYS_RoleAccess roleCompany = new SYS_RoleAccess();
      roleCompany.setRoacID(UUIDUtil.get32UUID());
      roleCompany.setDataType("Company");
      roleCompany.setDataValue(entity.getCompanyID());
      roleCompany.setRoleID(entity.getRoleID());
      roleCompany.setRoleName(entity.getRoleName());
      roleCompany.setInputDate(DateUtil.getDateTimeString());
      roleCompany.setInputName(user.getRealName() + "[" + user.getUserName() + "]");
      // 添加跟目录
      List<SYS_RoleModule> list = new ArrayList<SYS_RoleModule>();
      SYS_RoleModule rm = new SYS_RoleModule();
      rm.setRomoID(UUIDUtil.get32UUID());
      rm.setRoleID(entity.getRoleID());
      rm.setRoleName(entity.getRoleName());
      rm.setModuleID("400");
      rm.setModuleName(entity.getCompanyName());
      rm.setInputDate(DateUtil.getDateTimeString());
      rm.setInputName(user.getUserName());
      list.add(rm);
      String s = SQLUtil.getInsertSQL(list);
      s += SQLUtil.getInsertSQL(entity);
      roleDao.jdbcTemplate.execute(s);
      //			roleDao.insert(entity);
    } catch (Exception e) {
      return MessageUtil.exception(user, e);
    }

    return MessageUtil.success();
  }
Example #2
0
  @SuppressWarnings("unchecked")
  @RequestMapping(params = "p=addrolemodule")
  public @ResponseBody Map<String, Object> addRoleModule(
      @ModelAttribute SYS_Role role,
      String module1,
      String module2,
      String modulestr,
      HttpSession session,
      String appPlatform) {
    SYS_User user = (SYS_User) session.getAttribute(Const.SESSION_USER);
    Map<String, Object> result = new HashMap<String, Object>();
    try {
      JSONArray jsonArray = JSONArray.fromObject(unicode(modulestr));

      if (CheckUtil.isNullStr(module1)) {
        throw new CustomerException("请选择子系统");
      }

      if (CheckUtil.isNullStr(module2)) {
        throw new CustomerException("请选择一级菜单");
      }

      List<SYS_RoleModule> list = new ArrayList<SYS_RoleModule>();
      List<SYS_RoleModule> list1 = new ArrayList<SYS_RoleModule>();
      // String sql = "select * from SYS_Module where ModuleID in ('" +
      // module1 + "','" + module2 + "')"+" ;";
      String sql =
          "select * from SYS_Module where ParentID = '"
              + module2
              + "' || ModuleID = '"
              + module2
              + "' ;";
      String sql1 = "select * from SYS_Module where ModuleID = '" + module2 + "' ;";
      List<SYS_Module> pars = roleDao.query(SYS_Module.class, sql);
      SYS_Module pars1 = roleDao.query(SYS_Module.class, sql1).get(0);
      if (pars.size() > 0 || "AIR".equals(appPlatform)) {
        for (SYS_Module temp : pars) {
          SYS_RoleModule rm = new SYS_RoleModule();
          rm.setRomoID(UUIDUtil.get32UUID());
          rm.setRoleID(role.getRoleID());
          rm.setRoleName(unicode(role.getRoleName()));
          rm.setModuleID(temp.getModuleID());
          rm.setModuleName(temp.getModuleName());
          rm.setInputDate(DateUtil.getDateTimeString());
          rm.setInputName(user.getUserName());
          list.add(rm);
        }
      }
      sql += SQLUtil.getDeleteSQLByModule(list);

      for (Object obj : jsonArray) {
        SYS_Module temp = PropertyUtil.copyMap(SYS_Module.class, (Map<String, Object>) obj);
        SYS_RoleModule rm = new SYS_RoleModule();
        rm.setRomoID(UUIDUtil.get32UUID());
        rm.setRoleID(role.getRoleID());
        rm.setRoleName(unicode(role.getRoleName()));
        rm.setModuleID(temp.getModuleID());
        rm.setModuleName(temp.getModuleName());
        rm.setInputDate(DateUtil.getDateTimeString());
        rm.setInputName(user.getUserName());
        list1.add(rm);
      }
      for (Object obj : jsonArray) {
        SYS_Module temp = PropertyUtil.copyMap(SYS_Module.class, (Map<String, Object>) obj);
        SYS_RoleModule rm = new SYS_RoleModule();
        if (temp.getParentID().equals(module2)) {
          rm.setRomoID(UUIDUtil.get32UUID());
          rm.setRoleID(role.getRoleID());
          rm.setRoleName(unicode(role.getRoleName()));
          rm.setModuleID(pars1.getModuleID());
          rm.setModuleName(pars1.getModuleName());
          rm.setInputDate(DateUtil.getDateTimeString());
          rm.setInputName(user.getUserName());
          list1.add(rm);
        }
        break;
      }

      // if ("AIR".equals(appPlatform) && CheckUtil.isNullStr(module2)) {
      // sql = "delete from SYS_RoleModule where ModuleId in ('" + module1
      // + "','" + module2 + "') and RoleID='" + role.getRoleID() + "'\n"+
      // " ; ";
      // } else {
      // sql = "delete from SYS_RoleModule where ModuleId in ('" + module1
      // + "','" + module2 + "') and RoleID='" + role.getRoleID() + "'\n"
      // + " ; ";
      // }

      // sql +=
      // "delete a from SYS_RoleModule a, SYS_Module b where "+module1+" =
      // "+module2+/*a.ModuleID=b.ModuleID*/" and b.ParentID='"+module2+"' and RoleID='"
      // + role.getRoleID() + "'\n";

      sql += SQLUtil.getInsertSQLByRole(list1);

      roleDao.jdbcTemplate.execute(sql);
    } catch (Exception e) {
      return MessageUtil.exception(user, e);
    }

    return MessageUtil.success(result);
  }