assetlenddao.java

来自「struts做得固定资产管理系统 带毕业论文完整版」· Java 代码 · 共 259 行

JAVA
259
字号
package com.qrsx.appcam.dao;

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

import com.qrsx.appcam.model.AssetLend;

public class AssetLendDAO extends BaseDAO {
	/**
	 * 创建新的资产借出明细
	 * 
	 * @param assetLend
	 * @throws SQLException
	 */
	public void create(AssetLend assetLend) throws SQLException {

		String sql = "Insert into assetLend (assetId,lendDate,givebackPlanDate,"
				+ "borrowMan,clientId,state) values(?,?,?,?,?,?)";
		// 设置参数
		ps = conn.prepareStatement(sql);
		ps.setInt(1, assetLend.getAssetId());// 资产编号
		ps.setString(2, assetLend.getLendDate());// 借出日期
		ps.setString(3, assetLend.getGivebackPlanDate());// 预计归还日期
		// ps.setString(4, assetLend.getLendEmployee());// 发放人编号
		ps.setString(4, assetLend.getBorrowMan());// 借用人名称
		ps.setInt(5, assetLend.getClientId());// 借用公司
		// ps.setInt(7, assetLend.getDeptmentId());// 借用单位
		// ps.setString(8, assetLend.getGivebackDate());// 归还日期
		ps.setInt(6, 1);// 状态 1为借出 2为归还
		// 执行插入操作
		ps.executeUpdate();

	}

	/**
	 * 更新 资产借出明细
	 * 
	 * @param assetLend
	 * @throws SQLException
	 */

	public void update(AssetLend assetLend) throws SQLException {

		String sql = "Update assetLend set assetId=?,lendDate=?,givebackPlanDate=?,"
				+ "lendEmployee=?,borrowMan=?,clientId=?,deptmentId=?,givebackDate=?,state=? where id=?";
		ps = conn.prepareStatement(sql);
		// 设置参数
		ps = conn.prepareStatement(sql);
		ps.setInt(1, assetLend.getAssetId());
		ps.setString(2, assetLend.getLendDate());
		ps.setString(3, assetLend.getGivebackPlanDate());
		ps.setString(4, assetLend.getLendEmployee());
		ps.setString(5, assetLend.getBorrowMan());
		ps.setInt(6, assetLend.getClientId());
		ps.setInt(7, assetLend.getDeptmentId());// 借用单位
		ps.setString(8, assetLend.getGivebackDate());// 归还日期
		ps.setInt(9, assetLend.getState());// 状态 1为借出 2为归还
		ps.setInt(10, assetLend.getId());
		// 执行更新操作
		ps.executeUpdate();

	}

	/**
	 * 资产归还 更新借出表状态
	 * 
	 * @param assetLend
	 * @throws SQLException
	 */
	public void giveBackUpdate(AssetLend assetLend) throws SQLException {

		String sql = "Update assetLend set givebackDate=?,state=? where id=?";
		ps = conn.prepareStatement(sql);
		// 设置参数
		ps = conn.prepareStatement(sql);
		ps.setString(1, assetLend.getGivebackDate());// 归还日期
		ps.setInt(2, 2);// 状态 1为借出 2为归还
		ps.setInt(3, assetLend.getId());
		// 执行更新操作
		ps.executeUpdate();

	}

	/**
	 * 删除:根据借出明细得主键编号
	 * 
	 * @param assetLendId
	 * @return int(acount)
	 * @throws SQLException
	 */

	public int delete(Integer assetLendId) throws SQLException {

		String sql = "Delete from assetLend where id=?";
		// 设置参数并执行删除操作
		ps = conn.prepareStatement(sql);
		ps.setInt(1, assetLendId);
		int acount = ps.executeUpdate();
		return acount;
	}

	/**
	 * 检索借出明细信息
	 * 
	 * @param assetLendId
	 * @return AssetLend
	 * @throws SQLException
	 */
	public AssetLend findById(Integer assetLendId) throws SQLException {

		String sql = "select * from assetLend where id =? ";
		// 设置参数并执行查询操作
		ps = conn.prepareStatement(sql);
		ps.setInt(1, assetLendId);
		ResultSet rs = ps.executeQuery();

		AssetLend assetLend = null;
		AssetDAO assetDao = new AssetDAO();
		ClientDAO clientDao = new ClientDAO();
		//DeptmentDAO deptmentDao = new DeptmentDAO();
		// 如果返回结果集不为空,则组装assetLend对象
		if (rs.next()) {
			assetLend = new AssetLend();
			assetLend.setId(rs.getInt("id"));
			assetLend.setAssetId(rs.getInt("assetId"));
			assetLend.setLendDate(rs.getString("lendDate"));
			assetLend.setGivebackPlanDate(rs.getString("givebackPlanDate"));
			//assetLend.setLendEmployee(rs.getString("lendEmployee"));
			assetLend.setBorrowMan(rs.getString("borrowMan"));
			assetLend.setClientId(rs.getInt("clientId"));
			//assetLend.setDeptmentId(rs.getInt("deptmentId"));
			assetLend.setGivebackDate(rs.getString("givebackDate"));
			assetLend.setState(rs.getInt("state"));
			assetLend.setAsset(assetDao.findById(rs.getInt("assetId")));
			assetLend.setClient(clientDao.findById(rs.getInt("clientId")));
			//assetLend
			//		.setDeptment(deptmentDao.findById(rs.getInt("deptmentId")));
		}
		return assetLend;
	}

	/**
	 * 检索所有的借出明细信息
	 * 
	 * @return List<AssetLend>
	 * @throws SQLException
	 */
	public List<AssetLend> findAll() throws SQLException {

		String sql = "Select *  from assetLend ";
		// 设置参数并执行查询操作
		ps = conn.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		AssetLend assetLend = null;
		List<AssetLend> list = new ArrayList<AssetLend>();
		AssetDAO assetDao = new AssetDAO();
		ClientDAO clientDao = new ClientDAO();
		DeptmentDAO deptmentDao = new DeptmentDAO();
		// 如果返回结果集不为空,则组装assetLend对象
		while (rs.next()) {
			assetLend = new AssetLend();
			assetLend.setId(rs.getInt("id"));
			assetLend.setAssetId(rs.getInt("assetId"));
			assetLend.setLendDate(rs.getString("lendDate"));
			assetLend.setGivebackPlanDate(rs.getString("givebackPlanDate"));
			assetLend.setLendEmployee(rs.getString("lendEmployee"));
			assetLend.setBorrowMan(rs.getString("borrowMan"));
			assetLend.setClientId(rs.getInt("clientId"));
			assetLend.setDeptmentId(rs.getInt("deptmentId"));
			assetLend.setGivebackDate(rs.getString("givebackDate"));
			assetLend.setState(rs.getInt("state"));
			assetLend.setAsset(assetDao.findById(rs.getInt("assetId")));
			assetLend.setClient(clientDao.findById(rs.getInt("clientId")));
			assetLend
					.setDeptment(deptmentDao.findById(rs.getInt("deptmentId")));
			list.add(assetLend);
		}
		return list;
	}

	/**
	 * 根据条件检索借出明细
	 * 
	 * @param assetLend
	 * @return
	 * @throws SQLException
	 */
	public List<AssetLend> list(AssetLend assetLend) throws SQLException {

		String sql = "Select * from assetLend,asset where asset.id=assetLend.assetId and 1=1 ";
		
		// 根据借出人检索
		String borrowMan = assetLend.getBorrowMan();
		if (borrowMan != null && !borrowMan.equals("")) {
			sql = sql + "  and borrowMan like '%" + borrowMan + "%'  ";
		}
		// 根据借出日期检索
		String lendDate = assetLend.getLendDate();
		if (lendDate != null && !lendDate.equals("")) {
			sql = sql + "  and lendDate like '%" + lendDate + "%'  ";
		}
		// 根据归还日期检索
		String givebackDate = assetLend.getGivebackDate();
		if (givebackDate != null && !givebackDate.equals("")) {
			sql = sql + "  and givebackDate like '%" + givebackDate + "%'  ";
		}
		// 根据资产的状态检索
		Integer state = assetLend.getState();
		if (state != null ) {
			sql = sql + "  and  assetLend.state  = " + state + "  ";
		}

		// 根据资产名称检索
		String assetName = assetLend.getAsset().getName();
		if (assetName != null && !assetName.equals("")) {

			sql = sql + "  and  asset.name like '%" + assetName + "%'  ";
		}
		
		// 根据资产代码检索
		String code = assetLend.getAsset().getCode();
		if (code != null && !code.equals("")) {

			sql = sql + "  and  asset.code like '%" + code + "%'  ";
		}

		ps = conn.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		AssetLend assetLend1 = null;
		List<AssetLend> list = new ArrayList<AssetLend>();
		AssetDAO assetDao = new AssetDAO();
		ClientDAO clientDao = new ClientDAO();
		// DeptmentDAO deptmentDao = new DeptmentDAO();
		// 如果返回结果集不为空,则组装assetLend对象
		while (rs.next()) {
			assetLend1 = new AssetLend();
			assetLend1.setId(rs.getInt("id"));
			assetLend1.setAssetId(rs.getInt("assetId"));
			assetLend1.setLendDate(rs.getString("lendDate"));
			assetLend1.setGivebackPlanDate(rs.getString("givebackPlanDate"));
			// assetLend1.setLendEmployee(rs.getString("lendEmployee"));
			assetLend1.setBorrowMan(rs.getString("borrowMan"));
			assetLend1.setClientId(rs.getInt("clientId"));
			// assetLend1.setDeptmentId(rs.getInt("deptmentId"));
			assetLend1.setGivebackDate(rs.getString("givebackDate"));
			assetLend1.setState(rs.getInt("state"));
			assetLend1.setAsset(assetDao.findById(rs.getInt("assetId")));
			assetLend1.setClient(clientDao.findById(rs.getInt("clientId")));
			// assetLend1.setDeptment(deptmentDao
			// .findById(rs.getInt("deptmentId")));
			list.add(assetLend1);
		}
		return list;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?