Exemplo n.º 1
0
  public static SysUser jsonToObject(JSONObject jsonObject) {
    SysUser model = new SysUser();

    if (jsonObject.containsKey("actorId")) {
      model.setActorId(jsonObject.getString("actorId"));
    }
    if (jsonObject.containsKey("account")) {
      model.setActorId(jsonObject.getString("account"));
    }
    if (jsonObject.containsKey("name")) {
      model.setName(jsonObject.getString("name"));
    }

    if (jsonObject.containsKey("evection")) {
      model.setEvection(jsonObject.getIntValue("evection"));
    }

    if (jsonObject.containsKey("gender")) {
      model.setGender(jsonObject.getIntValue("gender"));
    }

    if (jsonObject.containsKey("userType")) {
      model.setUserType(jsonObject.getIntValue("userType"));
    }

    if (jsonObject.containsKey("accountType")) {
      model.setAccountType(jsonObject.getIntValue("accountType"));
    }

    if (jsonObject.containsKey("dumpFlag")) {
      model.setDumpFlag(jsonObject.getIntValue("dumpFlag"));
    }

    if (jsonObject.containsKey("createDate")) {
      model.setCreateDate(jsonObject.getDate("createDate"));
    }

    if (jsonObject.containsKey("createBy")) {
      model.setCreateBy(jsonObject.getString("createBy"));
    }
    if (jsonObject.containsKey("updateBy")) {
      model.setUpdateBy(jsonObject.getString("updateBy"));
    }
    if (jsonObject.containsKey("updateDate")) {
      model.setUpdateDate(jsonObject.getDate("updateDate"));
    }

    if (jsonObject.containsKey("lastLoginTime")) {
      model.setLastLoginTime(jsonObject.getDate("lastLoginTime"));
    }

    if (jsonObject.containsKey("lastLoginIP")) {
      model.setLastLoginIP(jsonObject.getString("lastLoginIP"));
    }

    if (jsonObject.containsKey("remark")) {
      model.setRemark(jsonObject.getString("remark"));
    }

    if (jsonObject.containsKey("deptId")) {
      model.setDeptId(jsonObject.getInteger("deptId"));
    }

    if (jsonObject.containsKey("mail")) {
      model.setMail(jsonObject.getString("mail"));
    }

    if (jsonObject.containsKey("mobile")) {
      model.setMobile(jsonObject.getString("mobile"));
    }

    if (jsonObject.containsKey("telephone")) {
      model.setTelephone(jsonObject.getString("telephone"));
    }

    if (jsonObject.containsKey("headship")) {
      model.setHeadship(jsonObject.getString("headship"));
    }

    if (jsonObject.containsKey("superiorIds")) {
      model.setSuperiorIds(jsonObject.getString("superiorIds"));
    }

    if (jsonObject.containsKey("status")) {
      model.setStatus(jsonObject.getString("status"));
    }

    if (jsonObject.containsKey("adminFlag")) {
      model.setAdminFlag(jsonObject.getString("adminFlag"));
    }

    if (jsonObject.containsKey("userRoles")) {
      JSONArray array = jsonObject.getJSONArray("userRoles");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysUserRole r = SysUserRoleJsonFactory.jsonToObject(json);
          model.getUserRoles().add(r);
        }
      }
    }

    if (jsonObject.containsKey("roles")) {
      JSONArray array = jsonObject.getJSONArray("roles");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysRole r = SysRoleJsonFactory.jsonToObject(json);
          model.getRoles().add(r);
        }
      }
    }

    if (jsonObject.containsKey("functions")) {
      JSONArray array = jsonObject.getJSONArray("functions");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysFunction r = SysFunctionJsonFactory.jsonToObject(json);
          model.getFunctions().add(r);
        }
      }
    }

    if (jsonObject.containsKey("apps")) {
      JSONArray array = jsonObject.getJSONArray("apps");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysApplication r = SysApplicationJsonFactory.jsonToObject(json);
          model.getApps().add(r);
        }
      }
    }

    return model;
  }
Exemplo n.º 2
0
  public static ObjectNode toObjectNode(SysUser user) {
    ObjectNode jsonObject = new ObjectMapper().createObjectNode();

    jsonObject.put("actorId", user.getAccount());
    jsonObject.put("actorId_enc", RequestUtils.encodeString(user.getAccount()));
    jsonObject.put("userId", user.getAccount());
    jsonObject.put("userId_enc", RequestUtils.encodeString(user.getAccount()));

    jsonObject.put("name", user.getName());
    jsonObject.put("locked", user.getStatus());
    jsonObject.put("status", user.getStatus());

    if (user.getDepartment() != null) {
      jsonObject.put("deptId", user.getDepartment().getId());
      jsonObject.put("deptName", user.getDepartment().getName());
    } else {
      jsonObject.put("deptId", user.getDeptId());
    }

    jsonObject.put("accountType", user.getAccountType());
    jsonObject.put("userType", user.getUserType());
    jsonObject.put("dumpFlag", user.getDumpFlag());
    jsonObject.put("gender", user.getGender());
    jsonObject.put("evection", user.getEvection());
    jsonObject.put("superiorIds", user.getSuperiorIds());

    jsonObject.put("fax", user.getFax());
    jsonObject.put("telephone", user.getTelephone());
    jsonObject.put("headship", user.getHeadship());
    jsonObject.put("adminFlag", user.getAdminFlag());

    if (user.getEmail() != null) {
      jsonObject.put("mail", user.getEmail());
      jsonObject.put("email", user.getEmail());
    }
    if (user.getMobile() != null) {
      jsonObject.put("mobile", user.getMobile());
    }
    if (user.getLastLoginTime() != null) {
      jsonObject.put("lastLoginDate", DateUtils.getDateTime(user.getLastLoginDate()));
      jsonObject.put("lastLoginTime", DateUtils.getDateTime(user.getLastLoginDate()));
    }
    if (user.getLastLoginIP() != null) {
      jsonObject.put("loginIP", user.getLastLoginIP());
    }

    if (user.getCreateBy() != null) {
      jsonObject.put("createBy", user.getCreateBy());
    }
    if (user.getUpdateBy() != null) {
      jsonObject.put("updateBy", user.getUpdateBy());
    }
    if (user.getUpdateDate() != null) {
      jsonObject.put("updateDate", DateUtils.getDate(user.getUpdateDate()));
      jsonObject.put("updateDate_date", DateUtils.getDate(user.getUpdateDate()));
      jsonObject.put("updateDate_datetime", DateUtils.getDateTime(user.getUpdateDate()));
    }

    if (user.getUserRoles() != null && !user.getUserRoles().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysUserRole sysUserRole : user.getUserRoles()) {
        array.add(sysUserRole.toObjectNode());
      }
      jsonObject.set("userRoles", array);
    }

    if (user.getRoles() != null && !user.getRoles().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysRole sysRole : user.getRoles()) {
        array.add(sysRole.toObjectNode());
      }
      jsonObject.set("roles", array);
    }

    if (user.getFunctions() != null && !user.getFunctions().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysFunction sysFunction : user.getFunctions()) {
        array.add(sysFunction.toObjectNode());
      }
      // jsonObject.set("functions", array);
    }

    if (user.getApps() != null && !user.getApps().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysApplication app : user.getApps()) {
        array.add(app.toObjectNode());
      }
      // jsonObject.set("apps", array);
    }

    return jsonObject;
  }