📄 ininventorybilldaoimpl.java
字号:
package com.cownew.PIS.inv.bizLayer;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.cownew.PIS.framework.common.IValueObject;
import com.cownew.PIS.framework.common.utils.KeyValueList;
import com.cownew.PIS.framework.server.helper.ServerMetaDataLoaderFactory;
import com.cownew.PIS.framework.server.helper.ServerSQLExecutorUtils;
import com.cownew.PIS.inv.common.IInInventoryBillDAO;
import com.cownew.PIS.inv.common.InInvBillStateEnum;
import com.cownew.PIS.inv.common.InInventoryBillInfo;
import com.cownew.PIS.inv.common.InInventoryBillValidator;
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 InInventoryBillDAOImpl extends InvBaseDAOImpl implements
IInInventoryBillDAO
{
public InInventoryBillDAOImpl()
{
super();
}
protected void validateVO(IValueObject valueObject)
{
super.validateVO(valueObject);
InInventoryBillValidator validator = new InInventoryBillValidator(
ServerMetaDataLoaderFactory.getLoader(), this);
validator.validate(valueObject);
}
public void accountBill(String billId)
{
// 判断是否重复登帐
if (hasAccounted(billId))
{
throw new InvException(InvException.ALREADYACCOUNT);
}
// 使用insert ...select 语句批量登帐
StringBuffer sb = new StringBuffer();
sb.append("insert into T_INV_InvAccount(\n");
sb.append("FMaterialId,FMaterialName,FMaterialNumber,\n");
sb.append("FBillId,FBillNumber,\n");
sb.append("FAccountDate,FBizDate,FInvAccountType,FQty,FAmount)\n");
sb.append("select billDetail.FMaterialId as FMaterialId,\n");
sb.append("material.FName as FMaterialName,\n");
sb.append("material.FNumber as FMaterialNumber,\n");
sb.append("billDetail.FHeadId as FBillId,\n");
sb.append("billHead.FNumber as FBillNumber,\n");
sb.append("? as FAccountDate,billHead.FInDate as FBizDate,\n");
sb.append("? as FInvAccountType,\n");
sb.append("billDetail.FBaseQty as FQty,\n");
sb.append("billDetail.FAmount as FAmount\n");
sb.append("from T_INV_InInvBillDetail billDetail\n");
sb.append("inner join T_BD_Material material on \n");
sb.append("billDetail.FMaterialId=material.FId\n");
sb.append("inner join T_INV_InInventoryBill billHead on \n");
sb.append("billDetail.FHeadId=billHead.FId\n");
sb.append("where billHead.FId=?\n");
try
{
ServerSQLExecutorUtils.execute(sb.toString(), new Object[] {
DateUtils.getSQLNow(), InvAccountTypeEnum.ININV.getName(),
billId });
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
// 设置登帐标志,设置“登帐日期”为当前日期,日期取应用服务器的时间
StringBuffer sbUpdate = new StringBuffer();
sbUpdate.append("update T_INV_InInventoryBill\n");
sbUpdate.append("set FBillState=?,FAccountDate=?\n");
sbUpdate.append("where FId=?\n");
try
{
ServerSQLExecutorUtils.execute(sbUpdate.toString(), new Object[] {
InInvBillStateEnum.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_InInventoryBill where FId=?",
new Object[] { billId });
rs.next();
String billState = rs.getString("FBillState");
return InInvBillStateEnum.ACCOUNTED.getName().equals(billState);
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
public boolean isRedBill(String billId)
{
try
{
ResultSet rs = ServerSQLExecutorUtils.executeQuery(
"select FIsRedBill from T_INV_InInventoryBill where FId=?",
new Object[] { billId });
rs.next();
return rs.getBoolean("FIsRedBill");
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
protected Class getPersistObjectClass()
{
return InInventoryBillInfo.class;
}
public boolean isSavedState(String billId)
{
// 判断是否已经进行登帐等操作(即单据状态不为"保存")
KeyValueList kvList = new KeyValueList();
kvList.add("id", billId);
kvList.add("billState", InInvBillStateEnum.SAVED.getName());
String oql = "from " + InInventoryBillInfo.class.getName()
+ " where id=:id and billState=:billState";
return exists(oql, kvList);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -