Browse Source

咨询页面收到咨询和收到答复的接口

zzy.zhiyuan.foxmail 8 years ago
parent
commit
4cab907792

+ 394 - 9
src/main/java/com/ekexiu/portal/dao/ConsultDao.java

@ -1,22 +1,26 @@
1 1
package com.ekexiu.portal.dao;
2 2

3
import java.math.BigDecimal;
3 4
import java.sql.Connection;
4 5
import java.sql.PreparedStatement;
6
import java.sql.ResultSet;
5 7
import java.sql.SQLException;
8
import java.util.ArrayList;
9
import java.util.Collections;
6 10
import java.util.List;
7 11

8 12
import org.jfw.apt.annotation.Nullable;
9 13
import org.jfw.apt.orm.annotation.dao.DAO;
10 14
import org.jfw.apt.orm.annotation.dao.method.From;
11
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
12 15
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
13
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
14 16
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
15 17
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
16 18
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
17 19
import org.jfw.apt.orm.annotation.dao.param.Set;
20
import org.jfw.util.PageQueryResult;
18 21

19 22
import com.ekexiu.portal.po.Consult;
23
import com.ekexiu.portal.pojo.EditProfessor;
20 24

21 25
@DAO
22 26
public abstract class ConsultDao {
@ -46,13 +50,394 @@ public abstract class ConsultDao {
46 50
	@Nullable
47 51
	public abstract Consult query(Connection con, String consultId) throws SQLException;
48 52
	
49
	@SelectList
50
	@OrderBy(" ORDER BY CONSULT.CREATE_TIME DESC ")
51
	public abstract List<Consult> queryPro(Connection con, String professorId) throws SQLException;
52
	
53
	@SelectList
54
	@OrderBy(" ORDER BY CONSULT.CREATE_TIME DESC ")
55
	public abstract List<Consult> queryCon(Connection con, String consultantId) throws SQLException;
53
	public PageQueryResult<Consult> queryPagePro(Connection con, String professorId, int consultStatus, int timeType, int sortType, int pageSize, int pageNo) throws SQLException{
54
		PageQueryResult<Consult> queryResult = new PageQueryResult<Consult>();
55
		StringBuilder sql = new StringBuilder();
56
		sql.append(" WHERE CONSULT.PROFESSOR_ID = ? ");
57
		if(0 != consultStatus) {
58
			sql.append(" AND CONSULT_STATUS = ? ");
59
		}
60
		StringBuilder whereSql = sql;
61
		sql = new StringBuilder();
62
		sql.append("SELECT COUNT(1) FROM CONSULT");
63
		if (whereSql.length() > 0) {
64
			sql.append(whereSql);
65
		}
66
		PreparedStatement ps = con.prepareStatement(sql.toString());
67
		int paramIndex = 1;
68
		int totalSize = 0;
69
		try {
70
			ps.setString(paramIndex++, professorId);
71
			if(0 != consultStatus){
72
				ps.setInt(paramIndex++, consultStatus);
73
			}
74
			queryResult.setPageSize(pageSize);
75
			ResultSet resultSet = ps.executeQuery();
76
			try {
77
				resultSet.next();
78
				totalSize = resultSet.getInt(1);
79
			} finally {
80
				try {
81
					resultSet.close();
82
				} catch (Exception _m_6) {
83
				}
84
			}
85
		} finally {
86
			try {
87
				ps.close();
88
			} catch (Exception _m_7) {
89
			}
90
		}
91
		queryResult.setTotal(totalSize);
92
		if (0 == totalSize) {
93
			queryResult.setPageNo(1);
94
			queryResult.setData(Collections.<Consult> emptyList());
95
			return queryResult;
96
		}
97
		paramIndex = 1;
98
		if (1 == pageNo) {
99
			queryResult.setPageNo(1);
100
			sql = new StringBuilder();
101
			sql.append(" SELECT CONSULT_ID,CONSULT_TYPE,CONSULT_TITLE,CONSULT_CONTANT,CONSULT.PROFESSOR_ID,CONSULTANT_ID,CONSULT_STATUS,FINISH_TIME,ASSESS_STATUS,ASSESS_STAR,ASSESS_CONTANT,ASSESS_TIME,THANKS_STATUS,THANKS_MONEY,THANKS_TIME,REVOVERY_TIME,CONSULT.CREATE_TIME,PROFESSOR.NAME,PROFESSOR.DEPARTMENT,PROFESSOR.TITLE,PROFESSOR.ADDRESS,ORGANIZATION.NAME FROM CONSULT LEFT JOIN PROFESSOR ON CONSULT.CONSULTANT_ID = PROFESSOR.ID LEFT JOIN ORGANIZATION ON PROFESSOR.ORG_ID = ORGANIZATION.ID ");
102
			if (whereSql.length() > 0) {
103
				sql.append(whereSql);
104
			}
105
			if(0 == timeType) {
106
				sql.append(" ORDER BY CONSULT.CREATE_TIME ");
107
				if(0 == sortType) {
108
					sql.append(" DESC ");
109
				}
110
			}else if(1 == timeType) {
111
				sql.append(" ORDER BY REVOVERY_TIME ");
112
				if(0 == sortType) {
113
					sql.append(" DESC ");
114
				}
115
			}else if(2 == timeType) {
116
				sql.append(" ORDER BY FINISH_TIME ");
117
				if(0 == sortType) {
118
					sql.append(" DESC ");
119
				}
120
			}
121
			sql.append(" LIMIT ").append(pageSize);
122
		} else {
123
			int _pageSize = totalSize / pageSize;
124
			if (totalSize % pageSize != 0) {
125
				++_pageSize;
126
			}
127
			if (pageNo > _pageSize) {
128
				pageNo = _pageSize;
129
			}
130
			queryResult.setPageNo(pageNo);
131
			--pageNo;
132
			int _m_10 = (pageNo * pageSize);
133
			sql = new StringBuilder();
134
			sql.append(" SELECT CONSULT_ID,CONSULT_TYPE,CONSULT_TITLE,CONSULT_CONTANT,CONSULT.PROFESSOR_ID,CONSULTANT_ID,CONSULT_STATUS,FINISH_TIME,ASSESS_STATUS,ASSESS_STAR,ASSESS_CONTANT,ASSESS_TIME,THANKS_STATUS,THANKS_MONEY,THANKS_TIME,REVOVERY_TIME,CONSULT.CREATE_TIME,PROFESSOR.NAME,PROFESSOR.DEPARTMENT,PROFESSOR.TITLE,PROFESSOR.ADDRESS,ORGANIZATION.NAME FROM CONSULT LEFT JOIN PROFESSOR ON CONSULT.CONSULTANT_ID = PROFESSOR.ID LEFT JOIN ORGANIZATION ON PROFESSOR.ORG_ID = ORGANIZATION.ID ");
135
			if (whereSql.length() > 0) {
136
				sql.append(whereSql);
137
			}
138
			if(0 == timeType) {
139
				sql.append(" ORDER BY CONSULT.CREATE_TIME ");
140
				if(0 == sortType) {
141
					sql.append(" DESC ");
142
				}
143
			}else if(1 == timeType) {
144
				sql.append(" ORDER BY REVOVERY_TIME ");
145
				if(0 == sortType) {
146
					sql.append(" DESC ");
147
				}
148
			}else if(2 == timeType) {
149
				sql.append(" ORDER BY FINISH_TIME ");
150
				if(0 == sortType) {
151
					sql.append(" DESC ");
152
				}
153
			}
154
			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(_m_10);
155
		}
156
		ps = con.prepareStatement(sql.toString());
157
		try {
158
			ps.setString(paramIndex++, professorId);
159
			if(0 != consultStatus){
160
				ps.setInt(paramIndex++, consultStatus);
161
			}
162
			ResultSet rs = ps.executeQuery();
163
			try {
164
				List<Consult> _m_11 = new ArrayList<Consult>();
165
				queryResult.setData(_m_11);
166
				while (rs.next()) {
167
					Consult consult = new Consult();
168
					consult.setConsultId(rs.getString(1));
169
					consult.setConsultType(rs.getString(2));
170
					consult.setConsultTitle(rs.getString(3));
171
					consult.setConsultContant(rs.getString(4));
172
					consult.setProfessorId(rs.getString(5));
173
					EditProfessor professor = new EditProfessor();
174
					professor.setId(rs.getString(6));
175
					Integer m1 = rs.getInt(7);
176
					if (rs.wasNull()) {
177
						m1 = null;
178
					}
179
					consult.setConsultStatus(m1);
180
					String m2 = rs.getString(8);
181
					if (rs.wasNull()) {
182
						m2 = null;
183
					}
184
					consult.setFinishTime(m2);
185
					Integer m3 = rs.getInt(9);
186
					if (rs.wasNull()) {
187
						m3 = null;
188
					}
189
					consult.setAssessStatus(m3);
190
//					Integer m4 = rs.getInt(10);
191
//					if (rs.wasNull()) {
192
//						System.out.println("1");
193
//						m4 = null;
194
//					}
195
//					consult.setAssessStar(m4);
196
					consult.setAssessStar(rs.getInt(10));
197
					String m5 = rs.getString(11);
198
					if (rs.wasNull()) {
199
						m5 = null;
200
					}
201
					consult.setAssessContant(m5);
202
					String m6 = rs.getString(12);
203
					if (rs.wasNull()) {
204
						m6 = null;
205
					}
206
					consult.setAssessTime(m6);
207
					Integer m7 = rs.getInt(13);
208
					if (rs.wasNull()) {
209
						m7 = null;
210
					}
211
					consult.setThanksStatus(m7);
212
					BigDecimal m8 = rs.getBigDecimal(14);
213
					if (rs.wasNull()) {
214
						m8 = null;
215
					}
216
					consult.setThanksMoney(m8);
217
					String m9 = rs.getString(15);
218
					if (rs.wasNull()) {
219
						m9 = null;
220
					}
221
					consult.setThanksTime(m9);
222
					consult.setRevoveryTime(rs.getString(16));
223
					consult.setCreateTime(rs.getString(17));
224
					professor.setName(rs.getString(18));
225
					professor.setDepartment(rs.getString(19));
226
					professor.setTitle(rs.getString(20));
227
					String m10 = rs.getString(21);
228
					if (rs.wasNull()) {
229
						m10 = null;
230
					}
231
					professor.setAddress(m10);
232
					professor.setOrgName(rs.getString(22));
233
					consult.setProfessor(professor);
234
					_m_11.add(consult);
235
				}
236
				return queryResult;
237
			} finally {
238
				try {
239
					rs.close();
240
				} catch (Exception _m_17) {
241
				}
242
			}
243
		} finally {
244
			try {
245
				ps.close();
246
			} catch (Exception _m_18) {
247
			}
248
		}
249
	}
56 250
	
251
	public PageQueryResult<Consult> queryPageCon(Connection con, String consultantId, int consultStatus, int timeType, int sortType, int pageSize, int pageNo) throws SQLException{
252
		PageQueryResult<Consult> queryResult = new PageQueryResult<Consult>();
253
		StringBuilder sql = new StringBuilder();
254
		sql.append(" WHERE CONSULT.CONSULTANT_ID = ? ");
255
		if(0 != consultStatus) {
256
			sql.append(" AND CONSULT_STATUS = ? ");
257
		}
258
		StringBuilder whereSql = sql;
259
		sql = new StringBuilder();
260
		sql.append("SELECT COUNT(1) FROM CONSULT");
261
		if (whereSql.length() > 0) {
262
			sql.append(whereSql);
263
		}
264
		PreparedStatement ps = con.prepareStatement(sql.toString());
265
		int paramIndex = 1;
266
		int totalSize = 0;
267
		try {
268
			ps.setString(paramIndex++, consultantId);
269
			if(0 != consultStatus){
270
				ps.setInt(paramIndex++, consultStatus);
271
			}
272
			queryResult.setPageSize(pageSize);
273
			ResultSet resultSet = ps.executeQuery();
274
			try {
275
				resultSet.next();
276
				totalSize = resultSet.getInt(1);
277
			} finally {
278
				try {
279
					resultSet.close();
280
				} catch (Exception _m_6) {
281
				}
282
			}
283
		} finally {
284
			try {
285
				ps.close();
286
			} catch (Exception _m_7) {
287
			}
288
		}
289
		queryResult.setTotal(totalSize);
290
		if (0 == totalSize) {
291
			queryResult.setPageNo(1);
292
			queryResult.setData(Collections.<Consult> emptyList());
293
			return queryResult;
294
		}
295
		paramIndex = 1;
296
		if (1 == pageNo) {
297
			queryResult.setPageNo(1);
298
			sql = new StringBuilder();
299
			sql.append(" SELECT CONSULT_ID,CONSULT_TYPE,CONSULT_TITLE,CONSULT_CONTANT,CONSULT.PROFESSOR_ID,CONSULTANT_ID,CONSULT_STATUS,FINISH_TIME,ASSESS_STATUS,ASSESS_STAR,ASSESS_CONTANT,ASSESS_TIME,THANKS_STATUS,THANKS_MONEY,THANKS_TIME,REVOVERY_TIME,CONSULT.CREATE_TIME,PROFESSOR.NAME,PROFESSOR.DEPARTMENT,PROFESSOR.TITLE,PROFESSOR.ADDRESS,ORGANIZATION.NAME FROM CONSULT LEFT JOIN PROFESSOR ON CONSULT.PROFESSOR_ID = PROFESSOR.ID LEFT JOIN ORGANIZATION ON PROFESSOR.ORG_ID = ORGANIZATION.ID ");
300
			if (whereSql.length() > 0) {
301
				sql.append(whereSql);
302
			}
303
			if(0 == timeType) {
304
				sql.append(" ORDER BY CONSULT.CREATE_TIME ");
305
				if(0 == sortType) {
306
					sql.append(" DESC ");
307
				}
308
			}else if(1 == timeType) {
309
				sql.append(" ORDER BY REVOVERY_TIME ");
310
				if(0 == sortType) {
311
					sql.append(" DESC ");
312
				}
313
			}else if(2 == timeType) {
314
				sql.append(" ORDER BY FINISH_TIME ");
315
				if(0 == sortType) {
316
					sql.append(" DESC ");
317
				}
318
			}
319
			sql.append(" LIMIT ").append(pageSize);
320
		} else {
321
			int _pageSize = totalSize / pageSize;
322
			if (totalSize % pageSize != 0) {
323
				++_pageSize;
324
			}
325
			if (pageNo > _pageSize) {
326
				pageNo = _pageSize;
327
			}
328
			queryResult.setPageNo(pageNo);
329
			--pageNo;
330
			int _m_10 = (pageNo * pageSize);
331
			sql = new StringBuilder();
332
			sql.append(" SELECT CONSULT_ID,CONSULT_TYPE,CONSULT_TITLE,CONSULT_CONTANT,CONSULT.PROFESSOR_ID,CONSULTANT_ID,CONSULT_STATUS,FINISH_TIME,ASSESS_STATUS,ASSESS_STAR,ASSESS_CONTANT,ASSESS_TIME,THANKS_STATUS,THANKS_MONEY,THANKS_TIME,REVOVERY_TIME,CONSULT.CREATE_TIME,PROFESSOR.NAME,PROFESSOR.DEPARTMENT,PROFESSOR.TITLE,PROFESSOR.ADDRESS,ORGANIZATION.NAME FROM CONSULT LEFT JOIN PROFESSOR ON CONSULT.PROFESSOR_ID = PROFESSOR.ID LEFT JOIN ORGANIZATION ON PROFESSOR.ORG_ID = ORGANIZATION.ID ");
333
			if (whereSql.length() > 0) {
334
				sql.append(whereSql);
335
			}
336
			if(0 == timeType) {
337
				sql.append(" ORDER BY CONSULT.CREATE_TIME ");
338
				if(0 == sortType) {
339
					sql.append(" DESC ");
340
				}
341
			}else if(1 == timeType) {
342
				sql.append(" ORDER BY REVOVERY_TIME ");
343
				if(0 == sortType) {
344
					sql.append(" DESC ");
345
				}
346
			}else if(2 == timeType) {
347
				sql.append(" ORDER BY FINISH_TIME ");
348
				if(0 == sortType) {
349
					sql.append(" DESC ");
350
				}
351
			}
352
			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(_m_10);
353
		}
354
		ps = con.prepareStatement(sql.toString());
355
		try {
356
			ps.setString(paramIndex++, consultantId);
357
			if(0 != consultStatus){
358
				ps.setInt(paramIndex++, consultStatus);
359
			}
360
			ResultSet rs = ps.executeQuery();
361
			try {
362
				List<Consult> _m_11 = new ArrayList<Consult>();
363
				queryResult.setData(_m_11);
364
				while (rs.next()) {
365
					Consult consult = new Consult();
366
					consult.setConsultId(rs.getString(1));
367
					consult.setConsultType(rs.getString(2));
368
					consult.setConsultTitle(rs.getString(3));
369
					consult.setConsultContant(rs.getString(4));
370
					EditProfessor professor = new EditProfessor();
371
					professor.setId(rs.getString(5));
372
					consult.setConsultantId(rs.getString(6));
373
					Integer m1 = rs.getInt(7);
374
					if (rs.wasNull()) {
375
						m1 = null;
376
					}
377
					consult.setConsultStatus(m1);
378
					String m2 = rs.getString(8);
379
					if (rs.wasNull()) {
380
						m2 = null;
381
					}
382
					consult.setFinishTime(m2);
383
					Integer m3 = rs.getInt(9);
384
					if (rs.wasNull()) {
385
						m3 = null;
386
					}
387
					consult.setAssessStatus(m3);
388
					consult.setAssessStar(rs.getInt(10));
389
					String m5 = rs.getString(11);
390
					if (rs.wasNull()) {
391
						m5 = null;
392
					}
393
					consult.setAssessContant(m5);
394
					String m6 = rs.getString(12);
395
					if (rs.wasNull()) {
396
						m6 = null;
397
					}
398
					consult.setAssessTime(m6);
399
					Integer m7 = rs.getInt(13);
400
					if (rs.wasNull()) {
401
						m7 = null;
402
					}
403
					consult.setThanksStatus(m7);
404
					BigDecimal m8 = rs.getBigDecimal(14);
405
					if (rs.wasNull()) {
406
						m8 = null;
407
					}
408
					consult.setThanksMoney(m8);
409
					String m9 = rs.getString(15);
410
					if (rs.wasNull()) {
411
						m9 = null;
412
					}
413
					consult.setThanksTime(m9);
414
					consult.setRevoveryTime(rs.getString(16));
415
					consult.setCreateTime(rs.getString(17));
416
					professor.setName(rs.getString(18));
417
					professor.setDepartment(rs.getString(19));
418
					professor.setTitle(rs.getString(20));
419
					String m10 = rs.getString(21);
420
					if (rs.wasNull()) {
421
						m10 = null;
422
					}
423
					professor.setAddress(m10);
424
					professor.setOrgName(rs.getString(22));
425
					consult.setProfessor(professor);
426
					_m_11.add(consult);
427
				}
428
				return queryResult;
429
			} finally {
430
				try {
431
					rs.close();
432
				} catch (Exception _m_17) {
433
				}
434
			}
435
		} finally {
436
			try {
437
				ps.close();
438
			} catch (Exception _m_18) {
439
			}
440
		}
441
	}
57 442
	
58 443
}

+ 14 - 8
src/main/java/com/ekexiu/portal/service/ConsultService.java

@ -2,15 +2,16 @@ package com.ekexiu.portal.service;
2 2

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

7 6
import org.jfw.apt.annotation.Autowrie;
7
import org.jfw.apt.annotation.DefaultValue;
8 8
import org.jfw.apt.web.annotation.Path;
9 9
import org.jfw.apt.web.annotation.operate.Get;
10 10
import org.jfw.apt.web.annotation.operate.Post;
11 11
import org.jfw.apt.web.annotation.operate.Put;
12 12
import org.jfw.apt.web.annotation.param.JdbcConn;
13 13
import org.jfw.apt.web.annotation.param.PathVar;
14
import org.jfw.util.PageQueryResult;
14 15
import org.jfw.util.StringUtil;
15 16

16 17
import com.ekexiu.portal.dao.ConsultDao;
@ -58,14 +59,19 @@ public class ConsultService {
58 59
	}
59 60
	
60 61
	@Get
61
	@Path("/qapro")
62
	public List<Consult> queryPro(@JdbcConn Connection con, String professorId) throws SQLException {
63
		return this.consultDao.queryPro(con, professorId);
64
	}
62
	@Path("/pqpro")
63
	public PageQueryResult<Consult> queryPagePro(@JdbcConn Connection con, String professorId, 
64
			@DefaultValue("0") int consultStatus, @DefaultValue("0") int timeType, @DefaultValue("0") int sortType, 
65
			@DefaultValue("5") int pageSize, @DefaultValue("1") int pageNo) throws SQLException {
66
		return this.consultDao.queryPagePro(con, professorId, consultStatus, timeType, sortType, pageSize, pageNo);
67
	}	
65 68
	
66 69
	@Get
67
	@Path("/qacon")
68
	public List<Consult> queryCon(@JdbcConn Connection con, String consultantId) throws SQLException {
69
		return this.consultDao.queryCon(con, consultantId);
70
	@Path("/pqcon")
71
	public PageQueryResult<Consult> queryPageCon(@JdbcConn Connection con, String consultantId, 
72
			@DefaultValue("0") int consultStatus, @DefaultValue("0") int timeType, @DefaultValue("0") int sortType, 
73
			@DefaultValue("5") int pageSize, @DefaultValue("1") int pageNo) throws SQLException {
74
		return this.consultDao.queryPageCon(con, consultantId, consultStatus, timeType, sortType, pageSize, pageNo);
70 75
	}
76
	
71 77
}