diff --git a/src/com/hellogithub/dao/AdminDao.java b/src/com/hellogithub/dao/AdminDao.java index 690a7c5..1e5b08c 100644 --- a/src/com/hellogithub/dao/AdminDao.java +++ b/src/com/hellogithub/dao/AdminDao.java @@ -6,10 +6,7 @@ import com.hellogithub.utils.JdbcUtils; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.BeanListHandler; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.List; public class AdminDao { @@ -41,20 +38,80 @@ public class AdminDao { } } - public int updateAdminLoginTime(String name){ - String label=""; + public int updateAdminLoginTime(String name,String loginTime){ int num; try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql="UPDATE user SET searchHistory = ? WHERE userName= ? and isValid = 1"; - num = runner.update(conn,sql,label,name); + String sql="UPDATE admin SET loginTime = ? WHERE adminName= ? and isValid = 1"; + num = runner.update(conn,sql,loginTime,name); } catch (SQLException e) { throw new RuntimeException(e); } return num; } + /** + * 根据用户名查询管理员 + * */ + public adminEntity findByAdminName(String adminName) { + ResultSet resultSet = null; + PreparedStatement preparedStatement = null; + Connection connection = null; + try { + connection = JdbcUtils.getConnection(); + String Sql = "select * from admin where adminName=? and isValid = 1"; + preparedStatement = connection.prepareStatement(Sql); + preparedStatement.setString(1, adminName); + resultSet = preparedStatement.executeQuery(); + if (!resultSet.next()) { // 查询不到用户数据 + return null; + } + // 将db中数据 返回给客户端 查询到数据 + Integer id = resultSet.getInt(1); + String dbUserName = resultSet.getString(2); + String dbUserPwd = resultSet.getString(3); + adminEntity adminEntity = new adminEntity(dbUserName, dbUserPwd); + return adminEntity; + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally { + JdbcUtils.closeConnection(resultSet, preparedStatement, connection); + } + } + + /** + * 管理员注册 + * + * */ + public int adminRegister(String adminName,String adminPwd){ + Connection connection = null; + PreparedStatement preparedStatement = null; + try { + connection = JdbcUtils.getConnection(); + // sql语句写的操作 ----加上事务 + JdbcUtils.beginTransaction(connection); // 开启事务 + String insertSql = "INSERT INTO admin (adminId, adminName, adminPassword,isValid,loginTime) VALUES (null, ?,?,1,?);"; + preparedStatement = connection.prepareStatement(insertSql); + preparedStatement.setString(1,adminName); + preparedStatement.setString(2, adminPwd); + Date time= new java.sql.Date(new java.util.Date().getTime()); + preparedStatement.setDate(3, time); + int result = preparedStatement.executeUpdate(); + // 代码执行没有问题的情况下 则会提交数据 + JdbcUtils.commitTransaction(connection); // 提交事务 + return result; + } catch (Exception e) { + // 程序代码报错之后 是需要回滚事务 + e.printStackTrace(); + JdbcUtils.rollBackTransaction(connection);// 回滚事务 + return 0; + } finally { + JdbcUtils.closeConnection(preparedStatement, connection); + } + + } /* * diff --git a/src/com/hellogithub/service/UserService.java b/src/com/hellogithub/service/UserService.java index b3340de..0e3b966 100644 --- a/src/com/hellogithub/service/UserService.java +++ b/src/com/hellogithub/service/UserService.java @@ -87,4 +87,13 @@ public class UserService { } public void LevelUp(String username){userDao.LevelUp(username);} + + + public List selectAllUser(){return userDao.selectAllUser(); } + + public int updateUserDetail(int userId ,String userName , String userPassword, String creatTime ,int isValid ,int projectNum ,String searchHistory ,int contributionValue, String userAvatar ,int userLevel) + { + return userDao.updateUserDetail( userId , userName , userPassword, creatTime , isValid , projectNum , searchHistory , contributionValue, userAvatar , userLevel); + } + public int deleteUser(int id ){return userDao.deleteUser(id); } } diff --git a/src/com/hellogithub/service/commentService.java b/src/com/hellogithub/service/commentService.java index 877b56c..18ff389 100644 --- a/src/com/hellogithub/service/commentService.java +++ b/src/com/hellogithub/service/commentService.java @@ -97,4 +97,9 @@ public class commentService { } return tip; } + public List selectAllComment(){return commentDao.selectAllComment();} + public int updateCommentDetail(int commentId , int userId , int projectId, String content ,int isUsed ,String commentTime ,int isValid ,int star, int likeNum ){ + return commentDao.updateCommentDetail( commentId , userId , projectId, content , isUsed ,commentTime ,isValid ,star, likeNum ); + } + public int deleteComment(int id ){return commentDao.deleteComment(id);} } diff --git a/src/com/hellogithub/service/projectService.java b/src/com/hellogithub/service/projectService.java index 5b90e17..5d4df04 100644 --- a/src/com/hellogithub/service/projectService.java +++ b/src/com/hellogithub/service/projectService.java @@ -281,4 +281,13 @@ public class projectService { public int selectProjectByPname(String projectName){ return projectDao.selectProjectByPname(projectName); } + + + public List selectAllProject(){return projectDao.selectAllProject();} + + public int updateProjectDetail(int projectId , int userId , String projectName, String projectUrl ,String projectIco ,String projectTitle ,String projectDescription ,int startNum, String submitTime ,int categoryId,int isValid,String fileAddress,int periodicals,int lookCount) + { + return projectDao.updateProjectDetail( projectId , userId , projectName, projectUrl , projectIco , projectTitle , projectDescription , startNum, submitTime ,categoryId,isValid,fileAddress, periodicals, lookCount); + } + public int deleteProject(int id ){return projectDao.deleteProject(id);} } \ No newline at end of file