Przeglądaj źródła

APP咨询搜索页按条件搜索咨询列表。

zzy.zhiyuan.foxmail 8 lat temu
rodzic
commit
a0d5f31a9e

+ 214 - 0
src/main/java/com/ekexiu/portal/dao/ConsultDao.java

@ -47,6 +47,14 @@ public abstract class ConsultDao {
47 47
        }
48 48
    }
49 49
	
50
	/**
51
	 * 更新完成时间和完成状态
52
	 * @param con 
53
	 * @param consultId 咨询ID
54
	 * @param consultStatus 咨询状态
55
	 * @return 
56
	 * @throws SQLException
57
	 */
50 58
	public int updateFinishTime(Connection con,String consultId,int consultStatus) throws SQLException{
51 59
        int _m_2 = 1;
52 60
        String sql ="UPDATE CONSULT SET FINISH_TIME= TO_CHAR(NOW(),'YYYYMMDDHH24MISS'),CONSULT_STATUS= ? WHERE CONSULT_ID = ?";
@ -1208,4 +1216,210 @@ public abstract class ConsultDao {
1208 1216
		}
1209 1217
	}
1210 1218
	
1219
	/**
1220
	 * 按条件搜索所有咨询的接口
1221
	 * @param con
1222
	 * @param professorId 用户ID
1223
	 * @param consultOrNeed 接受咨询或咨询别人的状态值,1-别人咨询我的,2-我咨询别人的,默认为0
1224
	 * @param status 查询状态 0-全部,1-进行中,2-未感谢,3-未评价,4-已完成,默认为0
1225
	 * @param timeType 排序类型 0-按发起时间,1-按最后回复时间,2-按完成时间,默认为0
1226
	 * @param pageSize
1227
	 * @param pageNo
1228
	 * @return 返回咨询列表
1229
	 * @throws SQLException
1230
	 */
1231
	public PageQueryResult<Consult> queryPageBase(Connection con, String professorId, int consultOrNeed, 
1232
			int status, int timeType, int pageSize, int pageNo) throws SQLException{
1233
		PageQueryResult<Consult> queryResult = new PageQueryResult<Consult>();
1234
		StringBuilder sql = new StringBuilder();
1235
		if(0 == consultOrNeed){
1236
			sql.append(" WHERE PROFESSOR_ID = ? OR CONSULTANT_ID = ?");
1237
		}else if(1 == consultOrNeed){
1238
			sql.append(" WHERE PROFESSOR_ID = ? ");
1239
		}else if(2 == consultOrNeed){
1240
			sql.append(" WHERE CONSULTANT_ID = ? ");
1241
		}
1242
		if(1 == status) {
1243
			sql.append(" AND CONSULT_STATUS = 0 ");
1244
		}else if(2 == status) {
1245
			sql.append(" AND CONSULT_STATUS = 1 AND THANKS_STATUS = 0 ");
1246
		}else if(3 == status) {
1247
			sql.append(" AND CONSULT_STATUS = 1 AND ASSESS_STATUS = 0 ");
1248
		}else if(4 == status) {
1249
			sql.append(" AND CONSULT_STATUS = 1 ");
1250
		}
1251
		StringBuilder whereSql = sql;
1252
		sql = new StringBuilder();
1253
		sql.append("SELECT COUNT(1) FROM CONSULT");
1254
		if (whereSql.length() > 0) {
1255
			sql.append(whereSql);
1256
		}
1257
		PreparedStatement ps = con.prepareStatement(sql.toString());
1258
		int paramIndex = 1;
1259
		int totalSize = 0;
1260
		try {
1261
			ps.setString(paramIndex++, professorId);
1262
			if(0 == consultOrNeed){
1263
				ps.setString(paramIndex++, professorId);
1264
			}
1265
			queryResult.setPageSize(pageSize);
1266
			ResultSet resultSet = ps.executeQuery();
1267
			try {
1268
				resultSet.next();
1269
				totalSize = resultSet.getInt(1);
1270
			} finally {
1271
				try {
1272
					resultSet.close();
1273
				} catch (Exception _m_6) {
1274
				}
1275
			}
1276
		} finally {
1277
			try {
1278
				ps.close();
1279
			} catch (Exception _m_7) {
1280
			}
1281
		}
1282
		queryResult.setTotal(totalSize);
1283
		if (0 == totalSize) {
1284
			queryResult.setPageNo(1);
1285
			queryResult.setData(Collections.<Consult> emptyList());
1286
			return queryResult;
1287
		}
1288
		paramIndex = 1;
1289
		if (1 == pageNo) {
1290
			queryResult.setPageNo(1);
1291
			sql = new StringBuilder();
1292
			sql.append(" SELECT CONSULT_ID,CONSULT_TYPE,CONSULT_TITLE,CONSULT_CONTANT,PROFESSOR_ID,CONSULTANT_ID,"
1293
					+ " CONSULT_STATUS,FINISH_TIME,ASSESS_STATUS,ASSESS_STAR,ASSESS_CONTANT,ASSESS_TIME,THANKS_STATUS,"
1294
					+ " THANKS_MONEY,THANKS_TIME,REVOVERY_TIME,READ_STATUS,CREATE_TIME FROM CONSULT ");
1295
			if (whereSql.length() > 0) {
1296
				sql.append(whereSql);
1297
			}
1298
			if(0 == timeType) {
1299
				sql.append(" ORDER BY CREATE_TIME ");
1300
			}else if(1 == timeType) {
1301
				sql.append(" ORDER BY REVOVERY_TIME DESC ");
1302
			}else if(2 == timeType) {
1303
				sql.append(" ORDER BY FINISH_TIME DESC ");
1304
			}
1305
			sql.append(" LIMIT ").append(pageSize);
1306
		} else {
1307
			int _pageSize = totalSize / pageSize;
1308
			if (totalSize % pageSize != 0) {
1309
				++_pageSize;
1310
			}
1311
			if (pageNo > _pageSize) {
1312
				pageNo = _pageSize;
1313
			}
1314
			queryResult.setPageNo(pageNo);
1315
			--pageNo;
1316
			int _m_10 = (pageNo * pageSize);
1317
			sql = new StringBuilder();
1318
			sql.append(" SELECT CONSULT_ID,CONSULT_TYPE,CONSULT_TITLE,CONSULT_CONTANT,PROFESSOR_ID,CONSULTANT_ID,"
1319
					+ " CONSULT_STATUS,FINISH_TIME,ASSESS_STATUS,ASSESS_STAR,ASSESS_CONTANT,ASSESS_TIME,THANKS_STATUS,"
1320
					+ " THANKS_MONEY,THANKS_TIME,REVOVERY_TIME,READ_STATUS,CREATE_TIME FROM CONSULT ");
1321
			if (whereSql.length() > 0) {
1322
				sql.append(whereSql);
1323
			}
1324
			if(0 == timeType) {
1325
				sql.append(" ORDER BY CREATE_TIME ");
1326
			}else if(1 == timeType) {
1327
				sql.append(" ORDER BY REVOVERY_TIME DESC ");
1328
			}else if(2 == timeType) {
1329
				sql.append(" ORDER BY FINISH_TIME DESC ");
1330
			}
1331
			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(_m_10);
1332
		}
1333
		ps = con.prepareStatement(sql.toString());
1334
		try {
1335
			ps.setString(paramIndex++, professorId);
1336
			if(0 == consultOrNeed){
1337
				ps.setString(paramIndex++, professorId);
1338
			}
1339
			ResultSet rs = ps.executeQuery();
1340
			try {
1341
				List<Consult> _m_11 = new ArrayList<Consult>();
1342
				queryResult.setData(_m_11);
1343
				while (rs.next()) {
1344
					Consult consult = new Consult();
1345
					consult.setConsultId(rs.getString(1));
1346
					consult.setConsultType(rs.getString(2));
1347
					consult.setConsultTitle(rs.getString(3));
1348
					consult.setConsultContant(rs.getString(4));
1349
					consult.setProfessorId(rs.getString(5));
1350
					consult.setConsultantId(rs.getString(6));
1351
					Integer m1 = rs.getInt(7);
1352
					if (rs.wasNull()) {
1353
						m1 = null;
1354
					}
1355
					consult.setConsultStatus(m1);
1356
					String m2 = rs.getString(8);
1357
					if (rs.wasNull()) {
1358
						m2 = null;
1359
					}
1360
					consult.setFinishTime(m2);
1361
					Integer m3 = rs.getInt(9);
1362
					if (rs.wasNull()) {
1363
						m3 = null;
1364
					}
1365
					consult.setAssessStatus(m3);
1366
					consult.setAssessStar(rs.getInt(10));
1367
					String m5 = rs.getString(11);
1368
					if (rs.wasNull()) {
1369
						m5 = null;
1370
					}
1371
					consult.setAssessContant(m5);
1372
					String m6 = rs.getString(12);
1373
					if (rs.wasNull()) {
1374
						m6 = null;
1375
					}
1376
					consult.setAssessTime(m6);
1377
					Integer m7 = rs.getInt(13);
1378
					if (rs.wasNull()) {
1379
						m7 = null;
1380
					}
1381
					consult.setThanksStatus(m7);
1382
					BigDecimal m8 = rs.getBigDecimal(14);
1383
					if (rs.wasNull()) {
1384
						m8 = null;
1385
					}
1386
					consult.setThanksMoney(m8);
1387
					String m9 = rs.getString(15);
1388
					if (rs.wasNull()) {
1389
						m9 = null;
1390
					}
1391
					consult.setThanksTime(m9);
1392
					consult.setRevoveryTime(rs.getString(16));
1393
					consult.setReadStatus(rs.getInt(17));
1394
					consult.setCreateTime(rs.getString(18));
1395
					EditProfessor professor = new EditProfessor();
1396
					if(0 == consultOrNeed){
1397
						if(professorId.equals(consult.getProfessorId())){
1398
							professor = this.professorDao.queryBaseInfo(con, consult.getConsultantId());
1399
						}else if(professorId.equals(consult.getConsultantId())){
1400
							professor = this.professorDao.queryBaseInfo(con, consult.getProfessorId());
1401
						}
1402
					}else if(1 == consultOrNeed){
1403
						professor = this.professorDao.queryBaseInfo(con, consult.getConsultantId());
1404
					}else if(2 == consultOrNeed){
1405
						professor = this.professorDao.queryBaseInfo(con, consult.getProfessorId());
1406
					}
1407
					consult.setProfessor(professor);
1408
					_m_11.add(consult);
1409
				}
1410
				return queryResult;
1411
			} finally {
1412
				try {
1413
					rs.close();
1414
				} catch (Exception _m_17) {
1415
				}
1416
			}
1417
		} finally {
1418
			try {
1419
				ps.close();
1420
			} catch (Exception _m_18) {
1421
			}
1422
		}
1423
	}
1424
	
1211 1425
}

+ 17 - 0
src/main/java/com/ekexiu/portal/service/ConsultService.java

@ -216,4 +216,21 @@ public class ConsultService {
216 216
		return this.consultDao.queryPageCon(con, consultantId, status, timeType, sortType, pageSize, pageNo);
217 217
	}
218 218
	
219
	@Get
220
	@Path("/pq")
221
	public PageQueryResult<Consult> queryPageBase(@JdbcConn Connection con, String professorId, 
222
			@DefaultValue("0") int consultOrNeed, @DefaultValue("0") int status, @DefaultValue("1") int timeType, 
223
			@DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException {
224
		PageQueryResult<Consult> queryResult = this.consultDao.queryPageBase(con, professorId, consultOrNeed, status, timeType, pageSize, pageNo);
225
		List<Consult> consults = queryResult.getData();
226
		if(consults != null){
227
			for (Consult consult : consults) {
228
				int hasHeadImage = this.imageService.hasProfessorImage(consult.getProfessorId());
229
				consult.getProfessor().setHasHeadImage(hasHeadImage);
230
			}
231
			queryResult.setData(consults);
232
		}
233
		return queryResult;
234
	}
235
	
219 236
}