261 lines
14 KiB
XML
261 lines
14 KiB
XML
<?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.wms.mapper.StockMapper">
|
|
<resultMap type="Stock" id="StockMap">
|
|
<result property="stockId" column="stock_id"/>
|
|
<result property="locationId" column="location_id"/>
|
|
<result property="vehicleId" column="vehicle_id"/>
|
|
<result property="goodsId" column="goods_id"/>
|
|
<result property="goodsName" column="goods_name"/>
|
|
<result property="batchNo" column="batch_no"/>
|
|
<result property="remainNum" column="remain_num"/>
|
|
<result property="availableNum" column="available_num"/>
|
|
<result property="realNum" column="real_num"/>
|
|
<result property="providerId" column="provider_id"/>
|
|
<result property="providerName" column="provider_name"/>
|
|
<result property="productionDate" column="production_date"/>
|
|
<result property="expirationDate" column="expiration_date"/>
|
|
<result property="stockStatus" column="stock_status"/>
|
|
<result property="goodsStatus" column="goods_status"/>
|
|
<result property="createTime" column="create_time"/>
|
|
<result property="lastUpdateTime" column="last_update_time"/>
|
|
<result property="lastUpdateUser" column="last_update_user"/>
|
|
<result property="remark" column="remark"/>
|
|
<result property="isInventory" column="is_inventory"/>
|
|
<result property="inventoryTaskId" column="inventory_task_id"/>
|
|
<result property="currentLocation" column="current_location"/>
|
|
<result property="shelfLife" column="shelf_life"/>
|
|
<result property="warehouseName" column="warehouse_name"/>
|
|
</resultMap>
|
|
|
|
<sql id="selectAll">
|
|
select stock_id, warehouse_name, location_id, vehicle_id, goods_id, goods_name, batch_no, available_num, remain_num, real_num, provider_id,
|
|
provider_name, production_date, expiration_date, stock_status, goods_status, create_time, last_update_time, last_update_user, remark,
|
|
is_inventory, inventory_task_id, current_location, shelf_life
|
|
from tbl_app_stock
|
|
</sql>
|
|
|
|
<select id="selStocksFront" parameterType="String" resultMap="StockMap">
|
|
<include refid="selectAll" />
|
|
<where>
|
|
<if test="query != null and query != ''"> vehicle_id = #{query} or goods_id like concat('%', #{query}, '%') or goods_name like concat('%', #{query}, '%') or batch_no = #{query}</if>
|
|
</where>
|
|
</select>
|
|
|
|
<select id="selStocksByGoodsId" parameterType="Stock" resultMap="StockMap">
|
|
select goods_id, goods_name, SUM(real_num) as real_num
|
|
from tbl_app_stock
|
|
<where>
|
|
<if test="goodsId != null and goodsId != ''"> and goods_id = #{goodsId}</if>
|
|
</where>
|
|
group by goods_id, goods_name
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selStocksByLocationId" parameterType="string" resultMap="StockMap">
|
|
select stock_id, warehouse_name, location_id, vehicle_id, goods_id, goods_name, batch_no, available_num, remain_num, real_num, provider_id,
|
|
provider_name, production_date, expiration_date, stock_status, goods_status, create_time, last_update_time, last_update_user, remark,
|
|
is_inventory, inventory_task_id, current_location, shelf_life
|
|
from tbl_app_stock
|
|
<where>
|
|
<if test="locationId != null and locationId != ''"> and location_id = #{locationId}</if>
|
|
</where>
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selStockOutOfDate" resultMap="StockMap">
|
|
<include refid="selectAll" />
|
|
where expiration_date < now() and goods_status != 3
|
|
</select>
|
|
|
|
<select id="selStockNearDeadLine" parameterType="integer" resultMap="StockMap">
|
|
<include refid="selectAll" />
|
|
where DATEDIFF(EXPIRATION_DATE,CURRENT_DATE) <= #{nearInterval} and goods_status != 3
|
|
</select>
|
|
|
|
<select id="selStockLongTimeNoUse" parameterType="integer" resultMap="StockMap">
|
|
<include refid="selectAll" />
|
|
where DATEDIFF(last_update_time,CURRENT_DATE) <= #{nearInterval} and goods_status = 0
|
|
</select>
|
|
|
|
<select id="selStocks" parameterType="Stock" resultMap="StockMap">
|
|
<include refid="selectAll" />
|
|
<where>
|
|
<if test="stockId != null and stockId != ''"> and stock_id = #{stockId}</if>
|
|
<if test="locationId != null and locationId != ''"> and location_id = #{locationId}</if>
|
|
<if test="warehouseName != null">and warehouse_name = #{warehouseName}</if>
|
|
<if test="vehicleId != null and vehicleId != ''"> and vehicle_id = #{vehicleId}</if>
|
|
<if test="goodsId != null and goodsId != ''"> and goods_id = #{goodsId}</if>
|
|
<if test="goodsName != null and goodsName != ''"> and goods_name = #{goodsName}</if>
|
|
<if test="batchNo != null and batchNo != ''"> and batch_no = #{batchNo}</if>
|
|
<if test="availableNum != null"> and available_num = #{availableNum}</if>
|
|
<if test="remainNum != null"> and remain_num = #{remainNum}</if>
|
|
<if test="realNum != null"> and real_num = #{realNum}</if>
|
|
<if test="providerId != null and providerId != ''"> and provider_id = #{providerId}</if>
|
|
<if test="providerName != null and providerName != ''"> and provider_name = #{providerName}</if>
|
|
<if test="productionDate != null"> and production_date = #{productionDate}</if>
|
|
<if test="expirationDate != null"> and expiration_date = #{expirationDate}</if>
|
|
<if test="stockStatus != null"> and stock_status = #{stockStatus}</if>
|
|
<if test="goodsStatus != null"> and goods_status = #{goodsStatus}</if>
|
|
<if test="createTime != null"> and create_time = #{createTime}</if>
|
|
<if test="lastUpdateTime != null"> and last_update_time = #{lastUpdateTime}</if>
|
|
<if test="lastUpdateUser != null and lastUpdateUser != ''"> and last_update_user = #{lastUpdateUser}</if>
|
|
<if test="remark != null and remark != ''"> and remark = #{remark}</if>
|
|
<if test="isInventory != null"> and is_inventory = #{isInventory}</if>
|
|
<if test="inventoryTaskId != null and inventoryTaskId != ''"> and inventory_task_id = #{inventoryTaskId}</if>
|
|
<if test="currentLocation != null and currentLocation != ''"> and current_location = #{currentLocation}</if>
|
|
<if test="shelfLife != null"> and shelf_life = #{shelfLife}</if>
|
|
</where>
|
|
order by goods_status desc, available_num asc , create_time asc
|
|
</select>
|
|
|
|
<insert id="addStock" parameterType="Stock">
|
|
insert into tbl_app_stock
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="stockId != null">stock_id,</if>
|
|
<if test="warehouseName != null">warehouse_name,</if>
|
|
<if test="locationId != null">location_id,</if>
|
|
<if test="vehicleId != null">vehicle_id,</if>
|
|
<if test="goodsId != null">goods_id,</if>
|
|
<if test="goodsName != null">goods_name,</if>
|
|
<if test="batchNo != null">batch_no,</if>
|
|
<if test="remainNum != null">remain_num,</if>
|
|
<if test="availableNum != null">available_num,</if>
|
|
<if test="realNum != null">real_num,</if>
|
|
<if test="providerId != null">provider_id,</if>
|
|
<if test="providerName != null">provider_name,</if>
|
|
<if test="productionDate != null">production_date,</if>
|
|
<if test="expirationDate != null">expiration_date,</if>
|
|
<if test="stockStatus != null">stock_status,</if>
|
|
<if test="goodsStatus != null">goods_status,</if>
|
|
<if test="createTime != null">create_time,</if>
|
|
<if test="lastUpdateTime != null">last_update_time,</if>
|
|
<if test="lastUpdateUser != null">last_update_user,</if>
|
|
<if test="remark != null">remark,</if>
|
|
<if test="isInventory != null">is_inventory,</if>
|
|
<if test="inventoryTaskId != null">inventory_task_id,</if>
|
|
<if test="currentLocation != null">current_location,</if>
|
|
<if test="shelfLife != null">shelf_life,</if>
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="stockId != null">#{stockId},</if>
|
|
<if test="warehouseName != null">#{warehouseName},</if>
|
|
<if test="locationId != null">#{locationId},</if>
|
|
<if test="vehicleId != null">#{vehicleId},</if>
|
|
<if test="goodsId != null">#{goodsId},</if>
|
|
<if test="goodsName != null">#{goodsName},</if>
|
|
<if test="batchNo != null">#{batchNo},</if>
|
|
<if test="remainNum != null">#{remainNum},</if>
|
|
<if test="availableNum != null">#{availableNum},</if>
|
|
<if test="realNum != null">#{realNum},</if>
|
|
<if test="providerId != null">#{providerId},</if>
|
|
<if test="providerName != null">#{providerName},</if>
|
|
<if test="productionDate != null">#{productionDate},</if>
|
|
<if test="expirationDate != null">#{expirationDate},</if>
|
|
<if test="stockStatus != null">#{stockStatus},</if>
|
|
<if test="goodsStatus != null">#{goodsStatus},</if>
|
|
<if test="createTime != null">#{createTime},</if>
|
|
<if test="lastUpdateTime != null">#{lastUpdateTime},</if>
|
|
<if test="lastUpdateUser != null">#{lastUpdateUser},</if>
|
|
<if test="remark != null">#{remark},</if>
|
|
<if test="isInventory != null">#{isInventory},</if>
|
|
<if test="inventoryTaskId != null">#{inventoryTaskId},</if>
|
|
<if test="currentLocation != null">#{currentLocation},</if>
|
|
<if test="shelfLife != null">#{shelfLife},</if>
|
|
</trim>
|
|
</insert>
|
|
|
|
<update id="modifyStock" parameterType="Stock">
|
|
update tbl_app_stock
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
<if test="locationId != null">location_id = #{locationId},</if>
|
|
<if test="vehicleId != null">vehicle_id = #{vehicleId},</if>
|
|
<if test="goodsId != null">goods_id = #{goodsId},</if>
|
|
<if test="goodsName != null">goods_name = #{goodsName},</if>
|
|
<if test="batchNo != null">batch_no = #{batchNo},</if>
|
|
<if test="remainNum != null">remain_num = #{remainNum},</if>
|
|
<if test="availableNum != null">available_num = #{availableNum},</if>
|
|
<if test="realNum != null">real_num = #{realNum},</if>
|
|
<if test="providerId != null">provider_id = #{providerId},</if>
|
|
<if test="providerName != null">provider_name = #{providerName},</if>
|
|
<if test="productionDate != null">production_date = #{productionDate},</if>
|
|
<if test="expirationDate != null">expiration_date = #{expirationDate},</if>
|
|
<if test="stockStatus != null">stock_status = #{stockStatus},</if>
|
|
<if test="goodsStatus != null">goods_status = #{goodsStatus},</if>
|
|
<if test="createTime != null">create_time = #{createTime},</if>
|
|
<if test="lastUpdateTime != null">last_update_time = #{lastUpdateTime},</if>
|
|
<if test="lastUpdateUser != null">last_update_user = #{lastUpdateUser},</if>
|
|
<if test="remark != null">remark = #{remark},</if>
|
|
<if test="isInventory != null">is_inventory = #{isInventory},</if>
|
|
<if test="inventoryTaskId != null">inventory_task_id = #{inventoryTaskId},</if>
|
|
<if test="currentLocation != null">current_location = #{currentLocation},</if>
|
|
<if test="shelfLife != null">shelf_life = #{shelfLife},</if>
|
|
</trim>
|
|
where stock_id = #{stockId}
|
|
</update>
|
|
|
|
<update id="updateLocation">
|
|
update tbl_app_stock set location_id = #{newLocationId} where location_id = #{oldLocationId}
|
|
</update>
|
|
<update id="updateLocationAndStatus">
|
|
update tbl_app_stock set location_id = #{newLocationId}, stock_status = #{status} where location_id = #{oldLocationId}
|
|
</update>
|
|
|
|
<select id="groupByVehicleNo" parameterType="Stock" resultMap="StockMap">
|
|
SELECT batch_no ,SUM(available_num) AS available_num,MAX(stock_id) AS stock_id,MAX(warehouse_name) AS warehouse_name,MAX(goods_id) AS goods_id
|
|
FROM tbl_app_stock where location_id = #{locationId}
|
|
GROUP BY batch_no
|
|
</select>
|
|
|
|
<select id="groupByBatchNo" parameterType="Stock" resultMap="StockMap">
|
|
SELECT vehicle_id ,SUM(available_num) AS available_num,MAX(stock_id) AS stock_id,MAX(warehouse_name) AS warehouse_name,MAX(goods_id) AS goods_id
|
|
FROM tbl_app_stock where location_id = #{locationId}
|
|
GROUP BY vehicle_id
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<update id="resetStock" parameterType="Stock">
|
|
update tbl_app_stock set available_num = real_num;
|
|
</update>
|
|
|
|
|
|
<delete id="deleteStock" parameterType="String">
|
|
delete from tbl_app_stock where stock_id = #{stockId}
|
|
</delete>
|
|
|
|
|
|
<delete id="deleteStockWithLocationId" parameterType="String">
|
|
delete from tbl_app_stock where location_id = #{locationId}
|
|
</delete>
|
|
|
|
<update id="updateStockStatusWithLocationId">
|
|
update tbl_app_stock set stock_status = #{status} where location_id = #{locationId}
|
|
</update>
|
|
|
|
<update id="updateStockAvailableNumWithStockId">
|
|
update tbl_app_stock set available_num = #{availableNum} where stock_id = #{stockId}
|
|
</update>
|
|
|
|
|
|
<update id="updateStockProductionDateWithStockId">
|
|
update tbl_app_stock set production_date = #{productionDate} where stock_id = #{stockId}
|
|
</update>
|
|
|
|
|
|
|
|
<update id="updateLocationIdWithBetchNo">
|
|
update tbl_app_stock set location_id = #{locationId} where batch_no = #{batchNo}
|
|
</update>
|
|
|
|
|
|
|
|
</mapper> |