Просмотр исходного кода

--科研文章修改-201705121510

zzy.zhiyuan.foxmail лет назад: 8
Родитель
Сommit
bfefac6d5b

+ 169 - 0
src/main/java/com/ekexiu/portal/dao/ArticleDao.java

14
import org.jfw.apt.orm.annotation.dao.method.From;
14
import org.jfw.apt.orm.annotation.dao.method.From;
15
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
15
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
16
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
16
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
17
import org.jfw.apt.orm.annotation.dao.method.Where;
17
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
18
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
18
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
19
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
19
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
20
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
21
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
20
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
22
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
21
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
23
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
22
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
24
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
23
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
25
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
24
import org.jfw.apt.orm.annotation.dao.param.LessThan;
26
import org.jfw.apt.orm.annotation.dao.param.LessThan;
27
import org.jfw.apt.orm.annotation.dao.param.Like;
25
import org.jfw.apt.orm.annotation.dao.param.Set;
28
import org.jfw.apt.orm.annotation.dao.param.Set;
26
import org.jfw.util.PageQueryResult;
29
import org.jfw.util.PageQueryResult;
27

30

37
	@Dynamic
40
	@Dynamic
38
	public abstract int update(Connection con, Article article) throws SQLException;
41
	public abstract int update(Connection con, Article article) throws SQLException;
39
	
42
	
43
	@UpdateWith
44
	@From(Article.class)
45
	@SetSentence("PAGE_VIEWS = PAGE_VIEWS + 1")
46
	public abstract int incPageViews(Connection con,String articleId) throws SQLException;
47
	
48
	@UpdateWith
49
	@From(Article.class)
50
	public abstract int updateStatus(Connection con,String articleId,@Set String status) throws SQLException;
51
	
52
	@UpdateWith
53
	@From(Article.class)
54
	public abstract int updatePublishTime(Connection con,String articleId,@Set String status,@Set String publishTime) throws SQLException;
55
	
40
	@UpdateWith
56
	@UpdateWith
41
	@From(Article.class)
57
	@From(Article.class)
42
	@SetSentence("ARTICLE_AGREE = ARTICLE_AGREE + 1")
58
	@SetSentence("ARTICLE_AGREE = ARTICLE_AGREE + 1")
63
	@From(Article.class)
79
	@From(Article.class)
64
	public abstract int deletePro(Connection con, String professorId) throws SQLException;
80
	public abstract int deletePro(Connection con, String professorId) throws SQLException;
65
	
81
	
82
	@SelectList
83
	@Where("STATUS = '2'")
84
	public abstract List<Article> queryTiming(Connection con, @LessThan String publishTime) throws SQLException;
85
	
66
	@SelectList
86
	@SelectList
67
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
87
	@OrderBy(" ORDER BY MODIFY_TIME DESC ")
68
	public abstract List<Article> queryPro(Connection con, String professorId) throws SQLException;
88
	public abstract List<Article> queryPro(Connection con, String professorId) throws SQLException;
79
	@Nullable
99
	@Nullable
80
	public abstract Article queryOne(Connection con, String articleId) throws SQLException;
100
	public abstract Article queryOne(Connection con, String articleId) throws SQLException;
81
	
101
	
102
	@PageSelect
103
	@OrderBy("ORDER BY PUBLISH_TIME DESC")
104
	@Where("STATUS = '1'")
105
	public abstract PageQueryResult<Article> queryPageForPublish(Connection con,@Like@Nullable String articleTitle,int pageSize,int pageNo) throws SQLException;
106
	
107
	public PageQueryResult<Article> queryPageForSelf(Connection con,@Nullable String articleTitle,int pageSize,int pageNo) throws SQLException{
108
        int total = 0;
109
        PageQueryResult<Article> queryResult = new PageQueryResult<Article>();
110
        int index = 1;
111
        boolean hasArticleTitle = null != articleTitle;
112
        StringBuilder sql = new StringBuilder();
113
        sql.append("SELECT COUNT(1) FROM ARTICLE WHERE STATUS IN('0','1','2')");
114
        if(hasArticleTitle){
115
        	sql.append(" AND ARTICLE_TITLE LIKE ?");
116
        }
117
        PreparedStatement ps = con.prepareStatement(sql.toString());
118
        try{
119
        	if(hasArticleTitle){
120
        		ps.setString(index++, articleTitle);
121
        	}
122
        	queryResult.setPageSize(pageSize);
123
            ResultSet rs = ps.executeQuery();
124
            try{
125
                rs.next();
126
                total = rs.getInt(1);
127
            }finally{
128
                try{rs.close();}catch(Exception e1){}
129
            }
130
        }finally{
131
            try{ps.close();}catch(Exception e2){}
132
        }
133
        queryResult.setTotal(total);
134
        if(0== total){
135
        	queryResult.setPageNo(1);
136
        	queryResult.setData(Collections.<Article>emptyList());
137
            return queryResult;
138
        }
139
        boolean firstPage = (1 == pageNo);
140
        if(firstPage){
141
        	queryResult.setPageNo(1);
142
        	sql = new StringBuilder();
143
        	sql.append("(SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,ARTICLE_CONTENT,SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME FROM ARTICLE WHERE STATUS IN('0','2')");
144
        	if(hasArticleTitle){
145
        		sql.append(" AND ARTICLE_TITLE LIKE ?");
146
        	}
147
        	sql.append(" ORDER BY MODIFY_TIME DESC) UNION ALL (SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,ARTICLE_CONTENT,SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME FROM ARTICLE WHERE STATUS = '1'");
148
        	if(hasArticleTitle){
149
        		sql.append(" AND ARTICLE_TITLE LIKE ?");
150
        	}
151
        	sql.append(" ORDER BY PUBLISH_TIME DESC)");
152
        	sql.append(" LIMIT ").append(pageSize);
153
        }else{
154
            int pageNum = total / pageSize;
155
            if(total % pageSize != 0){
156
                ++pageNum;
157
            }
158
            if(pageNo > pageNum){
159
                pageNo = pageNum;
160
            }
161
            queryResult.setPageNo(pageNo);
162
            --pageNo;
163
            int offset = (pageNo * pageSize);
164
            sql.append("(SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,ARTICLE_CONTENT,SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME FROM ARTICLE WHERE STATUS IN('0','2')");
165
        	if(hasArticleTitle){
166
        		sql.append(" AND ARTICLE_TITLE LIKE ?");
167
        	}
168
        	sql.append(" ORDER BY MODIFY_TIME DESC) UNION ALL (SELECT ARTICLE_ID,PROFESSOR_ID,ARTICLE_TITLE,ARTICLE_CONTENT,SUBJECT,INDUSTRY,PUBLISH_TIME,ARTICLE_IMG,ORG_ID,ARTICLE_TYPE,ARTICLE_AGREE,PAGE_VIEWS,STATUS,CREATE_TIME,MODIFY_TIME FROM ARTICLE WHERE STATUS = '1'");
169
        	if(hasArticleTitle){
170
        		sql.append(" AND ARTICLE_TITLE LIKE ?");
171
        	}
172
        	sql.append(" ORDER BY PUBLISH_TIME DESC)");
173
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
174
        }
175
        ps = con.prepareStatement(sql.toString());
176
        try{
177
        	if(hasArticleTitle){
178
        		ps.setString(index++, articleTitle);
179
        		ps.setString(index++, articleTitle);
180
        	}
181
            ResultSet rs = ps.executeQuery();
182
            try{
183
                List<Article> articles = new ArrayList<Article>();
184
                queryResult.setData(articles);
185
                int size = 0;
186
                while((size<pageSize) && rs.next()){
187
                    ++size;
188
                    Article article =  new Article();
189
                    article.setArticleId(rs.getString(1));
190
                    String professorId = rs.getString(2);
191
                    if(rs.wasNull()){
192
                    	professorId = null;
193
                    }
194
                    article.setProfessorId(professorId);
195
                    article.setArticleTitle(rs.getString(3));
196
                    String articleContent = rs.getString(4);
197
                    if(rs.wasNull()){
198
                    	articleContent = null;
199
                    }
200
                    article.setArticleContent(articleContent);
201
                    String subject = rs.getString(5);
202
                    if(rs.wasNull()){
203
                    	subject = null;
204
                    }
205
                    article.setSubject(subject);
206
                    String industry = rs.getString(6);
207
                    if(rs.wasNull()){
208
                    	industry = null;
209
                    }
210
                    article.setIndustry(industry);
211
                    String publishTime = rs.getString(7);
212
                    if(rs.wasNull()){
213
                    	publishTime = null;
214
                    }
215
                    article.setPublishTime(publishTime);
216
                    String articleImg = rs.getString(8);
217
                    if(rs.wasNull()){
218
                    	articleImg = null;
219
                    }
220
                    article.setArticleImg(articleImg);
221
                    String orgId = rs.getString(9);
222
                    if(rs.wasNull()){
223
                    	orgId = null;
224
                    }
225
                    article.setOrgId(orgId);
226
                    String articleType = rs.getString(10);
227
                    if(rs.wasNull()){
228
                    	articleType = null;
229
                    }
230
                    article.setArticleType(articleType);
231
                    article.setArticleAgree(rs.getInt(11));
232
                    article.setPageViews(rs.getInt(12));
233
                    String status = rs.getString(13);
234
                    if(rs.wasNull()){
235
                    	status = null;
236
                    }
237
                    article.setStatus(status);
238
                    article.setCreateTime(rs.getString(14));
239
                    article.setModifyTime(rs.getString(15));
240
                    articles.add(article);
241
                }
242
                return queryResult;
243
            }finally{
244
                try{rs.close();}catch(Exception e3){}
245
            }
246
        }finally{
247
            try{ps.close();}catch(Exception e4){}
248
        }
249
    }
250
	
82
	public PageQueryResult<FindInfo> queryPage(Connection con,int pageSize,int pageNo) throws SQLException{
251
	public PageQueryResult<FindInfo> queryPage(Connection con,int pageSize,int pageNo) throws SQLException{
83
        int total = 0;
252
        int total = 0;
84
        PageQueryResult<FindInfo> queryResult = new PageQueryResult<FindInfo>();
253
        PageQueryResult<FindInfo> queryResult = new PageQueryResult<FindInfo>();

+ 37 - 0
src/main/java/com/ekexiu/portal/dao/ArticleProDao.java

1
package com.ekexiu.portal.dao;
2

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

7
import org.jfw.apt.annotation.DefaultValue;
8
import org.jfw.apt.orm.annotation.dao.Column;
9
import org.jfw.apt.orm.annotation.dao.DAO;
10
import org.jfw.apt.orm.annotation.dao.method.From;
11
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
12
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
13
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
14
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
15
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
16

17
import com.ekexiu.portal.po.ArticlePro;
18

19
@DAO
20
public abstract class ArticleProDao {
21
	@Insert
22
	public abstract int insert(Connection con, ArticlePro articlePro) throws SQLException;
23

24
	@QueryVal
25
	@From(ArticlePro.class)
26
	@Column(handlerClass = IntHandler.class, value = "COUNT(1)")
27
	@DefaultValue("0")
28
	public abstract int queryByArticleId(Connection con, String articleId) throws SQLException;
29

30
	@SelectList
31
	public abstract List<ArticlePro> query(Connection con, String articleId) throws SQLException;
32
	
33
	@DeleteWith
34
	@From(ArticlePro.class)
35
	public abstract int delete(Connection con, String articleId) throws SQLException;
36

37
}

+ 38 - 0
src/main/java/com/ekexiu/portal/dao/ArticleResDao.java

1
package com.ekexiu.portal.dao;
2

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

7
import org.jfw.apt.annotation.DefaultValue;
8
import org.jfw.apt.orm.annotation.dao.Column;
9
import org.jfw.apt.orm.annotation.dao.DAO;
10
import org.jfw.apt.orm.annotation.dao.method.From;
11
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
12
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
13
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
14
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
15
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
16

17
import com.ekexiu.portal.po.ArticlePro;
18
import com.ekexiu.portal.po.ArticleRes;
19

20
@DAO
21
public abstract class ArticleResDao {
22
	@Insert
23
	public abstract int insert(Connection con, ArticleRes articleRes) throws SQLException;
24

25
	@QueryVal
26
	@From(ArticlePro.class)
27
	@Column(handlerClass = IntHandler.class, value = "COUNT(1)")
28
	@DefaultValue("0")
29
	public abstract int queryByArticleId(Connection con, String articleId) throws SQLException;
30

31
	@SelectList
32
	public abstract List<ArticleRes> query(Connection con, String articleId) throws SQLException;
33
	
34
	@DeleteWith
35
	@From(ArticleRes.class)
36
	public abstract int delete(Connection con, String articleId) throws SQLException;
37

38
}

+ 69 - 0
src/main/java/com/ekexiu/portal/job/ArticleTaskJobEntry.java

1
package com.ekexiu.portal.job;
2

3
import java.sql.Connection;
4
import java.text.SimpleDateFormat;
5
import java.util.Date;
6
import java.util.List;
7

8
import javax.sql.DataSource;
9

10
import org.apache.log4j.Logger;
11
import org.jfw.apt.annotation.Autowrie;
12
import org.jfw.apt.annotation.Bean;
13

14
import com.ekexiu.portal.dao.ArticleDao;
15
import com.ekexiu.portal.po.Article;
16

17
@Bean
18
public class ArticleTaskJobEntry implements Runnable {
19
	private static Logger logger = Logger.getLogger(ArticleTaskJobEntry.class);
20
	private long delayTime = 10 * 60;
21
	private String dateFormat = "yyyyMMddHHmmss";
22
	@Autowrie("dataSource")
23
	private DataSource dataSource;
24
	@Autowrie
25
	private ArticleDao articleDao;
26
	public long getDelayTime() {
27
		return delayTime;
28
	}
29
	public void setDelayTime(long delayTime) {
30
		this.delayTime = delayTime;
31
	}
32
	public DataSource getDataSource() {
33
		return dataSource;
34
	}
35
	public void setDataSource(DataSource dataSource) {
36
		this.dataSource = dataSource;
37
	}
38
	public ArticleDao getArticleDao() {
39
		return articleDao;
40
	}
41
	public void setArticleDao(ArticleDao articleDao) {
42
		this.articleDao = articleDao;
43
	}
44
	
45
	@Override
46
	public void run() {
47
		try {
48
			Connection con =dataSource.getConnection();
49
			try{
50
				SimpleDateFormat df = new SimpleDateFormat(this.dateFormat);
51
				List<Article> articles = this.articleDao.queryTiming(con, df.format(new Date()));
52
				for (Article article : articles) {
53
					this.articleDao.updateStatus(con, article.getArticleId(), "1");
54
					logger.info("定时发布文章:"+article.getArticleId()+"--"+df.format(new Date()));
55
				}
56
                con.commit();
57
            }catch(Exception e){
58
                try{con.rollback();
59
                }catch(Exception e1){e1.printStackTrace();}
60
            }finally{
61
                try{con.close();
62
                }catch(Exception e2){e2.printStackTrace();} 
63
            }
64
		} catch (Exception e) {
65
			e.printStackTrace();
66
		}
67
	}
68
	
69
}

+ 2 - 0
src/main/java/com/ekexiu/portal/job/TaskJob.java

21
	@Override
21
	@Override
22
	public void handle(BeanFactory bf) throws Throwable {
22
	public void handle(BeanFactory bf) throws Throwable {
23
	
23
	
24
		ArticleTaskJobEntry atje = (ArticleTaskJobEntry) bf.getBean("com_ekexiu_portal_job_ArticleTaskJobEntry");
24
		TaskJobEntry tje = (TaskJobEntry) bf.getBean("com_ekexiu_portal_job_TaskJobEntry");
25
		TaskJobEntry tje = (TaskJobEntry) bf.getBean("com_ekexiu_portal_job_TaskJobEntry");
25
		ProScoreTaskJobEntry pstje = (ProScoreTaskJobEntry) bf.getBean("com_ekexiu_portal_job_ProScoreTaskJobEntry");
26
		ProScoreTaskJobEntry pstje = (ProScoreTaskJobEntry) bf.getBean("com_ekexiu_portal_job_ProScoreTaskJobEntry");
26
//		UserLogTaskJobEntry ultje = (UserLogTaskJobEntry) bf.getBean("com_ekexiu_portal_job_UserLogTaskJobEntry");
27
//		UserLogTaskJobEntry ultje = (UserLogTaskJobEntry) bf.getBean("com_ekexiu_portal_job_UserLogTaskJobEntry");
34
		
35
		
35
        this.service = JfwAppContext.getScheduledExecutorService();
36
        this.service = JfwAppContext.getScheduledExecutorService();
36
        // 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间  
37
        // 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间  
38
        service.scheduleAtFixedRate(atje, 1, atje.getDelayTime(), TimeUnit.SECONDS);
37
		service.scheduleAtFixedRate(tje, taskTime, delayTime, TimeUnit.MILLISECONDS);
39
		service.scheduleAtFixedRate(tje, taskTime, delayTime, TimeUnit.MILLISECONDS);
38
		
40
		
39
		long pstjeTask = getTimeMillis(pstje.getTaskTime());
41
		long pstjeTask = getTimeMillis(pstje.getTaskTime());

+ 26 - 1
src/main/java/com/ekexiu/portal/po/Article.java

4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5
import org.jfw.apt.orm.annotation.entry.Table;
5
import org.jfw.apt.orm.annotation.entry.Table;
6
import org.jfw.apt.orm.core.defaultImpl.FixLenStringHandler;
6
import org.jfw.apt.orm.core.defaultImpl.FixLenStringHandler;
7
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
7
import org.jfw.apt.orm.core.enums.DE;
8
import org.jfw.apt.orm.core.enums.DE;
8

9

9
import com.ekexiu.portal.basepo.CreateTimeSupported;
10
import com.ekexiu.portal.basepo.CreateTimeSupported;
21
	private String industry;
22
	private String industry;
22
	private String createTime;
23
	private String createTime;
23
	private String modifyTime;
24
	private String modifyTime;
25
	private String publishTime;
24
	private String articleImg;
26
	private String articleImg;
25
	private String orgId;
27
	private String orgId;
26
	private String articleType;
28
	private String articleType;
27
	private int articleAgree;
29
	private int articleAgree;
30
	private int pageViews;
31
	private String status;
28
	private EditProfessor professor;
32
	private EditProfessor professor;
29
	private Organization organization;
33
	private Organization organization;
30
	
34
	
94
	public void setModifyTime(String modifyTime) {
98
	public void setModifyTime(String modifyTime) {
95
		this.modifyTime = modifyTime;
99
		this.modifyTime = modifyTime;
96
	}
100
	}
101
	@Column(handlerClass=FixLenStringHandler.class,dbType="CHAR(14)",nullable=true,renewable=false)
102
	public String getPublishTime() {
103
		return publishTime;
104
	}
105
	public void setPublishTime(String publishTime) {
106
		this.publishTime = publishTime;
107
	}
97
	@Column(DE.String_de)
108
	@Column(DE.String_de)
98
	public String getArticleImg() {
109
	public String getArticleImg() {
99
		return articleImg;
110
		return articleImg;
115
	public void setArticleType(String articleType) {
126
	public void setArticleType(String articleType) {
116
		this.articleType = articleType;
127
		this.articleType = articleType;
117
	}
128
	}
118
	@Column(DE.int_de)
129
	@Column(handlerClass=IntHandler.class,dbType="INTEGER",renewable=false)
119
	public int getArticleAgree() {
130
	public int getArticleAgree() {
120
		return articleAgree;
131
		return articleAgree;
121
	}
132
	}
122
	public void setArticleAgree(int articleAgree) {
133
	public void setArticleAgree(int articleAgree) {
123
		this.articleAgree = articleAgree;
134
		this.articleAgree = articleAgree;
124
	}
135
	}
136
	@Column(handlerClass=IntHandler.class,dbType="INTEGER",nullable=true,renewable=false)
137
	public int getPageViews() {
138
		return pageViews;
139
	}
140
	public void setPageViews(int pageViews) {
141
		this.pageViews = pageViews;
142
	}
143
	@Column(handlerClass=FixLenStringHandler.class,dbType="CHAR(1)",nullable=true,renewable=false)
144
	public String getStatus() {
145
		return status;
146
	}
147
	public void setStatus(String status) {
148
		this.status = status;
149
	}
125

150

126
}
151
}

+ 43 - 0
src/main/java/com/ekexiu/portal/po/ArticlePro.java

1
package com.ekexiu.portal.po;
2

3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.Table;
5
import org.jfw.apt.orm.annotation.entry.Unique;
6
import org.jfw.apt.orm.annotation.entry.Uniques;
7
import org.jfw.apt.orm.core.enums.DE;
8

9
import com.ekexiu.portal.basepo.CreateTimeSupported;
10

11
@Table
12
@Uniques(@Unique(clolumns = { "articleId", "professorId" }, name = "ARTICLE_PRO_UQ"))
13
public class ArticlePro implements CreateTimeSupported {
14
	private String articleId;
15
	private String professorId;
16
	private String createTime;
17

18
	@Column(DE.id_32)
19
	public String getArticleId() {
20
		return articleId;
21
	}
22

23
	public void setArticleId(String articleId) {
24
		this.articleId = articleId;
25
	}
26

27
	@Column(DE.id_32)
28
	public String getProfessorId() {
29
		return professorId;
30
	}
31

32
	public void setProfessorId(String professorId) {
33
		this.professorId = professorId;
34
	}
35

36
	public String getCreateTime() {
37
		return createTime;
38
	}
39

40
	public void setCreateTime(String createTime) {
41
		this.createTime = createTime;
42
	}
43
}

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

1
package com.ekexiu.portal.po;
2

3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.Table;
5
import org.jfw.apt.orm.annotation.entry.Unique;
6
import org.jfw.apt.orm.annotation.entry.Uniques;
7
import org.jfw.apt.orm.core.enums.DE;
8

9
import com.ekexiu.portal.basepo.CreateTimeSupported;
10

11
@Table
12
@Uniques(@Unique(clolumns = { "articleId", "resourceId" }, name = "ARTICLE_RES_UQ"))
13
public class ArticleRes implements CreateTimeSupported {
14
	private String articleId;
15
	private String resourceId;
16
	private String createTime;
17

18
	@Column(DE.id_32)
19
	public String getArticleId() {
20
		return articleId;
21
	}
22

23
	public void setArticleId(String articleId) {
24
		this.articleId = articleId;
25
	}
26

27
	@Column(DE.id_32)
28
	public String getResourceId() {
29
		return resourceId;
30
	}
31

32
	public void setResourceId(String resourceId) {
33
		this.resourceId = resourceId;
34
	}
35

36
	public String getCreateTime() {
37
		return createTime;
38
	}
39

40
	public void setCreateTime(String createTime) {
41
		this.createTime = createTime;
42
	}
43
}

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

15

15

16
import org.jfw.apt.annotation.Autowrie;
16
import org.jfw.apt.annotation.Autowrie;
17
import org.jfw.apt.annotation.DefaultValue;
17
import org.jfw.apt.annotation.DefaultValue;
18
import org.jfw.apt.annotation.Nullable;
18
import org.jfw.apt.web.annotation.Path;
19
import org.jfw.apt.web.annotation.Path;
19
import org.jfw.apt.web.annotation.operate.Get;
20
import org.jfw.apt.web.annotation.operate.Get;
20
import org.jfw.apt.web.annotation.operate.Post;
21
import org.jfw.apt.web.annotation.operate.Post;
27

28

28
import com.ekexiu.portal.dao.ArticleAgreeDao;
29
import com.ekexiu.portal.dao.ArticleAgreeDao;
29
import com.ekexiu.portal.dao.ArticleDao;
30
import com.ekexiu.portal.dao.ArticleDao;
31
import com.ekexiu.portal.dao.ArticleProDao;
32
import com.ekexiu.portal.dao.ArticleResDao;
30
import com.ekexiu.portal.dao.LeaveWordDao;
33
import com.ekexiu.portal.dao.LeaveWordDao;
31
import com.ekexiu.portal.dao.OrgDao;
34
import com.ekexiu.portal.dao.OrgDao;
32
import com.ekexiu.portal.dao.ProfessorDao;
35
import com.ekexiu.portal.dao.ProfessorDao;
35
import com.ekexiu.portal.dao.WatchDao;
38
import com.ekexiu.portal.dao.WatchDao;
36
import com.ekexiu.portal.po.Article;
39
import com.ekexiu.portal.po.Article;
37
import com.ekexiu.portal.po.ArticleAgree;
40
import com.ekexiu.portal.po.ArticleAgree;
41
import com.ekexiu.portal.po.ArticlePro;
42
import com.ekexiu.portal.po.ArticleRes;
38
import com.ekexiu.portal.po.Image;
43
import com.ekexiu.portal.po.Image;
39
import com.ekexiu.portal.pojo.FindInfo;
44
import com.ekexiu.portal.pojo.FindInfo;
40

45

43
	private File tmpPath;
48
	private File tmpPath;
44
	private File articlePath;
49
	private File articlePath;
45
	private String dateFormat = "yyyyMMdd";
50
	private String dateFormat = "yyyyMMdd";
51
	private String timeFormat = "yyyyMMddHHmmss";
46
	private int artMaxLen=640;
52
	private int artMaxLen=640;
47
	private static final String JPG = "jpg";
53
	private static final String JPG = "jpg";
48
	public static final String MAX_MODIFYTIME = "9";
54
	public static final String MAX_MODIFYTIME = "9";
66
	private OrgDao orgDao;
72
	private OrgDao orgDao;
67
	@Autowrie
73
	@Autowrie
68
	private WatchDao watchDao;
74
	private WatchDao watchDao;
75
	@Autowrie
76
	private ArticleProDao articleProDao;
77
	@Autowrie
78
	private ArticleResDao articleResDao;
69

79

70
	public String getDateFormat() {
80
	public String getDateFormat() {
71
		return dateFormat;
81
		return dateFormat;
75
		this.dateFormat = dateFormat;
85
		this.dateFormat = dateFormat;
76
	}
86
	}
77

87

88
	public String getTimeFormat() {
89
		return timeFormat;
90
	}
91

92
	public void setTimeFormat(String timeFormat) {
93
		this.timeFormat = timeFormat;
94
	}
95

78
	public File getTmpPath() {
96
	public File getTmpPath() {
79
		return tmpPath;
97
		return tmpPath;
80
	}
98
	}
179
		this.watchDao = watchDao;
197
		this.watchDao = watchDao;
180
	}
198
	}
181

199

200
	public ArticleProDao getArticleProDao() {
201
		return articleProDao;
202
	}
203

204
	public void setArticleProDao(ArticleProDao articleProDao) {
205
		this.articleProDao = articleProDao;
206
	}
207

208
	public ArticleResDao getArticleResDao() {
209
		return articleResDao;
210
	}
211

212
	public void setArticleResDao(ArticleResDao articleResDao) {
213
		this.articleResDao = articleResDao;
214
	}
215

182
	private byte[] resImage(byte[] src, int maxLen) throws IOException {
216
	private byte[] resImage(byte[] src, int maxLen) throws IOException {
183
		ByteArrayInputStream in = new ByteArrayInputStream(src);
217
		ByteArrayInputStream in = new ByteArrayInputStream(src);
184
		ByteArrayOutputStream out = new ByteArrayOutputStream();
218
		ByteArrayOutputStream out = new ByteArrayOutputStream();
221
		return date;
255
		return date;
222
	}
256
	}
223
	
257
	
258
	private String publishTime(){
259
		SimpleDateFormat df = new SimpleDateFormat(this.timeFormat);
260
		String publishTime = df.format(new Date());
261
		return publishTime;
262
	}
263
	
224
	@Post
264
	@Post
225
	@Path
265
	@Path
226
	public String insert(@JdbcConn(true) Connection con, Article article) 
266
	public String insert(@JdbcConn(true) Connection con, Article article) 
232
		}
272
		}
233
		article.setArticleId(articleId);
273
		article.setArticleId(articleId);
234
		article.setArticleAgree(0);
274
		article.setArticleAgree(0);
275
		article.setPageViews(0);
276
		article.setStatus("1");
277
		article.setPublishTime(this.publishTime());
235
		if(article.getProfessorId() != null && article.getOrgId() == null){
278
		if(article.getProfessorId() != null && article.getOrgId() == null){
236
			article.setArticleType("1");
279
			article.setArticleType("1");
237
		}else if(article.getProfessorId() == null && article.getOrgId() != null){
280
		}else if(article.getProfessorId() == null && article.getOrgId() != null){
243
		return articleId;
286
		return articleId;
244
	}
287
	}
245
	
288
	
289
	@Post
290
	@Path("/save")
291
	public String saveArticle(@JdbcConn(true) Connection con,Article article,String[] professors,String[] resources)
292
			throws SQLException, IOException, JfwBaseException{
293
		if(article.getArticleId() == null){
294
			String articleId = StringUtil.buildUUID();
295
			if(article.getArticleImg() != null){
296
				this.saveArtImg(article.getArticleImg(), articleId);
297
				article.setArticleImg(this.createDate()+"/"+articleId+"."+JPG);
298
			}
299
			article.setArticleId(articleId);
300
			article.setArticleAgree(0);
301
			article.setPageViews(0);
302
			article.setStatus("1");
303
			article.setPublishTime(this.publishTime());
304
			if(article.getProfessorId() != null && article.getOrgId() == null){
305
				article.setArticleType("1");
306
			}else if(article.getProfessorId() == null && article.getOrgId() != null){
307
				article.setArticleType("2");
308
			}else{
309
				throw new JfwBaseException(-1, "错误参数:文章发布者ID");
310
			}
311
			this.articleDao.insert(con, article);
312
			for (String professor : professors) {
313
				ArticlePro articlePro = new ArticlePro();
314
				articlePro.setArticleId(articleId);
315
				articlePro.setProfessorId(professor);
316
				this.articleProDao.insert(con, articlePro);
317
			}
318
			for (String resource : resources) {
319
				ArticleRes articleRes = new ArticleRes();
320
				articleRes.setArticleId(articleId);
321
				articleRes.setResourceId(resource);
322
				this.articleResDao.insert(con, articleRes);
323
			}
324
			return articleId;
325
		}else if(article.getArticleId().trim().length() == 32){
326
			if(article.getArticleImg() != null){
327
				this.saveArtImg(article.getArticleImg(), article.getArticleId());
328
				article.setArticleImg(this.createDate()+"/"+article.getArticleId()+"."+JPG);
329
			}
330
			this.articleDao.update(con, article);
331
			this.articleDao.updatePublishTime(con, article.getArticleId(), "1", this.publishTime());
332
			this.articleProDao.delete(con, article.getArticleId());
333
			this.articleResDao.delete(con, article.getArticleId());
334
			for (String professor : professors) {
335
				ArticlePro articlePro = new ArticlePro();
336
				articlePro.setArticleId(article.getArticleId());
337
				articlePro.setProfessorId(professor);
338
				this.articleProDao.insert(con, articlePro);
339
			}
340
			for (String resource : resources) {
341
				ArticleRes articleRes = new ArticleRes();
342
				articleRes.setArticleId(article.getArticleId());
343
				articleRes.setResourceId(resource);
344
				this.articleResDao.insert(con, articleRes);
345
			}
346
			return article.getArticleId();
347
		}else{
348
			throw new JfwBaseException(-2, "bad parameter:articleId");
349
		}
350
	}
351
	
352
	@Post
353
	@Path("/draft")
354
	public String draft(@JdbcConn(true) Connection con,Article article,String[] professors,String[] resources)
355
			throws SQLException, IOException, JfwBaseException{
356
		if(article.getArticleId() == null){
357
			String articleId = StringUtil.buildUUID();
358
			if(article.getArticleImg() != null){
359
				this.saveArtImg(article.getArticleImg(), articleId);
360
				article.setArticleImg(this.createDate()+"/"+articleId+"."+JPG);
361
			}
362
			article.setArticleId(articleId);
363
			article.setArticleAgree(0);
364
			article.setPageViews(0);
365
			article.setStatus("0");
366
			if(article.getProfessorId() != null && article.getOrgId() == null){
367
				article.setArticleType("1");
368
			}else if(article.getProfessorId() == null && article.getOrgId() != null){
369
				article.setArticleType("2");
370
			}else{
371
				throw new JfwBaseException(-1, "错误参数:文章发布者ID");
372
			}
373
			this.articleDao.insert(con, article);
374
			for (String professor : professors) {
375
				ArticlePro articlePro = new ArticlePro();
376
				articlePro.setArticleId(articleId);
377
				articlePro.setProfessorId(professor);
378
				this.articleProDao.insert(con, articlePro);
379
			}
380
			for (String resource : resources) {
381
				ArticleRes articleRes = new ArticleRes();
382
				articleRes.setArticleId(articleId);
383
				articleRes.setResourceId(resource);
384
				this.articleResDao.insert(con, articleRes);
385
			}
386
			return articleId;
387
		}else if(article.getArticleId().trim().length() == 32){
388
			if(article.getArticleImg() != null){
389
				this.saveArtImg(article.getArticleImg(), article.getArticleId());
390
				article.setArticleImg(this.createDate()+"/"+article.getArticleId()+"."+JPG);
391
			}
392
			this.articleDao.update(con, article);
393
			this.articleDao.updateStatus(con, article.getArticleId(), "0");
394
			this.articleProDao.delete(con, article.getArticleId());
395
			this.articleResDao.delete(con, article.getArticleId());
396
			for (String professor : professors) {
397
				ArticlePro articlePro = new ArticlePro();
398
				articlePro.setArticleId(article.getArticleId());
399
				articlePro.setProfessorId(professor);
400
				this.articleProDao.insert(con, articlePro);
401
			}
402
			for (String resource : resources) {
403
				ArticleRes articleRes = new ArticleRes();
404
				articleRes.setArticleId(article.getArticleId());
405
				articleRes.setResourceId(resource);
406
				this.articleResDao.insert(con, articleRes);
407
			}
408
			return article.getArticleId();
409
		}else{
410
			throw new JfwBaseException(-2, "bad parameter:articleId");
411
		}
412
	}
413
	
414
	@Post
415
	@Path("/timing")
416
	public String timingPublish(@JdbcConn(true) Connection con,Article article,String[] professors,String[] resources)
417
			throws SQLException, IOException, JfwBaseException{
418
		if(article.getPublishTime() == null){
419
			throw new JfwBaseException(-3, "no parameter found:publishTime");
420
		}
421
		if(article.getArticleId() == null){
422
			String articleId = StringUtil.buildUUID();
423
			if(article.getArticleImg() != null){
424
				this.saveArtImg(article.getArticleImg(), articleId);
425
				article.setArticleImg(this.createDate()+"/"+articleId+"."+JPG);
426
			}
427
			article.setArticleId(articleId);
428
			article.setArticleAgree(0);
429
			article.setPageViews(0);
430
			article.setStatus("2");
431
			if(article.getProfessorId() != null && article.getOrgId() == null){
432
				article.setArticleType("1");
433
			}else if(article.getProfessorId() == null && article.getOrgId() != null){
434
				article.setArticleType("2");
435
			}else{
436
				throw new JfwBaseException(-1, "错误参数:文章发布者ID");
437
			}
438
			this.articleDao.insert(con, article);
439
			for (String professor : professors) {
440
				ArticlePro articlePro = new ArticlePro();
441
				articlePro.setArticleId(articleId);
442
				articlePro.setProfessorId(professor);
443
				this.articleProDao.insert(con, articlePro);
444
			}
445
			for (String resource : resources) {
446
				ArticleRes articleRes = new ArticleRes();
447
				articleRes.setArticleId(articleId);
448
				articleRes.setResourceId(resource);
449
				this.articleResDao.insert(con, articleRes);
450
			}
451
			return articleId;
452
		}else if(article.getArticleId().trim().length() == 32){
453
			if(article.getArticleImg() != null){
454
				this.saveArtImg(article.getArticleImg(), article.getArticleId());
455
				article.setArticleImg(this.createDate()+"/"+article.getArticleId()+"."+JPG);
456
			}
457
			this.articleDao.update(con, article);
458
			this.articleDao.updatePublishTime(con, article.getArticleId(), "2", article.getPublishTime());
459
			this.articleProDao.delete(con, article.getArticleId());
460
			this.articleResDao.delete(con, article.getArticleId());
461
			for (String professor : professors) {
462
				ArticlePro articlePro = new ArticlePro();
463
				articlePro.setArticleId(article.getArticleId());
464
				articlePro.setProfessorId(professor);
465
				this.articleProDao.insert(con, articlePro);
466
			}
467
			for (String resource : resources) {
468
				ArticleRes articleRes = new ArticleRes();
469
				articleRes.setArticleId(article.getArticleId());
470
				articleRes.setResourceId(resource);
471
				this.articleResDao.insert(con, articleRes);
472
			}
473
			return article.getArticleId();
474
		}else{
475
			throw new JfwBaseException(-2, "bad parameter:articleId");
476
		}
477
	}
478
	
246
	@Post
479
	@Post
247
	@Path("/updateArt")
480
	@Path("/updateArt")
248
	public void update(@JdbcConn(true) Connection con, Article article) 
481
	public void update(@JdbcConn(true) Connection con, Article article) 
254
		this.articleDao.update(con, article);
487
		this.articleDao.update(con, article);
255
	}
488
	}
256
	
489
	
490
	@Post
491
	@Path("/pageViews")
492
	public void pageViews(@JdbcConn(true) Connection con,String articleId) throws SQLException{
493
		this.articleDao.incPageViews(con, articleId);
494
	}
495
	
496
	@Post
497
	@Path("/publish")
498
	public void publish(@JdbcConn(true) Connection con,String articleId) throws SQLException{
499
		//修改文章状态为发布
500
		this.articleDao.updateStatus(con, articleId, "1");
501
	}
502
	
503
	@Post
504
	@Path("/deleteArticle")
505
	public void deleteArticle(@JdbcConn(true) Connection con,String articleId) throws SQLException{
506
		//修改文章状态为删除
507
		this.articleDao.updateStatus(con, articleId, "3");
508
	}
509
	
510
	@Post
511
	@Path("/close")
512
	public void closeArticle(@JdbcConn(true) Connection con,String articleId) throws SQLException{
513
		//修改文章状态为关闭
514
		this.articleDao.updateStatus(con, articleId, "4");
515
	}
516
	
257
	@Post
517
	@Post
258
	@Path("/agree")
518
	@Path("/agree")
259
	public void agree(@JdbcConn(true) Connection con,String operateId,String articleId)throws SQLException{
519
	public void agree(@JdbcConn(true) Connection con,String operateId,String articleId)throws SQLException{
309
		return this.articleDao.queryOne(con, articleId);
569
		return this.articleDao.queryOne(con, articleId);
310
	}
570
	}
311
	
571
	
572
	@Get
573
	@Path("/pqpublish")
574
	public PageQueryResult<Article> queryPagePublish(@JdbcConn Connection con,@Nullable String articleTitle,
575
			@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
576
		if(articleTitle != null){
577
			articleTitle = "%" + articleTitle + "%";
578
		}
579
		return this.articleDao.queryPageForPublish(con, articleTitle, pageSize, pageNo);
580
	}
581
	
582
	@Get
583
	@Path("/pqself")
584
	public PageQueryResult<Article> queryPageSelf(@JdbcConn Connection con,@Nullable String articleTitle,
585
			@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
586
		if(articleTitle != null){
587
			articleTitle = "%" + articleTitle + "%";
588
		}
589
		return this.articleDao.queryPageForSelf(con, articleTitle, pageSize, pageNo);
590
	}
591
	
312
	@Get
592
	@Get
313
	@Path("/pqFind")
593
	@Path("/pqFind")
314
	public PageQueryResult<FindInfo> queryPage(@JdbcConn Connection con,@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
594
	public PageQueryResult<FindInfo> queryPage(@JdbcConn Connection con,@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
326
		return queryResult;
606
		return queryResult;
327
	}
607
	}
328
	
608
	
609
	@Get
610
	@Path("/ralatePro")
611
	public List<ArticlePro> ralatePro(@JdbcConn Connection con,String articleId) throws SQLException{
612
		return this.articleProDao.query(con, articleId);
613
	}
614
	
615
	@Get
616
	@Path("/ralateRes")
617
	public List<ArticleRes> ralateRes(@JdbcConn Connection con,String articleId) throws SQLException{
618
		return this.articleResDao.query(con, articleId);
619
	}
620
	
329
	@Post
621
	@Post
330
	@Path("/delete")
622
	@Path("/delete")
331
	public void delete(@JdbcConn(true) Connection con, String articleId) throws SQLException{
623
	public void delete(@JdbcConn(true) Connection con, String articleId) throws SQLException{