Browse Source

Merge remote-tracking branch 'origin/test'

jiapeng 7 years ago
parent
commit
e9debfd10f

+ 5 - 0
src/main/java/com/ekexiu/portal/cms/ContentType.java

@ -0,0 +1,5 @@
1
package com.ekexiu.portal.cms;
2

3
public enum ContentType {
4
	Article,Paper,Patent
5
}

+ 18 - 0
src/main/java/com/ekexiu/portal/cms/Node.java

@ -0,0 +1,18 @@
1
package com.ekexiu.portal.cms;
2

3
public class Node {
4
	private ContentType type;
5
	private Object key;
6
	public ContentType getType() {
7
		return type;
8
	}
9
	public void setType(ContentType type) {
10
		this.type = type;
11
	}
12
	public Object getKey() {
13
		return key;
14
	}
15
	public void setKey(Object key) {
16
		this.key = key;
17
	}
18
}

+ 406 - 18
src/main/java/com/ekexiu/portal/cms/TemplateService.java

@ -7,10 +7,32 @@ import java.io.OutputStream;
7 7
import java.io.OutputStreamWriter;
8 8
import java.io.Reader;
9 9
import java.io.StringReader;
10
import java.sql.Connection;
11
import java.sql.PreparedStatement;
12
import java.sql.ResultSet;
13
import java.sql.SQLException;
14
import java.util.HashMap;
10 15
import java.util.Map;
16
import java.util.Queue;
17
import java.util.concurrent.ConcurrentLinkedQueue;
11 18

19
import javax.sql.DataSource;
20

21
import org.jfw.apt.annotation.Autowrie;
12 22
import org.jfw.apt.web.annotation.Path;
23
import org.jfw.apt.web.annotation.operate.Get;
24
import org.jfw.apt.web.annotation.operate.Post;
13 25
import org.jfw.util.ConstData;
26
import org.jfw.util.json.JsonService;
27
import org.jfw.util.log.LogFactory;
28
import org.jfw.util.log.Logger;
29

30
import com.ekexiu.portal.dao.ArticleDao;
31
import com.ekexiu.portal.dao.PpaperDao;
32
import com.ekexiu.portal.dao.PpatentDao;
33
import com.ekexiu.portal.po.Article;
34
import com.ekexiu.portal.po.Ppaper;
35
import com.ekexiu.portal.po.Ppatent;
14 36

15 37
import freemarker.cache.TemplateLoader;
16 38
import freemarker.template.Configuration;
@ -20,9 +42,70 @@ import freemarker.template.TemplateExceptionHandler;
20 42

21 43
@Path("/cms")
22 44
public class TemplateService {
23
	
45
	private static final Logger log = LogFactory.getLog(TemplateService.class);
46

47
	private final Queue<Node> queue = new ConcurrentLinkedQueue<Node>();
48

49
	@SuppressWarnings("unused")
24 50
	private File source;
25
	private Configuration cfg =  new Configuration(Configuration.VERSION_2_3_26);
51

52
	private Configuration cfg = new Configuration(Configuration.VERSION_2_3_26);
53

54
	private long rate = 10000;
55
	
56
	private long lastIndexStatic = 0;
57
	
58
	private long indexRate = 24*60*60*1000;
59

60
	@Autowrie
61
	private ArticleDao articleDao;
62
	@Autowrie
63
	private PpaperDao ppaperDao;
64
	@Autowrie
65
	private PpatentDao ppatentDao;
66

67
	private File dir;
68

69
	public File getDir() {
70
		return dir;
71
	}
72

73
	public void setDir(File dir) {
74
		this.dir = dir;
75
	}
76

77
	public ArticleDao getArticleDao() {
78
		return articleDao;
79
	}
80

81
	public void setArticleDao(ArticleDao articleDao) {
82
		this.articleDao = articleDao;
83
	}
84

85
	public PpaperDao getPpaperDao() {
86
		return ppaperDao;
87
	}
88

89
	public void setPpaperDao(PpaperDao ppaperDao) {
90
		this.ppaperDao = ppaperDao;
91
	}
92

93
	public PpatentDao getPpatentDao() {
94
		return ppatentDao;
95
	}
96

97
	public void setPpatentDao(PpatentDao ppatentDao) {
98
		this.ppatentDao = ppatentDao;
99
	}
100

101
	public long getRate() {
102
		return rate;
103
	}
104

105
	public void setRate(long rate) {
106
		this.rate = rate;
107
	}
108

26 109
	public void setSource(File source) {
27 110
		this.source = source;
28 111
		try {
@ -32,20 +115,20 @@ public class TemplateService {
32 115
			this.cfg.setTemplateLoader(new TemplateLoader() {
33 116
				@Override
34 117
				public Reader getReader(Object templateSource, String encoding) throws IOException {
35
					StringReader reader = new StringReader("TemplateService'source is invalid dir,so "+templateSource.toString()+" can't read");
118
					StringReader reader = new StringReader("TemplateService'source is invalid dir,so " + templateSource.toString() + " can't read");
36 119
					return reader;
37 120
				}
38
				
121

39 122
				@Override
40 123
				public long getLastModified(Object templateSource) {
41 124
					return 0;
42 125
				}
43
				
126

44 127
				@Override
45 128
				public Object findTemplateSource(String name) throws IOException {
46 129
					return name;
47 130
				}
48
				
131

49 132
				@Override
50 133
				public void closeTemplateSource(Object templateSource) throws IOException {
51 134
				}
@ -53,15 +136,18 @@ public class TemplateService {
53 136
		}
54 137
		cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
55 138
	}
56
	
57
	
58
	public void genCnt(String templateName,File dest,Map<String,Object> root) throws IOException, TemplateException{
59
		if(dest.exists()){
60
			if(!dest.delete()){
61
				throw new IOException("delete file["+dest.getAbsolutePath()+"] error");
139

140
	public void genCnt(String templateName, File dest, Map<String, Object> root) throws IOException, TemplateException {
141
		if (dest.exists()) {
142
			if (!dest.delete()) {
143
				throw new IOException("delete file[" + dest.getAbsolutePath() + "] error");
62 144
			}
63 145
		}
64
		Template template = this.cfg.getTemplate(templateName,"UTF-8");
146
		File parent = dest.getParentFile();
147
		if (!parent.exists()) {
148
			parent.mkdirs();
149
		}
150
		Template template = this.cfg.getTemplate(templateName, "UTF-8");
65 151
		OutputStream out = new FileOutputStream(dest);
66 152
		try {
67 153
			template.process(root, new OutputStreamWriter(out, ConstData.UTF8));
@ -70,15 +156,317 @@ public class TemplateService {
70 156
			out.close();
71 157
		}
72 158
	}
73
	
74
	
75
	
76 159

160
	public void push(ContentType type, Object key) {
161
		Node node = new Node();
162
		node.setType(type);
163
		node.setKey(key);
164
		this.queue.add(node);
165
	}
166

167
	@Get
168
	@Post
169
	@Path()
170
	public void push(String t, String k) {
171
		ContentType type = null;
172
		try {
173
			type = ContentType.valueOf(t);
174
		} catch (Throwable thr) {
175
		}
176
		if (type != null) {
177
			this.push(type, k);
178
		}
179
	}
180

181
	public synchronized void handle(DataSource ds) {
182
		Connection con;
183
		try {
184
			con = ds.getConnection();
185
		} catch (SQLException e1) {
186
			return;
187
		}
188
		try {
189
			for (;;) {
190
				if (!this.handle(con))
191
					break;
192
			}
193
			long ct = System.currentTimeMillis();
194
			if((ct - this.lastIndexStatic)> this.indexRate){
195
				this.handleIndex(con);
196
				this.lastIndexStatic = ct;
197
			}
198
		} finally {
199
			if (con != null) {
200
				try {
201
					con.close();
202
				} catch (Exception e) {
203
				}
204
			}
205
		}
206

207
	}
208
	public void handleIndex(Connection con){
209
		this.staticArticleIndex(con);
210
		this.staticPaperIndex(con);
211
		this.staticPatentIndex(con);
212
		try {
213
			this.saveFile(new File(dir,"index.html"), "<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'></head><body>"
214
					+ "<a href='a/index.html'>article</a><br><a href='pp/index.html'>paper</a><br><a href='pt/index.html'>patent</a></body></html>");
215
		} catch (IOException e) {
216
		}
217
	}
77 218
	
219
	public boolean handle(Connection con) {
220
		Node node = this.queue.peek();
221
		if (node == null)
222
			return false;
223
		try {
224
			ContentType type = node.getType();
225
			Object key = node.getKey();
226
			if (type != null) {
227
				switch (type) {
228
				case Article:
229
					this.staticArticle(con, key);
230
					break;
231
				case Paper:
232
					this.staticPaper(con, key);
233
					break;
234
				case Patent:
235
					this.staticPatent(con, key);
236
					break;
237
				default:
238
					break;
239
				}
240
			}
241
		} finally {
242
			if (node != null) {
243
				this.queue.poll();
244
			}
245
		}
246
		return true;
247
	}
248

249
	private void staticArticle(Connection con, Object key) {
250
		try {
251
			Article article = articleDao.queryOne(con, (String) key);
252
			if (article == null)
253
				return;
254
			String path = article.getCreateTime().substring(0, 8) + "/";
255
			File file = new File(this.dir, "a/" + path + article.getShareId() + ".html");
256
			if (file.exists()) {
257
				file.delete();
258
			}
259
			Map<String, Object> data = new HashMap<String, Object>();
260
			data.put("data", article);
261
			data.put("jsonData", JsonService.toJson(article));
262
			if (article.getStatus().equals("1")) {
263
				this.genCnt("article.html", file, data);
264
			}
265
		} catch (Exception e) {
266
			log.error("static article[" + key + "]error", e);
267
		}
268
	}
269

270

271
	private void saveFile(File dest,String cnt) throws IOException{
272
		if(dest.exists()){
273
			dest.delete();
274
		}
275
		byte[] fc =cnt.getBytes(ConstData.UTF8);
276
		FileOutputStream fos = new FileOutputStream(dest);
277
		try{
278
			fos.write(fc);
279
			fos.flush();
280
		}finally{
281
			try{fos.close();}catch(IOException e){}
282
		}
283
	}
78 284
	
79 285
	
286
	private void flushIndex(StringBuilder cnt,String path,int pageno) throws IOException {
287
		StringBuilder sb = new StringBuilder();
288
		sb.append("<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'></head><body>");		
289
		sb.append(cnt);
290
		if(pageno>1){
291
			sb.append("<a href='index_"+(pageno-1)+".html'>上一页</a>");
292
		}else if(pageno==1){
293
			sb.append("<a href='index.html'>上一页</a>");
294
		}
295
		sb.append("<a href='index_"+(pageno+1)+".html'>下一页</a></body></html>");
296
		File dest = new File(dir,path+"/index"+(pageno==0?"":("_"+pageno))+".html");
297
		this.saveFile(dest, sb.toString());
298
	}
80 299
	
81
	
82
	
300
	private void staticArticleIndex(Connection con) {
301
		int pageno = 0;
302
		int rn = 0;
303
		StringBuilder sb = new StringBuilder();
304
		try {
305
			PreparedStatement ps = con.prepareStatement("SELECT ARTICLE_ID,CREATE_TIME,SHARE_ID FROM ARTICLE WHERE STATUS ='1'");
306
			try {
307
				ResultSet rs = ps.executeQuery();
308
				try {
309
					while (rs.next()) {
310
						String id = rs.getString(1);
311
						String ct = rs.getString(2);
312
						long si = rs.getLong(3);
313
						sb.append("<a href='").append(ct.substring(0,8)).append("/").append(si).append(".html'>").append(rn).append("  :  ").append(id).append("</a><br>");
314
						++rn;
315
						if(rn == 200){
316
							flushIndex(sb, "a", pageno);
317
							++pageno;
318
							rn=0;
319
							sb.delete(0,sb.length());
320
						}
321
					}
322
					flushIndex(sb, "a", pageno);
323
					sb.delete(0,sb.length());
324
				} finally {
325
					try {
326
						rs.close();
327
					} catch (SQLException e) {
328

329
					}
330
				}
331
			} finally {
332
				try {
333
					ps.close();
334
				} catch (SQLException e) {
335

336
				}
337
			}
338
			
339
			
340
		} catch (Exception e) {
341
			log.error("static article index error", e);
342
		}
343
		
344
	}
345
	private void staticPaperIndex(Connection con) {
346
		int pageno = 0;
347
		int rn = 0;
348
		StringBuilder sb = new StringBuilder();
349
		try {
350
			PreparedStatement ps = con.prepareStatement("SELECT ID,CREATE_TIME,SHARE_ID FROM PPAPER");
351
			try {
352
				ResultSet rs = ps.executeQuery();
353
				try {
354
					while (rs.next()) {
355
						String id = rs.getString(1);
356
						String ct = rs.getString(2);
357
						long si = rs.getLong(3);
358
						sb.append("<a href='").append(ct.substring(0,8)).append("/").append(si).append(".html'>").append(rn).append(" : ").append(id).append("</a><br>");
359
						++rn;
360
						if(rn  ==200){
361
							flushIndex(sb, "pp", pageno);
362
							++pageno;
363
							rn=0;
364
							sb.delete(0,sb.length());
365
						}
366
					}
367
				} finally {
368
					try {
369
						rs.close();
370
					} catch (SQLException e) {
371

372
					}
373
				}
374
				flushIndex(sb, "pp", pageno);
375
				sb.delete(0,sb.length());
376
			} finally {
377
				try {
378
					ps.close();
379
				} catch (SQLException e) {
380

381
				}
382
			}
383
		} catch (Exception e) {
384
			log.error("static paper index error", e);
385
		}
386
	}
387
	private void staticPatentIndex(Connection con) {
388
		int pageno = 0;
389
		int rn = 0;
390
		StringBuilder sb = new StringBuilder();
391
		try {
392
			PreparedStatement ps = con.prepareStatement("SELECT ID,CREATE_TIME,SHARE_ID FROM PPATENT");
393
			try {
394
				ResultSet rs = ps.executeQuery();
395
				try {
396
					while (rs.next()) {
397
						String id = rs.getString(1);
398
						String ct = rs.getString(2);
399
						long si = rs.getLong(3);
400
						sb.append("<a href='").append(ct.substring(0,8)).append("/").append(si).append(".html'>").append(rn).append(" : ").append(id).append("</a>");
401
						++rn;
402
						if(rn ==200){
403
							flushIndex(sb, "pt", pageno);
404
							++pageno;
405
							rn=0;
406
							sb.delete(0,sb.length());
407
						}
408
					}
409
				} finally {
410
					try {
411
						rs.close();
412
					} catch (SQLException e) {
413

414
					}
415
				}
416
				flushIndex(sb, "pt", pageno);
417
				sb.delete(0,sb.length());
418
			} finally {
419
				try {
420
					ps.close();
421
				} catch (SQLException e) {
422

423
				}
424
			}
425
		} catch (Exception e) {
426
			log.error("static article index error", e);
427
		}
428
	}
429
	private void staticPaper(Connection con, Object key) {
430
		try {
431
			Ppaper page = this.ppaperDao.query(con, (String) key);
432
			if (page == null)
433
				return;
434
			String path = page.getCreateTime().substring(0, 8) + "/";
435
			File file = new File(this.dir, "pp/" + path + page.getShareId() + ".html");
436
			if (file.exists()) {
437
				file.delete();
438
			}
439
			Map<String, Object> data = new HashMap<String, Object>();
440
			data.put("data", page);
441
			data.put("jsonData", JsonService.toJson(page));
442
			this.genCnt("paper.html", file, data);
443
		} catch (Exception e) {
444
			log.error("static paper[" + key + "]error", e);
445
		}
446
	}
447

448
	private void staticPatent(Connection con, Object key) {
449
		try {
450
			Ppatent page = this.ppatentDao.query(con, (String) key);
451
			if (page == null)
452
				return;
453
			String path = page.getCreateTime().substring(0, 8) + "/";
454
			File file = new File(this.dir, "pt/" + path + page.getShareId() + ".html");
455
			if (file.exists()) {
456
				file.delete();
457
			}
458
			Map<String, Object> data = new HashMap<String, Object>();
459
			data.put("data", page);
460
			data.put("jsonData", JsonService.toJson(page));
461
			this.genCnt("patent.html", file, data);
462
		} catch (Exception e) {
463
			log.error("static patent[" + key + "]error", e);
464
		}
465
	}
466

467
	public static void main(String[] args) throws Exception {
468
		System.out.println(ContentType.valueOf("Article"));
469

470
	}
83 471

84 472
}

+ 47 - 31
src/main/java/com/ekexiu/portal/job/TaskJob.java

@ -7,57 +7,65 @@ import java.util.Date;
7 7
import java.util.concurrent.ScheduledExecutorService;
8 8
import java.util.concurrent.TimeUnit;
9 9

10
import javax.sql.DataSource;
11

10 12
import org.jfw.apt.annotation.Bean;
11 13
import org.jfw.util.bean.AfterBeanFactory;
12 14
import org.jfw.util.bean.BeanFactory;
13 15
import org.jfw.util.context.JfwAppContext;
14 16

17
import com.ekexiu.portal.cms.TemplateService;
15 18
import com.ekexiu.portal.service.WeixinService;
16 19
import com.ekexiu.push.service.PushService;
17 20

18 21
@Bean
19 22
public class TaskJob implements AfterBeanFactory {
20 23
	private ScheduledExecutorService service;
21
	
24
	private DataSource dataSource;
25

22 26
	@Override
23 27
	public void handle(BeanFactory bf) throws Throwable {
24
	
28
		this.dataSource =(DataSource) bf.getBean("dataSource");
25 29
		ArticleTaskJobEntry atje = (ArticleTaskJobEntry) bf.getBean("com_ekexiu_portal_job_ArticleTaskJobEntry");
26 30
		TaskJobEntry tje = (TaskJobEntry) bf.getBean("com_ekexiu_portal_job_TaskJobEntry");
27 31
		ProScoreTaskJobEntry pstje = (ProScoreTaskJobEntry) bf.getBean("com_ekexiu_portal_job_ProScoreTaskJobEntry");
28
//		UserLogTaskJobEntry ultje = (UserLogTaskJobEntry) bf.getBean("com_ekexiu_portal_job_UserLogTaskJobEntry");
32
		// UserLogTaskJobEntry ultje = (UserLogTaskJobEntry)
33
		// bf.getBean("com_ekexiu_portal_job_UserLogTaskJobEntry");
29 34
		DictTaskJobEntry dtje = (DictTaskJobEntry) bf.getBean("com_ekexiu_portal_job_DictTaskJobEntry");
30 35
		HotKeyJobEntry hkje = (HotKeyJobEntry) bf.getBean("com_ekexiu_portal_job_HotKeyJobEntry");
31
		final WeixinService weixin =(WeixinService)bf.getBean("com_ekexiu_portal_service_WeixinService");
32
		final PushService pushService =(PushService)bf.getBean("com_ekexiu_push_service_PushService");
33
		
34
		DemandInvalidJob dij = (DemandInvalidJob)bf.getBean("com_ekexiu_portal_job_DemandInvalidJob");
35
		
36
		final WeixinService weixin = (WeixinService) bf.getBean("com_ekexiu_portal_service_WeixinService");
37
		final PushService pushService = (PushService) bf.getBean("com_ekexiu_push_service_PushService");
38

39
		final TemplateService templateService = (TemplateService) bf.getBean("com_ekexiu_portal_cms_TemplateService");
40

41
		DemandInvalidJob dij = (DemandInvalidJob) bf.getBean("com_ekexiu_portal_job_DemandInvalidJob");
42

36 43
		long delayTime = tje.getDelayTime();
37 44
		long task = getTimeMillis(tje.getTaskTime());
38 45
		long taskTime = task - System.currentTimeMillis();
39 46
		taskTime = taskTime > 0 ? taskTime : delayTime + taskTime;
40
		
41
        this.service = JfwAppContext.getScheduledExecutorService();
42
        // 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间  
43
        service.scheduleAtFixedRate(atje, 1, atje.getDelayTime(), TimeUnit.SECONDS);
47

48
		this.service = JfwAppContext.getScheduledExecutorService();
49
		// 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间
50
		service.scheduleAtFixedRate(atje, 1, atje.getDelayTime(), TimeUnit.SECONDS);
44 51
		service.scheduleAtFixedRate(tje, taskTime, delayTime, TimeUnit.MILLISECONDS);
45
		
52

46 53
		long pstjeTask = getTimeMillis(pstje.getTaskTime());
47 54
		long pstjeTaskTime = pstjeTask - System.currentTimeMillis();
48 55
		pstjeTaskTime = pstjeTaskTime > 0 ? pstjeTaskTime : pstjeTaskTime + pstje.getDelayTime();
49 56
		service.scheduleAtFixedRate(pstje, pstjeTaskTime, pstje.getDelayTime(), TimeUnit.MILLISECONDS);
50
//		service.scheduleAtFixedRate(ultje, taskTime, delayTime, TimeUnit.MILLISECONDS);
57
		// service.scheduleAtFixedRate(ultje, taskTime, delayTime,
58
		// TimeUnit.MILLISECONDS);
51 59
		service.scheduleAtFixedRate(dtje, 1, dtje.getDelayTime(), TimeUnit.SECONDS);
52
		
60

53 61
		long hkjeTask = getTimeMillis(hkje.getTaskTime());
54 62
		long hkjeTaskTime = hkjeTask - System.currentTimeMillis();
55 63
		hkjeTaskTime = hkjeTaskTime > 0 ? hkjeTaskTime : hkjeTaskTime + hkje.getDelayTime();
56 64
		service.scheduleAtFixedRate(hkje, hkjeTaskTime, hkje.getDelayTime(), TimeUnit.MILLISECONDS);
57
		if(hkjeTaskTime>300*1000){
65
		if (hkjeTaskTime > 300 * 1000) {
58 66
			service.submit(hkje);
59 67
		}
60
		
68

61 69
		service.scheduleAtFixedRate(new Runnable() {
62 70
			@Override
63 71
			public void run() {
@ -67,21 +75,29 @@ public class TaskJob implements AfterBeanFactory {
67 75
		service.scheduleAtFixedRate(new Runnable() {
68 76
			@Override
69 77
			public void run() {
70
				pushService.refresh();				
78
				pushService.refresh();
79
			}
80
		}, 0, 2, TimeUnit.SECONDS);
81
		service.scheduleAtFixedRate(dij, 0, 5, TimeUnit.MINUTES);
82
		service.scheduleWithFixedDelay(new Runnable() {
83
			@Override
84
			public void run() {
85
				templateService.handle(dataSource);
71 86
			}
72
		}, 0, 2,TimeUnit.SECONDS);		
73
		service.scheduleAtFixedRate(dij, 0, 5,TimeUnit.MINUTES);
87
		}, 0, templateService.getRate(), TimeUnit.MILLISECONDS);
88

74 89
	}
75
	private static long getTimeMillis(String time) {  
76
	    try {  
77
	        DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");  
78
	        DateFormat dayFormat = new SimpleDateFormat("yy-MM-dd");  
79
	        Date curDate = dateFormat.parse(dayFormat.format(new Date()) + " " + time);  
80
	        return curDate.getTime();  
81
	    } catch (ParseException e) {  
82
	        e.printStackTrace();  
83
	    }  
84
	    return 0;  
90

91
	private static long getTimeMillis(String time) {
92
		try {
93
			DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
94
			DateFormat dayFormat = new SimpleDateFormat("yy-MM-dd");
95
			Date curDate = dateFormat.parse(dayFormat.format(new Date()) + " " + time);
96
			return curDate.getTime();
97
		} catch (ParseException e) {
98
			e.printStackTrace();
99
		}
100
		return 0;
85 101
	}
86
	
102

87 103
}

+ 381 - 267
src/main/java/com/ekexiu/portal/service/ArticleService.java

@ -28,6 +28,8 @@ import org.jfw.util.StringUtil;
28 28
import org.jfw.util.exception.JfwBaseException;
29 29
import org.jfw.util.io.IoUtil;
30 30

31
import com.ekexiu.portal.cms.ContentType;
32
import com.ekexiu.portal.cms.TemplateService;
31 33
import com.ekexiu.portal.dao.ArticleAgreeDao;
32 34
import com.ekexiu.portal.dao.ArticleDao;
33 35
import com.ekexiu.portal.dao.ArticleOrgDao;
@ -59,6 +61,7 @@ public class ArticleService {
59 61
	private int artMaxLen = 70;
60 62
	private static final String JPG = "jpg";
61 63
	public static final String MAX_MODIFYTIME = "9";
64

62 65
	@Autowrie
63 66
	private ArticleDao articleDao;
64 67
	@Autowrie
@ -90,6 +93,17 @@ public class ArticleService {
90 93
	@Autowrie
91 94
	private KeyWordService keyWordService;
92 95

96
	@Autowrie
97
	private TemplateService templateService;
98

99
	public TemplateService getTemplateService() {
100
		return templateService;
101
	}
102

103
	public void setTemplateService(TemplateService templateService) {
104
		this.templateService = templateService;
105
	}
106

93 107
	public KeyWordService getKeyWordService() {
94 108
		return keyWordService;
95 109
	}
@ -292,34 +306,9 @@ public class ArticleService {
292 306

293 307
	@Post
294 308
	@Path
295
	public String insert(@JdbcConn(true) Connection con, Article article) throws SQLException, IOException, JfwBaseException {
309
	public String insert(@JdbcConn(false) Connection con, Article article) throws SQLException, IOException, JfwBaseException {
296 310
		String articleId = StringUtil.buildUUID();
297
		if (article.getArticleImg() != null) {
298
			this.saveArtImg(article.getArticleImg(), articleId);
299
			article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG);
300
		}
301
		article.setArticleId(articleId);
302
		article.setArticleAgree(0);
303
		article.setPageViews(0);
304
		article.setStatus("1");
305
		article.setPublishTime(this.publishTime());
306
		if (article.getProfessorId() != null && article.getOrgId() == null) {
307
			article.setArticleType("1");
308
		} else if (article.getProfessorId() == null && article.getOrgId() != null) {
309
			article.setArticleType("2");
310
		} else {
311
			throw new JfwBaseException(-1, "错误参数:文章发布者ID");
312
		}
313
		this.articleDao.insert(con, article);
314
		return articleId;
315
	}
316

317
	@Post
318
	@Path("/save")
319
	public String saveArticle(@JdbcConn(true) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources,
320
			@Nullable String[] orgs) throws SQLException, IOException, JfwBaseException {
321
		if (article.getArticleId() == null) {
322
			String articleId = StringUtil.buildUUID();
311
		try {
323 312
			if (article.getArticleImg() != null) {
324 313
				this.saveArtImg(article.getArticleImg(), articleId);
325 314
				article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG);
@ -337,262 +326,344 @@ public class ArticleService {
337 326
				throw new JfwBaseException(-1, "错误参数:文章发布者ID");
338 327
			}
339 328
			this.articleDao.insert(con, article);
340
			this.keyWordService.refreshArticle(con, articleId, KeyWordService.splitKeyWord(article.getSubject()));
341
			if (professors != null) {
342
				for (String professor : professors) {
343
					ArticlePro articlePro = new ArticlePro();
344
					articlePro.setArticleId(articleId);
345
					articlePro.setProfessorId(professor);
346
					this.articleProDao.insert(con, articlePro);
347
				}
329
			con.commit();
330
			this.templateService.push(ContentType.Article, article.getArticleId());
331
		} catch (SQLException e) {
332
			try {
333
				con.rollback();
334
			} catch (SQLException ee) {
348 335
			}
349
			if (resources != null) {
350
				for (String resource : resources) {
351
					ArticleRes articleRes = new ArticleRes();
352
					articleRes.setArticleId(articleId);
353
					articleRes.setResourceId(resource);
354
					this.articleResDao.insert(con, articleRes);
336
			throw e;
337
		}
338

339
		return articleId;
340
	}
341

342
	@Post
343
	@Path("/save")
344
	public String saveArticle(@JdbcConn(false) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources,
345
			@Nullable String[] orgs) throws SQLException, IOException, JfwBaseException {
346
		String articleId = null;
347
		try {
348

349
			if (article.getArticleId() == null) {
350
				articleId = StringUtil.buildUUID();
351
				if (article.getArticleImg() != null) {
352
					this.saveArtImg(article.getArticleImg(), articleId);
353
					article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG);
355 354
				}
356
			}
357
			if (orgs != null && orgs.length > 0) {
358
				for (String org : orgs) {
359
					ArticleOrg articleOrg = new ArticleOrg();
360
					articleOrg.setArticleId(articleId);
361
					articleOrg.setOrgId(org);
362
					this.articleOrgDao.insert(con, articleOrg);
355
				article.setArticleId(articleId);
356
				article.setArticleAgree(0);
357
				article.setPageViews(0);
358
				article.setStatus("1");
359
				article.setPublishTime(this.publishTime());
360
				if (article.getProfessorId() != null && article.getOrgId() == null) {
361
					article.setArticleType("1");
362
				} else if (article.getProfessorId() == null && article.getOrgId() != null) {
363
					article.setArticleType("2");
364
				} else {
365
					throw new JfwBaseException(-1, "错误参数:文章发布者ID");
363 366
				}
364
			}
365
			return articleId;
366
		} else if (article.getArticleId().trim().length() == 32) {
367
			if (article.getArticleImg() != null) {
368
				this.saveArtImg(article.getArticleImg(), article.getArticleId());
369
				article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG);
370
			}
371
			this.articleDao.update(con, article);
372
			this.articleDao.updatePublishTime(con, article.getArticleId(), "1", this.publishTime());
373
			this.keyWordService.refreshArticle(con, article.getArticleId(), KeyWordService.splitKeyWord(article.getSubject()));
374
			this.articleProDao.delete(con, article.getArticleId());
375
			this.articleResDao.delete(con, article.getArticleId());
376
			this.articleOrgDao.delete(con, article.getArticleId());
377
			if (professors != null) {
378
				for (String professor : professors) {
379
					ArticlePro articlePro = new ArticlePro();
380
					articlePro.setArticleId(article.getArticleId());
381
					articlePro.setProfessorId(professor);
382
					this.articleProDao.insert(con, articlePro);
367
				this.articleDao.insert(con, article);
368
				this.keyWordService.refreshArticle(con, articleId, KeyWordService.splitKeyWord(article.getSubject()));
369
				if (professors != null) {
370
					for (String professor : professors) {
371
						ArticlePro articlePro = new ArticlePro();
372
						articlePro.setArticleId(articleId);
373
						articlePro.setProfessorId(professor);
374
						this.articleProDao.insert(con, articlePro);
375
					}
383 376
				}
384
			}
385
			if (resources != null) {
386
				for (String resource : resources) {
387
					ArticleRes articleRes = new ArticleRes();
388
					articleRes.setArticleId(article.getArticleId());
389
					articleRes.setResourceId(resource);
390
					this.articleResDao.insert(con, articleRes);
377
				if (resources != null) {
378
					for (String resource : resources) {
379
						ArticleRes articleRes = new ArticleRes();
380
						articleRes.setArticleId(articleId);
381
						articleRes.setResourceId(resource);
382
						this.articleResDao.insert(con, articleRes);
383
					}
391 384
				}
392
			}
393
			if (orgs != null && orgs.length > 0) {
394
				for (String org : orgs) {
395
					ArticleOrg articleOrg = new ArticleOrg();
396
					articleOrg.setArticleId(article.getArticleId());
397
					articleOrg.setOrgId(org);
398
					this.articleOrgDao.insert(con, articleOrg);
385
				if (orgs != null && orgs.length > 0) {
386
					for (String org : orgs) {
387
						ArticleOrg articleOrg = new ArticleOrg();
388
						articleOrg.setArticleId(articleId);
389
						articleOrg.setOrgId(org);
390
						this.articleOrgDao.insert(con, articleOrg);
391
					}
399 392
				}
393
			} else if (article.getArticleId().trim().length() == 32) {
394
				articleId = article.getArticleId();
395
				if (article.getArticleImg() != null) {
396
					this.saveArtImg(article.getArticleImg(), article.getArticleId());
397
					article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG);
398
				}
399
				this.articleDao.update(con, article);
400
				this.articleDao.updatePublishTime(con, article.getArticleId(), "1", this.publishTime());
401
				this.keyWordService.refreshArticle(con, article.getArticleId(), KeyWordService.splitKeyWord(article.getSubject()));
402
				this.articleProDao.delete(con, article.getArticleId());
403
				this.articleResDao.delete(con, article.getArticleId());
404
				this.articleOrgDao.delete(con, article.getArticleId());
405
				if (professors != null) {
406
					for (String professor : professors) {
407
						ArticlePro articlePro = new ArticlePro();
408
						articlePro.setArticleId(article.getArticleId());
409
						articlePro.setProfessorId(professor);
410
						this.articleProDao.insert(con, articlePro);
411
					}
412
				}
413
				if (resources != null) {
414
					for (String resource : resources) {
415
						ArticleRes articleRes = new ArticleRes();
416
						articleRes.setArticleId(article.getArticleId());
417
						articleRes.setResourceId(resource);
418
						this.articleResDao.insert(con, articleRes);
419
					}
420
				}
421
				if (orgs != null && orgs.length > 0) {
422
					for (String org : orgs) {
423
						ArticleOrg articleOrg = new ArticleOrg();
424
						articleOrg.setArticleId(article.getArticleId());
425
						articleOrg.setOrgId(org);
426
						this.articleOrgDao.insert(con, articleOrg);
427
					}
428
				}
429
			} else {
430
				throw new JfwBaseException(-2, "bad parameter:articleId");
400 431
			}
401
			return article.getArticleId();
402
		} else {
403
			throw new JfwBaseException(-2, "bad parameter:articleId");
432
			con.commit();
433
			this.templateService.push(ContentType.Article, article.getArticleId());
434
		} catch (SQLException | IOException | JfwBaseException e) {
435
			try {
436
				con.rollback();
437
			} catch (SQLException ee) {
438
			}
439
			throw e;
404 440
		}
441
		return articleId;
405 442
	}
406 443

407 444
	@Post
408 445
	@Path("/draft")
409
	public String draft(@JdbcConn(true) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources, @Nullable String[] orgs)
446
	public String draft(@JdbcConn(false) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources, @Nullable String[] orgs)
410 447
			throws SQLException, IOException, JfwBaseException {
411
		if (article.getArticleId() == null) {
412
			String articleId = StringUtil.buildUUID();
413
			if (article.getArticleImg() != null) {
414
				this.saveArtImg(article.getArticleImg(), articleId);
415
				article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG);
416
			}
417
			article.setArticleId(articleId);
418
			article.setArticleAgree(0);
419
			article.setPageViews(0);
420
			article.setStatus("0");
421
			if (article.getProfessorId() != null && article.getOrgId() == null) {
422
				article.setArticleType("1");
423
			} else if (article.getProfessorId() == null && article.getOrgId() != null) {
424
				article.setArticleType("2");
425
			} else {
426
				throw new JfwBaseException(-1, "错误参数:文章发布者ID");
427
			}
428
			this.articleDao.insert(con, article);
429
			this.keyWordService.refreshArticle(con, articleId, null);
430
			if (professors != null) {
431
				for (String professor : professors) {
432
					ArticlePro articlePro = new ArticlePro();
433
					articlePro.setArticleId(articleId);
434
					articlePro.setProfessorId(professor);
435
					this.articleProDao.insert(con, articlePro);
448

449
		String articleId = null;
450
		try {
451
			if (article.getArticleId() == null) {
452
				articleId = StringUtil.buildUUID();
453
				if (article.getArticleImg() != null) {
454
					this.saveArtImg(article.getArticleImg(), articleId);
455
					article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG);
436 456
				}
437
			}
438
			if (resources != null) {
439
				for (String resource : resources) {
440
					ArticleRes articleRes = new ArticleRes();
441
					articleRes.setArticleId(articleId);
442
					articleRes.setResourceId(resource);
443
					this.articleResDao.insert(con, articleRes);
457
				article.setArticleId(articleId);
458
				article.setArticleAgree(0);
459
				article.setPageViews(0);
460
				article.setStatus("0");
461
				if (article.getProfessorId() != null && article.getOrgId() == null) {
462
					article.setArticleType("1");
463
				} else if (article.getProfessorId() == null && article.getOrgId() != null) {
464
					article.setArticleType("2");
465
				} else {
466
					throw new JfwBaseException(-1, "错误参数:文章发布者ID");
444 467
				}
445
			}
446
			if (orgs != null && orgs.length > 0) {
447
				for (String org : orgs) {
448
					ArticleOrg articleOrg = new ArticleOrg();
449
					articleOrg.setArticleId(articleId);
450
					articleOrg.setOrgId(org);
451
					this.articleOrgDao.insert(con, articleOrg);
468
				this.articleDao.insert(con, article);
469
				this.keyWordService.refreshArticle(con, articleId, null);
470
				if (professors != null) {
471
					for (String professor : professors) {
472
						ArticlePro articlePro = new ArticlePro();
473
						articlePro.setArticleId(articleId);
474
						articlePro.setProfessorId(professor);
475
						this.articleProDao.insert(con, articlePro);
476
					}
452 477
				}
453
			}
454
			return articleId;
455
		} else if (article.getArticleId().trim().length() == 32) {
456
			if (article.getArticleImg() != null) {
457
				this.saveArtImg(article.getArticleImg(), article.getArticleId());
458
				article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG);
459
			}
460
			this.articleDao.update(con, article);
461
			this.articleDao.updateStatus(con, article.getArticleId(), "0");
462
			this.keyWordService.refreshArticle(con, article.getArticleId(), null);
463
			this.articleProDao.delete(con, article.getArticleId());
464
			this.articleResDao.delete(con, article.getArticleId());
465
			this.articleOrgDao.delete(con, article.getArticleId());
466
			if (professors != null) {
467
				for (String professor : professors) {
468
					ArticlePro articlePro = new ArticlePro();
469
					articlePro.setArticleId(article.getArticleId());
470
					articlePro.setProfessorId(professor);
471
					this.articleProDao.insert(con, articlePro);
478
				if (resources != null) {
479
					for (String resource : resources) {
480
						ArticleRes articleRes = new ArticleRes();
481
						articleRes.setArticleId(articleId);
482
						articleRes.setResourceId(resource);
483
						this.articleResDao.insert(con, articleRes);
484
					}
472 485
				}
473
			}
474
			if (resources != null) {
475
				for (String resource : resources) {
476
					ArticleRes articleRes = new ArticleRes();
477
					articleRes.setArticleId(article.getArticleId());
478
					articleRes.setResourceId(resource);
479
					this.articleResDao.insert(con, articleRes);
486
				if (orgs != null && orgs.length > 0) {
487
					for (String org : orgs) {
488
						ArticleOrg articleOrg = new ArticleOrg();
489
						articleOrg.setArticleId(articleId);
490
						articleOrg.setOrgId(org);
491
						this.articleOrgDao.insert(con, articleOrg);
492
					}
480 493
				}
481
			}
482
			if (orgs != null && orgs.length > 0) {
483
				for (String org : orgs) {
484
					ArticleOrg articleOrg = new ArticleOrg();
485
					articleOrg.setArticleId(article.getArticleId());
486
					articleOrg.setOrgId(org);
487
					this.articleOrgDao.insert(con, articleOrg);
494
			} else if (article.getArticleId().trim().length() == 32) {
495
				articleId = article.getArticleId();
496
				if (article.getArticleImg() != null) {
497
					this.saveArtImg(article.getArticleImg(), article.getArticleId());
498
					article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG);
499
				}
500
				this.articleDao.update(con, article);
501
				this.articleDao.updateStatus(con, article.getArticleId(), "0");
502
				this.keyWordService.refreshArticle(con, article.getArticleId(), null);
503
				this.articleProDao.delete(con, article.getArticleId());
504
				this.articleResDao.delete(con, article.getArticleId());
505
				this.articleOrgDao.delete(con, article.getArticleId());
506
				if (professors != null) {
507
					for (String professor : professors) {
508
						ArticlePro articlePro = new ArticlePro();
509
						articlePro.setArticleId(article.getArticleId());
510
						articlePro.setProfessorId(professor);
511
						this.articleProDao.insert(con, articlePro);
512
					}
488 513
				}
514
				if (resources != null) {
515
					for (String resource : resources) {
516
						ArticleRes articleRes = new ArticleRes();
517
						articleRes.setArticleId(article.getArticleId());
518
						articleRes.setResourceId(resource);
519
						this.articleResDao.insert(con, articleRes);
520
					}
521
				}
522
				if (orgs != null && orgs.length > 0) {
523
					for (String org : orgs) {
524
						ArticleOrg articleOrg = new ArticleOrg();
525
						articleOrg.setArticleId(article.getArticleId());
526
						articleOrg.setOrgId(org);
527
						this.articleOrgDao.insert(con, articleOrg);
528
					}
529
				}
530
			} else {
531
				throw new JfwBaseException(-2, "bad parameter:articleId");
489 532
			}
490
			return article.getArticleId();
491
		} else {
492
			throw new JfwBaseException(-2, "bad parameter:articleId");
533
			con.commit();
534
			this.templateService.push(ContentType.Article, articleId);
535
		} catch (SQLException | IOException | JfwBaseException e) {
536
			try {
537
				con.rollback();
538
			} catch (SQLException ee) {
539
			}
540
			throw e;
493 541
		}
542
		return articleId;
494 543
	}
495 544

496 545
	@Post
497 546
	@Path("/timing")
498
	public String timingPublish(@JdbcConn(true) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources,
547
	public String timingPublish(@JdbcConn(false) Connection con, Article article, @Nullable String[] professors, @Nullable String[] resources,
499 548
			@Nullable String[] orgs) throws SQLException, IOException, JfwBaseException {
500
		if (article.getPublishTime() == null) {
501
			throw new JfwBaseException(-3, "no parameter found:publishTime");
502
		}
503
		if (article.getArticleId() == null) {
504
			String articleId = StringUtil.buildUUID();
505
			if (article.getArticleImg() != null) {
506
				this.saveArtImg(article.getArticleImg(), articleId);
507
				article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG);
508
			}
509
			article.setArticleId(articleId);
510
			article.setArticleAgree(0);
511
			article.setPageViews(0);
512
			article.setStatus("2");
513
			if (article.getProfessorId() != null && article.getOrgId() == null) {
514
				article.setArticleType("1");
515
			} else if (article.getProfessorId() == null && article.getOrgId() != null) {
516
				article.setArticleType("2");
517
			} else {
518
				throw new JfwBaseException(-1, "错误参数:文章发布者ID");
549
		String articleId = null;
550
		try {
551
			if (article.getPublishTime() == null) {
552
				throw new JfwBaseException(-3, "no parameter found:publishTime");
519 553
			}
520
			this.articleDao.insert(con, article);
521
			if (professors != null) {
522
				for (String professor : professors) {
523
					ArticlePro articlePro = new ArticlePro();
524
					articlePro.setArticleId(articleId);
525
					articlePro.setProfessorId(professor);
526
					this.articleProDao.insert(con, articlePro);
554
			if (article.getArticleId() == null) {
555
				articleId = StringUtil.buildUUID();
556
				if (article.getArticleImg() != null) {
557
					this.saveArtImg(article.getArticleImg(), articleId);
558
					article.setArticleImg(this.createDate() + "/" + articleId + "." + JPG);
527 559
				}
528
			}
529
			if (resources != null) {
530
				for (String resource : resources) {
531
					ArticleRes articleRes = new ArticleRes();
532
					articleRes.setArticleId(articleId);
533
					articleRes.setResourceId(resource);
534
					this.articleResDao.insert(con, articleRes);
560
				article.setArticleId(articleId);
561
				article.setArticleAgree(0);
562
				article.setPageViews(0);
563
				article.setStatus("2");
564
				if (article.getProfessorId() != null && article.getOrgId() == null) {
565
					article.setArticleType("1");
566
				} else if (article.getProfessorId() == null && article.getOrgId() != null) {
567
					article.setArticleType("2");
568
				} else {
569
					throw new JfwBaseException(-1, "错误参数:文章发布者ID");
535 570
				}
536
			}
537
			if (orgs != null && orgs.length > 0) {
538
				for (String org : orgs) {
539
					ArticleOrg articleOrg = new ArticleOrg();
540
					articleOrg.setArticleId(articleId);
541
					articleOrg.setOrgId(org);
542
					this.articleOrgDao.insert(con, articleOrg);
571
				this.articleDao.insert(con, article);
572
				if (professors != null) {
573
					for (String professor : professors) {
574
						ArticlePro articlePro = new ArticlePro();
575
						articlePro.setArticleId(articleId);
576
						articlePro.setProfessorId(professor);
577
						this.articleProDao.insert(con, articlePro);
578
					}
543 579
				}
544
			}
545
			return articleId;
546
		} else if (article.getArticleId().trim().length() == 32) {
547
			if (article.getArticleImg() != null) {
548
				this.saveArtImg(article.getArticleImg(), article.getArticleId());
549
				article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG);
550
			}
551
			this.articleDao.update(con, article);
552
			this.articleDao.updatePublishTime(con, article.getArticleId(), "2", article.getPublishTime());
553
			this.keyWordService.refreshArticle(con, article.getArticleId(), null);
554
			this.articleResDao.delete(con, article.getArticleId());
555
			this.articleProDao.delete(con, article.getArticleId());
556
			this.articleOrgDao.delete(con, article.getArticleId());
557

558
			if (professors != null) {
559
				for (String professor : professors) {
560
					ArticlePro articlePro = new ArticlePro();
561
					articlePro.setArticleId(article.getArticleId());
562
					articlePro.setProfessorId(professor);
563
					this.articleProDao.insert(con, articlePro);
580
				if (resources != null) {
581
					for (String resource : resources) {
582
						ArticleRes articleRes = new ArticleRes();
583
						articleRes.setArticleId(articleId);
584
						articleRes.setResourceId(resource);
585
						this.articleResDao.insert(con, articleRes);
586
					}
564 587
				}
565
			}
566
			if (resources != null) {
567
				for (String resource : resources) {
568
					ArticleRes articleRes = new ArticleRes();
569
					articleRes.setArticleId(article.getArticleId());
570
					articleRes.setResourceId(resource);
571
					this.articleResDao.insert(con, articleRes);
588
				if (orgs != null && orgs.length > 0) {
589
					for (String org : orgs) {
590
						ArticleOrg articleOrg = new ArticleOrg();
591
						articleOrg.setArticleId(articleId);
592
						articleOrg.setOrgId(org);
593
						this.articleOrgDao.insert(con, articleOrg);
594
					}
572 595
				}
573
			}
574
			if (orgs != null && orgs.length > 0) {
575
				for (String org : orgs) {
576
					ArticleOrg articleOrg = new ArticleOrg();
577
					articleOrg.setArticleId(article.getArticleId());
578
					articleOrg.setOrgId(org);
579
					this.articleOrgDao.insert(con, articleOrg);
596
			} else if (article.getArticleId().trim().length() == 32) {
597
				articleId = article.getArticleId();
598
				if (article.getArticleImg() != null) {
599
					this.saveArtImg(article.getArticleImg(), article.getArticleId());
600
					article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG);
601
				}
602
				this.articleDao.update(con, article);
603
				this.articleDao.updatePublishTime(con, article.getArticleId(), "2", article.getPublishTime());
604
				this.keyWordService.refreshArticle(con, article.getArticleId(), null);
605
				this.articleResDao.delete(con, article.getArticleId());
606
				this.articleProDao.delete(con, article.getArticleId());
607
				this.articleOrgDao.delete(con, article.getArticleId());
608

609
				if (professors != null) {
610
					for (String professor : professors) {
611
						ArticlePro articlePro = new ArticlePro();
612
						articlePro.setArticleId(article.getArticleId());
613
						articlePro.setProfessorId(professor);
614
						this.articleProDao.insert(con, articlePro);
615
					}
580 616
				}
617
				if (resources != null) {
618
					for (String resource : resources) {
619
						ArticleRes articleRes = new ArticleRes();
620
						articleRes.setArticleId(article.getArticleId());
621
						articleRes.setResourceId(resource);
622
						this.articleResDao.insert(con, articleRes);
623
					}
624
				}
625
				if (orgs != null && orgs.length > 0) {
626
					for (String org : orgs) {
627
						ArticleOrg articleOrg = new ArticleOrg();
628
						articleOrg.setArticleId(article.getArticleId());
629
						articleOrg.setOrgId(org);
630
						this.articleOrgDao.insert(con, articleOrg);
631
					}
632
				}
633
				return article.getArticleId();
634
			} else {
635
				throw new JfwBaseException(-2, "bad parameter:articleId");
581 636
			}
582
			return article.getArticleId();
583
		} else {
584
			throw new JfwBaseException(-2, "bad parameter:articleId");
637
			con.commit();
638
			this.templateService.push(ContentType.Article, articleId);
639
		} catch (SQLException | IOException | JfwBaseException e) {
640
			try {
641
				con.rollback();
642
			} catch (SQLException ee) {
643
			}
644
			throw e;
585 645
		}
646
		return articleId;
586 647
	}
587 648

588 649
	@Post
589 650
	@Path("/updateArt")
590
	public void update(@JdbcConn(true) Connection con, Article article) throws SQLException, JfwBaseException, IOException {
591
		if (article.getArticleImg() != null) {
592
			this.saveArtImg(article.getArticleImg(), article.getArticleId());
593
			article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG);
651
	public void update(@JdbcConn(false) Connection con, Article article) throws SQLException, JfwBaseException, IOException {
652
		try {
653
			if (article.getArticleImg() != null) {
654
				this.saveArtImg(article.getArticleImg(), article.getArticleId());
655
				article.setArticleImg(this.createDate() + "/" + article.getArticleId() + "." + JPG);
656
			}
657
			this.articleDao.update(con, article);
658
			con.commit();
659
			this.templateService.push(ContentType.Article, article.getArticleId());
660
		} catch (SQLException | IOException | JfwBaseException e) {
661
			try {
662
				con.rollback();
663
			} catch (SQLException ee) {
664
			}
665
			throw e;
594 666
		}
595
		this.articleDao.update(con, article);
596 667
	}
597 668

598 669
	@Post
@ -603,36 +674,76 @@ public class ArticleService {
603 674

604 675
	@Post
605 676
	@Path("/updateDraft")
606
	public void updateDraft(@JdbcConn(true) Connection con, String articleId) throws SQLException {
677
	public void updateDraft(@JdbcConn(false) Connection con, String articleId) throws SQLException {
607 678
		// 修改文章状态为草稿
608
		this.articleDao.updateStatus(con, articleId, "0");
609
		this.keyWordService.refreshArticle(con, articleId, null);
679
		try {
680
			this.articleDao.updateStatus(con, articleId, "0");
681
			this.keyWordService.refreshArticle(con, articleId, null);
682
			con.commit();
683
			this.templateService.push(ContentType.Article, articleId);
684
		} catch (SQLException e) {
685
			try {
686
				con.rollback();
687
			} catch (SQLException ee) {
688
			}
689
			throw e;
690
		}
610 691
	}
611 692

612 693
	@Post
613 694
	@Path("/publish")
614
	public void publish(@JdbcConn(true) Connection con, String articleId) throws SQLException {
695
	public void publish(@JdbcConn(false) Connection con, String articleId) throws SQLException {
615 696
		// 修改文章状态为发布
616
		this.articleDao.updateStatus(con, articleId, "1");
617
		Article a = this.articleDao.queryOne(con, articleId);
618
		if (a != null) {
619
			this.keyWordService.refreshArticle(con, articleId, KeyWordService.splitKeyWord(a.getSubject()));
697
		try {
698
			this.articleDao.updateStatus(con, articleId, "1");
699
			Article a = this.articleDao.queryOne(con, articleId);
700
			if (a != null) {
701
				this.keyWordService.refreshArticle(con, articleId, KeyWordService.splitKeyWord(a.getSubject()));
702
			}
703
			con.commit();
704
			this.templateService.push(ContentType.Article, articleId);
705
		} catch (SQLException e) {
706
			try {
707
				con.rollback();
708
			} catch (SQLException ee) {
709
			}
710
			throw e;
620 711
		}
621 712
	}
622 713

623 714
	@Post
624 715
	@Path("/deleteArticle")
625
	public void deleteArticle(@JdbcConn(true) Connection con, String articleId) throws SQLException {
716
	public void deleteArticle(@JdbcConn(false) Connection con, String articleId) throws SQLException {
626 717
		// 修改文章状态为删除
627
		this.articleDao.updateStatus(con, articleId, "3");
628
		this.keyWordService.refreshArticle(con, articleId, null);
718
		try {
719
			this.articleDao.updateStatus(con, articleId, "3");
720
			this.keyWordService.refreshArticle(con, articleId, null);
721
			con.commit();
722
			this.templateService.push(ContentType.Article, articleId);
723
		} catch (SQLException e) {
724
			try {
725
				con.rollback();
726
			} catch (SQLException ee) {
727
			}
728
			throw e;
729
		}
629 730
	}
630 731

631 732
	@Post
632 733
	@Path("/close")
633 734
	public void closeArticle(@JdbcConn(true) Connection con, String articleId) throws SQLException {
634 735
		// 修改文章状态为关闭
736
		try{
635 737
		this.articleDao.updateStatus(con, articleId, "4");
738
		con.commit();
739
		this.templateService.push(ContentType.Article,articleId);
740
		} catch (SQLException  e) {
741
			try {
742
				con.rollback();
743
			} catch (SQLException ee) {
744
			}
745
			throw e;
746
		}
636 747
	}
637 748

638 749
	@Post
@ -764,8 +875,8 @@ public class ArticleService {
764 875

765 876
	@Get
766 877
	@Path("/pqself")
767
	public PageQueryResult<SelfArticle> queryPageSelf(@JdbcConn Connection con, @Nullable String professorId, @Nullable String orgId, @Nullable String articleTitle,
768
			@DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException {
878
	public PageQueryResult<SelfArticle> queryPageSelf(@JdbcConn Connection con, @Nullable String professorId, @Nullable String orgId,
879
			@Nullable String articleTitle, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException {
769 880
		if (articleTitle != null) {
770 881
			articleTitle = "%" + articleTitle + "%";
771 882
		}
@ -855,7 +966,7 @@ public class ArticleService {
855 966

856 967
		return this.articleDao.limitQueryPublish(con, ids, rows);
857 968
	}
858
	
969

859 970
	@Get
860 971
	@Path("/byAssOrg")
861 972
	public List<Article> byAssOrg(@JdbcConn Connection con, String id, @DefaultValue("5") int rows) throws SQLException {
@ -873,6 +984,7 @@ public class ArticleService {
873 984

874 985
		return this.articleDao.limitQueryPublish(con, ids, rows);
875 986
	}
987

876 988
	@Get
877 989
	@Path("/byAssResource")
878 990
	public List<Article> byAssResource(@JdbcConn Connection con, String id, @DefaultValue("5") int rows) throws SQLException {
@ -896,23 +1008,25 @@ public class ArticleService {
896 1008
	public Article query(@JdbcConn Connection con, long id) throws SQLException {
897 1009
		return this.articleDao.query(con, id);
898 1010
	}
899
	
900
	
1011

901 1012
	@Path("/find")
902 1013
	@Get
903
	public PageQueryResult<Article> find(@JdbcConn Connection con,@DefaultValue("0") int col,@Nullable String[] exclude,@DefaultValue("20") int pageSize,@DefaultValue("1") int pageNo) throws SQLException{
904
			return this.articleDao.queryFind(con,col>0?col:null,exclude, pageSize, pageNo);
1014
	public PageQueryResult<Article> find(@JdbcConn Connection con, @DefaultValue("0") int col, @Nullable String[] exclude, @DefaultValue("20") int pageSize,
1015
			@DefaultValue("1") int pageNo) throws SQLException {
1016
		return this.articleDao.queryFind(con, col > 0 ? col : null, exclude, pageSize, pageNo);
905 1017
	}
1018

906 1019
	@Path("/lastestPublished")
907 1020
	@Get
908
	public List<Article> lastet(@JdbcConn Connection con,@Nullable String time,@DefaultValue("10") int rows) throws SQLException{
909
		if(time==null){
910
			time = DateUtil.formatDate(System.currentTimeMillis() - 7*24*60*60*1000)+"000000";
1021
	public List<Article> lastet(@JdbcConn Connection con, @Nullable String time, @DefaultValue("10") int rows) throws SQLException {
1022
		if (time == null) {
1023
			time = DateUtil.formatDate(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000) + "000000";
911 1024
		}
912
		return this.articleDao.lasterByPublishTime(con,time,rows);		
1025
		return this.articleDao.lasterByPublishTime(con, time, rows);
913 1026
	}
914 1027

915
	public static void main(String[] args){
916
		System.out.println( DateUtil.formatDate(System.currentTimeMillis() - 7*24*60*60*1000));
1028
	public static void main(String[] args) {
1029
		System.out.println(DateUtil.formatDate(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000));
917 1030
	}
1031

918 1032
}

+ 1 - 1
src/main/java/com/ekexiu/push/service/PushService.java

@ -61,7 +61,7 @@ public class PushService {
61 61
	private String appId = "TUdvbnxu1c97r6Fb6cUy57";
62 62
	private int timeout = 0;
63 63
	private boolean enable = false;
64
	private String tokenUrl = "http://192.168.2.233/ajax/push/token";
64
	private String tokenUrl = "http://192.168.3.233/ajax/push/token";
65 65
	private String lastLoadToken = null;
66 66

67 67
	private String token = null;

+ 3 - 1
src/main/resources/project-test-dev.properties

@ -273,4 +273,6 @@ com_ekexiu_portal_oauth_OAuthService.handlers-ref=oauthService_handlers
273 273
oauthService_handlers::map=java.util.HashMap
274 274
oauthService_handlers.map-key-1=weixin
275 275
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
276
com_ekexiu_push_service_PushService.enable::boolean=false
276
com_ekexiu_push_service_PushService.enable::boolean=false
277
com_ekexiu_portal_cms_TemplateService.source::java.io.File=/kexiu/www/html1/fw_template_r3254
278
com_ekexiu_portal_cms_TemplateService.dir::java.io.File=/kexiu/webdata1/shtml

+ 3 - 1
src/main/resources/project-test.properties

@ -273,4 +273,6 @@ com_ekexiu_portal_oauth_OAuthService.handlers-ref=oauthService_handlers
273 273
oauthService_handlers::map=java.util.HashMap
274 274
oauthService_handlers.map-key-1=weixin
275 275
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
276
com_ekexiu_push_service_PushService.enable::boolean=true
276
com_ekexiu_push_service_PushService.enable::boolean=true
277
com_ekexiu_portal_cms_TemplateService.source::java.io.File=/kexiu/www/html/fw_template_r3254
278
com_ekexiu_portal_cms_TemplateService.dir::java.io.File=/kexiu/webdata/shtml

+ 2 - 1
src/main/resources/project.properties

@ -275,4 +275,5 @@ com_ekexiu_push_service_PushService.enable::boolean=true
275 275
com_ekexiu_push_service_PushService.secret=QewoTEuuOGAkWnBKqrbfj8
276 276
com_ekexiu_push_service_PushService.appKey=xXqSF9Gmb69SG37XVT3lL2
277 277
com_ekexiu_push_service_PushService.appId=vGS5OBXtmV6SrDVJDQ8dGA
278
278
com_ekexiu_portal_cms_TemplateService.source::java.io.File=/kexiu/www/html/fw_template_r3254
279
com_ekexiu_portal_cms_TemplateService.dir::java.io.File=/kexiu/webdata/shtml