wlzboy
5 天以前 7de1396e315896dbc72a9d54e44f77434ea90f18
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
<?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.SysTaskAttachmentMapper">
    
    <resultMap type="SysTaskAttachment" id="SysTaskAttachmentResult">
        <result property="attachmentId"     column="attachment_id"     />
        <result property="taskId"           column="task_id"           />
        <result property="fileName"         column="file_name"         />
        <result property="filePath"         column="file_path"         />
        <result property="fileSize"         column="file_size"         />
        <result property="fileType"         column="file_type"         />
        <result property="attachmentCategory" column="attachment_category" />
        <result property="uploadTime"       column="upload_time"       />
        <result property="uploadBy"         column="upload_by"         />
        <result property="syncedToImageData" column="synced_to_image_data" />
        <result property="syncTime"         column="sync_time"         />
        <result property="imageDataId"      column="image_data_id"     />
    </resultMap>
 
    <sql id="selectSysTaskAttachmentVo">
        select attachment_id, task_id, file_name, file_path, file_size, file_type, attachment_category, upload_time, upload_by, synced_to_image_data, sync_time, image_data_id
        from sys_task_attachment
    </sql>
 
    <select id="selectSysTaskAttachmentList" parameterType="SysTaskAttachment" resultMap="SysTaskAttachmentResult">
        <include refid="selectSysTaskAttachmentVo"/>
        <where>  
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileType != null  and fileType != ''"> and file_type = #{fileType}</if>
            <if test="attachmentCategory != null and attachmentCategory != ''"> and attachment_category = #{attachmentCategory}</if>
            <if test="uploadBy != null  and uploadBy != ''"> and upload_by like concat('%', #{uploadBy}, '%')</if>
        </where>
        order by upload_time desc
    </select>
    
    <select id="selectSysTaskAttachmentByAttachmentId" parameterType="Long" resultMap="SysTaskAttachmentResult">
        <include refid="selectSysTaskAttachmentVo"/>
        where attachment_id = #{attachmentId}
    </select>
 
    <select id="selectSysTaskAttachmentByTaskId" parameterType="Long" resultMap="SysTaskAttachmentResult">
        <include refid="selectSysTaskAttachmentVo"/>
        where task_id = #{taskId}
        order by upload_time desc
    </select>
        
    <insert id="insertSysTaskAttachment" parameterType="SysTaskAttachment" useGeneratedKeys="true" keyProperty="attachmentId">
        insert into sys_task_attachment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="fileName != null and fileName != ''">file_name,</if>
            <if test="filePath != null and filePath != ''">file_path,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="fileType != null">file_type,</if>
            <if test="attachmentCategory != null and attachmentCategory != ''">attachment_category,</if>
            <if test="uploadTime != null">upload_time,</if>
            <if test="uploadBy != null and uploadBy != ''">upload_by,</if>
            <if test="syncedToImageData != null">synced_to_image_data,</if>
            <if test="syncTime != null">sync_time,</if>
            <if test="imageDataId != null">image_data_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="fileName != null and fileName != ''">#{fileName},</if>
            <if test="filePath != null and filePath != ''">#{filePath},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="attachmentCategory != null and attachmentCategory != ''">#{attachmentCategory},</if>
            <if test="uploadTime != null">#{uploadTime},</if>
            <if test="uploadBy != null and uploadBy != ''">#{uploadBy},</if>
            <if test="syncedToImageData != null">#{syncedToImageData},</if>
            <if test="syncTime != null">#{syncTime},</if>
            <if test="imageDataId != null">#{imageDataId},</if>
         </trim>
    </insert>
 
    <update id="updateSysTaskAttachment" parameterType="SysTaskAttachment">
        update sys_task_attachment
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="fileName != null and fileName != ''">file_name = #{fileName},</if>
            <if test="filePath != null and filePath != ''">file_path = #{filePath},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="attachmentCategory != null and attachmentCategory != ''">attachment_category = #{attachmentCategory},</if>
            <if test="uploadTime != null">upload_time = #{uploadTime},</if>
            <if test="uploadBy != null and uploadBy != ''">upload_by = #{uploadBy},</if>
            <if test="syncedToImageData != null">synced_to_image_data = #{syncedToImageData},</if>
            <if test="syncTime != null">sync_time = #{syncTime},</if>
            <if test="imageDataId != null">image_data_id = #{imageDataId},</if>
        </trim>
        where attachment_id = #{attachmentId}
    </update>
 
    <delete id="deleteSysTaskAttachmentByAttachmentId" parameterType="Long">
        delete from sys_task_attachment where attachment_id = #{attachmentId}
    </delete>
 
    <delete id="deleteSysTaskAttachmentByAttachmentIds" parameterType="String">
        delete from sys_task_attachment where attachment_id in 
        <foreach item="attachmentId" collection="array" open="(" separator="," close=")">
            #{attachmentId}
        </foreach>
    </delete>
 
    <delete id="deleteSysTaskAttachmentByTaskId" parameterType="Long">
        delete from sys_task_attachment where task_id = #{taskId}
    </delete>
    
    <!-- 查询待同步的任务附件列表 -->
    <select id="selectPendingSyncAttachments" resultMap="SysTaskAttachmentResult">
        SELECT 
            a.attachment_id,
            a.task_id,
            a.file_name,
            a.file_path,
            a.file_size,
            a.file_type,
            a.attachment_category,
            a.upload_time,
            a.upload_by,
            a.synced_to_image_data,
            a.sync_time,
            a.image_data_id
        FROM sys_task_attachment a
        INNER JOIN sys_task t ON a.task_id = t.task_id
        INNER JOIN sys_task_emergency e ON t.task_id = e.task_id
        WHERE t.task_type = 'EMERGENCY_TRANSFER'
            AND e.dispatch_sync_status = 2
            AND e.legacy_dispatch_ord_id IS NOT NULL
            AND e.legacy_service_ord_id IS NOT NULL
            AND (a.synced_to_image_data = 0 OR a.synced_to_image_data IS NULL)
        ORDER BY a.upload_time ASC
    </select>
</mapper>