프론트 데스크톱 dao 인터페이스와 NeOrderFatherDao 구현

4729 단어 order
package cn.client.dao;

import java.util.List;

import cn.entity.NeOrderFather;

/*
 *      DAO   
 * */
public interface NeOrderFatherDao {
	
	//           
	public int insertOrderFather(String orderFatherId, String username);
	
	//            
	public  int getTotalCount(String username);
	
	//               
	public  int getTotalCount(String username,int statusId);
	
	//                        
	public List<NeOrderFather> getNeOrderFatherByPage(int pageIndex, int pageSize,String username);
	
	//      ,     ,        
	public int update(String orderFatherId,int statusId);
	
}

 
package cn.client.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.client.dao.BaseDao;
import cn.client.dao.NeOrderFatherDao;
import cn.entity.NeOrderFather;

/*
 *      DAO   
 * */
public class NeOrderFatherDaoImpl extends BaseDao implements NeOrderFatherDao {
	Connection conn = null;//       
	PreparedStatement pstmt = null;//       
	ResultSet rs = null;//        

	//           
	public int insertOrderFather(String orderFatherId, String username) {
		String sql = "insert into ne_order_father" +
				"  (ne_order_father_id, ne_user_id, ne_order_time, ne_status_id)" + 
				"values" + 
				"  (?, ?, sysdate, 1)";
		return this.executeUpdate(sql, new  Object[]{ 
				orderFatherId,
				username
		});
	}

	//            
	public  int getTotalCount(String username){
		int total = 0;
		String sql = "select count(*) from ne_order_father where ne_user_id =?";
		conn=this.getConnection();
		try {
			pstmt=conn.prepareStatement(sql);
			pstmt.setString(1, username);
			rs = pstmt.executeQuery();
			if(rs.next()){
				total = rs.getInt(1); 
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return total;
	}

	//               
	public  int getTotalCount(String username,int statusId){
		int total = 0;
		String sql = "select count(*) from ne_order_father where ne_user_id =? and ne_status_id=?";
		conn=this.getConnection();
		try {
			pstmt=conn.prepareStatement(sql);
			pstmt.setString(1, username);
			pstmt.setInt(2, statusId);
			rs = pstmt.executeQuery();
			if(rs.next()){
				total = rs.getInt(1); 
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return total;
	}

	//                        
	public List<NeOrderFather> getNeOrderFatherByPage(int pageIndex, int pageSize,String username){
		int start = (pageIndex - 1) * pageSize; //     
		int end = pageIndex * pageSize; //   
		if(start>=1){
			start++;
		}
		List<NeOrderFather> list = new ArrayList<NeOrderFather>();
		NeOrderFather item = null;
		String sql ="SELECT * FROM ( SELECT A.*, ROWNUM RN " +
				"FROM (SELECT * FROM ne_order_father  where " + 
				"ne_user_id =? " + 
				"order by ne_order_father.ne_order_time desc) A) WHERE RN BETWEEN ? AND ?";
		conn=this.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, username);
			pstmt.setInt(2, start);
			pstmt.setInt(3, end);
			rs = pstmt.executeQuery();
			while(rs.next()){
				item = new NeOrderFather(
						rs.getString(1),
						rs.getString(2),
						rs.getString(3),
						rs.getInt(4)
						);
				list.add(item);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return list;
	}

	//      ,     ,        
	public int update(String orderFatherId,int statusId){
		String sql= "update ne_order_father " +
						"   set ne_status_id = ? " + 
						" where ne_order_father_id = ?";
		return this.executeUpdate(sql, new Object[]{
				statusId,
				orderFatherId
		});
	}
}

 

좋은 웹페이지 즐겨찾기