jiapeng 7 years ago
parent
commit
00e02af7c1

+ 653 - 588
src/main/java/com/ekexiu/portal/dao/ArticleDao.java

5
import java.sql.ResultSet;
5
import java.sql.ResultSet;
6
import java.sql.SQLException;
6
import java.sql.SQLException;
7
import java.util.ArrayList;
7
import java.util.ArrayList;
8
import java.util.Collections;
9
import java.util.List;
8
import java.util.List;
10

9

11
import org.jfw.apt.annotation.Nullable;
10
import org.jfw.apt.annotation.Nullable;
13
import org.jfw.apt.orm.annotation.dao.Dynamic;
12
import org.jfw.apt.orm.annotation.dao.Dynamic;
14
import org.jfw.apt.orm.annotation.dao.method.Exclude;
13
import org.jfw.apt.orm.annotation.dao.method.Exclude;
15
import org.jfw.apt.orm.annotation.dao.method.From;
14
import org.jfw.apt.orm.annotation.dao.method.From;
15
import org.jfw.apt.orm.annotation.dao.method.Or;
16
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
16
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
17
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
17
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
18
import org.jfw.apt.orm.annotation.dao.method.Where;
18
import org.jfw.apt.orm.annotation.dao.method.Where;
30
import org.jfw.apt.orm.annotation.dao.param.LessThan;
30
import org.jfw.apt.orm.annotation.dao.param.LessThan;
31
import org.jfw.apt.orm.annotation.dao.param.Like;
31
import org.jfw.apt.orm.annotation.dao.param.Like;
32
import org.jfw.apt.orm.annotation.dao.param.Set;
32
import org.jfw.apt.orm.annotation.dao.param.Set;
33
import org.jfw.apt.orm.annotation.dao.param.SqlColumn;
34
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
33
import org.jfw.util.PageQueryResult;
35
import org.jfw.util.PageQueryResult;
34

36

35
import com.ekexiu.portal.po.Article;
37
import com.ekexiu.portal.po.Article;
36
import com.ekexiu.portal.pojo.FindInfo;
37
import com.ekexiu.portal.pojo.SelfArticle;
38
import com.ekexiu.portal.pojo.SelfArticle;
38

39

39
@DAO
40
@DAO
40
public abstract class ArticleDao {
41
public abstract class ArticleDao {
41
	@Insert
42
	@Insert
42
	public abstract int insert(Connection con, Article article) throws SQLException;
43
	public abstract int insert(Connection con, Article article) throws SQLException;
43
	
44

44
	@Update
45
	@Update
45
	@Dynamic
46
	@Dynamic
46
	public abstract int update(Connection con, Article article) throws SQLException;
47
	public abstract int update(Connection con, Article article) throws SQLException;
47
	
48

48
	@UpdateWith
49
	@UpdateWith
49
	@From(Article.class)
50
	@From(Article.class)
50
	@SetSentence("PAGE_VIEWS = PAGE_VIEWS + 1")
51
	@SetSentence("PAGE_VIEWS = PAGE_VIEWS + 1")
51
	public abstract int incPageViews(Connection con,String articleId) throws SQLException;
52
	
52
	public abstract int incPageViews(Connection con, String articleId) throws SQLException;
53

53
	@UpdateWith
54
	@UpdateWith
54
	@From(Article.class)
55
	@From(Article.class)
55
	public abstract int updateStatus(Connection con,String articleId,@Set String status) throws SQLException;
56
	
56
	public abstract int updateStatus(Connection con, String articleId, @Set String status) throws SQLException;
57

57
	@UpdateWith
58
	@UpdateWith
58
	@From(Article.class)
59
	@From(Article.class)
59
	public abstract int updatePublishTime(Connection con,String articleId,@Set String status,@Set String publishTime) throws SQLException;
60
	
60
	public abstract int updatePublishTime(Connection con, String articleId, @Set String status, @Set String publishTime) throws SQLException;
61

61
	@UpdateWith
62
	@UpdateWith
62
	@From(Article.class)
63
	@From(Article.class)
63
	@SetSentence("ARTICLE_AGREE = ARTICLE_AGREE + 1")
64
	@SetSentence("ARTICLE_AGREE = ARTICLE_AGREE + 1")
64
	public abstract int incAgree(Connection con,String articleId) throws SQLException;
65
	
65
	public abstract int incAgree(Connection con, String articleId) throws SQLException;
66

66
	@UpdateWith
67
	@UpdateWith
67
	@From(Article.class)
68
	@From(Article.class)
68
	@SetSentence("ARTICLE_AGREE = ARTICLE_AGREE - 1")
69
	@SetSentence("ARTICLE_AGREE = ARTICLE_AGREE - 1")
69
	public abstract int decAgree(Connection con,String articleId) throws SQLException;
70
	
70
	public abstract int decAgree(Connection con, String articleId) throws SQLException;
71

71
	@UpdateWith
72
	@UpdateWith
72
	@From(Article.class)
73
	@From(Article.class)
73
	public abstract int updateSubject(Connection con, @Set String subject, String articleId) throws SQLException;
74
	public abstract int updateSubject(Connection con, @Set String subject, String articleId) throws SQLException;
74
	
75

75
	@UpdateWith
76
	@UpdateWith
76
	@From(Article.class)
77
	@From(Article.class)
77
	public abstract int updateIndustry(Connection con, @Set String industry, String articleId) throws SQLException;
78
	public abstract int updateIndustry(Connection con, @Set String industry, String articleId) throws SQLException;
78
	
79

79
	@DeleteWith
80
	@DeleteWith
80
	@From(Article.class)
81
	@From(Article.class)
81
	public abstract int delete(Connection con, String articleId) throws SQLException;
82
	public abstract int delete(Connection con, String articleId) throws SQLException;
82
	
83

83
	@DeleteWith
84
	@DeleteWith
84
	@From(Article.class)
85
	@From(Article.class)
85
	public abstract int deletePro(Connection con, String professorId) throws SQLException;
86
	public abstract int deletePro(Connection con, String professorId) throws SQLException;
86
	
87

87
	@Exclude("articleContent")
88
	@Exclude("articleContent")
88
	@SelectList
89
	@SelectList
89
	@Where("STATUS = '2'")
90
	@Where("STATUS = '2'")
90
	public abstract List<Article> queryTiming(Connection con, @LessThan String publishTime) throws SQLException;
91
	public abstract List<Article> queryTiming(Connection con, @LessThan String publishTime) throws SQLException;
91
	
92

92
	@Exclude("articleContent")
93
	@Exclude("articleContent")
93
	@SelectList
94
	@SelectList
94
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
95
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
95
	public abstract List<Article> queryPro(Connection con, String professorId) throws SQLException;
96
	public abstract List<Article> queryPro(Connection con, String professorId) throws SQLException;
96
	
97

97
	@Exclude("articleContent")
98
	@Exclude("articleContent")
98
	@SelectList
99
	@SelectList
99
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
100
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
100
	@Where("STATUS = '1'")
101
	@Where("STATUS = '1'")
101
	public abstract List<Article> queryProPublish(Connection con, String professorId) throws SQLException;
102
	public abstract List<Article> queryProPublish(Connection con, String professorId) throws SQLException;
102
	
103

103
	@Exclude("articleContent")
104
	@Exclude("articleContent")
104
	@PageSelect
105
	@PageSelect
105
	@OrderBy(" ORDER BY PUBLISH_TIME DESC,SHARE_ID ASC")
106
	@OrderBy(" ORDER BY PUBLISH_TIME DESC,SHARE_ID ASC")
106
	@Where("STATUS = '1'")
107
	@Where("STATUS = '1'")
107
	public abstract PageQueryResult<Article> pageQueryProPublish(Connection con, String professorId,int pageSize,int pageNo) throws SQLException;
108
	
108
	public abstract PageQueryResult<Article> pageQueryProPublish(Connection con, String professorId, int pageSize, int pageNo) throws SQLException;
109

109
	@Exclude("articleContent")
110
	@Exclude("articleContent")
110
	@SelectList
111
	@SelectList
111
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
112
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
112
	@Where("STATUS IN ('0','1','2')")
113
	@Where("STATUS IN ('0','1','2')")
113
	public abstract List<Article> queryForDesk(Connection con, String professorId) throws SQLException;
114
	public abstract List<Article> queryForDesk(Connection con, String professorId) throws SQLException;
114
	
115

115
	@Exclude("articleContent")
116
	@Exclude("articleContent")
116
	@SelectList
117
	@SelectList
117
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
118
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
118
	public abstract List<Article> queryOrg(Connection con, String orgId) throws SQLException;
119
	public abstract List<Article> queryOrg(Connection con, String orgId) throws SQLException;
119
	
120
	
120

121
	@Exclude("articleContent")
121
	@Exclude("articleContent")
122
	@SelectList
122
	@SelectList
123
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
123
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
124
	@Where("STATUS = '1'")
124
	@Where("STATUS = '1'")
125
	public abstract List<Article> queryOrgPublish(Connection con, String orgId) throws SQLException;
125
	public abstract List<Article> queryOrgPublish(Connection con, String orgId) throws SQLException;
126
	
126

127
	@Exclude("articleContent")
127
	@Exclude("articleContent")
128
	@PageSelect
128
	@PageSelect
129
	@OrderBy(" ORDER BY PUBLISH_TIME DESC,SHARE_ID ASC")
129
	@OrderBy(" ORDER BY PUBLISH_TIME DESC,SHARE_ID ASC")
130
	@Where("STATUS = '1'")
130
	@Where("STATUS = '1'")
131
	public abstract PageQueryResult<Article> pageQueryOrgPublish(Connection con, String orgId,int pageSize,int pageNo) throws SQLException;
131
	public abstract PageQueryResult<Article> pageQueryOrgPublish(Connection con, String orgId, int pageSize, int pageNo) throws SQLException;
132

132
	@Exclude("articleContent")
133
	@Exclude("articleContent")
133
	@LimitSelect
134
	@LimitSelect
134
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
135
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
135
	public abstract List<Article> queryLimit(Connection con,String orgId,@LessThan String modifyTime,int rows)throws SQLException;
136
	
136
	public abstract List<Article> queryLimit(Connection con, String orgId, @LessThan String modifyTime, int rows) throws SQLException;
137

137
	@SelectOne
138
	@SelectOne
138
	@Nullable
139
	@Nullable
139
	public abstract Article queryOne(Connection con, String articleId) throws SQLException;
140
	public abstract Article queryOne(Connection con, String articleId) throws SQLException;
140
	
141

141

142
	public List<Article> queryByPageViews(Connection con,String articleId,int rows)throws SQLException{
142
	public List<Article> queryByPageViews(Connection con, String articleId, int rows) throws SQLException {
143
		int index = 1;
143
		int index = 1;
144
		boolean hasArticleId = null != articleId;
144
		boolean hasArticleId = null != articleId;
145
		StringBuilder sql = new StringBuilder();
145
		StringBuilder sql = new StringBuilder();
146
		sql.append("SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE");
146
		sql.append(
147
				"SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE");
147
		sql.append(" WHERE STATUS = '1'");
148
		sql.append(" WHERE STATUS = '1'");
148
		if(hasArticleId){
149
		if (hasArticleId) {
149
			sql.append(" AND ARTICLE_ID != ?");
150
			sql.append(" AND ARTICLE_ID != ?");
150
		}
151
		}
151
		sql.append(" ORDER BY PAGE_VIEWS DESC");
152
		sql.append(" ORDER BY PAGE_VIEWS DESC");
152
        sql.append(" LIMIT ").append(rows);
153
		sql.append(" LIMIT ").append(rows);
153
		PreparedStatement ps = con.prepareStatement(sql.toString());
154
		PreparedStatement ps = con.prepareStatement(sql.toString());
154
		try{
155
			if(hasArticleId){
155
		try {
156
			if (hasArticleId) {
156
				ps.setString(index++, articleId);
157
				ps.setString(index++, articleId);
157
			}
158
			}
158
			ResultSet rs = ps.executeQuery();
159
			ResultSet rs = ps.executeQuery();
159
			try{
160
			try {
160
				List<Article> articles = new ArrayList<Article>();
161
				List<Article> articles = new ArrayList<Article>();
161
				while(rs.next()){
162
				while (rs.next()) {
162
					Article article = new Article();
163
					Article article = new Article();
163
					article.setArticleId(rs.getString(1));
164
					article.setArticleId(rs.getString(1));
164
                    String proId = rs.getString(2);
165
                    if(rs.wasNull()){
166
                    	proId = null;
167
                    }
168
                    article.setProfessorId(proId);
169
                    article.setArticleTitle(rs.getString(3));
170
                    String articleContent = rs.getString(4);
171
                    if(rs.wasNull()){
172
                    	articleContent = null;
173
                    }
174
                    article.setArticleContent(articleContent);
175
                    String subject = rs.getString(5);
176
                    if(rs.wasNull()){
177
                    	subject = null;
178
                    }
179
                    article.setSubject(subject);
180
                    String publishTime = rs.getString(6);
181
                    if(rs.wasNull()){
182
                    	publishTime = null;
183
                    }
184
                    article.setPublishTime(publishTime);
185
                    String articleImg = rs.getString(7);
186
                    if(rs.wasNull()){
187
                    	articleImg = null;
188
                    }
189
                    article.setArticleImg(articleImg);
190
                    String org = rs.getString(8);
191
                    if(rs.wasNull()){
192
                    	org = null;
193
                    }
194
                    article.setOrgId(org);
195
                    String articleType = rs.getString(9);
196
                    if(rs.wasNull()){
197
                    	articleType = null;
198
                    }
199
                    article.setArticleType(articleType);
200
                    article.setArticleAgree(rs.getInt(10));
201
                    article.setPageViews(rs.getInt(11));
202
                    String status = rs.getString(12);
203
                    if(rs.wasNull()){
204
                    	status = null;
205
                    }
206
                    article.setStatus(status);
207
                    article.setCreateTime(rs.getString(13));
208
                    article.setModifyTime(rs.getString(14));
209
                    article.setShareId(rs.getLong(15));
210
                    article.setColNum(rs.getInt(16));
165
					String proId = rs.getString(2);
166
					if (rs.wasNull()) {
167
						proId = null;
168
					}
169
					article.setProfessorId(proId);
170
					article.setArticleTitle(rs.getString(3));
171
					String articleContent = rs.getString(4);
172
					if (rs.wasNull()) {
173
						articleContent = null;
174
					}
175
					article.setArticleContent(articleContent);
176
					String subject = rs.getString(5);
177
					if (rs.wasNull()) {
178
						subject = null;
179
					}
180
					article.setSubject(subject);
181
					String publishTime = rs.getString(6);
182
					if (rs.wasNull()) {
183
						publishTime = null;
184
					}
185
					article.setPublishTime(publishTime);
186
					String articleImg = rs.getString(7);
187
					if (rs.wasNull()) {
188
						articleImg = null;
189
					}
190
					article.setArticleImg(articleImg);
191
					String org = rs.getString(8);
192
					if (rs.wasNull()) {
193
						org = null;
194
					}
195
					article.setOrgId(org);
196
					String articleType = rs.getString(9);
197
					if (rs.wasNull()) {
198
						articleType = null;
199
					}
200
					article.setArticleType(articleType);
201
					article.setArticleAgree(rs.getInt(10));
202
					article.setPageViews(rs.getInt(11));
203
					String status = rs.getString(12);
204
					if (rs.wasNull()) {
205
						status = null;
206
					}
207
					article.setStatus(status);
208
					article.setCreateTime(rs.getString(13));
209
					article.setModifyTime(rs.getString(14));
210
					article.setShareId(rs.getLong(15));
211
					article.setColNum(rs.getInt(16));
211
					articles.add(article);
212
					articles.add(article);
212
				}
213
				}
213
				return articles;
214
				return articles;
214
			}finally{
215
				try{rs.close();}catch(Exception e1){}
215
			} finally {
216
				try {
217
					rs.close();
218
				} catch (Exception e1) {
219
				}
220
			}
221
		} finally {
222
			try {
223
				ps.close();
224
			} catch (Exception e2) {
216
			}
225
			}
217
		}finally{
218
			try{ps.close();}catch(Exception e2){}
219
		}
226
		}
220
	}
227
	}
221
	
222
	public List<Article> queryByAuthor(Connection con,String professorId,String orgId,String articleId,int rows)throws SQLException{
228

229
	public List<Article> queryByAuthor(Connection con, String professorId, String orgId, String articleId, int rows) throws SQLException {
223
		int index = 1;
230
		int index = 1;
224
		boolean hasProId = null != professorId;
231
		boolean hasProId = null != professorId;
225
		boolean hasOrgId = null != orgId;
232
		boolean hasOrgId = null != orgId;
226
		boolean hasArticleId = null != articleId;
233
		boolean hasArticleId = null != articleId;
227
		StringBuilder sql = new StringBuilder();
234
		StringBuilder sql = new StringBuilder();
228
		sql.append("SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE");
235
		sql.append(
236
				"SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE");
229
		sql.append(" WHERE STATUS = '1'");
237
		sql.append(" WHERE STATUS = '1'");
230
		if(hasProId){
238
		if (hasProId) {
231
			sql.append(" AND PROFESSOR_ID = ?");
239
			sql.append(" AND PROFESSOR_ID = ?");
232
		}
240
		}
233
		if(hasOrgId){
241
		if (hasOrgId) {
234
			sql.append(" AND ORG_ID = ?");
242
			sql.append(" AND ORG_ID = ?");
235
		}
243
		}
236
		if(hasArticleId){
244
		if (hasArticleId) {
237
			sql.append(" AND ARTICLE_ID != ?");
245
			sql.append(" AND ARTICLE_ID != ?");
238
		}
246
		}
239
		sql.append(" ORDER BY PUBLISH_TIME DESC");
247
		sql.append(" ORDER BY PUBLISH_TIME DESC");
240
        sql.append(" LIMIT ").append(rows);
248
		sql.append(" LIMIT ").append(rows);
241
		PreparedStatement ps = con.prepareStatement(sql.toString());
249
		PreparedStatement ps = con.prepareStatement(sql.toString());
242
		try{
243
			if(hasProId){
250
		try {
251
			if (hasProId) {
244
				ps.setString(index++, professorId);
252
				ps.setString(index++, professorId);
245
			}
253
			}
246
			if(hasOrgId){
254
			if (hasOrgId) {
247
				ps.setString(index++, orgId);
255
				ps.setString(index++, orgId);
248
			}
256
			}
249
			if(hasArticleId){
257
			if (hasArticleId) {
250
				ps.setString(index++, articleId);
258
				ps.setString(index++, articleId);
251
			}
259
			}
252
			ResultSet rs = ps.executeQuery();
260
			ResultSet rs = ps.executeQuery();
253
			try{
261
			try {
254
				List<Article> articles = new ArrayList<Article>();
262
				List<Article> articles = new ArrayList<Article>();
255
				while(rs.next()){
263
				while (rs.next()) {
256
					Article article = new Article();
264
					Article article = new Article();
257
					article.setArticleId(rs.getString(1));
265
					article.setArticleId(rs.getString(1));
258
                    String proId = rs.getString(2);
259
                    if(rs.wasNull()){
260
                    	proId = null;
261
                    }
262
                    article.setProfessorId(proId);
263
                    article.setArticleTitle(rs.getString(3));
264
                    String articleContent = rs.getString(4);
265
                    if(rs.wasNull()){
266
                    	articleContent = null;
267
                    }
268
                    article.setArticleContent(articleContent);
269
                    String subject = rs.getString(5);
270
                    if(rs.wasNull()){
271
                    	subject = null;
272
                    }
273
                    article.setSubject(subject);
274
                    String publishTime = rs.getString(6);
275
                    if(rs.wasNull()){
276
                    	publishTime = null;
277
                    }
278
                    article.setPublishTime(publishTime);
279
                    String articleImg = rs.getString(7);
280
                    if(rs.wasNull()){
281
                    	articleImg = null;
282
                    }
283
                    article.setArticleImg(articleImg);
284
                    String org = rs.getString(8);
285
                    if(rs.wasNull()){
286
                    	org = null;
287
                    }
288
                    article.setOrgId(org);
289
                    String articleType = rs.getString(9);
290
                    if(rs.wasNull()){
291
                    	articleType = null;
292
                    }
293
                    article.setArticleType(articleType);
294
                    article.setArticleAgree(rs.getInt(10));
295
                    article.setPageViews(rs.getInt(11));
296
                    String status = rs.getString(12);
297
                    if(rs.wasNull()){
298
                    	status = null;
299
                    }
300
                    article.setStatus(status);
301
                    article.setCreateTime(rs.getString(13));
302
                    article.setModifyTime(rs.getString(14));
303
                    article.setShareId(rs.getLong(15));
304
                    article.setColNum(rs.getInt(16));
266
					String proId = rs.getString(2);
267
					if (rs.wasNull()) {
268
						proId = null;
269
					}
270
					article.setProfessorId(proId);
271
					article.setArticleTitle(rs.getString(3));
272
					String articleContent = rs.getString(4);
273
					if (rs.wasNull()) {
274
						articleContent = null;
275
					}
276
					article.setArticleContent(articleContent);
277
					String subject = rs.getString(5);
278
					if (rs.wasNull()) {
279
						subject = null;
280
					}
281
					article.setSubject(subject);
282
					String publishTime = rs.getString(6);
283
					if (rs.wasNull()) {
284
						publishTime = null;
285
					}
286
					article.setPublishTime(publishTime);
287
					String articleImg = rs.getString(7);
288
					if (rs.wasNull()) {
289
						articleImg = null;
290
					}
291
					article.setArticleImg(articleImg);
292
					String org = rs.getString(8);
293
					if (rs.wasNull()) {
294
						org = null;
295
					}
296
					article.setOrgId(org);
297
					String articleType = rs.getString(9);
298
					if (rs.wasNull()) {
299
						articleType = null;
300
					}
301
					article.setArticleType(articleType);
302
					article.setArticleAgree(rs.getInt(10));
303
					article.setPageViews(rs.getInt(11));
304
					String status = rs.getString(12);
305
					if (rs.wasNull()) {
306
						status = null;
307
					}
308
					article.setStatus(status);
309
					article.setCreateTime(rs.getString(13));
310
					article.setModifyTime(rs.getString(14));
311
					article.setShareId(rs.getLong(15));
312
					article.setColNum(rs.getInt(16));
305
					articles.add(article);
313
					articles.add(article);
306
				}
314
				}
307
				return articles;
315
				return articles;
308
			}finally{
309
				try{rs.close();}catch(Exception e1){}
316
			} finally {
317
				try {
318
					rs.close();
319
				} catch (Exception e1) {
320
				}
321
			}
322
		} finally {
323
			try {
324
				ps.close();
325
			} catch (Exception e2) {
310
			}
326
			}
311
		}finally{
312
			try{ps.close();}catch(Exception e2){}
313
		}
327
		}
314
	}
328
	}
315
	
316
	public String[] queryArticleIdWithSameKeyWord(Connection con,String id,int rows)throws SQLException{
329

330
	public String[] queryArticleIdWithSameKeyWord(Connection con, String id, int rows) throws SQLException {
317
		List<String> ret = new ArrayList<String>();
331
		List<String> ret = new ArrayList<String>();
318
		String sql = "select id,count(1) sort from art_key_word where kw in (select kw from art_key_word where id=?) and id <>? group by id order by sort desc limit ?";
332
		String sql = "select id,count(1) sort from art_key_word where kw in (select kw from art_key_word where id=?) and id <>? group by id order by sort desc limit ?";
319
		PreparedStatement ps = con.prepareStatement(sql);
333
		PreparedStatement ps = con.prepareStatement(sql);
320
		try{
334
		try {
321
			ps.setString(1, id);
335
			ps.setString(1, id);
322
			ps.setString(2, id);
336
			ps.setString(2, id);
323
			ps.setInt(3, rows);
337
			ps.setInt(3, rows);
324
			ResultSet rs = ps.executeQuery();
338
			ResultSet rs = ps.executeQuery();
325
			try{
326
				while(rs.next()){
339
			try {
340
				while (rs.next()) {
327
					ret.add(rs.getString(1));
341
					ret.add(rs.getString(1));
328
				}
342
				}
329
			}finally{
330
				try{rs.close();}catch(Exception e1){}
343
			} finally {
344
				try {
345
					rs.close();
346
				} catch (Exception e1) {
347
				}
348
			}
349
		} finally {
350
			try {
351
				ps.close();
352
			} catch (Exception e2) {
331
			}
353
			}
332
		}finally{
333
			try{ps.close();}catch(Exception e2){}
334
		}
354
		}
335
		return ret.isEmpty()?null:ret.toArray(new String[ret.size()]);		
355
		return ret.isEmpty() ? null : ret.toArray(new String[ret.size()]);
336
	}
356
	}
357

337
	@SelectList
358
	@SelectList
338
	public abstract List<Article> query(Connection con,@In String[] articleId) throws SQLException;
339
	
359
	public abstract List<Article> query(Connection con, @In String[] articleId) throws SQLException;
360

340
	@Exclude("articleContent")
361
	@Exclude("articleContent")
341
	@LimitSelect
362
	@LimitSelect
342
	@Where("STATUS ='1'")
363
	@Where("STATUS ='1'")
343
	@OrderBy("ORDER BY PAGE_VIEWS DESC")
364
	@OrderBy("ORDER BY PAGE_VIEWS DESC")
344
	public abstract List<Article> limitQueryPublish(Connection con,@In String[] articleId,int rows) throws SQLException;
345
	
365
	public abstract List<Article> limitQueryPublish(Connection con, @In String[] articleId, int rows) throws SQLException;
346

366

347
//	public List<Article> queryLimit(Connection con,String[] keys,String articleId,int rows) throws SQLException{
367
	// public List<Article> queryLimit(Connection con,String[] keys,String
368
	// articleId,int rows) throws SQLException{
369
	// int index = 1;
370
	// boolean hasKeys = null != keys;
371
	// boolean hasArticleId = null != articleId;
372
	// StringBuilder sql = new StringBuilder();
373
	// sql.append("SELECT
374
	// ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,ARTICLE_CONTENT,SUBJECT,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID
375
	// FROM ARTICLE");
376
	// sql.append(" WHERE STATUS = '1'");
377
	// if(hasArticleId){
378
	// sql.append(" AND ARTICLE_ID != ?");
379
	// }
380
	// if(hasKeys){
381
	// for (int i = 0; i < keys.length; i++) {
382
	// if(i == 0){
383
	// sql.append(" AND (SUBJECT LIKE ?");
384
	// }else{
385
	// sql.append(" OR SUBJECT LIKE ?");
386
	// }
387
	// }
388
	// sql.append(")");
389
	// }
390
	// sql.append(" ORDER BY PUBLISH_TIME DESC");
391
	// sql.append(" LIMIT ").append(rows);
392
	// PreparedStatement ps = con.prepareStatement(sql.toString());
393
	// try{
394
	// if(hasArticleId){
395
	// ps.setString(index++, articleId);
396
	// }
397
	// if(hasKeys){
398
	// for (String key : keys) {
399
	// ps.setString(index++, "%"+key+"%");
400
	// }
401
	// }
402
	// ResultSet rs = ps.executeQuery();
403
	// try{
404
	// List<Article> articles = new ArrayList<Article>();
405
	// while(rs.next()){
406
	// Article article = new Article();
407
	// article.setArticleId(rs.getString(1));
408
	// String proId = rs.getString(2);
409
	// if(rs.wasNull()){
410
	// proId = null;
411
	// }
412
	// article.setProfessorId(proId);
413
	// article.setArticleTitle(rs.getString(3));
414
	// String articleContent = rs.getString(4);
415
	// if(rs.wasNull()){
416
	// articleContent = null;
417
	// }
418
	// article.setArticleContent(articleContent);
419
	// String subject = rs.getString(5);
420
	// if(rs.wasNull()){
421
	// subject = null;
422
	// }
423
	// article.setSubject(subject);
424
	// String publishTime = rs.getString(6);
425
	// if(rs.wasNull()){
426
	// publishTime = null;
427
	// }
428
	// article.setPublishTime(publishTime);
429
	// String articleImg = rs.getString(7);
430
	// if(rs.wasNull()){
431
	// articleImg = null;
432
	// }
433
	// article.setArticleImg(articleImg);
434
	// String org = rs.getString(8);
435
	// if(rs.wasNull()){
436
	// org = null;
437
	// }
438
	// article.setOrgId(org);
439
	// String articleType = rs.getString(9);
440
	// if(rs.wasNull()){
441
	// articleType = null;
442
	// }
443
	// article.setArticleType(articleType);
444
	// article.setArticleAgree(rs.getInt(10));
445
	// article.setPageViews(rs.getInt(11));
446
	// String status = rs.getString(12);
447
	// if(rs.wasNull()){
448
	// status = null;
449
	// }
450
	// article.setStatus(status);
451
	// article.setCreateTime(rs.getString(13));
452
	// article.setModifyTime(rs.getString(14));
453
	// article.setShareId(rs.getLong(15));
454
	// articles.add(article);
455
	// }
456
	// return articles;
457
	// }finally{
458
	// try{rs.close();}catch(Exception e1){}
459
	// }
460
	// }finally{
461
	// try{ps.close();}catch(Exception e2) {}
462
	// }
463
	// }
464
	//
465

466
	@Exclude("articleContent")
467
	@PageSelect
468
	@OrderBy("ORDER BY PUBLISH_TIME DESC")
469
	@Where("STATUS = '1'")
470
	public abstract PageQueryResult<Article> queryPageForPublish(Connection con, @Like @Nullable String articleTitle, int pageSize, int pageNo)
471
			throws SQLException;
472

473
	@Exclude("articleContent")
474
	@PageSelect
475
	@OrderBy(" ORDER BY SORT_NUM DESC, PUBLISH_TIME DESC")
476
	@Or
477
	public abstract PageQueryResult<Article> firstPageQuery(Connection con,
478
			@SqlColumn(handlerClass = StringHandler.class, value = { " (PROFESSOR_ID IN (SELECT ID FROM PROFESSOR WHERE NAME LIKE ?) AND STATUS = '1')",
479
					" (ORG_ID IN (SELECT ID FROM ORGANIZATION WHERE NAME LIKE ?) AND STATUS = '1')",
480
					" (ORG_ID IN (SELECT ID FROM ORGANIZATION WHEREFOR_SHORT LIKE ?) AND STATUS = '1')", "(ARTICLE_TITLE LIKE ?  AND STATUS = '1')",
481
					"(SUBJECT LIKE ?  AND STATUS = '1')" }) @Nullable String key,
482
			int pageSize, int pageNo) throws SQLException;
483

484
//	public PageQueryResult<Article> firstPageQuery(Connection con, String key, int pageSize, int pageNo) throws SQLException {
485
//		int total = 0;
486
//		PageQueryResult<Article> queryResult = new PageQueryResult<Article>();
348
//		int index = 1;
487
//		int index = 1;
349
//		boolean hasKeys = null != keys;
350
//		boolean hasArticleId = null != articleId;
488
//		boolean hasKey = null != key;
351
//		StringBuilder sql = new StringBuilder();
489
//		StringBuilder sql = new StringBuilder();
352
//		sql.append("SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,ARTICLE_CONTENT,SUBJECT,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID FROM ARTICLE");
353
//		sql.append(" WHERE STATUS = '1'");
490
//		sql.append(" WHERE STATUS = '1'");
354
//		if(hasArticleId){
355
//			sql.append(" AND ARTICLE_ID != ?");
356
//		}
357
//		if(hasKeys){
358
//			for (int i = 0; i < keys.length; i++) {
359
//        		if(i == 0){
360
//        			sql.append(" AND (SUBJECT LIKE ?");
361
//        		}else{
362
//        			sql.append(" OR SUBJECT LIKE ?");
363
//        		}
364
//			}
365
//        	sql.append(")");
491
//		if (hasKey) {
492
//			sql.append(" AND (PROFESSOR_ID IN (SELECT ID FROM PROFESSOR WHERE NAME LIKE ?)");
493
//			sql.append(" OR ORG_ID IN (SELECT ID FROM ORGANIZATION WHERE NAME LIKE ? OR FOR_SHORT LIKE ?)");
494
//			sql.append(" OR ARTICLE_TITLE LIKE ? OR SUBJECT LIKE ?)");
366
//		}
495
//		}
367
//		sql.append(" ORDER BY PUBLISH_TIME DESC");
368
//        sql.append(" LIMIT ").append(rows);
496
//		StringBuilder whereSql = sql;
497
//		sql = new StringBuilder();
498
//		sql.append("SELECT COUNT(1) FROM ARTICLE");
499
//		sql.append(whereSql);
369
//		PreparedStatement ps = con.prepareStatement(sql.toString());
500
//		PreparedStatement ps = con.prepareStatement(sql.toString());
370
//		try{
371
//			if(hasArticleId){
372
//				ps.setString(index++, articleId);
501
//		try {
502
//			if (hasKey) {
503
//				ps.setString(index++, key);
504
//				ps.setString(index++, key);
505
//				ps.setString(index++, key);
506
//				ps.setString(index++, key);
507
//				ps.setString(index++, key);
373
//			}
508
//			}
374
//			if(hasKeys){
375
//        		for (String key : keys) {
376
//        			ps.setString(index++, "%"+key+"%");
509
//			queryResult.setPageSize(pageSize);
510
//			ResultSet rs = ps.executeQuery();
511
//			try {
512
//				rs.next();
513
//				total = rs.getInt(1);
514
//			} finally {
515
//				try {
516
//					rs.close();
517
//				} catch (Exception e1) {
377
//				}
518
//				}
378
//        	}
519
//			}
520
//		} finally {
521
//			try {
522
//				ps.close();
523
//			} catch (Exception e2) {
524
//			}
525
//		}
526
//		queryResult.setTotal(total);
527
//		if (0 == total) {
528
//			queryResult.setPageNo(1);
529
//			queryResult.setData(Collections.<Article> emptyList());
530
//			return queryResult;
531
//		}
532
//		index = 1;
533
//		boolean firstPage = (1 == pageNo);
534
//		if (firstPage) {
535
//			queryResult.setPageNo(1);
536
//			sql = new StringBuilder();
537
//			sql.append(
538
//					"SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE");
539
//			sql.append(whereSql);
540
//			sql.append(" ORDER BY SORT_NUM DESC, PUBLISH_TIME DESC");
541
//			sql.append(" LIMIT ").append(pageSize);
542
//		} else {
543
//			int pageNum = total / pageSize;
544
//			if (total % pageSize != 0) {
545
//				++pageNum;
546
//			}
547
//			if (pageNo > pageNum) {
548
//				pageNo = pageNum;
549
//			}
550
//			queryResult.setPageNo(pageNo);
551
//			--pageNo;
552
//			int offset = (pageNo * pageSize);
553
//			sql = new StringBuilder();
554
//			sql.append(
555
//					"SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE");
556
//			sql.append(whereSql);
557
//			sql.append(" ORDER BY SORT_NUM DESC,PUBLISH_TIME DESC");
558
//			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
559
//		}
560
//		ps = con.prepareStatement(sql.toString());
561
//		try {
562
//			if (hasKey) {
563
//				ps.setString(index++, key);
564
//				ps.setString(index++, key);
565
//				ps.setString(index++, key);
566
//				ps.setString(index++, key);
567
//				ps.setString(index++, key);
568
//			}
379
//			ResultSet rs = ps.executeQuery();
569
//			ResultSet rs = ps.executeQuery();
380
//			try{
570
//			try {
381
//				List<Article> articles = new ArrayList<Article>();
571
//				List<Article> articles = new ArrayList<Article>();
382
//				while(rs.next()){
572
//				queryResult.setData(articles);
573
//				int size = 0;
574
//				while ((size < pageSize) && rs.next()) {
575
//					++size;
383
//					Article article = new Article();
576
//					Article article = new Article();
384
//					article.setArticleId(rs.getString(1));
577
//					article.setArticleId(rs.getString(1));
385
//                    String proId = rs.getString(2);
386
//                    if(rs.wasNull()){
387
//                    	proId = null;
388
//                    }
389
//                    article.setProfessorId(proId);
390
//                    article.setArticleTitle(rs.getString(3));
391
//                    String articleContent = rs.getString(4);
392
//                    if(rs.wasNull()){
393
//                    	articleContent = null;
394
//                    }
395
//                    article.setArticleContent(articleContent);
396
//                    String subject = rs.getString(5);
397
//                    if(rs.wasNull()){
398
//                    	subject = null;
399
//                    }
400
//                    article.setSubject(subject);
401
//                    String publishTime = rs.getString(6);
402
//                    if(rs.wasNull()){
403
//                    	publishTime = null;
404
//                    }
405
//                    article.setPublishTime(publishTime);
406
//                    String articleImg = rs.getString(7);
407
//                    if(rs.wasNull()){
408
//                    	articleImg = null;
409
//                    }
410
//                    article.setArticleImg(articleImg);
411
//                    String org = rs.getString(8);
412
//                    if(rs.wasNull()){
413
//                    	org = null;
414
//                    }
415
//                    article.setOrgId(org);
416
//                    String articleType = rs.getString(9);
417
//                    if(rs.wasNull()){
418
//                    	articleType = null;
419
//                    }
420
//                    article.setArticleType(articleType);
421
//                    article.setArticleAgree(rs.getInt(10));
422
//                    article.setPageViews(rs.getInt(11));
423
//                    String status = rs.getString(12);
424
//                    if(rs.wasNull()){
425
//                    	status = null;
426
//                    }
427
//                    article.setStatus(status);
428
//                    article.setCreateTime(rs.getString(13));
429
//                    article.setModifyTime(rs.getString(14));
430
//                    article.setShareId(rs.getLong(15));
578
//					String professorId = rs.getString(2);
579
//					if (rs.wasNull()) {
580
//						professorId = null;
581
//					}
582
//					article.setProfessorId(professorId);
583
//					article.setArticleTitle(rs.getString(3));
584
//					String articleContent = rs.getString(4);
585
//					if (rs.wasNull()) {
586
//						articleContent = null;
587
//					}
588
//					article.setArticleContent(articleContent);
589
//					String subject = rs.getString(5);
590
//					if (rs.wasNull()) {
591
//						subject = null;
592
//					}
593
//					article.setSubject(subject);
594
//					String industry = rs.getString(6);
595
//					if (rs.wasNull()) {
596
//						industry = null;
597
//					}
598
//					article.setIndustry(industry);
599
//					String publishTime = rs.getString(7);
600
//					if (rs.wasNull()) {
601
//						publishTime = null;
602
//					}
603
//					article.setPublishTime(publishTime);
604
//					String articleImg = rs.getString(8);
605
//					if (rs.wasNull()) {
606
//						articleImg = null;
607
//					}
608
//					article.setArticleImg(articleImg);
609
//					String orgId = rs.getString(9);
610
//					if (rs.wasNull()) {
611
//						orgId = null;
612
//					}
613
//					article.setOrgId(orgId);
614
//					String articleType = rs.getString(10);
615
//					if (rs.wasNull()) {
616
//						articleType = null;
617
//					}
618
//					article.setArticleType(articleType);
619
//					article.setArticleAgree(rs.getInt(11));
620
//					article.setPageViews(rs.getInt(12));
621
//					String status = rs.getString(13);
622
//					if (rs.wasNull()) {
623
//						status = null;
624
//					}
625
//					article.setStatus(status);
626
//					article.setCreateTime(rs.getString(14));
627
//					article.setModifyTime(rs.getString(15));
628
//					article.setShareId(rs.getLong(16));
629
//					article.setColNum(rs.getInt(17));
431
//					articles.add(article);
630
//					articles.add(article);
432
//				}
631
//				}
433
//				return articles;
434
//			}finally{
435
//				try{rs.close();}catch(Exception e1){}
632
//				return queryResult;
633
//			} finally {
634
//				try {
635
//					rs.close();
636
//				} catch (Exception e3) {
637
//				}
638
//			}
639
//		} finally {
640
//			try {
641
//				ps.close();
642
//			} catch (Exception e4) {
436
//			}
643
//			}
437
//		}finally{
438
//			try{ps.close();}catch(Exception e2) {}
439
//		}
644
//		}
440
//	}
645
//	}
441
//	
442
	
443
	@Exclude("articleContent")
444
	@PageSelect
445
	@OrderBy("ORDER BY PUBLISH_TIME DESC")
446
	@Where("STATUS = '1'")
447
	public abstract PageQueryResult<Article> queryPageForPublish(Connection con,@Like@Nullable String articleTitle,int pageSize,int pageNo) throws SQLException;
448
	
449
	public PageQueryResult<Article> firstPageQuery(Connection con,String key,int pageSize,int pageNo) throws SQLException{
450
        int total = 0;
451
        PageQueryResult<Article> queryResult = new PageQueryResult<Article>();
452
        int index = 1;
453
        boolean hasKey = null != key;
454
        StringBuilder sql = new StringBuilder();
455
        sql.append(" WHERE STATUS = '1'");
456
        if(hasKey){
457
            sql.append(" AND (PROFESSOR_ID IN (SELECT ID FROM PROFESSOR WHERE NAME LIKE ?)");
458
            sql.append(" OR ORG_ID IN (SELECT ID FROM ORGANIZATION WHERE NAME LIKE ? OR FOR_SHORT LIKE ?)");
459
            sql.append(" OR ARTICLE_TITLE LIKE ? OR SUBJECT LIKE ?)");
460
        }
461
        StringBuilder whereSql = sql;
462
        sql = new StringBuilder();
463
        sql.append("SELECT COUNT(1) FROM ARTICLE");
464
        sql.append(whereSql);
465
        PreparedStatement ps = con.prepareStatement(sql.toString());
466
        try{
467
            if(hasKey){
468
                ps.setString(index++,key);
469
                ps.setString(index++,key);
470
                ps.setString(index++,key);
471
                ps.setString(index++,key);
472
                ps.setString(index++,key);
473
            }
474
            queryResult.setPageSize(pageSize);
475
            ResultSet rs = ps.executeQuery();
476
            try{
477
                rs.next();
478
                total = rs.getInt(1);
479
            }finally{
480
                try{rs.close();}catch(Exception e1){}
481
            }
482
        }finally{
483
            try{ps.close();}catch(Exception e2){}
484
        }
485
        queryResult.setTotal(total);
486
        if(0== total){
487
            queryResult.setPageNo(1);
488
            queryResult.setData(Collections.<Article>emptyList());
489
            return queryResult;
490
        }
491
        index = 1;
492
        boolean firstPage = (1 == pageNo);
493
        if(firstPage){
494
            queryResult.setPageNo(1);
495
            sql = new StringBuilder();
496
            sql.append("SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE");
497
            sql.append(whereSql);
498
            sql.append(" ORDER BY SORT_NUM DESC, PUBLISH_TIME DESC");
499
            sql.append(" LIMIT ").append(pageSize);
500
        }else{
501
            int pageNum = total / pageSize;
502
            if(total % pageSize != 0){
503
                ++pageNum;
504
            }
505
            if(pageNo > pageNum){
506
                pageNo = pageNum;
507
            }
508
            queryResult.setPageNo(pageNo);
509
            --pageNo;
510
            int offset = (pageNo * pageSize);
511
            sql = new StringBuilder();
512
            sql.append("SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,'',SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME,SHARE_ID,COL_NUM FROM ARTICLE");
513
            sql.append(whereSql);
514
            sql.append(" ORDER BY SORT_NUM DESC,PUBLISH_TIME DESC");
515
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
516
        }
517
        ps = con.prepareStatement(sql.toString());
518
        try{
519
            if(hasKey){
520
                ps.setString(index++,key);
521
                ps.setString(index++,key);
522
                ps.setString(index++,key);
523
                ps.setString(index++,key);
524
                ps.setString(index++,key);
525
            }
526
            ResultSet rs = ps.executeQuery();
527
            try{
528
                List<Article> articles = new ArrayList<Article>();
529
                queryResult.setData(articles);
530
                int size = 0;
531
                while((size<pageSize) && rs.next()){
532
                    ++size;
533
                    Article article =  new Article();
534
                    article.setArticleId(rs.getString(1));
535
                    String professorId = rs.getString(2);
536
                    if(rs.wasNull()){
537
                    	professorId = null;
538
                    }
539
                    article.setProfessorId(professorId);
540
                    article.setArticleTitle(rs.getString(3));
541
                    String articleContent = rs.getString(4);
542
                    if(rs.wasNull()){
543
                    	articleContent = null;
544
                    }
545
                    article.setArticleContent(articleContent);
546
                    String subject = rs.getString(5);
547
                    if(rs.wasNull()){
548
                    	subject = null;
549
                    }
550
                    article.setSubject(subject);
551
                    String industry = rs.getString(6);
552
                    if(rs.wasNull()){
553
                    	industry = null;
554
                    }
555
                    article.setIndustry(industry);
556
                    String publishTime = rs.getString(7);
557
                    if(rs.wasNull()){
558
                    	publishTime = null;
559
                    }
560
                    article.setPublishTime(publishTime);
561
                    String articleImg = rs.getString(8);
562
                    if(rs.wasNull()){
563
                    	articleImg = null;
564
                    }
565
                    article.setArticleImg(articleImg);
566
                    String orgId = rs.getString(9);
567
                    if(rs.wasNull()){
568
                    	orgId = null;
569
                    }
570
                    article.setOrgId(orgId);
571
                    String articleType = rs.getString(10);
572
                    if(rs.wasNull()){
573
                    	articleType = null;
574
                    }
575
                    article.setArticleType(articleType);
576
                    article.setArticleAgree(rs.getInt(11));
577
                    article.setPageViews(rs.getInt(12));
578
                    String status = rs.getString(13);
579
                    if(rs.wasNull()){
580
                    	status = null;
581
                    }
582
                    article.setStatus(status);
583
                    article.setCreateTime(rs.getString(14));
584
                    article.setModifyTime(rs.getString(15));
585
                    article.setShareId(rs.getLong(16));
586
                    article.setColNum(rs.getInt(17));
587
                    articles.add(article);
588
                }
589
                return queryResult;
590
            }finally{
591
                try{rs.close();}catch(Exception e3){}
592
            }
593
        }finally{
594
            try{ps.close();}catch(Exception e4){}
595
        }
596
    }
597
	
598
	
646

599
	@PageQuery
647
	@PageQuery
600
	@Exclude("articleContent")
648
	@Exclude("articleContent")
601
	@OrderBy(" ORDER BY selfOrderField DESC,SHARE_ID ASC ")
649
	@OrderBy(" ORDER BY selfOrderField DESC,SHARE_ID ASC ")
602
	@Where("STATUS IN ('1','0','2')")
650
	@Where("STATUS IN ('1','0','2')")
603
	public abstract PageQueryResult<SelfArticle> queryPageForSelf(Connection con,@Nullable String professorId,@Nullable String orgId,
604
		@Like	@Nullable String articleTitle,int pageSize,int pageNo) throws SQLException;
605

606
	public PageQueryResult<FindInfo> queryPage(Connection con,int pageSize,int pageNo) throws SQLException{
607
        int total = 0;
608
        PageQueryResult<FindInfo> queryResult = new PageQueryResult<FindInfo>();
609
        String sql = null;
610
        sql = "SELECT SUM(NUM) FROM (SELECT COUNT(1) NUM FROM ARTICLE UNION ALL SELECT COUNT(1) NUM FROM RESOURCE) TBL";
611
        PreparedStatement ps = con.prepareStatement(sql);
612
        try{
613
        	queryResult.setPageSize(pageSize);
614
            ResultSet rs = ps.executeQuery();
615
            try{
616
                rs.next();
617
                total = rs.getInt(1);
618
            }finally{
619
                try{rs.close();}catch(Exception e1){}
620
            }
621
        }finally{
622
            try{ps.close();}catch(Exception e2){}
623
        }
624
        queryResult.setTotal(total);
625
        if(0== total){
626
        	queryResult.setPageNo(1);
627
        	queryResult.setData(Collections.<FindInfo>emptyList());
628
            return queryResult;
629
        }
630
        boolean firstPage = (1 == pageNo);
631
        if(firstPage){
632
        	queryResult.setPageNo(1);
633
        	sql = "SELECT ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,CREATE_TIME,ORG_ID,PROFESSOR_ID FROM ARTICLE"
634
                	+ " UNION ALL SELECT RESOURCE_ID,RESOURCE_NAME,NULL,'3',CREATE_TIME,NULL,PROFESSOR_ID FROM RESOURCE";
635
            sql = sql + " ORDER BY CREATE_TIME DESC ";
636
            sql = sql + " LIMIT " + pageSize;
637
        }else{
638
            int pageNum = total / pageSize;
639
            if(total % pageSize != 0){
640
                ++pageNum;
641
            }
642
            if(pageNo > pageNum){
643
                pageNo = pageNum;
644
            }
645
            queryResult.setPageNo(pageNo);
646
            --pageNo;
647
            int offset = (pageNo * pageSize);
648
            sql = "SELECT ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,CREATE_TIME,ORG_ID,PROFESSOR_ID FROM ARTICLE"
649
                	+ " UNION ALL SELECT RESOURCE_ID,RESOURCE_NAME,NULL,'3',CREATE_TIME,NULL,PROFESSOR_ID FROM RESOURCE";
650
            sql = sql + " ORDER BY CREATE_TIME DESC ";
651
            sql = sql + " LIMIT " + pageSize+ " OFFSET " + offset;
652
        }
653
        ps = con.prepareStatement(sql);
654
        try{
655
            ResultSet rs = ps.executeQuery();
656
            try{
657
                List<FindInfo> findInfos = new ArrayList<FindInfo>();
658
                queryResult.setData(findInfos);
659
                int size = 0;
660
                while((size<pageSize) && rs.next()){
661
                    ++size;
662
                    FindInfo findInfo =  new FindInfo();
663
                    findInfo.setId(rs.getString(1));
664
                    findInfo.setName(rs.getString(2));
665
                    String image = rs.getString(3);
666
                    if(rs.wasNull()){
667
                    	image = null;
668
                    }
669
                    findInfo.setImage(image);
670
                    findInfo.setType(rs.getString(4));
671
                    findInfo.setCreateTime(rs.getString(5));
672
                    String orgId = rs.getString(6);
673
                    if(rs.wasNull()){
674
                    	findInfo.setOwner(rs.getString(7));
675
                    }else{
676
                    	findInfo.setOwner(orgId);
677
                    }
678
                    findInfos.add(findInfo);
679
                }
680
                return queryResult;
681
            }finally{
682
                try{rs.close();}catch(Exception e3){}
683
            }
684
        }finally{
685
            try{ps.close();}catch(Exception e4){}
686
        }
687
    }
688
	
689
	public PageQueryResult<FindInfo> queryFindHot(Connection con,int pageSize,int pageNo) throws SQLException{
690
        int total = 0;
691
        PageQueryResult<FindInfo> queryResult = new PageQueryResult<FindInfo>();
692
        String sql = null;
693
        sql = "SELECT SUM(NUM) FROM ((SELECT COUNT(1) NUM FROM ARTICLE WHERE STATUS = '1') UNION ALL (SELECT COUNT(1) NUM FROM RESOURCE WHERE STATUS = '1')) TBL";
694
        PreparedStatement ps = con.prepareStatement(sql);
695
        try{
696
        	queryResult.setPageSize(pageSize);
697
            ResultSet rs = ps.executeQuery();
698
            try{
699
                rs.next();
700
                total = rs.getInt(1);
701
            }finally{
702
                try{rs.close();}catch(Exception e1){}
703
            }
704
        }finally{
705
            try{ps.close();}catch(Exception e2){}
706
        }
707
        queryResult.setTotal(total);
708
        if(0== total){
709
        	queryResult.setPageNo(1);
710
        	queryResult.setData(Collections.<FindInfo>emptyList());
711
            return queryResult;
712
        }
713
        boolean firstPage = (1 == pageNo);
714
        if(firstPage){
715
        	queryResult.setPageNo(1);
716
        	sql = "(SELECT ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,PUBLISH_TIME,ORG_ID,PROFESSOR_ID FROM ARTICLE WHERE STATUS = '1')"
717
                + " UNION ALL (SELECT RESOURCE_ID,RESOURCE_NAME,NULL,CASE WHEN RESOURCE_TYPE = '1' THEN '3' WHEN RESOURCE_TYPE = '2' THEN '4' ELSE NULL END,"
718
                + " PUBLISH_TIME,ORG_ID,PROFESSOR_ID FROM RESOURCE WHERE STATUS = '1')";
719
            sql = sql + " ORDER BY PUBLISH_TIME DESC ";
720
            sql = sql + " LIMIT " + pageSize;
721
        }else{
722
            int pageNum = total / pageSize;
723
            if(total % pageSize != 0){
724
                ++pageNum;
725
            }
726
            if(pageNo > pageNum){
727
                pageNo = pageNum;
728
            }
729
            queryResult.setPageNo(pageNo);
730
            --pageNo;
731
            int offset = (pageNo * pageSize);
732
            sql = "(SELECT ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,PUBLISH_TIME,ORG_ID,PROFESSOR_ID FROM ARTICLE WHERE STATUS = '1')"
733
                + " UNION ALL (SELECT RESOURCE_ID,RESOURCE_NAME,NULL,CASE WHEN RESOURCE_TYPE = '1' THEN '3' WHEN RESOURCE_TYPE = '2' THEN '4' ELSE NULL END,"
734
                + " PUBLISH_TIME,ORG_ID,PROFESSOR_ID FROM RESOURCE WHERE STATUS = '1')";
735
            sql = sql + " ORDER BY PUBLISH_TIME DESC ";
736
            sql = sql + " LIMIT " + pageSize+ " OFFSET " + offset;
737
        }
738
        ps = con.prepareStatement(sql);
739
        try{
740
            ResultSet rs = ps.executeQuery();
741
            try{
742
                List<FindInfo> findInfos = new ArrayList<FindInfo>();
743
                queryResult.setData(findInfos);
744
                int size = 0;
745
                while((size<pageSize) && rs.next()){
746
                    ++size;
747
                    FindInfo findInfo =  new FindInfo();
748
                    findInfo.setId(rs.getString(1));
749
                    findInfo.setName(rs.getString(2));
750
                    String image = rs.getString(3);
751
                    if(rs.wasNull()){
752
                    	image = null;
753
                    }
754
                    findInfo.setImage(image);
755
                    findInfo.setType(rs.getString(4));
756
                    String createTime = rs.getString(5);
757
                    if(rs.wasNull()){
758
                    	createTime = null;
759
                    }
760
                    findInfo.setCreateTime(createTime);
761
                    String orgId = rs.getString(6);
762
                    if(rs.wasNull()){
763
                    	findInfo.setOwner(rs.getString(7));
764
                    }else{
765
                    	findInfo.setOwner(orgId);
766
                    }
767
                    findInfos.add(findInfo);
768
                }
769
                return queryResult;
770
            }finally{
771
                try{rs.close();}catch(Exception e3){}
772
            }
773
        }finally{
774
            try{ps.close();}catch(Exception e4){}
775
        }
776
    }
777
	
651
	public abstract PageQueryResult<SelfArticle> queryPageForSelf(Connection con, @Nullable String professorId, @Nullable String orgId,
652
			@Like @Nullable String articleTitle, int pageSize, int pageNo) throws SQLException;
653

654
	// public PageQueryResult<FindInfo> queryPage(Connection con,int
655
	// pageSize,int pageNo) throws SQLException{
656
	// int total = 0;
657
	// PageQueryResult<FindInfo> queryResult = new PageQueryResult<FindInfo>();
658
	// String sql = null;
659
	// sql = "SELECT SUM(NUM) FROM (SELECT COUNT(1) NUM FROM ARTICLE UNION ALL
660
	// SELECT COUNT(1) NUM FROM RESOURCE) TBL";
661
	// PreparedStatement ps = con.prepareStatement(sql);
662
	// try{
663
	// queryResult.setPageSize(pageSize);
664
	// ResultSet rs = ps.executeQuery();
665
	// try{
666
	// rs.next();
667
	// total = rs.getInt(1);
668
	// }finally{
669
	// try{rs.close();}catch(Exception e1){}
670
	// }
671
	// }finally{
672
	// try{ps.close();}catch(Exception e2){}
673
	// }
674
	// queryResult.setTotal(total);
675
	// if(0== total){
676
	// queryResult.setPageNo(1);
677
	// queryResult.setData(Collections.<FindInfo>emptyList());
678
	// return queryResult;
679
	// }
680
	// boolean firstPage = (1 == pageNo);
681
	// if(firstPage){
682
	// queryResult.setPageNo(1);
683
	// sql = "SELECT
684
	// ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,CREATE_TIME,ORG_ID,PROFESSOR_ID
685
	// FROM ARTICLE"
686
	// + " UNION ALL SELECT
687
	// RESOURCE_ID,RESOURCE_NAME,NULL,'3',CREATE_TIME,NULL,PROFESSOR_ID FROM
688
	// RESOURCE";
689
	// sql = sql + " ORDER BY CREATE_TIME DESC ";
690
	// sql = sql + " LIMIT " + pageSize;
691
	// }else{
692
	// int pageNum = total / pageSize;
693
	// if(total % pageSize != 0){
694
	// ++pageNum;
695
	// }
696
	// if(pageNo > pageNum){
697
	// pageNo = pageNum;
698
	// }
699
	// queryResult.setPageNo(pageNo);
700
	// --pageNo;
701
	// int offset = (pageNo * pageSize);
702
	// sql = "SELECT
703
	// ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,CREATE_TIME,ORG_ID,PROFESSOR_ID
704
	// FROM ARTICLE"
705
	// + " UNION ALL SELECT
706
	// RESOURCE_ID,RESOURCE_NAME,NULL,'3',CREATE_TIME,NULL,PROFESSOR_ID FROM
707
	// RESOURCE";
708
	// sql = sql + " ORDER BY CREATE_TIME DESC ";
709
	// sql = sql + " LIMIT " + pageSize+ " OFFSET " + offset;
710
	// }
711
	// ps = con.prepareStatement(sql);
712
	// try{
713
	// ResultSet rs = ps.executeQuery();
714
	// try{
715
	// List<FindInfo> findInfos = new ArrayList<FindInfo>();
716
	// queryResult.setData(findInfos);
717
	// int size = 0;
718
	// while((size<pageSize) && rs.next()){
719
	// ++size;
720
	// FindInfo findInfo = new FindInfo();
721
	// findInfo.setId(rs.getString(1));
722
	// findInfo.setName(rs.getString(2));
723
	// String image = rs.getString(3);
724
	// if(rs.wasNull()){
725
	// image = null;
726
	// }
727
	// findInfo.setImage(image);
728
	// findInfo.setType(rs.getString(4));
729
	// findInfo.setCreateTime(rs.getString(5));
730
	// String orgId = rs.getString(6);
731
	// if(rs.wasNull()){
732
	// findInfo.setOwner(rs.getString(7));
733
	// }else{
734
	// findInfo.setOwner(orgId);
735
	// }
736
	// findInfos.add(findInfo);
737
	// }
738
	// return queryResult;
739
	// }finally{
740
	// try{rs.close();}catch(Exception e3){}
741
	// }
742
	// }finally{
743
	// try{ps.close();}catch(Exception e4){}
744
	// }
745
	// }
746
	//
747
	// public PageQueryResult<FindInfo> queryFindHot(Connection con,int
748
	// pageSize,int pageNo) throws SQLException{
749
	// int total = 0;
750
	// PageQueryResult<FindInfo> queryResult = new PageQueryResult<FindInfo>();
751
	// String sql = null;
752
	// sql = "SELECT SUM(NUM) FROM ((SELECT COUNT(1) NUM FROM ARTICLE WHERE
753
	// STATUS = '1') UNION ALL (SELECT COUNT(1) NUM FROM RESOURCE WHERE STATUS =
754
	// '1')) TBL";
755
	// PreparedStatement ps = con.prepareStatement(sql);
756
	// try{
757
	// queryResult.setPageSize(pageSize);
758
	// ResultSet rs = ps.executeQuery();
759
	// try{
760
	// rs.next();
761
	// total = rs.getInt(1);
762
	// }finally{
763
	// try{rs.close();}catch(Exception e1){}
764
	// }
765
	// }finally{
766
	// try{ps.close();}catch(Exception e2){}
767
	// }
768
	// queryResult.setTotal(total);
769
	// if(0== total){
770
	// queryResult.setPageNo(1);
771
	// queryResult.setData(Collections.<FindInfo>emptyList());
772
	// return queryResult;
773
	// }
774
	// boolean firstPage = (1 == pageNo);
775
	// if(firstPage){
776
	// queryResult.setPageNo(1);
777
	// sql = "(SELECT
778
	// ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,PUBLISH_TIME,ORG_ID,PROFESSOR_ID
779
	// FROM ARTICLE WHERE STATUS = '1')"
780
	// + " UNION ALL (SELECT RESOURCE_ID,RESOURCE_NAME,NULL,CASE WHEN
781
	// RESOURCE_TYPE = '1' THEN '3' WHEN RESOURCE_TYPE = '2' THEN '4' ELSE NULL
782
	// END,"
783
	// + " PUBLISH_TIME,ORG_ID,PROFESSOR_ID FROM RESOURCE WHERE STATUS = '1')";
784
	// sql = sql + " ORDER BY PUBLISH_TIME DESC ";
785
	// sql = sql + " LIMIT " + pageSize;
786
	// }else{
787
	// int pageNum = total / pageSize;
788
	// if(total % pageSize != 0){
789
	// ++pageNum;
790
	// }
791
	// if(pageNo > pageNum){
792
	// pageNo = pageNum;
793
	// }
794
	// queryResult.setPageNo(pageNo);
795
	// --pageNo;
796
	// int offset = (pageNo * pageSize);
797
	// sql = "(SELECT
798
	// ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,PUBLISH_TIME,ORG_ID,PROFESSOR_ID
799
	// FROM ARTICLE WHERE STATUS = '1')"
800
	// + " UNION ALL (SELECT RESOURCE_ID,RESOURCE_NAME,NULL,CASE WHEN
801
	// RESOURCE_TYPE = '1' THEN '3' WHEN RESOURCE_TYPE = '2' THEN '4' ELSE NULL
802
	// END,"
803
	// + " PUBLISH_TIME,ORG_ID,PROFESSOR_ID FROM RESOURCE WHERE STATUS = '1')";
804
	// sql = sql + " ORDER BY PUBLISH_TIME DESC ";
805
	// sql = sql + " LIMIT " + pageSize+ " OFFSET " + offset;
806
	// }
807
	// ps = con.prepareStatement(sql);
808
	// try{
809
	// ResultSet rs = ps.executeQuery();
810
	// try{
811
	// List<FindInfo> findInfos = new ArrayList<FindInfo>();
812
	// queryResult.setData(findInfos);
813
	// int size = 0;
814
	// while((size<pageSize) && rs.next()){
815
	// ++size;
816
	// FindInfo findInfo = new FindInfo();
817
	// findInfo.setId(rs.getString(1));
818
	// findInfo.setName(rs.getString(2));
819
	// String image = rs.getString(3);
820
	// if(rs.wasNull()){
821
	// image = null;
822
	// }
823
	// findInfo.setImage(image);
824
	// findInfo.setType(rs.getString(4));
825
	// String createTime = rs.getString(5);
826
	// if(rs.wasNull()){
827
	// createTime = null;
828
	// }
829
	// findInfo.setCreateTime(createTime);
830
	// String orgId = rs.getString(6);
831
	// if(rs.wasNull()){
832
	// findInfo.setOwner(rs.getString(7));
833
	// }else{
834
	// findInfo.setOwner(orgId);
835
	// }
836
	// findInfos.add(findInfo);
837
	// }
838
	// return queryResult;
839
	// }finally{
840
	// try{rs.close();}catch(Exception e3){}
841
	// }
842
	// }finally{
843
	// try{ps.close();}catch(Exception e4){}
844
	// }
845
	// }
846
	//
778
	@SelectOne
847
	@SelectOne
779
	@Nullable
848
	@Nullable
780
	public abstract Article query(Connection con ,long shareId)throws SQLException;
849
	public abstract Article query(Connection con, long shareId) throws SQLException;
781

850

782
	
783
	@PageSelect 
851
	@PageSelect
784
	@Exclude("articleContent")
852
	@Exclude("articleContent")
785
	@OrderBy(" ORDER BY PUBLISH_TIME DESC,SHARE_ID ASC ")
853
	@OrderBy(" ORDER BY PUBLISH_TIME DESC,SHARE_ID ASC ")
786
	@Where("STATUS='1'")
854
	@Where("STATUS='1'")
787
	public abstract PageQueryResult<Article> queryFind(Connection con,Integer colNum,int pageSize,int pageNo)throws SQLException;
855
	public abstract PageQueryResult<Article> queryFind(Connection con, Integer colNum, int pageSize, int pageNo) throws SQLException;
788

856

789
	
790
	@LimitSelect
857
	@LimitSelect
791
	@Exclude("articleContent")
858
	@Exclude("articleContent")
792
	@OrderBy(" ORDER BY PAGE_VIEWS DESC,SHARE_ID ASC ")
859
	@OrderBy(" ORDER BY PAGE_VIEWS DESC,SHARE_ID ASC ")
793
	@Where("STATUS='1'")
860
	@Where("STATUS='1'")
794
	public abstract List<Article> lasterByPublishTime(Connection con,@GtEq String publishTime ,int rows) throws SQLException;
795
	
796
	
797
	
861
	public abstract List<Article> lasterByPublishTime(Connection con, @GtEq String publishTime, int rows) throws SQLException;
862

798
}
863
}

+ 4 - 25
src/main/java/com/ekexiu/portal/dao/ArticleResDao.java

9

9

10
import org.jfw.apt.orm.annotation.dao.DAO;
10
import org.jfw.apt.orm.annotation.dao.DAO;
11
import org.jfw.apt.orm.annotation.dao.method.From;
11
import org.jfw.apt.orm.annotation.dao.method.From;
12
import org.jfw.apt.orm.annotation.dao.method.Where;
12
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
13
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
13
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
14
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
14
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
15
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
25
//	@Column(handlerClass = IntHandler.class, value = "COUNT(1)")
26
//	@Column(handlerClass = IntHandler.class, value = "COUNT(1)")
26
//	@DefaultValue("0")
27
//	@DefaultValue("0")
27
//	public abstract int queryByArticleId(Connection con, String articleId) throws SQLException;
28
//	public abstract int queryByArticleId(Connection con, String articleId) throws SQLException;
29
	@SelectList
30
	@Where("RESOURCE_ID IN (SELECT RESOURCE_ID FROM RESOURCE WHERE STATUS='1')")
31
	public abstract List<ArticleRes> query(Connection con,String articleId)throws SQLException;
28

32

29
	public List<ArticleRes> query(Connection con, String articleId) throws SQLException{
30
        int index = 1;
31
        String sql = "SELECT ARTICLE_ID,A.RESOURCE_ID,A.CREATE_TIME FROM ARTICLE_RES A INNER JOIN RESOURCE R ON A.RESOURCE_ID = R.RESOURCE_ID WHERE R.STATUS = '1' AND ARTICLE_ID = ?";
32
        PreparedStatement ps = con.prepareStatement(sql);
33
        try{
34
            ps.setString(index++,articleId);
35
            ResultSet rs = ps.executeQuery();
36
            try{
37
                List<ArticleRes> result = new ArrayList<ArticleRes>();
38
                while(rs.next()){
39
                    ArticleRes articleRes =  new ArticleRes();
40
                    articleRes.setArticleId(rs.getString(1));
41
                    articleRes.setResourceId(rs.getString(2));
42
                    articleRes.setCreateTime(rs.getString(3));
43
                    result.add(articleRes);
44
                }
45
                return result;
46
            }finally{
47
                try{rs.close();}catch(Exception e1){}
48
            }
49
        }finally{
50
            try{ps.close();}catch(Exception e2){}
51
        }
52
    }
53
	
54
	public List<ArticleRes> queryArticles(Connection con, String resourceId, int rows) throws SQLException {
33
	public List<ArticleRes> queryArticles(Connection con, String resourceId, int rows) throws SQLException {
55
		int index = 1;
34
		int index = 1;
56
        String sql = "SELECT A.ARTICLE_ID,A.RESOURCE_ID,A.CREATE_TIME FROM ARTICLE_RES A INNER JOIN ARTICLE AR ON A.ARTICLE_ID = AR.ARTICLE_ID "
35
        String sql = "SELECT A.ARTICLE_ID,A.RESOURCE_ID,A.CREATE_TIME FROM ARTICLE_RES A INNER JOIN ARTICLE AR ON A.ARTICLE_ID = AR.ARTICLE_ID "

+ 18 - 40
src/main/java/com/ekexiu/portal/dao/GrowthLogDao.java

7
import java.util.ArrayList;
7
import java.util.ArrayList;
8
import java.util.List;
8
import java.util.List;
9

9

10
import org.jfw.apt.annotation.DefaultValue;
10
import org.jfw.apt.annotation.Nullable;
11
import org.jfw.apt.annotation.Nullable;
12
import org.jfw.apt.orm.annotation.dao.Column;
11
import org.jfw.apt.orm.annotation.dao.DAO;
13
import org.jfw.apt.orm.annotation.dao.DAO;
14
import org.jfw.apt.orm.annotation.dao.method.From;
12
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
15
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
13
import org.jfw.apt.orm.annotation.dao.method.Where;
16
import org.jfw.apt.orm.annotation.dao.method.Where;
14
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
17
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
15
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
18
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
19
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
16
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
20
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
17
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
21
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
18
import org.jfw.apt.orm.annotation.dao.param.LessThan;
22
import org.jfw.apt.orm.annotation.dao.param.LessThan;
19
import org.jfw.apt.orm.annotation.dao.param.Like;
23
import org.jfw.apt.orm.annotation.dao.param.Like;
24
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
20

25

21
import com.ekexiu.portal.po.GrowthLog;
26
import com.ekexiu.portal.po.GrowthLog;
22
import com.ekexiu.portal.pojo.InviteUserScore;
27
import com.ekexiu.portal.pojo.InviteUserScore;
108
        }
113
        }
109
    }
114
    }
110
	
115
	
111
	public int queryInviteScore(Connection con,String professorId)throws SQLException{
112
		int index = 1;
113
		String sql = "SELECT SUM(SCORE) FROM GROWTH_LOG WHERE PROFESSOR_ID = ? AND INVITE_PRO IS NOT NULL";
114
		PreparedStatement ps = con.prepareStatement(sql);
115
		try{
116
			ps.setString(index++, professorId);
117
			ResultSet rs = ps.executeQuery();
118
			try{
119
				if(rs.next()){
120
                    return rs.getInt(1);
121
                }else{
122
                    return 0;
123
                }
124
			}finally{
125
				try{rs.close();}catch(Exception e1){}
126
			}
127
		}finally{
128
			try{ps.close();}catch(Exception e2){}
129
		}
130
	}
116
	@DefaultValue("0")
117
	@QueryVal
118
	@Column(handlerClass=IntHandler.class,value="SUM(SCORE)")
119
	@Where("INVITE_PRO IS NOT NULL")
120
	@From(GrowthLog.class)
121
	public abstract int queryInviteScore(Connection con,String professorId) throws SQLException;
122
	@DefaultValue("0")
123
	@QueryVal
124
	@Column(handlerClass=IntHandler.class,value="SUM(SCORE)")
125
	@Where("INVITE_PRO IS NULL")
126
	@From(GrowthLog.class)
127
	public abstract int queryMyScore(Connection con,String professorId)throws SQLException;
131
	
128
	
132
	public int queryMyScore(Connection con,String professorId)throws SQLException{
133
		int index = 1;
134
		String sql = "SELECT SUM(SCORE) FROM GROWTH_LOG WHERE PROFESSOR_ID = ? AND INVITE_PRO IS NULL";
135
		PreparedStatement ps = con.prepareStatement(sql);
136
		try{
137
			ps.setString(index++, professorId);
138
			ResultSet rs = ps.executeQuery();
139
			try{
140
				if(rs.next()){
141
                    return rs.getInt(1);
142
                }else{
143
                    return 0;
144
                }
145
			}finally{
146
				try{rs.close();}catch(Exception e1){}
147
			}
148
		}finally{
149
			try{ps.close();}catch(Exception e2){}
150
		}
151
	}
129

152
	
130
	
153
	@SelectList
131
	@SelectList
154
	@Where("(OPERATE = '2' OR OPERATE = '3' OR OPERATE = '4' OR OPERATE = '25' OR OPERATE = '26' OR OPERATE = '27' )")
132
	@Where("(OPERATE = '2' OR OPERATE = '3' OR OPERATE = '4' OR OPERATE = '25' OR OPERATE = '26' OR OPERATE = '27' )")

+ 36 - 38
src/main/java/com/ekexiu/portal/service/ArticleService.java

44
import com.ekexiu.portal.po.ArticleOrg;
44
import com.ekexiu.portal.po.ArticleOrg;
45
import com.ekexiu.portal.po.ArticlePro;
45
import com.ekexiu.portal.po.ArticlePro;
46
import com.ekexiu.portal.po.ArticleRes;
46
import com.ekexiu.portal.po.ArticleRes;
47
import com.ekexiu.portal.po.Image;
48
import com.ekexiu.portal.pojo.EditOrganization;
47
import com.ekexiu.portal.pojo.EditOrganization;
49
import com.ekexiu.portal.pojo.EditProfessor;
48
import com.ekexiu.portal.pojo.EditProfessor;
50
import com.ekexiu.portal.pojo.FindInfo;
51
import com.ekexiu.portal.pojo.SelfArticle;
49
import com.ekexiu.portal.pojo.SelfArticle;
52

50

53
@Path("/article")
51
@Path("/article")
772
		return this.articleDao.queryPageForSelf(con, professorId, orgId, articleTitle, pageSize, pageNo);
770
		return this.articleDao.queryPageForSelf(con, professorId, orgId, articleTitle, pageSize, pageNo);
773
	}
771
	}
774

772

775
	@Get
776
	@Path("/pqFind")
777
	public PageQueryResult<FindInfo> queryPage(@JdbcConn Connection con, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException {
778
		PageQueryResult<FindInfo> queryResult = this.articleDao.queryPage(con, pageSize, pageNo);
779
		List<FindInfo> findInfos = queryResult.getData();
780
		for (FindInfo findInfo : findInfos) {
781
			if ("3".equals(findInfo.getType())) {
782
				List<Image> images = this.imagesService.queryRes(con, findInfo.getId());
783
				if (images.size() > 0) {
784
					findInfo.setImage(findInfo.getId() + ".jpg");
785
				}
786
			}
787
		}
788
		queryResult.setData(findInfos);
789
		return queryResult;
790
	}
791

792
	@Get
793
	@Path("/findHot")
794
	public PageQueryResult<FindInfo> queryFindHot(@JdbcConn Connection con, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo)
795
			throws SQLException {
796
		PageQueryResult<FindInfo> queryResult = this.articleDao.queryFindHot(con, pageSize, pageNo);
797
		List<FindInfo> findInfos = queryResult.getData();
798
		if (!findInfos.isEmpty()) {
799
			for (FindInfo findInfo : findInfos) {
800
				if ("3".equals(findInfo.getType()) || "4".equals(findInfo.getType())) {
801
					List<Image> images = this.imagesService.queryRes(con, findInfo.getId());
802
					if (images.size() > 0) {
803
						findInfo.setImage(images.get(0).getImageSrc());
804
					}
805
				}
806
			}
807
			queryResult.setData(findInfos);
808
		}
809
		return queryResult;
810
	}
773
//	@Get
774
//	@Path("/pqFind")
775
//	public PageQueryResult<FindInfo> queryPage(@JdbcConn Connection con, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException {
776
//		PageQueryResult<FindInfo> queryResult = this.articleDao.queryPage(con, pageSize, pageNo);
777
//		List<FindInfo> findInfos = queryResult.getData();
778
//		for (FindInfo findInfo : findInfos) {
779
//			if ("3".equals(findInfo.getType())) {
780
//				List<Image> images = this.imagesService.queryRes(con, findInfo.getId());
781
//				if (images.size() > 0) {
782
//					findInfo.setImage(findInfo.getId() + ".jpg");
783
//				}
784
//			}
785
//		}
786
//		queryResult.setData(findInfos);
787
//		return queryResult;
788
//	}
789

790
//	@Get
791
//	@Path("/findHot")
792
//	public PageQueryResult<FindInfo> queryFindHot(@JdbcConn Connection con, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo)
793
//			throws SQLException {
794
//		PageQueryResult<FindInfo> queryResult = this.articleDao.queryFindHot(con, pageSize, pageNo);
795
//		List<FindInfo> findInfos = queryResult.getData();
796
//		if (!findInfos.isEmpty()) {
797
//			for (FindInfo findInfo : findInfos) {
798
//				if ("3".equals(findInfo.getType()) || "4".equals(findInfo.getType())) {
799
//					List<Image> images = this.imagesService.queryRes(con, findInfo.getId());
800
//					if (images.size() > 0) {
801
//						findInfo.setImage(images.get(0).getImageSrc());
802
//					}
803
//				}
804
//			}
805
//			queryResult.setData(findInfos);
806
//		}
807
//		return queryResult;
808
//	}
811

809

812
	@Get
810
	@Get
813
	@Path("/ralatePro")
811
	@Path("/ralatePro")