<?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.jeeplus.test.oss.mapper.OssServiceMapper">

  <select id="selectSaveById" resultType="java.lang.Integer">
    SELECT
        COUNT( 0 )
    FROM
        work_attachment
    WHERE
        del_flag = 0
        AND attachment_id = (
        SELECT
            attachment_id
        FROM
            work_attachment
    WHERE
        id = #{id})
  </select>

  <update id="updateProjectRecord">
    UPDATE project_records
    SET file_upload_type = 0
    WHERE
        id = (
        SELECT
            attachment_id
        FROM
            work_attachment
    WHERE
        id = #{id})
  </update>

    <select id="findList" resultType="com.jeeplus.test.oss.domain.WorkAttachment">
        SELECT a.id, a.url, a.type, a.attachment_id, a.attachment_name, a.attachment_flag,
        a.module_type, a.attachment_type, a.file_size, a.sort, a.description,
        a.create_date, a.create_by as "create_by.id", su.name as "createBy.name" , a.update_date, a.update_by as "updateBy.id", a.del_flag
         FROM work_attachment a
         left join sys_user su on su.id = a.create_by
         ${ew.customSqlSegment}
         ORDER BY a.sort ASC;
    </select>

    <insert id="insertWorkAttachment">
        INSERT INTO work_attachment (
            id,
            create_by,
            create_date,
            update_by,
            update_date,
            del_flag,
            url,
            type,
            attachment_id,
            attachment_name,
            attachment_flag,
            file_size,
            sort
            )
        VALUES(
            #{workAttachment.id},
            #{userDto.id},
            #{workAttachment.createDate},
            #{userDto.id},
            #{workAttachment.updateDate},
            #{workAttachment.delFlag},
            #{workAttachment.url},
            #{workAttachment.type},
            #{workAttachment.attachmentId},
            #{workAttachment.attachmentName},
            #{workAttachment.attachmentFlag},
            #{workAttachment.fileSize},
            #{workAttachment.sort}
            )
    </insert>
</mapper>