jiapeng 7 years ago
parent
commit
24370a8f44

+ 5 - 0
pom.xml

@ -123,6 +123,11 @@
123 123
			<artifactId>json-simple</artifactId>
124 124
			<version>1.1.1</version>
125 125
		</dependency>
126
		<dependency>
127
			<groupId>org.freemarker</groupId>
128
			<artifactId>freemarker</artifactId>
129
			<version>2.3.26-incubating</version>
130
		</dependency>
126 131
	</dependencies>
127 132
	<build>
128 133
		<resources>

+ 84 - 0
src/main/java/com/ekexiu/portal/cms/TemplateService.java

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

3
import java.io.File;
4
import java.io.FileOutputStream;
5
import java.io.IOException;
6
import java.io.OutputStream;
7
import java.io.OutputStreamWriter;
8
import java.io.Reader;
9
import java.io.StringReader;
10
import java.util.Map;
11

12
import org.jfw.apt.web.annotation.Path;
13
import org.jfw.util.ConstData;
14

15
import freemarker.cache.TemplateLoader;
16
import freemarker.template.Configuration;
17
import freemarker.template.Template;
18
import freemarker.template.TemplateException;
19
import freemarker.template.TemplateExceptionHandler;
20

21
@Path("/cms")
22
public class TemplateService {
23
	
24
	private File source;
25
	private Configuration cfg =  new Configuration(Configuration.VERSION_2_3_26);
26
	public void setSource(File source) {
27
		this.source = source;
28
		try {
29
			this.cfg.setDirectoryForTemplateLoading(source);
30
		} catch (IOException e) {
31
			this.source = null;
32
			this.cfg.setTemplateLoader(new TemplateLoader() {
33
				@Override
34
				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");
36
					return reader;
37
				}
38
				
39
				@Override
40
				public long getLastModified(Object templateSource) {
41
					return 0;
42
				}
43
				
44
				@Override
45
				public Object findTemplateSource(String name) throws IOException {
46
					return name;
47
				}
48
				
49
				@Override
50
				public void closeTemplateSource(Object templateSource) throws IOException {
51
				}
52
			});
53
		}
54
		cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
55
	}
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");
62
			}
63
		}
64
		Template template = this.cfg.getTemplate(templateName,"UTF-8");
65
		OutputStream out = new FileOutputStream(dest);
66
		try {
67
			template.process(root, new OutputStreamWriter(out, ConstData.UTF8));
68
			out.flush();
69
		} finally {
70
			out.close();
71
		}
72
	}
73
	
74
	
75
	
76

77
	
78
	
79
	
80
	
81
	
82
	
83

84
}

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

@ -151,7 +151,7 @@ public abstract class GrowthLogDao {
151 151
	}
152 152
	
153 153
	@SelectList
154
	@Where("(OPERATE = '2' OR OPERATE = '3' OR OPERATE = '4')")
154
	@Where("(OPERATE = '2' OR OPERATE = '3' OR OPERATE = '4' OR OPERATE = '25' OR OPERATE = '26' OR OPERATE = '27' )")
155 155
	public abstract List<GrowthLog> queryShare(Connection con,String professorId,@Like String createTime)throws SQLException;
156 156
	
157 157
}

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

@ -52,7 +52,7 @@ public class ArticleService {
52 52
	private File articlePath;
53 53
	private String dateFormat = "yyyyMMdd";
54 54
	private String timeFormat = "yyyyMMddHHmmss";
55
	private int artMaxLen=640;
55
	private int artMaxLen=70;
56 56
	private static final String JPG = "jpg";
57 57
	public static final String MAX_MODIFYTIME = "9";
58 58
	@Autowrie

+ 84 - 0
src/main/java/com/ekexiu/portal/service/GrowthLogService.java

@ -306,6 +306,90 @@ public class GrowthLogService {
306 306
		}
307 307
	}
308 308
	
309
	/**
310
	 * 分享企业
311
	 * @param con
312
	 * @param professorId 用户ID
313
	 * @return 分享成功并积分返回true,分享成功不积分返回false(每天分享前10次积分,之后不积分)
314
	 * @throws SQLException
315
	 */
316
	@Post
317
	@Path("/shareOrg")
318
	public boolean shareOrg(@JdbcConn(true) Connection con,String professorId)throws SQLException{
319
		List<GrowthLog> logs = this.growthLogDao.queryShare(con, professorId, this.getDate()+"%");
320
		GrowthLog growthLog = new GrowthLog();
321
		growthLog.setId(StringUtil.buildUUID());
322
		growthLog.setProfessorId(professorId);
323
		growthLog.setOperate("25");
324
		if(logs.size() < 10){
325
			growthLog.setScore(this.rule.getShareOrg());
326
			this.growthLogDao.insert(con, growthLog);
327
			this.professorDao.updateScoreValue(con, professorId, growthLog.getScore());
328
			this.professorDao.updateGrowthValue(con, professorId, growthLog.getScore());
329
			return true;
330
		}else{
331
			growthLog.setScore(0);
332
			this.growthLogDao.insert(con, growthLog);
333
			return false;
334
		}
335
	}
336
	
337
	/**
338
	 * 分享专利
339
	 * @param con
340
	 * @param professorId 用户ID
341
	 * @return 分享成功并积分返回true,分享成功不积分返回false(每天分享前10次积分,之后不积分)
342
	 * @throws SQLException
343
	 */
344
	@Post
345
	@Path("/sharePatent")
346
	public boolean sharePatent(@JdbcConn(true) Connection con,String professorId)throws SQLException{
347
		List<GrowthLog> logs = this.growthLogDao.queryShare(con, professorId, this.getDate()+"%");
348
		GrowthLog growthLog = new GrowthLog();
349
		growthLog.setId(StringUtil.buildUUID());
350
		growthLog.setProfessorId(professorId);
351
		growthLog.setOperate("26");
352
		if(logs.size() < 10){
353
			growthLog.setScore(this.rule.getSharePatent());
354
			this.growthLogDao.insert(con, growthLog);
355
			this.professorDao.updateScoreValue(con, professorId, growthLog.getScore());
356
			this.professorDao.updateGrowthValue(con, professorId, growthLog.getScore());
357
			return true;
358
		}else{
359
			growthLog.setScore(0);
360
			this.growthLogDao.insert(con, growthLog);
361
			return false;
362
		}
363
	}
364
	
365
	/**
366
	 * 分享论文
367
	 * @param con
368
	 * @param professorId 用户ID
369
	 * @return 分享成功并积分返回true,分享成功不积分返回false(每天分享前10次积分,之后不积分)
370
	 * @throws SQLException
371
	 */
372
	@Post
373
	@Path("/sharePaper")
374
	public boolean sharePaper(@JdbcConn(true) Connection con,String professorId)throws SQLException{
375
		List<GrowthLog> logs = this.growthLogDao.queryShare(con, professorId, this.getDate()+"%");
376
		GrowthLog growthLog = new GrowthLog();
377
		growthLog.setId(StringUtil.buildUUID());
378
		growthLog.setProfessorId(professorId);
379
		growthLog.setOperate("27");
380
		if(logs.size() < 10){
381
			growthLog.setScore(this.rule.getSharePaper());
382
			this.growthLogDao.insert(con, growthLog);
383
			this.professorDao.updateScoreValue(con, professorId, growthLog.getScore());
384
			this.professorDao.updateGrowthValue(con, professorId, growthLog.getScore());
385
			return true;
386
		}else{
387
			growthLog.setScore(0);
388
			this.growthLogDao.insert(con, growthLog);
389
			return false;
390
		}
391
	}
392
	
309 393
	/**
310 394
	 * 用户签到,第1天5分,连续2天6分,连续3天7分,连续4天8分,连续5天9分,连续5天以上10分
311 395
	 * @param con

+ 33 - 0
src/main/java/com/ekexiu/portal/service/GrowthRuleService.java

@ -105,6 +105,21 @@ public class GrowthRuleService {
105 105
	 * 分享资源
106 106
	 */
107 107
	private int shareResource = 20;
108
	/**
109
	 * 分享企业
110
	 */
111
	private int shareOrg = 20;
112
	/**
113
	 * 分享专利
114
	 */
115
	private int sharePatent = 20;
116
	/**
117
	 * 分享论文
118
	 */
119
	private int sharePaper = 20;
120
	
121
	
122
	
108 123
	/**
109 124
	 * 成功邀请一个好友
110 125
	 */
@ -397,5 +412,23 @@ public class GrowthRuleService {
397 412
	public void setSignInSixDays(int signInSixDays) {
398 413
		this.signInSixDays = signInSixDays;
399 414
	}
415
	public int getShareOrg() {
416
		return shareOrg;
417
	}
418
	public void setShareOrg(int shareOrg) {
419
		this.shareOrg = shareOrg;
420
	}
421
	public int getSharePatent() {
422
		return sharePatent;
423
	}
424
	public void setSharePatent(int sharePatent) {
425
		this.sharePatent = sharePatent;
426
	}
427
	public int getSharePaper() {
428
		return sharePaper;
429
	}
430
	public void setSharePaper(int sharePaper) {
431
		this.sharePaper = sharePaper;
432
	}
400 433
	
401 434
}