首页>代码>JSP+Struts2开发社区医院远程预约挂号管理系统源代码下载>/JavaWeb社区医院远程挂号系统/PatientInfo/src/org/com/dao/GuaHaoDao.java
package org.com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.com.model.GuaHao;
import org.com.model.PageBean;
import org.com.model.Patient;
import org.com.util.DateUtil;
import org.com.util.StringUtil;

public class GuaHaoDao {
	
	public ResultSet guahaoList(Connection con,PageBean pageBean,Patient patient,GuaHao guahao, String s_bGhDate, String s_eGhDate)throws Exception{
		StringBuffer sb=new StringBuffer("SELECT * FROM t_ghinfo g ,t_patient p ,t_user u WHERE p.userId=u.userId AND g.patientId=p.patientId");
		if(patient.getUserId()!=-1){			
			sb.append(" and p.userId = '"+patient.getUserId()+"'");
		}
		if(StringUtil.isNotEmpty(guahao.getPatientName())){
			sb.append(" and p.patientName like '%"+guahao.getPatientName()+"%'");
		}
		if(StringUtil.isNotEmpty(patient.getSex())){
			sb.append(" and p.sex ='"+patient.getSex()+"'");
		}
		if(StringUtil.isNotEmpty(s_bGhDate)){
			sb.append(" and TO_DAYS(g.date)>=TO_DAYS('"+s_bGhDate+"')");
		}
		if(StringUtil.isNotEmpty(s_eGhDate)){
			sb.append(" and TO_DAYS(g.date)<=TO_DAYS('"+s_eGhDate+"')");
		}
		if(StringUtil.isNotEmpty(guahao.getOfficeName())){
			sb.append(" and g.officeName ='"+guahao.getOfficeName()+"'");
		}
		//分页
		if(pageBean!=null){
			sb.append(" limit "+pageBean.getStart()+","+pageBean.getRows());
		}
		PreparedStatement pstmt=con.prepareStatement(sb.toString());
		return pstmt.executeQuery();
	}
	/**
	 * 获取数据总条数
	 * @param con
	 * @param grade
	 * @return
	 * @throws Exception
	 */
	public int guahaoCount(Connection con,Patient patient, GuaHao guahao, String s_bGhDate, String s_eGhDate)throws Exception{
		StringBuffer sb=new StringBuffer("select count(*) as total from t_ghinfo g ,t_patient p ,t_user u WHERE p.userId=u.userId AND g.patientId=p.patientId");
		if(patient.getUserId()!=-1){			
			sb.append(" and p.userId = '"+patient.getUserId()+"'");
		}
		if(StringUtil.isNotEmpty(guahao.getPatientName())){
			sb.append(" and p.patientName like '%"+guahao.getPatientName()+"%'");
		}
		if(StringUtil.isNotEmpty(patient.getSex())){
			sb.append(" and p.sex ='"+patient.getSex()+"'");
		}
		if(StringUtil.isNotEmpty(s_bGhDate)){
			sb.append(" and TO_DAYS(g.date)>=TO_DAYS('"+s_bGhDate+"')");
		}
		if(StringUtil.isNotEmpty(s_eGhDate)){
			sb.append(" and TO_DAYS(g.date)<=TO_DAYS('"+s_eGhDate+"')");
		}
		if(StringUtil.isNotEmpty(guahao.getOfficeName())){
			sb.append(" and g.officeName ='"+guahao.getOfficeName()+"'");
		}
		PreparedStatement pstmt=con.prepareStatement(sb.toString());
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			return rs.getInt("total");
		}else{
			return 0;
		}
	}
	/**
	 *  数据库插入数据
	 * @param con
	 * @param guahao
	 * @return
	 * @throws Exception
	 */
	public int guahaoAdd(Connection con, GuaHao guahao)throws Exception{
		String sql="insert into t_ghinfo values(null,?,?,?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setInt(1, guahao.getPatientId());
		pstmt.setString(2, new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()));//将当前时间作为流水号码
		pstmt.setString(3, DateUtil.formatDate(guahao.getDate(), "yyyy-MM-dd"));
		pstmt.setString(4, guahao.getOfficeName());
		pstmt.setString(5, guahao.getGhDesc());
		return pstmt.executeUpdate();
	}
	/**
	 * 修改数据
	 * @param con
	 * @param guahao
	 * @return
	 * @throws Exception
	 */
	public int guahaoModify(Connection con, GuaHao guahao)throws Exception{
		String sql="update t_ghinfo set patientId=? , date=? , officeName=? , ghDesc=? where ghId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setInt(1, guahao.getPatientId());
		pstmt.setString(2, DateUtil.formatDate(guahao.getDate(), "yyyy-MM-dd"));
		pstmt.setString(3, guahao.getOfficeName());
		pstmt.setString(4, guahao.getGhDesc());
		pstmt.setInt(5, guahao.getGhId());
		return pstmt.executeUpdate();
	}
	/**
	 * 删除数据
	 * @param con
	 * @param delIds
	 * @return
	 * @throws Exception
	 */
	public int guahaoDelete(Connection con,String delIds)throws Exception{
		String sql="delete from t_ghinfo where ghId in("+delIds+")";
		PreparedStatement pstmt=con.prepareStatement(sql);
		return pstmt.executeUpdate();
	}
	/**
	 * 统计每个科室的挂号数量
	 * @param con
	 * @return
	 * @throws Exception
	 */
	public ResultSet guahaoChart(Connection con,Patient patient, GuaHao guahao) throws Exception {
		StringBuffer sb=new StringBuffer("SELECT g.officeName,COUNT(*) FROM t_ghinfo g ,t_patient p ,t_user u WHERE p.userId=u.userId AND g.patientId=p.patientId");
		if(patient.getUserId()!=-1){			
			sb.append(" AND p.userId = '"+patient.getUserId()+"'");
		}
		sb.append(" GROUP BY g.officeName");			
		PreparedStatement pstmt=con.prepareStatement(sb.toString());
		return pstmt.executeQuery();
	}
}
最近下载更多
17558420274  LV16 2024年8月17日
泓鼎168  LV20 2024年6月12日
koumeiyuu  LV9 2024年6月7日
李朝磊  LV18 2023年12月22日
zhaoming200677  LV13 2023年4月17日
Lcovde  LV19 2023年1月5日
2410068425  LV23 2022年5月22日
fajoifjaop  LV2 2022年5月16日
北诺成尘  LV4 2022年3月12日
李拾壹  LV5 2022年1月6日
最近浏览更多
zhihou  LV2 2月6日
xjc1825605176 1月22日
暂无贡献等级
citybird  LV4 2024年11月18日
kamiomisuzu  LV9 2024年10月14日
15719908287  LV9 2024年9月27日
1745713478 2024年9月3日
暂无贡献等级
卢旯旯  LV4 2024年6月10日
17693282606  LV12 2024年6月7日
koumeiyuu  LV9 2024年6月7日
dftyuidfgn 2024年5月16日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友