CustomerShortMapper.xml
3.61 KB
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
<?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.lframework.xingyun.basedata.mappers.CustomerShortMapper">
<resultMap id="CustomerShort" type="com.lframework.xingyun.basedata.entity.CustomerShort">
<id column="id" property="id"/>
<result column="short_name" property="shortName"/>
<result column="customer_id" property="customerId"/>
<result column="customer_name" property="customerName"/>
<result column="type" property="type"/>
<result column="dept_id" property="deptId"/>
<result column="dept_name" property="deptName"/>
<result column="region" property="region"/>
<result column="region_name" property="regionName"/>
<result column="create_by_id" property="createById"/>
<result column="update_by_id" property="updateById"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="CustomerShort_sql">
SELECT
tb.id,
tb.short_name,
tb.customer_id,
c.name as customer_name,
tb.type,
tb.dept_id,
d.name as dept_name,
tb.region,
r.name as region_name,
tb.create_by_id,
tb.update_by_id,
tb.create_time,
tb.update_time
FROM base_data_customer_short AS tb
LEFT JOIN base_data_customer c ON tb.customer_id = c.id
LEFT JOIN sys_dept d ON tb.dept_id = d.id
LEFT JOIN sys_dept r ON tb.region = r.id
</sql>
<select id="query" resultMap="CustomerShort">
<include refid="CustomerShort_sql"/>
<where>
<if test="vo.customerId != null and vo.customerId != ''">
AND tb.customer_id = #{vo.customerId}
</if>
<if test="vo.type != null and vo.type != ''">
AND tb.type = #{vo.type}
</if>
<if test="vo.deptId != null and vo.deptId != ''">
AND tb.dept_id = #{vo.deptId}
</if>
<if test="vo.region != null and vo.region != ''">
AND tb.region = #{vo.region}
</if>
<if test="vo.customerName != null and vo.customerName != ''">
AND c.name LIKE CONCAT('%', #{vo.customerName}, '%')
</if>
<if test="vo.shortName != null and vo.shortName != ''">
AND tb.short_name LIKE CONCAT('%', #{vo.shortName}, '%')
</if>
<if test="vo.deptName != null and vo.deptName != ''">
AND d.name LIKE CONCAT('%', #{vo.deptName}, '%')
</if>
</where>
</select>
<select id="queryShortName" resultMap="CustomerShort">
SELECT id,
short_name,
customer_id,
type,
create_by_id,
update_by_id,
create_time,
update_time
FROM (
SELECT tb.id,
tb.short_name,
tb.customer_id,
tb.type,
tb.create_by_id,
tb.update_by_id,
tb.create_time,
tb.update_time,
ROW_NUMBER() OVER (PARTITION BY tb.short_name ORDER BY tb.id) AS rn
FROM base_data_customer_short AS tb
<where>
<if test="vo.shortName != null and vo.shortName != ''">
AND tb.short_name LIKE CONCAT('%', #{vo.shortName}, '%')
</if>
</where>
) t
WHERE rn = 1
ORDER BY create_time desc
LIMIT #{pageIndex}, #{pageSize}
</select>
</mapper>