Browse Source

修改query接口。

bulomakaka 8 years ago
parent
commit
94f0d3a8b4

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

@ -1,231 +1,231 @@
1
package com.ekexiu.portal.dao;
2
3
import java.sql.Connection;
4
import java.sql.SQLException;
5
import java.util.List;
6
7
import org.jfw.apt.annotation.Nullable;
8
import org.jfw.apt.orm.annotation.dao.DAO;
9
import org.jfw.apt.orm.annotation.dao.method.From;
10
import org.jfw.apt.orm.annotation.dao.method.Or;
11
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
12
import org.jfw.apt.orm.annotation.dao.method.Select;
13
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
14
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
15
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
16
import org.jfw.apt.orm.annotation.dao.method.operator.QueryOne;
17
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
18
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
19
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
20
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
21
import org.jfw.apt.orm.annotation.dao.param.Set;
22
import org.jfw.apt.orm.annotation.dao.param.SqlColumn;
23
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
24
import org.jfw.util.PageQueryResult;
25
26
import com.ekexiu.portal.po.Professor;
27
import com.ekexiu.portal.pojo.ProfessorInfo;
28
29
@DAO
30
public abstract class ProfessorDao {
31
32
	@Insert
33
	public abstract int insert(Connection con, Professor professor) throws SQLException;
34
35
	@Update
36
	public abstract int update(Connection con, Professor professor) throws SQLException;
37
38
	@UpdateWith
39
	@From(Professor.class)
40
	public abstract int updateSubject(Connection con, String id, @Set String subject) throws SQLException;
41
42
	@UpdateWith
43
	@From(Professor.class)
44
	public abstract int updateDescp(Connection con, String id, @Set String descp) throws SQLException;
45
46
	@UpdateWith
47
	@From(Professor.class)
48
	public abstract int updateIndustry(Connection con, String id, @Set String industry) throws SQLException;
49
50
	@Nullable
51
	@SelectOne
52
	public abstract Professor query(Connection con, String id) throws SQLException;
53
54
	@SelectList
55
	public abstract List<Professor> query(Connection con) throws SQLException;
56
57
	@Nullable
58
	@QueryOne
59
	@From(Professor.class)
60
	@Select(Professor.class)
61
	public abstract ProfessorInfo queryInfo(Connection con, String id) throws SQLException;
62
63
	@DeleteWith
64
	@From(Professor.class)
65
	public abstract int delete(Connection con, String id) throws SQLException;
66
67
	@PageSelect
68
	@Or
69
	@OrderBy(" ORDER BY ID ")
70
	public abstract PageQueryResult<Professor> query(Connection con,
71
			@Nullable @SqlColumn(value = { "ID IN (SELECT PROFESSOR_ID FROM RESEARCH_AREA WHERE CAPTION LIKE ?)",
72
					"" + "ORG_ID IN(SELECT ID FROM ORGANIZATION WHERE NAME LIKE ?)", "NAME LIKE ?" }, handlerClass = StringHandler.class) String key,
73
			int pageSize, int pageNo) throws SQLException;
74
75
	public PageQueryResult<Professor> query(Connection con, @Nullable String key, String subject, String industry, int pageSize, int pageNo)
76
			throws SQLException {
77
78
		org.jfw.util.PageQueryResult<com.ekexiu.portal.po.Professor> _result = new org.jfw.util.PageQueryResult<com.ekexiu.portal.po.Professor>();
79
80
		StringBuilder sql = new StringBuilder();
81
		boolean hasKey = null != key;
82
		if (hasKey) {
83
			sql.append(
84
					" WHERE (( ID IN (SELECT PROFESSOR_ID FROM RESEARCH_AREA WHERE CAPTION LIKE ?)) OR (ORG_ID IN(SELECT ID FROM ORGANIZATION WHERE NAME LIKE ?)) OR( ORG_ID IN(SELECT ID FROM ORGANIZATION WHERE NAME LIKE ?)))");
85
		}
86
		boolean hasSubject = null != subject;
87
		boolean hasIndustry = null != industry;
88
		if (hasSubject) {
89
			sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(SUBJECT LIKE ?)");
90
		}
91
		if (hasIndustry) {
92
			sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(INDUSTRY LIKE ?)");
93
		}
94
95
		StringBuilder whereSql = sql;
96
		sql = new StringBuilder();
97
		sql.append("SELECT COUNT(1) FROM PROFESSOR");
98
		if (whereSql.length() > 0) {
99
			sql.append(whereSql);
100
		}
101
		java.sql.PreparedStatement ps = con.prepareStatement(sql.toString());
102
		int paramIndex = 1;
103
		int totalSize = 0;
104
		try {
105
			if (hasKey) {
106
				ps.setString(paramIndex++, key);
107
				ps.setString(paramIndex++, key);
108
				ps.setString(paramIndex++, key);
109
			}
110
			if (hasSubject) {
111
				ps.setString(paramIndex++, subject);
112
			}
113
			if (hasIndustry) {
114
				ps.setString(paramIndex++, industry);
115
			}
116
			_result.setPageSize(pageSize);
117
			java.sql.ResultSet _pageRs = ps.executeQuery();
118
			try {
119
				_pageRs.next();
120
				totalSize = _pageRs.getInt(1);
121
			} finally {
122
				try {
123
					_pageRs.close();
124
				} catch (Exception _m_6) {
125
				}
126
			}
127
		} finally {
128
			try {
129
				ps.close();
130
			} catch (Exception _m_7) {
131
			}
132
		}
133
		_result.setTotal(totalSize);
134
		if (0 == totalSize) {
135
			_result.setPageNo(1);
136
			_result.setData(java.util.Collections.<com.ekexiu.portal.po.Professor> emptyList());
137
			return _result;
138
		}
139
		paramIndex = 1;
140
		if (1 == pageNo) {
141
			_result.setPageNo(1);
142
			sql = new StringBuilder();
143
			sql.append("SELECT OFFICE,SUBJECT,INDUSTRY,DEPARTMENT,ORG_ID,TITLE,AUTHENTICATION,ID,NAME,DESCP,CREATE_TIME,MODIFY_TIME FROM PROFESSOR");
144
			if (whereSql.length() > 0) {
145
				sql.append(whereSql);
146
			}
147
			sql.append(" LIMIT ").append(pageSize);
148
		} else {
149
			int _pageSize = totalSize / pageSize;
150
			if (totalSize % pageSize != 0) {
151
				++_pageSize;
152
			}
153
			if (pageNo > _pageSize) {
154
				pageNo = _pageSize;
155
			}
156
			_result.setPageNo(pageNo);
157
			--pageNo;
158
			int _m_10 = (pageNo * pageSize);
159
			sql = new StringBuilder();
160
			sql.append("SELECT OFFICE,SUBJECT,INDUSTRY,DEPARTMENT,ORG_ID,TITLE,AUTHENTICATION,ID,NAME,DESCP,CREATE_TIME,MODIFY_TIME FROM PROFESSOR");
161
			if (whereSql.length() > 0) {
162
				sql.append(whereSql);
163
			}
164
			sql.append(" ORDER BY ID");
165
			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(_m_10);
166
		}
167
		ps = con.prepareStatement(sql.toString());
168
		try {
169
			if (hasKey) {
170
				ps.setString(paramIndex++, key);
171
				ps.setString(paramIndex++, key);
172
				ps.setString(paramIndex++, key);
173
			}
174
			if (hasSubject) {
175
				ps.setString(paramIndex++, subject);
176
			}
177
			if (hasIndustry) {
178
				ps.setString(paramIndex++, industry);
179
			}
180
			java.sql.ResultSet rs = ps.executeQuery();
181
			try {
182
				java.util.List<com.ekexiu.portal.po.Professor> _m_11 = new java.util.ArrayList<com.ekexiu.portal.po.Professor>();
183
				_result.setData(_m_11);
184
				while (rs.next()) {
185
					com.ekexiu.portal.po.Professor _obj = new com.ekexiu.portal.po.Professor();
186
					java.lang.String _m_13 = rs.getString(1);
187
					if (rs.wasNull()) {
188
						_m_13 = null;
189
					}
190
					_obj.setOffice(_m_13);
191
					java.lang.String _m_14 = rs.getString(2);
192
					if (rs.wasNull()) {
193
						_m_14 = null;
194
					}
195
					_obj.setSubject(_m_14);
196
					java.lang.String _m_15 = rs.getString(3);
197
					if (rs.wasNull()) {
198
						_m_15 = null;
199
					}
200
					_obj.setIndustry(_m_15);
201
					_obj.setDepartment(rs.getString(4));
202
					_obj.setOrgId(rs.getString(5));
203
					_obj.setTitle(rs.getString(6));
204
					_obj.setAuthentication("1".equals(rs.getString(7)));
205
					_obj.setId(rs.getString(8));
206
					_obj.setName(rs.getString(9));
207
					java.lang.String _m_16 = rs.getString(10);
208
					if (rs.wasNull()) {
209
						_m_16 = null;
210
					}
211
					_obj.setDescp(_m_16);
212
					_obj.setCreateTime(rs.getString(11));
213
					_obj.setModifyTime(rs.getString(12));
214
					_m_11.add(_obj);
215
				}
216
				return _result;
217
			} finally {
218
				try {
219
					rs.close();
220
				} catch (Exception _m_17) {
221
				}
222
			}
223
		} finally {
224
			try {
225
				ps.close();
226
			} catch (Exception _m_18) {
227
			}
228
		}
229
	}
230
231
}
1
package com.ekexiu.portal.dao;
2

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

7
import org.jfw.apt.annotation.Nullable;
8
import org.jfw.apt.orm.annotation.dao.DAO;
9
import org.jfw.apt.orm.annotation.dao.method.From;
10
import org.jfw.apt.orm.annotation.dao.method.Or;
11
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
12
import org.jfw.apt.orm.annotation.dao.method.Select;
13
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
14
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
15
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
16
import org.jfw.apt.orm.annotation.dao.method.operator.QueryOne;
17
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
18
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
19
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
20
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
21
import org.jfw.apt.orm.annotation.dao.param.Set;
22
import org.jfw.apt.orm.annotation.dao.param.SqlColumn;
23
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
24
import org.jfw.util.PageQueryResult;
25

26
import com.ekexiu.portal.po.Professor;
27
import com.ekexiu.portal.pojo.ProfessorInfo;
28

29
@DAO
30
public abstract class ProfessorDao {
31

32
	@Insert
33
	public abstract int insert(Connection con, Professor professor) throws SQLException;
34

35
	@Update
36
	public abstract int update(Connection con, Professor professor) throws SQLException;
37

38
	@UpdateWith
39
	@From(Professor.class)
40
	public abstract int updateSubject(Connection con, String id, @Set String subject) throws SQLException;
41

42
	@UpdateWith
43
	@From(Professor.class)
44
	public abstract int updateDescp(Connection con, String id, @Set String descp) throws SQLException;
45

46
	@UpdateWith
47
	@From(Professor.class)
48
	public abstract int updateIndustry(Connection con, String id, @Set String industry) throws SQLException;
49

50
	@Nullable
51
	@SelectOne
52
	public abstract Professor query(Connection con, String id) throws SQLException;
53

54
	@SelectList
55
	public abstract List<Professor> query(Connection con) throws SQLException;
56

57
	@Nullable
58
	@QueryOne
59
	@From(Professor.class)
60
	@Select(Professor.class)
61
	public abstract ProfessorInfo queryInfo(Connection con, String id) throws SQLException;
62

63
	@DeleteWith
64
	@From(Professor.class)
65
	public abstract int delete(Connection con, String id) throws SQLException;
66

67
	@PageSelect
68
	@Or
69
	@OrderBy(" ORDER BY ID ")
70
	public abstract PageQueryResult<Professor> query(Connection con,
71
			@Nullable @SqlColumn(value = { "ID IN (SELECT PROFESSOR_ID FROM RESEARCH_AREA WHERE CAPTION LIKE ?)",
72
					"" + "ORG_ID IN(SELECT ID FROM ORGANIZATION WHERE NAME LIKE ?)", "NAME LIKE ?" }, handlerClass = StringHandler.class) String key,
73
			int pageSize, int pageNo) throws SQLException;
74

75
	public PageQueryResult<Professor> query(Connection con, @Nullable String key, String subject, String industry, int pageSize, int pageNo)
76
			throws SQLException {
77

78
		org.jfw.util.PageQueryResult<com.ekexiu.portal.po.Professor> _result = new org.jfw.util.PageQueryResult<com.ekexiu.portal.po.Professor>();
79

80
		StringBuilder sql = new StringBuilder();
81
		boolean hasKey = null != key;
82
		if (hasKey) {
83
			sql.append(
84
					" WHERE (( ID IN (SELECT PROFESSOR_ID FROM RESEARCH_AREA WHERE CAPTION LIKE ?)) OR (ORG_ID IN(SELECT ID FROM ORGANIZATION WHERE NAME LIKE ?)) OR ( NAME LIKE ?))");
85
		}
86
		boolean hasSubject = null != subject;
87
		boolean hasIndustry = null != industry;
88
		if (hasSubject) {
89
			sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(SUBJECT LIKE ?)");
90
		}
91
		if (hasIndustry) {
92
			sql.append(sql.length() > 0 ? " AND " : " WHERE ").append("(INDUSTRY LIKE ?)");
93
		}
94

95
		StringBuilder whereSql = sql;
96
		sql = new StringBuilder();
97
		sql.append("SELECT COUNT(1) FROM PROFESSOR");
98
		if (whereSql.length() > 0) {
99
			sql.append(whereSql);
100
		}
101
		java.sql.PreparedStatement ps = con.prepareStatement(sql.toString());
102
		int paramIndex = 1;
103
		int totalSize = 0;
104
		try {
105
			if (hasKey) {
106
				ps.setString(paramIndex++, key);
107
				ps.setString(paramIndex++, key);
108
				ps.setString(paramIndex++, key);
109
			}
110
			if (hasSubject) {
111
				ps.setString(paramIndex++, subject);
112
			}
113
			if (hasIndustry) {
114
				ps.setString(paramIndex++, industry);
115
			}
116
			_result.setPageSize(pageSize);
117
			java.sql.ResultSet _pageRs = ps.executeQuery();
118
			try {
119
				_pageRs.next();
120
				totalSize = _pageRs.getInt(1);
121
			} finally {
122
				try {
123
					_pageRs.close();
124
				} catch (Exception _m_6) {
125
				}
126
			}
127
		} finally {
128
			try {
129
				ps.close();
130
			} catch (Exception _m_7) {
131
			}
132
		}
133
		_result.setTotal(totalSize);
134
		if (0 == totalSize) {
135
			_result.setPageNo(1);
136
			_result.setData(java.util.Collections.<com.ekexiu.portal.po.Professor> emptyList());
137
			return _result;
138
		}
139
		paramIndex = 1;
140
		if (1 == pageNo) {
141
			_result.setPageNo(1);
142
			sql = new StringBuilder();
143
			sql.append("SELECT OFFICE,SUBJECT,INDUSTRY,DEPARTMENT,ORG_ID,TITLE,AUTHENTICATION,ID,NAME,DESCP,CREATE_TIME,MODIFY_TIME FROM PROFESSOR");
144
			if (whereSql.length() > 0) {
145
				sql.append(whereSql);
146
			}
147
			sql.append(" LIMIT ").append(pageSize);
148
		} else {
149
			int _pageSize = totalSize / pageSize;
150
			if (totalSize % pageSize != 0) {
151
				++_pageSize;
152
			}
153
			if (pageNo > _pageSize) {
154
				pageNo = _pageSize;
155
			}
156
			_result.setPageNo(pageNo);
157
			--pageNo;
158
			int _m_10 = (pageNo * pageSize);
159
			sql = new StringBuilder();
160
			sql.append("SELECT OFFICE,SUBJECT,INDUSTRY,DEPARTMENT,ORG_ID,TITLE,AUTHENTICATION,ID,NAME,DESCP,CREATE_TIME,MODIFY_TIME FROM PROFESSOR");
161
			if (whereSql.length() > 0) {
162
				sql.append(whereSql);
163
			}
164
			sql.append(" ORDER BY ID");
165
			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(_m_10);
166
		}
167
		ps = con.prepareStatement(sql.toString());
168
		try {
169
			if (hasKey) {
170
				ps.setString(paramIndex++, key);
171
				ps.setString(paramIndex++, key);
172
				ps.setString(paramIndex++, key);
173
			}
174
			if (hasSubject) {
175
				ps.setString(paramIndex++, subject);
176
			}
177
			if (hasIndustry) {
178
				ps.setString(paramIndex++, industry);
179
			}
180
			java.sql.ResultSet rs = ps.executeQuery();
181
			try {
182
				java.util.List<com.ekexiu.portal.po.Professor> _m_11 = new java.util.ArrayList<com.ekexiu.portal.po.Professor>();
183
				_result.setData(_m_11);
184
				while (rs.next()) {
185
					com.ekexiu.portal.po.Professor _obj = new com.ekexiu.portal.po.Professor();
186
					java.lang.String _m_13 = rs.getString(1);
187
					if (rs.wasNull()) {
188
						_m_13 = null;
189
					}
190
					_obj.setOffice(_m_13);
191
					java.lang.String _m_14 = rs.getString(2);
192
					if (rs.wasNull()) {
193
						_m_14 = null;
194
					}
195
					_obj.setSubject(_m_14);
196
					java.lang.String _m_15 = rs.getString(3);
197
					if (rs.wasNull()) {
198
						_m_15 = null;
199
					}
200
					_obj.setIndustry(_m_15);
201
					_obj.setDepartment(rs.getString(4));
202
					_obj.setOrgId(rs.getString(5));
203
					_obj.setTitle(rs.getString(6));
204
					_obj.setAuthentication("1".equals(rs.getString(7)));
205
					_obj.setId(rs.getString(8));
206
					_obj.setName(rs.getString(9));
207
					java.lang.String _m_16 = rs.getString(10);
208
					if (rs.wasNull()) {
209
						_m_16 = null;
210
					}
211
					_obj.setDescp(_m_16);
212
					_obj.setCreateTime(rs.getString(11));
213
					_obj.setModifyTime(rs.getString(12));
214
					_m_11.add(_obj);
215
				}
216
				return _result;
217
			} finally {
218
				try {
219
					rs.close();
220
				} catch (Exception _m_17) {
221
				}
222
			}
223
		} finally {
224
			try {
225
				ps.close();
226
			} catch (Exception _m_18) {
227
			}
228
		}
229
	}
230

231
}

+ 277 - 253
src/main/java/com/ekexiu/portal/service/ProfessorService.java

@ -1,253 +1,277 @@
1
package com.ekexiu.portal.service;
2
3
import java.io.IOException;
4
import java.sql.Connection;
5
import java.sql.SQLException;
6
import java.util.List;
7
8
import org.jfw.apt.annotation.Autowrie;
9
import org.jfw.apt.annotation.DefaultValue;
10
import org.jfw.apt.annotation.Nullable;
11
import org.jfw.apt.web.annotation.Path;
12
import org.jfw.apt.web.annotation.operate.Delete;
13
import org.jfw.apt.web.annotation.operate.Get;
14
import org.jfw.apt.web.annotation.operate.Post;
15
import org.jfw.apt.web.annotation.operate.Put;
16
import org.jfw.apt.web.annotation.param.JdbcConn;
17
import org.jfw.apt.web.annotation.param.PathVar;
18
import org.jfw.apt.web.annotation.param.RequestBody;
19
import org.jfw.util.PageQueryResult;
20
import org.jfw.util.StringUtil;
21
22
import com.ekexiu.portal.dao.HonorDao;
23
import com.ekexiu.portal.dao.OrgDao;
24
import com.ekexiu.portal.dao.PaperDao;
25
import com.ekexiu.portal.dao.PartTimeJobDao;
26
import com.ekexiu.portal.dao.PatentDao;
27
import com.ekexiu.portal.dao.ProfessorDao;
28
import com.ekexiu.portal.dao.ProfessorEduBgDao;
29
import com.ekexiu.portal.dao.ProjectDao;
30
import com.ekexiu.portal.dao.ResearchAreaDao;
31
import com.ekexiu.portal.dao.ResearchAreaLogDao;
32
import com.ekexiu.portal.po.Professor;
33
import com.ekexiu.portal.pojo.ProfessorInfo;
34
35
@Path("/professor")
36
public class ProfessorService {
37
	@Autowrie
38
	private ImageService imageService;
39
	@Autowrie
40
	private OrgService orgService;
41
	@Autowrie
42
	private PaperDao paperDao;
43
	@Autowrie
44
	private OrgDao orgDao;
45
	@Autowrie
46
	private ProfessorDao professorDao;
47
	@Autowrie
48
	private ResearchAreaLogDao researchAreaLogDao;
49
	@Autowrie
50
	private ResearchAreaDao researchAreaDao;
51
	@Autowrie
52
	private ProfessorEduBgDao professorEduBgDao;
53
	@Autowrie
54
	private PartTimeJobDao partTimeJobDao;
55
	@Autowrie
56
	private PatentDao patentDao;
57
	@Autowrie
58
	private HonorDao honorDao;
59
	@Autowrie
60
	private ProjectDao projectDao;
61
62
	
63
	
64
	
65
	public ImageService getImageService() {
66
		return imageService;
67
	}
68
69
	public void setImageService(ImageService imageService) {
70
		this.imageService = imageService;
71
	}
72
73
	public OrgService getOrgService() {
74
		return orgService;
75
	}
76
77
	public void setOrgService(OrgService orgService) {
78
		this.orgService = orgService;
79
	}
80
81
	public ProjectDao getProjectDao() {
82
		return projectDao;
83
	}
84
85
	public void setProjectDao(ProjectDao projectDao) {
86
		this.projectDao = projectDao;
87
	}
88
89
	public HonorDao getHonorDao() {
90
		return honorDao;
91
	}
92
93
	public void setHonorDao(HonorDao honorDao) {
94
		this.honorDao = honorDao;
95
	}
96
97
	public PatentDao getPatentDao() {
98
		return patentDao;
99
	}
100
101
	public void setPatentDao(PatentDao patentDao) {
102
		this.patentDao = patentDao;
103
	}
104
105
	public PartTimeJobDao getPartTimeJobDao() {
106
		return partTimeJobDao;
107
	}
108
109
	public void setPartTimeJobDao(PartTimeJobDao partTimeJobDao) {
110
		this.partTimeJobDao = partTimeJobDao;
111
	}
112
113
	public PaperDao getPaperDao() {
114
		return paperDao;
115
	}
116
117
	public void setPaperDao(PaperDao paperDao) {
118
		this.paperDao = paperDao;
119
	}
120
121
	public ProfessorEduBgDao getProfessorEduBgDao() {
122
		return professorEduBgDao;
123
	}
124
125
	public void setProfessorEduBgDao(ProfessorEduBgDao professorEduBgDao) {
126
		this.professorEduBgDao = professorEduBgDao;
127
	}
128
129
	public ResearchAreaLogDao getResearchAreaLogDao() {
130
		return researchAreaLogDao;
131
	}
132
133
	public void setResearchAreaLogDao(ResearchAreaLogDao researchAreaLogDao) {
134
		this.researchAreaLogDao = researchAreaLogDao;
135
	}
136
137
	public ResearchAreaDao getResearchAreaDao() {
138
		return researchAreaDao;
139
	}
140
141
	public void setResearchAreaDao(ResearchAreaDao researchAreaDao) {
142
		this.researchAreaDao = researchAreaDao;
143
	}
144
145
	public ProfessorDao getProfessorDao() {
146
		return professorDao;
147
	}
148
149
	public void setProfessorDao(ProfessorDao professorDao) {
150
		this.professorDao = professorDao;
151
	}
152
153
	public OrgDao getOrgDao() {
154
		return orgDao;
155
	}
156
157
	public void setOrgDao(OrgDao orgDao) {
158
		this.orgDao = orgDao;
159
	}
160
161
162
	
163
164
	@Post
165
	@Path
166
	public String insert(@JdbcConn(true) Connection con, Professor professor, @Nullable String orgName)
167
			throws SQLException, IOException {
168
		String id = StringUtil.buildUUID();
169
		professor.setId(id);
170
		professor.setAuthentication(true);
171
		if (professor.getOrgId() == null) {
172
			professor.setOrgId(this.orgService.createOrganization(con, orgName));
173
		}
174
		this.professorDao.insert(con, professor);
175
		this.imageService.saveDefaultHeadImage(id);
176
		return id;
177
	}
178
179
	@Put
180
	@Path
181
	public void update(@JdbcConn(true) Connection con, @RequestBody Professor professor) throws SQLException {
182
		this.professorDao.update(con, professor);
183
	}
184
185
	@Get
186
	@Path("/{id}")
187
	public Professor query(@JdbcConn Connection con, @PathVar String id) throws SQLException {
188
		return this.professorDao.query(con, id);
189
	}
190
	@Get
191
	@Path("/qa")
192
	public List<Professor> queryAll(@JdbcConn Connection con)throws SQLException
193
	{
194
		return this.professorDao.query(con);
195
	}
196
	
197
	@Post
198
	@Path("/subject")
199
	public void updateSubject(@JdbcConn(true) Connection con,String id, String subject) throws SQLException{
200
		this.professorDao.updateSubject(con, id, subject);
201
	}
202
	
203
	@Post
204
	@Path("/industry")
205
	public void updateIndustry(@JdbcConn(true) Connection con, String id, String industry) throws SQLException{
206
		this.professorDao.updateIndustry(con, id, industry);
207
	}
208
	@Post
209
	@Path("/descp")
210
	public void updateDescp(@JdbcConn(true) Connection con, String id, String descp) throws SQLException{
211
		this.professorDao.updateDescp(con, id, descp);
212
	}
213
	
214
215
	@Delete
216
	@Path("/{id}")
217
	public void delete(@JdbcConn(true) Connection con, @PathVar String id) throws SQLException {
218
		this.researchAreaLogDao.delete(con, id);
219
		this.researchAreaDao.delete(con, id);
220
		this.professorEduBgDao.delete(con, id);
221
		this.partTimeJobDao.delete(con, id);
222
		this.paperDao.delete(con, id);
223
		this.professorDao.delete(con, id);
224
		this.patentDao.delete(con, id);
225
		this.honorDao.delete(con, id);
226
		this.projectDao.delete(con, id);
227
	}
228
	@Get
229
	@Path("/pq")
230
	PageQueryResult<Professor> query(@JdbcConn(false) Connection con,@Nullable String key,@Nullable String subject,@Nullable String industry, @DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
231
		if(key!=null) key="%"+key+"%";
232
		return this.professorDao.query(con, key, subject, industry, pageSize, pageNo);
233
	}
234
	
235
	@Get
236
	@Path("/info/{id}")
237
	public ProfessorInfo qinfo(@JdbcConn(false) Connection con,@PathVar String id) throws SQLException{
238
		ProfessorInfo info = this.professorDao.queryInfo(con, id);
239
		if(info!=null){
240
			info.setOrgName(this.orgDao.query(con, info.getOrgId()).getName());
241
			info.setEdus(this.professorEduBgDao.query(con, id));
242
			info.setHonors(this.honorDao.query(con, id));
243
			info.setJobs(this.partTimeJobDao.query(con, id));
244
			info.setPapers(this.paperDao.query(con, id));
245
			info.setPatents(this.patentDao.query(con, id));
246
			info.setProjects(this.projectDao.query(con, id));
247
			info.setResearchAreaLogs(this.researchAreaLogDao.query(con, id));
248
			info.setResearchAreas(this.researchAreaDao.query(con, id));
249
		}
250
		return info;
251
		
252
	}
253
}
1
package com.ekexiu.portal.service;
2

3
import java.io.IOException;
4
import java.net.URLEncoder;
5
import java.sql.Connection;
6
import java.sql.SQLException;
7
import java.util.List;
8

9
import org.jfw.apt.annotation.Autowrie;
10
import org.jfw.apt.annotation.DefaultValue;
11
import org.jfw.apt.annotation.Nullable;
12
import org.jfw.apt.web.annotation.Path;
13
import org.jfw.apt.web.annotation.operate.Delete;
14
import org.jfw.apt.web.annotation.operate.Get;
15
import org.jfw.apt.web.annotation.operate.Post;
16
import org.jfw.apt.web.annotation.operate.Put;
17
import org.jfw.apt.web.annotation.param.JdbcConn;
18
import org.jfw.apt.web.annotation.param.PathVar;
19
import org.jfw.apt.web.annotation.param.RequestBody;
20
import org.jfw.util.PageQueryResult;
21
import org.jfw.util.StringUtil;
22

23
import com.ekexiu.portal.dao.HonorDao;
24
import com.ekexiu.portal.dao.OrgDao;
25
import com.ekexiu.portal.dao.PaperDao;
26
import com.ekexiu.portal.dao.PartTimeJobDao;
27
import com.ekexiu.portal.dao.PatentDao;
28
import com.ekexiu.portal.dao.ProfessorDao;
29
import com.ekexiu.portal.dao.ProfessorEduBgDao;
30
import com.ekexiu.portal.dao.ProjectDao;
31
import com.ekexiu.portal.dao.ResearchAreaDao;
32
import com.ekexiu.portal.dao.ResearchAreaLogDao;
33
import com.ekexiu.portal.po.Professor;
34
import com.ekexiu.portal.pojo.ProfessorInfo;
35

36
@Path("/professor")
37
public class ProfessorService {
38
	@Autowrie
39
	private ImageService imageService;
40
	@Autowrie
41
	private OrgService orgService;
42
	@Autowrie
43
	private PaperDao paperDao;
44
	@Autowrie
45
	private OrgDao orgDao;
46
	@Autowrie
47
	private ProfessorDao professorDao;
48
	@Autowrie
49
	private ResearchAreaLogDao researchAreaLogDao;
50
	@Autowrie
51
	private ResearchAreaDao researchAreaDao;
52
	@Autowrie
53
	private ProfessorEduBgDao professorEduBgDao;
54
	@Autowrie
55
	private PartTimeJobDao partTimeJobDao;
56
	@Autowrie
57
	private PatentDao patentDao;
58
	@Autowrie
59
	private HonorDao honorDao;
60
	@Autowrie
61
	private ProjectDao projectDao;
62

63
	
64
	
65
	
66
	public ImageService getImageService() {
67
		return imageService;
68
	}
69

70
	public void setImageService(ImageService imageService) {
71
		this.imageService = imageService;
72
	}
73

74
	public OrgService getOrgService() {
75
		return orgService;
76
	}
77

78
	public void setOrgService(OrgService orgService) {
79
		this.orgService = orgService;
80
	}
81

82
	public ProjectDao getProjectDao() {
83
		return projectDao;
84
	}
85

86
	public void setProjectDao(ProjectDao projectDao) {
87
		this.projectDao = projectDao;
88
	}
89

90
	public HonorDao getHonorDao() {
91
		return honorDao;
92
	}
93

94
	public void setHonorDao(HonorDao honorDao) {
95
		this.honorDao = honorDao;
96
	}
97

98
	public PatentDao getPatentDao() {
99
		return patentDao;
100
	}
101

102
	public void setPatentDao(PatentDao patentDao) {
103
		this.patentDao = patentDao;
104
	}
105

106
	public PartTimeJobDao getPartTimeJobDao() {
107
		return partTimeJobDao;
108
	}
109

110
	public void setPartTimeJobDao(PartTimeJobDao partTimeJobDao) {
111
		this.partTimeJobDao = partTimeJobDao;
112
	}
113

114
	public PaperDao getPaperDao() {
115
		return paperDao;
116
	}
117

118
	public void setPaperDao(PaperDao paperDao) {
119
		this.paperDao = paperDao;
120
	}
121

122
	public ProfessorEduBgDao getProfessorEduBgDao() {
123
		return professorEduBgDao;
124
	}
125

126
	public void setProfessorEduBgDao(ProfessorEduBgDao professorEduBgDao) {
127
		this.professorEduBgDao = professorEduBgDao;
128
	}
129

130
	public ResearchAreaLogDao getResearchAreaLogDao() {
131
		return researchAreaLogDao;
132
	}
133

134
	public void setResearchAreaLogDao(ResearchAreaLogDao researchAreaLogDao) {
135
		this.researchAreaLogDao = researchAreaLogDao;
136
	}
137

138
	public ResearchAreaDao getResearchAreaDao() {
139
		return researchAreaDao;
140
	}
141

142
	public void setResearchAreaDao(ResearchAreaDao researchAreaDao) {
143
		this.researchAreaDao = researchAreaDao;
144
	}
145

146
	public ProfessorDao getProfessorDao() {
147
		return professorDao;
148
	}
149

150
	public void setProfessorDao(ProfessorDao professorDao) {
151
		this.professorDao = professorDao;
152
	}
153

154
	public OrgDao getOrgDao() {
155
		return orgDao;
156
	}
157

158
	public void setOrgDao(OrgDao orgDao) {
159
		this.orgDao = orgDao;
160
	}
161

162

163
	
164

165
	@Post
166
	@Path
167
	public String insert(@JdbcConn(true) Connection con, Professor professor, @Nullable String orgName)
168
			throws SQLException, IOException {
169
		String id = StringUtil.buildUUID();
170
		professor.setId(id);
171
		professor.setAuthentication(true);
172
		if (professor.getOrgId() == null) {
173
			professor.setOrgId(this.orgService.createOrganization(con, orgName));
174
		}
175
		this.professorDao.insert(con, professor);
176
		this.imageService.saveDefaultHeadImage(id);
177
		return id;
178
	}
179

180
	@Put
181
	@Path
182
	public void update(@JdbcConn(true) Connection con, @RequestBody Professor professor) throws SQLException {
183
		this.professorDao.update(con, professor);
184
	}
185

186
	@Get
187
	@Path("/{id}")
188
	public Professor query(@JdbcConn Connection con, @PathVar String id) throws SQLException {
189
		return this.professorDao.query(con, id);
190
	}
191
	@Get
192
	@Path("/qa")
193
	public List<Professor> queryAll(@JdbcConn Connection con)throws SQLException
194
	{
195
		return this.professorDao.query(con);
196
	}
197
	
198
	@Post
199
	@Path("/subject")
200
	public void updateSubject(@JdbcConn(true) Connection con,String id, String subject) throws SQLException{
201
		this.professorDao.updateSubject(con, id, subject);
202
	}
203
	
204
	@Post
205
	@Path("/industry")
206
	public void updateIndustry(@JdbcConn(true) Connection con, String id, String industry) throws SQLException{
207
		this.professorDao.updateIndustry(con, id, industry);
208
	}
209
	@Post
210
	@Path("/descp")
211
	public void updateDescp(@JdbcConn(true) Connection con, String id, String descp) throws SQLException{
212
		this.professorDao.updateDescp(con, id, descp);
213
	}
214
	
215

216
	@Delete
217
	@Path("/{id}")
218
	public void delete(@JdbcConn(true) Connection con, @PathVar String id) throws SQLException {
219
		this.researchAreaLogDao.delete(con, id);
220
		this.researchAreaDao.delete(con, id);
221
		this.professorEduBgDao.delete(con, id);
222
		this.partTimeJobDao.delete(con, id);
223
		this.paperDao.delete(con, id);
224
		this.professorDao.delete(con, id);
225
		this.patentDao.delete(con, id);
226
		this.honorDao.delete(con, id);
227
		this.projectDao.delete(con, id);
228
	}
229
	@Get
230
	@Path("/pq")
231
	PageQueryResult<Professor> query(@JdbcConn(false) Connection con,@Nullable String key,@Nullable String subject,@Nullable String industry, @DefaultValue("10") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
232
	//	System.out.println("key==["+(key==null?"":key)+"]");
233
	//	System.out.println("subject==["+(subject==null?"":subject)+"]");
234
	//	System.out.println("industry==["+(industry==null?"":industry)+"]");
235
		if(key!=null) key="%"+key+"%";
236
		if(subject!=null) subject ="%"+subject+"%";
237
		if(null!=industry)industry="%"+industry+"%";
238
		return this.professorDao.query(con, key, subject, industry, pageSize, pageNo);
239
	}
240
	
241
	@Get
242
	@Path("/info/{id}")
243
	public ProfessorInfo qinfo(@JdbcConn(false) Connection con,@PathVar String id) throws SQLException{
244
		ProfessorInfo info = this.professorDao.queryInfo(con, id);
245
		if(info!=null){
246
			info.setOrgName(this.orgDao.query(con, info.getOrgId()).getName());
247
			info.setEdus(this.professorEduBgDao.query(con, id));
248
			info.setHonors(this.honorDao.query(con, id));
249
			info.setJobs(this.partTimeJobDao.query(con, id));
250
			info.setPapers(this.paperDao.query(con, id));
251
			info.setPatents(this.patentDao.query(con, id));
252
			info.setProjects(this.projectDao.query(con, id));
253
			info.setResearchAreaLogs(this.researchAreaLogDao.query(con, id));
254
			info.setResearchAreas(this.researchAreaDao.query(con, id));
255
		}
256
		return info;
257
		
258
	}
259
	
260
	public static void main(String[] args)throws Exception{
261
//		Connection con = DriverManager.getConnection("jdbc:postgresql://121.42.53.174:5432/ekexiu", "postgres",  "postgres");
262
//		try{
263
//		ProfessorService service = new ProfessorService();
264
//		ProfessorDao dao = new ProfessorDaoExtend();
265
//		service.setProfessorDao(dao);
266
//		PageQueryResult<Professor> result =service.query(con,"杨", "材料", "金属", 10, 2);
267
//		System.out.println(result.getTotal());
268
//		for(Professor p:result.getData()){
269
//			System.out.println("======");
270
//			JsonService.toJson(p,System.out);
271
//		}
272
//		}finally{
273
//			con.close();
274
//		}
275
		System.out.println(URLEncoder.encode("有", "UTF-8"));
276
	}
277
}