jiapeng 7 years ago
parent
commit
bb958ecc53

+ 2 - 1
src/main/java/com/ekexiu/portal/question/Answer.java

11
@PrimaryKey("id")
11
@PrimaryKey("id")
12
@Uniques({@Unique(clolumns={"qid","uid"},name="UNI_ANSWER_QID_UID")})
12
@Uniques({@Unique(clolumns={"qid","uid"},name="UNI_ANSWER_QID_UID")})
13
@Table
13
@Table
14
public class Answer  implements ModifyTimeSupported{
14
public class Answer {
15
	private String id;
15
	private String id;
16
	private String qid;
16
	private String qid;
17
	private String uid;
17
	private String uid;
114
	public void setCreateTime(String createTime) {
114
	public void setCreateTime(String createTime) {
115
		this.createTime = createTime;
115
		this.createTime = createTime;
116
	}
116
	}
117
	@Column(DE.text_de)
117
	public String getModifyTime() {
118
	public String getModifyTime() {
118
		return modifyTime;
119
		return modifyTime;
119
	}
120
	}

+ 15 - 1
src/main/java/com/ekexiu/portal/question/QuestionDao.java

42
	@SetSentence("REPLY_COUNT=REPLY_COUNT+1")
42
	@SetSentence("REPLY_COUNT=REPLY_COUNT+1")
43
	int incQuestionReply(Connection con,String id)throws SQLException;
43
	int incQuestionReply(Connection con,String id)throws SQLException;
44
	
44
	
45
	@UpdateWith
46
	@From(Question.class)
47
	@SetSentence("REPLY_COUNT=REPLY_COUNT+1")
48
	int onlyIncQuestionReply(Connection con,String id)throws SQLException;
49
	
50
	
51
	
45
	@UpdateWith
52
	@UpdateWith
46
	@From(Question.class)
53
	@From(Question.class)
47
	@SetSentence("REPLY_COUNT=REPLY_COUNT-1")
54
	@SetSentence("REPLY_COUNT=REPLY_COUNT-1")
78
	@SetSentence("STATE='0'")
85
	@SetSentence("STATE='0'")
79
	@Where("STATE ='1'")
86
	@Where("STATE ='1'")
80
	int logicDeleteAnswer(Connection con,String id)throws SQLException;
87
	int logicDeleteAnswer(Connection con,String id)throws SQLException;
88
	
89
	@UpdateWith
90
	@From(Answer.class)
91
	@SetSentence("STATE='1'")
92
	@Where("STATE <>'1'")
93
	int unDeleteAnswer(Connection con,String id,String qid)throws SQLException;
81

94

82
	
95
	
83
	@SelectOne
96
	@SelectOne
141

154

142
	@UpdateWith
155
	@UpdateWith
143
	@From(Answer.class)
156
	@From(Answer.class)
144
	@IncludeFixSet
157
	@Where("STATE='1'")
158
	@SetSentence("MODIFY_TIME=TO_CHAR(NOW(),'YYYYMMDDHH24MISS')")
145
	int updateAnswer(Connection con, String id, @Set String cnt) throws SQLException;
159
	int updateAnswer(Connection con, String id, @Set String cnt) throws SQLException;
146
	
160
	
147
	@Insert
161
	@Insert

+ 24 - 7
src/main/java/com/ekexiu/portal/question/Service.java

5
import com.ekexiu.portal.util.SqlUtil;
5
import com.ekexiu.portal.util.SqlUtil;
6
import org.jfw.apt.annotation.Autowrie;
6
import org.jfw.apt.annotation.Autowrie;
7
import org.jfw.apt.annotation.DefaultValue;
7
import org.jfw.apt.annotation.DefaultValue;
8
import org.jfw.apt.annotation.Nullable;
8
import org.jfw.apt.web.annotation.Path;
9
import org.jfw.apt.web.annotation.Path;
9
import org.jfw.apt.web.annotation.operate.Get;
10
import org.jfw.apt.web.annotation.operate.Get;
10
import org.jfw.apt.web.annotation.operate.Post;
11
import org.jfw.apt.web.annotation.operate.Post;
147
		q.setPageViews(0);
148
		q.setPageViews(0);
148
		String time = DateUtil.formatDateTime(System.currentTimeMillis());
149
		String time = DateUtil.formatDateTime(System.currentTimeMillis());
149
		q.setCreateTime(time);
150
		q.setCreateTime(time);
150
		q.setTimeDesc(time+id);
151
		q.setTimeDesc(time + id);
151
		List<String> kws = ListUtil.splitTrimExcludeEmpty(q.getKeys(), ',');
152
		List<String> kws = ListUtil.splitTrimExcludeEmpty(q.getKeys(), ',');
152
		if (kws.isEmpty())
153
		if (kws.isEmpty())
153
			throw new IllegalArgumentException("param keys invalid");
154
			throw new IllegalArgumentException("param keys invalid");
155
		questionDao.insert(con, build(id, kws));
156
		questionDao.insert(con, build(id, kws));
156
		return id;
157
		return id;
157
	}
158
	}
158
	
159

159
	@Path("/pageViews")
160
	@Path("/pageViews")
160
	@Post
161
	@Post
161
	public void incQuestionPageView(@JdbcConn(true) Connection con,String qid)throws SQLException{
162
	public void incQuestionPageView(@JdbcConn(true) Connection con, String qid) throws SQLException {
162
		questionDao.incQuestionPageViews(con, qid);
163
		questionDao.incQuestionPageViews(con, qid);
163
	}
164
	}
164

165

279
		a.setState("1");
280
		a.setState("1");
280
		a.setUid(uid);
281
		a.setUid(uid);
281
		a.setCreateTime(time);
282
		a.setCreateTime(time);
282
		a.setTimeDesc(time+id);
283
		a.setTimeDesc(time + id);
284
		a.setModifyTime(time);
283
		try {
285
		try {
284
			questionDao.insert(con, a);
286
			questionDao.insert(con, a);
285
		} catch (SQLException e) {
287
		} catch (SQLException e) {
295

297

296
	@Get
298
	@Get
297
	@Path("/answer")
299
	@Path("/answer")
298
	public Answer answer(@JdbcConn Connection con, String id) throws SQLException {
299
		return questionDao.queryAnswer(con, id);
300
	public Answer answer(@JdbcConn Connection con,@Nullable String id,@Nullable String uid, @Nullable String qid) throws SQLException {
301
		if(id!=null){
302
			return questionDao.queryAnswer(con, id);
303
		}else if(qid!=null && uid !=null){
304
			return questionDao.answer(con, uid, qid);
305
		}
306
		return null;
300
	}
307
	}
301

308

302
	@Get
309
	@Get
578
	@Get
585
	@Get
579
	@Path("/answer/delete")
586
	@Path("/answer/delete")
580
	public int logicDelete(@JdbcConn(true) Connection con, String id) throws SQLException {
587
	public int logicDelete(@JdbcConn(true) Connection con, String id) throws SQLException {
581
		if(questionDao.logicDeleteAnswer(con, id)>0){
588
		if (questionDao.logicDeleteAnswer(con, id) > 0) {
582
			questionDao.deccQuestionReply(con, id);
589
			questionDao.deccQuestionReply(con, id);
583
			return 1;
590
			return 1;
584
		}
591
		}
585
		return 0;
592
		return 0;
586
	}
593
	}
587

594

595
	@Get
596
	@Path("/answer/unDel")
597
	public int unDelete(@JdbcConn(true) Connection con, String id, String qid) throws SQLException {
598
		if (questionDao.unDeleteAnswer(con, id, qid) > 0) {
599
			questionDao.onlyIncQuestionReply(con, qid);
600
			return 1;
601
		}
602
		return 0;
603
	}
604

588
	@Post
605
	@Post
589
	@Path("/answer/unAgree")
606
	@Path("/answer/unAgree")
590
	public void unAgree(@JdbcConn(true) Connection con, String id, String uid, String uname, @AfterCommit List<Runnable> runs)
607
	public void unAgree(@JdbcConn(true) Connection con, String id, String uid, String uname, @AfterCommit List<Runnable> runs)