浏览代码

--add agree();add unAgree();

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

+ 31 - 0
src/main/java/com/ekexiu/portal/dao/ArcicleAgreeDao.java

@ -0,0 +1,31 @@
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.orm.annotation.dao.DAO;
8
import org.jfw.apt.orm.annotation.dao.method.From;
9
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
10
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
11
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
12

13
import com.ekexiu.portal.po.ArticleAgree;
14

15
@DAO
16
public abstract class ArcicleAgreeDao {
17
	@Insert
18
	public abstract int insert(Connection con,ArticleAgree articleAgree)throws SQLException;
19
	
20
	@DeleteWith
21
	@From(ArticleAgree.class)
22
	public abstract int deleteAgree(Connection con,String operateId,String articleId)throws SQLException;
23
	
24
	@DeleteWith
25
	@From(ArticleAgree.class)
26
	public abstract int delete(Connection con,String articleId)throws SQLException;
27
	
28
	@SelectList
29
	public abstract List<ArticleAgree> query(Connection con,String articleId)throws SQLException;
30
	
31
}

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

@ -13,6 +13,7 @@ import org.jfw.apt.orm.annotation.dao.DAO;
13 13
import org.jfw.apt.orm.annotation.dao.Dynamic;
14 14
import org.jfw.apt.orm.annotation.dao.method.From;
15 15
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
16
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
16 17
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
17 18
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
18 19
import org.jfw.apt.orm.annotation.dao.method.operator.LimitSelect;
@ -36,6 +37,16 @@ public abstract class ArticleDao {
36 37
	@Dynamic
37 38
	public abstract int update(Connection con, Article article) throws SQLException;
38 39
	
40
	@UpdateWith
41
	@From(Article.class)
42
	@SetSentence("ARTICLE_AGREE = ARTICLE_AGREE + 1")
43
	public abstract int incAgree(Connection con,String articleId) throws SQLException;
44
	
45
	@UpdateWith
46
	@From(Article.class)
47
	@SetSentence("ARTICLE_AGREE = ARTICLE_AGREE - 1")
48
	public abstract int decAgree(Connection con,String articleId) throws SQLException;
49
	
39 50
	@UpdateWith
40 51
	@From(Article.class)
41 52
	public abstract int updateSubject(Connection con, @Set String subject, String articleId) throws SQLException;

+ 21 - 21
src/main/java/com/ekexiu/portal/dao/ResearchAreaLogDao.java

@ -33,57 +33,57 @@ public abstract class ResearchAreaLogDao {
33 33
	public abstract int delete(Connection con,String professorId)throws SQLException;
34 34
	
35 35
	public List<EditResearchAreaLog> queryLimit(Connection con,String professorId,String caption,String createTime,int rows) throws SQLException{
36
        int _m_1 = 1;
36
        int index = 1;
37 37
        String sql = "SELECT OPRETE_PROFESSOR_ID,CREATE_TIME,PROFESSOR_ID,CAPTION FROM RESEARCH_AREA_LOG "
38 38
        		+ " WHERE CREATE_TIME < ? AND CAPTION = ? AND PROFESSOR_ID = ? ORDER BY CREATE_TIME DESC LIMIT "+rows;
39 39
        PreparedStatement ps = con.prepareStatement(sql);
40 40
        try{
41
            ps.setString(_m_1++,createTime);
42
            ps.setString(_m_1++,caption);
43
            ps.setString(_m_1++,professorId);
41
            ps.setString(index++,createTime);
42
            ps.setString(index++,caption);
43
            ps.setString(index++,professorId);
44 44
            ResultSet rs = ps.executeQuery();
45 45
            try{
46
                List<EditResearchAreaLog> _result = new ArrayList<EditResearchAreaLog>();
46
                List<EditResearchAreaLog> areaLogs = new ArrayList<EditResearchAreaLog>();
47 47
                while(rs.next()){
48
                	EditResearchAreaLog _obj =  new EditResearchAreaLog();
49
                    _obj.setOpreteProfessorId(rs.getString(1));
50
                    _obj.setCreateTime(rs.getString(2));
51
                    _obj.setProfessorId(rs.getString(3));
52
                    _obj.setCaption(rs.getString(4));
53
                    _result.add(_obj);
48
                	EditResearchAreaLog areaLog =  new EditResearchAreaLog();
49
                	areaLog.setOpreteProfessorId(rs.getString(1));
50
                	areaLog.setCreateTime(rs.getString(2));
51
                	areaLog.setProfessorId(rs.getString(3));
52
                	areaLog.setCaption(rs.getString(4));
53
                    areaLogs.add(areaLog);
54 54
                }
55
                return _result;
55
                return areaLogs;
56 56
            }finally{
57
                try{rs.close();}catch(Exception _m_2){}
57
                try{rs.close();}catch(Exception e1){}
58 58
            }
59 59
        }finally{
60
            try{ps.close();}catch(Exception _m_3){}
60
            try{ps.close();}catch(Exception e2){}
61 61
        }
62 62
    }
63 63
	
64 64
	public List<EditResearchAreaLog> query(Connection con,String professorId) throws SQLException{
65
        int _m_1 = 1;
65
        int index = 1;
66 66
        String sql = "SELECT OPRETE_PROFESSOR_ID,CREATE_TIME,PROFESSOR_ID,CAPTION FROM RESEARCH_AREA_LOG WHERE PROFESSOR_ID = ?";
67 67
        PreparedStatement ps = con.prepareStatement(sql);
68 68
        try{
69
            ps.setString(_m_1++,professorId);
69
            ps.setString(index++,professorId);
70 70
            ResultSet rs = ps.executeQuery();
71 71
            try{
72
                List<EditResearchAreaLog> _result = new ArrayList<EditResearchAreaLog>();
72
                List<EditResearchAreaLog> areaLogs = new ArrayList<EditResearchAreaLog>();
73 73
                while(rs.next()){
74 74
                	EditResearchAreaLog log =  new EditResearchAreaLog();
75 75
                	log.setOpreteProfessorId(rs.getString(1));
76 76
                	log.setCreateTime(rs.getString(2));
77 77
                	log.setProfessorId(rs.getString(3));
78 78
                	log.setCaption(rs.getString(4));
79
                    _result.add(log);
79
                	areaLogs.add(log);
80 80
                }
81
                return _result;
81
                return areaLogs;
82 82
            }finally{
83
                try{rs.close();}catch(Exception _m_2){}
83
                try{rs.close();}catch(Exception e1){}
84 84
            }
85 85
        }finally{
86
            try{ps.close();}catch(Exception _m_3){}
86
            try{ps.close();}catch(Exception e2){}
87 87
        }
88 88
    }
89 89

+ 36 - 0
src/main/java/com/ekexiu/portal/po/ArticleAgree.java

@ -0,0 +1,36 @@
1
package com.ekexiu.portal.po;
2

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

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

10
@Table
11
@PrimaryKey({"operateId","articleId"})
12
public class ArticleAgree implements CreateTimeSupported {
13
	private String operateId;
14
	private String articleId;
15
	private String createTime;
16
	@Column(DE.id_32)
17
	public String getOperateId() {
18
		return operateId;
19
	}
20
	public void setOperateId(String operateId) {
21
		this.operateId = operateId;
22
	}
23
	@Column(DE.id_32)
24
	public String getArticleId() {
25
		return articleId;
26
	}
27
	public void setArticleId(String articleId) {
28
		this.articleId = articleId;
29
	}
30
	public String getCreateTime() {
31
		return createTime;
32
	}
33
	public void setCreateTime(String createTime) {
34
		this.createTime = createTime;
35
	}
36
}

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

@ -25,13 +25,17 @@ import org.jfw.util.StringUtil;
25 25
import org.jfw.util.exception.JfwBaseException;
26 26
import org.jfw.util.io.IoUtil;
27 27

28
import com.ekexiu.portal.dao.ArcicleAgreeDao;
28 29
import com.ekexiu.portal.dao.ArticleDao;
29 30
import com.ekexiu.portal.dao.LeaveWordDao;
30 31
import com.ekexiu.portal.dao.OrgDao;
31 32
import com.ekexiu.portal.dao.ProfessorDao;
32 33
import com.ekexiu.portal.dao.ResearchAreaDao;
33 34
import com.ekexiu.portal.dao.ResourceDao;
35
import com.ekexiu.portal.dao.WatchDao;
34 36
import com.ekexiu.portal.po.Article;
37
import com.ekexiu.portal.po.ArticleAgree;
38
import com.ekexiu.portal.po.Image;
35 39
import com.ekexiu.portal.pojo.FindInfo;
36 40

37 41
@Path("/article")
@ -45,17 +49,23 @@ public class ArticleService {
45 49
	@Autowrie
46 50
	private ArticleDao articleDao;
47 51
	@Autowrie
52
	private ArcicleAgreeDao articleAgreeDao;
53
	@Autowrie
48 54
	private ProfessorDao professorDao;
49 55
	@Autowrie
50 56
	private ResourceDao resourceDao;
51 57
	@Autowrie
52 58
	private ImageService imageService;
53 59
	@Autowrie
60
	private ImagesService imagesService;
61
	@Autowrie
54 62
	private ResearchAreaDao researchAreaDao;
55 63
	@Autowrie
56 64
	private LeaveWordDao leaveWordDao;
57 65
	@Autowrie
58 66
	private OrgDao orgDao;
67
	@Autowrie
68
	private WatchDao watchDao;
59 69

60 70
	public String getDateFormat() {
61 71
		return dateFormat;
@ -97,6 +107,14 @@ public class ArticleService {
97 107
		this.articleDao = articleDao;
98 108
	}
99 109
	
110
	public ArcicleAgreeDao getArticleAgreeDao() {
111
		return articleAgreeDao;
112
	}
113

114
	public void setArticleAgreeDao(ArcicleAgreeDao articleAgreeDao) {
115
		this.articleAgreeDao = articleAgreeDao;
116
	}
117

100 118
	public ProfessorDao getProfessorDao() {
101 119
		return professorDao;
102 120
	}
@ -121,6 +139,14 @@ public class ArticleService {
121 139
		this.imageService = imageService;
122 140
	}
123 141

142
	public ImagesService getImagesService() {
143
		return imagesService;
144
	}
145

146
	public void setImagesService(ImagesService imagesService) {
147
		this.imagesService = imagesService;
148
	}
149

124 150
	public ResearchAreaDao getResearchAreaDao() {
125 151
		return researchAreaDao;
126 152
	}
@ -145,6 +171,14 @@ public class ArticleService {
145 171
		this.orgDao = orgDao;
146 172
	}
147 173

174
	public WatchDao getWatchDao() {
175
		return watchDao;
176
	}
177

178
	public void setWatchDao(WatchDao watchDao) {
179
		this.watchDao = watchDao;
180
	}
181

148 182
	private byte[] resImage(byte[] src, int maxLen) throws IOException {
149 183
		ByteArrayInputStream in = new ByteArrayInputStream(src);
150 184
		ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -197,6 +231,7 @@ public class ArticleService {
197 231
			article.setArticleImg(this.createDate()+"/"+articleId+"."+JPG);
198 232
		}
199 233
		article.setArticleId(articleId);
234
		article.setArticleAgree(0);
200 235
		if(article.getProfessorId() != null && article.getOrgId() == null){
201 236
			article.setArticleType("1");
202 237
		}else if(article.getProfessorId() == null && article.getOrgId() != null){
@ -219,6 +254,25 @@ public class ArticleService {
219 254
		this.articleDao.update(con, article);
220 255
	}
221 256
	
257
	@Post
258
	@Path("/agree")
259
	public void agree(@JdbcConn(true) Connection con,String operateId,String articleId)throws SQLException{
260
		if(this.articleDao.incAgree(con, articleId) > 0){
261
			ArticleAgree articleAgree = new ArticleAgree();
262
			articleAgree.setOperateId(operateId);
263
			articleAgree.setArticleId(articleId);
264
			this.articleAgreeDao.insert(con, articleAgree);
265
		}
266
	}
267
	
268
	@Post
269
	@Path("/unAgree")
270
	public void unAgree(@JdbcConn(true) Connection con,String operateId,String articleId)throws SQLException{
271
		if(this.articleDao.decAgree(con, articleId) > 0){
272
			this.articleAgreeDao.deleteAgree(con, operateId, articleId);
273
		}
274
	}
275
	
222 276
	@Get
223 277
	@Path("/qaPro")
224 278
	public List<Article> queryPro(@JdbcConn Connection con, String professorId) throws SQLException{
@ -247,6 +301,16 @@ public class ArticleService {
247 301
	@Path("/pqFind")
248 302
	public PageQueryResult<FindInfo> queryPage(@JdbcConn Connection con,@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
249 303
		PageQueryResult<FindInfo> queryResult = this.articleDao.queryPage(con, pageSize, pageNo);
304
		List<FindInfo> findInfos = queryResult.getData();
305
		for (FindInfo findInfo : findInfos) {
306
			if("3".equals(findInfo.getType())){
307
				List<Image> images = this.imagesService.queryRes(con, findInfo.getId());
308
				if(images.size() > 0){
309
					findInfo.setImage(findInfo.getId()+".jpg");
310
				}
311
			}
312
		}
313
		queryResult.setData(findInfos);
250 314
		return queryResult;
251 315
	}
252 316
	
@ -255,6 +319,8 @@ public class ArticleService {
255 319
	public void delete(@JdbcConn(true) Connection con, String articleId) throws SQLException{
256 320
		this.articleDao.delete(con, articleId);
257 321
		this.leaveWordDao.deleteArticle(con, articleId);
322
		this.articleAgreeDao.delete(con, articleId);
323
		this.watchDao.deleteWatch(con, articleId);
258 324
	}
259 325

260 326
}