DigitalManagementTemplateStaffRefMapper.xml
5.56 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?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="cn.com.glsx.dj.mindworkplate.mapper.digitalmanagement.DigitalManagementTemplateStaffRefMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.digitalmanagement.DigitalManagementTemplateStaffRef" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="template_code" property="templateCode" jdbcType="VARCHAR" />
<result column="staff_uuid_list" property="staffUuidListStr" jdbcType="VARCHAR" />
<result column="effective_date" property="effectiveDate" jdbcType="DATE" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
</resultMap>
<resultMap id="DTOResult" type="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.DigitalManagementTemplateStaffRefDTO" extends="BaseResultMap"/>
<sql id="Base_Column_List" >
<!--
WARNING - @mbg.generated
-->
id, template_code, staff_uuid_list, effective_date, created_by, created_date, updated_by,
updated_date, deleted_flag
</sql>
<select id="findCondition" resultMap="DTOResult"
parameterType="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.DigitalManagementTemplateDTO">
select *
from digital_management_template_staff_ref
where id in (
select max(id) from digital_management_template_staff_ref
<where>
deleted_flag = 'N'
<if test="code != null and code != ''">
and template_code = #{code}
</if>
<if test="startTime != null">
and effective_date > date(#{startTime})
</if>
<if test="endTime != null">
and effective_date <= date(#{endTime})
</if>
<!-- 每日最新数据,旧数据不用管,反正修改圈人,记录也会被删除
<if test="staffUuidList != null and staffUuidList.size() > 0">
and
<foreach collection="staffUuidList" item="item" open="(" separator=" OR " close=")">
FIND_IN_SET(#{item}, staff_uuid_list) > 0
</foreach>
</if>
-->
</where>
group by effective_date
)
union
(select * from dj_smartcarlife.digital_management_template_staff_ref
<where>
deleted_flag = 'N'
<if test="code != null and code != ''">
and template_code = #{code}
</if>
<if test="startTime != null">
and effective_date <= date(#{startTime})
</if>
<if test="staffUuidList != null and staffUuidList.size() > 0">
and
<foreach collection="staffUuidList" item="item" open="(" separator=" OR " close=")">
FIND_IN_SET(#{item}, staff_uuid_list) > 0
</foreach>
</if>
</where>
order by created_date desc limit 1)
order by id;
</select>
<select id="findByCodeAndTime" resultMap="DTOResult">
select *
from digital_management_template_staff_ref
where deleted_flag = 'N'
and template_code = #{templateCode}
and effective_date = date(#{date})
order by created_date desc, id desc
limit 1
</select>
<select id="findLatestByCode" resultMap="DTOResult">
select *
from digital_management_template_staff_ref
where deleted_flag = 'N'
and template_code = #{templateCode}
order by created_date desc, id desc
limit 1
</select>
<select id="getTemplateBindingStaff" resultType="string">
select
sr.staff_uuid_list
from digital_management_template_staff_ref sr
right join (
select max(sr.template_code) as template_code, max(sr.created_date) as max_cd
from digital_management_template_staff_ref sr
left join digital_management_template t on t.code = sr.template_code
where sr.deleted_flag = "N" and t.deleted_flag = "N"
<if test="filterTemplateTypeName != null and filterTemplateTypeName != ''">
and t.type_name != #{filterTemplateTypeName}
</if>
group by t.`type`
) as m on m.template_code = sr.template_code and sr.created_date = m.max_cd
<where>
<if test="staffUuids != null and staffUuids.size() > 0">
and
<foreach collection="staffUuids" item="item" open="(" separator=" OR " close=")">
FIND_IN_SET(#{item}, staff_uuid_list) > 0
</foreach>
</if>
</where>
</select>
<resultMap id="TemplateStaffRefDTO" type="cn.com.glsx.dj.mindworkplate.dto.digitalmanagement.TemplateStaffRefDTO" extends="BaseResultMap">
<result column="target_date" property="targetDate" jdbcType="VARCHAR" />
</resultMap>
<select id="findLatestRecordsByDates"
resultMap="TemplateStaffRefDTO">
SELECT
d.*,
tmp.target_date
FROM (
<foreach collection="targetDates" item="date" index="index" separator=" UNION ALL ">
SELECT #{date} AS target_date
</foreach>
) tmp
LEFT JOIN digital_management_template_staff_ref d ON d.id = (
SELECT d1.id
FROM digital_management_template_staff_ref d1
WHERE d1.deleted_flag = 'N'
AND d1.template_code = #{templateCode}
AND d1.effective_date <= tmp.target_date
ORDER BY d1.effective_date DESC
LIMIT 1
)
WHERE d.id IS NOT NULL
ORDER BY tmp.target_date
</select>
</mapper>