Browse Source

--add pageQueryOrg();update queryOne();

zzy.zhiyuan.foxmail 8 years ago
parent
commit
48bdb13dd3

+ 135 - 2
src/main/java/com/ekexiu/portal/dao/DemandDao.java

@ -43,6 +43,11 @@ public abstract class DemandDao {
43 43
	@From(Demand.class)
44 44
	public abstract int queryCountByStatus(Connection con,String demander,String demandStatus)throws SQLException, JfwBaseException;
45 45
	
46
	@QueryVal
47
	@Column(handlerClass=IntHandler.class,value="COUNT(1)")
48
	@From(Demand.class)
49
	public abstract int queryCountStatus(Connection con,String demandStatus)throws SQLException, JfwBaseException;
50
	
46 51
	@SelectList
47 52
	@OrderBy("ORDER BY CREATE_TIME DESC")
48 53
	public abstract List<Demand> queryByDemander(Connection con,String demander)throws SQLException;
@ -203,7 +208,7 @@ public abstract class DemandDao {
203 208
        if(firstPage){
204 209
        	queryResult.setPageNo(1);
205 210
            sql = new StringBuilder();
206
            sql.append("SELECT DEMAND_ID,DEMANDER,DEMAND_AIM,DEMAND_TYPE,DEMAND_TITLE,DEMAND_CONTENT,DEMAND_STATUS,CLOSE_TIME,ORDER_KEY,CREATE_TIME FROM DEMAND");
211
            sql.append("SELECT DEMAND_ID,DEMANDER,DEMAND_AIM,DEMAND_TYPE,DEMAND_TITLE,DEMAND_CONTENT,DEMAND_STATUS,CLOSE_TIME,ORDER_KEY,CREATE_TIME,ORG_ID FROM DEMAND");
207 212
            if(whereSql.length()>0){
208 213
                sql.append(whereSql);
209 214
            }
@ -224,7 +229,7 @@ public abstract class DemandDao {
224 229
            --pageNo;
225 230
            int offset = (pageNo * pageSize);
226 231
            sql = new StringBuilder();
227
            sql.append("SELECT DEMAND_ID,DEMANDER,DEMAND_AIM,DEMAND_TYPE,DEMAND_TITLE,DEMAND_CONTENT,DEMAND_STATUS,CLOSE_TIME,ORDER_KEY,CREATE_TIME FROM DEMAND");
232
            sql.append("SELECT DEMAND_ID,DEMANDER,DEMAND_AIM,DEMAND_TYPE,DEMAND_TITLE,DEMAND_CONTENT,DEMAND_STATUS,CLOSE_TIME,ORDER_KEY,CREATE_TIME,ORG_ID FROM DEMAND");
228 233
            if(whereSql.length()>0){
229 234
                sql.append(whereSql);
230 235
            }
@ -266,6 +271,134 @@ public abstract class DemandDao {
266 271
                    demand.setCloseTime(closeTime);
267 272
                    demand.setOrderKey(rs.getLong(9));
268 273
                    demand.setCreateTime(rs.getString(10));
274
                    String orgId = rs.getString(11);
275
                    if(rs.wasNull()){
276
                    	orgId = null;
277
                    }
278
                    demand.setOrgId(orgId);
279
                    demands.add(demand);
280
                }
281
                return queryResult;
282
            }finally{
283
                try{rs.close();}catch(Exception e3){}
284
            }
285
        }finally{
286
            try{ps.close();}catch(Exception e4){}
287
        }
288
    }
289
	
290
	public PageQueryResult<Demand> pageQueryOrg(Connection con,String orgId,String demandStatus,int sortType,int pageSize,int pageNo) throws SQLException{
291
        int total = 0;
292
        PageQueryResult<Demand> queryResult = new PageQueryResult<Demand>();
293
        int index = 1;
294
        boolean hasDemandStatus = null != demandStatus;
295
        StringBuilder sql = new StringBuilder();
296
        sql.append(" WHERE ORG_ID = ? ");
297
        if(hasDemandStatus){
298
            sql.append(" AND DEMAND_STATUS = ?");
299
        }
300
        StringBuilder whereSql = sql;
301
        sql = new StringBuilder();
302
        sql.append("SELECT COUNT(1) FROM DEMAND");
303
        if(whereSql.length()>0){
304
            sql.append(whereSql);
305
        }
306
        PreparedStatement ps = con.prepareStatement(sql.toString());
307
        try{
308
        	ps.setString(index++, orgId);
309
            if(hasDemandStatus){
310
                ps.setString(index++,demandStatus);
311
            }
312
            queryResult.setPageSize(pageSize);
313
            ResultSet rs = ps.executeQuery();
314
            try{
315
                rs.next();
316
                total = rs.getInt(1);
317
            }finally{
318
                try{rs.close();}catch(Exception e1){}
319
            }
320
        }finally{
321
            try{ps.close();}catch(Exception e2){}
322
        }
323
        queryResult.setTotal(total);
324
        if(0== total){
325
        	queryResult.setPageNo(1);
326
        	queryResult.setData(Collections.<Demand>emptyList());
327
            return queryResult;
328
        }
329
        index = 1;
330
        boolean firstPage = (1 == pageNo);
331
        if(firstPage){
332
        	queryResult.setPageNo(1);
333
            sql = new StringBuilder();
334
            sql.append("SELECT DEMAND_ID,DEMANDER,DEMAND_AIM,DEMAND_TYPE,DEMAND_TITLE,DEMAND_CONTENT,DEMAND_STATUS,CLOSE_TIME,ORDER_KEY,CREATE_TIME,ORG_ID FROM DEMAND");
335
            if(whereSql.length()>0){
336
                sql.append(whereSql);
337
            }
338
            sql.append(" ORDER BY CREATE_TIME");
339
            if(sortType == 0){
340
            	sql.append(" DESC ");
341
            }
342
            sql.append(" LIMIT ").append(pageSize);
343
        }else{
344
            int pageNum = total / pageSize;
345
            if(total % pageSize != 0){
346
                ++pageNum;
347
            }
348
            if(pageNo > pageNum){
349
                pageNo = pageNum;
350
            }
351
            queryResult.setPageNo(pageNo);
352
            --pageNo;
353
            int offset = (pageNo * pageSize);
354
            sql = new StringBuilder();
355
            sql.append("SELECT DEMAND_ID,DEMANDER,DEMAND_AIM,DEMAND_TYPE,DEMAND_TITLE,DEMAND_CONTENT,DEMAND_STATUS,CLOSE_TIME,ORDER_KEY,CREATE_TIME,ORG_ID FROM DEMAND");
356
            if(whereSql.length()>0){
357
                sql.append(whereSql);
358
            }
359
            sql.append(" ORDER BY CREATE_TIME");
360
            if(sortType == 0){
361
            	sql.append(" DESC ");
362
            }
363
            sql.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(offset);
364
        }
365
        ps = con.prepareStatement(sql.toString());
366
        try{
367
        	ps.setString(index++, orgId);
368
            if(hasDemandStatus){
369
                ps.setString(index++,demandStatus);
370
            }
371
            ResultSet rs = ps.executeQuery();
372
            try{
373
                List<Demand> demands = new ArrayList<Demand>();
374
                queryResult.setData(demands);
375
                int size = 0;
376
                while((size<pageSize) && rs.next()){
377
                    ++size;
378
                    Demand demand =  new Demand();
379
                    demand.setDemandId(rs.getString(1));
380
                    demand.setDemander(rs.getString(2));
381
                    demand.setDemandAim(rs.getString(3));
382
                    demand.setDemandType(rs.getString(4));
383
                    demand.setDemandTitle(rs.getString(5));
384
                    String demandContent = rs.getString(6);
385
                    if(rs.wasNull()){
386
                        demandContent = null;
387
                    }
388
                    demand.setDemandContent(demandContent);
389
                    demand.setDemandStatus(rs.getString(7));
390
                    String closeTime = rs.getString(8);
391
                    if(rs.wasNull()){
392
                    	closeTime = null;
393
                    }
394
                    demand.setCloseTime(closeTime);
395
                    demand.setOrderKey(rs.getLong(9));
396
                    demand.setCreateTime(rs.getString(10));
397
                    String orgid = rs.getString(11);
398
                    if(rs.wasNull()){
399
                    	orgid = null;
400
                    }
401
                    demand.setOrgId(orgid);
269 402
                    demands.add(demand);
270 403
                }
271 404
                return queryResult;

+ 8 - 0
src/main/java/com/ekexiu/portal/po/Demand.java

@ -7,6 +7,7 @@ import org.jfw.apt.orm.core.defaultImpl.FixLenStringHandler;
7 7
import org.jfw.apt.orm.core.enums.DE;
8 8

9 9
import com.ekexiu.portal.basepo.CreateTimeSupported;
10
import com.ekexiu.portal.pojo.EditOrganization;
10 11
import com.ekexiu.portal.pojo.EditProfessor;
11 12

12 13
@Table
@ -24,6 +25,7 @@ public class Demand implements CreateTimeSupported {
24 25
	private long orderKey;
25 26
	private String orgId;
26 27
	private EditProfessor professor;
28
	private EditOrganization organization;
27 29
	
28 30
	public EditProfessor getProfessor() {
29 31
		return professor;
@ -31,6 +33,12 @@ public class Demand implements CreateTimeSupported {
31 33
	public void setProfessor(EditProfessor professor) {
32 34
		this.professor = professor;
33 35
	}
36
	public EditOrganization getOrganization() {
37
		return organization;
38
	}
39
	public void setOrganization(EditOrganization organization) {
40
		this.organization = organization;
41
	}
34 42
	@Column(DE.id_32)
35 43
	public String getDemandId() {
36 44
		return demandId;

+ 38 - 3
src/main/java/com/ekexiu/portal/service/DemandService.java

@ -36,6 +36,9 @@ public class DemandService {
36 36
	private ProfessorDao professorDao;
37 37
	@Autowrie
38 38
	private ImageService imageService;
39
	@Autowrie
40
	private OrgService orgService;
41
	
39 42
	public DemandDao getDemandDao() {
40 43
		return demandDao;
41 44
	}
@ -60,6 +63,12 @@ public class DemandService {
60 63
	public void setImageService(ImageService imageService) {
61 64
		this.imageService = imageService;
62 65
	}
66
	public OrgService getOrgService() {
67
		return orgService;
68
	}
69
	public void setOrgService(OrgService orgService) {
70
		this.orgService = orgService;
71
	}
63 72
	
64 73
	@Post
65 74
	@Path
@ -99,11 +108,14 @@ public class DemandService {
99 108
			professor.setHasHeadImage(this.imageService.hasProfessorImage(demand.getDemander()));
100 109
		}
101 110
		demand.setProfessor(professor);
111
		if(demand.getOrgId() != null){
112
			demand.setOrganization(this.orgService.query(con, demand.getOrgId()));
113
		}
102 114
		return demand;
103 115
	}
104 116
	
105 117
	/**
106
	 * 查询发布中的需求总数
118
	 * 查询发布中的需求总数
107 119
	 * @param con
108 120
	 * @param demander 发布者ID
109 121
	 * @return 返回状态发布中的需求总数
@ -111,11 +123,17 @@ public class DemandService {
111 123
	 * @throws JfwBaseException 
112 124
	 */
113 125
	@Get
114
	@Path("/queryPublish")
115
	public int queryPublish(@JdbcConn Connection con,String demander)throws SQLException, JfwBaseException{
126
	@Path("/queryMyPublish")
127
	public int queryMyPublish(@JdbcConn Connection con,String demander)throws SQLException, JfwBaseException{
116 128
		return this.demandDao.queryCountByStatus(con, demander, "1");
117 129
	}
118 130
	
131
	@Get
132
	@Path("/queryPublish")
133
	public int queryPublish(@JdbcConn Connection con)throws SQLException, JfwBaseException{
134
		return this.demandDao.queryCountStatus(con, "1");
135
	}
136
	
119 137
	@Get
120 138
	@Path("/byDemander")
121 139
	public List<Demand> queryByDemander(@JdbcConn Connection con,String demander)throws SQLException{
@ -147,6 +165,23 @@ public class DemandService {
147 165
		return queryResult;
148 166
	}
149 167
	
168
	@Get
169
	@Path("/pqOrg")
170
	public PageQueryResult<Demand> pageQueryOrg(@JdbcConn Connection con,String orgId,@Nullable String demandStatus,
171
			@DefaultValue("0") int sortType,@DefaultValue("5") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{
172
		PageQueryResult<Demand> queryResult = this.demandDao.pageQueryOrg(con, orgId, demandStatus, sortType, pageSize, pageNo);
173
		List<Demand> demands = queryResult.getData();
174
		for (Demand demand : demands) {
175
			EditProfessor professor = this.professorDao.queryBaseInfo(con, demand.getDemander());
176
			if(professor != null){
177
				professor.setHasHeadImage(this.imageService.hasProfessorImage(demand.getDemander()));
178
			}
179
			demand.setProfessor(professor);
180
		}
181
		queryResult.setData(demands);
182
		return queryResult;
183
	}
184
	
150 185
	@Get
151 186
	@Path("/ql")
152 187
	public List<Demand> queryByStatus(@JdbcConn Connection con,@Nullable String demandAim,@Nullable String subject,