DutyRosterPlanSMapper.xml
7.13 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?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.zteits.park.mapper.smapper.DutyRosterPlanSMapper">
<resultMap id="BaseResultMap" type="com.zteits.park.domain.DutyRosterPlan">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="org_id" jdbcType="BIGINT" property="orgId" />
<result column="plan_id" jdbcType="BIGINT" property="planId" />
<result column="duty_type" jdbcType="INTEGER" property="dutyType" />
<result column="plan_name" jdbcType="VARCHAR" property="planName" />
<result column="effect_time" jdbcType="TIMESTAMP" property="effectTime" />
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="employee_num" jdbcType="INTEGER" property="employeeNum" />
<result column="pl_num" jdbcType="INTEGER" property="plNum" />
<result column="duty_cycle" jdbcType="INTEGER" property="dutyCycle" />
<result column="berth_range_num" jdbcType="INTEGER" property="berthRangeNum" />
<result column="rest_type" jdbcType="VARCHAR" property="restType" />
<result column="area_manage_type" jdbcType="INTEGER" property="areaManageType" />
<result column="data_status" jdbcType="INTEGER" property="dataStatus" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="create_op" jdbcType="BIGINT" property="createOp" />
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
<result column="modify_op" jdbcType="BIGINT" property="modifyOp" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, org_id, plan_id, duty_type, plan_name, effect_time, expire_time, employee_num,
pl_num, duty_cycle, berth_range_num, rest_type, area_manage_type, data_status, create_time,
create_op, modify_time, modify_op
</sql>
<select id="queryDutyPlanMaxDutyDay" resultType="com.zteits.park.domain.bean.DutyRosterPlanDO">
SELECT
a.plan_id AS planId,
a.plan_name AS planName,
a.duty_cycle AS dutyCycle,
b.duty_day AS dutyDay
FROM
duty_roster_plan a
LEFT JOIN (
SELECT
c.plan_id,
max(c.duty_day) AS duty_day
FROM
duty_roster c
WHERE
c.data_status = 1
GROUP BY
c.plan_id
) b ON a.plan_id = b.plan_id
WHERE
1 = 1
AND a.data_status = 1
<![CDATA[and a.effect_time <= now()
and a.expire_time >= now()]]>
<if test="dutyType != null">
and a.duty_type = #{dutyType}
</if>
GROUP BY
a.plan_id,
a.plan_name,
a.duty_cycle,
b.duty_day
</select>
<select id="queryPlanIdOfEffectDutyRosterPlan" resultType="java.lang.Long">
SELECT DISTINCT t.plan_id
FROM duty_roster_plan t
WHERE t.expire_time > now() AND data_status = 1
<if test="dutyType != null">
and t.duty_type = #{dutyType}
</if>
</select>
<update id="decreasePlNumFromRosterPlan">
UPDATE duty_roster_plan
<set>
<if test="plNum != 0 ">
pl_num = (
CASE
WHEN (pl_num - #{plNum}) > 0 THEN (pl_num - #{plNum})
ELSE 1
END
),
</if>
<if test="chargerNum != 0 ">
employee_num = #{chargerNum}
</if>
</set>
WHERE
1=1
and plan_id = #{planId}
</update>
<update id="updatePlNumAndEmployeeNumForRosterPlan" parameterType="com.zteits.clouds.api.dto.park.param.dutyroster.DutyRosterForAddRosterInfoReq">
update duty_roster_plan
<set>
<if test="employeeNum != null">
employee_num = #{employeeNum,jdbcType=INTEGER},
</if>
<if test="plNum != null">
pl_num = #{plNum,jdbcType=INTEGER}
</if>
</set>
where data_status = 1
and plan_id = #{planId}
</update>
</mapper>