⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countinventorybilldao.java

📁 《j2ee开发全程实录》随书源码
💻 JAVA
字号:
package com.cownew.PIS.inv.bizLayer;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.lang.enums.EnumUtils;


import com.cownew.PIS.framework.common.utils.KeyValueList;
import com.cownew.PIS.framework.server.helper.ServerSQLExecutorUtils;
import com.cownew.PIS.inv.common.CountInvBillStateEnum;
import com.cownew.PIS.inv.common.CountInvTypeEnum;
import com.cownew.PIS.inv.common.CountInventoryBillInfo;
import com.cownew.PIS.inv.common.ICountInventoryBillDAO;
import com.cownew.PIS.inv.common.InvAccountTypeEnum;
import com.cownew.PIS.inv.common.InvException;
import com.cownew.ctk.common.DateUtils;
import com.cownew.ctk.common.ExceptionUtils;

public class CountInventoryBillDAO extends InvBaseDAOImpl implements
		ICountInventoryBillDAO
{

	public CountInventoryBillDAO() 
	{
		super();
	}

	protected Class getPersistObjectClass()
	{
		return CountInventoryBillInfo.class;
	}

	public void accountBill(String billId) 
	{
		// 判断是否重复登帐
		if (hasAccounted(billId))
		{
			throw new InvException(InvException.ALREADYACCOUNT);
		}

		CountInventoryBillInfo countBillInfo = (CountInventoryBillInfo) loadByPK(billId);

		CountInvTypeEnum countInvType = (CountInvTypeEnum) EnumUtils.getEnum(
				CountInvTypeEnum.class, countBillInfo.getCountType());

		InvAccountTypeEnum invAccountType = null;
		if (countInvType == CountInvTypeEnum.EARN)
		{
			invAccountType = InvAccountTypeEnum.COUNTININV;
		} else if (countInvType == CountInvTypeEnum.LOSE)
		{
			invAccountType = InvAccountTypeEnum.COUNTOUTINV;
		}

		StringBuffer sbSQL = new StringBuffer();
		sbSQL.append("insert into T_INV_InvAccount(\n");
		sbSQL
				.append("FMaterialId,FMaterialName,FMaterialNumber,FBillId,FBillNumber,\n");
		sbSQL.append("FAccountDate,FBizDate,FInvAccountType,FQty,FAmount)\n");
		sbSQL
				.append("select billDetail.FMaterialId as FMaterialId,material.FName as FMaterialName,\n");
		sbSQL
				.append("material.FNumber as FMaterialNumber,billDetail.FHeadId as FBillId,billHead.FNumber as FBillNumber,\n");
		sbSQL
				.append("? as FAccountDate,billHead.FCountDate as FBizDate,? as FInvAccountType,\n");
		sbSQL.append("billDetail.FBaseQty as FQty,0 as FAmount\n");
		sbSQL.append("from T_INV_CountInvBillDetail  billDetail\n");
		sbSQL.append("inner join T_BD_Material  material on \n");
		sbSQL.append("billDetail.FMaterialId=material.FId\n");
		sbSQL.append("inner join T_INV_CountInventoryBill  billHead on \n");
		sbSQL.append("billDetail.FHeadId=billHead.FId\n");
		sbSQL.append("where billHead.FId=?\n");

		// 盘平无需登帐
		if (countInvType != CountInvTypeEnum.BALANCE)
		{
			try
			{
				ServerSQLExecutorUtils.execute(sbSQL.toString(), new Object[] {
						DateUtils.getSQLNow(), invAccountType.getName(),billId });
			} catch (SQLException e)
			{
				throw ExceptionUtils.toRuntimeException(e);
			}
		}

		// 设置登帐标志,设置“登帐日期”为当前日期,日期取应用服务器的时间
		String sql = "update T_INV_CountInventoryBill set FBillState=?,FAccountDate=? where FId=?";
		try
		{
			ServerSQLExecutorUtils.execute(sql, new Object[] {
					CountInvBillStateEnum.ACCOUNTED.getName(),
					DateUtils.getSQLNow(), billId });
		} catch (SQLException e)
		{
			throw ExceptionUtils.toRuntimeException(e);
		}
	}

	public boolean hasAccounted(String billId) 
	{
		try
		{
			ResultSet rs = ServerSQLExecutorUtils
					.executeQuery(
							"select FBillState from T_INV_CountInventoryBill where FId=?",
							new Object[] { billId });
			rs.next();
			String billState = rs.getString("FBillState");
			return CountInvBillStateEnum.ACCOUNTED.getName().equals(billState);
		} catch (SQLException e)
		{
			throw ExceptionUtils.toRuntimeException(e);
		}
	}

	public boolean isSavedState(String billId) 
	{
		// 判断是否已经进行登帐等操作(即单据状态不为"保存")
		KeyValueList kvList = new KeyValueList();
		kvList.add("id", billId);
		kvList.add("billState", CountInvBillStateEnum.SAVED.getName());
		String oql = "from " + CountInventoryBillInfo.class.getName()
				+ " where id=:id and billState=:billState";
		return exists(oql, kvList);
	}

}

⌨️ 快捷键说明

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