Browse Source

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

zzy.zhiyuan.foxmail 8 years ago
parent
commit
dec3735e24

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

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

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

1
package com.ekexiu.portal.dao;
1
package com.ekexiu.portal.dao;
2

2

3
import java.math.BigDecimal;
3
import java.sql.Connection;
4
import java.sql.Connection;
4
import java.sql.PreparedStatement;
5
import java.sql.PreparedStatement;
5
import java.sql.ResultSet;
6
import java.sql.ResultSet;
26

27

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

32

31
@DAO
33
@DAO
38
	
40
	
39
	@UpdateWith
41
	@UpdateWith
40
	@From(Professor.class)
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
	@UpdateWith
49
	@UpdateWith
44
	@From(Professor.class)
50
	@From(Professor.class)
56
	@From(Professor.class)
62
	@From(Professor.class)
57
	public abstract int updateAddress(Connection con, String id, @Set String address) throws SQLException;
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
	public Professor query(Connection con, String id) throws SQLException{
152
	public Professor query(Connection con, String id) throws SQLException{
60
        int _m_1 = 1;
153
        int _m_1 = 1;
61
        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 = ?";
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
package com.ekexiu.portal.po;
1
package com.ekexiu.portal.po;
2
2
3
import java.math.BigDecimal;
4
3
import org.jfw.apt.orm.annotation.entry.Column;
5
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
6
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5
import org.jfw.apt.orm.annotation.entry.Table;
7
import org.jfw.apt.orm.annotation.entry.Table;
8
import org.jfw.apt.orm.core.defaultImpl.BigDecimalHandler;
6
import org.jfw.apt.orm.core.defaultImpl.FixLenStringHandler;
9
import org.jfw.apt.orm.core.defaultImpl.FixLenStringHandler;
7
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
10
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
8
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
11
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
37
	private String descp;
40
	private String descp;
38
	private String createTime;
41
	private String createTime;
39
	private String modifyTime;
42
	private String modifyTime;
40
	private int starLevel;
43
	private BigDecimal starLevel;
44
	private int consultCount;
41
	private Organization organization;
45
	private Organization organization;
42
	
46
	
43
	public Organization getOrganization() {
47
	public Organization getOrganization() {
176
		this.modifyTime = modifyTime;
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
		return starLevel;
185
		return starLevel;
182
	}
186
	}
183
184
	public void setStarLevel(int starLevel) {
187
	
188
	public void setStarLevel(BigDecimal starLevel) {
185
		this.starLevel = starLevel;
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
package com.ekexiu.portal.pojo;
1
package com.ekexiu.portal.pojo;
2

2

3
import java.util.List;
4

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

7

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

15

8
	public String getOrgName() {
16
	public String getOrgName() {
9
		return orgName;
17
		return orgName;
12
	public void setOrgName(String orgName) {
20
	public void setOrgName(String orgName) {
13
		this.orgName = orgName;
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
import org.jfw.util.StringUtil;
14
import org.jfw.util.StringUtil;
15

15

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

19

19
@Path("/consult")
20
@Path("/consult")
20
public class ConsultService {
21
public class ConsultService {
21
	@Autowrie
22
	@Autowrie
22
	private ConsultDao consultDao;
23
	private ConsultDao consultDao;
24
	@Autowrie
25
	private ProfessorDao professorDao;
26
	
23
	public ConsultDao getConsultDao() {
27
	public ConsultDao getConsultDao() {
24
		return consultDao;
28
		return consultDao;
25
	}
29
	}
26
	public void setConsultDao(ConsultDao consultDao) {
30
	public void setConsultDao(ConsultDao consultDao) {
27
		this.consultDao = consultDao;
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
	@Post
40
	@Post
31
	@Path
41
	@Path
48
		Consult consult = this.consultDao.query(con, consultId);
58
		Consult consult = this.consultDao.query(con, consultId);
49
		if(null == consult.getFinishTime()){
59
		if(null == consult.getFinishTime()){
50
			this.consultDao.updateFinishTime(con, consultId,consultStatus);
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
			return true;
63
			return true;
52
		}
64
		}
53
		return false;
65
		return false;
59
		Consult consult = this.consultDao.query(con, consultId);
71
		Consult consult = this.consultDao.query(con, consultId);
60
		if(0 == consult.getAssessStatus()){
72
		if(0 == consult.getAssessStatus()){
61
			this.consultDao.updateAssess(con, consultId, assessStatus, assessStar, assessContant);
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
			return true;
76
			return true;
63
		}
77
		}
64
		return false;
78
		return false;

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

141
	public void setDefaultResourcePhoto(File defaultResourcePhoto) {
141
	public void setDefaultResourcePhoto(File defaultResourcePhoto) {
142
		this.defaultResourcePhoto = defaultResourcePhoto;
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
	private File getTemplateFielName(File path, String suffix) {
160
	private File getTemplateFielName(File path, String suffix) {
146
		File result = null;
161
		File result = null;

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

1
package com.ekexiu.portal.service;
1
package com.ekexiu.portal.service;
2

2

3
import java.io.IOException;
3
import java.io.IOException;
4
import java.math.BigDecimal;
4
import java.net.URLEncoder;
5
import java.net.URLEncoder;
5
import java.sql.Connection;
6
import java.sql.Connection;
6
import java.sql.SQLException;
7
import java.sql.SQLException;
194
			}
195
			}
195
		this.professorDao.update(con, professor);
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
	@Get
215
	@Get
199
	@Path("/{id}")
216
	@Path("/{id}")
200
	public Professor query(@JdbcConn Connection con, @PathVar String id) throws SQLException {
217
	public Professor query(@JdbcConn Connection con, @PathVar String id) throws SQLException {
208
	
225
	
209
	@Post
226
	@Post
210
	@Path("/starLevel")
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
		this.professorDao.updateStarLevel(con, id, starLevel);
229
		this.professorDao.updateStarLevel(con, id, starLevel);
213
	}
230
	}
214
	
231