📄 outinventorybilldaoimpl.java
字号:
package com.cownew.PIS.inv.bizLayer;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.cownew.PIS.common.validator.IValidator;
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.IOutInventoryBillDAO;
import com.cownew.PIS.inv.common.InvAccountTypeEnum;
import com.cownew.PIS.inv.common.InvException;
import com.cownew.PIS.inv.common.OutInvBillStateEnum;
import com.cownew.PIS.inv.common.OutInventoryBillInfo;
import com.cownew.PIS.inv.common.OutInventoryBillValidator;
import com.cownew.ctk.common.DateUtils;
import com.cownew.ctk.common.ExceptionUtils;
/**
* 虽然目前出入库单的逻辑非常相似,但是不要玩无谓的继承,否则会很惨的!
* 此时使用复制粘贴代码是最好的,所以说不一定复制粘贴代码就是不好的
* @author 杨中科
*
*/
public class OutInventoryBillDAOImpl extends InvBaseDAOImpl implements
IOutInventoryBillDAO
{
public OutInventoryBillDAOImpl()
{
super();
}
protected void validateVO(IValueObject valueObject)
{
super.validateVO(valueObject);
IValidator validator = new OutInventoryBillValidator(
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,FBillId,FBillNumber,\n");
sb.append("FAccountDate,FBizDate,FInvAccountType,FQty,FAmount)\n");
sb.append("select billDetail.FMaterialId as FMaterialId,material.FName as FMaterialName,\n");
sb.append("material.FNumber as FMaterialNumber,billDetail.FHeadId as FBillId,billHead.FNumber as FBillNumber,\n");
sb.append("? as FAccountDate,billHead.FOutDate as FBizDate,? as FInvAccountType,\n");
sb.append("billDetail.FBaseQty as FQty,billDetail.FAmount as FAmount\n");
sb.append("from T_INV_OutInvBillDetail 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_OutInventoryBill billHead on \n");
sb.append("billDetail.FHeadId=billHead.FId\n");
sb.append("where billHead.FId=?\n");
// 因为ldbc不支持中文,所以"出库"两个字通过参数设置
try
{
ServerSQLExecutorUtils
.execute(sb.toString(), new Object[] {DateUtils.getSQLNow(),InvAccountTypeEnum.OUTINV.getName(),billId});
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
// 设置登帐标志,设置“登帐日期”为当前日期,日期取应用服务器的时间
String sql = "update T_INV_OutInventoryBill set FBillState=?,FAccountDate=? where FId=?";
try
{
ServerSQLExecutorUtils.execute(sql, new Object[] {
OutInvBillStateEnum.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_OutInventoryBill where FId=?",
new Object[] { billId });
rs.next();
String billState = rs.getString("FBillState");
return OutInvBillStateEnum.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_OutInventoryBill where FId=?",
new Object[] { billId });
rs.next();
return rs.getBoolean("FIsRedBill");
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
protected Class getPersistObjectClass()
{
return OutInventoryBillInfo.class;
}
public boolean isSavedState(String billId)
{
// 判断是否已经进行登帐等操作(即单据状态不为"保存")
KeyValueList kvList = new KeyValueList();
kvList.add("id", billId);
kvList.add("billState", OutInvBillStateEnum.SAVED.getName());
String oql = "from " + OutInventoryBillInfo.class.getName()
+ " where id=:id and billState=:billState";
return exists(oql, kvList);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -