Browse Source

专家基本信息接口和专家基本信息(加上星级和被咨询次数)接口。ImageService添加判断是否存在专家头像的接口。

zzy.zhiyuan.foxmail 8 years ago
parent
commit
dec3735e24

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

@ -107,7 +107,7 @@ public abstract class ConsultDao {
107 107
	 * @return 返回用户被评价的平均星级
108 108
	 * @throws SQLException
109 109
	 */
110
	public int queryStarLevel(Connection con, String professorId) throws SQLException {
110
	public BigDecimal queryStarLevel(Connection con, String professorId) throws SQLException {
111 111
		int _m_2 = 1;
112 112
		String sql = " SELECT AVG(ASSESS_STAR) FROM CONSULT WHERE ASSESS_STATUS = 1 AND PROFESSOR_ID = ? ";
113 113
		PreparedStatement ps = con.prepareStatement(sql);
@ -115,7 +115,7 @@ public abstract class ConsultDao {
115 115
			ps.setString(_m_2++, professorId);
116 116
			ResultSet rs = ps.executeQuery();
117 117
			rs.next();
118
			int avg = rs.getInt(1);
118
			BigDecimal avg = rs.getBigDecimal(1);
119 119
			return avg;
120 120
		} finally{
121 121
            try{ps.close();}catch(Exception _m_3){}
@ -175,15 +175,15 @@ public abstract class ConsultDao {
175 175
	}
176 176
	
177 177
	/**
178
	 * 我的工作台中显示接受咨询的总次数
178
	 * 我的工作台中显示接受咨询的总次数(已完成状态)
179 179
	 * @param con
180 180
	 * @param professorId 登陆者ID
181
	 * @return 返回接受咨询的总次数
181
	 * @return 返回接受咨询已完成的总次数
182 182
	 * @throws SQLException
183 183
	 */
184 184
	public int queryReceiveConsult(Connection con, String professorId) throws SQLException {
185 185
		int _m_2 = 1;
186
		String sql = " SELECT COUNT(1) FROM CONSULT WHERE PROFESSOR_ID = ? ";
186
		String sql = " SELECT COUNT(1) FROM CONSULT WHERE (CONSULT_STATUS = 1) AND (PROFESSOR_ID = ?) ";
187 187
		PreparedStatement ps = con.prepareStatement(sql);
188 188
		try {
189 189
			ps.setString(_m_2++, professorId);

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

@ -1,5 +1,6 @@
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;
5 6
import java.sql.ResultSet;
@ -26,6 +27,7 @@ import org.jfw.util.PageQueryResult;
26 27

27 28
import com.ekexiu.portal.po.Organization;
28 29
import com.ekexiu.portal.po.Professor;
30
import com.ekexiu.portal.pojo.EditProfessor;
29 31
import com.ekexiu.portal.pojo.ProfessorInfo;
30 32

31 33
@DAO
@ -38,7 +40,11 @@ public abstract class ProfessorDao {
38 40
	
39 41
	@UpdateWith
40 42
	@From(Professor.class)
41
	public abstract int updateStarLevel(Connection con, String id, @Set int starLevel) throws SQLException;
43
	public abstract int updateStarLevel(Connection con, String id, @Set BigDecimal starLevel) throws SQLException;
44
	
45
	@UpdateWith
46
	@From(Professor.class)
47
	public abstract int updateConsultCount(Connection con, String id, @Set int consultCount) throws SQLException;
42 48

43 49
	@UpdateWith
44 50
	@From(Professor.class)
@ -56,6 +62,93 @@ public abstract class ProfessorDao {
56 62
	@From(Professor.class)
57 63
	public abstract int updateAddress(Connection con, String id, @Set String address) throws SQLException;
58 64
	
65
	/**
66
	 * 查询专家基本信息接口
67
	 * @param con
68
	 * @param id 专家ID
69
	 * @return 返回专家基本信息
70
	 * @throws SQLException
71
	 */
72
	public EditProfessor queryBaseInfo(Connection con, String id) throws SQLException {
73
		int _m_1 = 1;
74
        String sql = "SELECT P.OFFICE,P.DEPARTMENT,P.TITLE,AUTHENTICATION,P.ID,P.NAME,P.ADDRESS,ORGANIZATION.NAME "
75
        		+ " FROM PROFESSOR P LEFT JOIN ORGANIZATION ON P.ORG_ID = ORGANIZATION.ID WHERE P.ID = ?";
76
        PreparedStatement ps = con.prepareStatement(sql);
77
        try{
78
            ps.setString(_m_1++,id);
79
            ResultSet rs = ps.executeQuery();
80
            try{
81
                if(rs.next()){
82
                	EditProfessor professor = new EditProfessor();
83
                    professor.setOffice(rs.getString(1));
84
                    professor.setDepartment(rs.getString(2));
85
                    professor.setTitle(rs.getString(3));
86
                    professor.setAuthentication("1".equals(rs.getString(4)));
87
                    professor.setId(rs.getString(5));
88
                    professor.setName(rs.getString(6));
89
                    professor.setAddress(rs.getString(7));
90
                    professor.setOrgName(rs.getString(8));
91
                    return professor;
92
                }else{
93
                    return null;
94
                }
95
            }finally{
96
                try{rs.close();}catch(Exception _m_9){}
97
            }
98
        }finally{
99
            try{ps.close();}catch(Exception _m_10){}
100
        }
101
	}
102
	
103
	/**
104
	 * 查询专家基本信息+星级+咨询次数的接口
105
	 * @param con
106
	 * @param id 专家ID
107
	 * @return 返回专家基本信息+星级+咨询次数
108
	 * @throws SQLException
109
	 */
110
	public EditProfessor queryEditBaseInfo(Connection con, String id) throws SQLException {
111
		int _m_1 = 1;
112
        String sql = "SELECT P.OFFICE,P.DEPARTMENT,P.TITLE,AUTHENTICATION,P.ID,P.NAME,"
113
        		+ " P.ADDRESS,P.STAR_LEVEL,P.CONSULT_COUNT,ORGANIZATION.NAME "
114
        		+ " FROM PROFESSOR P LEFT JOIN ORGANIZATION ON P.ORG_ID = ORGANIZATION.ID WHERE P.ID = ?";
115
        PreparedStatement ps = con.prepareStatement(sql);
116
        try{
117
            ps.setString(_m_1++,id);
118
            ResultSet rs = ps.executeQuery();
119
            try{
120
                if(rs.next()){
121
                	EditProfessor professor = new EditProfessor();
122
                    professor.setOffice(rs.getString(1));
123
                    professor.setDepartment(rs.getString(2));
124
                    professor.setTitle(rs.getString(3));
125
                    professor.setAuthentication("1".equals(rs.getString(4)));
126
                    professor.setId(rs.getString(5));
127
                    professor.setName(rs.getString(6));
128
                    professor.setAddress(rs.getString(7));
129
                    BigDecimal starLevel = rs.getBigDecimal(8);
130
                    if(rs.wasNull()){
131
                    	starLevel = null;
132
                    }
133
                    professor.setStarLevel(starLevel);
134
                    Integer consultCount = rs.getInt(9);
135
                    if(rs.wasNull()){
136
                    	consultCount = 0;
137
                    }
138
                    professor.setConsultCount(consultCount);
139
                    professor.setOrgName(rs.getString(10));
140
                    return professor;
141
                }else{
142
                    return null;
143
                }
144
            }finally{
145
                try{rs.close();}catch(Exception _m_9){}
146
            }
147
        }finally{
148
            try{ps.close();}catch(Exception _m_10){}
149
        }
150
	}
151
	
59 152
	public Professor query(Connection con, String id) throws SQLException{
60 153
        int _m_1 = 1;
61 154
        String sql = "SELECT P.OFFICE,P.SUBJECT,P.INDUSTRY,P.ADDRESS,P.DEPARTMENT,ORG_ID,P.TITLE,AUTHENTICATION,P.ID,P.NAME,P.DESCP,P.CREATE_TIME,P.MODIFY_TIME,ORGANIZATION.NAME FROM PROFESSOR P LEFT JOIN ORGANIZATION ON P.ORG_ID = ORGANIZATION.ID WHERE P.ID = ?";

+ 18 - 5
src/main/java/com/ekexiu/portal/po/Professor.java

@ -1,8 +1,11 @@
1 1
package com.ekexiu.portal.po;
2 2
3
import java.math.BigDecimal;
4
3 5
import org.jfw.apt.orm.annotation.entry.Column;
4 6
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5 7
import org.jfw.apt.orm.annotation.entry.Table;
8
import org.jfw.apt.orm.core.defaultImpl.BigDecimalHandler;
6 9
import org.jfw.apt.orm.core.defaultImpl.FixLenStringHandler;
7 10
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
8 11
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
@ -37,7 +40,8 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
37 40
	private String descp;
38 41
	private String createTime;
39 42
	private String modifyTime;
40
	private int starLevel;
43
	private BigDecimal starLevel;
44
	private int consultCount;
41 45
	private Organization organization;
42 46
	
43 47
	public Organization getOrganization() {
@ -176,13 +180,22 @@ public class Professor implements CreateTimeSupported, ModifyTimeSupported{
176 180
		this.modifyTime = modifyTime;
177 181
	}
178 182
179
	@Column(handlerClass=IntHandler.class,dbType="INT",insertable=false,nullable=true,renewable=true,queryable=true)
180
	public int getStarLevel() {
183
	@Column(handlerClass=BigDecimalHandler.class,dbType="DECIMAL",insertable=false,nullable=true,renewable=true,queryable=true)
184
	public BigDecimal getStarLevel() {
181 185
		return starLevel;
182 186
	}
183
184
	public void setStarLevel(int starLevel) {
187
	
188
	public void setStarLevel(BigDecimal starLevel) {
185 189
		this.starLevel = starLevel;
186 190
	}
187 191
192
	@Column(handlerClass=IntHandler.class,dbType="INT",insertable=false,nullable=true,renewable=true,queryable=true)
193
	public int getConsultCount() {
194
		return consultCount;
195
	}
196
197
	public void setConsultCount(int consultCount) {
198
		this.consultCount = consultCount;
199
	}
200
188 201
}

+ 24 - 1
src/main/java/com/ekexiu/portal/pojo/EditProfessor.java

@ -1,9 +1,17 @@
1 1
package com.ekexiu.portal.pojo;
2 2

3
import java.util.List;
4

3 5
import com.ekexiu.portal.po.Professor;
6
import com.ekexiu.portal.po.ResearchArea;
4 7

5 8
public class EditProfessor extends Professor {
6 9
	private String orgName;
10
	private int hasHeadImage;
11
	/**
12
	 * 研究方向
13
	 */
14
	private List<ResearchArea> researchAreas;
7 15

8 16
	public String getOrgName() {
9 17
		return orgName;
@ -12,6 +20,21 @@ public class EditProfessor extends Professor {
12 20
	public void setOrgName(String orgName) {
13 21
		this.orgName = orgName;
14 22
	}
15
	
23

24
	public int getHasHeadImage() {
25
		return hasHeadImage;
26
	}
27

28
	public void setHasHeadImage(int hasHeadImage) {
29
		this.hasHeadImage = hasHeadImage;
30
	}
31

32
	public List<ResearchArea> getResearchAreas() {
33
		return researchAreas;
34
	}
35

36
	public void setResearchAreas(List<ResearchArea> researchAreas) {
37
		this.researchAreas = researchAreas;
38
	}
16 39

17 40
}

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

@ -14,18 +14,28 @@ import org.jfw.util.PageQueryResult;
14 14
import org.jfw.util.StringUtil;
15 15

16 16
import com.ekexiu.portal.dao.ConsultDao;
17
import com.ekexiu.portal.dao.ProfessorDao;
17 18
import com.ekexiu.portal.po.Consult;
18 19

19 20
@Path("/consult")
20 21
public class ConsultService {
21 22
	@Autowrie
22 23
	private ConsultDao consultDao;
24
	@Autowrie
25
	private ProfessorDao professorDao;
26
	
23 27
	public ConsultDao getConsultDao() {
24 28
		return consultDao;
25 29
	}
26 30
	public void setConsultDao(ConsultDao consultDao) {
27 31
		this.consultDao = consultDao;
28 32
	}
33
	public ProfessorDao getProfessorDao() {
34
		return professorDao;
35
	}
36
	public void setProfessorDao(ProfessorDao professorDao) {
37
		this.professorDao = professorDao;
38
	}
29 39
	
30 40
	@Post
31 41
	@Path
@ -48,6 +58,8 @@ public class ConsultService {
48 58
		Consult consult = this.consultDao.query(con, consultId);
49 59
		if(null == consult.getFinishTime()){
50 60
			this.consultDao.updateFinishTime(con, consultId,consultStatus);
61
			int finishConsult = this.consultDao.queryReceiveConsult(con, consult.getProfessorId());
62
			this.professorDao.updateConsultCount(con, consult.getProfessorId(), finishConsult);
51 63
			return true;
52 64
		}
53 65
		return false;
@ -59,6 +71,8 @@ public class ConsultService {
59 71
		Consult consult = this.consultDao.query(con, consultId);
60 72
		if(0 == consult.getAssessStatus()){
61 73
			this.consultDao.updateAssess(con, consultId, assessStatus, assessStar, assessContant);
74
			BigDecimal avgStar = this.consultDao.queryStarLevel(con, consult.getProfessorId());
75
			this.professorDao.updateStarLevel(con, consult.getProfessorId(), avgStar);
62 76
			return true;
63 77
		}
64 78
		return false;

+ 15 - 0
src/main/java/com/ekexiu/portal/service/ImageService.java

@ -141,6 +141,21 @@ public class ImageService {
141 141
	public void setDefaultResourcePhoto(File defaultResourcePhoto) {
142 142
		this.defaultResourcePhoto = defaultResourcePhoto;
143 143
	}
144
	
145
	/**
146
	 * 判断是否有专家头像
147
	 * @param id 专家ID
148
	 * @return 有头像返回1,没有返回0.
149
	 */
150
	public int hasProfessorImage(String id) {
151
		String headPath = this.headPath+"/"+id+"_l.jpg";
152
		File file = new File(headPath);
153
		if(file.exists()){
154
			return 1;
155
		}else{
156
			return 0;
157
		}
158
	}
144 159
145 160
	private File getTemplateFielName(File path, String suffix) {
146 161
		File result = null;

+ 19 - 2
src/main/java/com/ekexiu/portal/service/ProfessorService.java

@ -1,6 +1,7 @@
1 1
package com.ekexiu.portal.service;
2 2

3 3
import java.io.IOException;
4
import java.math.BigDecimal;
4 5
import java.net.URLEncoder;
5 6
import java.sql.Connection;
6 7
import java.sql.SQLException;
@ -194,7 +195,23 @@ public class ProfessorService {
194 195
			}
195 196
		this.professorDao.update(con, professor);
196 197
	}
197

198
	
199
	@Get
200
	@Path("/baseInfo/{id}")
201
	public EditProfessor queryBaseInfo(@JdbcConn Connection con, @PathVar String id) throws SQLException {
202
		EditProfessor professor = this.professorDao.queryBaseInfo(con, id);
203
		professor.setHasHeadImage(this.imageService.hasProfessorImage(id));
204
		return professor;
205
	}
206
	
207
	@Get
208
	@Path("/editBaseInfo/{id}")
209
	public EditProfessor queryEditBaseInfo(@JdbcConn Connection con, @PathVar String id) throws SQLException {
210
		EditProfessor professor = this.professorDao.queryEditBaseInfo(con, id);
211
		professor.setHasHeadImage(this.imageService.hasProfessorImage(id));
212
		return professor;
213
	}
214
	
198 215
	@Get
199 216
	@Path("/{id}")
200 217
	public Professor query(@JdbcConn Connection con, @PathVar String id) throws SQLException {
@ -208,7 +225,7 @@ public class ProfessorService {
208 225
	
209 226
	@Post
210 227
	@Path("/starLevel")
211
	public void updateStarLevel(@JdbcConn(true) Connection con, String id, int starLevel) throws SQLException{
228
	public void updateStarLevel(@JdbcConn(true) Connection con, String id, BigDecimal starLevel) throws SQLException{
212 229
		this.professorDao.updateStarLevel(con, id, starLevel);
213 230
	}
214 231