Browse Source

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

zzy.zhiyuan.foxmail 8 years ago
parent
commit
1182afd5a5

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

99
	@Nullable
99
	@Nullable
100
	public abstract Article queryOne(Connection con, String articleId) throws SQLException;
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
	@PageSelect
366
	@PageSelect
103
	@OrderBy("ORDER BY PUBLISH_TIME DESC")
367
	@OrderBy("ORDER BY PUBLISH_TIME DESC")
104
	@Where("STATUS = '1'")
368
	@Where("STATUS = '1'")
213
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
477
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
214
        }
478
        }
215
        ps = con.prepareStatement(sql.toString());
479
        ps = con.prepareStatement(sql.toString());
216
        System.out.println(sql.toString());
217
        index = 1;
480
        index = 1;
218
        try{
481
        try{
219
        	if(hasProfessorId){
482
        	if(hasProfessorId){
386
            try{ps.close();}catch(Exception e4){}
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
	@DefaultValue("0")
30
	@DefaultValue("0")
31
	public abstract int queryByArticleId(Connection con, String articleId) throws SQLException;
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
        int index = 1;
34
        int index = 1;
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 = ?";
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
        PreparedStatement ps = con.prepareStatement(sql);
36
        PreparedStatement ps = con.prepareStatement(sql);
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
	@DeleteWith
84
	@DeleteWith
59
	@From(ArticleRes.class)
85
	@From(ArticleRes.class)
60
	public abstract int delete(Connection con, String articleId) throws SQLException;
86
	public abstract int delete(Connection con, String articleId) throws SQLException;

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

11
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
11
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
12
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
12
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
13
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
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
import com.ekexiu.portal.po.Image;
17
import com.ekexiu.portal.po.Image;
16

18

19
	@Insert
21
	@Insert
20
	public abstract int insert(Connection con, Image image) throws SQLException;
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
	@SelectOne
28
	@SelectOne
23
	@Nullable
29
	@Nullable
24
	public abstract Image query(Connection con, String imageId) throws SQLException;
30
	public abstract Image query(Connection con, String imageId) throws SQLException;

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

14
import org.jfw.apt.orm.annotation.dao.Dynamic;
14
import org.jfw.apt.orm.annotation.dao.Dynamic;
15
import org.jfw.apt.orm.annotation.dao.method.From;
15
import org.jfw.apt.orm.annotation.dao.method.From;
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.Where;
18
import org.jfw.apt.orm.annotation.dao.method.Where;
18
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
19
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
19
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
20
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
63
	@Dynamic
64
	@Dynamic
64
	public abstract int updateRes(Connection con,Resource resource) throws SQLException;
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
	@UpdateWith
72
	@UpdateWith
67
	@From(Resource.class)
73
	@From(Resource.class)
68
	public abstract int updateStatus(Connection con, String resourceId, @Set String status) throws SQLException;
74
	public abstract int updateStatus(Connection con, String resourceId, @Set String status) throws SQLException;
108
	@Nullable
114
	@Nullable
109
	public abstract Resource queryOne(Connection con, String resourceId) throws SQLException;
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
	 * 查询资源基础信息(ID,名称,学术领域,应用行业,可提供服务,发布者ID,资源图片)
473
	 * 查询资源基础信息(ID,名称,学术领域,应用行业,可提供服务,发布者ID,资源图片)
113
	 * @param con
474
	 * @param con

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

10

10

11
import javax.sql.DataSource;
11
import javax.sql.DataSource;
12

12

13
import org.apache.log4j.Logger;
14
import org.jfw.apt.annotation.Autowrie;
13
import org.jfw.apt.annotation.Autowrie;
15
import org.jfw.apt.annotation.Bean;
14
import org.jfw.apt.annotation.Bean;
16
import org.jfw.util.ListUtil;
15
import org.jfw.util.ListUtil;
19
import com.ekexiu.portal.service.DataDictService;
18
import com.ekexiu.portal.service.DataDictService;
20
@Bean
19
@Bean
21
public class DictTaskJobEntry implements Runnable{
20
public class DictTaskJobEntry implements Runnable{
22
	private static Logger logger = Logger.getLogger(TaskJobEntry.class);
23
	private long delayTime = 600;
21
	private long delayTime = 600;
24
	private int maxCount = 20;
22
	private int maxCount = 20;
25
	@Autowrie("dataSource")
23
	@Autowrie("dataSource")
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
		Items items = new Items();
90
		Items items = new Items();
93
		Statement st = con.createStatement();
91
		Statement st = con.createStatement();
94
		try {
92
		try {
121
		}
119
		}
122
	}
120
	}
123

121

124
	private static class Items{
122
	protected static class Items{
125
		private List<Item> items = new ArrayList<Item>();
123
		private List<Item> items = new ArrayList<Item>();
126
		
124
		
127
		public void add(String itemCaption){
125
		public void add(String itemCaption){
138
			if(limit >= items.size()) return items;
136
			if(limit >= items.size()) return items;
139
			return items.subList(0, limit);
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
		private String caption;
145
		private String caption;
144
		private long value = 1;
146
		private long value = 1;
145

147

154
		public void setCaption(String caption) {
156
		public void setCaption(String caption) {
155
			this.caption = caption;
157
			this.caption = caption;
156
		}
158
		}
157

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

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

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
		TaskJobEntry tje = (TaskJobEntry) bf.getBean("com_ekexiu_portal_job_TaskJobEntry");
25
		TaskJobEntry tje = (TaskJobEntry) bf.getBean("com_ekexiu_portal_job_TaskJobEntry");
26
		ProScoreTaskJobEntry pstje = (ProScoreTaskJobEntry) bf.getBean("com_ekexiu_portal_job_ProScoreTaskJobEntry");
26
		ProScoreTaskJobEntry pstje = (ProScoreTaskJobEntry) bf.getBean("com_ekexiu_portal_job_ProScoreTaskJobEntry");
27
//		UserLogTaskJobEntry ultje = (UserLogTaskJobEntry) bf.getBean("com_ekexiu_portal_job_UserLogTaskJobEntry");
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
		final WeixinService weixin =(WeixinService)bf.getBean("com_ekexiu_portal_service_WeixinService");
30
		final WeixinService weixin =(WeixinService)bf.getBean("com_ekexiu_portal_service_WeixinService");
30
		
31
		
31
		long delayTime = tje.getDelayTime();
32
		long delayTime = tje.getDelayTime();
44
		service.scheduleAtFixedRate(pstje, pstjeTaskTime, pstje.getDelayTime(), TimeUnit.MILLISECONDS);
45
		service.scheduleAtFixedRate(pstje, pstjeTaskTime, pstje.getDelayTime(), TimeUnit.MILLISECONDS);
45
//		service.scheduleAtFixedRate(ultje, taskTime, delayTime, TimeUnit.MILLISECONDS);
46
//		service.scheduleAtFixedRate(ultje, taskTime, delayTime, TimeUnit.MILLISECONDS);
46
		service.scheduleAtFixedRate(dtje, 1, dtje.getDelayTime(), TimeUnit.SECONDS);
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
		service.scheduleAtFixedRate(new Runnable() {
53
		service.scheduleAtFixedRate(new Runnable() {
48
			@Override
54
			@Override
49
			public void run() {
55
			public void run() {

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

14
	private String articleId;
14
	private String articleId;
15
	private String resourceId;
15
	private String resourceId;
16
	private String createTime;
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
	@Column(DE.id_32)
27
	@Column(DE.id_32)
19
	public String getArticleId() {
28
	public String getArticleId() {

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

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

12

60
	 * 发布时间
61
	 * 发布时间
61
	 */
62
	 */
62
	private String publishTime;
63
	private String publishTime;
64
	/**
65
	 * 浏览量
66
	 */
67
	private int pageViews;
63
	
68
	
64
	public List<Image> getImages() {
69
	public List<Image> getImages() {
65
		return images;
70
		return images;
216
		this.publishTime = publishTime;
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
package com.ekexiu.portal.pojo;
1
package com.ekexiu.portal.pojo;
2

2

3
public class DataDictCode {
3
public class DataDictCode {
4
	private long count;
4
	private String caption;
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
	public String getCaption() {
15
	public String getCaption() {
7
		return caption;
16
		return caption;
8
	}
17
	}

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

10
import java.sql.Connection;
10
import java.sql.Connection;
11
import java.sql.SQLException;
11
import java.sql.SQLException;
12
import java.text.SimpleDateFormat;
12
import java.text.SimpleDateFormat;
13
import java.util.ArrayList;
13
import java.util.Date;
14
import java.util.Date;
14
import java.util.List;
15
import java.util.List;
15

16

243
		File dateFile = new File(savePath);
244
		File dateFile = new File(savePath);
244
		if (!dateFile.exists()) {
245
		if (!dateFile.exists()) {
245
			// 创建日期目录
246
			// 创建日期目录
246
			dateFile.mkdir();
247
			dateFile.mkdirs();
247
		}
248
		}
248
		IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "." + JPG)), src, true);
249
		IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "." + JPG)), src, true);
249
		IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "_s." + JPG)), shareResImage, true);
250
		IoUtil.saveStream(new FileOutputStream(new File(dateFile, id + "_s." + JPG)), shareResImage, true);
518
		this.articleDao.incPageViews(con, articleId);
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
	@Post
529
	@Post
522
	@Path("/publish")
530
	@Path("/publish")
523
	public void publish(@JdbcConn(true) Connection con,String articleId) throws SQLException{
531
	public void publish(@JdbcConn(true) Connection con,String articleId) throws SQLException{
631
		return queryResult;
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
	@Get
661
	@Get
635
	@Path("/ralatePro")
662
	@Path("/ralatePro")
636
	public List<ArticlePro> ralatePro(@JdbcConn Connection con,String articleId) throws SQLException{
663
	public List<ArticlePro> ralatePro(@JdbcConn Connection con,String articleId) throws SQLException{
643
		return this.articleResDao.query(con, articleId);
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
	@Post
690
	@Post
647
	@Path("/delete")
691
	@Path("/delete")
648
	public void delete(@JdbcConn(true) Connection con, String articleId) throws SQLException{
692
	public void delete(@JdbcConn(true) Connection con, String articleId) throws SQLException{

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

26
	
26
	
27
	private volatile List<DataDictCode> hotSubjects = new ArrayList<DataDictCode>();
27
	private volatile List<DataDictCode> hotSubjects = new ArrayList<DataDictCode>();
28
	private volatile List<DataDictCode> hotIndustries = new ArrayList<DataDictCode>();
28
	private volatile List<DataDictCode> hotIndustries = new ArrayList<DataDictCode>();
29
	private volatile List<DataDictCode> hotKey = new ArrayList<DataDictCode>();
29
	
30
	
30
	@Autowrie
31
	@Autowrie
31
	private DataDictDao dataDictDao;
32
	private DataDictDao dataDictDao;
66
		this.hotIndustries = hotIndustries;
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
	@Post
78
	@Post
70
	@Path
79
	@Path
71
	public void insert(@JdbcConn(true) Connection con,String dictCode,String code,@Nullable String parentCode,String caption,String descp ) throws SQLException
80
	public void insert(@JdbcConn(true) Connection con,String dictCode,String code,@Nullable String parentCode,String caption,String descp ) throws SQLException
103
		 return this.queryDictCode(dictCode.equals("SUBJECT"));
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
	private List<DataDictCode> queryDictCode(boolean isSubject){
131
	private List<DataDictCode> queryDictCode(boolean isSubject){
107
		List<DataDictCode> ret = null;
132
		List<DataDictCode> ret = null;
108
		if(isSubject){
133
		if(isSubject){

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

145
		}
145
		}
146
	}
146
	}
147
	
147
	
148
	@Post
149
	@Path("/saveImg")
150
	public void saveImg(@JdbcConn(true) Connection con, String resourceId, String[] fns) 
148
	public void saveImg(@JdbcConn(true) Connection con, String resourceId, String[] fns) 
151
			throws SQLException, IOException, JfwBaseException {
149
			throws SQLException, IOException, JfwBaseException {
152
		for (int i = 0; i < fns.length; i++) {
150
		for (int i = 0; i < fns.length; i++) {
153
			byte[] src = this.readTmpFile(fns[i]);
151
			byte[] src = this.readTmpFile(fns[i]);
154
			src = JpgUtil.read(src);
152
			src = JpgUtil.read(src);
155
			byte[] shareResImage = this.resImage(src, this.resImageMaxLen);
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
			Image image = new Image();
159
			Image image = new Image();
159
			String imageId = StringUtil.buildUUID();
160
			String imageId = StringUtil.buildUUID();
160
			image.setImageId(imageId);
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
			image.setSort(i+1);
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
			image.setImageSrc(imageSrc);
190
			image.setImageSrc(imageSrc);
164
			image.setResourceId(resourceId);
191
			image.setResourceId(resourceId);
165
			this.imageDao.insert(con, image);
192
			this.imageDao.insert(con, image);

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

4
import java.sql.Connection;
4
import java.sql.Connection;
5
import java.sql.SQLException;
5
import java.sql.SQLException;
6
import java.text.SimpleDateFormat;
6
import java.text.SimpleDateFormat;
7
import java.util.ArrayList;
7
import java.util.Date;
8
import java.util.Date;
8
import java.util.List;
9
import java.util.List;
9

10

20
import org.jfw.util.StringUtil;
21
import org.jfw.util.StringUtil;
21
import org.jfw.util.exception.JfwBaseException;
22
import org.jfw.util.exception.JfwBaseException;
22

23

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

60

52
	public String getTimeFormat() {
61
	public String getTimeFormat() {
53
		return timeFormat;
62
		return timeFormat;
121
		this.growthLogService = growthLogService;
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
	private String publishTime(){
149
	private String publishTime(){
125
		SimpleDateFormat df = new SimpleDateFormat(this.timeFormat);
150
		SimpleDateFormat df = new SimpleDateFormat(this.timeFormat);
126
		String publishTime = df.format(new Date());
151
		String publishTime = df.format(new Date());
143
	
168
	
144
	@Post
169
	@Post
145
	@Path("/save")
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
			throws JfwBaseException, SQLException, IOException {
172
			throws JfwBaseException, SQLException, IOException {
148
		if(resource.getResourceId() == null){
173
		if(resource.getResourceId() == null){
149
			String resourceId = StringUtil.buildUUID();
174
			String resourceId = StringUtil.buildUUID();
152
			}
177
			}
153
			resource.setResourceId(resourceId);
178
			resource.setResourceId(resourceId);
154
			resource.setStatus("1");
179
			resource.setStatus("1");
180
			resource.setPageViews(0);
155
			resource.setPublishTime(this.publishTime());
181
			resource.setPublishTime(this.publishTime());
156
			this.resourceDao.insert(con, resource);
182
			this.resourceDao.insert(con, resource);
157
			//this.growthLogService.addResource(con, resource.getProfessorId());
183
			//this.growthLogService.addResource(con, resource.getProfessorId());
158
			return resourceId;
184
			return resourceId;
159
		}else if(resource.getResourceId().trim().length() == 32){
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
			if(fns != null){
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
			this.resourceDao.update(con, resource);
206
			this.resourceDao.update(con, resource);
165
			this.resourceDao.updatePublishTime(con, resource.getResourceId(), "1", this.publishTime());
207
			this.resourceDao.updatePublishTime(con, resource.getResourceId(), "1", this.publishTime());
171
	
213
	
172
	@Post
214
	@Post
173
	@Path("/draft")
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
			throws SQLException, IOException, JfwBaseException{
217
			throws SQLException, IOException, JfwBaseException{
176
		if(resource.getResourceId() == null){
218
		if(resource.getResourceId() == null){
177
			String resourceId = StringUtil.buildUUID();
219
			String resourceId = StringUtil.buildUUID();
180
			}
222
			}
181
			resource.setResourceId(resourceId);
223
			resource.setResourceId(resourceId);
182
			resource.setStatus("0");
224
			resource.setStatus("0");
225
			resource.setPageViews(0);
183
			this.resourceDao.insert(con, resource);
226
			this.resourceDao.insert(con, resource);
184
			return resourceId;
227
			return resourceId;
185
		}else if(resource.getResourceId().trim().length() == 32){
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
			if(fns != null){
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
			this.resourceDao.update(con, resource);
249
			this.resourceDao.update(con, resource);
191
			this.resourceDao.updateStatus(con, resource.getResourceId(), "0");
250
			this.resourceDao.updateStatus(con, resource.getResourceId(), "0");
197
	
256
	
198
	@Post
257
	@Post
199
	@Path("/timing")
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
			throws SQLException, IOException, JfwBaseException{
260
			throws SQLException, IOException, JfwBaseException{
202
		if(resource.getResourceId() == null){
261
		if(resource.getResourceId() == null){
203
			String resourceId = StringUtil.buildUUID();
262
			String resourceId = StringUtil.buildUUID();
206
			}
265
			}
207
			resource.setResourceId(resourceId);
266
			resource.setResourceId(resourceId);
208
			resource.setStatus("2");
267
			resource.setStatus("2");
268
			resource.setPageViews(0);
209
			this.resourceDao.insert(con, resource);
269
			this.resourceDao.insert(con, resource);
210
			return resourceId;
270
			return resourceId;
211
		}else if(resource.getResourceId().trim().length() == 32){
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
			if(fns != null){
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
			this.resourceDao.update(con, resource);
292
			this.resourceDao.update(con, resource);
217
			this.resourceDao.updatePublishTime(con, resource.getResourceId(), "2", resource.getPublishTime());
293
			this.resourceDao.updatePublishTime(con, resource.getResourceId(), "2", resource.getPublishTime());
252
		this.resourceDao.update(con, resource);
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
	@Get
337
	@Get
256
	@Path("/{resourceId}")
338
	@Path("/{resourceId}")
257
	public Resource query(@JdbcConn Connection con, @PathVar String resourceId) throws SQLException {
339
	public Resource query(@JdbcConn Connection con, @PathVar String resourceId) throws SQLException {
277
		return resource;
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
	@Get
419
	@Get
281
	@Path("/resourceInfo")
420
	@Path("/resourceInfo")
282
	public Resource queryInfo(@JdbcConn Connection con, String resourceId) throws SQLException {
421
	public Resource queryInfo(@JdbcConn Connection con, String resourceId) throws SQLException {