Files
TimiServerAPI/src/main/resources/mapper/timi-server/gao/GaoCustomerPackageItemMapper.xml
T
2026-09-01 01:16:52 +08:00

40 lines
2.0 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.imyeyu.api.modules.gao.mapper.GaoCustomerPackageItemMapper">
<select id="selectByCustomerPackageId" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackageItem">
SELECT * FROM `gao_customer_package_item`
WHERE `customer_package_id` = #{customerPackageId} AND `deleted_at` IS NULL
ORDER BY `sort`, `created_at`
</select>
<select id="selectByCustomerPackageIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackageItem">
SELECT * FROM `gao_customer_package_item`
WHERE `deleted_at` IS NULL
<choose>
<when test="customerPackageIdList != null and !customerPackageIdList.isEmpty()">
AND `customer_package_id` IN <foreach collection="customerPackageIdList" item="id" open="(" separator="," close=")">#{id}</foreach>
</when>
<otherwise>AND FALSE</otherwise>
</choose>
ORDER BY `customer_package_id`, `sort`, `created_at`
</select>
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackageItem">
SELECT * FROM `gao_customer_package_item`
WHERE `id` = #{id} AND `deleted_at` IS NULL
FOR UPDATE
</select>
<update id="updateReservedQuantity">
UPDATE `gao_customer_package_item`
SET `reserved_quantity` = `reserved_quantity` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
WHERE `id` = #{id} AND `deleted_at` IS NULL
AND `reserved_quantity` + #{delta} &gt;= 0
AND `reserved_quantity` + `delivered_quantity` + #{delta} &lt;= `total_quantity`
</update>
<update id="updateDeliveredQuantity">
UPDATE `gao_customer_package_item`
SET `delivered_quantity` = `delivered_quantity` + #{delta}, `updated_at` = FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000)
WHERE `id` = #{id} AND `deleted_at` IS NULL
AND `delivered_quantity` + #{delta} &gt;= 0
AND `reserved_quantity` + `delivered_quantity` + #{delta} &lt;= `total_quantity`
</update>
</mapper>