yangys
2025-04-11 120755e6874893d284fda5f617924d46960286c0
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?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.qianwen.smartman.modules.tpm.mapper.MaintainPlanMapper">
    <!-- 查询保养日期为当前日的保养计划 -->
    <select id="getPlan" resultType="com.qianwen.smartman.modules.tpm.vo.MaintainPlanVO">
        SELECT id   AS id,
               code AS code
        FROM blade_maintain_plan
        WHERE is_deleted = 0
          AND plan_status = 1
          AND DATE_FORMAT(maintain_date, '%Y-%m-%d') = DATE_FORMAT(
            NOW(),
            '%Y-%m-%d')
    </select>
 
    <select id="export" resultType="com.qianwen.smartman.modules.tpm.vo.excel.MaintainPlanExcel">
        SELECT plan.code AS code,
        plan.device_code AS deviceCode,
        plan.device_name AS deviceName,
        plan.device_type_name AS deviceTypeName,
        plan.project_name AS projectName,
        plan.pre_maintain_time AS preMaintainTime,
        plan.interval_time AS intervalTime,
        plan.maintain_date AS maintaindate
        FROM blade_maintain_plan plan
        WHERE plan.is_deleted = 0
        <if test="tenantId != null and tenantId != ''">
            AND plan.tenant_id = #{tenantId}
        </if>
        <if test="maintainPlanExportDTO.deviceTypeId != null">
            AND plan.device_type_id = #{maintainPlanExportDTO.deviceTypeId}
        </if>
 
        <if test="maintainPlanExportDTO.deviceId != null">
            AND plan.device_id = #{maintainPlanExportDTO.deviceId}
        </if>
 
        <if test="maintainPlanExportDTO.isAuto != null">
            AND plan.is_auto = #{maintainPlanExportDTO.isAuto}
        </if>
 
        <if test="maintainPlanExportDTO.keyWord != null and maintainPlanExportDTO.keyWord != ''">
            AND (plan.code like concat(#{maintainPlanExportDTO.keyWord},'%')
            OR plan.device_code like concat(#{maintainPlanExportDTO.keyWord},'%')
            OR plan.device_name like concat(#{maintainPlanExportDTO.keyWord},'%')
            )
        </if>
        <if test="maintainPlanExportDTO.planStatusList != null and maintainPlanExportDTO.planStatusList.size >0">
            AND plan.plan_status in
            <foreach collection="maintainPlanExportDTO.planStatusList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ORDER BY plan.create_time DESC,plan.id desc
    </select>
 
    <select id="maintainPlanStatisticsNum" resultType="com.qianwen.smartman.modules.tpm.vo.MaintainStatisticsVO">
        SELECT
        IFNULL(SUM(
        CASE WHEN DATE_FORMAT( NOW(), '%Y-%m-%d' ) <![CDATA[ > ]]> DATE_FORMAT( maintain_date, '%Y-%m-%d' )
        AND
        plan_status = 2
        THEN 1 ELSE 0 END ),0) AS delayNum,
        IFNULL(SUM(
        CASE WHEN ( DATE_FORMAT( NOW(), '%Y-%m-%d' )= DATE_FORMAT( maintain_date, '%Y-%m-%d' ) AND plan_status = 2 )
        OR plan_status = 3 THEN
        1 ELSE 0 END),0) AS todayNum,
        IFNULL(SUM(
        CASE WHEN DATE_FORMAT( NOW(), '%Y-%m-%d' ) <![CDATA[ >= ]]>
        <if test="_databaseId == 'mysql' ">
            DATE_FORMAT( date_sub( maintain_date, INTERVAL pre_warning_days DAY ),'%Y-%m-%d' )
        </if>
        <if test="_databaseId == 'dm' ">
            DATE_FORMAT( DATEADD(DAY, -pre_warning_days, maintain_date),'%Y-%m-%d' )
        </if>
        AND DATE_FORMAT( NOW(), '%Y-%m-%d' )<![CDATA[ < ]]> DATE_FORMAT( maintain_date, '%Y-%m-%d' ) AND
        plan_status = 1 THEN
        1 ELSE 0 END),0) AS warningNum
        FROM
        blade_maintain_plan
        WHERE
        is_deleted = 0
        <if test="tenantId != null and tenantId != ''">
            AND tenant_id = #{tenantId}
        </if>
    </select>
 
    <sql id="selectFromMaintainPlan">
        plan
        .
        id
        AS id,
        plan.code AS code, plan.device_id AS deviceId, plan.device_code AS deviceCode, plan.device_name AS deviceName,plan.device_type_id AS deviceTypeId,plan.device_type_name AS deviceTypeName,
        plan.project_id AS pojectId,plan.project_code AS projectCode,plan.project_name AS projectName,plan.maintain_date AS maintainDate,plan.pre_warning_days AS preWarningDays,plan.plan_status AS planStatus,
        plan.is_auto AS isAuto,plan.interval_time AS intervalTime,plan.pre_maintain_time AS preMaintainTime,plan.remark as remark,plan.maintain_nature as maintainNature
        FROM blade_maintain_plan plan
        WHERE plan.is_deleted = 0
    </sql>
 
    <select id="pageMaintainPlanExpire" resultType="com.qianwen.smartman.modules.tpm.vo.MaintainPlanExpireVO">
        SELECT
        <include refid="selectFromMaintainPlan"/>
        AND
        DATE_FORMAT( NOW(), '%Y-%m-%d' ) <![CDATA[ > ]]> DATE_FORMAT( maintain_date, '%Y-%m-%d' )
        AND
        plan_status = 2
        <if test="tenantId != null and tenantId != ''">
            AND plan.tenant_id = #{tenantId}
        </if>
        <if test="maintainPlanExpireQueryVO.code != null and maintainPlanExpireQueryVO.code != ''">
            AND plan.code like concat(#{maintainPlanExpireQueryVO.code},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.deviceCode != null and maintainPlanExpireQueryVO.deviceCode != ''">
            AND plan.device_code like concat(#{maintainPlanExpireQueryVO.deviceCode},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.deviceName != null and maintainPlanExpireQueryVO.deviceName != ''">
            AND plan.device_name like concat(#{maintainPlanExpireQueryVO.deviceName},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.projectName != null and maintainPlanExpireQueryVO.projectName != ''">
            AND plan.project_name like concat(#{maintainPlanExpireQueryVO.projectName},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.isAuto != null">
            AND plan.is_auto = #{maintainPlanExpireQueryVO.isAuto}
        </if>
        ORDER BY plan.maintain_date ASC
    </select>
 
    <select id="pageMaintainPlanToday" resultType="com.qianwen.smartman.modules.tpm.vo.MaintainPlanExpireVO">
        SELECT
        <include refid="selectFromMaintainPlan"/>
        AND
        ((DATE_FORMAT( NOW(), '%Y-%m-%d' ) = DATE_FORMAT( maintain_date, '%Y-%m-%d' )
        AND plan_status = 2)
        OR plan_status = 3)
        <if test="tenantId != null and tenantId != ''">
            AND plan.tenant_id = #{tenantId}
        </if>
        <if test="maintainPlanExpireQueryVO.code != null and maintainPlanExpireQueryVO.code != ''">
            AND plan.code like concat(#{maintainPlanExpireQueryVO.code},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.deviceCode != null and maintainPlanExpireQueryVO.deviceCode != ''">
            AND plan.device_code like concat(#{maintainPlanExpireQueryVO.deviceCode},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.deviceName != null and maintainPlanExpireQueryVO.deviceName != ''">
            AND plan.device_name like concat(#{maintainPlanExpireQueryVO.deviceName},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.projectName != null and maintainPlanExpireQueryVO.projectName != ''">
            AND plan.project_name like concat(#{maintainPlanExpireQueryVO.projectName},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.isAuto != null">
            AND plan.is_auto = #{maintainPlanExpireQueryVO.isAuto}
        </if>
        ORDER BY plan.maintain_date ASC
    </select>
 
    <select id="pageMaintainPlanWarning" resultType="com.qianwen.smartman.modules.tpm.vo.MaintainPlanExpireVO">
        SELECT
        <include refid="selectFromMaintainPlan"/>
        AND
        <if test="_databaseId == 'mysql' ">
            (DATE_FORMAT( NOW(), '%Y-%m-%d' ) <![CDATA[ >= ]]>
            DATE_FORMAT(date_sub( maintain_date, INTERVAL pre_warning_days DAY ),'%Y-%m-%d'))
        </if>
        <if test="_databaseId == 'dm' ">
            (TO_DATE(NOW(), 'YYYY-MM-DD') <![CDATA[ >= ]]>
            TO_DATE(DATEADD(DAY, -pre_warning_days, maintain_date),'YYYY-MM-DD'))
        </if>
        AND
        <if test="_databaseId == 'mysql' ">
            (DATE_FORMAT( NOW(), '%Y-%m-%d' )<![CDATA[ < ]]> DATE_FORMAT( maintain_date, '%Y-%m-%d'))
        </if>
        <if test="_databaseId == 'dm' ">
            (TO_DATE(NOW(), 'YYYY-MM-DD') <![CDATA[ < ]]> TO_DATE(maintain_date, 'YYYY-MM-DD'))
        </if>
        AND
        plan_status = 1
        <if test="tenantId != null and tenantId != ''">
            AND plan.tenant_id = #{tenantId}
        </if>
        <if test="maintainPlanExpireQueryVO.code != null and maintainPlanExpireQueryVO.code != ''">
            AND plan.code like concat(#{maintainPlanExpireQueryVO.code},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.deviceCode != null and maintainPlanExpireQueryVO.deviceCode != ''">
            AND plan.device_code like concat(#{maintainPlanExpireQueryVO.deviceCode},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.deviceName != null and maintainPlanExpireQueryVO.deviceName != ''">
            AND plan.device_name like concat(#{maintainPlanExpireQueryVO.deviceName},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.projectName != null and maintainPlanExpireQueryVO.projectName != ''">
            AND plan.project_name like concat(#{maintainPlanExpireQueryVO.projectName},'%')
        </if>
        <if test="maintainPlanExpireQueryVO.isAuto != null">
            AND plan.is_auto = #{maintainPlanExpireQueryVO.isAuto}
        </if>
        ORDER BY plan.maintain_date ASC
    </select>
 
</mapper>