IIndexDao
package com.ucap.netcheck.dao;
import com.ucap.netcheck.combination.beans.IndexCombinationBean;
import com.ucap.netcheck.common.Page;
import com.ucap.netcheck.common.dao.GenericDao;
import com.ucap.netcheck.entity.Site;
/**
* @Title: IIndexDao.java
* @Package com.ucap.netcheck.index.dao
* @Description:
* @author Zuoquan Tu
* @date 2015⑷⑹ 下午6:35:31
* @version V1.0
*/
public interface IIndexDao {
/**
* queryJoinedActivity(通过这个方法实现获得首页的分页信息)
*
* @Title: queryJoinedActivity
* @Description: 通过这个方法实现获得首页的分页信息
* @param @param pageNo 要查找的页数
* @param @param pageRow 每页显示记录数
* @param @param params 查找条件
* @param @return 设定文件
* @return Page<IndexCombinationBean> 返回首页制定页面的结果集的结果集
* @throws
*/
public Page<IndexCombinationBean> queryIndexInfoByPage(
int pageNo,int pageRow, Object... params);
}
IndexDaoImpl
package com.ucap.netcheck.dao.impl;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.ucap.netcheck.combination.beans.IndexCombinationBean;
import com.ucap.netcheck.common.Page;
import com.ucap.netcheck.common.dao.BaseDAO;
import com.ucap.netcheck.dao.IIndexDao;
import com.ucap.netcheck.entity.CheckService;
import com.ucap.netcheck.entity.Site;
import com.ucap.netcheck.entity.SiteService;
import com.ucap.netcheck.entity.TaskStatus;
import com.ucap.netcheck.exception.DAOException;
/**
* @Title: IndexDaoImpl.java
* @Package com.ucap.netcheck.index.dao
* @Description:
* @author Zuoquan Tu
* @date 2015⑷⑹ 下午6:37:29
* @version V1.0
*/
@Repository
@Transactional
public class IndexDaoImpl extends BaseDAO implements IIndexDao {
/**
* 通过条件查询分页信息
* params[0]:表示检查名称
* params[1]:表示首页网址
* params[2]:表示网站标识码
* params[3]:表示当前状态
* params[4]:表示的是用户id
*/
@SuppressWarnings("unchecked")
public Page<IndexCombinationBean> queryIndexInfoByPage(
int pageNo,int pageRow, Object... params) {
try {
//Map<String, Object> map = new HashMap<String, Object>();
List<Object> lists = new ArrayList<Object>();
String sql = "SELECT new com.ucap.netcheck.combination.beans.IndexCombinationBean(" +
"s.wzmc,s.url,s.siteCode,cs.taskStatus,cs.taskRunNum," +
"cs.taskOpenNum,cs.userId) " +
"FROM " + Site.class.getSimpleName() + " s,"
+ CheckService.class.getSimpleName() + " cs,"
+ SiteService.class.getSimpleName() + " ss " +
"WHERE ss.siteCode = s.siteCode AND ss.servId = cs.servId ";
//通过网站名称进行查询
if (StringUtils.isNotBlank((String)params[0])) {
sql += " AND s.wzmc like ? ";
lists.add("%" + (String)params[0] + "%");
}
if (StringUtils.isNotBlank((String)params[1])) {
sql += " AND s.url like ? ";
lists.add("%" + (String)params[1] + "%");
}
if (StringUtils.isNotBlank((String)params[2])) {
sql += " AND s.siteCode like ? ";
lists.add("%" + (String)params[2] + "%");
}
if (null != (TaskStatus)params[3]) {
//sql += " AND cs.taskStatus like ? ";
//lists.add("%" + (String)params[3] + "%");
sql += " AND cs.taskStatus =?";
lists.add((TaskStatus)params[3]);
}
if (null != (Integer)params[4]) {
sql += " AND cs.userId =? ";
lists.add((Integer)params[4]);
}
Page<IndexCombinationBean> pages = this.queryByPage(sql, pageNo, pageRow, lists);
//System.out.println("pages.getRecordList().size() = " + pages.getRecordList().size());
return pages;
} catch (Exception ex) {
throw new DAOException("分页查询所有->ERROR", ex);
}
}
}
IndexCombinationBean
package com.ucap.netcheck.combination.beans;
import com.ucap.netcheck.entity.TaskStatus;
/**
* @Title: IndexCombinationBean.java
* @Package com.ucap.netcheck.combination.beans
* @Description: 对应site表,task表,SiteService,CheckService表中的内容,供首页使用
* @author Tuzuoquan
* @date 2015⑷⑹ 下午6:54:50
* @version V1.0
*/
public class IndexCombinationBean {
/**
* 网站名称
*/
private String wzmc;
/**
* 首页地址
*/
private String url;
/**
* 网站标识码,对应task表中的uuid
*/
private String siteCode;
/**
* 任务状态
*/
private TaskStatus taskStatus;
/**
* 任务履行了的次数
*/
private int taskRunNum;
/**
* 任务开通总次数
*/
private int taskOpenNum;
/**
* 用户id
*/
private int userId;
public IndexCombinationBean(String wzmc, String url, String siteCode,
TaskStatus taskStatus, int taskRunNum, int taskOpenNum, int userId) {
this.wzmc = wzmc;
this.url = url;
this.siteCode = siteCode;
this.taskStatus = taskStatus;
this.taskRunNum = taskRunNum;
this.taskOpenNum = taskOpenNum;
this.userId = userId;
}
public String getWzmc() {
return wzmc;
}
public void setWzmc(String wzmc) {
this.wzmc = wzmc;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getSiteCode() {
return siteCode;
}
public void setSiteCode(String siteCode) {
this.siteCode = siteCode;
}
public TaskStatus getTaskStatus() {
return taskStatus;
}
public void setTaskStatus(TaskStatus taskStatus) {
this.taskStatus = taskStatus;
}
public int getTaskRunNum() {
return taskRunNum;
}
public void setTaskRunNum(int taskRunNum) {
this.taskRunNum = taskRunNum;
}
public int getTaskOpenNum() {
return taskOpenNum;
}
public void setTaskOpenNum(int taskOpenNum) {
this.taskOpenNum = taskOpenNum;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
}