<?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.oa.mapper.SysOaClaimMapper">

    <resultMap type="com.ruoyi.oa.domain.vo.SysOaClaimVo" id="SysOaClaimResult">
        <result property="claimId" column="claim_id"/>
        <result property="userId" column="user_id"/>
        <result property="fileIds" column="file_ids"/>
        <result property="remark" column="remark"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="tripDays" column="trip_days"/>
        <result property="cost" column="cost"/>
        <result property="detailNumber" column="detail_number"/>
        <result property="projectId" column="project_id"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="delFlag" column="del_flag"/>
        <result property="procInsId" column="proc_ins_id"/>
        <result property="status" column="status_"/>
        <result property="completedTime" column="completed_time"/>
        <result property="projectName" column="project_name"/>
        <result property="address" column="address"/>
        <collection property="detailList" javaType="list" resultMap="SysOaClaimDetailResult"/>
        <collection property="fileList" javaType="list" resultMap="SysOssResult"/>
    </resultMap>

    <resultMap type="com.ruoyi.oa.domain.SysOaClaimDetail" id="SysOaClaimDetailResult">
        <result property="claimDetailId" column="claim_detail_id"/>
        <result property="claimId" column="claim_id"/>
        <result property="claimType" column="claim_type"/>
        <result property="beginTime" column="begin_time"/>
        <result property="endTime" column="detail_end"/>
        <result property="lodgingAddress" column="lodging_address"/>
        <result property="remark" column="remark"/>
        <result property="cost" column="detail_cost"/>
        <result property="bigCost" column="big_cost"/>
    </resultMap>


    <resultMap type="com.ruoyi.system.domain.SysOss" id="SysOssResult">
        <result property="ossId" column="oss_id"/>
        <result property="url" column="file_url"/>
        <result property="fileName" column="file_name"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <select id="selectSysOaClaimVoById" resultMap="SysOaClaimResult" parameterType="Long">
        SELECT soc.claim_id,
               soc.user_id,
               soc.file_ids,
               soc.remark,
               soc.start_time,
               soc.end_time,
               soc.address,
               soc.trip_days,
               soc.cost,
               soc.detail_number,
               soc.project_id,
               soc.create_time,
               soc.create_by,
               soc.update_time,
               soc.update_by,
               soc.del_flag,
               soc.proc_ins_id,
               soc.completed_time,
               socd.claim_detail_id,
               claim_type,
               socd.begin_time ,
               socd.end_time as detail_end,
               socd.lodging_address,
               socd.create_time,
               socd.create_by,
               socd.update_time,
               socd.update_by,
               socd.del_flag,
               socd.remark,
               socd.file_ids,
               socd.cost as detail_cost,
               socd.big_cost,
               sop.project_name
        FROM sys_oa_claim soc
                 left join sys_oa_claim_detail socd on soc.claim_id = socd.claim_id
                left join sys_oa_project sop on soc.project_id = sop.project_id
        where soc.claim_id = #{claimId}
    </select>

    <select id="selectPageVo" resultMap="SysOaClaimResult">
        SELECT soc.claim_id,
               soc.user_id,
               soc.file_ids,
               soc.remark,
               soc.start_time,
               soc.end_time,
               soc.trip_days,
               soc.cost,
               soc.detail_number,
               soc.project_id,
               soc.address,
               soc.create_time,
               soc.create_by,
               soc.update_time,
               soc.update_by,
               soc.del_flag,
               soc.proc_ins_id,
               soc.completed_time,
               sop.project_name,
               IF(ahp.END_TIME_ IS NULL, 0, 1) AS status_
        FROM sys_oa_claim soc
                 left join ACT_HI_PROCINST ahp on soc.proc_ins_id = ahp.PROC_INST_ID_
                    left join sys_oa_project sop on sop.project_id = soc.project_id
            ${ew.getCustomSqlSegment}
    </select>

    <select id="selectSysOaClaimVoByProcInsId" resultMap="SysOaClaimResult" parameterType="String">
        SELECT soc.claim_id,
               soc.user_id,
               soc.file_ids,
               soc.remark,
               soc.start_time,
               soc.end_time,
               soc.address,
               soc.trip_days,
               soc.cost,
               soc.detail_number,
               soc.project_id,
               soc.create_time,
               soc.create_by,
               soc.update_time,
               soc.update_by,
               soc.del_flag,
               soc.proc_ins_id,
               soc.completed_time,
               socd.claim_detail_id,
               claim_type,
               socd.begin_time ,
               socd.end_time as detail_end,
               socd.lodging_address,
               socd.create_time,
               socd.create_by,
               socd.update_time,
               socd.update_by,
               socd.del_flag,
               socd.remark,
               socd.file_ids,
               socd.cost as detail_cost,
               socd.big_cost,
               sop.project_name
        FROM sys_oa_claim soc
                 left join sys_oa_claim_detail socd on soc.claim_id = socd.claim_id
                 left join sys_oa_project sop on soc.project_id = sop.project_id
        where soc.proc_ins_id = #{procInsId}
    </select>
    <select id="getClaimCost" resultType="java.lang.Double">
            SELECT SUM(cost) FROM sys_oa_claim WHERE claim_id = #{claimId} and del_flag = '0'
    </select>


</mapper>
