first commit
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?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.linke.transport.infrastructure.warehouse.inventory.persistence.InventoryMapper">
|
||||
|
||||
<!-- 原子性增加库存 -->
|
||||
<update id="increaseQuantity">
|
||||
UPDATE inventory
|
||||
SET quantity = quantity + #{quantity},
|
||||
updated_by = #{userName}
|
||||
WHERE id = #{inventoryId}
|
||||
AND is_deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 原子性扣减库存 -->
|
||||
<update id="decreaseQuantity">
|
||||
UPDATE inventory
|
||||
SET quantity = quantity - #{quantity},
|
||||
updated_by = #{userName}
|
||||
WHERE id = #{inventoryId}
|
||||
AND quantity >= #{quantity} -- 确保库存足够扣减
|
||||
AND is_deleted = 0 -- 确保记录有效
|
||||
</update>
|
||||
|
||||
<!-- 分页查询库存列表 (JOIN 物料表) -->
|
||||
<!-- 注意: 请确保你有一个名为 material 的表,并且字段名匹配 -->
|
||||
<select id="findInventoryList" resultType="com.linke.transport.application.service.warehouse.inventory.vo.InventoryVO">
|
||||
SELECT
|
||||
i.id,
|
||||
i.inventory_order_no,
|
||||
i.owner_id,
|
||||
i.owner_name,
|
||||
i.material_id,
|
||||
m.category AS material_category,
|
||||
m.name AS material_name,
|
||||
m.model AS material_model,
|
||||
i.quantity,
|
||||
m.unit,
|
||||
m.weight,
|
||||
m.code_managed,
|
||||
m.value,
|
||||
i.machine_serial_no,
|
||||
i.created_at
|
||||
FROM
|
||||
inventory i
|
||||
LEFT JOIN
|
||||
material m ON i.material_id = m.id AND m.is_deleted = 0
|
||||
WHERE
|
||||
i.is_deleted = 0
|
||||
<if test="query.ownerId != null">
|
||||
AND i.owner_id = #{query.ownerId}
|
||||
</if>
|
||||
<if test="query.ownerName != null and query.ownerName != ''">
|
||||
AND i.owner_name LIKE CONCAT('%', #{query.ownerName}, '%')
|
||||
</if>
|
||||
<if test="query.materialCode != null and query.materialCode != ''">
|
||||
AND m.code LIKE CONCAT('%', #{query.materialCode}, '%')
|
||||
</if>
|
||||
<if test="query.materialName != null and query.materialName != ''">
|
||||
AND m.name LIKE CONCAT('%', #{query.materialName}, '%')
|
||||
</if>
|
||||
<if test="query.materialCategory != null and query.materialCategory != ''">
|
||||
AND m.category LIKE CONCAT('%', #{query.materialCategory}, '%')
|
||||
</if>
|
||||
<if test="query.machineCode != null and query.machineCode != ''">
|
||||
AND i.machine_serial_no LIKE CONCAT('%', #{query.machineCode}, '%')
|
||||
</if>
|
||||
<if test="query.inventoryOrderNo != null and query.inventoryOrderNo != ''">
|
||||
AND i.inventory_order_no LIKE CONCAT('%', #{query.inventoryOrderNo}, '%')
|
||||
</if>
|
||||
|
||||
<if test="query.materialModel != null and query.materialModel != ''">
|
||||
AND m.material_model LIKE CONCAT('%', #{query.materialModel}, '%')
|
||||
</if>
|
||||
|
||||
<if test="query.codeManaged != null and query.codeManaged != ''">
|
||||
AND m.code_managed = #{query.codeManaged}
|
||||
</if>
|
||||
<if test="query.createdAtStart != null and query.createdAtEnd != null and @org.jeecg.common.util.oConvertUtils@isNotEmpty(query.createdAtStart) and @org.jeecg.common.util.oConvertUtils@isNotEmpty(query.createdAtEnd)">
|
||||
and DATE_FORMAT(i.created_at,'%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{query.createdAtStart},'%Y-%m-%d')
|
||||
and DATE_FORMAT(i.created_at,'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{query.createdAtEnd},'%Y-%m-%d')
|
||||
</if>
|
||||
ORDER BY
|
||||
i.updated_at DESC
|
||||
</select>
|
||||
<select id="findAllInventoryList" resultType="com.linke.transport.application.service.warehouse.inventory.vo.InventoryVO">
|
||||
SELECT i.id,
|
||||
i.inventory_order_no,
|
||||
i.owner_id,
|
||||
i.owner_name,
|
||||
i.material_id,
|
||||
m.category AS material_category,
|
||||
m.name AS material_name,
|
||||
m.model AS material_model,
|
||||
i.quantity,
|
||||
m.unit,
|
||||
m.weight,
|
||||
m.code_managed,
|
||||
i.machine_serial_no
|
||||
FROM inventory i
|
||||
LEFT JOIN
|
||||
material m ON i.material_id = m.id AND m.is_deleted = 0
|
||||
WHERE i.is_deleted = 0
|
||||
<if test="ownerId != null">
|
||||
AND i.owner_id = #{ownerId}
|
||||
</if>
|
||||
<if test="machineSerialNo != null and machineSerialNo !=''">
|
||||
AND i.machine_serial_no LIKE CONCAT('%', #{machineSerialNo}, '%')
|
||||
</if>
|
||||
ORDER BY i.updated_at DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user