wlzboy
3 天以前 40a8157440e3b906da8f52e07d939d78c3f4c313
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
<?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.ruoyi.system.mapper.VehicleAlertConfigMapper">
    
    <resultMap type="VehicleAlertConfig" id="VehicleAlertConfigResult">
        <result property="configId"    column="config_id"    />
        <result property="configType"    column="config_type"    />
        <result property="deptId"    column="dept_id"    />
        <result property="vehicleId"    column="vehicle_id"    />
        <result property="mileageThreshold"    column="mileage_threshold"    />
        <result property="dailyAlertLimit"    column="daily_alert_limit"    />
        <result property="alertInterval"    column="alert_interval"    />
        <result property="notifyUserIds"    column="notify_user_ids"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>
 
    <sql id="selectVehicleAlertConfigVo">
        select c.config_id, c.config_type, c.dept_id, c.vehicle_id, c.mileage_threshold, 
               c.daily_alert_limit, c.alert_interval, c.notify_user_ids, c.status, c.remark, 
               c.create_by, c.create_time, c.update_by, c.update_time,
               CASE 
                   WHEN c.config_type = 'DEPT' THEN d.dept_name
                   WHEN c.config_type = 'VEHICLE' THEN v.vehicle_no
                   ELSE NULL
               END as target_name
        from tb_vehicle_alert_config c
        left join sys_dept d on c.dept_id = d.dept_id
        left join tb_vehicle_info v on c.vehicle_id = v.vehicle_id
    </sql>
 
    <select id="selectVehicleAlertConfigList" parameterType="VehicleAlertConfig" resultMap="VehicleAlertConfigResult">
        <include refid="selectVehicleAlertConfigVo"/>
        <where>  
            <if test="configType != null  and configType != ''"> and c.config_type = #{configType}</if>
            <if test="deptId != null "> and c.dept_id = #{deptId}</if>
            <if test="vehicleId != null "> and c.vehicle_id = #{vehicleId}</if>
            <if test="status != null  and status != ''"> and c.status = #{status}</if>
        </where>
        order by 
            CASE c.config_type 
                WHEN 'GLOBAL' THEN 3
                WHEN 'DEPT' THEN 2
                WHEN 'VEHICLE' THEN 1
            END,
            c.create_time desc
    </select>
    
    <select id="selectVehicleAlertConfigByConfigId" parameterType="Long" resultMap="VehicleAlertConfigResult">
        <include refid="selectVehicleAlertConfigVo"/>
        where c.config_id = #{configId}
    </select>
 
    <select id="selectConfigByVehicle" resultMap="VehicleAlertConfigResult">
        <include refid="selectVehicleAlertConfigVo"/>
        where c.status = '0'
        and (
            (c.config_type = 'VEHICLE' and c.vehicle_id = #{vehicleId})
            or (c.config_type = 'DEPT' and c.dept_id = #{deptId})
            or c.config_type = 'GLOBAL'
        )
        order by 
            CASE c.config_type 
                WHEN 'VEHICLE' THEN 1
                WHEN 'DEPT' THEN 2
                WHEN 'GLOBAL' THEN 3
            END
        limit 1
    </select>
        
    <insert id="insertVehicleAlertConfig" parameterType="VehicleAlertConfig" useGeneratedKeys="true" keyProperty="configId">
        insert into tb_vehicle_alert_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="configType != null and configType != ''">config_type,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="vehicleId != null">vehicle_id,</if>
            <if test="mileageThreshold != null">mileage_threshold,</if>
            <if test="dailyAlertLimit != null">daily_alert_limit,</if>
            <if test="alertInterval != null">alert_interval,</if>
            <if test="notifyUserIds != null">notify_user_ids,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="configType != null and configType != ''">#{configType},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="vehicleId != null">#{vehicleId},</if>
            <if test="mileageThreshold != null">#{mileageThreshold},</if>
            <if test="dailyAlertLimit != null">#{dailyAlertLimit},</if>
            <if test="alertInterval != null">#{alertInterval},</if>
            <if test="notifyUserIds != null">#{notifyUserIds},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            now()
         </trim>
    </insert>
 
    <update id="updateVehicleAlertConfig" parameterType="VehicleAlertConfig">
        update tb_vehicle_alert_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="configType != null and configType != ''">config_type = #{configType},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="vehicleId != null">vehicle_id = #{vehicleId},</if>
            <if test="mileageThreshold != null">mileage_threshold = #{mileageThreshold},</if>
            <if test="dailyAlertLimit != null">daily_alert_limit = #{dailyAlertLimit},</if>
            <if test="alertInterval != null">alert_interval = #{alertInterval},</if>
            <if test="notifyUserIds != null">notify_user_ids = #{notifyUserIds},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = now()
        </trim>
        where config_id = #{configId}
    </update>
 
    <delete id="deleteVehicleAlertConfigByConfigId" parameterType="Long">
        delete from tb_vehicle_alert_config where config_id = #{configId}
    </delete>
 
    <delete id="deleteVehicleAlertConfigByConfigIds" parameterType="String">
        delete from tb_vehicle_alert_config where config_id in 
        <foreach item="configId" collection="array" open="(" separator="," close=")">
            #{configId}
        </foreach>
    </delete>
</mapper>