001 | package org.QQroom.dao.impl; |
002 |
003 | import java.sql.ResultSet; |
004 | import java.sql.SQLException; |
005 | import java.text.SimpleDateFormat; |
006 | import java.util.ArrayList; |
007 | import java.util.Date; |
008 | import java.util.List; |
009 |
010 | import org.QQroom.dao.DiaryDao; |
011 | import org.QQroom.entity.Diary; |
012 | import org.QQroom.entity.PageBean; |
013 | import org.QQroom.entity.UserLogin; |
014 | import org.QQroom.utils.BaseDao; |
015 | /** |
016 | * 日志实现类 |
017 | * @author lenovo |
018 | * |
019 | */ |
020 | public class DiaryDaoImpl extends BaseDao implements DiaryDao { |
021 | /** |
022 | *(当前用户)得到所有的日志 |
023 | */ |
024 | @Override |
025 | public List<Diary> getAllDiary( int userId) { //wirteTime, |
026 | String sql = "select id,wirteTime,title,content, userID from diary where userID=? order by id desc" ; |
027 | List<Diary> list = new ArrayList<Diary>(); |
028 | ResultSet rs = super .getResultSet(sql, userId); |
029 | if (rs!= null ){ |
030 | try { |
031 | while (rs.next()){ |
032 | Diary diary = new Diary(); |
033 | diary.setId(rs.getInt( "id" )); |
034 | diary.setWriteTime(rs.getDate( "wirteTime" )); |
035 |
036 | |
037 | diary.setWriteTime(rs.getTimestamp( "wirteTime" )); |
038 | diary.setTitle(rs.getString( "title" )); |
039 | diary.setContent(rs.getString( "content" )); |
040 | diary.setUserId(rs.getInt( "userID" )); |
041 | list.add(diary); |
042 | } |
043 | } catch (SQLException e) { |
044 | // TODO Auto-generated catch block |
045 | e.printStackTrace(); |
046 | } finally { |
047 | if (rs!= null ){ |
048 | try { |
049 | super .closeAll(rs, rs.getStatement(), rs.getStatement().getConnection()); |
050 | } catch (SQLException e) { |
051 | // TODO Auto-generated catch block |
052 | e.printStackTrace(); |
053 | } |
054 | } |
055 | } |
056 | } |
057 | return list; |
058 | } |
059 | /** |
060 | *(当前用户)得到所有的日志 |
061 | */ |
062 | |
063 | /*public List<Diary> getAllDiary(PageBean pageBean,int userId) {//wirteTime, |
064 | String sql = "select top (?) * from diary where id not in(select top (?) id from diary ) and userID=? order by id desc"; |
065 | List<Diary> list = new ArrayList<Diary>(); |
066 | Object params[] = {pageBean.getPageSize(),(pageBean.getPageNum()-1)*pageBean.getPageSize(),userId}; |
067 | ResultSet rs = super.getResultSet(sql, params); |
068 | if(rs!=null){ |
069 | try { |
070 | while(rs.next()){ |
071 | Diary diary = new Diary(); |
072 | diary.setId(rs.getInt("id")); |
073 | diary.setWriteTime(rs.getDate("wirteTime")); |
074 |
075 | |
076 | diary.setWriteTime(rs.getTimestamp("wirteTime")); |
077 | diary.setTitle(rs.getString("title")); |
078 | diary.setContent(rs.getString("content")); |
079 | diary.setUserId(rs.getInt("userID")); |
080 | list.add(diary); |
081 | } |
082 | } catch (SQLException e) { |
083 | // TODO Auto-generated catch block |
084 | e.printStackTrace(); |
085 | }finally{ |
086 | if(rs!=null){ |
087 | try { |
088 | super.closeAll(rs, rs.getStatement(), rs.getStatement().getConnection()); |
089 | } catch (SQLException e) { |
090 | // TODO Auto-generated catch block |
091 | e.printStackTrace(); |
092 | } |
093 | } |
094 | } |
095 | } |
096 | return list; |
097 | }*/ |
098 | /** |
099 | *添加日志 |
100 | */ |
101 | @Override |
102 | public int addDiary(Diary diary) { |
103 | String sql = "insert into diary(wirteTime, title, content, userID) values(default,?,?,?)"; |
104 | Object[] params = {diary.getTitle(),diary.getContent(),diary.getUserId()}; |
105 | return super.updateDate(sql, params); |
106 | } |
107 | /** |
108 | * 修改日志(通过当前登录的账号和日志编号) |
109 | * @return |
110 | */ |
111 | public int updateDiary(Diary diary){ |
112 | String sql = "update diary set wirteTime=getdate(),title=?,content=? where id=? and userID=?"; |
113 | Object[] params = {diary.getTitle(),diary.getContent(),diary.getId(),diary.getUserId()}; |
114 | return super.updateDate(sql, params); |
115 | } |
116 | /** |
117 | *删除日志 |
118 | */ |
119 | @Override |
120 | public int deleteDiary(int id,int userId) { |
121 | String sql = "delete diary where id = ? and userID = ?"; |
122 | Object[] params = {id,userId}; |
123 | return super.updateDate(sql, params); |
124 | } |
125 | /** |
126 | * 获取日志对象 (根据日志编号 和 用户的acc ) |
127 | */ |
128 | @Override |
129 | public Diary getOntDiay(Diary diary) { |
130 | String sql = "select id,wirteTime,title,content, userID from diary where userID=? and id=? "; |
131 | Diary diaryOne = null; |
132 | Object[] params = {diary.getUserId(),diary.getId()}; |
133 | ResultSet rs = super.getResultSet(sql, params); |
134 | if(rs!=null){ |
135 | try { |
136 | while(rs.next()){ |
137 | diaryOne = new Diary(); |
138 | diaryOne.setId(rs.getInt("id")); |
139 | /*diary.setWriteTime((rs.getDate("wirteTime")).toString());*/ |
140 | |
141 | /*diaryOne.setWriteTime(new Date(rs.getTime("wirteTime").getTime()));*/ |
142 | diaryOne.setWriteTime(rs.getDate("wirteTime")); |
143 | /*diaryOne.setWriteTime(rs.getTimestamp("wirteTime"));*/ |
144 | diaryOne.setTitle(rs.getString("title")); |
145 | diaryOne.setContent(rs.getString("content")); |
146 | diaryOne.setUserId(rs.getInt("userID")); |
147 | |
148 | } |
149 | } catch (SQLException e) { |
150 | // TODO Auto-generated catch block |
151 | e.printStackTrace(); |
152 | }finally{ |
153 | if(rs!=null){ |
154 | try { |
155 | super.closeAll(rs, rs.getStatement(), rs.getStatement().getConnection()); |
156 | } catch (SQLException e) { |
157 | // TODO Auto-generated catch block |
158 | e.printStackTrace(); |
159 | } |
160 | } |
161 | } |
162 | } |
163 | return diaryOne; |
164 | } |
165 | /** |
166 | * 得到当前用户日志的总数 |
167 | */ |
168 | @Override |
169 | public int getDiarySum(UserLogin user) { |
170 | String sql = "select count(0) as c from diary where userID=?" ; |
171 | ResultSet rs = super .getResultSet(sql, user.getAcc()); |
172 | int result = 0 ; |
173 | if (rs!= null ){ |
174 | try { |
175 | while (rs.next()){ |
176 | result=rs.getInt( "c" ); |
177 | } |
178 | } catch (SQLException e) { |
179 | // TODO Auto-generated catch block |
180 | e.printStackTrace(); |
181 | } finally { |
182 | if (rs!= null ){ |
183 | try { |
184 | super .closeAll(rs, rs.getStatement(), rs.getStatement().getConnection()); |
185 | } catch (SQLException e) { |
186 | // TODO Auto-generated catch block |
187 | e.printStackTrace(); |
188 | } |
189 | } |
190 | } |
191 | } |
192 | return result; |
193 | } |
194 | |
195 | |
196 |
197 | } |

阿萨大大123213 LV2
2024年2月24日
liu2022 LV14
2022年7月31日
最代码安逸 LV15
2022年3月6日
谢小饭_ LV8
2022年1月21日
nsz123456 LV11
2021年12月5日
17614867633 LV3
2021年6月13日
Orianna LV2
2021年5月8日
王东东 LV17
2021年4月16日
荆童123456 LV2
2021年3月22日
newscc LV8
2021年2月7日

3210423009
2024年12月21日
暂无贡献等级
edpwyg LV14
2024年7月28日
66219810 LV1
2024年7月16日
Alpaca_23
2024年6月15日
暂无贡献等级
goccgoccgocc LV4
2024年5月9日
Ashbell
2024年2月25日
暂无贡献等级
阿萨大大123213 LV2
2024年2月24日
微信网友_6878791569330176
2024年2月23日
暂无贡献等级
℡ LV8
2023年10月23日
cksndh LV4
2023年8月16日