private List<User> changeModel(List<Tuser> tusers) {
    List<User> users = new ArrayList<User>();
    if (tusers != null && tusers.size() > 0) {
      for (Tuser tu : tusers) {
        User u = new User();
        BeanUtils.copyProperties(tu, u);

        Set<Tusertrole> tusertroles = tu.getTusertroles();
        String roleIds = "";
        String roleNames = "";
        boolean b = false;
        if (tusertroles != null && tusertroles.size() > 0) {
          for (Tusertrole tusertrole : tusertroles) {
            if (tusertrole.getTrole() != null) {
              if (b) {
                roleIds += ",";
                roleNames += ",";
              }
              roleIds += tusertrole.getTrole().getCid();
              roleNames += tusertrole.getTrole().getCname();
              b = true;
            }
          }
        }
        u.setRoleIds(roleIds);
        u.setRoleNames(roleNames);

        users.add(u);
      }
    }
    return users;
  }
 public void update(User user) {
   Tuser u = userDao.get(Tuser.class, user.getCid());
   BeanUtils.copyProperties(user, u, new String[] {"cid", "cpwd"});
   if (user.getCpwd() != null && !user.getCpwd().trim().equals("")) {
     u.setCpwd(Encrypt.e(user.getCpwd()));
   }
   u.setCmodifydatetime(new Date());
   this.saveUserRole(user, u);
 }
  public void save(User user) {
    Tuser u = new Tuser();
    BeanUtils.copyProperties(user, u, new String[] {"cpwd"});
    u.setCid(UUID.randomUUID().toString());
    u.setCpwd(Encrypt.e(user.getCpwd()));
    if (user.getCcreatedatetime() == null) {
      u.setCcreatedatetime(new Date());
    }
    if (user.getCmodifydatetime() == null) {
      u.setCmodifydatetime(new Date());
    }
    userDao.save(u);

    this.saveUserRole(user, u);
  }
  public User login(User user) {
    Tuser t =
        userDao.get(
            "from Tuser t where t.cname = ? and t.cpwd = ?",
            new Object[] {user.getCname(), Encrypt.e(user.getCpwd())});
    if (t != null) {
      BeanUtils.copyProperties(t, user, new String[] {"cpwd"});

      Map<String, String> authIdsMap = new HashMap<String, String>();
      String authIds = "";
      String authNames = "";
      Map<String, String> authUrlsMap = new HashMap<String, String>();
      String authUrls = "";
      String roleIds = "";
      String roleNames = "";
      boolean b1 = false;
      Set<Tusertrole> tusertroles = t.getTusertroles();
      if (tusertroles != null && tusertroles.size() > 0) {
        for (Tusertrole tusertrole : tusertroles) {
          Trole trole = tusertrole.getTrole();
          if (b1) {
            roleIds += ",";
            roleNames += ",";
          }
          roleIds += trole.getCid();
          roleNames += trole.getCname();
          b1 = true;

          Set<Troletauth> troletauths = trole.getTroletauths();
          if (troletauths != null && troletauths.size() > 0) {
            for (Troletauth troletauth : troletauths) {
              Tauth tauth = troletauth.getTauth();
              authIdsMap.put(tauth.getCid(), tauth.getCname());
              authUrlsMap.put(tauth.getCid(), tauth.getCurl());
            }
          }
        }
      }
      boolean b2 = false;
      for (String id : authIdsMap.keySet()) {
        if (b2) {
          authIds += ",";
          authNames += ",";
        }
        authIds += id;
        authNames += authIdsMap.get(id);
        b2 = true;
      }
      user.setAuthIds(authIds);
      user.setAuthNames(authNames);
      user.setRoleIds(roleIds);
      user.setRoleNames(roleNames);
      boolean b3 = false;
      for (String id : authUrlsMap.keySet()) {
        if (b3) {
          authUrls += ",";
        }
        authUrls += authUrlsMap.get(id);
        b3 = true;
      }
      user.setAuthUrls(authUrls);

      return user;
    }
    return null;
  }
 public void editUserInfo(User user) {
   if (user.getCpwd() != null && !user.getCpwd().trim().equals("")) {
     Tuser t = userDao.get(Tuser.class, user.getCid());
     t.setCpwd(Encrypt.e(user.getCpwd()));
   }
 }