Files
TimiServerAPI/src/main/resources/mapper/timi-server/gao/GaoProductMapper.xml
T
2026-09-10 20:27:32 +08:00

56 lines
3.1 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.GaoProductMapper">
<select id="countByQuery" resultType="long">
SELECT COUNT(1) FROM `gao_product`
WHERE `deleted_at` IS NULL
<if test="storeId != null and storeId != ''">AND `store_id` = #{storeId}</if>
<choose>
<when test="categoryIdList != null and categoryIdList.size() > 0">
AND `category_id` IN <foreach collection="categoryIdList" item="categoryIdItem" separator="," open="(" close=")">#{categoryIdItem}</foreach>
</when>
<when test="categoryId != null and categoryId != ''">AND `category_id` = #{categoryId}</when>
</choose>
<if test="status != null">AND `status` = #{status}</if>
<if test="productType != null">AND `product_type` = #{productType}</if>
<if test="keyword != null and keyword.trim() != ''">AND (`code` LIKE CONCAT('%', #{keyword}, '%') OR `name` LIKE CONCAT('%', #{keyword}, '%') OR `name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR `name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR `name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%'))</if>
</select>
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoProduct">
SELECT * FROM `gao_product`
WHERE `deleted_at` IS NULL
<if test="storeId != null and storeId != ''">AND `store_id` = #{storeId}</if>
<choose>
<when test="categoryIdList != null and categoryIdList.size() > 0">
AND `category_id` IN <foreach collection="categoryIdList" item="categoryIdItem" separator="," open="(" close=")">#{categoryIdItem}</foreach>
</when>
<when test="categoryId != null and categoryId != ''">AND `category_id` = #{categoryId}</when>
</choose>
<if test="status != null">AND `status` = #{status}</if>
<if test="productType != null">AND `product_type` = #{productType}</if>
<if test="keyword != null and keyword.trim() != ''">AND (`code` LIKE CONCAT('%', #{keyword}, '%') OR `name` LIKE CONCAT('%', #{keyword}, '%') OR `name_pinyin_full` LIKE CONCAT(#{keyword}, '%') OR `name_pinyin_initial` LIKE CONCAT(#{keyword}, '%') OR `name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%'))</if>
ORDER BY `sort`, `name`, `code`, `created_at` DESC
LIMIT #{offset}, #{limit}
</select>
<select id="selectByIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoProduct">
SELECT * FROM `gao_product`
WHERE `deleted_at` IS NULL
<choose>
<when test="idList != null and !idList.isEmpty()">
AND `id` IN <foreach collection="idList" item="id" open="(" separator="," close=")">#{id}</foreach>
</when>
<otherwise>AND FALSE</otherwise>
</choose>
</select>
<select id="selectByStoreIdAndCode" resultType="com.imyeyu.api.modules.gao.entity.GaoProduct">
SELECT * FROM `gao_product`
WHERE `store_id` = #{storeId} AND `code` = #{code} AND `deleted_at` IS NULL
<if test="excludeId != null">AND `id` != #{excludeId}</if>
LIMIT 1
</select>
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoProduct">
SELECT * FROM `gao_product`
WHERE `id` = #{id} AND `deleted_at` IS NULL
FOR UPDATE
</select>
</mapper>