Files
TimiServerAPI/src/main/resources/mapper/timi-server/gao/GaoCustomerPackageMapper.xml
T
2026-09-06 15:49:57 +08:00

31 lines
1.7 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.GaoCustomerPackageMapper">
<select id="selectBySalesOrderId" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
SELECT * FROM `gao_customer_package`
WHERE `sales_order_id` = #{salesOrderId} AND `deleted_at` IS NULL
LIMIT 1
</select>
<sql id="queryWhere">
p.`deleted_at` IS NULL
<if test="storeId != null and storeId != ''">AND p.`store_id` = #{storeId}</if>
<if test="customerId != null and customerId != ''">AND p.`customer_id` = #{customerId}</if>
<if test="status != null">AND o.`status` = #{status}</if>
<if test="keyword != null and keyword.trim() != ''">AND (p.`package_name_snapshot` LIKE CONCAT('%', #{keyword}, '%') OR c.`name` LIKE CONCAT('%', #{keyword}, '%') OR c.`code` LIKE CONCAT('%', #{keyword}, '%'))</if>
</sql>
<select id="countByQuery" resultType="long">
SELECT COUNT(1) FROM `gao_customer_package` p
LEFT JOIN `gao_customer` c ON c.`id` = p.`customer_id`
INNER JOIN `gao_sales_order` o ON o.`id` = p.`sales_order_id` AND o.`store_id` = p.`store_id` AND o.`deleted_at` IS NULL
WHERE <include refid="queryWhere"/>
</select>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomerPackage">
SELECT p.* FROM `gao_customer_package` p
LEFT JOIN `gao_customer` c ON c.`id` = p.`customer_id`
INNER JOIN `gao_sales_order` o ON o.`id` = p.`sales_order_id` AND o.`store_id` = p.`store_id` AND o.`deleted_at` IS NULL
WHERE <include refid="queryWhere"/>
ORDER BY o.`purchased_at` DESC, p.`created_at` DESC
LIMIT #{offset}, #{limit}
</select>
</mapper>