📄 merchantgoodsstoragedao.java
字号:
/*
* 作者:刘云云
* 时间:2007年12月06日
* 功能:库存销售管理->商品管理->库存商品查询。
* 库存商品的分类浏览以及查询等功能
*/
package com.mole.struts.dao;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Iterator;
import com.mole.struts.bean.MerchantGoodsStorageBean;
import com.mole.struts.bean.MerchantGoodsTypeBean;
public class MerchantGoodsStorageDAO extends AbstractPageDAO {
private String typeId;// 商品类型
private String goodsName;// 商品名称
public MerchantGoodsStorageDAO() {
}
public MerchantGoodsStorageDAO(String column, String where, String id,
String group, String order, int pageSize) {
this.setColumnCondition(column);
this.setWhereCondition(where);
this.setIdCondition(id);
this.setGroupCondition(group);
this.setOrderCondition(order);
this.setPageSize(pageSize);
}
public void setWhere(String table, String storeId, String typeId,
String goodsName) {
this.typeId = typeId;
this.goodsName = goodsName;
String where = table + "WHERE StoreID=" + storeId;
if (typeId != null && !typeId.equals("0")) {
where = where + " AND goodsType=" + typeId;
}
if (goodsName != null && !goodsName.equals("")) {
where = where + " AND Name LIKE '%" + goodsName + "%' ";
}
this.setWhereCondition(where);
}
// 获取商品类型记录集
public MerchantGoodsTypeBean[] getGoodsType(String sql) {
ArrayList<Object[]> arrayList = this.executeQuery(sql);
MerchantGoodsTypeBean[] records = new MerchantGoodsTypeBean[arrayList
.size()];
Iterator<Object[]> it = arrayList.iterator();
int i = 0;
while (it.hasNext()) {
Object[] obj = it.next();
MerchantGoodsTypeBean record = new MerchantGoodsTypeBean();
record.setId(obj[0].toString());
record.setName(obj[1].toString());
records[i++] = record;
}
return records;
}
// 获取库存商品记录集
public MerchantGoodsStorageBean[] getGoodsStorageName(String sql) {
ArrayList<Object[]> arrayList = this.executeQuery(sql);
MerchantGoodsStorageBean[] records = new MerchantGoodsStorageBean[arrayList
.size()];
Iterator<Object[]> it = arrayList.iterator();
int i = 0;
while (it.hasNext()) {
Object[] obj = it.next();
MerchantGoodsStorageBean record = new MerchantGoodsStorageBean();
record.setName(obj[0].toString());
record.setType(obj[1].toString());
record.setId(obj[2].toString());
records[i++] = record;
}
return records;
}
// 获取库存商品记录集
public MerchantGoodsStorageBean[] getGoodsStoragePage() {
ArrayList<Object[]> arrayList = this.executeQuery(getSql());
if (arrayList == null)
return null;
MerchantGoodsStorageBean[] records = new MerchantGoodsStorageBean[arrayList
.size()];
Iterator<Object[]> it = arrayList.iterator();
int i = 0;
while (it.hasNext()) {
Object[] obj = it.next();
MerchantGoodsStorageBean record = new MerchantGoodsStorageBean();
record.setId(obj[0].toString());
record.setName(obj[1].toString());
record.setType(obj[2].toString());
record.setAmount(Integer.valueOf(obj[3].toString()));
record.setLastStockAmount(Integer.valueOf(obj[4].toString()));
record.setTotalAmount(Integer.valueOf(obj[5].toString()));
record.setStockDate(obj[6].toString().substring(0, 10));
records[i++] = record;
}
return records;
}
// 添加库存商品(存储过程)
public int executeStoredProcedure(String storeId, String merchantId,
String[] goodsNames, String[] amounts, String[] prices)
throws Exception {
CallableStatement stmt = null;
Connection conn = getConn();
try {
conn.setAutoCommit(true);
stmt = conn.prepareCall("{call sp_addGoodsStorage(?,?,?,?,?)}");
for (int i = 0; i < goodsNames.length; i++) {
stmt.setString(1, storeId);
stmt.setString(2, merchantId);
stmt.setString(3, goodsNames[i]);
stmt.setString(4, amounts[i]);
stmt.setString(5, prices[i]);
stmt.addBatch();
}
stmt.executeBatch();
return 1;
} finally {
if (stmt != null)
stmt.close();
}
}
public String getTypeId() {
return typeId;
}
public String getGoodsName() {
return goodsName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -