jiapeng 7 gadi atpakaļ
vecāks
revīzija
eb5649f9ff

+ 831 - 750
src/main/java/com/ekexiu/portal/dao/OperationDao.java

@ -10,15 +10,22 @@ import java.util.Collections;
10 10
import java.util.List;
11 11

12 12
import org.jfw.apt.annotation.Autowrie;
13
import org.jfw.apt.annotation.DefaultValue;
13 14
import org.jfw.apt.annotation.Nullable;
15
import org.jfw.apt.orm.annotation.dao.Column;
14 16
import org.jfw.apt.orm.annotation.dao.DAO;
15 17
import org.jfw.apt.orm.annotation.dao.method.From;
18
import org.jfw.apt.orm.annotation.dao.method.Where;
16 19
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
17 20
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
21
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
18 22
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
19 23
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
20 24
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
25
import org.jfw.apt.orm.annotation.dao.param.GroupSqlColumn;
21 26
import org.jfw.apt.orm.annotation.dao.param.Set;
27
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
28
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
22 29
import org.jfw.util.PageQueryResult;
23 30

24 31
import com.ekexiu.portal.po.Image;
@ -30,7 +37,7 @@ import com.ekexiu.portal.po.Resource;
30 37
public abstract class OperationDao {
31 38
	@Autowrie
32 39
	private ImageDao imageDao;
33
	
40

34 41
	public ImageDao getImageDao() {
35 42
		return imageDao;
36 43
	}
@ -41,833 +48,907 @@ public abstract class OperationDao {
41 48

42 49
	@Insert
43 50
	public abstract int insert(Connection con, Operation operation) throws SQLException;
44
	
51

45 52
	@Update
46 53
	public abstract int update(Connection con, Operation operation) throws SQLException;
47
	
54

48 55
	@UpdateWith
49 56
	@From(Operation.class)
50 57
	public abstract int updateDetailDemand(Connection con, String operationId, @Set String detailDemand) throws SQLException;
51
	
58

52 59
	@UpdateWith
53 60
	@From(Operation.class)
54 61
	public abstract int updateOperationStatus(Connection con, String operationId, @Set int operationStatus) throws SQLException;
55
	
62

56 63
	@UpdateWith
57 64
	@From(Operation.class)
58 65
	public abstract int updateDeliverTime(Connection con, String operationId, @Set String deliverTime) throws SQLException;
59
	
66

60 67
	@UpdateWith
61 68
	@From(Operation.class)
62 69
	public abstract int updateDealTime(Connection con, String operationId, @Set String dealTime) throws SQLException;
63
	
70

64 71
	@UpdateWith
65 72
	@From(Operation.class)
66 73
	public abstract int updatePayMethod(Connection con, String operationId, @Set String payMethod) throws SQLException;
67
	
74

68 75
	/**
69 76
	 * 查询有多少资源合作正在进行
77
	 * 
70 78
	 * @param con
71
	 * @param professorId 登陆者ID
79
	 * @param professorId
80
	 *            登陆者ID
72 81
	 * @return 返回正在合作的资源申请数量
73 82
	 * @throws SQLException
74 83
	 */
75
	public int queryOnGoingOper(Connection con, @Nullable String professorId) throws SQLException {
76
		String sql = " SELECT COUNT(1) FROM OPERATION O WHERE (OPERATION_STATUS IN (1,2,3,7)) "
77
				+ " AND (O.RESOURCE_ID IN (SELECT R.RESOURCE_ID FROM RESOURCE R WHERE R.PROFESSOR_ID = ?) "
78
				+ " OR O.DEMAND_ID = ?) ";
84
	@QueryVal
85
	@Column(value = "COUNT(1)", handlerClass = IntHandler.class)
86
	@From(Operation.class)
87
	@Where("OPERATION_STATUS IN (1,2,3,7)")
88
	@DefaultValue("0")
89
	public abstract int queryOnGoingOper(Connection con,
90
		@Nullable	 @GroupSqlColumn(value = { "RESOURCE_ID IN (SELECT R.RESOURCE_ID FROM RESOURCE R WHERE R.PROFESSOR_ID = ?)",
91
					"DEMAND_ID = ?" }, handlerClass = StringHandler.class, isAnd = false) String professorId)
92
			throws SQLException;
93

94

95
	public Operation query(Connection con, String operationId) throws SQLException {
96
		int index = 1;
97
		String sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,OPERATION_ID,OPERATION_STATUS,"
98
				+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
99
				+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME,APPLYSQUARE "
100
				+ " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID " + " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
101
				+ " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID " + " WHERE OPERATION_ID = ?";
79 102
		PreparedStatement ps = con.prepareStatement(sql);
80
		ps.setString(1, professorId);
81
		ps.setString(2, professorId);
82
		ResultSet rs = ps.executeQuery();
83
		rs.next();
84
		int count = rs.getInt(1);
85
		return count;
103
		try {
104
			ps.setString(index++, operationId);
105
			ResultSet rs = ps.executeQuery();
106
			try {
107
				if (rs.next()) {
108
					Operation operation = new Operation();
109
					operation.setReplyNotes(rs.getString(1));
110
					operation.setCreateTime(rs.getString(2));
111
					operation.setOperationId(rs.getString(3));
112
					operation.setOperationStatus(rs.getInt(4));
113
					Professor professor = new Professor();
114
					professor.setId(rs.getString(5));
115
					operation.setDetailDemand(rs.getString(6));
116
					operation.setDeliverTime(rs.getString(7));
117
					Resource resource = new Resource();
118
					resource.setResourceId(rs.getString(8));
119
					operation.setDealPrice(rs.getBigDecimal(9));
120
					operation.setDealTime(rs.getString(10));
121
					operation.setPayMethod(rs.getString(11));
122
					professor.setName(rs.getString(12));
123
					operation.setProfessor(professor);
124
					resource.setResourceName(rs.getString(13));
125
					Professor professor2 = new Professor();
126
					professor2.setId(rs.getString(14));
127
					professor2.setName(rs.getString(15));
128
					resource.setProfessor(professor2);
129
					operation.setResource(resource);
130
					operation.setApplysquare(rs.getString(16));
131
					return operation;
132
				} else {
133
					return null;
134
				}
135
			} finally {
136
				try {
137
					rs.close();
138
				} catch (Exception e1) {
139
				}
140
			}
141
		} finally {
142
			try {
143
				ps.close();
144
			} catch (Exception e2) {
145
			}
146
		}
86 147
	}
87
	
88
	public Operation query(Connection con,String operationId) throws SQLException{
89
        int index = 1;
90
        String sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,OPERATION_ID,OPERATION_STATUS,"
91
        		+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
92
        		+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME,APPLYSQUARE "
93
        		+ " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
94
        		+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
95
        		+ " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID "
96
        		+ " WHERE OPERATION_ID = ?";
97
        PreparedStatement ps = con.prepareStatement(sql);
98
        try{
99
            ps.setString(index++,operationId);
100
            ResultSet rs = ps.executeQuery();
101
            try{
102
                if(rs.next()){
103
                    Operation operation = new Operation();
104
                    operation.setReplyNotes(rs.getString(1));
105
                    operation.setCreateTime(rs.getString(2));
106
                    operation.setOperationId(rs.getString(3));
107
                    operation.setOperationStatus(rs.getInt(4));
108
                    Professor professor = new Professor();
109
                    professor.setId(rs.getString(5));
110
                    operation.setDetailDemand(rs.getString(6));
111
                    operation.setDeliverTime(rs.getString(7));
112
                    Resource resource = new Resource();
113
                    resource.setResourceId(rs.getString(8));
114
                    operation.setDealPrice(rs.getBigDecimal(9));
115
                    operation.setDealTime(rs.getString(10));
116
                    operation.setPayMethod(rs.getString(11));
117
                    professor.setName(rs.getString(12));
118
                    operation.setProfessor(professor);
119
                    resource.setResourceName(rs.getString(13));
120
                    Professor professor2 = new Professor();
121
                    professor2.setId(rs.getString(14));
122
                    professor2.setName(rs.getString(15));
123
                    resource.setProfessor(professor2);
124
                    operation.setResource(resource);
125
                    operation.setApplysquare(rs.getString(16));
126
                    return operation;
127
                }else{
128
                    return null;
129
                }
130
            }finally{
131
                try{rs.close();}catch(Exception e1){}
132
            }
133
        }finally{
134
            try{ps.close();}catch(Exception e2){}
135
        }
136
    }
137
	
138
	public List<Operation> query(Connection con) throws SQLException{
139
        String sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,OPERATION_ID,OPERATION_STATUS,"
140
        		+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
141
        		+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME,APPLYSQUARE "
142
        		+ " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
143
        		+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
144
        		+ " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID";
145
        PreparedStatement ps = con.prepareStatement(sql);
146
        try{
147
            ResultSet rs = ps.executeQuery();
148
            try{
149
                List<Operation> operations = new ArrayList<Operation>();
150
                while(rs.next()){
151
                    Operation operation =  new Operation();
152
                    operation.setReplyNotes(rs.getString(1));
153
                    operation.setCreateTime(rs.getString(2));
154
                    operation.setOperationId(rs.getString(3));
155
                    operation.setOperationStatus(rs.getInt(4));
156
                    Professor professor = new Professor();
157
                    professor.setId(rs.getString(5));
158
                    operation.setDetailDemand(rs.getString(6));
159
                    operation.setDeliverTime(rs.getString(7));
160
                    Resource resource = new Resource();
161
                    resource.setResourceId(rs.getString(8));
162
                    operation.setDealPrice(rs.getBigDecimal(9));
163
                    operation.setDealTime(rs.getString(10));
164
                    operation.setPayMethod(rs.getString(11));
165
                    professor.setName(rs.getString(12));
166
                    operation.setProfessor(professor);
167
                    resource.setResourceName(rs.getString(13));
168
                    Professor professor2 = new Professor();
169
                    professor2.setId(rs.getString(14));
170
                    professor2.setName(rs.getString(15));
171
                    resource.setProfessor(professor2);
172
                    operation.setResource(resource);
173
                    operation.setApplysquare(rs.getString(16));
174
                    operations.add(operation);
175
                }
176
                return operations;
177
            }finally{
178
                try{rs.close();}catch(Exception e1){}
179
            }
180
        }finally{
181
            try{ps.close();}catch(Exception e2){}
182
        }
183
    }
184
	
148

149
	public List<Operation> query(Connection con) throws SQLException {
150
		String sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,OPERATION_ID,OPERATION_STATUS,"
151
				+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
152
				+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME,APPLYSQUARE "
153
				+ " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID " + " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
154
				+ " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID";
155
		PreparedStatement ps = con.prepareStatement(sql);
156
		try {
157
			ResultSet rs = ps.executeQuery();
158
			try {
159
				List<Operation> operations = new ArrayList<Operation>();
160
				while (rs.next()) {
161
					Operation operation = new Operation();
162
					operation.setReplyNotes(rs.getString(1));
163
					operation.setCreateTime(rs.getString(2));
164
					operation.setOperationId(rs.getString(3));
165
					operation.setOperationStatus(rs.getInt(4));
166
					Professor professor = new Professor();
167
					professor.setId(rs.getString(5));
168
					operation.setDetailDemand(rs.getString(6));
169
					operation.setDeliverTime(rs.getString(7));
170
					Resource resource = new Resource();
171
					resource.setResourceId(rs.getString(8));
172
					operation.setDealPrice(rs.getBigDecimal(9));
173
					operation.setDealTime(rs.getString(10));
174
					operation.setPayMethod(rs.getString(11));
175
					professor.setName(rs.getString(12));
176
					operation.setProfessor(professor);
177
					resource.setResourceName(rs.getString(13));
178
					Professor professor2 = new Professor();
179
					professor2.setId(rs.getString(14));
180
					professor2.setName(rs.getString(15));
181
					resource.setProfessor(professor2);
182
					operation.setResource(resource);
183
					operation.setApplysquare(rs.getString(16));
184
					operations.add(operation);
185
				}
186
				return operations;
187
			} finally {
188
				try {
189
					rs.close();
190
				} catch (Exception e1) {
191
				}
192
			}
193
		} finally {
194
			try {
195
				ps.close();
196
			} catch (Exception e2) {
197
			}
198
		}
199
	}
200

185 201
	/**
186 202
	 * 搜索当前用户的所有资源申请(包括申请别人和别人申请自己的)
203
	 * 
187 204
	 * @param con
188
	 * @param id 登录用户ID
205
	 * @param id
206
	 *            登录用户ID
189 207
	 * @param pageSize
190 208
	 * @param pageNo
191 209
	 * @return 返回所有资源申请记录(包括申请别人和别人申请自己的)
192 210
	 * @throws SQLException
193 211
	 */
194
	public PageQueryResult<Operation> queryPro(Connection con, @Nullable String id,int pageSize,int pageNo) throws SQLException{
195
        int total = 0;
196
        PageQueryResult<Operation> queryResult = new PageQueryResult<Operation>();
197
        int index = 1;
198
        boolean hasId = null != id;
199
        StringBuilder sql = new StringBuilder();
200
        if(hasId){
201
            sql.append(" WHERE O.RESOURCE_ID IN (SELECT R.RESOURCE_ID FROM RESOURCE R WHERE R.PROFESSOR_ID = ?) OR (O.DEMAND_ID = ?) ");
202
        }
203
        StringBuilder whereSql = sql;
204
        sql = new StringBuilder();
205
        sql.append(" SELECT COUNT(1) FROM OPERATION O ");
206
        if(whereSql.length()>0){
207
            sql.append(whereSql);
208
        }
209
        PreparedStatement ps = con.prepareStatement(sql.toString());
210
        try{
211
            if(hasId){
212
                ps.setString(index++,id);
213
                ps.setString(index++,id);
214
            }
215
            queryResult.setPageSize(pageSize);
216
            ResultSet rs = ps.executeQuery();
217
            try{
218
                rs.next();
219
                total = rs.getInt(1);
220
            }finally{
221
                try{rs.close();}catch(Exception e1){}
222
            }
223
        }finally{
224
            try{ps.close();}catch(Exception e2){}
225
        }
226
        queryResult.setTotal(total);
227
        if(0== total){
228
        	queryResult.setPageNo(1);
229
        	queryResult.setData(Collections.<Operation>emptyList());
230
            return queryResult;
231
        }
232
        index = 1;
233
        boolean firstPage = (1 == pageNo);
234
        if(firstPage){
235
        	queryResult.setPageNo(1);
236
            sql = new StringBuilder();
237
            sql.append("SELECT REPLY_NOTES,APPLYSQUARE,OPERATION_ID,OPERATION_STATUS,DEMAND_ID,"
238
            		+ " DETAIL_DEMAND,DELIVER_TIME,O.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,PAY_METHOD,"
239
            		+ " O.CREATE_TIME,R.RESOURCE_NAME,SUPPORTED_SERVICES,R.DESCP,R.PROFESSOR_ID,P1.NAME,P2.NAME "
240
            		+ " FROM OPERATION O LEFT JOIN RESOURCE R ON O.RESOURCE_ID = R.RESOURCE_ID "
241
            		+ " LEFT JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
242
            		+ " LEFT JOIN PROFESSOR P2 ON R.PROFESSOR_ID = P2.ID");
243
            if(whereSql.length()>0){
244
                sql.append(whereSql);
245
            }
246
            sql.append(" ORDER BY O.CREATE_TIME DESC ");
247
            sql.append(" LIMIT ").append(pageSize);
248
        }else{
249
            int pageNum = total / pageSize;
250
            if(total % pageSize != 0){
251
                ++pageNum;
252
            }
253
            if(pageNo > pageNum){
254
                pageNo = pageNum;
255
            }
256
            queryResult.setPageNo(pageNo);
257
            --pageNo;
258
            int offset = (pageNo * pageSize);
259
            sql = new StringBuilder();
260
            sql.append("SELECT REPLY_NOTES,APPLYSQUARE,OPERATION_ID,OPERATION_STATUS,DEMAND_ID,"
261
            		+ " DETAIL_DEMAND,DELIVER_TIME,O.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,PAY_METHOD,"
262
            		+ " O.CREATE_TIME,R.RESOURCE_NAME,SUPPORTED_SERVICES,R.DESCP,R.PROFESSOR_ID,P1.NAME,P2.NAME "
263
            		+ " FROM OPERATION O LEFT JOIN RESOURCE R ON O.RESOURCE_ID = R.RESOURCE_ID "
264
            		+ " LEFT JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
265
            		+ " LEFT JOIN PROFESSOR P2 ON R.PROFESSOR_ID = P2.ID");
266
            if(whereSql.length()>0){
267
                sql.append(whereSql);
268
            }
269
            sql.append(" ORDER BY O.CREATE_TIME DESC ");
270
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
271
        }
272
        ps = con.prepareStatement(sql.toString());
273
        try{
274
            if(hasId){
275
                ps.setString(index++,id);
276
                ps.setString(index++,id);
277
            }
278
            ResultSet rs = ps.executeQuery();
279
            try{
280
                List<Operation> operations = new ArrayList<Operation>();
281
                queryResult.setData(operations);
282
                int size = 0;
283
                while((size<pageSize) && rs.next()){
284
                    ++size;
285
                    Operation operation =  new Operation();
286
                    String replyNotes = rs.getString(1);
287
                    if(rs.wasNull()){
288
                    	replyNotes = null;
289
                    }
290
                    operation.setReplyNotes(replyNotes);
291
                    String applysqare = rs.getString(2);
292
                    if(rs.wasNull()){
293
                    	applysqare = null;
294
                    }
295
                    operation.setApplysquare(applysqare);
296
                    operation.setOperationId(rs.getString(3));
297
                    operation.setOperationStatus(rs.getInt(4));
298
                    Professor professor = new Professor();
299
                    professor.setId(rs.getString(5));
300
                    operation.setDetailDemand(rs.getString(6));
301
                    operation.setDeliverTime(rs.getString(7));
302
                    Resource resource = new Resource();
303
                    resource.setResourceId(rs.getString(8));
304
                    BigDecimal dealPrice = rs.getBigDecimal(9);
305
                    if(rs.wasNull()){
306
                    	dealPrice = null;
307
                    }
308
                    operation.setDealPrice(dealPrice);
309
                    String dealTime = rs.getString(10);
310
                    if(rs.wasNull()){
311
                    	dealTime = null;
312
                    }
313
                    operation.setDealTime(dealTime);
314
                    String payMethod = rs.getString(11);
315
                    if(rs.wasNull()){
316
                    	payMethod = null;
317
                    }
318
                    operation.setPayMethod(payMethod);
319
                    operation.setCreateTime(rs.getString(12));
320
                    resource.setResourceName(rs.getString(13));
321
                    resource.setSupportedServices(rs.getString(14));
322
                    resource.setDescp(rs.getString(15));
323
                    List<Image> images = this.imageDao.queryRes(con, resource.getResourceId());
324
                    resource.setImages(images);
325
                    Professor professor2 = new Professor();
326
                    professor2.setId(rs.getString(16));
327
                    professor.setName(rs.getString(17));
328
                    operation.setProfessor(professor);
329
                    professor2.setName(rs.getString(18));
330
                    resource.setProfessor(professor2);
331
                    operation.setResource(resource);
332
                    operations.add(operation);
333
                }
334
                return queryResult;
335
            }finally{
336
                try{rs.close();}catch(Exception e3){}
337
            }
338
        }finally{
339
            try{ps.close();}catch(Exception e4){}
340
        }
341
    }
342
	
212
	public PageQueryResult<Operation> queryPro(Connection con, @Nullable String id, int pageSize, int pageNo) throws SQLException {
213
		int total = 0;
214
		PageQueryResult<Operation> queryResult = new PageQueryResult<Operation>();
215
		int index = 1;
216
		boolean hasId = null != id;
217
		StringBuilder sql = new StringBuilder();
218
		if (hasId) {
219
			sql.append(" WHERE O.RESOURCE_ID IN (SELECT R.RESOURCE_ID FROM RESOURCE R WHERE R.PROFESSOR_ID = ?) OR (O.DEMAND_ID = ?) ");
220
		}
221
		StringBuilder whereSql = sql;
222
		sql = new StringBuilder();
223
		sql.append(" SELECT COUNT(1) FROM OPERATION O ");
224
		if (whereSql.length() > 0) {
225
			sql.append(whereSql);
226
		}
227
		PreparedStatement ps = con.prepareStatement(sql.toString());
228
		try {
229
			if (hasId) {
230
				ps.setString(index++, id);
231
				ps.setString(index++, id);
232
			}
233
			queryResult.setPageSize(pageSize);
234
			ResultSet rs = ps.executeQuery();
235
			try {
236
				rs.next();
237
				total = rs.getInt(1);
238
			} finally {
239
				try {
240
					rs.close();
241
				} catch (Exception e1) {
242
				}
243
			}
244
		} finally {
245
			try {
246
				ps.close();
247
			} catch (Exception e2) {
248
			}
249
		}
250
		queryResult.setTotal(total);
251
		if (0 == total) {
252
			queryResult.setPageNo(1);
253
			queryResult.setData(Collections.<Operation> emptyList());
254
			return queryResult;
255
		}
256
		index = 1;
257
		boolean firstPage = (1 == pageNo);
258
		if (firstPage) {
259
			queryResult.setPageNo(1);
260
			sql = new StringBuilder();
261
			sql.append("SELECT REPLY_NOTES,APPLYSQUARE,OPERATION_ID,OPERATION_STATUS,DEMAND_ID,"
262
					+ " DETAIL_DEMAND,DELIVER_TIME,O.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,PAY_METHOD,"
263
					+ " O.CREATE_TIME,R.RESOURCE_NAME,SUPPORTED_SERVICES,R.DESCP,R.PROFESSOR_ID,P1.NAME,P2.NAME "
264
					+ " FROM OPERATION O LEFT JOIN RESOURCE R ON O.RESOURCE_ID = R.RESOURCE_ID " + " LEFT JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
265
					+ " LEFT JOIN PROFESSOR P2 ON R.PROFESSOR_ID = P2.ID");
266
			if (whereSql.length() > 0) {
267
				sql.append(whereSql);
268
			}
269
			sql.append(" ORDER BY O.CREATE_TIME DESC ");
270
			sql.append(" LIMIT ").append(pageSize);
271
		} else {
272
			int pageNum = total / pageSize;
273
			if (total % pageSize != 0) {
274
				++pageNum;
275
			}
276
			if (pageNo > pageNum) {
277
				pageNo = pageNum;
278
			}
279
			queryResult.setPageNo(pageNo);
280
			--pageNo;
281
			int offset = (pageNo * pageSize);
282
			sql = new StringBuilder();
283
			sql.append("SELECT REPLY_NOTES,APPLYSQUARE,OPERATION_ID,OPERATION_STATUS,DEMAND_ID,"
284
					+ " DETAIL_DEMAND,DELIVER_TIME,O.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,PAY_METHOD,"
285
					+ " O.CREATE_TIME,R.RESOURCE_NAME,SUPPORTED_SERVICES,R.DESCP,R.PROFESSOR_ID,P1.NAME,P2.NAME "
286
					+ " FROM OPERATION O LEFT JOIN RESOURCE R ON O.RESOURCE_ID = R.RESOURCE_ID " + " LEFT JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
287
					+ " LEFT JOIN PROFESSOR P2 ON R.PROFESSOR_ID = P2.ID");
288
			if (whereSql.length() > 0) {
289
				sql.append(whereSql);
290
			}
291
			sql.append(" ORDER BY O.CREATE_TIME DESC ");
292
			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
293
		}
294
		ps = con.prepareStatement(sql.toString());
295
		try {
296
			if (hasId) {
297
				ps.setString(index++, id);
298
				ps.setString(index++, id);
299
			}
300
			ResultSet rs = ps.executeQuery();
301
			try {
302
				List<Operation> operations = new ArrayList<Operation>();
303
				queryResult.setData(operations);
304
				int size = 0;
305
				while ((size < pageSize) && rs.next()) {
306
					++size;
307
					Operation operation = new Operation();
308
					String replyNotes = rs.getString(1);
309
					if (rs.wasNull()) {
310
						replyNotes = null;
311
					}
312
					operation.setReplyNotes(replyNotes);
313
					String applysqare = rs.getString(2);
314
					if (rs.wasNull()) {
315
						applysqare = null;
316
					}
317
					operation.setApplysquare(applysqare);
318
					operation.setOperationId(rs.getString(3));
319
					operation.setOperationStatus(rs.getInt(4));
320
					Professor professor = new Professor();
321
					professor.setId(rs.getString(5));
322
					operation.setDetailDemand(rs.getString(6));
323
					operation.setDeliverTime(rs.getString(7));
324
					Resource resource = new Resource();
325
					resource.setResourceId(rs.getString(8));
326
					BigDecimal dealPrice = rs.getBigDecimal(9);
327
					if (rs.wasNull()) {
328
						dealPrice = null;
329
					}
330
					operation.setDealPrice(dealPrice);
331
					String dealTime = rs.getString(10);
332
					if (rs.wasNull()) {
333
						dealTime = null;
334
					}
335
					operation.setDealTime(dealTime);
336
					String payMethod = rs.getString(11);
337
					if (rs.wasNull()) {
338
						payMethod = null;
339
					}
340
					operation.setPayMethod(payMethod);
341
					operation.setCreateTime(rs.getString(12));
342
					resource.setResourceName(rs.getString(13));
343
					resource.setSupportedServices(rs.getString(14));
344
					resource.setDescp(rs.getString(15));
345
					List<Image> images = this.imageDao.queryRes(con, resource.getResourceId());
346
					resource.setImages(images);
347
					Professor professor2 = new Professor();
348
					professor2.setId(rs.getString(16));
349
					professor.setName(rs.getString(17));
350
					operation.setProfessor(professor);
351
					professor2.setName(rs.getString(18));
352
					resource.setProfessor(professor2);
353
					operation.setResource(resource);
354
					operations.add(operation);
355
				}
356
				return queryResult;
357
			} finally {
358
				try {
359
					rs.close();
360
				} catch (Exception e3) {
361
				}
362
			}
363
		} finally {
364
			try {
365
				ps.close();
366
			} catch (Exception e4) {
367
			}
368
		}
369
	}
370

343 371
	/**
344 372
	 * 分页按资源申请者ID查资源申请
373
	 * 
345 374
	 * @param con
346
	 * @param demandId 资源申请者ID
347
	 * @param pageSize 每页记录数
348
	 * @param pageNo 当前页码
375
	 * @param demandId
376
	 *            资源申请者ID
377
	 * @param pageSize
378
	 *            每页记录数
379
	 * @param pageNo
380
	 *            当前页码
349 381
	 * @return 返回该用户ID申请的所有资源
350 382
	 * @throws SQLException
351 383
	 */
352
	public PageQueryResult<Operation> queryDemPage(Connection con,String demandId,int pageSize,int pageNo) throws SQLException{
353
        int total = 0;
354
        PageQueryResult<Operation> queryResult = new PageQueryResult<Operation>();
355
        int index = 1;
356
        String sql = null;
357
        sql = "  WHERE OPERATION.DEMAND_ID = ?        ";
358
        String whereSql = sql;
359
        sql = "SELECT COUNT(1) FROM OPERATION";
360
        sql = sql + whereSql;
361
        PreparedStatement ps = con.prepareStatement(sql);
362
        try{
363
            ps.setString(index++,demandId);
364
            queryResult.setPageSize(pageSize);
365
            ResultSet rs = ps.executeQuery();
366
            try{
367
                rs.next();
368
                total = rs.getInt(1);
369
            }finally{
370
                try{rs.close();}catch(Exception e1){}
371
            }
372
        }finally{
373
            try{ps.close();}catch(Exception e2){}
374
        }
375
        queryResult.setTotal(total);
376
        if(0== total){
377
        	queryResult.setPageNo(1);
378
        	queryResult.setData(Collections.<Operation>emptyList());
379
            return queryResult;
380
        }
381
        index = 1;
382
        boolean firstPage = (1 == pageNo);
383
        if(firstPage){
384
        	queryResult.setPageNo(1);
385
            sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,APPLYSQUARE,OPERATION_ID,OPERATION_STATUS,"
386
            		+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
387
            		+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME "
388
            		+ " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
389
            		+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
390
            		+ " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID";
391
            sql = sql + whereSql;
392
            sql = sql + "ORDER BY OPERATION.CREATE_TIME DESC";
393
            sql = sql + " LIMIT " + pageSize;
394
        }else{
395
            int pageNum = total / pageSize;
396
            if(total % pageSize != 0){
397
                ++pageNum;
398
            }
399
            if(pageNo > pageNum){
400
                pageNo = pageNum;
401
            }
402
            queryResult.setPageNo(pageNo);
403
            --pageNo;
404
            int offset = (pageNo * pageSize);
405
            sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,APPLYSQUARE,OPERATION_ID,OPERATION_STATUS,"
406
            		+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
407
            		+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME "
408
            		+ " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
409
            		+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
410
            		+ " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID";
411
            sql = sql + whereSql;
412
            sql = sql + "ORDER BY OPERATION.CREATE_TIME DESC";
413
            sql = sql + " LIMIT " + pageSize+ " OFFSET "+ offset;
414
        }
415
        ps = con.prepareStatement(sql);
416
        try{
417
            ps.setString(index++,demandId);
418
            ResultSet rs = ps.executeQuery();
419
            try{
420
                List<Operation> operations = new ArrayList<Operation>();
421
                queryResult.setData(operations);
422
                int size = 0;
423
                while((size<pageSize) && rs.next()){
424
                    ++size;
425
                    Operation operation =  new Operation();
426
                    String replyNotes = rs.getString(1);
427
                    if(rs.wasNull()){
428
                    	replyNotes = null;
429
                    }
430
                    operation.setReplyNotes(replyNotes);
431
                    operation.setCreateTime(rs.getString(2));
432
                    String applysquare = rs.getString(3);
433
                    if(rs.wasNull()){
434
                    	applysquare = null;
435
                    }
436
                    operation.setApplysquare(applysquare);
437
                    operation.setOperationId(rs.getString(4));
438
                    operation.setOperationStatus(rs.getInt(5));
439
                    Professor professor = new Professor();
440
                    professor.setId(rs.getString(6));
441
                    operation.setDetailDemand(rs.getString(7));
442
                    operation.setDeliverTime(rs.getString(8));
443
                    Resource resource = new Resource();
384
	public PageQueryResult<Operation> queryDemPage(Connection con, String demandId, int pageSize, int pageNo) throws SQLException {
385
		int total = 0;
386
		PageQueryResult<Operation> queryResult = new PageQueryResult<Operation>();
387
		int index = 1;
388
		String sql = null;
389
		sql = "  WHERE OPERATION.DEMAND_ID = ?        ";
390
		String whereSql = sql;
391
		sql = "SELECT COUNT(1) FROM OPERATION";
392
		sql = sql + whereSql;
393
		PreparedStatement ps = con.prepareStatement(sql);
394
		try {
395
			ps.setString(index++, demandId);
396
			queryResult.setPageSize(pageSize);
397
			ResultSet rs = ps.executeQuery();
398
			try {
399
				rs.next();
400
				total = rs.getInt(1);
401
			} finally {
402
				try {
403
					rs.close();
404
				} catch (Exception e1) {
405
				}
406
			}
407
		} finally {
408
			try {
409
				ps.close();
410
			} catch (Exception e2) {
411
			}
412
		}
413
		queryResult.setTotal(total);
414
		if (0 == total) {
415
			queryResult.setPageNo(1);
416
			queryResult.setData(Collections.<Operation> emptyList());
417
			return queryResult;
418
		}
419
		index = 1;
420
		boolean firstPage = (1 == pageNo);
421
		if (firstPage) {
422
			queryResult.setPageNo(1);
423
			sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,APPLYSQUARE,OPERATION_ID,OPERATION_STATUS,"
424
					+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
425
					+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME " + " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
426
					+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID " + " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID";
427
			sql = sql + whereSql;
428
			sql = sql + "ORDER BY OPERATION.CREATE_TIME DESC";
429
			sql = sql + " LIMIT " + pageSize;
430
		} else {
431
			int pageNum = total / pageSize;
432
			if (total % pageSize != 0) {
433
				++pageNum;
434
			}
435
			if (pageNo > pageNum) {
436
				pageNo = pageNum;
437
			}
438
			queryResult.setPageNo(pageNo);
439
			--pageNo;
440
			int offset = (pageNo * pageSize);
441
			sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,APPLYSQUARE,OPERATION_ID,OPERATION_STATUS,"
442
					+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
443
					+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME " + " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
444
					+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID " + " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID";
445
			sql = sql + whereSql;
446
			sql = sql + "ORDER BY OPERATION.CREATE_TIME DESC";
447
			sql = sql + " LIMIT " + pageSize + " OFFSET " + offset;
448
		}
449
		ps = con.prepareStatement(sql);
450
		try {
451
			ps.setString(index++, demandId);
452
			ResultSet rs = ps.executeQuery();
453
			try {
454
				List<Operation> operations = new ArrayList<Operation>();
455
				queryResult.setData(operations);
456
				int size = 0;
457
				while ((size < pageSize) && rs.next()) {
458
					++size;
459
					Operation operation = new Operation();
460
					String replyNotes = rs.getString(1);
461
					if (rs.wasNull()) {
462
						replyNotes = null;
463
					}
464
					operation.setReplyNotes(replyNotes);
465
					operation.setCreateTime(rs.getString(2));
466
					String applysquare = rs.getString(3);
467
					if (rs.wasNull()) {
468
						applysquare = null;
469
					}
470
					operation.setApplysquare(applysquare);
471
					operation.setOperationId(rs.getString(4));
472
					operation.setOperationStatus(rs.getInt(5));
473
					Professor professor = new Professor();
474
					professor.setId(rs.getString(6));
475
					operation.setDetailDemand(rs.getString(7));
476
					operation.setDeliverTime(rs.getString(8));
477
					Resource resource = new Resource();
444 478
					resource.setResourceId(rs.getString(9));
445
                    BigDecimal dealPrice = rs.getBigDecimal(10);
446
                    if(rs.wasNull()){
447
                    	dealPrice = null;
448
                    }
449
                    operation.setDealPrice(dealPrice);
450
                    String dealTime = rs.getString(11);
451
                    if(rs.wasNull()){
452
                    	dealTime = null;
453
                    }
454
                    operation.setDealTime(dealTime);
455
                    String payMethod = rs.getString(12);
456
                    if(rs.wasNull()){
457
                    	payMethod = null;
458
                    }
459
                    operation.setPayMethod(payMethod);
460
                    professor.setName(rs.getString(13));
461
                    operation.setProfessor(professor);
479
					BigDecimal dealPrice = rs.getBigDecimal(10);
480
					if (rs.wasNull()) {
481
						dealPrice = null;
482
					}
483
					operation.setDealPrice(dealPrice);
484
					String dealTime = rs.getString(11);
485
					if (rs.wasNull()) {
486
						dealTime = null;
487
					}
488
					operation.setDealTime(dealTime);
489
					String payMethod = rs.getString(12);
490
					if (rs.wasNull()) {
491
						payMethod = null;
492
					}
493
					operation.setPayMethod(payMethod);
494
					professor.setName(rs.getString(13));
495
					operation.setProfessor(professor);
462 496
					resource.setResourceName(rs.getString(14));
463 497
					Professor professor2 = new Professor();
464
                    professor2.setId(rs.getString(15));
465
                    professor2.setName(rs.getString(16));
466
                    resource.setProfessor(professor2);
498
					professor2.setId(rs.getString(15));
499
					professor2.setName(rs.getString(16));
500
					resource.setProfessor(professor2);
467 501
					operation.setResource(resource);
468 502
					operations.add(operation);
469
                }
470
                return queryResult;
471
            }finally{
472
                try{rs.close();}catch(Exception e3){}
473
            }
474
        }finally{
475
            try{ps.close();}catch(Exception e4){}
476
        }
477
    }
478
	
503
				}
504
				return queryResult;
505
			} finally {
506
				try {
507
					rs.close();
508
				} catch (Exception e3) {
509
				}
510
			}
511
		} finally {
512
			try {
513
				ps.close();
514
			} catch (Exception e4) {
515
			}
516
		}
517
	}
518

479 519
	/**
480 520
	 * 分页按资源ID查资源申请,返回资申请人姓名和资源名称
521
	 * 
481 522
	 * @param con
482
	 * @param resourceId 资源ID
483
	 * @param pageSize 每页记录数
484
	 * @param pageNo 当前页码
523
	 * @param resourceId
524
	 *            资源ID
525
	 * @param pageSize
526
	 *            每页记录数
527
	 * @param pageNo
528
	 *            当前页码
485 529
	 * @return 返回当前资源ID下的所有资源申请记录
486 530
	 * @throws SQLException
487 531
	 */
488
	public PageQueryResult<Operation> queryResPage(Connection con,String resourceId,int pageSize,int pageNo) throws SQLException{
489
        int total = 0;
490
        PageQueryResult<Operation> queryResult = new PageQueryResult<Operation>();
491
        int index = 1;
492
        String sql = null;
493
        sql = " WHERE OPERATION.RESOURCE_ID = ? ";
494
        String whereSql = sql;
495
        sql = "SELECT COUNT(1) FROM OPERATION";
496
        sql = sql + whereSql;
497
        PreparedStatement ps = con.prepareStatement(sql);
498
        try{
499
            ps.setString(index++,resourceId);
500
            queryResult.setPageSize(pageSize);
501
            ResultSet rs = ps.executeQuery();
502
            try{
503
                rs.next();
504
                total = rs.getInt(1);
505
            }finally{
506
                try{rs.close();}catch(Exception e1){}
507
            }
508
        }finally{
509
            try{ps.close();}catch(Exception e2){}
510
        }
511
        queryResult.setTotal(total);
512
        if(0== total){
513
        	queryResult.setPageNo(1);
514
        	queryResult.setData(Collections.<Operation>emptyList());
515
            return queryResult;
516
        }
517
        index = 1;
518
        boolean firstPage = (1 == pageNo);
519
        if(firstPage){
520
        	queryResult.setPageNo(1);
521
            sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,APPLYSQUARE,OPERATION.OPERATION_ID,OPERATION_STATUS,"
522
            		+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
523
            		+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME "
524
            		+ " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
525
            		+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
526
            		+ " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID ";
527
            sql = sql + whereSql;
528
            sql = sql + "ORDER BY OPERATION.CREATE_TIME DESC";
529
            sql = sql + " LIMIT " + pageSize;
530
        }else{
531
            int pageNum = total / pageSize;
532
            if(total % pageSize != 0){
533
                ++pageNum;
534
            }
535
            if(pageNo > pageNum){
536
                pageNo = pageNum;
537
            }
538
            queryResult.setPageNo(pageNo);
539
            --pageNo;
540
            int offset = (pageNo * pageSize);
541
            sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,APPLYSQUARE,OPERATION.OPERATION_ID,OPERATION_STATUS,"
542
            		+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
543
            		+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME "
544
            		+ " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
545
            		+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
546
            		+ " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID";
547
            sql = sql + whereSql;
548
            sql = sql + "ORDER BY OPERATION.CREATE_TIME DESC";
549
            sql = sql + " LIMIT " + pageSize+ " OFFSET "+ offset;
550
        }
551
        ps = con.prepareStatement(sql);
552
        try{
553
            ps.setString(index++,resourceId);
554
            ResultSet rs = ps.executeQuery();
555
            try{
556
                List<Operation> operations = new ArrayList<Operation>();
557
                queryResult.setData(operations);
558
                int size = 0;
559
                while((size<pageSize) && rs.next()){
560
                    ++size;
561
                    Operation operation =  new Operation();
562
                    String replyNotes = rs.getString(1);
563
                    if(rs.wasNull()){
564
                    	replyNotes = null;
565
                    }
566
                    operation.setReplyNotes(replyNotes);
567
                    operation.setCreateTime(rs.getString(2));
568
                    String applyaquare = rs.getString(3);
569
                    if(rs.wasNull()){
570
                    	applyaquare = null;
571
                    }
572
                    operation.setApplysquare(applyaquare);
573
                    operation.setOperationId(rs.getString(4));
574
                    operation.setOperationStatus(rs.getInt(5));
575
                    Professor professor = new Professor();
576
                    professor.setId(rs.getString(6));
577
                    operation.setDetailDemand(rs.getString(7));
578
                    operation.setDeliverTime(rs.getString(8));
579
                    Resource resource = new Resource();
532
	public PageQueryResult<Operation> queryResPage(Connection con, String resourceId, int pageSize, int pageNo) throws SQLException {
533
		int total = 0;
534
		PageQueryResult<Operation> queryResult = new PageQueryResult<Operation>();
535
		int index = 1;
536
		String sql = null;
537
		sql = " WHERE OPERATION.RESOURCE_ID = ? ";
538
		String whereSql = sql;
539
		sql = "SELECT COUNT(1) FROM OPERATION";
540
		sql = sql + whereSql;
541
		PreparedStatement ps = con.prepareStatement(sql);
542
		try {
543
			ps.setString(index++, resourceId);
544
			queryResult.setPageSize(pageSize);
545
			ResultSet rs = ps.executeQuery();
546
			try {
547
				rs.next();
548
				total = rs.getInt(1);
549
			} finally {
550
				try {
551
					rs.close();
552
				} catch (Exception e1) {
553
				}
554
			}
555
		} finally {
556
			try {
557
				ps.close();
558
			} catch (Exception e2) {
559
			}
560
		}
561
		queryResult.setTotal(total);
562
		if (0 == total) {
563
			queryResult.setPageNo(1);
564
			queryResult.setData(Collections.<Operation> emptyList());
565
			return queryResult;
566
		}
567
		index = 1;
568
		boolean firstPage = (1 == pageNo);
569
		if (firstPage) {
570
			queryResult.setPageNo(1);
571
			sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,APPLYSQUARE,OPERATION.OPERATION_ID,OPERATION_STATUS,"
572
					+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
573
					+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME " + " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
574
					+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID " + " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID ";
575
			sql = sql + whereSql;
576
			sql = sql + "ORDER BY OPERATION.CREATE_TIME DESC";
577
			sql = sql + " LIMIT " + pageSize;
578
		} else {
579
			int pageNum = total / pageSize;
580
			if (total % pageSize != 0) {
581
				++pageNum;
582
			}
583
			if (pageNo > pageNum) {
584
				pageNo = pageNum;
585
			}
586
			queryResult.setPageNo(pageNo);
587
			--pageNo;
588
			int offset = (pageNo * pageSize);
589
			sql = "SELECT REPLY_NOTES,OPERATION.CREATE_TIME,APPLYSQUARE,OPERATION.OPERATION_ID,OPERATION_STATUS,"
590
					+ " DEMAND_ID,DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,"
591
					+ " PAY_METHOD,P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME " + " FROM OPERATION INNER JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
592
					+ " INNER JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID " + " INNER JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID";
593
			sql = sql + whereSql;
594
			sql = sql + "ORDER BY OPERATION.CREATE_TIME DESC";
595
			sql = sql + " LIMIT " + pageSize + " OFFSET " + offset;
596
		}
597
		ps = con.prepareStatement(sql);
598
		try {
599
			ps.setString(index++, resourceId);
600
			ResultSet rs = ps.executeQuery();
601
			try {
602
				List<Operation> operations = new ArrayList<Operation>();
603
				queryResult.setData(operations);
604
				int size = 0;
605
				while ((size < pageSize) && rs.next()) {
606
					++size;
607
					Operation operation = new Operation();
608
					String replyNotes = rs.getString(1);
609
					if (rs.wasNull()) {
610
						replyNotes = null;
611
					}
612
					operation.setReplyNotes(replyNotes);
613
					operation.setCreateTime(rs.getString(2));
614
					String applyaquare = rs.getString(3);
615
					if (rs.wasNull()) {
616
						applyaquare = null;
617
					}
618
					operation.setApplysquare(applyaquare);
619
					operation.setOperationId(rs.getString(4));
620
					operation.setOperationStatus(rs.getInt(5));
621
					Professor professor = new Professor();
622
					professor.setId(rs.getString(6));
623
					operation.setDetailDemand(rs.getString(7));
624
					operation.setDeliverTime(rs.getString(8));
625
					Resource resource = new Resource();
580 626
					resource.setResourceId(rs.getString(9));
581
                    BigDecimal dealPrice = rs.getBigDecimal(10);
582
                    if(rs.wasNull()){
583
                    	dealPrice = null;
584
                    }
585
                    operation.setDealPrice(dealPrice);
586
                    String dealTime = rs.getString(11);
587
                    if(rs.wasNull()){
588
                    	dealTime = null;
589
                    }
590
                    operation.setDealTime(dealTime);
591
                    String payMethod = rs.getString(12);
592
                    if(rs.wasNull()){
593
                    	payMethod = null;
594
                    }
595
                    operation.setPayMethod(payMethod);
596
                    professor.setName(rs.getString(13));
597
                    operation.setProfessor(professor);
627
					BigDecimal dealPrice = rs.getBigDecimal(10);
628
					if (rs.wasNull()) {
629
						dealPrice = null;
630
					}
631
					operation.setDealPrice(dealPrice);
632
					String dealTime = rs.getString(11);
633
					if (rs.wasNull()) {
634
						dealTime = null;
635
					}
636
					operation.setDealTime(dealTime);
637
					String payMethod = rs.getString(12);
638
					if (rs.wasNull()) {
639
						payMethod = null;
640
					}
641
					operation.setPayMethod(payMethod);
642
					professor.setName(rs.getString(13));
643
					operation.setProfessor(professor);
598 644
					resource.setResourceName(rs.getString(14));
599 645
					Professor professor2 = new Professor();
600
                    professor2.setId(rs.getString(15));
601
                    professor2.setName(rs.getString(16));
602
                    resource.setProfessor(professor2);
646
					professor2.setId(rs.getString(15));
647
					professor2.setName(rs.getString(16));
648
					resource.setProfessor(professor2);
603 649
					operation.setResource(resource);
604 650
					operations.add(operation);
605
                }
606
                return queryResult;
607
            }finally{
608
                try{rs.close();}catch(Exception e3){}
609
            }
610
        }finally{
611
            try{ps.close();}catch(Exception e4){}
612
        }
613
    }
614
	
651
				}
652
				return queryResult;
653
			} finally {
654
				try {
655
					rs.close();
656
				} catch (Exception e3) {
657
				}
658
			}
659
		} finally {
660
			try {
661
				ps.close();
662
			} catch (Exception e4) {
663
			}
664
		}
665
	}
666

615 667
	@SelectList
616 668
	public abstract List<Operation> queryResourceId(Connection con, String resourceId) throws SQLException;
617
	
669

618 670
	@DeleteWith
619 671
	@From(Operation.class)
620 672
	public abstract int delete(Connection con, String operationId) throws SQLException;
621
	
673

622 674
	/**
623 675
	 * 获取当前资源申请的状态值。
676
	 * 
624 677
	 * @param con
625
	 * @param operationId 资源申请ID
678
	 * @param operationId
679
	 *            资源申请ID
626 680
	 * @return 返回资源申请状态值
627 681
	 * @throws SQLException
628 682
	 */
629
	public int queryOper(Connection con, String operationId) throws SQLException{
683
	public int queryOper(Connection con, String operationId) throws SQLException {
630 684
		String sql = "SELECT OPERATION_STATUS FROM OPERATION WHERE OPERATION_ID = ?";
631 685
		PreparedStatement ps = con.prepareStatement(sql);
632 686
		try {
633 687
			ps.setString(1, operationId);
634 688
			ResultSet rs = ps.executeQuery();
635
			try{
689
			try {
636 690
				rs.next();
637 691
				return rs.getInt(1);
638
			}finally{
639
                try{rs.close();}catch(Exception e1){}
640
            }
641
		}finally{
642
            try{ps.close();}catch(Exception e2){}
643
        }
692
			} finally {
693
				try {
694
					rs.close();
695
				} catch (Exception e1) {
696
				}
697
			}
698
		} finally {
699
			try {
700
				ps.close();
701
			} catch (Exception e2) {
702
			}
703
		}
704
	}
705

706
	public int deleteDem(Connection con, String operationId, String demandId) throws SQLException {
707
		int index = 1;
708
		String sql = "DELETE FROM OPERATION WHERE OPERATION_STATUS = 1 AND DEMAND_ID = ? AND OPERATION_ID = ?";
709
		PreparedStatement ps = con.prepareStatement(sql);
710
		try {
711
			ps.setString(index++, demandId);
712
			ps.setString(index++, operationId);
713
			return ps.executeUpdate();
714
		} finally {
715
			try {
716
				ps.close();
717
			} catch (Exception e) {
718
			}
719
		}
644 720
	}
645
	
646
	public int deleteDem(Connection con,String operationId,String demandId) throws SQLException{
647
        int index = 1;
648
        String sql = "DELETE FROM OPERATION WHERE OPERATION_STATUS = 1 AND DEMAND_ID = ? AND OPERATION_ID = ?";
649
        PreparedStatement ps = con.prepareStatement(sql);
650
        try{
651
            ps.setString(index++,demandId);
652
            ps.setString(index++,operationId);
653
            return ps.executeUpdate();
654
        }finally{
655
            try{ps.close();}catch(Exception e){}
656
        }
657
    }
658
	
721

659 722
	/**
660 723
	 * 分页查询资源申请 多条件模糊查询
724
	 * 
661 725
	 * @param con
662
	 * @param professorName 申请人姓名
663
	 * @param resourceName 资源名称
664
	 * @param firstTime 申请时间 查询初试时间
665
	 * @param lastTime 申请时间 查询结束时间
666
	 * @param lowPrice 成交价格 查询较低价格
667
	 * @param highPrice 成交时间 查询较高价格
668
	 * @param pageSize 每页记录数
669
	 * @param pageNo 当前页码
726
	 * @param professorName
727
	 *            申请人姓名
728
	 * @param resourceName
729
	 *            资源名称
730
	 * @param firstTime
731
	 *            申请时间 查询初试时间
732
	 * @param lastTime
733
	 *            申请时间 查询结束时间
734
	 * @param lowPrice
735
	 *            成交价格 查询较低价格
736
	 * @param highPrice
737
	 *            成交时间 查询较高价格
738
	 * @param pageSize
739
	 *            每页记录数
740
	 * @param pageNo
741
	 *            当前页码
670 742
	 * @return
671 743
	 * @throws SQLException
672 744
	 */
673
	public PageQueryResult<Operation> queryPage(Connection con,String professorName,String resourceName,String firstTime,String lastTime,java.math.BigDecimal lowPrice,java.math.BigDecimal highPrice,int pageSize,int pageNo) throws SQLException{
674
        int total = 0;
675
        PageQueryResult<Operation> queryResult = new PageQueryResult<Operation>();
676
        int index = 1;
677
        boolean hasProName = null != professorName;
678
        boolean hasResName = null != resourceName;
679
        boolean hasFirstTime = null != firstTime;
680
        boolean hasLastTime = null != lastTime;
681
        boolean hasLowPrice = null != lowPrice;
682
        boolean hasHighPrice = null != highPrice;
683
        StringBuilder sql = new StringBuilder();
684
        boolean hasWhere = true;
685
        if(hasProName){
686
        	hasWhere =  false;
687
            sql.append(" WHERE DEMAND_ID (SELECT PROFESSOR.PROFESSOR.ID FROM PROFESSOR WHERE PROFESSOR.NAME LIKE ?)");
688
        }
689
        if(hasResName){
690
            if(hasWhere){
691
            	hasWhere =  false;
692
                sql.append(" WHERE OPERATION.RESOURCE_ID IN (SELECT RESOURCE.RESOURCE_ID FROM RESOURCE WHERE RESOURCE_NAME LIKE ?)");
693
            }else{
694
                sql.append(" OR OPERATION.RESOURCE_ID IN (SELECT RESOURCE.RESOURCE_ID FROM RESOURCE WHERE RESOURCE_NAME LIKE ?)");
695
            }
696
        }
697
        if(hasFirstTime){
698
            if(hasWhere){
699
            	hasWhere =  false;
700
                sql.append(" WHERE OPERATION.CREATE_TIME > ?");
701
            }else{
702
                sql.append(" AND OPERATION.CREATE_TIME > ?");
703
            }
704
        }
705
        if(hasLastTime){
706
            if(hasWhere){
707
            	hasWhere =  false;
708
                sql.append(" WHERE OPERATION.CREATE_TIME <= ?");
709
            }else{
710
                sql.append(" AND OPERATION.CREATE_TIME <= ?");
711
            }
712
        }
713
        if(hasLowPrice){
714
            if(hasWhere){
715
            	hasWhere =  false;
716
                sql.append(" WHERE DEAL_PRICE > ?");
717
            }else{
718
                sql.append(" AND DEAL_PRICE > ?");
719
            }
720
        }
721
        if(hasHighPrice){
722
            if(hasWhere){
723
            	hasWhere =  false;
724
                sql.append(" WHERE DEAL_PRICE <= ?");
725
            }else{
726
                sql.append(" AND DEAL_PRICE <= ?");
727
            }
728
        }
729
        StringBuilder whereSql = sql;
730
        sql = new StringBuilder();
731
        sql.append("SELECT COUNT(1) FROM OPERATION");
732
        if(whereSql.length()>0){
733
            sql.append(whereSql);
734
        }
735
        PreparedStatement ps = con.prepareStatement(sql.toString());
736
        try{
737
            if(hasProName){
738
                ps.setString(index++,professorName);
739
            }
740
            if(hasResName){
741
                ps.setString(index++,resourceName);
742
            }
743
            if(hasFirstTime){
744
                ps.setString(index++,firstTime);
745
            }
746
            if(hasLastTime){
747
                ps.setString(index++,lastTime);
748
            }
749
            if(hasLowPrice){
750
                ps.setBigDecimal(index++,lowPrice);
751
            }
752
            if(hasHighPrice){
753
                ps.setBigDecimal(index++,highPrice);
754
            }
755
            queryResult.setPageSize(pageSize);
756
            ResultSet rs = ps.executeQuery();
757
            try{
758
                rs.next();
759
                total = rs.getInt(1);
760
            }finally{
761
                try{rs.close();}catch(Exception e1){}
762
            }
763
        }finally{
764
            try{ps.close();}catch(Exception e2){}
765
        }
766
        queryResult.setTotal(total);
767
        if(0== total){
768
        	queryResult.setPageNo(1);
769
        	queryResult.setData(Collections.<Operation>emptyList());
770
            return queryResult;
771
        }
772
        index = 1;
773
        boolean firstPage = (1 == pageNo);
774
        if(firstPage){
775
        	queryResult.setPageNo(1);
776
            sql = new StringBuilder();
777
            sql.append("SELECT REPLY_NOTES,OPERATION.CREATE_TIME,OPERATION_ID,OPERATION_STATUS,DEMAND_ID,"
778
            		+ " DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,PAY_METHOD,"
779
            		+ " P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME,APPLYSQUARE "
780
            		+ " FROM OPERATION LEFT JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
781
            		+ " LEFT JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
782
            		+ " LEFT JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID");
783
            if(whereSql.length()>0){
784
                sql.append(whereSql);
785
            }
786
            sql.append(" ORDER BY OPERATION.CREATE_TIME");
787
            sql.append(" LIMIT ").append(pageSize);
788
        }else{
789
            int pageNum = total / pageSize;
790
            if(total % pageSize != 0){
791
                ++pageNum;
792
            }
793
            if(pageNo > pageNum){
794
                pageNo = pageNum;
795
            }
796
            queryResult.setPageNo(pageNo);
797
            --pageNo;
798
            int offset = (pageNo * pageSize);
799
            sql = new StringBuilder();
800
            sql.append("SELECT REPLY_NOTES,OPERATION.CREATE_TIME,OPERATION_ID,OPERATION_STATUS,DEMAND_ID,"
801
            		+ " DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,PAY_METHOD,"
802
            		+ " P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME,APPLYSQUARE "
803
            		+ " FROM OPERATION LEFT JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
804
            		+ " LEFT JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID "
805
            		+ " LEFT JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID");
806
            if(whereSql.length()>0){
807
                sql.append(whereSql);
808
            }
809
            sql.append(" ORDER BY OPERATION.CREATE_TIME");
810
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
811
        }
812
        ps = con.prepareStatement(sql.toString());
813
        try{
814
            if(hasProName){
815
                ps.setString(index++,professorName);
816
            }
817
            if(hasResName){
818
                ps.setString(index++,resourceName);
819
            }
820
            if(hasFirstTime){
821
                ps.setString(index++,firstTime);
822
            }
823
            if(hasLastTime){
824
                ps.setString(index++,lastTime);
825
            }
826
            if(hasLowPrice){
827
                ps.setBigDecimal(index++,lowPrice);
828
            }
829
            if(hasHighPrice){
830
                ps.setBigDecimal(index++,highPrice);
831
            }
832
            ResultSet rs = ps.executeQuery();
833
            try{
834
                List<Operation> operations = new ArrayList<Operation>();
835
                queryResult.setData(operations);
836
                int size = 0;
837
                while((size<pageSize) && rs.next()){
838
                    ++size;
839
                    Operation operation =  new Operation();
840
                    operation.setReplyNotes(rs.getString(1));
841
                    operation.setCreateTime(rs.getString(2));
842
                    operation.setOperationId(rs.getString(3));
843
                    operation.setOperationStatus(rs.getInt(4));
844
                    Professor professor = new Professor();
845
                    professor.setId(rs.getString(5));
846
                    operation.setDetailDemand(rs.getString(6));
847
                    operation.setDeliverTime(rs.getString(7));
848
                    Resource resource = new Resource();
849
                    resource.setResourceId(rs.getString(8));
850
                    operation.setDealPrice(rs.getBigDecimal(9));
851
                    operation.setDealTime(rs.getString(10));
852
                    operation.setPayMethod(rs.getString(11));
853
                    professor.setName(rs.getString(12));
854
                    operation.setProfessor(professor);
855
                    resource.setResourceName(rs.getString(13));
856
                    Professor professor2 = new Professor();
857
                    professor2.setId(rs.getString(14));
858
                    professor2.setName(rs.getString(15));
859
                    resource.setProfessor(professor2);
860
                    operation.setResource(resource);
861
                    operation.setApplysquare(rs.getString(16));
862
                    operations.add(operation);
863
                }
864
                return queryResult;
865
            }finally{
866
                try{rs.close();}catch(Exception e3){}
867
            }
868
        }finally{
869
            try{ps.close();}catch(Exception e4){}
870
        }
871
    }
872
	
745
	public PageQueryResult<Operation> queryPage(Connection con, String professorName, String resourceName, String firstTime, String lastTime,
746
			java.math.BigDecimal lowPrice, java.math.BigDecimal highPrice, int pageSize, int pageNo) throws SQLException {
747
		int total = 0;
748
		PageQueryResult<Operation> queryResult = new PageQueryResult<Operation>();
749
		int index = 1;
750
		boolean hasProName = null != professorName;
751
		boolean hasResName = null != resourceName;
752
		boolean hasFirstTime = null != firstTime;
753
		boolean hasLastTime = null != lastTime;
754
		boolean hasLowPrice = null != lowPrice;
755
		boolean hasHighPrice = null != highPrice;
756
		StringBuilder sql = new StringBuilder();
757
		boolean hasWhere = true;
758
		if (hasProName) {
759
			hasWhere = false;
760
			sql.append(" WHERE DEMAND_ID (SELECT PROFESSOR.PROFESSOR.ID FROM PROFESSOR WHERE PROFESSOR.NAME LIKE ?)");
761
		}
762
		if (hasResName) {
763
			if (hasWhere) {
764
				hasWhere = false;
765
				sql.append(" WHERE OPERATION.RESOURCE_ID IN (SELECT RESOURCE.RESOURCE_ID FROM RESOURCE WHERE RESOURCE_NAME LIKE ?)");
766
			} else {
767
				sql.append(" OR OPERATION.RESOURCE_ID IN (SELECT RESOURCE.RESOURCE_ID FROM RESOURCE WHERE RESOURCE_NAME LIKE ?)");
768
			}
769
		}
770
		if (hasFirstTime) {
771
			if (hasWhere) {
772
				hasWhere = false;
773
				sql.append(" WHERE OPERATION.CREATE_TIME > ?");
774
			} else {
775
				sql.append(" AND OPERATION.CREATE_TIME > ?");
776
			}
777
		}
778
		if (hasLastTime) {
779
			if (hasWhere) {
780
				hasWhere = false;
781
				sql.append(" WHERE OPERATION.CREATE_TIME <= ?");
782
			} else {
783
				sql.append(" AND OPERATION.CREATE_TIME <= ?");
784
			}
785
		}
786
		if (hasLowPrice) {
787
			if (hasWhere) {
788
				hasWhere = false;
789
				sql.append(" WHERE DEAL_PRICE > ?");
790
			} else {
791
				sql.append(" AND DEAL_PRICE > ?");
792
			}
793
		}
794
		if (hasHighPrice) {
795
			if (hasWhere) {
796
				hasWhere = false;
797
				sql.append(" WHERE DEAL_PRICE <= ?");
798
			} else {
799
				sql.append(" AND DEAL_PRICE <= ?");
800
			}
801
		}
802
		StringBuilder whereSql = sql;
803
		sql = new StringBuilder();
804
		sql.append("SELECT COUNT(1) FROM OPERATION");
805
		if (whereSql.length() > 0) {
806
			sql.append(whereSql);
807
		}
808
		PreparedStatement ps = con.prepareStatement(sql.toString());
809
		try {
810
			if (hasProName) {
811
				ps.setString(index++, professorName);
812
			}
813
			if (hasResName) {
814
				ps.setString(index++, resourceName);
815
			}
816
			if (hasFirstTime) {
817
				ps.setString(index++, firstTime);
818
			}
819
			if (hasLastTime) {
820
				ps.setString(index++, lastTime);
821
			}
822
			if (hasLowPrice) {
823
				ps.setBigDecimal(index++, lowPrice);
824
			}
825
			if (hasHighPrice) {
826
				ps.setBigDecimal(index++, highPrice);
827
			}
828
			queryResult.setPageSize(pageSize);
829
			ResultSet rs = ps.executeQuery();
830
			try {
831
				rs.next();
832
				total = rs.getInt(1);
833
			} finally {
834
				try {
835
					rs.close();
836
				} catch (Exception e1) {
837
				}
838
			}
839
		} finally {
840
			try {
841
				ps.close();
842
			} catch (Exception e2) {
843
			}
844
		}
845
		queryResult.setTotal(total);
846
		if (0 == total) {
847
			queryResult.setPageNo(1);
848
			queryResult.setData(Collections.<Operation> emptyList());
849
			return queryResult;
850
		}
851
		index = 1;
852
		boolean firstPage = (1 == pageNo);
853
		if (firstPage) {
854
			queryResult.setPageNo(1);
855
			sql = new StringBuilder();
856
			sql.append("SELECT REPLY_NOTES,OPERATION.CREATE_TIME,OPERATION_ID,OPERATION_STATUS,DEMAND_ID,"
857
					+ " DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,PAY_METHOD,"
858
					+ " P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME,APPLYSQUARE " + " FROM OPERATION LEFT JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
859
					+ " LEFT JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID " + " LEFT JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID");
860
			if (whereSql.length() > 0) {
861
				sql.append(whereSql);
862
			}
863
			sql.append(" ORDER BY OPERATION.CREATE_TIME");
864
			sql.append(" LIMIT ").append(pageSize);
865
		} else {
866
			int pageNum = total / pageSize;
867
			if (total % pageSize != 0) {
868
				++pageNum;
869
			}
870
			if (pageNo > pageNum) {
871
				pageNo = pageNum;
872
			}
873
			queryResult.setPageNo(pageNo);
874
			--pageNo;
875
			int offset = (pageNo * pageSize);
876
			sql = new StringBuilder();
877
			sql.append("SELECT REPLY_NOTES,OPERATION.CREATE_TIME,OPERATION_ID,OPERATION_STATUS,DEMAND_ID,"
878
					+ " DETAIL_DEMAND,DELIVER_TIME,OPERATION.RESOURCE_ID,DEAL_PRICE,DEAL_TIME,PAY_METHOD,"
879
					+ " P1.NAME,RESOURCE_NAME,RESOURCE.PROFESSOR_ID,P2.NAME,APPLYSQUARE " + " FROM OPERATION LEFT JOIN PROFESSOR P1 ON DEMAND_ID = P1.ID "
880
					+ " LEFT JOIN RESOURCE ON OPERATION.RESOURCE_ID = RESOURCE.RESOURCE_ID " + " LEFT JOIN PROFESSOR P2 ON RESOURCE.PROFESSOR_ID = P2.ID");
881
			if (whereSql.length() > 0) {
882
				sql.append(whereSql);
883
			}
884
			sql.append(" ORDER BY OPERATION.CREATE_TIME");
885
			sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
886
		}
887
		ps = con.prepareStatement(sql.toString());
888
		try {
889
			if (hasProName) {
890
				ps.setString(index++, professorName);
891
			}
892
			if (hasResName) {
893
				ps.setString(index++, resourceName);
894
			}
895
			if (hasFirstTime) {
896
				ps.setString(index++, firstTime);
897
			}
898
			if (hasLastTime) {
899
				ps.setString(index++, lastTime);
900
			}
901
			if (hasLowPrice) {
902
				ps.setBigDecimal(index++, lowPrice);
903
			}
904
			if (hasHighPrice) {
905
				ps.setBigDecimal(index++, highPrice);
906
			}
907
			ResultSet rs = ps.executeQuery();
908
			try {
909
				List<Operation> operations = new ArrayList<Operation>();
910
				queryResult.setData(operations);
911
				int size = 0;
912
				while ((size < pageSize) && rs.next()) {
913
					++size;
914
					Operation operation = new Operation();
915
					operation.setReplyNotes(rs.getString(1));
916
					operation.setCreateTime(rs.getString(2));
917
					operation.setOperationId(rs.getString(3));
918
					operation.setOperationStatus(rs.getInt(4));
919
					Professor professor = new Professor();
920
					professor.setId(rs.getString(5));
921
					operation.setDetailDemand(rs.getString(6));
922
					operation.setDeliverTime(rs.getString(7));
923
					Resource resource = new Resource();
924
					resource.setResourceId(rs.getString(8));
925
					operation.setDealPrice(rs.getBigDecimal(9));
926
					operation.setDealTime(rs.getString(10));
927
					operation.setPayMethod(rs.getString(11));
928
					professor.setName(rs.getString(12));
929
					operation.setProfessor(professor);
930
					resource.setResourceName(rs.getString(13));
931
					Professor professor2 = new Professor();
932
					professor2.setId(rs.getString(14));
933
					professor2.setName(rs.getString(15));
934
					resource.setProfessor(professor2);
935
					operation.setResource(resource);
936
					operation.setApplysquare(rs.getString(16));
937
					operations.add(operation);
938
				}
939
				return queryResult;
940
			} finally {
941
				try {
942
					rs.close();
943
				} catch (Exception e3) {
944
				}
945
			}
946
		} finally {
947
			try {
948
				ps.close();
949
			} catch (Exception e4) {
950
			}
951
		}
952
	}
953

873 954
}

+ 36 - 204
src/main/java/com/ekexiu/portal/dao/OrgDao.java

@ -28,6 +28,7 @@ import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
28 28
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
29 29
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
30 30
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
31
import org.jfw.apt.orm.annotation.dao.param.GroupSqlColumn;
31 32
import org.jfw.apt.orm.annotation.dao.param.In;
32 33
import org.jfw.apt.orm.annotation.dao.param.Like;
33 34
import org.jfw.apt.orm.annotation.dao.param.Set;
@ -217,194 +218,18 @@ public abstract class OrgDao {
217 218
					"(ID IN (SELECT ORG_ID FROM RESOURCE WHERE RESOURCE_TYPE='2' AND RESOURCE_NAME LIKE ?) AND IS_JOIN ='1')",
218 219
					"(ID IN (SELECT ORG_ID FROM ARTICLE WHERE ARTICLE_TYPE='2' AND ARTICLE_TITLE LIKE ?) AND IS_JOIN ='1')" }) String kw,
219 220
			int pageSize, int pageNo) throws SQLException;
220
	
221
	
222
	public PageQueryResult<EditOrganization> queryByKwAndIndustryAndAddr(Connection con,String kw,String industry,String addr,int pageSize,int pageNo)throws SQLException{
223
		  int _m_1 = 0;
224
	        org.jfw.util.PageQueryResult<com.ekexiu.portal.pojo.EditOrganization> _result = new org.jfw.util.PageQueryResult<com.ekexiu.portal.pojo.EditOrganization>();
225
	        int _m_2 = 1;
226
	        String sql = null;
227
	        sql = "  WHERE INDUSTRY LIKE ? AND ADDR LIKE ? AND ((ID IN (SELECT ORG_ID FROM ARTICLE WHERE ARTICLE_TYPE='2' AND ARTICLE_TITLE LIKE ?) AND IS_JOIN ='1') OR (ID IN (SELECT ORG_ID FROM RESOURCE WHERE RESOURCE_TYPE='2' AND RESOURCE_NAME LIKE ?) AND IS_JOIN ='1') OR (industry LIKE ?  AND IS_JOIN ='1') OR (SUBJECT LIKE ? AND IS_JOIN ='1') OR (DESCP LIKE ?  AND IS_JOIN ='1') OR (FOR_SHORT LIKE ? AND IS_JOIN ='1') OR (NAME LIKE ? AND IS_JOIN ='1'))";
228
	        String _m_3 = sql;
229
	        sql = "SELECT COUNT(1) FROM ORGANIZATION";
230
	        sql = sql + _m_3;
231
	        java.sql.PreparedStatement ps = con.prepareStatement(sql);
232
	        try{
233
	            ps.setString(_m_2++,industry);	
234
	            ps.setString(_m_2++,addr);	        	
235
	            ps.setString(_m_2++,kw);
236
	            ps.setString(_m_2++,kw);
237
	            ps.setString(_m_2++,kw);
238
	            ps.setString(_m_2++,kw);
239
	            ps.setString(_m_2++,kw);
240
	            ps.setString(_m_2++,kw);
241
	            ps.setString(_m_2++,kw);
242
	            _result.setPageSize(pageSize);
243
	            java.sql.ResultSet _pageRs = ps.executeQuery();
244
	            try{
245
	                _pageRs.next();
246
	                _m_1 = _pageRs.getInt(1);
247
	            }finally{
248
	                try{_pageRs.close();}catch(Exception _m_4){}
249
	            }
250
	        }finally{
251
	            try{ps.close();}catch(Exception _m_5){}
252
	        }
253
	        _result.setTotal(_m_1);
254
	        if(0== _m_1){
255
	            _result.setPageNo(1);
256
	            _result.setData(java.util.Collections.<com.ekexiu.portal.pojo.EditOrganization>emptyList());
257
	            return _result;
258
	        }
259
	        _m_2 = 1;
260
	        boolean _m_6 = (1 == pageNo);
261
	        if(_m_6){
262
	            _result.setPageNo(1);
263
	            sql = "SELECT FOR_SHORT,ORG_URL,FOUND_TIME,PROVINCE,CITY,SUBJECT,INDUSTRY,ORG_SIZE,QUALIFICATION,IS_JOIN,AUTH_STATUS,ADDR,EMAIL,CONTACT_NUM,FIELD_OF_CUSTOMER,FIELD_OF_SUPPLIER,SORT_NUM,PAGE_VIEWS,SHARE_ID,ORG_ATTR,ID,NAME,ORG_TYPE,CREATE_TIME,MODIFY_TIME,DESCP FROM ORGANIZATION";
264
	            sql = sql + _m_3;
265
	            sql = sql + " ORDER BY SORT_NUM DESC,MODIFY_TIME DESC";
266
	            sql = sql + " LIMIT " + pageSize;
267
	        }else{
268
	            int _m_7 = _m_1 / pageSize;
269
	            if(_m_1 % pageSize != 0){
270
	                ++_m_7;
271
	            }
272
	            if(pageNo > _m_7){
273
	                pageNo = _m_7;
274
	            }
275
	            _result.setPageNo(pageNo);
276
	            --pageNo;
277
	            int _m_8 = (pageNo * pageSize);
278
	            sql = "SELECT FOR_SHORT,ORG_URL,FOUND_TIME,PROVINCE,CITY,SUBJECT,INDUSTRY,ORG_SIZE,QUALIFICATION,IS_JOIN,AUTH_STATUS,ADDR,EMAIL,CONTACT_NUM,FIELD_OF_CUSTOMER,FIELD_OF_SUPPLIER,SORT_NUM,PAGE_VIEWS,SHARE_ID,ORG_ATTR,ID,NAME,ORG_TYPE,CREATE_TIME,MODIFY_TIME,DESCP FROM ORGANIZATION";
279
	            sql = sql + _m_3;
280
	            sql = sql + " ORDER BY SORT_NUM DESC,MODIFY_TIME DESC";
281
	            sql = sql + " LIMIT " + pageSize+ " OFFSET "+_m_8;
282
	        }
283
	        ps = con.prepareStatement(sql);
284
	        try{
285
	            ps.setString(_m_2++,industry);	
286
	            ps.setString(_m_2++,addr);	   
287
	            ps.setString(_m_2++,kw);
288
	            ps.setString(_m_2++,kw);
289
	            ps.setString(_m_2++,kw);
290
	            ps.setString(_m_2++,kw);
291
	            ps.setString(_m_2++,kw);
292
	            ps.setString(_m_2++,kw);
293
	            ps.setString(_m_2++,kw);
294
	            java.sql.ResultSet rs = ps.executeQuery();
295
	            try{
296
	                java.util.List<com.ekexiu.portal.pojo.EditOrganization> _m_9 = new java.util.ArrayList<com.ekexiu.portal.pojo.EditOrganization>();
297
	                _result.setData(_m_9);
298
	                int _m_10 = 0;
299
	                while((_m_10<pageSize) && rs.next()){
300
	                    ++_m_10;
301
	                    com.ekexiu.portal.pojo.EditOrganization _obj =  new com.ekexiu.portal.pojo.EditOrganization();
302
	                    java.lang.String _m_11 = rs.getString(1);
303
	                    if(rs.wasNull()){
304
	                        _m_11 = null;
305
	                    }
306
	                    _obj.setForShort(_m_11);
307
	                    java.lang.String _m_12 = rs.getString(2);
308
	                    if(rs.wasNull()){
309
	                        _m_12 = null;
310
	                    }
311
	                    _obj.setOrgUrl(_m_12);
312
	                    java.lang.String _m_13 = rs.getString(3);
313
	                    if(rs.wasNull()){
314
	                        _m_13 = null;
315
	                    }
316
	                    _obj.setFoundTime(_m_13);
317
	                    java.lang.String _m_14 = rs.getString(4);
318
	                    if(rs.wasNull()){
319
	                        _m_14 = null;
320
	                    }
321
	                    _obj.setProvince(_m_14);
322
	                    java.lang.String _m_15 = rs.getString(5);
323
	                    if(rs.wasNull()){
324
	                        _m_15 = null;
325
	                    }
326
	                    _obj.setCity(_m_15);
327
	                    java.lang.String _m_16 = rs.getString(6);
328
	                    if(rs.wasNull()){
329
	                        _m_16 = null;
330
	                    }
331
	                    _obj.setSubject(_m_16);
332
	                    java.lang.String _m_17 = rs.getString(7);
333
	                    if(rs.wasNull()){
334
	                        _m_17 = null;
335
	                    }
336
	                    _obj.setIndustry(_m_17);
337
	                    java.lang.String _m_18 = rs.getString(8);
338
	                    if(rs.wasNull()){
339
	                        _m_18 = null;
340
	                    }
341
	                    _obj.setOrgSize(_m_18);
342
	                    java.lang.String _m_19 = rs.getString(9);
343
	                    if(rs.wasNull()){
344
	                        _m_19 = null;
345
	                    }
346
	                    _obj.setQualification(_m_19);
347
	                    _obj.setIsJoin(rs.getString(10));
348
	                    _obj.setAuthStatus(rs.getString(11));
349
	                    java.lang.String _m_20 = rs.getString(12);
350
	                    if(rs.wasNull()){
351
	                        _m_20 = null;
352
	                    }
353
	                    _obj.setAddr(_m_20);
354
	                    java.lang.String _m_21 = rs.getString(13);
355
	                    if(rs.wasNull()){
356
	                        _m_21 = null;
357
	                    }
358
	                    _obj.setEmail(_m_21);
359
	                    java.lang.String _m_22 = rs.getString(14);
360
	                    if(rs.wasNull()){
361
	                        _m_22 = null;
362
	                    }
363
	                    _obj.setContactNum(_m_22);
364
	                    java.lang.String _m_23 = rs.getString(15);
365
	                    if(rs.wasNull()){
366
	                        _m_23 = null;
367
	                    }
368
	                    _obj.setFieldOfCustomer(_m_23);
369
	                    java.lang.String _m_24 = rs.getString(16);
370
	                    if(rs.wasNull()){
371
	                        _m_24 = null;
372
	                    }
373
	                    _obj.setFieldOfSupplier(_m_24);
374
	                    _obj.setSortNum(rs.getLong(17));
375
	                    _obj.setPageViews(rs.getLong(18));
376
	                    _obj.setShareId(rs.getLong(19));
377
	                    java.lang.String _m_25 = rs.getString(20);
378
	                    if(rs.wasNull()){
379
	                        _m_25 = null;
380
	                    }
381
	                    _obj.setOrgAttr(_m_25);
382
	                    _obj.setId(rs.getString(21));
383
	                    _obj.setName(rs.getString(22));
384
	                    java.lang.String _m_26 = rs.getString(23);
385
	                    if(rs.wasNull()){
386
	                        _m_26 = null;
387
	                    }
388
	                    _obj.setOrgType(_m_26);
389
	                    _obj.setCreateTime(rs.getString(24));
390
	                    _obj.setModifyTime(rs.getString(25));
391
	                    java.lang.String _m_27 = rs.getString(26);
392
	                    if(rs.wasNull()){
393
	                        _m_27 = null;
394
	                    }
395
	                    _obj.setDescp(_m_27);
396
	                    _m_9.add(_obj);
397
	                }
398
	                return _result;
399
	            }finally{
400
	                try{rs.close();}catch(Exception _m_28){}
401
	            }
402
	        }finally{
403
	            try{ps.close();}catch(Exception _m_29){}
404
	        }
405
	    }
406
	
407
	
221
222
	@PageQuery
223
	@Select(Organization.class)
224
	@From(Organization.class)
225
	@OrderBy(" ORDER BY SORT_NUM DESC,MODIFY_TIME DESC")
226
	public abstract PageQueryResult<EditOrganization> queryByKwAndIndustryAndAddr(Connection con, 
227
			@GroupSqlColumn(isAnd=false, handlerClass = StringHandler.class, value = { "NAME LIKE ? AND IS_JOIN ='1'", "FOR_SHORT LIKE ? AND IS_JOIN ='1'",
228
					"DESCP LIKE ?  AND IS_JOIN ='1'", "SUBJECT LIKE ? AND IS_JOIN ='1' ", "industry LIKE ?  AND IS_JOIN ='1'",
229
					"ID IN (SELECT ORG_ID FROM RESOURCE WHERE RESOURCE_TYPE='2' AND RESOURCE_NAME LIKE ?) AND IS_JOIN ='1'",
230
					"ID IN (SELECT ORG_ID FROM ARTICLE WHERE ARTICLE_TYPE='2' AND ARTICLE_TITLE LIKE ?) AND IS_JOIN ='1'" })
231
		@Nullable	String kw, @Nullable String industry,@Nullable String addr, int pageSize,
232
			int pageNo) throws SQLException;
408 233
409 234
	@PageQuery
410 235
	@From(Organization.class)
@ -412,46 +237,53 @@ public abstract class OrgDao {
412 237
	@Select(Organization.class)
413 238
	@Where("IS_JOIN ='1'")
414 239
	public abstract PageQueryResult<EditOrganization> query(Connection con, int pageSize, int pageNo) throws SQLException;
415
	
416
	
240
417 241
	@PageQuery
418 242
	@From(Organization.class)
419 243
	@OrderBy("ORDER BY SORT_NUM DESC,MODIFY_TIME DESC")
420 244
	@Select(Organization.class)
421 245
	@Where("IS_JOIN ='1'")
422
	public abstract PageQueryResult<EditOrganization> queryByIndustryAndAddr(Connection con,@Like String industry,@Like String addr,  int pageSize, int pageNo) throws SQLException;
423
	
246
	public abstract PageQueryResult<EditOrganization> queryByIndustryAndAddr(Connection con, @Like String industry, @Like String addr, int pageSize, int pageNo)
247
			throws SQLException;
248
424 249
	@QueryList
425 250
	@From(Organization.class)
426 251
	@Select(Organization.class)
427
	public abstract List<EditOrganization> query(Connection con,@In String[] id) throws SQLException;
428
	
252
	public abstract List<EditOrganization> query(Connection con, @In String[] id) throws SQLException;
253
429 254
	@LimitQuery
430 255
	@Select(Organization.class)
431 256
	@From(Organization.class)
432 257
	@OrderBy(" ORDER BY SORT_NUM DESC,PAGE_VIEWS DESC,SHARE_ID ASC")
433 258
	@Or
434
	public abstract List<EditOrganization> relateQuery(Connection con,@Nullable @SqlColumn(value={"(IS_JOIN='1' AND NAME LIKE ?)","(IS_JOIN='1' AND FOR_SHORT LIKE ?)"},handlerClass=StringHandler.class) String kw,int rows)throws SQLException;
259
	public abstract List<EditOrganization> relateQuery(Connection con, @Nullable @SqlColumn(value = { "(IS_JOIN='1' AND NAME LIKE ?)",
260
			"(IS_JOIN='1' AND FOR_SHORT LIKE ?)" }, handlerClass = StringHandler.class) String kw, int rows) throws SQLException;
435 261
436
	public String[] queryOrgIdWithSameKeyWord(Connection con,String id,int rows)throws SQLException{
262
	public String[] queryOrgIdWithSameKeyWord(Connection con, String id, int rows) throws SQLException {
437 263
		List<String> ret = new ArrayList<String>();
438 264
		String sql = "select id,count(1) sort from org_key_word where kw in (select kw from org_key_word where id=?) and id <>? group by id order by sort desc limit ?";
439 265
		PreparedStatement ps = con.prepareStatement(sql);
440
		try{
266
		try {
441 267
			ps.setString(1, id);
442 268
			ps.setString(2, id);
443 269
			ps.setInt(3, rows);
444 270
			ResultSet rs = ps.executeQuery();
445
			try{
446
				while(rs.next()){
271
			try {
272
				while (rs.next()) {
447 273
					ret.add(rs.getString(1));
448 274
				}
449
			}finally{
450
				try{rs.close();}catch(Exception e1){}
275
			} finally {
276
				try {
277
					rs.close();
278
				} catch (Exception e1) {
279
				}
280
			}
281
		} finally {
282
			try {
283
				ps.close();
284
			} catch (Exception e2) {
451 285
			}
452
		}finally{
453
			try{ps.close();}catch(Exception e2){}
454 286
		}
455
		return ret.isEmpty()?null:ret.toArray(new String[ret.size()]);		
287
		return ret.isEmpty() ? null : ret.toArray(new String[ret.size()]);
456 288
	}
457 289
}

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

@ -56,19 +56,10 @@ public abstract class ProfessorDao {
56 56
	@Update
57 57
	public abstract int update(Connection con, Professor professor) throws SQLException;
58 58

59
	public int updateScoreValue(Connection con, String id, Integer scoreValue) throws SQLException {
60
		String sql = "UPDATE PROFESSOR SET SCORE_VALUE = SCORE_VALUE + " + scoreValue + " WHERE ID = '" + id + "'";
61
		PreparedStatement ps = con.prepareStatement(sql);
62
		try {
63
			return ps.executeUpdate();
64
		} finally {
65
			try {
66
				ps.close();
67
			} catch (Exception e) {
68
			}
69
		}
70
	}
71

59
	@UpdateWith
60
	@From(Professor.class)
61
	public abstract  int updateScoreValue(Connection con, String id,@Set("= SCORE_VALUE + ?") int scoreValue) throws SQLException;
62
	
72 63
	public int updateGrowthValue(Connection con, String id, Integer growthValue) throws SQLException {
73 64
		String sql = "UPDATE PROFESSOR SET GROWTH_VALUE = GROWTH_VALUE + " + growthValue + " WHERE ID = '" + id + "'";
74 65
		PreparedStatement ps = con.prepareStatement(sql);

+ 13 - 56
src/main/java/com/ekexiu/portal/dao/ResearchAreaLogDao.java

@ -1,16 +1,17 @@
1 1
package com.ekexiu.portal.dao;
2 2
3 3
import java.sql.Connection;
4
import java.sql.PreparedStatement;
5
import java.sql.ResultSet;
6 4
import java.sql.SQLException;
7
import java.util.ArrayList;
8 5
import java.util.List;
9 6
10 7
import org.jfw.apt.orm.annotation.dao.DAO;
11 8
import org.jfw.apt.orm.annotation.dao.method.From;
9
import org.jfw.apt.orm.annotation.dao.method.Select;
12 10
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
13 11
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
12
import org.jfw.apt.orm.annotation.dao.method.operator.LimitQuery;
13
import org.jfw.apt.orm.annotation.dao.method.operator.QueryList;
14
import org.jfw.apt.orm.annotation.dao.param.LessThan;
14 15
15 16
import com.ekexiu.portal.po.ResearchAreaLog;
16 17
import com.ekexiu.portal.pojo.EditResearchAreaLog;
@ -32,59 +33,15 @@ public abstract class ResearchAreaLogDao {
32 33
	@From(ResearchAreaLog.class)
33 34
	public abstract int delete(Connection con,String professorId)throws SQLException;
34 35
	
35
	public List<EditResearchAreaLog> queryLimit(Connection con,String professorId,String caption,String createTime,int rows) throws SQLException{
36
        int index = 1;
37
        String sql = "SELECT OPRETE_PROFESSOR_ID,CREATE_TIME,PROFESSOR_ID,CAPTION FROM RESEARCH_AREA_LOG "
38
        		+ " WHERE CREATE_TIME < ? AND CAPTION = ? AND PROFESSOR_ID = ? ORDER BY CREATE_TIME DESC LIMIT "+rows;
39
        PreparedStatement ps = con.prepareStatement(sql);
40
        try{
41
            ps.setString(index++,createTime);
42
            ps.setString(index++,caption);
43
            ps.setString(index++,professorId);
44
            ResultSet rs = ps.executeQuery();
45
            try{
46
                List<EditResearchAreaLog> areaLogs = new ArrayList<EditResearchAreaLog>();
47
                while(rs.next()){
48
                	EditResearchAreaLog areaLog =  new EditResearchAreaLog();
49
                	areaLog.setOpreteProfessorId(rs.getString(1));
50
                	areaLog.setCreateTime(rs.getString(2));
51
                	areaLog.setProfessorId(rs.getString(3));
52
                	areaLog.setCaption(rs.getString(4));
53
                    areaLogs.add(areaLog);
54
                }
55
                return areaLogs;
56
            }finally{
57
                try{rs.close();}catch(Exception e1){}
58
            }
59
        }finally{
60
            try{ps.close();}catch(Exception e2){}
61
        }
62
    }
63 36
	
64
	public List<EditResearchAreaLog> query(Connection con,String professorId) throws SQLException{
65
        int index = 1;
66
        String sql = "SELECT OPRETE_PROFESSOR_ID,CREATE_TIME,PROFESSOR_ID,CAPTION FROM RESEARCH_AREA_LOG WHERE PROFESSOR_ID = ?";
67
        PreparedStatement ps = con.prepareStatement(sql);
68
        try{
69
            ps.setString(index++,professorId);
70
            ResultSet rs = ps.executeQuery();
71
            try{
72
                List<EditResearchAreaLog> areaLogs = new ArrayList<EditResearchAreaLog>();
73
                while(rs.next()){
74
                	EditResearchAreaLog log =  new EditResearchAreaLog();
75
                	log.setOpreteProfessorId(rs.getString(1));
76
                	log.setCreateTime(rs.getString(2));
77
                	log.setProfessorId(rs.getString(3));
78
                	log.setCaption(rs.getString(4));
79
                	areaLogs.add(log);
80
                }
81
                return areaLogs;
82
            }finally{
83
                try{rs.close();}catch(Exception e1){}
84
            }
85
        }finally{
86
            try{ps.close();}catch(Exception e2){}
87
        }
88
    }
37
	@LimitQuery
38
	@From(ResearchAreaLog.class)
39
	@Select(ResearchAreaLog.class)	
40
	public abstract List<EditResearchAreaLog> queryLimit(Connection con,String professorId,String caption,@LessThan String createTime,int rows) throws SQLException;
89 41
42
	@QueryList
43
	@From(ResearchAreaLog.class)
44
	@Select(ResearchAreaLog.class)	
45
	public abstract List<EditResearchAreaLog> query(Connection con,String professorId) throws SQLException;
46
	
90 47
}

+ 26 - 22
src/main/java/com/ekexiu/portal/dao/TidingsDao.java

@ -7,10 +7,18 @@ import java.sql.SQLException;
7 7
import java.util.ArrayList;
8 8
import java.util.List;
9 9

10
import org.jfw.apt.annotation.DefaultValue;
11
import org.jfw.apt.orm.annotation.dao.Column;
10 12
import org.jfw.apt.orm.annotation.dao.DAO;
13
import org.jfw.apt.orm.annotation.dao.method.From;
11 14
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
15
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
16
import org.jfw.apt.orm.annotation.dao.method.Where;
12 17
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
18
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
13 19
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
20
import org.jfw.apt.orm.annotation.dao.method.operator.UpdateWith;
21
import org.jfw.apt.orm.core.defaultImpl.IntHandler;
14 22

15 23
import com.ekexiu.portal.po.Consult;
16 24
import com.ekexiu.portal.po.Tidings;
@ -21,18 +29,13 @@ public abstract class TidingsDao {
21 29
	@Insert
22 30
	public abstract int insert(Connection con, Tidings tidings) throws SQLException;
23 31
	
24
	public int updateReadStatus(Connection con,String senderId,String consultId) throws SQLException{
25
        int index = 1;
26
        String sql ="UPDATE TIDINGS SET READ_STATUS = 1 WHERE READ_STATUS = 0 AND CONSULT_ID = ? AND SENDER_ID != ? ";
27
        PreparedStatement ps = con.prepareStatement(sql);
28
        try{
29
            ps.setString(index++,consultId);
30
            ps.setString(index++,senderId);
31
            return ps.executeUpdate();
32
        }finally{
33
            try{ps.close();}catch(Exception e){}
34
        }
35
    }
32
	@UpdateWith
33
	@From(Tidings.class)
34
	@Where("READ_STATUS = 0")
35
	@SetSentence("READ_STATUS = 1")
36
	public abstract int updateReadStatus(Connection con,String senderId,String consultId) throws SQLException;
37
	
38
	
36 39
	
37 40
	/**
38 41
	 * 查询当前咨询有几条未读消息
@ -42,16 +45,13 @@ public abstract class TidingsDao {
42 45
	 * @return 返回该咨询中对方发送过来未查看的信息条数
43 46
	 * @throws SQLException
44 47
	 */
45
	public int queryNotReadTidings(Connection con, String consultId, String senderId) throws SQLException {
46
		String sql = " SELECT COUNT(1) FROM TIDINGS WHERE READ_STATUS = 0 AND CONSULT_ID = ? AND SENDER_ID != ? ";
47
		PreparedStatement ps = con.prepareStatement(sql);
48
		ps.setString(1, consultId);
49
		ps.setString(2, senderId);
50
		ResultSet rs = ps.executeQuery();
51
		rs.next();
52
		int count = rs.getInt(1);
53
		return count;
54
	}
48
	
49
	@QueryVal
50
	@Column(handlerClass=IntHandler.class,value="COUNT(1)")
51
	@From(Tidings.class)
52
	@Where("READ_STATUS = 0")
53
	@DefaultValue("0")
54
	public abstract int queryNotReadTidings(Connection con, String consultId, String senderId) throws SQLException;
55 55
	
56 56
	/**
57 57
	 * 我的工作台最新回复
@ -107,6 +107,10 @@ public abstract class TidingsDao {
107 107
	 * @return 返回对方最后回复的信息
108 108
	 * @throws SQLException
109 109
	 */
110
//	@SelectOne
111
//	@Nullable
112
//	public abstract Tidings queryLastRevovery(Connection con,String consultId,String senderId) throws SQLException;
113
//	
110 114
	public Tidings queryLastRevovery(Connection con,String consultId,String senderId) throws SQLException{
111 115
        int index = 1;
112 116
        String sql = "SELECT TIDINGS_ID,TIDINGS_CONTANT,SENDER_ID,CONSULT_ID,CREATE_TIME FROM TIDINGS "