Bang Hu
2 天以前 2b0b64182263d922b946ec898070e59b602382dc
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
<?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.webmanage.mapper.ProductMapper">
 
    <!-- 结果映射 -->
    <resultMap id="BaseResultMap" type="com.webmanage.entity.Product">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="product_name" property="productName" jdbcType="VARCHAR"/>
        <result column="product_code" property="productCode" jdbcType="VARCHAR"/>
        <result column="product_type" property="productType" jdbcType="VARCHAR"/>
        <result column="category" property="category" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="provider_id" property="providerId" jdbcType="BIGINT"/>
        <result column="provider_name" property="providerName" jdbcType="VARCHAR"/>
        <result column="provider_type" property="providerType" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="VARCHAR"/>
        <result column="audit_status" property="auditStatus" jdbcType="VARCHAR"/>
        <result column="tags" property="tags" jdbcType="VARCHAR"/>
        <result column="cover_image" property="coverImage" jdbcType="VARCHAR"/>
        <result column="demo_url" property="demoUrl" jdbcType="VARCHAR"/>
        <result column="doc_url" property="docUrl" jdbcType="VARCHAR"/>
        <result column="created_at" property="createdAt" jdbcType="TIMESTAMP"/>
        <result column="updated_at" property="updatedAt" jdbcType="TIMESTAMP"/>
        <result column="created_by" property="createdBy" jdbcType="BIGINT"/>
        <result column="updated_by" property="updatedBy" jdbcType="BIGINT"/>
        <result column="deleted" property="deleted" jdbcType="INTEGER"/>
    </resultMap>
 
    <!-- 基础字段 -->
    <sql id="Base_Column_List">
        id, product_name, product_code, product_type, category, description, 
        provider_id, provider_name, provider_type, status, audit_status, 
        tags, cover_image, demo_url, doc_url, created_at, updated_at, 
        created_by, updated_by, deleted
    </sql>
 
    <!-- 根据条件查询产品列表 -->
    <select id="selectProductList" resultMap="BaseResultMap">
        SELECT 
        <include refid="Base_Column_List"/>
        FROM tb_product
        WHERE deleted = 0
        <if test="productName != null and productName != ''">
            AND product_name LIKE CONCAT('%', #{productName}, '%')
        </if>
        <if test="productType != null and productType != ''">
            AND product_type = #{productType}
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </if>
        <if test="providerId != null">
            AND provider_id = #{providerId}
        </if>
        ORDER BY created_at DESC
    </select>
 
    <!-- 根据ID查询产品详情 -->
    <select id="selectProductById" resultMap="BaseResultMap">
        SELECT 
        <include refid="Base_Column_List"/>
        FROM tb_product
        WHERE id = #{id} AND deleted = 0
    </select>
 
    <!-- 更新产品状态 -->
    <update id="updateProductStatus">
        UPDATE tb_product
        SET status = #{status}, updated_at = CURRENT_TIMESTAMP
        WHERE id = #{id} AND deleted = 0
    </update>
 
    <!-- 更新产品审核状态 -->
    <update id="updateProductAuditStatus">
        UPDATE tb_product
        SET audit_status = #{auditStatus}, updated_at = CURRENT_TIMESTAMP
        WHERE id = #{id} AND deleted = 0
    </update>
 
</mapper>