<?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.psimanage.loss.mapper.PsiLossDetailedMapper">

    <select id="getByBasicId" resultType="com.jeeplus.psimanage.loss.domain.PsiLossDetailed">
        SELECT
            a.id,
            a.create_by_id,
            a.create_time,
            a.update_by_id,
            a.update_time,
            a.del_flag,
            a.remarks,
            a.basic_id,
            a.recipient_agent,
            a.collect_type,
            a.goods_name,
            a.loss_number,
            a.company,
            a.produce_date,
            a.shelf_life,
            a.spec,
            a.shelf_life_unit,
            su.name AS recipientAgent,
            su.id AS recipientAgentId,
            so.name AS recipientOffice,
            d.id AS collectTypeId,
            d.name AS collectType

        FROM psi_management_loss_detailed a
        LEFT JOIN sys_user su ON a.recipient_agent = su.id
        LEFT JOIN sys_office so ON su.office_id = so.id

        LEFT JOIN psi_management_type d ON a.collect_type = d.id
        WHERE a.basic_id = #{id}
          AND a.del_flag = '0'
        ORDER BY a.create_time ASC
    </select>

    <select id="getByAttachmentId" resultType="com.jeeplus.psimanage.oss.service.dto.WorkAttachmentDto">
        SELECT
            id,
            url,
            attachment_name AS `name`,
            create_by_id AS `by`,
            create_time
        FROM work_attachment
        WHERE del_flag = 0
          AND attachment_id = #{id}
    </select>

    <select id="getIdByBasicId" resultType="java.lang.String">
        SELECT id
        FROM psi_management_loss_detailed
        WHERE basic_id = #{id}
          AND del_flag = 0
    </select>
</mapper>
