@ -1,70 +1,99 @@
<?xml version="1.0" encoding="UTF-8" ?>
< !DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace= "com.hw.wms.mapper.WmsProductStockMapper" >
<resultMap type= "WmsProductStock" id= "WmsProductStockResult" >
<result property= "productStockId" column= "product_stock_id" />
<result property= "warehouseId" column= "warehouse_id" />
<result property= "warehouseFloor" column= "warehouse_floor" />
<result property= "locationCode" column= "location_code" />
<result property= "stockType" column= "stock_type" />
<result property= "productBatch" column= "product_batch" />
<result property= "qualityStatus" column= "quality_status" />
<result property= "productId" column= "product_id" />
<result property= "planCode" column= "plan_code" />
<result property= "planDetailCode" column= "plan_detail_code" />
<result property= "saleOrderId" column= "sale_order_id" />
<result property= "saleorderCode" column= "saleorder_code" />
<result property= "totalAmount" column= "total_amount" />
<result property= "frozenAmount" column= "frozen_amount" />
<result property= "occupyAmount" column= "occupy_amount" />
<result property= "createBy" column= "create_by" />
<result property= "createDate" column= "create_date" />
<result property= "updateBy" column= "update_by" />
<result property= "updateDate" column= "update_date" />
<result property= "activeFlag" column= "active_flag" />
<result property= "instockDate" column= "instock_date" />
<result property= "materialCode" column= "material_code" />
<result property= "materialName" column= "material_name" />
<result property= "orderAmount" column= "order_amount" />
<result property= "warehouseName" column= "warehouse_name" />
<result property= "applyAmount" column= "apply_amount" />
<result property= "productStockId" column= "product_stock_id" />
<result property= "warehouseId" column= "warehouse_id" />
<result property= "warehouseFloor" column= "warehouse_floor" />
<result property= "locationCode" column= "location_code" />
<result property= "stockType" column= "stock_type" />
<result property= "productBatch" column= "product_batch" />
<result property= "qualityStatus" column= "quality_status" />
<result property= "productId" column= "product_id" />
<result property= "planCode" column= "plan_code" />
<result property= "planDetailCode" column= "plan_detail_code" />
<result property= "saleOrderId" column= "sale_order_id" />
<result property= "saleorderCode" column= "saleorder_code" />
<result property= "totalAmount" column= "total_amount" />
<result property= "frozenAmount" column= "frozen_amount" />
<result property= "occupyAmount" column= "occupy_amount" />
<result property= "createBy" column= "create_by" />
<result property= "createDate" column= "create_date" />
<result property= "updateBy" column= "update_by" />
<result property= "updateDate" column= "update_date" />
<result property= "activeFlag" column= "active_flag" />
<result property= "instockDate" column= "instock_date" />
<result property= "materialCode" column= "material_code" />
<result property= "materialName" column= "material_name" />
<result property= "orderAmount" column= "order_amount" />
<result property= "warehouseName" column= "warehouse_name" />
<result property= "applyAmount" column= "apply_amount" />
</resultMap>
<sql id= "selectWmsProductStockVo" >
select product_stock_id, warehouse_id, location_code, stock_type, product_batch, quality_status, product_id, plan_code, plan_detail_code,sale_order_id,saleorder_code, total_amount, frozen_amount, occupy_amount, create_by, create_date, update_by, update_date, active_flag, instock_date from wms_product_stock
select wps.product_stock_id,
wps.warehouse_id,
wbw.warehouse_name,
wbw.warehouse_floor,
wps.location_code,
wps.stock_type,
wps.product_batch,
wps.quality_status,
wps.product_id,
mbmi.material_code,
mbmi.material_name,
wps.plan_code,
wps.plan_detail_code,
wps.sale_order_id,
wps.saleorder_code,
wps.total_amount,
wps.frozen_amount,
wps.occupy_amount,
wps.create_by,
wps.create_date,
wps.update_by,
wps.update_date,
wps.active_flag,
wps.instock_date
from wms_product_stock wps
left join wms_base_warehouse wbw on wbw.warehouse_id = wps.warehouse_id
left join mes_base_material_info mbmi on mbmi.material_id = wps.product_id
</sql>
<select id= "selectWmsProductStockList" parameterType= "WmsProductStock" resultMap= "WmsProductStockResult" >
<include refid= "selectWmsProductStockVo" />
<where >
<if test= "warehouseId != null " > and warehouse_id = #{warehouseId}</if>
<if test= "locationCode != null and locationCode != ''" > and location_code = #{locationCode}</if>
<if test= "stockType != null and stockType != ''" > and stock_type = #{stockType}</if>
<if test= "productBatch != null and productBatch != ''" > and product_batch = #{productBatch}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and quality_status = #{qualityStatus}</if>
<if test= "productId != null " > and product_id = #{productId}</if>
<if test= "planCode != null " > and plan_code = #{planCode}</if>
<if test= "planDetailCode != null " > and plan_detail_code = #{planDetailCode}</if>
<if test= "saleorderCode != null " > and saleorder_code = #{saleorderCode}</if>
<if test= "totalAmount != null " > and total_amount = #{totalAmount}</if>
<if test= "frozenAmount != null " > and frozen_amount = #{frozenAmount}</if>
<if test= "occupyAmount != null " > and occupy_amount = #{occupyAmount}</if>
<if test= "createDate != null " > and create_date = #{createDate}</if>
<if test= "updateDate != null " > and update_date = #{updateDate}</if>
<if test= "activeFlag != null and activeFlag != ''" > and active_flag = #{activeFlag}</if>
<if test= "instockDate != null " > and instock_date = #{instockDate}</if>
<if test= "warehouseId != null " > and wps.warehouse_id = #{warehouseId}</if>
<if test= "locationCode != null and locationCode != ''" > and wps.location_code = #{locationCode}</if>
<if test= "stockType != null and stockType != ''" > and wps.stock_type = #{stockType}</if>
<if test= "productBatch != null and productBatch != ''" > and wps.product_batch = #{productBatch}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and wps.quality_status = #{qualityStatus}</if>
<if test= "productId != null " > and wps.product_id = #{productId}</if>
<if test= "planCode != null " > and wps.plan_code = #{planCode}</if>
<if test= "planDetailCode != null " > and wps.plan_detail_code = #{planDetailCode}</if>
<if test= "saleorderCode != null " > and wps.saleorder_code = #{saleorderCode}</if>
<if test= "totalAmount != null " > and wps.total_amount = #{totalAmount}</if>
<if test= "frozenAmount != null " > and wps.frozen_amount = #{frozenAmount}</if>
<if test= "occupyAmount != null " > and wps.occupy_amount = #{occupyAmount}</if>
<if test= "updateDate != null " > and wps.update_date = #{updateDate}</if>
<if test= "activeFlag != null and activeFlag != ''" > and wps.active_flag = #{activeFlag}</if>
<if test= "instockDate != null " > and wps.instock_date = #{instockDate}</if>
<if test= "params.beginCreateDate != null and params.beginCreateDate != '' and params.endCreateDate != null and params.endCreateDate != ''" >
and wps.create_date between #{params.beginCreateDate} and #{params.endCreateDate}
</if>
</where>
</select>
<select id= "selectWmsProductStockByProductStockId" parameterType= "Long" resultMap= "WmsProductStockResult" >
<include refid= "selectWmsProductStockVo" />
where product_stock_id = #{productStockId}
where wps. product_stock_id = #{productStockId}
</select>
<insert id= "insertWmsProductStock" parameterType= "WmsProductStock" useGeneratedKeys= "true" keyProperty= "productStockId" >
<insert id= "insertWmsProductStock" parameterType= "WmsProductStock" useGeneratedKeys= "true"
keyProperty="productStockId">
insert into wms_product_stock
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "warehouseId != null" > warehouse_id,</if>
@ -86,7 +115,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test= "updateDate != null" > update_date,</if>
<if test= "activeFlag != null" > active_flag,</if>
<if test= "instockDate != null" > instock_date,</if>
</trim>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "warehouseId != null" > #{warehouseId},</if>
<if test= "warehouseFloor != null" > #{warehouseFloor},</if>
@ -107,7 +136,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test= "updateDate != null" > #{updateDate},</if>
<if test= "activeFlag != null" > #{activeFlag},</if>
<if test= "instockDate != null" > #{instockDate},</if>
</trim>
</trim>
</insert>
<update id= "updateWmsProductStock" parameterType= "WmsProductStock" >
@ -136,7 +165,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id= "deleteWmsProductStockByProductStockId" parameterType= "Long" >
delete from wms_product_stock where product_stock_id = #{productStockId}
delete
from wms_product_stock
where product_stock_id = #{productStockId}
</delete>
<delete id= "deleteWmsProductStockByProductStockIds" parameterType= "String" >
@ -147,17 +178,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<select id= "getProductStockTotalAmount" resultType= "BigDecimal" parameterType= "WmsProductStock" >
select sum(total_amount) from wms_product_stock
<where >
<if test= "locationCode != null and locationCode != ''" > and location_code = #{locationCode}</if>
<if test= "locationCode != null and locationCode != ''" > and location_code = #{locationCode}</if>
and total_amount > 0
</where>
</select>
@ -169,12 +193,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id= "selectProductStockByLocationAndBatchAndSaleOrderId" resultMap= "WmsProductStockResult" >
<include refid= "selectWmsProductStockVo" />
where location_code = #{locationCode} and product_batch = #{productBatch} and sale_order_id=#{saleOrderId} and stock_type = #{stockType}
where location_code = #{locationCode} and product_batch = #{productBatch} and sale_order_id=#{saleOrderId} and
stock_type = #{stockType}
</select>
<select id= "selectWmsProductStockInList" parameterType= "WmsProductStock" resultMap= "WmsProductStockResult" >
<include refid= "selectWmsProductStockVo" />
<where >
@ -197,45 +220,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id= "selectWmsProductStockJoinList" parameterType= "WmsProductStock" resultMap= "WmsProductStockResult" >
select wps.product_stock_id, wps.warehouse_id, wps.location_code, wps.stock_type, wps.product_batch, wps.quality_status, wps.product_id,
wps.plan_code, wps.plan_detail_code, wps.total_amount, wps.frozen_amount, wps.occupy_amount, wps.active_flag, wps.instock_date,
select wps.product_stock_id, wps.warehouse_id, wps.location_code, wps.stock_type, wps.product_batch,
wps.quality_status, wps.product_id,
wps.plan_code, wps.plan_detail_code, wps.total_amount, wps.frozen_amount, wps.occupy_amount, wps.active_flag,
wps.instock_date,
mai.material_code,mai.material_name
from wms_product_stock wps left join mes_base_material_info mai on wps.product_id = mai.material_id
<where >
<if test= "warehouseId != null " > and warehouse_id = #{warehouseId}</if>
<if test= "locationCode != null and locationCode != ''" > and location_code = #{locationCode}</if>
<if test= "stockType != null and stockType != ''" > and stock_type = #{stockType}</if>
<if test= "productBatch != null and productBatch != ''" > and product_batch = #{productBatch}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and quality_status = #{qualityStatus}</if>
<if test= "productId != null " > and product_id = #{productId}</if>
<if test= "planCode != null " > and plan_code = #{planCode}</if>
<if test= "planDetailCode != null " > and plan_detail_code = #{planDetailCode}</if>
<if test= "totalAmount != null " > and total_amount = #{totalAmount}</if>
<if test= "frozenAmount != null " > and frozen_amount = #{frozenAmount}</if>
<if test= "occupyAmount != null " > and occupy_amount = #{occupyAmount}</if>
<if test= "createDate != null " > and create_date = #{createDate}</if>
<if test= "updateDate != null " > and update_date = #{updateDate}</if>
<if test= "activeFlag != null and activeFlag != ''" > and active_flag = #{activeFlag}</if>
<if test= "instockDate != null " > and instock_date = #{instockDate}</if>
<if test= "warehouseId != null " > and warehouse_id = #{warehouseId}</if>
<if test= "locationCode != null and locationCode != ''" > and location_code = #{locationCode}</if>
<if test= "stockType != null and stockType != ''" > and stock_type = #{stockType}</if>
<if test= "productBatch != null and productBatch != ''" > and product_batch = #{productBatch}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and quality_status = #{qualityStatus}</if>
<if test= "productId != null " > and product_id = #{productId}</if>
<if test= "planCode != null " > and plan_code = #{planCode}</if>
<if test= "planDetailCode != null " > and plan_detail_code = #{planDetailCode}</if>
<if test= "totalAmount != null " > and total_amount = #{totalAmount}</if>
<if test= "frozenAmount != null " > and frozen_amount = #{frozenAmount}</if>
<if test= "occupyAmount != null " > and occupy_amount = #{occupyAmount}</if>
<if test= "createDate != null " > and create_date = #{createDate}</if>
<if test= "updateDate != null " > and update_date = #{updateDate}</if>
<if test= "activeFlag != null and activeFlag != ''" > and active_flag = #{activeFlag}</if>
<if test= "instockDate != null " > and instock_date = #{instockDate}</if>
and totalAmount>0
</where>
</select>
<select id= "selectWmsProductStocksBySaleorder" parameterType= "WmsProductStock" resultMap= "WmsProductStockResult" >
select wps.warehouse_id,wps.sale_order_id,wps.product_id,sum(total_amount) total_amount,sum(frozen_amount) frozen_amount,sum(occupy_amount) occupy_amount,
select wps.warehouse_id,wps.sale_order_id,wps.product_id,sum(total_amount) total_amount,sum(frozen_amount)
frozen_amount,sum(occupy_amount) occupy_amount,
mbmi.material_code,mbmi.material_name,
wbw.warehouse_name,mso.order_amount,mso.saleorder_code,
(select sum(wpo.apply_qty) from wms_product_outstock wpo where wpo.sale_order_id=wps.sale_order_id and wpo.warehouse_id=wps.warehouse_id and wpo.product_id=wps.product_id and (wpo.execute_status='0' or wpo.execute_status='1')) apply_amount
(select sum(wpo.apply_qty) from wms_product_outstock wpo where wpo.sale_order_id=wps.sale_order_id and
wpo.warehouse_id=wps.warehouse_id and wpo.product_id=wps.product_id and (wpo.execute_status='0' or
wpo.execute_status='1')) apply_amount
from wms_product_stock wps
left join mes_base_material_info mbmi on wps.product_id=mbmi.material_id
left join wms_base_warehouse wbw on wps.warehouse_id=wbw.warehouse_id
left join wms_base_warehouse wbw on wps.warehouse_id=wbw.warehouse_id
left join mes_sale_order mso on wps.sale_order_id=mso.sale_order_id
<where >
wps.total_amount>0 and wps.stock_type='3'
<if test= "saleorderCode != null and saleorderCode != ''" > and mso.saleorder_code = #{saleorderCode}</if>
<if test= "saleorderCode != null and saleorderCode != ''" > and mso.saleorder_code = #{saleorderCode}</if>
<if test= "warehouseId != null " > and wps.warehouse_id = #{warehouseId}</if>
<if test= "productId != null " > and wps.product_id = #{productId}</if>
</where>
@ -243,7 +270,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<!-- select id="selectWmsProductStocksBySaleorder" parameterType="WmsProductStock" resultMap="WmsProductStockResult">
select wgb.warehouse_id,wgb.saleorder_code,wgb.product_id,mso.order_amount,wgb.total_amount,wgb.frozen_amount,wgb.occupy_amount,wbw.warehouse_name,mbmi.material_code,mbmi.material_name from mes_sale_order mso left join
(select wps.warehouse_id,wps.saleorder_code,wps.product_id,sum(total_amount) total_amount,sum(frozen_amount) frozen_amount,sum(occupy_amount) occupy_amount from wms_product_stock wps where wps.total_amount>0 and wps.stock_type='3'