廖井涛
2024-03-15 5a5e59f8aaa2a030511ef245886bf6d1db9bf774
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
<!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.CustomerMapper">
 
    <select id="getCustomerList">
        select
            *
        from
            sd.customer
    </select>
    <select id="getSelectCustomer">
        select
            *
        from
            sd.customer c
        <where>
            <if test="customer.id != null and customer.id != ''">
                and c.id regexp #{customer.id}
            </if>
            <if test="customer.customerName != null and customer.customerName != ''">
                and c.customer_name regexp #{customer.customerName}
            </if>
            <if test="customer.grade != null and customer.grade != ''">
                and c.grade regexp #{customer.grade}
            </if>
            <if test="customer.moneyLimit != null and customer.moneyLimit != ''">
                and c.money_limit regexp REGEXP_REPLACE(#{customer.moneyLimit},'\\.0+$','')
            </if>
            <if test="customer.address != null and customer.address != ''">
                and c.address regexp #{customer.address}
            </if>
            <if test="customer.contact != null and customer.contact != ''">
                and c.contact regexp #{customer.contact}
            </if>
            <if test="customer.phone != null and customer.phone != ''">
                and c.phone regexp #{customer.phone}
            </if>
 
        </where>
        limit #{offset},#{pageSize};
    </select>
 
    <select id="getSelectCustomerPageTotal">
        select
            CEILING(count(id)/#{pageSize}) as 'pageTotal',
            count(id) as 'total'
        from
            sd.customer c
        <where>
            <if test="customer.id != null and customer.id != ''">
                and c.id regexp #{customer.id}
            </if>
            <if test="customer.customerName != null and customer.customerName != ''">
                and c.customer_name regexp #{customer.customerName}
            </if>
            <if test="customer.grade != null and customer.grade != ''">
                and c.grade regexp #{customer.grade}
            </if>
            <if test="customer.moneyLimit != null and customer.moneyLimit != ''">
                and c.money_limit regexp REGEXP_REPLACE(#{customer.moneyLimit},'\\.0+$','')
            </if>
            <if test="customer.address != null and customer.address != ''">
                and c.address regexp #{customer.address}
            </if>
            <if test="customer.contact != null and customer.contact != ''">
                and c.contact regexp #{customer.contact}
            </if>
            <if test="customer.phone != null and customer.phone != ''">
                and c.phone regexp #{customer.phone}
            </if>
 
        </where>
        limit #{offset},#{pageSize};
    </select>
 
    <insert id="insertCustomer"  useGeneratedKeys="true" >
        insert into sd.customer(customer_name,grade,money_limit,address,contact,phone)
        values (
                   #{customer.customerName},#{customer.grade},#{customer.moneyLimit},
                #{customer.address},#{customer.contact},#{customer.phone}
               )
    </insert>
 
    <update id="updateCustomer"  useGeneratedKeys="true" >
        update sd.customer set customer_name=#{customer.customerName},grade=#{customer.grade},
                                    money_limit=#{customer.moneyLimit},address= #{customer.address},
                                    contact=#{customer.contact},phone=#{customer.phone} where id=#{customer.id}
    </update>
 
    <delete id="deleteCustomer" >
        delete from sd.customer  where id=#{customer.id}
    </delete>
</mapper>