Example #1
0
  @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
  @Path("/delete")
  @POST
  public String delete(@FormParam("jsonString") String jsonString) {
    App app = JsonMapper.buildNonDefaultMapper().fromJson(jsonString, App.class);

    int result = appService.delete(app);
    if (result > 0) {
      return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.SUCCESS);
    } else {
      return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.ERROR);
    }
  }
Example #2
0
  @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
  @Path("/add")
  @POST
  public String add(
      @FormParam("name") String name,
      @FormParam("description") String description /*,@FormParam("status") String status*/) {
    if (name == null
        || name.trim().equals("")
        || description == null
        || description.trim().equals("") /* ||status==null|| status.trim().equals("")*/) {
      return JsonResultUtils.getCodeAndMesByString(JsonResultUtils.Code.ERROR.getCode(), "参数不能为空!");
    }
    long id;
    try {
      id = appService.getIdByName(name);
    } catch (Exception ex) {
      id = 0;
    }
    if (id == 0) {
      Date now = new Date();
      // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
      // String createtime = dateFormat.format( now );

      App app = new App();
      app.setName(name);
      app.setDescription(description);
      app.setStatus("启用");
      app.setCreatetime(now);

      appService.add(app);
      return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.SUCCESS);
    } else {
      return JsonResultUtils.getCodeAndMesByString(JsonResultUtils.Code.ERROR.getCode(), "企业名已存在!");
    }
  }
 @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
 @Path("/delete")
 @POST
 public String delete(@FormParam("jsonString") String jsonString) {
   Authority authority = JsonMapper.buildNonDefaultMapper().fromJson(jsonString, Authority.class);
   String authorityName = authority.getName();
   int numDeleted = authorityPowerService.deleteByAuthorityName(authorityName);
   int result = authorityService.delete(authority);
   List<UserAuthority> userAuthorityList = userAuthorityService.findByAuthorityName(authorityName);
   if (userAuthorityList.size() > 0) {
     for (UserAuthority ua : userAuthorityList) {
       String userName = ua.getUserName();
       User user = userService.findByName(userName);
       String role = user.getRole();
       String[] roles = role.split(";");
       String[] newRoles = new String[roles.length - 1];
       int temp = 0;
       for (int i = 0; i < roles.length; i++) {
         if (!roles[i].equals(authorityName)) {
           newRoles[temp] = roles[i] + ";";
           temp++;
         }
       }
       String roles2 = "";
       String nr;
       for (int i = 0; i < newRoles.length; i++) {
         roles2 += newRoles[i];
       }
       if (roles2.equals("")) {
         nr = "";
       } else {
         nr = roles2.substring(0, roles2.length() - 1);
       }
       user.setRole(nr);
       userService.update(user);
       userAuthorityService.delete(ua);
     }
   }
   if ((result > 0) && (numDeleted >= 0)) {
     return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.SUCCESS);
   } else {
     return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.ERROR);
   }
 }
 @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
 @Path("/update")
 @POST
 public String update(@FormParam("jsonString") String jsonString) {
   SubAuthority subAuthority =
       JsonMapper.buildNonDefaultMapper().fromJson(jsonString, SubAuthority.class);
   long authorityId = subAuthority.getId();
   String authorityName = subAuthority.getName();
   String authorityDescription = subAuthority.getDescription();
   int authorityStatus = subAuthority.getStatus();
   String resource = subAuthority.getResource();
   Authority authority = new Authority();
   authority.setId(authorityId);
   authority.setName(authorityName);
   authority.setDescription(authorityDescription);
   authority.setStatus(authorityStatus);
   int deleted = authorityPowerService.deleteByAuthorityName(authorityName);
   if (deleted >= 0) {
     int result = authorityService.update(authority);
     String[] resourceArray = resource.split(";");
     for (int i = 0; i < resourceArray.length; i++) {
       Long powId = powerService.getIdByResource(resourceArray[i]);
       AuthorityPower authorityPower = new AuthorityPower();
       authorityPower.setAuthorityId(authorityId);
       authorityPower.setPowerId(powId);
       authorityPower.setPowerResource(resourceArray[i]);
       authorityPower.setAuthorityName(authorityName);
       authorityPowerService.add(authorityPower);
     }
     if (result > 0) {
       return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.SUCCESS);
     } else {
       return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.ERROR);
     }
   } else {
     return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.ERROR);
   }
 }
  @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
  @Path("/add")
  @POST
  public String add(
      @FormParam("name") String name,
      @FormParam("description") String description,
      @FormParam("status") String status,
      @FormParam("resource") String resource) {
    /*if(name==null || name.trim().equals("") || description==null || description.trim().equals("") || status==null || status.trim().equals("")){
        return JsonResultUtils.getCodeAndMesByString(JsonResultUtils.Code.ERROR.getCode(), "参数不能为空!");
    }*/
    long existAuthorityId;
    try {
      existAuthorityId = authorityService.getIdByName(name);

    } catch (Exception ex) {
      existAuthorityId = 0;
    }
    if (existAuthorityId == 0) {
      Authority authority = new Authority();
      authority.setName(name);
      authority.setDescription(description);
      authority.setStatus(Integer.parseInt(status));
      authorityService.add(authority);
      long currentAuthorityId = authorityService.getIdByName(name);
      String[] resourceArray = resource.split(";");
      for (int i = 0; i < resourceArray.length; i++) {
        long powerId = powerService.getIdByResource(resourceArray[i]);
        AuthorityPower authorityPower = new AuthorityPower();
        authorityPower.setAuthorityId(currentAuthorityId);
        authorityPower.setPowerId(powerId);
        authorityPower.setPowerResource(resourceArray[i]);
        authorityPower.setAuthorityName(name);
        authorityPowerService.add(authorityPower);
      }
      return JsonResultUtils.getCodeAndMesByStringAsDefault(JsonResultUtils.Code.SUCCESS);
    } else {
      return JsonResultUtils.getObjectResultByStringAsDefault("fail", JsonResultUtils.Code.ERROR);
    }
  }