📄 stockutil.java.svn-base
字号:
package com.casin.erp.util;
import java.util.List;
import com.casin.erp.Stock;
import com.waveline.webbuilder.dao.DaoFactory;
import com.waveline.webbuilder.exception.DataBaseException;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import com.casin.erp.InStock;
import com.casin.erp.OutStock;
import com.casin.erp.InStockDetail;
import com.casin.erp.ClientBaseInfo;
import com.casin.erp.Vendor;
import com.waveline.webbuilder.util.FunctionUtil;
import com.waveline.webbuilder.struts.ContentFormForm;
import com.waveline.webbuilder.exception.ProgramException;
import com.casin.erp.Product;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class StockUtil
{
protected static Log log;
private static List activedStockProductList = null;//可用库存产品列表
private static boolean asplRefresh = true;//可用库存产品列表更新标志
private static List activedCustomerList = null;//可用客户列表
private static boolean aclRefresh = true;//可用客户更新标志
private static List activedVendorList = null; //可用供应列表
private static boolean avlRefresh = true; //可用供应量更新标志
static
{
log = LogFactory.getLog(StockUtil.class);
}
/**
* 公开的获取可用库存产品列表接口
* @return List
*/
public List getProductList()
{
if(activedStockProductList == null || asplRefresh)
{
try
{
refreshStockProduct();
asplRefresh = false;
}
catch(Exception e)
{
log.warn("Exception in refresh active stock product list:" + e.getMessage());
}
}
return activedStockProductList;
}
/**
* 设置可用库存产品列表更新标志。当实际可用库存产品列表发生变化时,可通过设置此标志,通知列表使用者更新列表。
*/
public void setStockProductRefreshable()
{
asplRefresh = true;
}
/**
* 更新可用库存产品列表
* @throws DataBaseException
*/
private void refreshStockProduct()
throws DataBaseException
{
StringBuffer hql = new StringBuffer();
hql.append("SELECT mco FROM ").
append(Stock.class.getName()).
append(" as mco WHERE mco.status = 0 ORDER BY mco.name ASC");
activedStockProductList = DaoFactory.getContentDao().getAll(hql.toString());
}
/**
* 公开的获取可用客户列表接口
* @return List
*/
public List getCustomerList()
{
if(activedCustomerList == null || aclRefresh)
{
try
{
refreshCustomer();
aclRefresh = false;
}
catch(Exception e)
{
log.warn("Exception in refresh active customer list:" + e.getMessage());
}
}
return activedCustomerList;
}
/**
* 更新可用客户列表
* @throws DataBaseException
*/
private void refreshCustomer()
throws DataBaseException
{
StringBuffer hql = new StringBuffer();
hql.append("SELECT mco FROM ").
append(ClientBaseInfo.class.getName()).
append(" as mco ORDER BY mco.name ASC");
activedCustomerList = DaoFactory.getContentDao().getAll(hql.toString());
}
/**
* 设置可用客户列表更新标志。当实际可用客户列表发生变化时,可通过设置此标志,通知列表使用者更新列表。
*/
public void setCustomerRefreshable()
{
aclRefresh = true;
}
/**
* 公开的获取可用供应商列表接口
* @return List
*/
public List getVendorList()
{
if(activedVendorList == null || avlRefresh)
{
try
{
refreshVendor();
avlRefresh = false;
}
catch(Exception e)
{
log.warn("Exception in refresh active customer list:" + e.getMessage());
}
}
return activedVendorList;
}
/**
* 更新可用供应商列表
* @throws DataBaseException
*/
private void refreshVendor()
throws DataBaseException
{
StringBuffer hql = new StringBuffer();
hql.append("SELECT mco FROM ").
append(Vendor.class.getName()).
append(" as mco ORDER BY mco.companyName ASC");
activedVendorList = DaoFactory.getContentDao().getAll(hql.toString());
}
/**
* 设置可用供应商列表更新标志。当实际可用供应商列表发生变化时,可通过设置此标志,通知列表使用者更新列表。
*/
public void setVendorRefreshable()
{
avlRefresh = true;
}
public List getInStockList(Stock stock)
throws DataBaseException
{
if(stock == null || stock.getId() == null) return null;
StringBuffer hql = new StringBuffer();
hql.append("SELECT mco FROM ").append(InStock.class.getName()).append(" as mco join mco.stock as stock WHERE stock.id=").append(stock.getId());
return DaoFactory.getContentDao().getAll(hql.toString());
}
public int countInStockList(Stock stock)
throws DataBaseException
{
if(stock == null || stock.getId() == null) return -1;
StringBuffer hql = new StringBuffer();
hql.append("SELECT count(mco) FROM ").append(InStock.class.getName()).append(" as mco join mco.stock as stock WHERE stock.id=").append(stock.getId());
return DaoFactory.getContentDao().getCount(hql.toString());
}
public List getOutStockList(Stock stock)
throws DataBaseException
{
if(stock == null || stock.getId() == null) return null;
StringBuffer hql = new StringBuffer();
hql.append("SELECT mco FROM ").append(OutStock.class.getName()).append(" as mco join mco.stock as stock WHERE stock.id=").append(stock.getId());
return DaoFactory.getContentDao().getAll(hql.toString());
}
public int countOutStockList(Stock stock)
throws DataBaseException
{
if(stock == null || stock.getId() == null) return -1;
StringBuffer hql = new StringBuffer();
hql.append("SELECT count(mco) FROM ").append(OutStock.class.getName()).append(" as mco join mco.stock as stock WHERE stock.id=").append(stock.getId());
return DaoFactory.getContentDao().getCount(hql.toString());
}
public List getInStockDetailNameList(InStock inStock)
throws DataBaseException
{
if(inStock == null || inStock.getId() == null) return null;
StringBuffer hql = new StringBuffer();
hql.append("SELECT mco.name FROM ").append(InStockDetail.class.getName()).append(" as mco join mco.inStock as inStock WHERE inStock.id=").append(inStock.getId());
return DaoFactory.getContentDao().getAll(hql.toString());
}
public List getInStockDetailList(InStock inStock)
throws DataBaseException
{
if(inStock == null || inStock.getId() == null) return null;
StringBuffer hql = new StringBuffer();
hql.append("SELECT mco FROM ").append(InStockDetail.class.getName()).append(" as mco join mco.inStock as inStock WHERE inStock.id=").append(inStock.getId());
return DaoFactory.getContentDao().getAll(hql.toString());
}
public boolean outStock(OutStock outStock,
ContentFormForm contentFormForm,
Object session)
throws ProgramException, DataBaseException
{
Stock stock = (Stock) FunctionUtil.loadContentObject(Stock.class.
getName(), outStock.getStock().getId());
InStockDetail detail = (InStockDetail) FunctionUtil.loadContentObject(
InStockDetail.class.getName(), outStock.getDetail().getId());
if (outStock.getAmount().intValue() < 1)
{
contentFormForm.setRetMsg("出库数量必须是大于0的正整数。");
return false;
}
if (outStock.getAmount().intValue() > stock.getAmount().intValue())
{
contentFormForm.setRetMsg("库存产品数量不足。");
return false;
}
try
{
stock.setAmount(new Integer(stock.
getAmount().intValue() -
outStock.getAmount().intValue()));
FunctionUtil.update(stock, false, session);
}
catch (Exception ex)
{
contentFormForm.setRetMsg("核减库存产品数量出现异常");
return false;
}
//将产品序列号设置为“已被占用”
if(detail.getStatus() != null && detail.getStatus().intValue() == 1)
{
contentFormForm.setRetMsg("产品" + detail.getName() + "已经出库");
return false;
}
detail.setStatus(new Integer(1));
FunctionUtil.update(detail, false, session);
return true;
}
public boolean outStockRollback(OutStock outStock,
ContentFormForm contentFormForm,
Object session)
throws ProgramException, DataBaseException
{
Stock stock = (Stock) FunctionUtil.loadContentObject(Stock.class.
getName(), outStock.getStock().getId());
InStockDetail detail = (InStockDetail) FunctionUtil.loadContentObject(
InStockDetail.class.getName(), outStock.getDetail().getId());
try
{
stock.setAmount(new Integer(stock.
getAmount().intValue() +
outStock.getAmount().intValue()));
FunctionUtil.update(stock, false, session);
}
catch (Exception ex)
{
contentFormForm.setRetMsg("取消核减库存产品数量出现异常");
return false;
}
//将产品序列号恢复为“未占用”
detail.setStatus(new Integer(0));
FunctionUtil.update(detail, false, session);
return true;
}
public List getOutStockList(Product product)
throws DataBaseException
{
if(product == null || product.getId() == null) return null;
StringBuffer hql = new StringBuffer();
hql.append("SELECT mco FROM ").append(OutStock.class.getName()).append(" as mco WHERE mco.productSeriesNo='").append(product.getProductSeriesNo()).append("'");
return DaoFactory.getContentDao().getAll(hql.toString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -