<?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">
<mapper namespace= "com.hw.wms.mapper.WmsRawStockMapper" >
<resultMap type= "WmsRawStock" id= "WmsRawStockResult" >
<result property= "rawStockId" column= "raw_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= "materialId" column= "material_id" />
<result property= "instockBatch" column= "instock_batch" />
<result property= "palletInfoCode" column= "pallet_info_code" />
<result property= "saleOrderId" column= "sale_order_id" />
<result property= "safeFlag" column= "safe_flag" />
<result property= "instockDate" column= "instock_date" />
<result property= "lastOutstockTime" column= "last_outstock_time" />
<result property= "qualityStatus" column= "quality_status" />
<result property= "completeFlag" column= "complete_flag" />
<result property= "totalAmount" column= "total_amount" />
<result property= "frozenAmount" column= "frozen_amount" />
<result property= "occupyAmount" column= "occupy_amount" />
<result property= "supplierId" column= "supplier_id" />
<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= "materialCode" column= "material_code" />
<result property= "materialName" column= "material_name" />
<result property= "materialSpec" column= "material_spec" />
<result property= "warehouseName" column= "warehouse_name" />
<result property= "saleorderCode" column= "saleorder_code" />
</resultMap>
<sql id= "selectWmsRawStockVo" >
select wrs.raw_stock_id,
wrs.warehouse_id,
wbw.warehouse_name,
wbw.warehouse_floor,
wrs.location_code,
wrs.stock_type,
wrs.material_id,
mbmi.material_code,
mbmi.material_name,
mbmi.material_spec,
wrs.instock_batch,
wrs.pallet_info_code,
wrs.sale_order_id,
wrs.safe_flag,
wrs.instock_date,
wrs.last_outstock_time,
wrs.quality_status,
wrs.complete_flag,
wrs.total_amount,
wrs.frozen_amount,
wrs.occupy_amount,
wrs.supplier_id,
wrs.create_by,
wrs.create_date,
wrs.update_by,
wrs.update_date,
wrs.active_flag
from wms_raw_stock wrs
left join wms_base_warehouse wbw on wbw.warehouse_id = wrs.warehouse_id
left join mes_base_material_info mbmi on mbmi.material_id = wrs.material_id
</sql>
<select id= "selectWmsRawStockList" parameterType= "WmsRawStock" resultMap= "WmsRawStockResult" >
<include refid= "selectWmsRawStockVo" />
<where >
<if test= "warehouseId != null " > and wrs.warehouse_id = #{warehouseId}</if>
<if test= "locationCode != null and locationCode != ''" > and wrs.location_code = #{locationCode}</if>
<if test= "stockType != null and stockType != ''" > and wrs.stock_type = #{stockType}</if>
<if test= "materialId != null " > and wrs.material_id = #{materialId}</if>
<if test= "saleOrderId != null " > and wrs.sale_order_id = #{saleOrderId}</if>
<if test= "safeFlag != null and safeFlag != ''" > and wrs.safe_flag = #{safeFlag}</if>
<if test= "instockBatch != null and instockBatch != ''" > and wrs.instock_batch = #{instockBatch}</if>
<if test= "instockDate != null " > and wrs.instock_date = #{instockDate}</if>
<if test= "lastOutstockTime != null " > and wrs.last_outstock_time = #{lastOutstockTime}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and wrs.quality_status = #{qualityStatus}</if>
<if test= "totalAmount != null " > and wrs.total_amount = #{totalAmount}</if>
<if test= "frozenAmount != null " > and wrs.frozen_amount = #{frozenAmount}</if>
<if test= "occupyAmount != null " > and wrs.occupy_amount = #{occupyAmount}</if>
<if test= "supplierId != null " > and wrs.supplier_id = #{supplierId}</if>
<if test= "updateDate != null " > and wrs.update_date = #{updateDate}</if>
<if test= "activeFlag != null and activeFlag != ''" > and wrs.active_flag = #{activeFlag}</if>
<if test= "params.beginCreateDate != null and params.beginCreateDate != '' and params.endCreateDate != null and params.endCreateDate != ''" >
and wrs.create_date between #{params.beginCreateDate} and #{params.endCreateDate}
</if>
</where>
</select>
<select id= "selectWmsRawStockByRawStockId" parameterType= "Long" resultMap= "WmsRawStockResult" >
<include refid= "selectWmsRawStockVo" />
where wrs.raw_stock_id = #{rawStockId}
</select>
<insert id= "insertWmsRawStock" parameterType= "WmsRawStock" useGeneratedKeys= "true" keyProperty= "rawStockId" >
insert into wms_raw_stock
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "warehouseId != null" > warehouse_id,</if>
<if test= "warehouseFloor != null" > warehouse_floor,</if>
<if test= "locationCode != null and locationCode != ''" > location_code,</if>
<if test= "stockType != null and stockType != ''" > stock_type,</if>
<if test= "materialId != null" > material_id,</if>
<if test= "instockBatch != null and instockBatch != ''" > instock_batch,</if>
<if test= "saleOrderId != null" > sale_order_id,</if>
<if test= "safeFlag != null and safeFlag != ''" > safe_flag,</if>
<if test= "instockDate != null" > instock_date,</if>
<if test= "lastOutstockTime != null" > last_outstock_time,</if>
<if test= "qualityStatus != null and qualityStatus != ''" > quality_status,</if>
<if test= "completeFlag != null and completeFlag != ''" > complete_flag,</if>
<if test= "totalAmount != null" > total_amount,</if>
<if test= "frozenAmount != null" > frozen_amount,</if>
<if test= "occupyAmount != null" > occupy_amount,</if>
<if test= "supplierId != null" > supplier_id,</if>
<if test= "createBy != null" > create_by,</if>
<if test= "createDate != null" > create_date,</if>
<if test= "updateBy != null" > update_by,</if>
<if test= "updateDate != null" > update_date,</if>
<if test= "activeFlag != null" > active_flag,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "warehouseId != null" > #{warehouseId},</if>
<if test= "warehouseFloor != null" > #{warehouseFloor},</if>
<if test= "locationCode != null and locationCode != ''" > #{locationCode},</if>
<if test= "stockType != null and stockType != ''" > #{stockType},</if>
<if test= "materialId != null" > #{materialId},</if>
<if test= "instockBatch != null and instockBatch != ''" > #{instockBatch},</if>
<if test= "saleOrderId != null" > #{saleOrderId},</if>
<if test= "safeFlag != null and safeFlag != ''" > #{safeFlag},</if>
<if test= "instockDate != null" > #{instockDate},</if>
<if test= "lastOutstockTime != null" > #{lastOutstockTime},</if>
<if test= "qualityStatus != null and qualityStatus != ''" > #{qualityStatus},</if>
<if test= "completeFlag != null and completeFlag != ''" > #{completeFlag},</if>
<if test= "totalAmount != null" > #{totalAmount},</if>
<if test= "frozenAmount != null" > #{frozenAmount},</if>
<if test= "occupyAmount != null" > #{occupyAmount},</if>
<if test= "supplierId != null" > #{supplierId},</if>
<if test= "createBy != null" > #{createBy},</if>
<if test= "createDate != null" > #{createDate},</if>
<if test= "updateBy != null" > #{updateBy},</if>
<if test= "updateDate != null" > #{updateDate},</if>
<if test= "activeFlag != null" > #{activeFlag},</if>
</trim>
</insert>
<update id= "updateWmsRawStock" parameterType= "WmsRawStock" >
update wms_raw_stock
<trim prefix= "SET" suffixOverrides= "," >
<if test= "warehouseId != null" > warehouse_id = #{warehouseId},</if>
<if test= "locationCode != null and locationCode != ''" > location_code = #{locationCode},</if>
<if test= "stockType != null and stockType != ''" > stock_type = #{stockType},</if>
<if test= "materialId != null" > material_id = #{materialId},</if>
<if test= "saleOrderId != null" > sale_order_id = #{saleOrderId},</if>
<if test= "safeFlag != null and safeFlag != ''" > safe_flag = #{safeFlag},</if>
<if test= "instockBatch != null and instockBatch != ''" > instock_batch = #{instockBatch},</if>
<if test= "instockDate != null" > instock_date = #{instockDate},</if>
<if test= "lastOutstockTime != null" > last_outstock_time = #{lastOutstockTime},</if>
<if test= "qualityStatus != null and qualityStatus != ''" > quality_status = #{qualityStatus},</if>
<if test= "completeFlag != null and completeFlag != ''" > complete_flag = #{completeFlag},</if>
<if test= "totalAmount != null" > total_amount = #{totalAmount},</if>
<if test= "frozenAmount != null" > frozen_amount = #{frozenAmount},</if>
<if test= "occupyAmount != null" > occupy_amount = #{occupyAmount},</if>
<if test= "supplierId != null" > supplier_id = #{supplierId},</if>
<if test= "createBy != null" > create_by = #{createBy},</if>
<if test= "createDate != null" > create_date = #{createDate},</if>
<if test= "updateBy != null" > update_by = #{updateBy},</if>
<if test= "updateDate != null" > update_date = #{updateDate},</if>
<if test= "activeFlag != null" > active_flag = #{activeFlag},</if>
</trim>
where raw_stock_id = #{rawStockId}
</update>
<delete id= "deleteWmsRawStockByRawStockId" parameterType= "Long" >
delete
from wms_raw_stock
where raw_stock_id = #{rawStockId}
</delete>
<delete id= "deleteWmsRawStockByRawStockIds" parameterType= "String" >
delete from wms_raw_stock where raw_stock_id in
<foreach item= "rawStockId" collection= "array" open= "(" separator= "," close= ")" >
#{rawStockId}
</foreach>
</delete>
<select id= "selectRawStockByBarcode" resultMap= "WmsRawStockResult" >
<include refid= "selectWmsRawStockVo" />
where instock_batch = #{instockBatch}
</select>
<select id= "getRawStockTotalAmount" resultType= "BigDecimal" parameterType= "WmsRawStock" >
select sum(total_amount) from wms_raw_stock
<where >
<if test= "locationCode != null and locationCode != ''" > and location_code = #{locationCode}</if>
and total_amount > 0
</where>
</select>
<select id= "selectWmsRawStocks4Apply" parameterType= "WmsRawStock" resultMap= "WmsRawStockResult" >
<include refid= "selectWmsRawStockVo" />
<where >
<if test= "warehouseId != null " > and warehouse_id = #{warehouseId}</if>
<if test= "materialId != null " > and material_id = #{materialId}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and quality_status = #{qualityStatus}</if>
</where>
order by instock_date asc
</select>
<select id= "selectWmsRawStockInList" parameterType= "WmsRawStock" resultMap= "WmsRawStockResult" >
<include refid= "selectWmsRawStockVo" />
<where >
<if test= "warehouseId != null " > and wrs.warehouse_id = #{warehouseId}</if>
<if test= "locationCode != null and locationCode != ''" > and wrs.location_code = #{locationCode}</if>
<if test= "stockType != null and stockType != ''" > and wrs.stock_type = #{stockType}</if>
<if test= "materialId != null " > and wrs.material_id = #{materialId}</if>
<if test= "instockBatch != null and instockBatch != ''" > and wrs.instock_batch = #{instockBatch}</if>
<if test= "instockDate != null " > and wrs.instock_date = #{instockDate}</if>
<if test= "lastOutstockTime != null " > and wrs.last_outstock_time = #{lastOutstockTime}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and wrs.quality_status = #{qualityStatus}</if>
<if test= "completeFlag != null and completeFlag != ''" > and wrs.complete_flag = #{completeFlag}</if>
<if test= "frozenAmount != null " > and wrs.frozen_amount = #{frozenAmount}</if>
<if test= "occupyAmount != null " > and wrs.occupy_amount = #{occupyAmount}</if>
<if test= "supplierId != null " > and wrs.supplier_id = #{supplierId}</if>
<if test= "createDate != null " > and wrs.create_date = #{createDate}</if>
<if test= "updateDate != null " > and wrs.update_date = #{updateDate}</if>
<if test= "activeFlag != null and activeFlag != ''" > and wrs.active_flag = #{activeFlag}</if>
and wrs.total_amount > 0
</where>
</select>
<select id= "selectOnlyWmsRawStockInList" parameterType= "WmsRawStock" resultMap= "WmsRawStockResult" >
select wrs.raw_stock_id,
wrs.warehouse_id,
wrs.location_code,
wrs.stock_type,
wrs.material_id,
wrs.instock_batch,
wrs.pallet_info_code,
wrs.sale_order_id,
wrs.safe_flag,
wrs.instock_date,
wrs.last_outstock_time,
wrs.quality_status,
wrs.complete_flag,
wrs.total_amount,
wrs.frozen_amount,
wrs.occupy_amount,
wrs.supplier_id,
wrs.create_by,
wrs.create_date,
wrs.update_by,
wrs.update_date,
wrs.active_flag
from wms_raw_stock wrs
<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= "materialId != null " > and material_id = #{materialId}</if>
<if test= "instockBatch != null and instockBatch != ''" > and instock_batch = #{instockBatch}</if>
<if test= "instockDate != null " > and instock_date = #{instockDate}</if>
<if test= "lastOutstockTime != null " > and last_outstock_time = #{lastOutstockTime}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and quality_status = #{qualityStatus}</if>
<if test= "completeFlag != null and completeFlag != ''" > and complete_flag = #{completeFlag}</if>
<if test= "frozenAmount != null " > and frozen_amount = #{frozenAmount}</if>
<if test= "occupyAmount != null " > and occupy_amount = #{occupyAmount}</if>
<if test= "supplierId != null " > and supplier_id = #{supplierId}</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>
and total_amount > 0
</where>
</select>
<select id= "selectWmsRawStockJoinList" parameterType= "WmsRawStock" resultMap= "WmsRawStockResult" >
select wrs.raw_stock_id,
wrs.warehouse_id,
wbw.warehouse_name,
wbw.warehouse_floor,
wrs.location_code,
wrs.stock_type,
wrs.material_id,
mbmi.material_code,
mbmi.material_name,
mbmi.material_spec,
wrs.instock_batch,
wrs.pallet_info_code,
wrs.sale_order_id,
wrs.safe_flag,
wrs.instock_date,
wrs.last_outstock_time,
wrs.quality_status,
wrs.complete_flag,
wrs.total_amount,
wrs.frozen_amount,
wrs.occupy_amount,
wrs.supplier_id,
wrs.create_by,
wrs.create_date,
wrs.update_by,
wrs.update_date,
wrs.active_flag,
mso.saleorder_code
from wms_raw_stock wrs
left join wms_base_warehouse wbw on wbw.warehouse_id = wrs.warehouse_id
left join mes_base_material_info mbmi on mbmi.material_id = wrs.material_id
left join mes_sale_order mso on wrs.sale_order_id = mso.sale_order_id
<where >
<if test= "warehouseId != null " > and wrs.warehouse_id = #{warehouseId}</if>
<if test= "locationCode != null and locationCode != ''" > and wrs.location_code = #{locationCode}</if>
<if test= "stockType != null and stockType != ''" > and wrs.stock_type = #{stockType}</if>
<if test= "materialId != null " > and wrs.material_id = #{materialId}</if>
<if test= "saleOrderId != null " > and wrs.sale_order_id = #{saleOrderId}</if>
<if test= "safeFlag != null and safeFlag != ''" > and wrs.safe_flag = #{safeFlag}</if>
<if test= "materialCode != null and materialCode != ''" > and mbmi.material_code like concat('%', #{materialCode}, '%')</if>
<if test= "materialName != null and materialName != ''" > and mbmi.material_name like concat('%', #{materialName}, '%')</if>
<if test= "materialSpec != null and materialSpec != ''" > and replace(mbmi.material_spec,' ','') like concat('%', #{materialSpec},
'%')</if>
<if test= "saleorderCode != null and saleorderCode != ''" > and mso.saleorder_code like concat('%', #{saleorderCode}, '%')</if>
<if test= "instockBatch != null and instockBatch != ''" > and wrs.instock_batch like concat('%', #{instockBatch},
'%')</if>
<if test= "instockDate != null " > and wrs.instock_date = #{instockDate}</if>
<if test= "lastOutstockTime != null " > and wrs.last_outstock_time = #{lastOutstockTime}</if>
<if test= "qualityStatus != null and qualityStatus != ''" > and wrs.quality_status = #{qualityStatus}</if>
<if test= "totalAmount != null " > and wrs.total_amount = #{totalAmount}</if>
<if test= "frozenAmount != null " > and wrs.frozen_amount = #{frozenAmount}</if>
<if test= "occupyAmount != null " > and wrs.occupy_amount = #{occupyAmount}</if>
<if test= "supplierId != null " > and wrs.supplier_id = #{supplierId}</if>
<if test= "updateDate != null " > and wrs.update_date = #{updateDate}</if>
<if test= "activeFlag != null and activeFlag != ''" > and wrs.active_flag = #{activeFlag}</if>
<if test= "params.beginCreateDate != null and params.beginCreateDate != '' and params.endCreateDate != null and params.endCreateDate != ''" >
and wrs.create_date between #{params.beginCreateDate} and #{params.endCreateDate}
</if>
</where>
order by wrs.instock_date desc
</select>
<select id= "selectWmsRawStocks4Transfer" parameterType= "WmsRawStock" resultMap= "WmsRawStockResult" >
select wrs.raw_stock_id,wrs.sale_order_id,wrs.safe_flag,wrs.instock_batch from wms_raw_stock wrs left join wms_base_location wbl on wrs.location_code =wbl.location_code
<where >
and wrs.total_amount=1 and wrs.occupy_amount < = 0 and wrs.frozen_amount < = 0 and wbl.location_status='1'
<if test= "warehouseId != null " > and wrs.warehouse_id = #{warehouseId}</if>
<if test= "materialId != null " > and wrs.material_id = #{materialId}</if>
<if test= "saleOrderId != null and saleOrderId != ''" > and wrs.sale_order_id = #{saleOrderId}</if>
</where>
order by wbl.loc_column asc, wbl.loc_deep desc limit #{params.limit}
</select>
<select id= "selectAutoOutstockRawStockList" parameterType= "WmsRawStock" resultMap= "WmsRawStockResult" >
select wrs.raw_stock_id,wrs.warehouse_id,wrs.sale_order_id,wrs.material_id,wrs.instock_batch,wrs.total_amount from wms_raw_stock wrs where wrs.material_id=#{materialId}
and exists (select 1 from mes_base_barcode_info mbbi where wrs.instock_batch = mbbi.barcode_info and mbbi.po_no=#{poNo} )
</select>
<select id= "selectRawLocationPercentage" resultType= "com.hw.wms.domain.WmsRawStock" >
select
material_id,
sum(total_amount) total_amount
from
`hwjy-cloud`.wms_raw_stock
where
warehouse_id = 511
group by
material_id
</select>
</mapper>