货位库存管理页面

货位库存管理页面

目的: 练习分页查询结构,了解tab分页显示方式,了解数据修改操作功能说明: 编写货位库存管理页面,支持货位间库存调整功能要求:

  • 编写货位库存管理界面,基于货位库存的维度展示数据
  • 页面存在tab分页,能够显示货品信息,显示该货品在指定仓库的所有其他货位信息
  • 搜索条件包括仓库,货品,单品,货位,库存量相关的常用搜索条件双击货位库存时打开货品属性页面
  • 右键功能移动货品,将选中货位库存,移动录入数量到指定的货位,并在仓库货品日志表中记录日志。非系统货位不允许负库存(不用考虑创建移位单,只需要修改货位库存即可)

c#代码

	[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
	{
		protected override void OnLoad()
		{

			this.BindAttach(new Dictionary
				{
					{"#stock_spec_list", "wms.StockSpec.queryStockPosition"},
					{"#goods_info", "goods.ApiGoods.getBySpecId"},
					{"#goods_other_position_info_list", "wms.StockSpec.getPositionInfoByGoodsNo"},
					{"#stock_spec_log_list", "wms.StockSpec.getLogAdapter"},

				});
		}
			
		[Click("#btn_search")]
		void OnClickSearch()
		{
			Alert(Q("#warehouse_list").GetHtml());
			var queryParams = this.ToQueryParam(".flat_bar");
			Q("#stock_spec_list").DbPageBind("wms.StockSpec.queryStockPosition", queryParams);
		}

		// 双击查看货品属性信息
		[DblClickTR("#stock_spec_list")]
		void OnClickGoodsDetail()
		{
			var tr = Q("#stock_spec_list > tr:checked");

			if(tr == null)
			{
				return ;
			}

			var goodsID = tr.GetData("goods_id");
			DoModal(default(GoodsEditWindow), new GoodsEditParams{goodsId=goodsID, view=true});
		}

		// 货位库存列表中的一列被单击时的回调函数
		// 单击展示对应货位的tab分页
		[ClickTR("#stock_spec_list")]
		void OnClickGoodsList()
		{
			var tr = Q("#stock_spec_list>tr:checked");

			if (tr == null)
			{
				return ;
			}

			var stockSpecPoId = tr.RecId();
			var goodsId = tr.GetData("goods_id");
			var positionId = tr.GetData("position_id");
			var warehouseId = Q("[qp=warehouse_id]").IntegerValue;

			// 展示对应货位的tab分页
			this.BindTab("#bottom_tabs", (Action)OnBindTab, stockSpecPoId, goodsId, warehouseId, positionId);
		}


		//点击tab
		[Expanded("#bottom_tabs")]
		void OnBottomTabsSwitch()
		{
			OnClickGoodsList();
		}

		void OnBindTab(string name, Element el, long stockSpecPoId, int goodsId, int warehouseId, int positionId)
		{
			switch(name)
			{
				case "goods_info":
					{
						el.Q("#goods_info").DbBind("wms.StockSpec.getGoodsInfoByGoodsId", goodsId);
						break;
					}
				case "goods_other_position_info":
					{
						el.Q("#goods_other_position_info_list").DbPageBind("wms.StockSpec.getPositionInfoByGoodsNo", goodsId, warehouseId, positionId);
						break;
					}
				case "stock_spec_log":
					{
						el.Q("#stock_spec_log_list").DbPageBind("wms.StockSpec.getLog",stockSpecPoId);
						break;
					}
			}
		}

		[Command("#menu_stock_move")]
		void onClickStockBatchMove() {

			// 获取仓库ID
			int warehouseId = Q("#warehouse_list").IntegerValue;

			var tr = Q("#stock_spec_list > tr:checked");

			if(tr == null)
			{
				Alert("请选择货位");
				return ;
			}

			if(tr.GetData("position_id") < 0)
			{
				Alert("系统货位禁止移位");
				return ;
			}

			var arg = new PositionSelectParams{
				WarehouseId=warehouseId,
				SpecId = tr.GetData("spec_id"),
				Defect = tr.GetData("defect"),
				ZoneType = tr.GetData("zone_type"),
				ZoneId = tr.GetData("zone_id"),
				stockSpecPoId = tr.RecId(),
				PositionNO = tr.Field("position_no").StringValue,
				PositionId = tr.GetData("position_id"),
			};
			DoModal(default(PositionSelectWindow), arg);
		}
	}

}

 
  

总体来说:
1、这段代码实现了一个图形用户界面(GUI)窗口,与后端数据进行交互,包括搜索、双击查看货品详情、选项卡切换和执行库存移动等功能
2、具体的一些细节逻辑包括将后端查询到数据绑定到页面元素展示给用户、页面之间的参数传递。

java代码页面查询

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);
	}

总的来说是,是根据搜索条件包括仓库,货品,单品,货位,库存量相关的常用搜索条件,对库存的分页查询,并返回到客户端

java代码货品信息的分页功能

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);
	}

java代码查询同仓库不同货位的信息分页

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);
	}

java获取当前货位的日志信息

	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);
	}

java移动货位操作

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、原货位减库存、 目标货位加库存、日志内容拼接、在仓库货品日志表中记录日志

你可能感兴趣的:(java)