jiapeng vor 7 Jahren
Ursprung
Commit
ae44a0a407

+ 5 - 0
src/main/java/com/ekexiu/portal/question/QuestionDao.java

@ -123,4 +123,9 @@ public interface QuestionDao {
123 123
	
124 124
	@SelectList
125 125
	List<QuestionInviteRec> queryInviteRec(Connection con,String qid,String uid,@In String[] pid)throws SQLException;
126
	
127
	@SelectOne
128
	@Nullable
129
	@Where("FLAG='1'")
130
	AnswerAgreeRec isAgree(Connection con,String uid,String aid)throws SQLException;
126 131
}

+ 44 - 37
src/main/java/com/ekexiu/portal/question/Service.java

@ -158,7 +158,7 @@ public class Service {
158 158
	 * @param id
159 159
	 *            提问ID
160 160
	 * @param uid
161
	 * 			  本人ID
161
	 *            本人ID
162 162
	 * @param count
163 163
	 *            limit 查询 返回最后一条的 kws ,首次不传
164 164
	 * @param pid
@ -170,14 +170,14 @@ public class Service {
170 170
	 */
171 171
	@Get
172 172
	@Path("/commendatoryPro")
173
	public List<Map<String, Object>> professor(@JdbcConn Connection con, final String id,final String uid, final @DefaultValue("Integer.MAX_VALUE") int count,
173
	public List<Map<String, Object>> professor(@JdbcConn Connection con, final String id, final String uid, final @DefaultValue("Integer.MAX_VALUE") int count,
174 174
			final @DefaultValue("\"0\"") String pid, final @DefaultValue("Integer.MAX_VALUE") int rows) throws SQLException {
175 175
		return JdbcUtil.queryMaps(con,
176 176
				"select id, kws from(select id,count(1) kws from pro_key_word where id <> ? and kw in (select kw from qet_key_word where id =?) group by id ) t where kws<= ? and id >? order by kws desc,id asc limit ?",
177 177
				new PreparedStatementConfig() {
178 178
					@Override
179 179
					public void config(PreparedStatement ps) throws SQLException {
180
					    ps.setString(1,uid);
180
						ps.setString(1, uid);
181 181
						ps.setString(2, id);
182 182
						ps.setInt(3, count);
183 183
						ps.setString(4, pid);
@ -204,32 +204,32 @@ public class Service {
204 204
	 */
205 205
	@Post
206 206
	@Path("/invite")
207
	public boolean invite(@JdbcConn(true) Connection con, String qid, String pid, String uid, String uname,@AfterCommit List<Runnable> runs) throws SQLException, JfwBaseException {
207
	public boolean invite(@JdbcConn(true) Connection con, String qid, String pid, String uid, String uname, @AfterCommit List<Runnable> runs)
208
			throws SQLException, JfwBaseException {
208 209
		Question q = questionDao.query(con, qid);
209 210
		if (q == null) {
210
			throw new JfwBaseException(50000, "question[" +qid + "] not found");
211
			throw new JfwBaseException(50000, "question[" + qid + "] not found");
211 212
		}
212 213
		QuestionInviteRec rec = new QuestionInviteRec();
213 214
		rec.setUid(uid);
214 215
		rec.setPid(pid);
215 216
		rec.setQid(qid);
216
		try{
217
			questionDao.insert(con,rec);
218
		}catch(SQLException e){
219
			if(SqlUtil.unique(e)){
217
		try {
218
			questionDao.insert(con, rec);
219
		} catch (SQLException e) {
220
			if (SqlUtil.unique(e)) {
220 221
				throw new JfwBaseException(50001, "duplicate invite");
221 222
			}
222 223
			throw e;
223 224
		}
224
		
225
		
225

226 226
		this.notifyService.notify(con, pid, uid, uname, qid, q.getTitle(), NotifyType.INVITE_ANSWER, runs);
227 227
		return true;
228 228
	}
229
	
229

230 230
	@Get
231 231
	@Path("/invite")
232
	public List<QuestionInviteRec> queryInviteRec(@JdbcConn Connection con,String uid,String qid,String[] pid)throws SQLException{
232
	public List<QuestionInviteRec> queryInviteRec(@JdbcConn Connection con, String uid, String qid, String[] pid) throws SQLException {
233 233
		return questionDao.queryInviteRec(con, qid, uid, pid);
234 234
	}
235 235

@ -278,16 +278,17 @@ public class Service {
278 278
		notifyService.notify(con, q.getUid(), uid, uname, qid, q.getTitle(), NotifyType.ANSWER_QUESTION, runs);
279 279
		return id;
280 280
	}
281

281 282
	@Get
282 283
	@Path("/answer")
283
	public Answer answer(@JdbcConn Connection con,String id)throws SQLException{
284
	public Answer answer(@JdbcConn Connection con, String id) throws SQLException {
284 285
		return questionDao.queryAnswer(con, id);
285 286
	}
286
	
287

287 288
	@Get
288 289
	@Path("/answer/exists")
289
	public boolean existsAnswer(@JdbcConn Connection con,String uid,String qid)throws SQLException{
290
		return null!=questionDao.answer(con, uid, qid);
290
	public boolean existsAnswer(@JdbcConn Connection con, String uid, String qid) throws SQLException {
291
		return null != questionDao.answer(con, uid, qid);
291 292
	}
292 293

293 294
	/**
@ -340,7 +341,7 @@ public class Service {
340 341
	@Path()
341 342
	public List<Question> query(@JdbcConn Connection con, @DefaultValue("\"99999999999999\"") String time, @DefaultValue("\"0\"") String id,
342 343
			@DefaultValue("10000000") int rows) throws SQLException {
343
		return questionDao.query(con, "1", null, time+id, rows);
344
		return questionDao.query(con, "1", null, time + id, rows);
344 345
	}
345 346

346 347
	/**
@ -362,7 +363,7 @@ public class Service {
362 363
	@Path("/my")
363 364
	public List<Question> querySelf(@JdbcConn Connection con, String uid, @DefaultValue("\"99999999999999\"") String time, @DefaultValue("\"0\"") String id,
364 365
			@DefaultValue("10000000") int rows) throws SQLException {
365
		return questionDao.query(con, "1", uid, time+id, rows);
366
		return questionDao.query(con, "1", uid, time + id, rows);
366 367
	}
367 368

368 369
	/**
@ -384,7 +385,7 @@ public class Service {
384 385
	@Path("/watch")
385 386
	public List<Question> watch(@JdbcConn Connection con, String uid, @DefaultValue("\"99999999999999\"") String time, @DefaultValue("\"0\"") String id,
386 387
			@DefaultValue("10000000") int rows) throws SQLException {
387
		return questionDao.watch(con, uid, time+ id, rows);
388
		return questionDao.watch(con, uid, time + id, rows);
388 389
	}
389 390

390 391
	/**
@ -406,7 +407,7 @@ public class Service {
406 407
	@Path("/answer/bySelf")
407 408
	public List<Answer> answerSelf(@JdbcConn Connection con, String uid, @DefaultValue("\"99999999999999\"") String time, @DefaultValue("\"0\"") String id,
408 409
			@DefaultValue("10000000") int rows) throws SQLException {
409
		return questionDao.answerSelf(con, uid, time+id, rows);
410
		return questionDao.answerSelf(con, uid, time + id, rows);
410 411
	}
411 412

412 413
	/**
@ -428,13 +429,12 @@ public class Service {
428 429
	@Path("/answer/byWatch")
429 430
	public List<Answer> answerWatch(@JdbcConn Connection con, String uid, @DefaultValue("\"99999999999999\"") String time, @DefaultValue("\"0\"") String id,
430 431
			@DefaultValue("10000000") int rows) throws SQLException {
431
		return questionDao.watchAnswer(con, uid, time+id, rows);
432
		return questionDao.watchAnswer(con, uid, time + id, rows);
432 433
	}
433
	
434

434 435
	/**
435
	 * 查询所有合法的回答(“发布中”的问题下的“发布中”的回答。);
436
	 * 按最新回答时间,由新到旧排序
437
	})
436
	 * 查询所有合法的回答(“发布中”的问题下的“发布中”的回答。); 按最新回答时间,由新到旧排序 })
437
	 * 
438 438
	 * @param con
439 439
	 * @param time
440 440
	 * @param id
@ -444,10 +444,11 @@ public class Service {
444 444
	 */
445 445
	@Get
446 446
	@Path("/answer/byTime")
447
	public List<Answer> answerByTime(@JdbcConn Connection con,@DefaultValue("\"99999999999999\"") String time, @DefaultValue("\"0\"") String id,
447
	public List<Answer> answerByTime(@JdbcConn Connection con, @DefaultValue("\"99999999999999\"") String time, @DefaultValue("\"0\"") String id,
448 448
			@DefaultValue("10000000") int rows) throws SQLException {
449
		return questionDao.answer(con,  time+ id, rows);
449
		return questionDao.answer(con, time + id, rows);
450 450
	}
451

451 452
	/**
452 453
	 * 指定提问的回答(按最新回答时间,由新到旧排序)
453 454
	 * 
@ -467,7 +468,7 @@ public class Service {
467 468
	@Path("/answer/qes/byTime")
468 469
	public List<Answer> byQes(@JdbcConn Connection con, String qid, @DefaultValue("\"99999999999999\"") String time, @DefaultValue("\"0\"") String id,
469 470
			@DefaultValue("10000000") int rows) throws SQLException {
470
		return questionDao.byQes(con, qid, time+id, rows);
471
		return questionDao.byQes(con, qid, time + id, rows);
471 472
	}
472 473

473 474
	/**
@ -489,12 +490,10 @@ public class Service {
489 490
	@Path("/answer/qes/byScore")
490 491
	public List<SortedAnswwer> byQes(@JdbcConn Connection con, String qid, @DefaultValue("99999") int score, @DefaultValue("\"Z\"") String id,
491 492
			@DefaultValue("10000000") int rows) throws SQLException {
492
		String p = "000000"+score;
493
		p = p.substring(p.length()-5)+id;
493
		String p = "000000" + score;
494
		p = p.substring(p.length() - 5) + id;
494 495
		return questionDao.byQesScore(con, qid, p, rows);
495 496
	}
496
	
497
	
498 497

499 498
	/**
500 499
	 * 我的回答总点赞数
@ -540,8 +539,9 @@ public class Service {
540 539
		} catch (SQLException e) {
541 540
			if (SqlUtil.unique(e)) {
542 541
				con.rollback();
542
			} else {
543
				throw e;
543 544
			}
544
			throw e;
545 545
		}
546 546
		if (inserted) {
547 547
			questionDao.update(con, id, 1, 1);
@ -555,12 +555,18 @@ public class Service {
555 555
		notifyService.notify(con, a.getUid(), uid, uname, a.getId(), q.getTitle(), NotifyType.ACCEPT_ANSWER, runs);
556 556
	}
557 557

558
	@Get
559
	@Path("/answer/agree")
560
	public boolean isAgree(@JdbcConn Connection con, String aid, String uid) throws SQLException {
561
		return null != questionDao.isAgree(con, uid, aid);
562
	}
563

558 564
	@Get
559 565
	@Path("/answer/delete")
560
	public int logicDelete(@JdbcConn(true) Connection con,String id)throws SQLException{
566
	public int logicDelete(@JdbcConn(true) Connection con, String id) throws SQLException {
561 567
		return questionDao.logicDeleteAnswer(con, id);
562 568
	}
563
	
569

564 570
	@Post
565 571
	@Path("/answer/unAgree")
566 572
	public void unAgree(@JdbcConn(true) Connection con, String id, String uid, String uname, @AfterCommit List<Runnable> runs)
@ -576,8 +582,9 @@ public class Service {
576 582
		} catch (SQLException e) {
577 583
			if (SqlUtil.unique(e)) {
578 584
				con.rollback();
585
			} else {
586
				throw e;
579 587
			}
580
			throw e;
581 588
		}
582 589
		if (inserted) {
583 590
			questionDao.update(con, id, 0, 1);