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
<?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.McsProductDAO">
 
    <resultMap type="com.panzhihua.service_community.entity.McsProduct" id="McsProductMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="image" column="image" jdbcType="VARCHAR"/>
        <result property="introduction" column="introduction" jdbcType="VARCHAR"/>
        <result property="viewNum" column="view_num" jdbcType="INTEGER"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="isDel" column="is_del" jdbcType="VARCHAR"/>
        <result property="merchantId" column="merchant_id" jdbcType="INTEGER"/>
        <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
        <result property="createdBy" column="created_by" jdbcType="INTEGER"/>
        <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
        <result property="updatedBy" column="updated_by" jdbcType="INTEGER"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.mcs_product(name, image, introduction, view_num, status, is_del, merchant_id, created_at,
        created_by, updated_at, updated_by)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.image}, #{entity.introduction}, #{entity.viewNum}, #{entity.status},
            #{entity.isDel}, #{entity.merchantId}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt},
            #{entity.updatedBy})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.mcs_product(name, image, introduction, view_num, status, is_del, merchant_id, created_at,
        created_by, updated_at, updated_by)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.image}, #{entity.introduction}, #{entity.viewNum}, #{entity.status},
            #{entity.isDel}, #{entity.merchantId}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt},
            #{entity.updatedBy})
        </foreach>
        on duplicate key update
        name = values(name) , image = values(image) , introduction = values(introduction) , view_num = values(view_num)
        , status = values(status) , is_del = values(is_del) , merchant_id = values(merchant_id) , created_at =
        values(created_at) , created_by = values(created_by) , updated_at = values(updated_at) , updated_by =
        values(updated_by)
    </insert>
    <select id="pageMcsProduct"
            resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsProductVO">
        SELECT t1.id, t1.`name`, t1.image, t1.view_num, t1.`status`, t1.introduction, t3.productLabel
        FROM mcs_product t1
        LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id
        LEFT JOIN (SELECT product_id, GROUP_CONCAT(label_name) AS productLabel FROM mcs_product_label GROUP BY product_id) t3 ON t1.id = t3.product_id
        WHERE t1.is_del = 0 AND t2.is_del = 0
        <if test="pageMcsProductDTO.merchantId != null">
            AND t1.merchant_id = #{pageMcsProductDTO.merchantId}
            AND t1.status = 1
        </if>
        <if test="pageMcsProductDTO.merchantId == null">
            AND t2.user_id = #{pageMcsProductDTO.userId}
        </if>
        <if test="pageMcsProductDTO.status != null">
            AND t1.`status` = #{pageMcsProductDTO.status}
        </if>
        <if test="pageMcsProductDTO.keyword != null and pageMcsProductDTO.keyword != &quot;&quot;">
            AND t1.`name` LIKE CONCAT(#{pageMcsProductDTO.keyword}, '%')
        </if>
        ORDER BY t1.created_at DESC
    </select>
 
</mapper>