예제 #1
0
 /**
  * 修改用户
  *
  * @param user
  */
 public void updateUser(User user) {
   Connection conn = DbUtil.getConnection();
   PreparedStatement ps = null;
   try {
     if (StringUtils.isNotBlank(user.getUserPassword())) {
       ps =
           conn.prepareStatement(
               "update auth_user au SET au.department_id = ? ,au.user_name = ? ,au.user_password = ? ,au.user_real_name = ?,au.use_status = ?,au.create_time = ? WHERE au.id = ?");
       ps.setInt(1, user.getDepartmentId());
       ps.setString(2, user.getUserName());
       ps.setString(3, Secure.encryptPwd(user.getUserPassword()));
       ps.setString(4, user.getUserRealName());
       ps.setInt(5, user.getUseStatus());
       ps.setTimestamp(6, user.getCreateTime());
       ps.setInt(7, user.getId());
       ps.executeUpdate();
     } else {
       ps =
           conn.prepareStatement(
               "update auth_user au SET au.department_id = ? ,au.user_name = ? ,au.user_real_name = ?,au.use_status = ?,au.create_time = ? WHERE au.id = ?");
       ps.setInt(1, user.getDepartmentId());
       ps.setString(2, user.getUserName());
       ps.setString(3, user.getUserRealName());
       ps.setInt(4, user.getUseStatus());
       ps.setTimestamp(5, user.getCreateTime());
       ps.setInt(6, user.getId());
       ps.executeUpdate();
     }
   } catch (Exception e) {
     log.error("修改用户信息出错", e);
   } finally {
     DbUtil.closeConnection(null, ps, conn);
   }
 }
예제 #2
0
 /**
  * 添加新用户
  *
  * @param user
  */
 public void addUser(User user) {
   Connection conn = DbUtil.getConnection();
   PreparedStatement ps = null;
   try {
     ps =
         conn.prepareStatement(
             "insert into auth_user(department_id,user_name,user_password,user_real_name,use_status,create_time) values(?,?,?,?,?,?)");
     ps.setInt(1, user.getDepartmentId());
     ps.setString(2, user.getUserName());
     ps.setString(3, Secure.encryptPwd(user.getUserPassword()));
     ps.setString(4, user.getUserRealName());
     ps.setInt(5, 1);
     ps.setTimestamp(6, user.getCreateTime());
     ps.execute();
   } catch (Exception e) {
     log.error("增加用户信息出错", e);
   } finally {
     DbUtil.closeConnection(null, ps, conn);
   }
 }