目的: 练习分页查询结构,了解tab分页显示方式,了解数据修改操作功能说明: 编写货位库存管理页面,支持货位间库存调整功能要求:
[Window(View="stock/stock_query/stock_position_query.html", Title="货位库存管理", Style=Style.WS_VISIBLE|Style.WS_CLIPCHILDREN|Style.WS_CHILD, Width=1024, Height=768)]
class StockPositionQueryWindow : BaseWindow
总体来说:
1、这段代码实现了一个图形用户界面(GUI)窗口,与后端数据进行交互,包括搜索、双击查看货品详情、选项卡切换和执行库存移动等功能
2、具体的一些细节逻辑包括将后端查询到数据绑定到页面元素展示给用户、页面之间的参数传递。
stockSpecService.queryPosition
public Response queryPosition(Session session, Map params, List noList, Pager pager)
throws SQLException, AppException
{
// 检查仓库权限
short warehouseId = MapUtils.getShort(params, "warehouse_id", Const.SHORT_ZERO);
WmsUtils.assertWarehouseRight(session, warehouseId);
DbSession db = session.db(false);
int zoneID = MapUtils.getInt(params, "zone_id", -1);
BigDecimal lowNum = MapUtils.getDec(params, "low_num", BigDecimal.ZERO);
boolean isDefault = MapUtils.getBool(params, "is_default", false);
// 排序方式
int sortPattern = MapUtils.getInt(params, "sort_pattern", 0);
// 货位
String positionNo = MapUtils.getString(params, "position_no", null);
// 货品分类
String classId = ConvertUtils.toString(params.get("class_id"));
String classPath;
if (classId != null)
classPath = db.get("SELECT path FROM goods_class where class_id=?", classId);
else
classPath = "";
Where where = new Where(params, session)
{
{
equalValue("ssp.warehouse_id", warehouseId);
equalOrLike("goods_spec_no_likeq", "spec_no", "gs.spec_no");
equalOrLike("goods_goods_no_likeq", "goods_no", "gg.goods_no");
likeAnyDisOrder("goods_name", "gg.goods_name");
equal("defect", "ssp.defect");
equal("spec_name", "gs.spec_name");
equal("barcode", "gb.barcode");
in("brand_id", "gg.brand_id");
likeValue("gc.path", classPath);
if (zoneID > 0)
equal("zone_id", "cwz.zone_id");
//特殊货位
if (zoneID == 0)
condition("cwp.rec_id<0");
if (StringUtils.isNotEmpty(positionNo) && !"全部".equals(positionNo))
{
if ("非特殊货位".equals(positionNo))
this.condition("cwp.rec_id>0");
else
equal("position_no", "cwp.position_no");
}
if (isDefault)
{
this.condition("sgdp.rec_id>0");
}
switch (this.param("stock_num_type", -1))
{
case 0:
lessValue("stock_num", lowNum);
break;
case 1:
equalValue("stock_num", lowNum);
break;
case 2:
greatValue("stock_num", lowNum);
break;
default:
break;
}
if (noList != null && noList.size() > 0)
inValues("gs.spec_no", noList);
}
}.orderBy("gs.goods_id,gs.spec_no ASC,ssp.rec_id DESC");
switch (sortPattern)
{
case 0:
where.orderBy("gs.goods_id,gs.spec_id,ssp.rec_id DESC");
break;
case 1:
where.orderBy("gs.goods_id,gs.spec_no ASC,ssp.rec_id DESC");
break;
case 2:
where.orderBy("gs.goods_id,gs.spec_no DESC,ssp.rec_id DESC");
break;
default:
where.orderBy("gs.goods_id,gs.spec_id,ssp.rec_id DESC ");
}
String on = "ssp.warehouse_id = ssd.warehouse_id and ssp.position_id = ssd.position_id and ssp.spec_id = ssd.spec_id";
Table table = new Table("stock_spec_position ssp", "ssp.rec_id", where)
{
{
leftJoin("goods_spec gs", "gs.spec_id = ssp.spec_id", "gs.,gg.");
leftJoin("goods_goods gg", "gg.goods_id = gs.goods_id", "gg.,gc.");
innerJoin("goods_class gc", "gc.class_id=gg.class_id", "gc.");
leftJoin("cfg_warehouse_position cwp", "cwp.rec_id=ssp.position_id", "cwp.,cwz.");
leftJoin("cfg_warehouse_zone cwz", "cwz.zone_id=cwp.zone_id", "cwz.");
leftJoin("stock_goods_default_position sgdp",
"ssp.warehouse_id=sgdp.warehouse_id AND ssp.position_id=sgdp.position_id AND sgdp.type=" + GoodsMerchantNo.TYPE_GOODS_SPEC + " AND sgdp.target_id=ssp.spec_id AND ssp.defect = sgdp.defect",
"sgdp.");
leftJoin("goods_barcode gb",
"gb.type=" + GoodsMerchantNo.TYPE_GOODS_SPEC + " AND gb.target_id= ssp.spec_id", "gb.");
}
}.extraJoin("goods_spec gs", "gs.spec_id = ssp.spec_id")
.extraJoin("goods_goods gg", "gg.goods_id = gs.goods_id")
.extraJoin("cfg_warehouse_position cwp", "cwp.rec_id=ssp.position_id")
.extraJoin("stock_goods_default_position sgdp",
"ssp.warehouse_id = sgdp.warehouse_id AND ssp.position_id=sgdp.position_id AND sgdp.type=" + GoodsMerchantNo.TYPE_GOODS_SPEC + " AND sgdp.target_id=ssp.spec_id AND ssp.defect = sgdp.defect")
.extraJoin("stock_spec_detail ssd", on);
//String fields = "ssp.rec_id,ssp.spec_id,ssp.defect,ssp.stock_num,IFNULL(sgdp.to_move_num,0) AS to_move_num,gs.spec_no,gs.spec_code,gs.spec_name," + "gg.goods_no,gg.goods_name,gg.short_name,cwp.position_no,IF(sgdp.rec_id>0,1,0) is_default,cwp.zone_id,gg.brand_id";
String fields = "ssp.rec_id,ssp.spec_id,ssp.defect,ssp.warehouse_id, ssp.position_id,ssp.stock_num,"
+ "ssd.zone_type, ssd.zone_id, ssd.expire_date, ssd.reserve_num, ssd.remark, ssd.last_pd_time, ssd.last_inout_time," + "gs.goods_id,gs.spec_no,gs.spec_code,gs.spec_name," + "cwp.position_no," + "gg.goods_no,gg.goods_name,gg.short_name,gg.brand_id," + "IFNULL(sgdp.to_move_num,0) AS to_move_num,IF(sgdp.rec_id>0,1,0) is_default";
table.setOutputFields(fields);
return SqlUtils.pageQuery(db, pager, table, where);
}
总的来说是,是根据搜索条件包括仓库,货品,单品,货位,库存量相关的常用搜索条件,对库存的分页查询,并返回到客户端
public Response getGoodsInfoByGoodsId(Session session, int goodsId) throws SQLException
{
DbSession db = session.db(false);
String querySql = "select * from goods_goods where goods_id = ?";
return db.query(querySql, goodsId);
}
public Response getPositionInfoByGoodsNo(Session session, int goodsId, short warehouseId, int positionId,
Pager pager) throws SQLException
{
DbSession db = session.db(false);
Where where = new Where(null, session)
{
{
equalValue("ssp.warehouse_id", warehouseId);
notEqualValue("ssp.position_id", positionId);
equalValue("gs.goods_id", goodsId);
}
}.orderBy("ssp.rec_id desc");
String on = "ssp.warehouse_id = ssd.warehouse_id and ssp.position_id = ssd.position_id and ssp.spec_id = ssd.spec_id";
Table table = new Table("stock_spec_position ssp", "ssp.rec_id", where)
{
{
innerJoin("goods_spec gs", "gs.spec_id = ssp.spec_id", true);
}
}.extraJoin("cfg_warehouse_position cwp", "cwp.rec_id=ssp.position_id").extraJoin("stock_spec_detail ssd", on);
String fields = "ssp.rec_id, ssp.spec_id, ssp.defect, ssp.position_id, ssp.warehouse_id, " + "ssd.zone_type, ssd.zone_id, ssd.expire_date, ssd.reserve_num, ssd.stock_num, ssd.remark, ssd.last_pd_time, ssd.last_inout_time," + "cwp.position_no";
table.setOutputFields(fields);
return SqlUtils.pageQuery(db, pager, table, where);
}
public Response getLog(Session session, int stockSpecPoId, Pager pager) throws SQLException
{
DbSession db = session.db(false);
Where where = new Where(null, session)
{
{
equalValue("sspl.ssp_id", stockSpecPoId);
}
}.orderBy("sspl.rec_id desc");
Table table = new Table("stock_spec_position_log sspl", "sspl.rec_id", where);
String fields = "sspl.*";
table.setOutputFields(fields);
return SqlUtils.pageQuery(db, pager, table, where);
}
ublic void movePosition(Session session, Map params) throws SQLException, AppException
{
DbSession db = session.db(false);
// 移位的数量
BigDecimal stockNum = MapUtils.getDec(params, "stock_num");
// 仓库id
int warehouseId = MapUtils.getInt(params, "warehouse_id");
// 原货位id
int oldPositionId = MapUtils.getInt(params, "old_position_id");
// 目标货位id
int newPositionId = MapUtils.getInt(params, "new_position_id");
// 原货位编码
String oldPositionNo = MapUtils.getString(params, "old_position_no");
// 目标货位编码
String newPositionNo = MapUtils.getString(params, "new_position_no");
// 单品id
int specId = MapUtils.getInt(params, "spec_id");
// stock_spec_position 主键,用于在仓库货品日志表中记录日志
int stockSpecPoId = MapUtils.getInt(params, "stock_spec_po_id");
int defeat = MapUtils.getInt(params, "defeat");
// 开启一个新的事务
db.startTx();
String where = "where warehouse_id = ? and position_id = ? and spec_id = ? and defect = ?";
// 货位不允许负库存
StockSpecPosition stockSpecPosition = db.query("select * from stock_spec_position" + where + " FOR UPDATE",
StockSpecPosition.class, warehouseId, oldPositionId, specId);
if (stockSpecPosition == null)
{
throw new AppException("货位不存在");
}
if (oldPositionId < 0 && stockSpecPosition.getStockNum().compareTo(stockNum) < 0)
{
throw new AppException("货位不允许负库存");
}
// 原货位减库存
db.update("update stock_spec_position set stock_num = stock_num - ?" + where, stockNum, warehouseId,
oldPositionId, specId, defeat);
// 目标货位加库存
db.update("update stock_spec_position set stock_num = stock_num + ?" + where, stockNum, warehouseId,
newPositionId, specId, defeat);
// 日志内容
String remark = oldPositionNo + "--->" + newPositionNo + ",数量为" + stockNum;
// 在仓库货品日志表中记录日志
db.insert("INSERT INTO stock_spec_position_log(ssp_id,remark,operator_id)" + " VALUES(?,?,?)", stockSpecPoId,
remark, session.getUserId());
// 提交事务
db.commit();
}
解释:
1、开启事务:
2、获取原货位信息,判断是否存在、不存在抛出异常。
3、判断原货位数量是否满足操作数量,不满足报错
4、原货位减库存、 目标货位加库存、日志内容拼接、在仓库货品日志表中记录日志