mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?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.panzhihua.service_community.dao.ConvenientProductDAO">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.panzhihua.service_community.model.dos.ConvenientProductDO">
                <id column="id" property="id" />
                <id column="name" property="name" />
                <id column="category_id" property="categoryId" />
                <id column="merchant_id" property="merchantId" />
                <id column="on_shelf" property="onShelf" />
                <id column="on_shelf_at" property="onShelfAt" />
                <id column="introduction" property="introduction" />
                <id column="is_del" property="isDel" />
                <id column="view_num" property="viewNum" />
                <id column="created_at" property="createdAt" />
                <id column="created_by" property="createdBy" />
                <id column="updated_at" property="updatedAt" />
                <id column="updated_by" property="updatedBy" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,`name`,category_id,merchant_id,on_shelf,on_shelf_at,introduction,is_del,view_num,created_at,created_by,updated_at,updated_by
    </sql>
    <update id="batchDeleteByIds">
        UPDATE com_convenient_products SET is_del = 1 WHERE id IN
        <foreach collection="needDelIds" open="(" separator="," close=")" index="index" item="item">
            #{item}
        </foreach>
    </update>
    <update id="batchOnShelfOrOffShelfByIds">
        UPDATE com_convenient_products SET on_shelf = #{saleStatus},
         <if test="saleStatus">
             on_shelf_at = NOW(),
         </if>
        updated_by = #{updatedBy} WHERE id IN
        <foreach collection="needDealIds" open="(" separator="," close=")" index="index" item="item">
            #{item}
        </foreach>
    </update>
    <update id="incrProductView">
        UPDATE com_convenient_products SET view_num = view_num + 1 WHERE id = #{productId}
    </update>
    <select id="pageProduct" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientProductVO">
        SELECT ccp.id, ccp.name,ccpc.name AS categoryName,ccp.view_num,ccp.on_shelf
        FROM com_convenient_products ccp
        LEFT JOIN com_convenient_product_categories ccpc ON ccp.category_id = ccpc.id
        WHERE ccp.merchant_id = #{pageConvenientProductDTO.merchantId} AND ccp.is_del = 0
        <if test="pageConvenientProductDTO.name != null and pageConvenientProductDTO.name != &quot;&quot;">
            AND ccp.name LIKE CONCAT('%', #{pageConvenientProductDTO.name}, '%')
        </if>
        <if test="pageConvenientProductDTO.categoryId != null and pageConvenientProductDTO.categoryId != 0">
            AND ccp.category_id = #{pageConvenientProductDTO.categoryId}
        </if>
        <if test="pageConvenientProductDTO.onShelf != null">
            AND ccp.on_shelf = #{pageConvenientProductDTO.onShelf}
        </if>
        ORDER BY ccp.created_at DESC
    </select>
    <select id="getMerchantProduct" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientProductVO">
        SELECT  ccp.id, ccp.name, ccp.category_id, ccp.on_shelf_at, ccp.introduction, ccpc.name AS categoryName
        FROM com_convenient_products ccp
        LEFT JOIN com_convenient_product_categories ccpc ON ccp.category_id = ccpc.id
        INNER JOIN com_convenient_product_specifications ccps ON ccp.id = ccps.product_id
        WHERE ccp.merchant_id = #{merchantId} AND ccp.is_del = 0
        AND ccp.on_shelf = 1 AND ccps.is_del = 0 GROUP BY ccp.id ORDER BY ccpc.weight DESC
    </select>
    <select id="getProductSpecifications" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientProductSpecificationVO">
        SELECT  ccps.id, ccps.name, ccps.price, ccps.image, ccps.product_id
        FROM com_convenient_products ccp
        LEFT JOIN com_convenient_product_categories ccpc ON ccp.category_id = ccpc.id
        INNER JOIN com_convenient_product_specifications ccps ON ccp.id = ccps.product_id
        WHERE ccp.merchant_id = #{merchantId} AND ccp.is_del = 0 AND ccp.on_shelf = 1 AND ccps.is_del = 0
    </select>
    <select id="pageSearchProduct" resultType="com.panzhihua.common.model.vos.community.convenient.ConvenientProductVO">
        SELECT ccp.id,ccp.`name`,ccp.category_id,ccp.merchant_id,ccp.introduction
        FROM com_convenient_products ccp
        LEFT JOIN com_convenient_merchants ccm  ON  ccp.merchant_id = ccm.id
        INNER JOIN com_convenient_product_specifications ccps ON ccp.id = ccps.product_id
        WHERE (ccm.community_id = ${pageSearchDTO.communityId} or ccm.community_id = 0) AND ccp.is_del = 0
        AND ccp.on_shelf = 1 AND ccps.is_del = 0 AND ccp.`name` LIKE CONCAT('%', #{pageSearchDTO.keyword}, '%') GROUP BY ccp.id
    </select>
</mapper>