浏览代码

--热门关键词搜索,首页发现,感兴趣的资源和文章。

zzy.zhiyuan.foxmail 8 年之前
父节点
当前提交
1182afd5a5

+ 347 - 1
src/main/java/com/ekexiu/portal/dao/ArticleDao.java

@ -99,6 +99,270 @@ public abstract class ArticleDao {
99 99
	@Nullable
100 100
	public abstract Article queryOne(Connection con, String articleId) throws SQLException;
101 101
	
102
	public List<Article> queryByPageViews(Connection con,String articleId,int rows)throws SQLException{
103
		int index = 1;
104
		boolean hasArticleId = null != articleId;
105
		StringBuilder sql = new StringBuilder();
106
		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 FROM ARTICLE");
107
		sql.append(" WHERE STATUS = '1'");
108
		if(hasArticleId){
109
			sql.append(" AND ARTICLE_ID != ?");
110
		}
111
		sql.append(" ORDER BY PAGE_VIEWS DESC");
112
        sql.append(" LIMIT ").append(rows);
113
		PreparedStatement ps = con.prepareStatement(sql.toString());
114
		try{
115
			if(hasArticleId){
116
				ps.setString(index++, articleId);
117
			}
118
			ResultSet rs = ps.executeQuery();
119
			try{
120
				List<Article> articles = new ArrayList<Article>();
121
				while(rs.next()){
122
					Article article = new Article();
123
					article.setArticleId(rs.getString(1));
124
                    String proId = rs.getString(2);
125
                    if(rs.wasNull()){
126
                    	proId = null;
127
                    }
128
                    article.setProfessorId(proId);
129
                    article.setArticleTitle(rs.getString(3));
130
                    String articleContent = rs.getString(4);
131
                    if(rs.wasNull()){
132
                    	articleContent = null;
133
                    }
134
                    article.setArticleContent(articleContent);
135
                    String subject = rs.getString(5);
136
                    if(rs.wasNull()){
137
                    	subject = null;
138
                    }
139
                    article.setSubject(subject);
140
                    String publishTime = rs.getString(6);
141
                    if(rs.wasNull()){
142
                    	publishTime = null;
143
                    }
144
                    article.setPublishTime(publishTime);
145
                    String articleImg = rs.getString(7);
146
                    if(rs.wasNull()){
147
                    	articleImg = null;
148
                    }
149
                    article.setArticleImg(articleImg);
150
                    String org = rs.getString(8);
151
                    if(rs.wasNull()){
152
                    	org = null;
153
                    }
154
                    article.setOrgId(org);
155
                    String articleType = rs.getString(9);
156
                    if(rs.wasNull()){
157
                    	articleType = null;
158
                    }
159
                    article.setArticleType(articleType);
160
                    article.setArticleAgree(rs.getInt(10));
161
                    article.setPageViews(rs.getInt(11));
162
                    String status = rs.getString(12);
163
                    if(rs.wasNull()){
164
                    	status = null;
165
                    }
166
                    article.setStatus(status);
167
                    article.setCreateTime(rs.getString(13));
168
                    article.setModifyTime(rs.getString(14));
169
					articles.add(article);
170
				}
171
				return articles;
172
			}finally{
173
				try{rs.close();}catch(Exception e1){}
174
			}
175
		}finally{
176
			try{ps.close();}catch(Exception e2){}
177
		}
178
	}
179
	
180
	public List<Article> queryByAuthor(Connection con,String professorId,String orgId,String articleId,int rows)throws SQLException{
181
		int index = 1;
182
		boolean hasProId = null != professorId;
183
		boolean hasOrgId = null != orgId;
184
		boolean hasArticleId = null != articleId;
185
		StringBuilder sql = new StringBuilder();
186
		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 FROM ARTICLE");
187
		sql.append(" WHERE STATUS = '1'");
188
		if(hasProId){
189
			sql.append(" AND PROFESSOR_ID = ?");
190
		}
191
		if(hasOrgId){
192
			sql.append(" AND ORG_ID = ?");
193
		}
194
		if(hasArticleId){
195
			sql.append(" AND ARTICLE_ID != ?");
196
		}
197
		sql.append(" ORDER BY PUBLISH_TIME DESC");
198
        sql.append(" LIMIT ").append(rows);
199
		PreparedStatement ps = con.prepareStatement(sql.toString());
200
		try{
201
			if(hasProId){
202
				ps.setString(index++, professorId);
203
			}
204
			if(hasOrgId){
205
				ps.setString(index++, orgId);
206
			}
207
			if(hasArticleId){
208
				ps.setString(index++, articleId);
209
			}
210
			ResultSet rs = ps.executeQuery();
211
			try{
212
				List<Article> articles = new ArrayList<Article>();
213
				while(rs.next()){
214
					Article article = new Article();
215
					article.setArticleId(rs.getString(1));
216
                    String proId = rs.getString(2);
217
                    if(rs.wasNull()){
218
                    	proId = null;
219
                    }
220
                    article.setProfessorId(proId);
221
                    article.setArticleTitle(rs.getString(3));
222
                    String articleContent = rs.getString(4);
223
                    if(rs.wasNull()){
224
                    	articleContent = null;
225
                    }
226
                    article.setArticleContent(articleContent);
227
                    String subject = rs.getString(5);
228
                    if(rs.wasNull()){
229
                    	subject = null;
230
                    }
231
                    article.setSubject(subject);
232
                    String publishTime = rs.getString(6);
233
                    if(rs.wasNull()){
234
                    	publishTime = null;
235
                    }
236
                    article.setPublishTime(publishTime);
237
                    String articleImg = rs.getString(7);
238
                    if(rs.wasNull()){
239
                    	articleImg = null;
240
                    }
241
                    article.setArticleImg(articleImg);
242
                    String org = rs.getString(8);
243
                    if(rs.wasNull()){
244
                    	org = null;
245
                    }
246
                    article.setOrgId(org);
247
                    String articleType = rs.getString(9);
248
                    if(rs.wasNull()){
249
                    	articleType = null;
250
                    }
251
                    article.setArticleType(articleType);
252
                    article.setArticleAgree(rs.getInt(10));
253
                    article.setPageViews(rs.getInt(11));
254
                    String status = rs.getString(12);
255
                    if(rs.wasNull()){
256
                    	status = null;
257
                    }
258
                    article.setStatus(status);
259
                    article.setCreateTime(rs.getString(13));
260
                    article.setModifyTime(rs.getString(14));
261
					articles.add(article);
262
				}
263
				return articles;
264
			}finally{
265
				try{rs.close();}catch(Exception e1){}
266
			}
267
		}finally{
268
			try{ps.close();}catch(Exception e2){}
269
		}
270
	}
271
	
272
	public List<Article> queryLimit(Connection con,String[] keys,String articleId,int rows) throws SQLException{
273
		int index = 1;
274
		boolean hasKeys = null != keys;
275
		boolean hasArticleId = null != articleId;
276
		StringBuilder sql = new StringBuilder();
277
		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 FROM ARTICLE");
278
		sql.append(" WHERE STATUS = '1'");
279
		if(hasArticleId){
280
			sql.append(" AND ARTICLE_ID != ?");
281
		}
282
		if(hasKeys){
283
			for (int i = 0; i < keys.length; i++) {
284
        		if(i == 0){
285
        			sql.append(" AND (SUBJECT LIKE ?");
286
        		}else{
287
        			sql.append(" OR SUBJECT LIKE ?");
288
        		}
289
			}
290
        	sql.append(")");
291
		}
292
		sql.append(" ORDER BY PUBLISH_TIME DESC");
293
        sql.append(" LIMIT ").append(rows);
294
		PreparedStatement ps = con.prepareStatement(sql.toString());
295
		try{
296
			if(hasArticleId){
297
				ps.setString(index++, articleId);
298
			}
299
			if(hasKeys){
300
        		for (String key : keys) {
301
        			ps.setString(index++, "%"+key+"%");
302
				}
303
        	}
304
			ResultSet rs = ps.executeQuery();
305
			try{
306
				List<Article> articles = new ArrayList<Article>();
307
				while(rs.next()){
308
					Article article = new Article();
309
					article.setArticleId(rs.getString(1));
310
                    String proId = rs.getString(2);
311
                    if(rs.wasNull()){
312
                    	proId = null;
313
                    }
314
                    article.setProfessorId(proId);
315
                    article.setArticleTitle(rs.getString(3));
316
                    String articleContent = rs.getString(4);
317
                    if(rs.wasNull()){
318
                    	articleContent = null;
319
                    }
320
                    article.setArticleContent(articleContent);
321
                    String subject = rs.getString(5);
322
                    if(rs.wasNull()){
323
                    	subject = null;
324
                    }
325
                    article.setSubject(subject);
326
                    String publishTime = rs.getString(6);
327
                    if(rs.wasNull()){
328
                    	publishTime = null;
329
                    }
330
                    article.setPublishTime(publishTime);
331
                    String articleImg = rs.getString(7);
332
                    if(rs.wasNull()){
333
                    	articleImg = null;
334
                    }
335
                    article.setArticleImg(articleImg);
336
                    String org = rs.getString(8);
337
                    if(rs.wasNull()){
338
                    	org = null;
339
                    }
340
                    article.setOrgId(org);
341
                    String articleType = rs.getString(9);
342
                    if(rs.wasNull()){
343
                    	articleType = null;
344
                    }
345
                    article.setArticleType(articleType);
346
                    article.setArticleAgree(rs.getInt(10));
347
                    article.setPageViews(rs.getInt(11));
348
                    String status = rs.getString(12);
349
                    if(rs.wasNull()){
350
                    	status = null;
351
                    }
352
                    article.setStatus(status);
353
                    article.setCreateTime(rs.getString(13));
354
                    article.setModifyTime(rs.getString(14));
355
					articles.add(article);
356
				}
357
				return articles;
358
			}finally{
359
				try{rs.close();}catch(Exception e1){}
360
			}
361
		}finally{
362
			try{ps.close();}catch(Exception e2) {}
363
		}
364
	}
365
	
102 366
	@PageSelect
103 367
	@OrderBy("ORDER BY PUBLISH_TIME DESC")
104 368
	@Where("STATUS = '1'")
@ -213,7 +477,6 @@ public abstract class ArticleDao {
213 477
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
214 478
        }
215 479
        ps = con.prepareStatement(sql.toString());
216
        System.out.println(sql.toString());
217 480
        index = 1;
218 481
        try{
219 482
        	if(hasProfessorId){
@ -386,5 +649,88 @@ public abstract class ArticleDao {
386 649
            try{ps.close();}catch(Exception e4){}
387 650
        }
388 651
    }
652
	
653
	public PageQueryResult<FindInfo> queryFindHot(Connection con,int pageSize,int pageNo) throws SQLException{
654
        int total = 0;
655
        PageQueryResult<FindInfo> queryResult = new PageQueryResult<FindInfo>();
656
        String sql = null;
657
        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";
658
        PreparedStatement ps = con.prepareStatement(sql);
659
        try{
660
        	queryResult.setPageSize(pageSize);
661
            ResultSet rs = ps.executeQuery();
662
            try{
663
                rs.next();
664
                total = rs.getInt(1);
665
            }finally{
666
                try{rs.close();}catch(Exception e1){}
667
            }
668
        }finally{
669
            try{ps.close();}catch(Exception e2){}
670
        }
671
        queryResult.setTotal(total);
672
        if(0== total){
673
        	queryResult.setPageNo(1);
674
        	queryResult.setData(Collections.<FindInfo>emptyList());
675
            return queryResult;
676
        }
677
        boolean firstPage = (1 == pageNo);
678
        if(firstPage){
679
        	queryResult.setPageNo(1);
680
        	sql = "(SELECT ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,CREATE_TIME,ORG_ID,PROFESSOR_ID FROM ARTICLE WHERE STATUS = '1')"
681
                	+ " UNION ALL (SELECT RESOURCE_ID,RESOURCE_NAME,NULL,'3',CREATE_TIME,NULL,PROFESSOR_ID FROM RESOURCE WHERE STATUS = '1')";
682
            sql = sql + " ORDER BY CREATE_TIME DESC ";
683
            sql = sql + " LIMIT " + pageSize;
684
        }else{
685
            int pageNum = total / pageSize;
686
            if(total % pageSize != 0){
687
                ++pageNum;
688
            }
689
            if(pageNo > pageNum){
690
                pageNo = pageNum;
691
            }
692
            queryResult.setPageNo(pageNo);
693
            --pageNo;
694
            int offset = (pageNo * pageSize);
695
            sql = "(SELECT ARTICLE_ID,ARTICLE_TITLE,ARTICLE_IMG,ARTICLE_TYPE,CREATE_TIME,ORG_ID,PROFESSOR_ID FROM ARTICLE WHERE STATUS = '1')"
696
                	+ " UNION ALL (SELECT RESOURCE_ID,RESOURCE_NAME,NULL,'3',CREATE_TIME,NULL,PROFESSOR_ID FROM RESOURCE WHERE STATUS = '1')";
697
            sql = sql + " ORDER BY CREATE_TIME DESC ";
698
            sql = sql + " LIMIT " + pageSize+ " OFFSET " + offset;
699
        }
700
        ps = con.prepareStatement(sql);
701
        try{
702
            ResultSet rs = ps.executeQuery();
703
            try{
704
                List<FindInfo> findInfos = new ArrayList<FindInfo>();
705
                queryResult.setData(findInfos);
706
                int size = 0;
707
                while((size<pageSize) && rs.next()){
708
                    ++size;
709
                    FindInfo findInfo =  new FindInfo();
710
                    findInfo.setId(rs.getString(1));
711
                    findInfo.setName(rs.getString(2));
712
                    String image = rs.getString(3);
713
                    if(rs.wasNull()){
714
                    	image = null;
715
                    }
716
                    findInfo.setImage(image);
717
                    findInfo.setType(rs.getString(4));
718
                    findInfo.setCreateTime(rs.getString(5));
719
                    String orgId = rs.getString(6);
720
                    if(rs.wasNull()){
721
                    	findInfo.setOwner(rs.getString(7));
722
                    }else{
723
                    	findInfo.setOwner(orgId);
724
                    }
725
                    findInfos.add(findInfo);
726
                }
727
                return queryResult;
728
            }finally{
729
                try{rs.close();}catch(Exception e3){}
730
            }
731
        }finally{
732
            try{ps.close();}catch(Exception e4){}
733
        }
734
    }
389 735

390 736
}

+ 27 - 1
src/main/java/com/ekexiu/portal/dao/ArticleResDao.java

@ -30,7 +30,7 @@ public abstract class ArticleResDao {
30 30
	@DefaultValue("0")
31 31
	public abstract int queryByArticleId(Connection con, String articleId) throws SQLException;
32 32

33
	public List<ArticleRes> query(Connection con,java.lang.String articleId) throws SQLException{
33
	public List<ArticleRes> query(Connection con, String articleId) throws SQLException{
34 34
        int index = 1;
35 35
        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 = ?";
36 36
        PreparedStatement ps = con.prepareStatement(sql);
@ -55,6 +55,32 @@ public abstract class ArticleResDao {
55 55
        }
56 56
    }
57 57
	
58
	public List<ArticleRes> queryArticles(Connection con, String resourceId, int rows) throws SQLException {
59
		int index = 1;
60
        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 "
61
        		+ " WHERE AR.STATUS = '1' AND A.RESOURCE_ID = ? ORDER BY PUBLISH_TIME DESC LIMIT " + rows;
62
        PreparedStatement ps = con.prepareStatement(sql);
63
        try{
64
            ps.setString(index++,resourceId);
65
            ResultSet rs = ps.executeQuery();
66
            try{
67
                List<ArticleRes> result = new ArrayList<ArticleRes>();
68
                while(rs.next()){
69
                    ArticleRes articleRes =  new ArticleRes();
70
                    articleRes.setArticleId(rs.getString(1));
71
                    articleRes.setResourceId(rs.getString(2));
72
                    articleRes.setCreateTime(rs.getString(3));
73
                    result.add(articleRes);
74
                }
75
                return result;
76
            }finally{
77
                try{rs.close();}catch(Exception e1){}
78
            }
79
        }finally{
80
            try{ps.close();}catch(Exception e2){}
81
        }
82
	}
83
	
58 84
	@DeleteWith
59 85
	@From(ArticleRes.class)
60 86
	public abstract int delete(Connection con, String articleId) throws SQLException;

+ 6 - 0
src/main/java/com/ekexiu/portal/dao/ImageDao.java

@ -11,6 +11,8 @@ import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
11 11
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
12 12
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
13 13
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
14
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
15
import org.jfw.apt.orm.annotation.dao.param.Set;
14 16

15 17
import com.ekexiu.portal.po.Image;
16 18

@ -19,6 +21,10 @@ public abstract class ImageDao {
19 21
	@Insert
20 22
	public abstract int insert(Connection con, Image image) throws SQLException;
21 23
	
24
	@UpdateWith
25
	@From(Image.class)
26
	public abstract int updateSort(Connection con, String imageId, @Set int sort) throws SQLException;
27
	
22 28
	@SelectOne
23 29
	@Nullable
24 30
	public abstract Image query(Connection con, String imageId) throws SQLException;

+ 361 - 0
src/main/java/com/ekexiu/portal/dao/ResourceDao.java

@ -14,6 +14,7 @@ import org.jfw.apt.orm.annotation.dao.DAO;
14 14
import org.jfw.apt.orm.annotation.dao.Dynamic;
15 15
import org.jfw.apt.orm.annotation.dao.method.From;
16 16
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
17
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
17 18
import org.jfw.apt.orm.annotation.dao.method.Where;
18 19
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
19 20
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
@ -63,6 +64,11 @@ public abstract class ResourceDao {
63 64
	@Dynamic
64 65
	public abstract int updateRes(Connection con,Resource resource) throws SQLException;
65 66
	
67
	@UpdateWith
68
	@From(Resource.class)
69
	@SetSentence("PAGE_VIEWS = PAGE_VIEWS + 1")
70
	public abstract int incPageViews(Connection con,String resourceId) throws SQLException;
71
	
66 72
	@UpdateWith
67 73
	@From(Resource.class)
68 74
	public abstract int updateStatus(Connection con, String resourceId, @Set String status) throws SQLException;
@ -108,6 +114,361 @@ public abstract class ResourceDao {
108 114
	@Nullable
109 115
	public abstract Resource queryOne(Connection con, String resourceId) throws SQLException;
110 116
	
117
	public PageQueryResult<Resource> queryForSelf(Connection con,String professorId,@Nullable String key,int pageSize,int pageNo) throws SQLException{
118
        int total = 0;
119
        PageQueryResult<Resource> queryResult = new PageQueryResult<Resource>();
120
        int index = 1;
121
        boolean hasProfessorId = null != professorId;
122
        boolean hasKey = null != key;
123
        StringBuilder sql = new StringBuilder();
124
        sql.append("SELECT COUNT(1) FROM RESOURCE WHERE STATUS IN('0','1')");
125
        if(hasProfessorId){
126
        	sql.append(" AND PROFESSOR_ID = ?");
127
        }
128
        if(hasKey){
129
        	sql.append(" AND (RESOURCE_NAME LIKE ? OR SUPPORTED_SERVICES LIKE ? OR SUBJECT LIKE ?)");
130
        }
131
        PreparedStatement ps = con.prepareStatement(sql.toString());
132
        try{
133
        	if(hasProfessorId){
134
        		ps.setString(index++, professorId);
135
        	}
136
        	if(hasKey){
137
        		ps.setString(index++, key);
138
        		ps.setString(index++, key);
139
        		ps.setString(index++, key);
140
        	}
141
        	queryResult.setPageSize(pageSize);
142
            ResultSet rs = ps.executeQuery();
143
            try{
144
                rs.next();
145
                total = rs.getInt(1);
146
            }finally{
147
                try{rs.close();}catch(Exception e1){}
148
            }
149
        }finally{
150
            try{ps.close();}catch(Exception e2){}
151
        }
152
        queryResult.setTotal(total);
153
        if(0== total){
154
        	queryResult.setPageNo(1);
155
        	queryResult.setData(Collections.<Resource>emptyList());
156
            return queryResult;
157
        }
158
        boolean firstPage = (1 == pageNo);
159
        if(firstPage){
160
        	queryResult.setPageNo(1);
161
        	sql = new StringBuilder();
162
        	sql.append("(SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,SUPPORTED_SERVICES,ORG_NAME,SPEC,PARAMETER,STATUS,DESCP,PROFESSOR_ID,PUBLISH_TIME,CREATE_TIME,MODIFY_TIME FROM RESOURCE WHERE STATUS = '0'");
163
        	if(hasProfessorId){
164
            	sql.append(" AND PROFESSOR_ID = ?");
165
            }
166
        	if(hasKey){
167
        		sql.append(" AND (RESOURCE_NAME LIKE ? OR SUPPORTED_SERVICES LIKE ? OR SUBJECT LIKE ?)");
168
        	}
169
        	sql.append(" ORDER BY MODIFY_TIME DESC) UNION ALL (SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,SUPPORTED_SERVICES,ORG_NAME,SPEC,PARAMETER,STATUS,DESCP,PROFESSOR_ID,PUBLISH_TIME,CREATE_TIME,MODIFY_TIME FROM RESOURCE WHERE STATUS = '1'");
170
        	if(hasProfessorId){
171
            	sql.append(" AND PROFESSOR_ID = ?");
172
            }
173
        	if(hasKey){
174
        		sql.append(" AND (RESOURCE_NAME LIKE ? OR SUPPORTED_SERVICES LIKE ? OR SUBJECT LIKE ?)");
175
        	}
176
        	sql.append(" ORDER BY PUBLISH_TIME DESC)");
177
        	sql.append(" LIMIT ").append(pageSize);
178
        }else{
179
            int pageNum = total / pageSize;
180
            if(total % pageSize != 0){
181
                ++pageNum;
182
            }
183
            if(pageNo > pageNum){
184
                pageNo = pageNum;
185
            }
186
            queryResult.setPageNo(pageNo);
187
            --pageNo;
188
            int offset = (pageNo * pageSize);
189
            sql = new StringBuilder();
190
            sql.append("(SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,SUPPORTED_SERVICES,ORG_NAME,SPEC,PARAMETER,STATUS,DESCP,PROFESSOR_ID,PUBLISH_TIME,CREATE_TIME,MODIFY_TIME FROM RESOURCE WHERE STATUS = '0'");
191
        	if(hasProfessorId){
192
            	sql.append(" AND PROFESSOR_ID = ?");
193
            }
194
        	if(hasKey){
195
        		sql.append(" AND (RESOURCE_NAME LIKE ? OR SUPPORTED_SERVICES LIKE ? OR SUBJECT LIKE ?)");
196
        	}
197
        	sql.append(" ORDER BY MODIFY_TIME DESC) UNION ALL (SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,SUPPORTED_SERVICES,ORG_NAME,SPEC,PARAMETER,STATUS,DESCP,PROFESSOR_ID,PUBLISH_TIME,CREATE_TIME,MODIFY_TIME FROM RESOURCE WHERE STATUS = '1'");
198
        	if(hasProfessorId){
199
            	sql.append(" AND PROFESSOR_ID = ?");
200
            }
201
        	if(hasKey){
202
        		sql.append(" AND (RESOURCE_NAME LIKE ? OR SUPPORTED_SERVICES LIKE ? OR SUBJECT LIKE ?)");
203
        	}
204
        	sql.append(" ORDER BY PUBLISH_TIME DESC)");
205
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
206
        }
207
        ps = con.prepareStatement(sql.toString());
208
        index = 1;
209
        try{
210
        	if(hasProfessorId){
211
        		ps.setString(index++, professorId);
212
        	}
213
        	if(hasKey){
214
        		ps.setString(index++, key);
215
        		ps.setString(index++, key);
216
        		ps.setString(index++, key);
217
        	}
218
        	if(hasProfessorId){
219
        		ps.setString(index++, professorId);
220
        	}
221
        	if(hasKey){
222
        		ps.setString(index++, key);
223
        		ps.setString(index++, key);
224
        		ps.setString(index++, key);
225
        	}
226
            ResultSet rs = ps.executeQuery();
227
            try{
228
                List<Resource> resources = new ArrayList<Resource>();
229
                queryResult.setData(resources);
230
                int size = 0;
231
                while((size<pageSize) && rs.next()){
232
                    ++size;
233
                    Resource resource =  new Resource();
234
                    resource.setResourceId(rs.getString(1));
235
                    resource.setResourceName(rs.getString(2));
236
                    String subject = rs.getString(3);
237
                    if(rs.wasNull()){
238
                    	subject = null;
239
                    }
240
                    resource.setSubject(subject);
241
                    resource.setSupportedServices(rs.getString(4));
242
                    String orgName = rs.getString(5);
243
                    if(rs.wasNull()){
244
                    	orgName = null;
245
                    }
246
                    resource.setOrgName(orgName);
247
                    String spec = rs.getString(6);
248
                    if(rs.wasNull()){
249
                    	spec = null;
250
                    }
251
                    resource.setSpec(spec);
252
                    String parameter = rs.getString(7);
253
                    if(rs.wasNull()){
254
                    	parameter = null;
255
                    }
256
                    resource.setParameter(parameter);
257
                    String status = rs.getString(8);
258
                    if(rs.wasNull()){
259
                    	status = null;
260
                    }
261
                    resource.setStatus(status);
262
                    String descp = rs.getString(9);
263
                    if(rs.wasNull()){
264
                    	descp = null;
265
                    }
266
                    resource.setDescp(descp);
267
                    resource.setProfessorId(rs.getString(10));
268
                    String publishTime = rs.getString(11);
269
                    if(rs.wasNull()){
270
                    	publishTime = null;
271
                    }
272
                    resource.setPublishTime(publishTime);
273
                    resource.setCreateTime(rs.getString(12));
274
                    resource.setModifyTime(rs.getString(13));
275
                    resources.add(resource);
276
                }
277
                return queryResult;
278
            }finally{
279
                try{rs.close();}catch(Exception e3){}
280
            }
281
        }finally{
282
            try{ps.close();}catch(Exception e4){}
283
        }
284
    }
285
	
286
	public List<Resource> queryByProId(Connection con,String professorId,String resourceId,int rows) throws SQLException{
287
		int index = 1;
288
        boolean hasProId = null != professorId;
289
        boolean hasResId = null != resourceId;
290
        StringBuilder sql = new StringBuilder();
291
        sql.append("SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,SUPPORTED_SERVICES,ORG_NAME,SPEC,PARAMETER,STATUS,DESCP,PROFESSOR_ID,PUBLISH_TIME,PAGE_VIEWS FROM RESOURCE");
292
        sql.append(" WHERE STATUS = '1'");
293
        if(hasResId){
294
        	sql.append(" AND RESOURCE_ID != ?");
295
        }
296
        if(hasProId){
297
        	sql.append(" AND PROFESSOR_ID = ?");
298
        	sql.append(" ORDER BY PUBLISH_TIME DESC");
299
        }else{
300
        	sql.append(" ORDER BY PAGE_VIEWS DESC");
301
        }
302
        sql.append(" LIMIT ").append(rows);
303
        PreparedStatement ps = con.prepareStatement(sql.toString());
304
        try{
305
        	if(hasResId){
306
        		ps.setString(index++, resourceId);
307
        	}
308
        	if(hasProId){
309
        		ps.setString(index++, professorId);
310
        	}
311
            ResultSet rs = ps.executeQuery();
312
            try{
313
                List<Resource> resources = new ArrayList<Resource>();
314
                while(rs.next()){
315
                    Resource resource =  new Resource();
316
                    resource.setResourceId(rs.getString(1));
317
                    resource.setResourceName(rs.getString(2));
318
                    String subject = rs.getString(3);
319
                    if(rs.wasNull()){
320
                    	subject = null;
321
                    }
322
                    resource.setSubject(subject);
323
                    resource.setSupportedServices(rs.getString(4));
324
                    String orgName = rs.getString(5);
325
                    if(rs.wasNull()){
326
                    	orgName = null;
327
                    }
328
                    resource.setOrgName(orgName);
329
                    String spec = rs.getString(6);
330
                    if(rs.wasNull()){
331
                    	spec = null;
332
                    }
333
                    resource.setSpec(spec);
334
                    String parameter = rs.getString(7);
335
                    if(rs.wasNull()){
336
                    	parameter = null;
337
                    }
338
                    resource.setParameter(parameter);
339
                    String status = rs.getString(8);
340
                    if(rs.wasNull()){
341
                    	status = null;
342
                    }
343
                    resource.setStatus(status);
344
                    String descp = rs.getString(9);
345
                    if(rs.wasNull()){
346
                    	descp = null;
347
                    }
348
                    resource.setDescp(descp);
349
                    resource.setProfessorId(rs.getString(10));
350
                    String publishTime = rs.getString(11);
351
                    if(rs.wasNull()){
352
                    	publishTime = null;
353
                    }
354
                    resource.setPublishTime(publishTime);
355
                    int pageViews = rs.getInt(12);
356
                    if(rs.wasNull()){
357
                    	pageViews = 0;
358
                    }
359
                    resource.setPageViews(pageViews);
360
                    resources.add(resource);
361
                }
362
                return resources;
363
            }finally{
364
                try{rs.close();}catch(Exception e1){}
365
            }
366
        }finally{
367
            try{ps.close();}catch(Exception e2){}
368
        }
369
	}
370
	
371
	/**
372
	 * 按关键字搜索文章列表,不包括本条资源
373
	 * @param con
374
	 * @param keys 关键词
375
	 * @param resourceId 资源ID
376
	 * @param rows 返回记录数
377
	 * @return
378
	 * @throws SQLException
379
	 */
380
	public List<Resource> queryLimit(Connection con,String[] keys,String resourceId,int rows) throws SQLException{
381
        int index = 1;
382
        boolean hasKeys = null != keys;
383
        boolean hasResId = null != resourceId;
384
        StringBuilder sql = new StringBuilder();
385
        sql.append("SELECT RESOURCE_ID,RESOURCE_NAME,SUBJECT,SUPPORTED_SERVICES,ORG_NAME,SPEC,PARAMETER,STATUS,DESCP,PROFESSOR_ID,PUBLISH_TIME,PAGE_VIEWS FROM RESOURCE");
386
        sql.append(" WHERE STATUS = '1'");
387
        if(hasResId){
388
        	sql.append(" AND RESOURCE_ID != ?");
389
        }
390
        if(hasKeys){
391
        	for (int i = 0; i < keys.length; i++) {
392
        		if(i == 0){
393
        			sql.append(" AND (SUBJECT LIKE ?");
394
        		}else{
395
        			sql.append(" OR SUBJECT LIKE ?");
396
        		}
397
			}
398
        	sql.append(")");
399
        }
400
        sql.append(" ORDER BY PUBLISH_TIME DESC");
401
        sql.append(" LIMIT ").append(rows);
402
        PreparedStatement ps = con.prepareStatement(sql.toString());
403
        try{
404
        	if(hasResId){
405
        		ps.setString(index++, resourceId);
406
        	}
407
        	if(hasKeys){
408
        		for (String key : keys) {
409
        			ps.setString(index++, "%"+key+"%");
410
				}
411
        	}
412
            ResultSet rs = ps.executeQuery();
413
            try{
414
                List<Resource> resources = new ArrayList<Resource>();
415
                while(rs.next()){
416
                    Resource resource =  new Resource();
417
                    resource.setResourceId(rs.getString(1));
418
                    resource.setResourceName(rs.getString(2));
419
                    String subject = rs.getString(3);
420
                    if(rs.wasNull()){
421
                    	subject = null;
422
                    }
423
                    resource.setSubject(subject);
424
                    resource.setSupportedServices(rs.getString(4));
425
                    String orgName = rs.getString(5);
426
                    if(rs.wasNull()){
427
                    	orgName = null;
428
                    }
429
                    resource.setOrgName(orgName);
430
                    String spec = rs.getString(6);
431
                    if(rs.wasNull()){
432
                    	spec = null;
433
                    }
434
                    resource.setSpec(spec);
435
                    String parameter = rs.getString(7);
436
                    if(rs.wasNull()){
437
                    	parameter = null;
438
                    }
439
                    resource.setParameter(parameter);
440
                    String status = rs.getString(8);
441
                    if(rs.wasNull()){
442
                    	status = null;
443
                    }
444
                    resource.setStatus(status);
445
                    String descp = rs.getString(9);
446
                    if(rs.wasNull()){
447
                    	descp = null;
448
                    }
449
                    resource.setDescp(descp);
450
                    resource.setProfessorId(rs.getString(10));
451
                    String publishTime = rs.getString(11);
452
                    if(rs.wasNull()){
453
                    	publishTime = null;
454
                    }
455
                    resource.setPublishTime(publishTime);
456
                    int pageViews = rs.getInt(12);
457
                    if(rs.wasNull()){
458
                    	pageViews = 0;
459
                    }
460
                    resource.setPageViews(pageViews);
461
                    resources.add(resource);
462
                }
463
                return resources;
464
            }finally{
465
                try{rs.close();}catch(Exception e1){}
466
            }
467
        }finally{
468
            try{ps.close();}catch(Exception e2){}
469
        }
470
	}
471
	
111 472
	/**
112 473
	 * 查询资源基础信息(ID,名称,学术领域,应用行业,可提供服务,发布者ID,资源图片)
113 474
	 * @param con

+ 12 - 6
src/main/java/com/ekexiu/portal/job/DictTaskJobEntry.java

@ -10,7 +10,6 @@ import java.util.List;
10 10

11 11
import javax.sql.DataSource;
12 12

13
import org.apache.log4j.Logger;
14 13
import org.jfw.apt.annotation.Autowrie;
15 14
import org.jfw.apt.annotation.Bean;
16 15
import org.jfw.util.ListUtil;
@ -19,7 +18,6 @@ import com.ekexiu.portal.pojo.DataDictCode;
19 18
import com.ekexiu.portal.service.DataDictService;
20 19
@Bean
21 20
public class DictTaskJobEntry implements Runnable{
22
	private static Logger logger = Logger.getLogger(TaskJobEntry.class);
23 21
	private long delayTime = 600;
24 22
	private int maxCount = 20;
25 23
	@Autowrie("dataSource")
@ -88,7 +86,7 @@ public class DictTaskJobEntry implements Runnable{
88 86
		}
89 87
		
90 88
	}
91
	private Items fillSetValue(Connection con, String sql) throws SQLException {
89
	protected Items fillSetValue(Connection con, String sql) throws SQLException {
92 90
		Items items = new Items();
93 91
		Statement st = con.createStatement();
94 92
		try {
@ -121,7 +119,7 @@ public class DictTaskJobEntry implements Runnable{
121 119
		}
122 120
	}
123 121

124
	private static class Items{
122
	protected static class Items{
125 123
		private List<Item> items = new ArrayList<Item>();
126 124
		
127 125
		public void add(String itemCaption){
@ -138,8 +136,12 @@ public class DictTaskJobEntry implements Runnable{
138 136
			if(limit >= items.size()) return items;
139 137
			return items.subList(0, limit);
140 138
		}
139
		public List<Item> getItemByDescSort(){
140
			Collections.sort(this.items);
141
			return items.subList(0, items.size());
142
		}
141 143
	}
142
	private static class Item implements Comparable<Item>{
144
	protected static class Item implements Comparable<Item>{
143 145
		private String caption;
144 146
		private long value = 1;
145 147

@ -154,7 +156,11 @@ public class DictTaskJobEntry implements Runnable{
154 156
		public void setCaption(String caption) {
155 157
			this.caption = caption;
156 158
		}
157

159
		
160
		public long getValue() {
161
			return value;
162
		}
163
		
158 164
		public void incVal(){
159 165
			++this.value;
160 166
		}

+ 93 - 0
src/main/java/com/ekexiu/portal/job/HotKeyJobEntry.java

@ -0,0 +1,93 @@
1
package com.ekexiu.portal.job;
2

3
import java.sql.Connection;
4
import java.util.ArrayList;
5
import java.util.List;
6

7
import javax.sql.DataSource;
8

9
import org.jfw.apt.annotation.Autowrie;
10
import org.jfw.apt.annotation.Bean;
11

12
import com.ekexiu.portal.pojo.DataDictCode;
13
import com.ekexiu.portal.service.DataDictService;
14

15
@Bean
16
public class HotKeyJobEntry extends DictTaskJobEntry implements Runnable {
17
	private String taskTime = "2:00:00";
18
	private long delayTime = 86400000L;
19
	@Autowrie("dataSource")
20
	private DataSource dataSource;
21
	@Autowrie
22
	private DataDictService dataDictService;
23

24
	public String getTaskTime() {
25
		return taskTime;
26
	}
27

28
	public void setTaskTime(String taskTime) {
29
		this.taskTime = taskTime;
30
	}
31

32
	public long getDelayTime() {
33
		return delayTime;
34
	}
35

36
	public void setDelayTime(long delayTime) {
37
		this.delayTime = delayTime;
38
	}
39

40
	public DataSource getDataSource() {
41
		return dataSource;
42
	}
43

44
	public void setDataSource(DataSource dataSource) {
45
		this.dataSource = dataSource;
46
	}
47

48
	public DataDictService getDataDictService() {
49
		return dataDictService;
50
	}
51

52
	public void setDataDictService(DataDictService dataDictService) {
53
		this.dataDictService = dataDictService;
54
	}
55

56
	@Override
57
	public void run() {
58
		try {
59
			Connection con = this.dataSource.getConnection();
60
			try {
61
				Items items = fillSetValue(con,
62
						"SELECT SUBJECT FROM PROFESSOR UNION ALL SELECT INDUSTRY FROM PROFESSOR UNION ALL SELECT SUBJECT FROM ARTICLE UNION ALL SELECT SUBJECT FROM RESOURCE");
63
				List<Item> list = items.getItemByDescSort();
64
				List<DataDictCode> codes = new ArrayList<DataDictCode>();
65
				for (Item item : list) {
66
					if (item.getValue() > 1) {
67
						DataDictCode code = new DataDictCode();
68
						code.setCount(item.getValue());
69
						code.setCaption(item.getCaption());
70
						codes.add(code);
71
					}
72
				}
73
				this.dataDictService.setHotKey(codes);
74

75
			} catch (Exception e) {
76
				try {
77
					con.rollback();
78
				} catch (Exception e1) {
79
					e1.printStackTrace();
80
				}
81
			} finally {
82
				try {
83
					con.close();
84
				} catch (Exception e) {
85
					e.printStackTrace();
86
				}
87
			}
88
		} catch (Exception e) {
89
			e.printStackTrace();
90
		}
91

92
	}
93
}

+ 7 - 1
src/main/java/com/ekexiu/portal/job/TaskJob.java

@ -25,7 +25,8 @@ public class TaskJob implements AfterBeanFactory {
25 25
		TaskJobEntry tje = (TaskJobEntry) bf.getBean("com_ekexiu_portal_job_TaskJobEntry");
26 26
		ProScoreTaskJobEntry pstje = (ProScoreTaskJobEntry) bf.getBean("com_ekexiu_portal_job_ProScoreTaskJobEntry");
27 27
//		UserLogTaskJobEntry ultje = (UserLogTaskJobEntry) bf.getBean("com_ekexiu_portal_job_UserLogTaskJobEntry");
28
		DictTaskJobEntry dtje =(DictTaskJobEntry) bf.getBean("com_ekexiu_portal_job_DictTaskJobEntry");
28
		DictTaskJobEntry dtje = (DictTaskJobEntry) bf.getBean("com_ekexiu_portal_job_DictTaskJobEntry");
29
		HotKeyJobEntry hkje = (HotKeyJobEntry) bf.getBean("com_ekexiu_portal_job_HotKeyJobEntry");
29 30
		final WeixinService weixin =(WeixinService)bf.getBean("com_ekexiu_portal_service_WeixinService");
30 31
		
31 32
		long delayTime = tje.getDelayTime();
@ -44,6 +45,11 @@ public class TaskJob implements AfterBeanFactory {
44 45
		service.scheduleAtFixedRate(pstje, pstjeTaskTime, pstje.getDelayTime(), TimeUnit.MILLISECONDS);
45 46
//		service.scheduleAtFixedRate(ultje, taskTime, delayTime, TimeUnit.MILLISECONDS);
46 47
		service.scheduleAtFixedRate(dtje, 1, dtje.getDelayTime(), TimeUnit.SECONDS);
48
		
49
		long hkjeTask = getTimeMillis(hkje.getTaskTime());
50
		long hkjeTaskTime = hkjeTask - System.currentTimeMillis();
51
		hkjeTaskTime = hkjeTaskTime > 0 ? hkjeTaskTime : hkjeTaskTime + hkje.getDelayTime();
52
		service.scheduleAtFixedRate(hkje, hkjeTaskTime, hkje.getDelayTime(), TimeUnit.MILLISECONDS);
47 53
		service.scheduleAtFixedRate(new Runnable() {
48 54
			@Override
49 55
			public void run() {

+ 9 - 0
src/main/java/com/ekexiu/portal/po/ArticleRes.java

@ -14,6 +14,15 @@ public class ArticleRes implements CreateTimeSupported {
14 14
	private String articleId;
15 15
	private String resourceId;
16 16
	private String createTime;
17
	private Article article;
18

19
	public Article getArticle() {
20
		return article;
21
	}
22

23
	public void setArticle(Article article) {
24
		this.article = article;
25
	}
17 26

18 27
	@Column(DE.id_32)
19 28
	public String getArticleId() {

+ 13 - 0
src/main/java/com/ekexiu/portal/po/Resource.java

@ -6,6 +6,7 @@ import org.jfw.apt.orm.annotation.entry.Column;
6 6
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
7 7
import org.jfw.apt.orm.annotation.entry.Table;
8 8
import org.jfw.apt.orm.core.defaultImpl.FixLenStringHandler;
9
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
9 10
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
10 11
import org.jfw.apt.orm.core.enums.DE;
11 12

@ -60,6 +61,10 @@ public class Resource implements CreateTimeSupported, ModifyTimeSupported{
60 61
	 * 发布时间
61 62
	 */
62 63
	private String publishTime;
64
	/**
65
	 * 浏览量
66
	 */
67
	private int pageViews;
63 68
	
64 69
	public List<Image> getImages() {
65 70
		return images;
@ -216,4 +221,12 @@ public class Resource implements CreateTimeSupported, ModifyTimeSupported{
216 221
		this.publishTime = publishTime;
217 222
	}
218 223
	
224
	@Column(handlerClass=IntHandler.class,dbType="INTEGER",nullable=true,renewable=false)
225
	public int getPageViews() {
226
		return pageViews;
227
	}
228
	public void setPageViews(int pageViews) {
229
		this.pageViews = pageViews;
230
	}
231
	
219 232
}

+ 9 - 0
src/main/java/com/ekexiu/portal/pojo/DataDictCode.java

@ -1,8 +1,17 @@
1 1
package com.ekexiu.portal.pojo;
2 2

3 3
public class DataDictCode {
4
	private long count;
4 5
	private String caption;
5 6

7
	public long getCount() {
8
		return count;
9
	}
10

11
	public void setCount(long count) {
12
		this.count = count;
13
	}
14

6 15
	public String getCaption() {
7 16
		return caption;
8 17
	}

+ 45 - 1
src/main/java/com/ekexiu/portal/service/ArticleService.java

@ -10,6 +10,7 @@ import java.io.InputStream;
10 10
import java.sql.Connection;
11 11
import java.sql.SQLException;
12 12
import java.text.SimpleDateFormat;
13
import java.util.ArrayList;
13 14
import java.util.Date;
14 15
import java.util.List;
15 16

@ -243,7 +244,7 @@ public class ArticleService {
243 244
		File dateFile = new File(savePath);
244 245
		if (!dateFile.exists()) {
245 246
			// 创建日期目录
246
			dateFile.mkdir();
247
			dateFile.mkdirs();
247 248
		}
248 249
		IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "." + JPG)), src, true);
249 250
		IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "_s." + JPG)), shareResImage, true);
@ -518,6 +519,13 @@ public class ArticleService {
518 519
		this.articleDao.incPageViews(con, articleId);
519 520
	}
520 521
	
522
	@Post
523
	@Path("/updateDraft")
524
	public void updateDraft(@JdbcConn(true) Connection con, String articleId) throws SQLException{
525
		//修改文章状态为草稿
526
		this.articleDao.updateStatus(con, articleId, "0");
527
	}
528
	
521 529
	@Post
522 530
	@Path("/publish")
523 531
	public void publish(@JdbcConn(true) Connection con,String articleId) throws SQLException{
@ -631,6 +639,25 @@ public class ArticleService {
631 639
		return queryResult;
632 640
	}
633 641
	
642
	@Get
643
	@Path("/findHot")
644
	public PageQueryResult<FindInfo> queryFindHot(@JdbcConn Connection con,@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
645
		PageQueryResult<FindInfo> queryResult = this.articleDao.queryFindHot(con, pageSize, pageNo);
646
		List<FindInfo> findInfos = queryResult.getData();
647
		if(!findInfos.isEmpty()){
648
			for (FindInfo findInfo : findInfos) {
649
				if("3".equals(findInfo.getType())){
650
					List<Image> images = this.imagesService.queryRes(con, findInfo.getId());
651
					if(images.size() > 0){
652
						findInfo.setImage(images.get(0).getImageSrc());
653
					}
654
				}
655
			}
656
			queryResult.setData(findInfos);
657
		}
658
		return queryResult;
659
	}
660
	
634 661
	@Get
635 662
	@Path("/ralatePro")
636 663
	public List<ArticlePro> ralatePro(@JdbcConn Connection con,String articleId) throws SQLException{
@ -643,6 +670,23 @@ public class ArticleService {
643 670
		return this.articleResDao.query(con, articleId);
644 671
	}
645 672
	
673
	@Get
674
	@Path("/ralateArticles")
675
	public List<Article> ralateArticles(@JdbcConn Connection con,@Nullable String[] keys,@Nullable String professorId,
676
			@Nullable String orgId,String articleId,@DefaultValue("10") int rows)throws SQLException{
677
		List<Article> articles = new ArrayList<Article>();
678
		if(keys != null){
679
			articles = this.articleDao.queryLimit(con, keys, articleId, rows);
680
		}
681
		if(articles.isEmpty()){
682
			articles = this.articleDao.queryByAuthor(con, professorId, orgId, articleId, rows);
683
			if(articles.isEmpty()){
684
				articles = this.articleDao.queryByPageViews(con, articleId, rows);
685
			}
686
		}
687
		return articles;
688
	}
689
	
646 690
	@Post
647 691
	@Path("/delete")
648 692
	public void delete(@JdbcConn(true) Connection con, String articleId) throws SQLException{

+ 25 - 0
src/main/java/com/ekexiu/portal/service/DataDictService.java

@ -26,6 +26,7 @@ public class DataDictService {
26 26
	
27 27
	private volatile List<DataDictCode> hotSubjects = new ArrayList<DataDictCode>();
28 28
	private volatile List<DataDictCode> hotIndustries = new ArrayList<DataDictCode>();
29
	private volatile List<DataDictCode> hotKey = new ArrayList<DataDictCode>();
29 30
	
30 31
	@Autowrie
31 32
	private DataDictDao dataDictDao;
@ -66,6 +67,14 @@ public class DataDictService {
66 67
		this.hotIndustries = hotIndustries;
67 68
	}
68 69
70
	public List<DataDictCode> getHotKey() {
71
		return hotKey;
72
	}
73
74
	public void setHotKey(List<DataDictCode> hotKey) {
75
		this.hotKey = hotKey;
76
	}
77
69 78
	@Post
70 79
	@Path
71 80
	public void insert(@JdbcConn(true) Connection con,String dictCode,String code,@Nullable String parentCode,String caption,String descp ) throws SQLException
@ -103,6 +112,22 @@ public class DataDictService {
103 112
		 return this.queryDictCode(dictCode.equals("SUBJECT"));
104 113
	}
105 114
	
115
	@Get
116
	@Path("/qaHotKey")
117
	public List<DataDictCode> queryHotKey(String key){
118
		List<DataDictCode> hotKeys = this.getHotKey();
119
		List<DataDictCode> keys = new ArrayList<DataDictCode>();
120
		for (DataDictCode hotKey : hotKeys) {
121
			if(hotKey.getCaption().indexOf(key) != -1){
122
				DataDictCode hotKey2 = new DataDictCode();
123
				hotKey2.setCount(hotKey.getCount());
124
				hotKey2.setCaption(hotKey.getCaption());
125
				keys.add(hotKey2);
126
			}
127
		}
128
		return keys;
129
	}
130
	
106 131
	private List<DataDictCode> queryDictCode(boolean isSubject){
107 132
		List<DataDictCode> ret = null;
108 133
		if(isSubject){

+ 32 - 5
src/main/java/com/ekexiu/portal/service/ImagesService.java

@ -145,21 +145,48 @@ public class ImagesService {
145 145
		}
146 146
	}
147 147
	
148
	@Post
149
	@Path("/saveImg")
150 148
	public void saveImg(@JdbcConn(true) Connection con, String resourceId, String[] fns) 
151 149
			throws SQLException, IOException, JfwBaseException {
152 150
		for (int i = 0; i < fns.length; i++) {
153 151
			byte[] src = this.readTmpFile(fns[i]);
154 152
			src = JpgUtil.read(src);
155 153
			byte[] shareResImage = this.resImage(src, this.resImageMaxLen);
156
			IoUtil.saveStream(new FileOutputStream(new File(this.resourceDataPath + "/" + this.createDate(), resourceId + "_" + i+1 + "." + JPG)), src, true);
157
			IoUtil.saveStream(new FileOutputStream(new File(this.resourceDataPath + "/" + this.createDate(), resourceId + "_" + i+1 + "_s." + JPG)), shareResImage, true);
154
			File dateFile = new File(this.resourceDataPath + "/" + this.createDate());
155
			if (!dateFile.exists()) {
156
				// 创建日期目录
157
				dateFile.mkdirs();
158
			}
158 159
			Image image = new Image();
159 160
			String imageId = StringUtil.buildUUID();
160 161
			image.setImageId(imageId);
162
			IoUtil.saveStream(new FileOutputStream(new File(dateFile, imageId + "." + JPG)), src, true);
163
			IoUtil.saveStream(new FileOutputStream(new File(dateFile, imageId + "_s." + JPG)), shareResImage, true);
161 164
			image.setSort(i+1);
162
			String imageSrc = this.createDate() + "/" + resourceId + "_" + i+1 + "." + JPG;
165
			String imageSrc = this.createDate() + "/" + imageId + "." + JPG;
166
			image.setImageSrc(imageSrc);
167
			image.setResourceId(resourceId);
168
			this.imageDao.insert(con, image);
169
		}
170
	}
171
	
172
	public void saveFns(@JdbcConn(true) Connection con, String resourceId, String[] fns, int sort) 
173
			throws SQLException, IOException, JfwBaseException {
174
		for (int i = 0; i < fns.length; i++) {
175
			byte[] src = this.readTmpFile(fns[i]);
176
			src = JpgUtil.read(src);
177
			byte[] shareResImage = this.resImage(src, this.resImageMaxLen);
178
			File dateFile = new File(this.resourceDataPath + "/" + this.createDate());
179
			if (!dateFile.exists()) {
180
				// 创建日期目录
181
				dateFile.mkdirs();
182
			}
183
			Image image = new Image();
184
			String imageId = StringUtil.buildUUID();
185
			image.setImageId(imageId);
186
			IoUtil.saveStream(new FileOutputStream(new File(dateFile, imageId + "." + JPG)), src, true);
187
			IoUtil.saveStream(new FileOutputStream(new File(dateFile, imageId + "_s." + JPG)), shareResImage, true);
188
			image.setSort(sort+i+1);
189
			String imageSrc = this.createDate() + "/" + imageId + "." + JPG;
163 190
			image.setImageSrc(imageSrc);
164 191
			image.setResourceId(resourceId);
165 192
			this.imageDao.insert(con, image);

+ 148 - 9
src/main/java/com/ekexiu/portal/service/ResourceService.java

@ -4,6 +4,7 @@ import java.io.IOException;
4 4
import java.sql.Connection;
5 5
import java.sql.SQLException;
6 6
import java.text.SimpleDateFormat;
7
import java.util.ArrayList;
7 8
import java.util.Date;
8 9
import java.util.List;
9 10

@ -20,11 +21,15 @@ import org.jfw.util.PageQueryResult;
20 21
import org.jfw.util.StringUtil;
21 22
import org.jfw.util.exception.JfwBaseException;
22 23

24
import com.ekexiu.portal.dao.ArticleDao;
25
import com.ekexiu.portal.dao.ArticleResDao;
23 26
import com.ekexiu.portal.dao.ImageDao;
24 27
import com.ekexiu.portal.dao.OperationDao;
25 28
import com.ekexiu.portal.dao.ProfessorDao;
26 29
import com.ekexiu.portal.dao.ResourceDao;
27 30
import com.ekexiu.portal.dao.WatchDao;
31
import com.ekexiu.portal.po.ArticleRes;
32
import com.ekexiu.portal.po.Image;
28 33
import com.ekexiu.portal.po.Operation;
29 34
import com.ekexiu.portal.po.Resource;
30 35
import com.ekexiu.portal.pojo.EditProfessor;
@ -48,6 +53,10 @@ public class ResourceService {
48 53
	private OperationDao operationDao;
49 54
	@Autowrie
50 55
	private GrowthLogService growthLogService;
56
	@Autowrie
57
	private ArticleResDao articleResDao;
58
	@Autowrie
59
	private ArticleDao articleDao;
51 60

52 61
	public String getTimeFormat() {
53 62
		return timeFormat;
@ -121,6 +130,22 @@ public class ResourceService {
121 130
		this.growthLogService = growthLogService;
122 131
	}
123 132
	
133
	public ArticleResDao getArticleResDao() {
134
		return articleResDao;
135
	}
136

137
	public void setArticleResDao(ArticleResDao articleResDao) {
138
		this.articleResDao = articleResDao;
139
	}
140

141
	public ArticleDao getArticleDao() {
142
		return articleDao;
143
	}
144

145
	public void setArticleDao(ArticleDao articleDao) {
146
		this.articleDao = articleDao;
147
	}
148

124 149
	private String publishTime(){
125 150
		SimpleDateFormat df = new SimpleDateFormat(this.timeFormat);
126 151
		String publishTime = df.format(new Date());
@ -143,7 +168,7 @@ public class ResourceService {
143 168
	
144 169
	@Post
145 170
	@Path("/save")
146
	public String save(@JdbcConn(true) Connection con, Resource resource, @Nullable String[] fns) 
171
	public String save(@JdbcConn(true) Connection con, Resource resource, @Nullable String[] fns, @Nullable String[] imageIds) 
147 172
			throws JfwBaseException, SQLException, IOException {
148 173
		if(resource.getResourceId() == null){
149 174
			String resourceId = StringUtil.buildUUID();
@ -152,14 +177,31 @@ public class ResourceService {
152 177
			}
153 178
			resource.setResourceId(resourceId);
154 179
			resource.setStatus("1");
180
			resource.setPageViews(0);
155 181
			resource.setPublishTime(this.publishTime());
156 182
			this.resourceDao.insert(con, resource);
157 183
			//this.growthLogService.addResource(con, resource.getProfessorId());
158 184
			return resourceId;
159 185
		}else if(resource.getResourceId().trim().length() == 32){
186
			int imageLength = 0;
187
			if(imageIds != null){
188
				imageLength = imageIds.length;
189
				List<Image> images = this.imageDao.queryRes(con, resource.getResourceId());
190
				for (int i = 0; i < imageLength; i++) {
191
					for (Image image : images) {
192
						if(image.getImageId().equals(imageIds[i])){
193
							this.imageDao.updateSort(con, image.getImageId(), i+1);
194
						}else{
195
							this.imageDao.deleteId(con, image.getImageId());
196
						}
197
					}
198
				}
199
			}
160 200
			if(fns != null){
161
				this.imageDao.deleteRes(con, resource.getResourceId());
162
				this.imagesService.saveImg(con, resource.getResourceId(), fns);
201
				if(imageIds == null){
202
					this.imageDao.deleteRes(con, resource.getResourceId());
203
				}
204
				this.imagesService.saveFns(con, resource.getResourceId(), fns, imageLength);
163 205
			}
164 206
			this.resourceDao.update(con, resource);
165 207
			this.resourceDao.updatePublishTime(con, resource.getResourceId(), "1", this.publishTime());
@ -171,7 +213,7 @@ public class ResourceService {
171 213
	
172 214
	@Post
173 215
	@Path("/draft")
174
	public String draft(@JdbcConn(true) Connection con, Resource resource, @Nullable String[] fns) 
216
	public String draft(@JdbcConn(true) Connection con, Resource resource, @Nullable String[] fns, @Nullable String[] imageIds) 
175 217
			throws SQLException, IOException, JfwBaseException{
176 218
		if(resource.getResourceId() == null){
177 219
			String resourceId = StringUtil.buildUUID();
@ -180,12 +222,29 @@ public class ResourceService {
180 222
			}
181 223
			resource.setResourceId(resourceId);
182 224
			resource.setStatus("0");
225
			resource.setPageViews(0);
183 226
			this.resourceDao.insert(con, resource);
184 227
			return resourceId;
185 228
		}else if(resource.getResourceId().trim().length() == 32){
229
			int imageLength = 0;
230
			if(imageIds != null){
231
				imageLength = imageIds.length;
232
				List<Image> images = this.imageDao.queryRes(con, resource.getResourceId());
233
				for (int i = 0; i < imageLength; i++) {
234
					for (Image image : images) {
235
						if(image.getImageId().equals(imageIds[i])){
236
							this.imageDao.updateSort(con, image.getImageId(), i+1);
237
						}else{
238
							this.imageDao.deleteId(con, image.getImageId());
239
						}
240
					}
241
				}
242
			}
186 243
			if(fns != null){
187
				this.imageDao.deleteRes(con, resource.getResourceId());
188
				this.imagesService.saveImg(con, resource.getResourceId(), fns);
244
				if(imageIds == null){
245
					this.imageDao.deleteRes(con, resource.getResourceId());
246
				}
247
				this.imagesService.saveFns(con, resource.getResourceId(), fns, imageLength);
189 248
			}
190 249
			this.resourceDao.update(con, resource);
191 250
			this.resourceDao.updateStatus(con, resource.getResourceId(), "0");
@ -197,7 +256,7 @@ public class ResourceService {
197 256
	
198 257
	@Post
199 258
	@Path("/timing")
200
	public String timing(@JdbcConn(true) Connection con, Resource resource, @Nullable String[] fns) 
259
	public String timing(@JdbcConn(true) Connection con, Resource resource, @Nullable String[] fns, @Nullable String[] imageIds) 
201 260
			throws SQLException, IOException, JfwBaseException{
202 261
		if(resource.getResourceId() == null){
203 262
			String resourceId = StringUtil.buildUUID();
@ -206,12 +265,29 @@ public class ResourceService {
206 265
			}
207 266
			resource.setResourceId(resourceId);
208 267
			resource.setStatus("2");
268
			resource.setPageViews(0);
209 269
			this.resourceDao.insert(con, resource);
210 270
			return resourceId;
211 271
		}else if(resource.getResourceId().trim().length() == 32){
272
			int imageLength = 0;
273
			if(imageIds != null){
274
				imageLength = imageIds.length;
275
				List<Image> images = this.imageDao.queryRes(con, resource.getResourceId());
276
				for (int i = 0; i < imageLength; i++) {
277
					for (Image image : images) {
278
						if(image.getImageId().equals(imageIds[i])){
279
							this.imageDao.updateSort(con, image.getImageId(), i+1);
280
						}else{
281
							this.imageDao.deleteId(con, image.getImageId());
282
						}
283
					}
284
				}
285
			}
212 286
			if(fns != null){
213
				this.imageDao.deleteRes(con, resource.getResourceId());
214
				this.imagesService.saveImg(con, resource.getResourceId(), fns);
287
				if(imageIds == null){
288
					this.imageDao.deleteRes(con, resource.getResourceId());
289
				}
290
				this.imagesService.saveFns(con, resource.getResourceId(), fns, imageLength);
215 291
			}
216 292
			this.resourceDao.update(con, resource);
217 293
			this.resourceDao.updatePublishTime(con, resource.getResourceId(), "2", resource.getPublishTime());
@ -252,6 +328,12 @@ public class ResourceService {
252 328
		this.resourceDao.update(con, resource);
253 329
	}
254 330
	
331
	@Post
332
	@Path("/pageViews")
333
	public void pageViews(@JdbcConn(true) Connection con,String resourceId) throws SQLException{
334
		this.resourceDao.incPageViews(con, resourceId);
335
	}
336
	
255 337
	@Get
256 338
	@Path("/{resourceId}")
257 339
	public Resource query(@JdbcConn Connection con, @PathVar String resourceId) throws SQLException {
@ -277,6 +359,63 @@ public class ResourceService {
277 359
		return resource;
278 360
	}
279 361
	
362
	@Get
363
	@Path("/pqSelf")
364
	public PageQueryResult<Resource> queryPageSelf(@JdbcConn Connection con,String professorId,@Nullable String key,
365
			@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
366
		if(key != null){
367
			key = "%" + key + "%";
368
		}
369
		PageQueryResult<Resource> queryResult = this.resourceDao.queryForSelf(con, professorId, key, pageSize, pageNo);
370
		List<Resource> resources = queryResult.getData();
371
		if(!resources.isEmpty()){
372
			for (Resource resource : resources) {
373
				resource.setImages(this.imagesService.queryRes(con, resource.getResourceId()));
374
			}
375
			queryResult.setData(resources);
376
		}
377
		return queryResult;
378
	}
379
	
380
	@Get
381
	@Path("/ralateRes")
382
	public List<Resource> queryLimit(@JdbcConn Connection con,@Nullable String[] keys,String resourceId,
383
			String professorId,@DefaultValue("10") int rows)throws SQLException{
384
		List<Resource> resources = new ArrayList<Resource>();
385
		if(keys != null){
386
			resources = this.resourceDao.queryLimit(con, keys, resourceId, rows);
387
		}
388
		if(resources.isEmpty()){
389
			resources = this.resourceDao.queryByProId(con, professorId, resourceId, rows);
390
			if(resources.isEmpty()){
391
				resources = this.resourceDao.queryByProId(con, null, resourceId, rows);
392
			}
393
		}
394
		if(!resources.isEmpty()){
395
			for (Resource resource : resources) {
396
				resource.setImages(this.imagesService.queryRes(con, resource.getResourceId()));
397
				EditProfessor professor = this.professorDao.queryBaseInfo(con, resource.getProfessorId());
398
				if(professor != null){
399
					professor.setHasHeadImage(this.imageService.hasProfessorImage(professor.getId()));
400
				}
401
				resource.setEditProfessor(professor);
402
			}
403
		}
404
		return resources;
405
	}
406
	
407
	@Get
408
	@Path("/articles")
409
	public List<ArticleRes> queryArticles(@JdbcConn Connection con, String resourceId, @DefaultValue("5") int rows) throws SQLException{
410
		List<ArticleRes> articleRes = this.articleResDao.queryArticles(con, resourceId, rows);
411
		if(!articleRes.isEmpty()){
412
			for (ArticleRes res : articleRes) {
413
				res.setArticle(this.articleDao.queryOne(con, res.getArticleId()));
414
			}
415
		}
416
		return articleRes;
417
	}
418
	
280 419
	@Get
281 420
	@Path("/resourceInfo")
282 421
	public Resource queryInfo(@JdbcConn Connection con, String resourceId) throws SQLException {