Browse Source

APP专家搜索接口

zzy.zhiyuan.foxmail 8 years ago
parent
commit
a96b1fe2d7

+ 323 - 1
src/main/java/com/ekexiu/portal/dao/ProfessorDao.java

@ -63,6 +63,14 @@ public abstract class ProfessorDao {
63 63
	@From(Professor.class)
64 64
	public abstract int updateAddress(Connection con, String id, @Set String address) throws SQLException;
65 65
	
66
	@UpdateWith
67
	@From(Professor.class)
68
	public abstract int updateProvince(Connection con, String id, @Set String province) throws SQLException;
69
	
70
	@UpdateWith
71
	@From(Professor.class)
72
	public abstract int updateStarAvg(Connection con, String id, @Set BigDecimal starAvg) throws SQLException;
73
	
66 74
	/**
67 75
	 * 查询专家基本信息接口
68 76
	 * @param con
@ -216,7 +224,10 @@ public abstract class ProfessorDao {
216 224
//	public abstract List<Professor> query(Connection con) throws SQLException;
217 225
	
218 226
	public List<Professor> query(Connection con) throws SQLException{
219
        String sql = "SELECT OFFICE,SUBJECT,INDUSTRY,ADDRESS,DEPARTMENT,ORG_ID,organization.NAME AS ONAME,TITLE,AUTHENTICATION,professor.ID,professor.NAME AS PNAME,professor.DESCP,professor.CREATE_TIME,professor.MODIFY_TIME FROM PROFESSOR LEFT JOIN ORGANIZATION ON professor.ORG_ID=organization.ID ORDER BY ONAME";
227
        String sql = "SELECT OFFICE,SUBJECT,INDUSTRY,ADDRESS,DEPARTMENT,ORG_ID,organization.NAME AS ONAME,"
228
        		+ " TITLE,AUTHENTICATION,professor.ID,professor.NAME AS PNAME,professor.DESCP,"
229
        		+ " professor.CREATE_TIME,professor.MODIFY_TIME FROM PROFESSOR "
230
        		+ " LEFT JOIN ORGANIZATION ON professor.ORG_ID=organization.ID ORDER BY ONAME";
220 231
        PreparedStatement ps = con.prepareStatement(sql);
221 232
        try{
222 233
            ResultSet rs = ps.executeQuery();
@ -267,6 +278,123 @@ public abstract class ProfessorDao {
267 278
        }
268 279
    }
269 280
	
281
	/**
282
	 * 查询所有专家的咨询星级和咨询完成次数
283
	 * @param con
284
	 * @return
285
	 * @throws SQLException
286
	 */
287
	public List<Professor> queryStar(Connection con) throws SQLException{
288
		String sql = "SELECT ID,STAR_LEVEL,CONSULT_COUNT FROM PROFESSOR ";
289
        PreparedStatement ps = con.prepareStatement(sql);
290
        try{
291
            ResultSet rs = ps.executeQuery();
292
            try{
293
                List<Professor> _result = new ArrayList<Professor>();
294
                while(rs.next()){
295
                    Professor professor =  new Professor();
296
                    professor.setId(rs.getString(1));
297
                    professor.setStarLevel(rs.getBigDecimal(2));
298
                    professor.setConsultCount(rs.getInt(3));
299
                    _result.add(professor);
300
                }
301
                return _result;
302
            }finally{
303
                try{rs.close();}catch(Exception _m_5){}
304
            }
305
        }finally{
306
            try{ps.close();}catch(Exception _m_6){}
307
        }
308
	}
309

310
	/**
311
	 * 查询所有专家咨询星级的最大值
312
	 * @param con
313
	 * @return
314
	 * @throws SQLException
315
	 */
316
	public BigDecimal queryBigStar(Connection con) throws SQLException{
317
		String sql = "SELECT MAX(STAR_LEVEL) FROM PROFESSOR ";
318
        PreparedStatement ps = con.prepareStatement(sql);
319
        try{
320
            ResultSet rs = ps.executeQuery();
321
            rs.next();
322
            try{
323
            	return rs.getBigDecimal(1);
324
            }finally{
325
                try{rs.close();}catch(Exception e1){}
326
            }
327
        }finally{
328
            try{ps.close();}catch(Exception e2){}
329
        }
330
	}
331
	
332
	/**
333
	 * 查询所有专家咨询星级的最小值
334
	 * @param con
335
	 * @return
336
	 * @throws SQLException
337
	 */
338
	public BigDecimal querySmallStar(Connection con) throws SQLException{
339
		String sql = "SELECT MIN(STAR_LEVEL) FROM PROFESSOR ";
340
        PreparedStatement ps = con.prepareStatement(sql);
341
        try{
342
            ResultSet rs = ps.executeQuery();
343
            rs.next();
344
            try{
345
            	return rs.getBigDecimal(1);
346
            }finally{
347
                try{rs.close();}catch(Exception e1){}
348
            }
349
        }finally{
350
            try{ps.close();}catch(Exception e2){}
351
        }
352
	}
353
	
354
	/**
355
	 * 查询所有专家咨询次数的最大值
356
	 * @param con
357
	 * @return
358
	 * @throws SQLException
359
	 */
360
	public BigDecimal queryBigConsult(Connection con) throws SQLException{
361
		String sql = "SELECT MAX(CONSULT_COUNT) FROM PROFESSOR ";
362
        PreparedStatement ps = con.prepareStatement(sql);
363
        try{
364
            ResultSet rs = ps.executeQuery();
365
            rs.next();
366
            try{
367
            	return new BigDecimal(rs.getInt(1));
368
            }finally{
369
                try{rs.close();}catch(Exception e1){}
370
            }
371
        }finally{
372
            try{ps.close();}catch(Exception e2){}
373
        }
374
	}
375
	
376
	/**
377
	 * 查询所有专家咨询次数的最小值
378
	 * @param con
379
	 * @return
380
	 * @throws SQLException
381
	 */
382
	public BigDecimal querySmallConsult(Connection con) throws SQLException{
383
		String sql = "SELECT MIN(CONSULT_COUNT) FROM PROFESSOR ";
384
        PreparedStatement ps = con.prepareStatement(sql);
385
        try{
386
            ResultSet rs = ps.executeQuery();
387
            rs.next();
388
            try{
389
            	return new BigDecimal(rs.getInt(1));
390
            }finally{
391
                try{rs.close();}catch(Exception e1){}
392
            }
393
        }finally{
394
            try{ps.close();}catch(Exception e2){}
395
        }
396
	}
397
	
270 398
	@Nullable
271 399
	@QueryOne
272 400
	@From(Professor.class)
@ -285,6 +413,200 @@ public abstract class ProfessorDao {
285 413
					"" + "ORG_ID IN(SELECT ID FROM ORGANIZATION WHERE NAME LIKE ?)", "NAME LIKE ?" }, handlerClass = StringHandler.class) String key,
286 414
			int pageSize, int pageNo) throws SQLException;
287 415

416
	/**
417
	 * APP专家搜索列表分页多条件查询
418
	 * @param con
419
	 * @param key
420
	 * @param subject 学术领域
421
	 * @param industry 应用行业
422
	 * @param province 所在省份
423
	 * @param address 所在城市
424
	 * @param authentication 是否认证
425
	 * @param pageSize 
426
	 * @param pageNo
427
	 * @return 按搜索条件返回专家列表
428
	 * @throws SQLException
429
	 */
430
	public PageQueryResult<EditProfessor> queryAPP(Connection con, @Nullable String key, String subject, String industry, 
431
			String province, String address, @Nullable Integer authentication, int pageSize, int pageNo) throws SQLException {
432
		PageQueryResult<EditProfessor> _result = new PageQueryResult<EditProfessor>();
433
		StringBuilder sql = new StringBuilder();
434
		boolean hasKey = null != key;
435
		if (hasKey) {
436
			sql.append(" WHERE (( PROFESSOR.ID IN (SELECT PROFESSOR_ID FROM RESEARCH_AREA WHERE CAPTION LIKE ?)) "
437
					+ " OR (ORG_ID IN(SELECT ORGANIZATION.ID FROM ORGANIZATION WHERE ORGANIZATION.NAME LIKE ?)) "
438
					+ " OR ( PROFESSOR.NAME LIKE ?) OR (SUBJECT LIKE ?) OR (INDUSTRY LIKE ?) OR (PROVINCE LIKE ?) OR (ADDRESS LIKE ?) "
439
					+ " OR PROFESSOR.ID IN (SELECT PROFESSOR_ID FROM RESOURCE WHERE RESOURCE_NAME LIKE ?))");
440
		}
441
		boolean hasSubject = null != subject;
442
		boolean hasIndustry = null != industry;
443
		boolean hasProvince = null != province;
444
		boolean hasAddress = null != address;
445
		boolean hasAuth = null != authentication;
446
		if (hasSubject) {
447
			sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(SUBJECT LIKE ?)");
448
		}
449
		if (hasIndustry) {
450
			sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(INDUSTRY LIKE ?)");
451
		}
452
		if (hasProvince) {
453
			sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(PROVINCE LIKE ?)");
454
		}
455
		if (hasAddress) {
456
			sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(ADDRESS LIKE ?)");
457
		}
458
		if (hasAuth) {
459
			if(0 == authentication){
460
				sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(AUTHENTICATION = '0')");
461
			}else if(1 == authentication){
462
				sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(AUTHENTICATION = '1')");
463
			}
464
		}
465
		StringBuilder whereSql = sql;
466
		sql = new StringBuilder();
467
		sql.append("SELECT COUNT(1) FROM PROFESSOR");
468
		if (whereSql.length() > 0) {
469
			sql.append(whereSql);
470
		}
471
		PreparedStatement ps = con.prepareStatement(sql.toString());
472
		int paramIndex = 1;
473
		int totalSize = 0;
474
		try {
475
			if (hasKey) {
476
				ps.setString(paramIndex++, key);
477
				ps.setString(paramIndex++, key);
478
				ps.setString(paramIndex++, key);
479
				ps.setString(paramIndex++, key);
480
				ps.setString(paramIndex++, key);
481
				ps.setString(paramIndex++, key);
482
				ps.setString(paramIndex++, key);
483
				ps.setString(paramIndex++, key);
484
			}
485
			if (hasSubject) {
486
				ps.setString(paramIndex++, subject);
487
			}
488
			if (hasIndustry) {
489
				ps.setString(paramIndex++, industry);
490
			}
491
			if (hasProvince) {
492
				ps.setString(paramIndex++, province);
493
			}
494
			if (hasAddress) {
495
				ps.setString(paramIndex++, address);
496
			}
497
			_result.setPageSize(pageSize);
498
			ResultSet _pageRs = ps.executeQuery();
499
			try {
500
				_pageRs.next();
501
				totalSize = _pageRs.getInt(1);
502
			} finally {
503
				try {
504
					_pageRs.close();
505
				} catch (Exception _m_6) {
506
				}
507
			}
508
		} finally {
509
			try {
510
				ps.close();
511
			} catch (Exception _m_7) {
512
			}
513
		}
514
		_result.setTotal(totalSize);
515
		if (0 == totalSize) {
516
			_result.setPageNo(1);
517
			_result.setData(Collections.<EditProfessor> emptyList());
518
			return _result;
519
		}
520
		paramIndex = 1;
521
		if (1 == pageNo) {
522
			_result.setPageNo(1);
523
			sql = new StringBuilder();
524
			sql.append("SELECT OFFICE,ADDRESS,TITLE,AUTHENTICATION,PROFESSOR.ID,PROFESSOR.NAME,ORG_ID,ORGANIZATION.NAME"
525
	        		+ " FROM PROFESSOR LEFT JOIN ORGANIZATION ON PROFESSOR.ORG_ID=ORGANIZATION.ID ");
526
			if (whereSql.length() > 0) {
527
				sql.append(whereSql);
528
			}
529
			sql.append(" ORDER BY STAR_LEVEL DESC ");
530
			sql.append(" LIMIT ").append(pageSize);
531
		} else {
532
			int _pageSize = totalSize / pageSize;
533
			if (totalSize % pageSize != 0) {
534
				++_pageSize;
535
			}
536
			if (pageNo > _pageSize) {
537
				pageNo = _pageSize;
538
			}
539
			_result.setPageNo(pageNo);
540
			--pageNo;
541
			int _m_10 = (pageNo * pageSize);
542
			sql = new StringBuilder();
543
			sql.append("SELECT OFFICE,ADDRESS,TITLE,AUTHENTICATION,PROFESSOR.ID,PROFESSOR.NAME,ORG_ID,ORGANIZATION.NAME"
544
	        		+ " FROM PROFESSOR LEFT JOIN ORGANIZATION ON PROFESSOR.ORG_ID=ORGANIZATION.ID ");
545
			if (whereSql.length() > 0) {
546
				sql.append(whereSql);
547
			}
548
			sql.append(" ORDER BY STAR_LEVEL DESC ");
549
			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(_m_10);
550
		}
551
		ps = con.prepareStatement(sql.toString());
552
		try {
553
			if (hasKey) {
554
				ps.setString(paramIndex++, key);
555
				ps.setString(paramIndex++, key);
556
				ps.setString(paramIndex++, key);
557
				ps.setString(paramIndex++, key);
558
				ps.setString(paramIndex++, key);
559
				ps.setString(paramIndex++, key);
560
				ps.setString(paramIndex++, key);
561
				ps.setString(paramIndex++, key);
562
			}
563
			if (hasSubject) {
564
				ps.setString(paramIndex++, subject);
565
			}
566
			if (hasIndustry) {
567
				ps.setString(paramIndex++, industry);
568
			}
569
			if (hasProvince) {
570
				ps.setString(paramIndex++, province);
571
			}
572
			if (hasAddress) {
573
				ps.setString(paramIndex++, address);
574
			}
575
			java.sql.ResultSet rs = ps.executeQuery();
576
			try {
577
				List<EditProfessor> _m_11 = new ArrayList<EditProfessor>();
578
				_result.setData(_m_11);
579
				while (rs.next()) {
580
					EditProfessor professor =  new EditProfessor();
581
                    String _m_1 = rs.getString(1);
582
                    if(rs.wasNull()){
583
                        _m_1 = null;
584
                    }
585
                    professor.setOffice(_m_1);
586
                    professor.setAddress(rs.getString(2));
587
                    professor.setTitle(rs.getString(3));
588
                    professor.setAuthentication("1".equals(rs.getString(4)));
589
                    professor.setId(rs.getString(5));
590
                    professor.setName(rs.getString(6));
591
                    professor.setOrgId(rs.getString(7));
592
                    professor.setOrgName(rs.getString(8));
593
					_m_11.add(professor);
594
				}
595
				return _result;
596
			} finally {
597
				try {
598
					rs.close();
599
				} catch (Exception e1) {
600
				}
601
			}
602
		} finally {
603
			try {
604
				ps.close();
605
			} catch (Exception e2) {
606
			}
607
		}
608
	}
609
	
288 610
	/**
289 611
	 * 分页查询专家基础信息,多条件查询专家列表。
290 612
	 * @param con

+ 44 - 14
src/main/java/com/ekexiu/portal/dao/ResourceDao.java

@ -297,10 +297,40 @@ public abstract class ResourceDao {
297 297
//    }
298 298
	
299 299
	/**
300
	 * 查询当前登录专家发布的所有资源
300
	 * APP涓撳鎼滅储鍒楄〃閲屾樉绀轰笓瀹剁殑鎵€鏈夎祫婧愶紙鍙渶瑕佽祫婧怚D鍜屽悕绉帮級
301
	 * @param con 
302
	 * @param professorId 涓撳ID
303
	 * @return 杩斿洖褰撳墠涓撳鍙戝竷鐨勬墍鏈夎祫婧愶紝骞舵寜鎺掑簭
304
	 * @throws SQLException
305
	 */
306
	public List<Resource> queryList(Connection con,String professorId) throws SQLException{
307
        String sql = "SELECT RESOURCE_ID,RESOURCE_NAME FROM RESOURCE WHERE PROFESSOR_ID = ? ORDER BY CREATE_TIME DESC";
308
        PreparedStatement ps = con.prepareStatement(sql);
309
        try{
310
            ps.setString(1,professorId);
311
            ResultSet rs = ps.executeQuery();
312
            try{
313
                List<Resource> resources = new ArrayList<Resource>();
314
                while(rs.next()){
315
                    Resource resource =  new Resource();
316
                    resource.setResourceId(rs.getString(1));
317
                    resource.setResourceName(rs.getString(2));
318
                    resources.add(resource);
319
                }
320
                return resources;
321
            }finally{
322
                try{rs.close();}catch(Exception e){}
323
            }
324
        }finally{
325
            try{ps.close();}catch(Exception e){}
326
        }
327
    }
328
	
329
	/**
330
	 * 鏌ヨ褰撳墠鐧诲綍涓撳鍙戝竷鐨勬墍鏈夎祫婧?
301 331
	 * @param con
302
	 * @param professorId 专家ID
303
	 * @return 返回当前专家发布的所有资源集合
332
	 * @param professorId 涓撳ID
333
	 * @return 杩斿洖褰撳墠涓撳鍙戝竷鐨勬墍鏈夎祫婧愰泦鍚?
304 334
	 * @throws SQLException
305 335
	 */
306 336
	public List<Resource> queryPro(Connection con,String professorId) throws SQLException{
@ -370,14 +400,14 @@ public abstract class ResourceDao {
370 400
	public abstract int delete(Connection con, String resourceId) throws SQLException;
371 401
	
372 402
	/**
373
	 * 分页查找所有资源(附带资源所有者基本信息),按资源名称排序
374
	 * @param key 查询内容(搜索框搜索内容-模糊查询)
375
	 * @param subject 学术领域
376
	 * @param industry 研究方向
377
	 * @param address 专家所在地
403
	 * 鍒嗛〉鏌ユ壘鎵€鏈夎祫婧?闄勫甫璧勬簮鎵€鏈夎€呭熀鏈俊鎭?锛屾寜璧勬簮鍚嶇О鎺掑簭
404
	 * @param key 鏌ヨ鍐呭锛堟悳绱㈡鎼滅储鍐呭-妯$硦鏌ヨ锛?
405
	 * @param subject 瀛︽湳棰嗗煙
406
	 * @param industry 鐮旂┒鏂瑰悜
407
	 * @param address 涓撳鎵€鍦ㄥ湴
378 408
	 * @param pageSize 
379 409
	 * @param pageNo
380
	 * @return 返回要查找的所有资源(附带资源所有者基本信息)
410
	 * @return 杩斿洖瑕佹煡鎵剧殑鎵€鏈夎祫婧?闄勫甫璧勬簮鎵€鏈夎€呭熀鏈俊鎭?
381 411
	 * @throws SQLException
382 412
	 */
383 413
	public PageQueryResult<Resource> queryPageRes(Connection con,String key,String subject,String industry,String address,int pageSize,int pageNo) throws SQLException{
@ -563,11 +593,11 @@ public abstract class ResourceDao {
563 593
    }
564 594
	
565 595
	/**
566
	 * 分页查找所有资源,按资源名称排序
567
	 * @param key 查询内容(搜索框搜索内容-模糊查询)
568
	 * @param subject 学术领域
569
	 * @param industry 研究方向
570
	 * @param address 专家所在地
596
	 * 鍒嗛〉鏌ユ壘鎵€鏈夎祫婧愶紝鎸夎祫婧愬悕绉版帓搴?
597
	 * @param key 鏌ヨ鍐呭锛堟悳绱㈡鎼滅储鍐呭-妯$硦鏌ヨ锛?
598
	 * @param subject 瀛︽湳棰嗗煙
599
	 * @param industry 鐮旂┒鏂瑰悜
600
	 * @param address 涓撳鎵€鍦ㄥ湴
571 601
	 * @param pageSize 
572 602
	 * @param pageNo
573 603
	 * @return

+ 39 - 1
src/main/java/com/ekexiu/portal/po/Professor.java

@ -1,6 +1,7 @@
1 1
package com.ekexiu.portal.po;
2 2
3 3
import java.math.BigDecimal;
4
import java.util.List;
4 5
5 6
import org.jfw.apt.orm.annotation.entry.Column;
6 7
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
@ -36,13 +37,16 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
36 37
	 * 应用行业
37 38
	 */
38 39
	private String industry;
40
	private String province;
39 41
	private String address;
40 42
	private String descp;
41 43
	private String createTime;
42 44
	private String modifyTime;
43 45
	private BigDecimal starLevel;
44 46
	private Integer consultCount;
47
	private BigDecimal starAvg;
45 48
	private Organization organization;
49
	private List<Resource> resources;
46 50
	
47 51
	public Organization getOrganization() {
48 52
		return organization;
@ -52,6 +56,14 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
52 56
		this.organization = organization;
53 57
	}
54 58
59
	public List<Resource> getResources() {
60
		return resources;
61
	}
62
63
	public void setResources(List<Resource> resources) {
64
		this.resources = resources;
65
	}
66
55 67
	@Column(value=DE.String_de,dbType="TEXT")
56 68
	public String getOffice() {
57 69
		return office;
@ -78,6 +90,23 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
78 90
		this.industry = industry;
79 91
	}
80 92
	
93
	/**
94
	 * 所在省份
95
	 * @return
96
	 */
97
	@Column(DE.String_de)
98
	public String getProvince() {
99
		return province;
100
	}
101
102
	public void setProvince(String province) {
103
		this.province = province;
104
	}
105
106
	/**
107
	 * 所在城市
108
	 * @return
109
	 */
81 110
	@Column(DE.String_de)
82 111
	public String getAddress() {
83 112
		return address;
@ -180,7 +209,7 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
180 209
		this.modifyTime = modifyTime;
181 210
	}
182 211
183
	@Column(handlerClass=BigDecimalHandler.class,dbType="DECIMAL",insertable=false,nullable=true,renewable=true,queryable=true)
212
	@Column(handlerClass=BigDecimalHandler.class,dbType="DECIMAL",insertable=false,nullable=false,renewable=true,queryable=true)
184 213
	public BigDecimal getStarLevel() {
185 214
		return starLevel;
186 215
	}
@ -198,4 +227,13 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
198 227
		this.consultCount = consultCount;
199 228
	}
200 229
230
	@Column(handlerClass=BigDecimalHandler.class,dbType="DECIMAL",insertable=false,nullable=false,renewable=true,queryable=true)
231
	public BigDecimal getStarAvg() {
232
		return starAvg;
233
	}
234
235
	public void setStarAvg(BigDecimal starAvg) {
236
		this.starAvg = starAvg;
237
	}
238
201 239
}

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

@ -119,6 +119,7 @@ public class ConsultService {
119 119
				professor.setHasHeadImage(this.imageService.hasProfessorImage(consult.getConsultantId()));
120 120
				consult.setProfessor(professor);
121 121
			}
122
			queryResult.setData(consults);
122 123
		}
123 124
		return queryResult;
124 125
	}
@ -177,6 +178,7 @@ public class ConsultService {
177 178
				int hasHeadImage = this.imageService.hasProfessorImage(consult.getConsultantId());
178 179
				consult.getProfessor().setHasHeadImage(hasHeadImage);
179 180
			}
181
			queryResult.setData(consults);
180 182
		}
181 183
		return queryResult;
182 184
	}	
@ -201,6 +203,7 @@ public class ConsultService {
201 203
				int hasHeadImage = this.imageService.hasProfessorImage(consult.getProfessorId());
202 204
				consult.getProfessor().setHasHeadImage(hasHeadImage);
203 205
			}
206
			queryResult.setData(consults);
204 207
		}
205 208
		return queryResult;
206 209
	}

+ 73 - 10
src/main/java/com/ekexiu/portal/service/ProfessorService.java

@ -31,12 +31,18 @@ import com.ekexiu.portal.dao.ProfessorEduBgDao;
31 31
import com.ekexiu.portal.dao.ProjectDao;
32 32
import com.ekexiu.portal.dao.ResearchAreaDao;
33 33
import com.ekexiu.portal.dao.ResearchAreaLogDao;
34
import com.ekexiu.portal.dao.ResourceDao;
34 35
import com.ekexiu.portal.po.Professor;
35 36
import com.ekexiu.portal.pojo.EditProfessor;
36 37
import com.ekexiu.portal.pojo.ProfessorInfo;
38
import com.ekexiu.portal.util.Calculate;
37 39

38 40
@Path("/professor")
39 41
public class ProfessorService {
42
	@Autowrie
43
	private Calculate calculate;
44
	@Autowrie
45
	private ResourceDao resourceDao;
40 46
	@Autowrie
41 47
	private ImageService imageService;
42 48
	@Autowrie
@ -63,8 +69,22 @@ public class ProfessorService {
63 69
	private ProjectDao projectDao;
64 70

65 71
	
66
	
67
	
72
	public Calculate getCalculate() {
73
		return calculate;
74
	}
75

76
	public void setCalculate(Calculate calculate) {
77
		this.calculate = calculate;
78
	}
79

80
	public ResourceDao getResourceDao() {
81
		return resourceDao;
82
	}
83

84
	public void setResourceDao(ResourceDao resourceDao) {
85
		this.resourceDao = resourceDao;
86
	}
87

68 88
	public ImageService getImageService() {
69 89
		return imageService;
70 90
	}
@ -223,10 +243,51 @@ public class ProfessorService {
223 243
	}
224 244
	@Get
225 245
	@Path("/qa")
226
	public List<Professor> queryAll(@JdbcConn Connection con)throws SQLException {
246
	public List<Professor> queryAll(@JdbcConn Connection con) throws SQLException {
227 247
		return this.professorDao.query(con);
228 248
	}
229 249
	
250
	@Post
251
	@Path("/updateStarAvg")
252
	public boolean updateStarAvg(@JdbcConn(true) Connection con) throws SQLException {
253
		List<Professor> professors = this.professorDao.queryStar(con);
254
		BigDecimal bigStar = this.professorDao.queryBigStar(con);
255
		BigDecimal smallStar = this.professorDao.querySmallStar(con);
256
		BigDecimal bigConsult = this.professorDao.queryBigConsult(con);
257
		BigDecimal smallConsult = this.professorDao.querySmallConsult(con);
258
		for (Professor professor : professors) {
259
			BigDecimal star = professor.getStarLevel();
260
			BigDecimal consult = new BigDecimal(professor.getConsultCount());
261
			BigDecimal avgStar = this.calculate.calcAvgStar(bigStar, smallStar, bigConsult, smallConsult, star, consult);
262
			this.professorDao.updateStarAvg(con, professor.getId(), avgStar);
263
		}
264
		return true;
265
	}
266
	
267
	@Get
268
	@Path("/pqAPP")
269
	public PageQueryResult<EditProfessor> queryAPP(@JdbcConn Connection con, @Nullable String key,
270
			@Nullable String subject,@Nullable String industry,@Nullable String province,
271
			@Nullable String address, @Nullable Integer authentication, 
272
			@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo) throws SQLException{
273
		if(key!=null) {key="%"+key+"%";}
274
		if(subject!=null) {subject ="%"+subject+"%";}
275
		if(null!=industry) {industry="%"+industry+"%";}
276
		if(null!=province) {province="%"+province+"%";}
277
		if(null!=address) {address="%"+address+"%";}
278
		PageQueryResult<EditProfessor> queryResult = this.professorDao.queryAPP(con,key,subject,industry,province,address,authentication,pageSize,pageNo);
279
		List<EditProfessor> editProfessors = queryResult.getData();
280
		if(editProfessors != null) {
281
			for (EditProfessor editProfessor : editProfessors) {
282
				editProfessor.setHasHeadImage(this.imageService.hasProfessorImage(editProfessor.getId()));
283
				editProfessor.setResearchAreas(this.researchAreaDao.query(con, editProfessor.getId()));
284
				editProfessor.setResources(this.resourceDao.queryList(con, editProfessor.getId()));
285
			}
286
			queryResult.setData(editProfessors);
287
		}
288
		return queryResult;
289
	}
290
	
230 291
	@Post
231 292
	@Path("/starLevel")
232 293
	public void updateStarLevel(@JdbcConn(true) Connection con, String id, BigDecimal starLevel) throws SQLException{
@ -246,7 +307,8 @@ public class ProfessorService {
246 307
	}
247 308
	@Post
248 309
	@Path("/address")
249
	public void updateAddress(@JdbcConn(true) Connection con, String id, String address) throws SQLException{
310
	public void updateAddress(@JdbcConn(true) Connection con, String id, String province, String address) throws SQLException{
311
		this.professorDao.updateProvince(con, id, province);
250 312
		this.professorDao.updateAddress(con, id, address);
251 313
	}
252 314
	@Post
@ -275,10 +337,10 @@ public class ProfessorService {
275 337
	PageQueryResult<EditProfessor> queryEditBaseInfo(@JdbcConn(false) Connection con,@Nullable String key,
276 338
			@Nullable String subject,@Nullable String industry,@Nullable String address,@Nullable Integer authentication, 
277 339
			@DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
278
		if(key!=null) key="%"+key+"%";
279
		if(subject!=null) subject ="%"+subject+"%";
280
		if(null!=industry) industry="%"+industry+"%";
281
		if(null!=address) address="%"+address+"%";
340
		if(key!=null) {key="%"+key+"%";}
341
		if(subject!=null) {subject ="%"+subject+"%";}
342
		if(null!=industry) {industry="%"+industry+"%";}
343
		if(null!=address) {address="%"+address+"%";}
282 344
		PageQueryResult<EditProfessor> queryResult = this.professorDao.queryEditBaseInfo(con, key, subject, industry, address, authentication, pageSize, pageNo);
283 345
		List<EditProfessor> editProfessors = queryResult.getData();
284 346
		if(editProfessors != null){
@ -286,6 +348,7 @@ public class ProfessorService {
286 348
				editProfessor.setHasHeadImage(this.imageService.hasProfessorImage(editProfessor.getId()));
287 349
				editProfessor.setResearchAreas(this.researchAreaDao.query(con, editProfessor.getId()));
288 350
			}
351
			queryResult.setData(editProfessors);
289 352
		}
290 353
		return queryResult;
291 354
	}
@ -330,7 +393,7 @@ public class ProfessorService {
330 393
//		ProfessorService service = new ProfessorService();
331 394
//		ProfessorDao dao = new ProfessorDaoExtend();
332 395
//		service.setProfessorDao(dao);
333
//		PageQueryResult<Professor> result =service.query(con,"杨", "材料", "金属", 10, 2);
396
//		PageQueryResult<Professor> result =service.query(con,"鏉?, "鏉愭枡", "閲戝睘", 10, 2);
334 397
//		System.out.println(result.getTotal());
335 398
//		for(Professor p:result.getData()){
336 399
//			System.out.println("======");
@ -339,6 +402,6 @@ public class ProfessorService {
339 402
//		}finally{
340 403
//			con.close();
341 404
//		}
342
		System.out.println(URLEncoder.encode("", "UTF-8"));
405
		System.out.println(URLEncoder.encode("输出中文", "UTF-8"));
343 406
	}
344 407
}