chenlu
2024-06-07 2f640b1038fa331954f78ed1f4317212cf5bb34d
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?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.example.erp.mapper.sd.ProductMapper">
    <resultMap id="productMap" type="com.example.erp.entity.sd.Product" >
        <id column="id" property="id"/>
        <result column="product_name" property="productName"/>
        <result column="product" property="productName"/>
        <result column="total_thickness" property="totalThickness"/>
        <result column="thickness" property="thickness"/>
        <result column="query" property="query"/>
        <result column="remarks" property="remarks"/>
        <result column="state" property="state"/>
        <result column="creator" property="creator"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <!--接收其他外键实体类数据-->
        <association property="basicGlassType" javaType="com.example.erp.entity.sd.BasicGlassType">
            <result column="type_id" property="typeId"/>
            <result column="type_name" property="typeName"/>
        </association>
 
        <!--<result column="g_typeId" property="glassTypes.typeId"/>
        <result column="g_type" property="glassTypes.type"/>-->
 
    </resultMap>
 
    <select id="defaultProduct" resultMap="productMap">
        select a.id ,
        a.product_name,
        a.total_thickness,
        a.thickness,
        a.query,
        a.remarks,
        a.state,
        a.creator,
        date(a.create_time) as create_time,
        a.update_time       as update_time,
        a.type_id         as type_id,
        bgt.type_name
        from product as a
        left join basic_glass_type bgt on bgt.type_id = a.type_id
        <where>
            <if test="glassTypeId != null and glassTypeId != ''">
                and a.type_id regexp #{glassTypeId}
            </if>
            <if test="product.id != null and product.id != ''">
                and a.id regexp #{product.id}
            </if>
            <if test="product.productName != null and product.productName != ''">
                and a.product_name regexp #{product.productName}
            </if>
            <if test="product.basicGlassType.typeName != null and product.basicGlassType.typeName!= ''">
                and bgt.type_name regexp #{product.basicGlassType.typeName}
            </if>
            <if test="product.query != null and product.query != ''">
                and a.query regexp #{product.query}
            </if>
            <if test="product.creator != null and product.creator != ''">
                and a.creator regexp #{product.creator}
            </if>
            <if test="product.createTime != null and product.createTime != ''">
                and date(a.create_time) regexp #{product.createTime}
            </if>
        </where>
 
        order by id desc
        limit #{offset},#{pageSize}
        ;
    </select>
 
    <select id="getPageTotal" >
        select
            CEILING(count(a.id)/#{pageSize})
        from product as a
        left join basic_glass_type bgt on bgt.type_id = a.type_id
        <where>
            <if test="glassTypeId != null and glassTypeId != ''">
                and a.type_id regexp #{glassTypeId}
            </if>
            <if test="product.id != null and product.id != ''">
                and a.id regexp #{product.id}
            </if>
            <if test="product.productName != null and product.productName != ''">
                and a.product_name regexp #{product.productName}
            </if>
            <if test="product.basicGlassType.typeName != null and product.basicGlassType.typeName!= ''">
                and bgt.type_name regexp #{product.basicGlassType.typeName}
            </if>
            <if test="product.query != null and product.query != ''">
                and a.query regexp #{product.query}
            </if>
            <if test="product.creator != null and product.creator != ''">
                and a.creator regexp #{product.creator}
            </if>
            <if test="product.createTime != null and product.createTime != ''">
                and date(a.create_time) regexp #{product.createTime}
            </if>
        </where>
 
        order by a.id desc
        limit #{offset},#{pageSize}
        ;
    </select>
    
    <update id="updateProductStateById">
        update product set state = #{state} where id = #{id}
    </update>
</mapper>