<?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="org.springblade.system.mapper.TransferApplyMapper">
	<insert id="insert" useGeneratedKeys="true" keyProperty="id">
		INSERT INTO da_ky_transfer_apply
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="proId != null and proId != ''">
				pro_id,
			</if>
			<if test="proName != null and proName != ''">
				pro_name,
			</if>
			<if test="singleProName != null and singleProName != ''">
				single_pro_name,
			</if>
			<if test="deptId != null and deptId != ''">
				dept_id,
			</if>
			<if test="deptName != null and deptName != ''">
				dept_name,
			</if>
			<if test="applyUser != null and applyUser != ''">
				apply_user,
			</if>
			<if test="applyTime != null">
				apply_time,
			</if>
			<if test="auditStatus != null and auditStatus != ''">
				audit_status,
			</if>
			<if test="auditOpinion != null and auditOpinion != ''">
				audit_opinion,
			</if>
			<if test="transferStatus != null and transferStatus != ''">
				transfer_status,
			</if>
			<if test="transferTime != null and transferTime != ''">
				transfer_time,
			</if>
			<if test="createUserId != null">
				create_user_id,
			</if>
			<if test="createUserName != null and createUserName != ''">
				create_user_name,
			</if>
			<if test="updateUserName != null and updateUserName != ''">
				update_user_name,
			</if>
			<if test="updateUserId != null">
				update_user_id,
			</if>
		</trim>
		<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
			<if test="proId != null and proId != ''">
				#{proId},
			</if>
			<if test="proName != null and proName != ''">
				#{proName},
			</if>
			<if test="singleProName != null and singleProName != ''">
				#{singleProName},
			</if>
			<if test="deptId != null and deptId != ''">
				#{deptId},
			</if>
			<if test="deptName != null and deptName != ''">
				#{deptName},
			</if>
			<if test="applyUser != null and applyUser != ''">
				#{applyUser},
			</if>
			<if test="applyTime != null">
				#{applyTime},
			</if>
			<if test="auditStatus != null and auditStatus != ''">
				#{auditStatus},
			</if>
			<if test="auditOpinion != null and auditOpinion != ''">
				#{auditOpinion},
			</if>
			<if test="transferStatus != null and transferStatus != ''">
				#{transferStatus},
			</if>
			<if test="transferTime != null and transferTime != ''">
				#{transferTime},
			</if>
			<if test="createUserId != null">
				#{createUserId},
			</if>
			<if test="createUserName != null and createUserName != ''">
				#{createUserName},
			</if>
			<if test="updateUserName != null and updateUserName != ''">
				#{updateUserName},
			</if>
			<if test="updateUserId != null">
				#{updateUserId},
			</if>
		</trim>
	</insert>
	<insert id="insertTransferFile">
		INSERT INTO da_ky_transfer_file
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="id != null">
				id,
			</if>
			<if test="transferApplyId != null">
				transfer_apply_id,
			</if>
			<if test="proFilesContentsId != null and proFilesContentsId != ''">
				pro_files_contents_id,
			</if>
			<if test="proId != null and proId != ''">
				pro_id,
			</if>
			<if test="fileSourceId != null">
				file_source_id,
			</if>
			<if test="fileName != null and fileName != ''">
				file_name,
			</if>
			<if test="filePath != null and filePath != ''">
				file_path,
			</if>
			<if test="transferStatus != null and transferStatus != ''">
				transfer_status,
			</if>
			<if test="transferTime != null">
				transfer_time,
			</if>
			<if test="receiveStatus != null and receiveStatus != ''">
				receive_status,
			</if>
			<if test="receiveTime != null">
				receive_time,
			</if>
		</trim>
		<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
			<if test="id != null">
				#{id},
			</if>
			<if test="transferApplyId != null">
				#{transferApplyId},
			</if>
			<if test="proFilesContentsId != null and proFilesContentsId != ''">
				#{proFilesContentsId},
			</if>
			<if test="proId != null and proId != ''">
				#{proId},
			</if>
			<if test="fileSourceId != null">
				#{fileSourceId},
			</if>
			<if test="fileName != null and fileName != ''">
				#{fileName},
			</if>
			<if test="filePath != null and filePath != ''">
				#{filePath},
			</if>
			<if test="transferStatus != null and transferStatus != ''">
				#{transferStatus},
			</if>
			<if test="transferTime != null">
				#{transferTime},
			</if>
			<if test="receiveStatus != null and receiveStatus != ''">
				#{receiveStatus},
			</if>
			<if test="receiveTime != null">
				#{receiveTime},
			</if>
		</trim>
	</insert>
	<insert id="addTransferAuditRecord">
		INSERT INTO da_ky_transfer_audit_record
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="id != null">
				transfer_apply_id,
			</if>
			<if test="auditStatus != null and auditStatus != ''">
				audit_status,
			</if>
			<if test="auditOpinion != null and auditOpinion != ''">
				audit_option,
			</if>
			<if test="auditUser != null">
				audit_user_id,
			</if>
			<if test="auditUserName != null and auditUserName != ''">
				audit_user_name,
			</if>
		</trim>
		<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
			<if test="id != null">
				#{id},
			</if>
			<if test="auditStatus != null and auditStatus != ''">
				#{auditStatus},
			</if>
			<if test="auditOpinion != null and auditOpinion != ''">
				#{auditOpinion},
			</if>
			<if test="auditUser != null">
				#{auditUser},
			</if>
			<if test="auditUserName != null and auditUserName != ''">
				#{auditUserName},
			</if>
		</trim>
	</insert>
	<update id="edit">
		UPDATE da_ky_transfer_apply
		<set>
			<if test="proId != null and proId != ''">
				pro_id = #{proId},
			</if>
			<if test="proName != null and proName != ''">
				pro_name = #{proName},
			</if>
			<if test="singleProName != null and singleProName != ''">
				single_pro_name = #{singleProName},
			</if>
			<if test="deptId != null and deptId != ''">
				dept_id = #{deptId},
			</if>
			<if test="deptName != null and deptName != ''">
				dept_name = #{deptName},
			</if>
			<if test="applyUser != null and applyUser != ''">
				apply_user = #{applyUser},
			</if>
			<if test="applyTime != null">
				apply_time = #{applyTime},
			</if>
			<if test="auditStatus != null and auditStatus != ''">
				audit_status = #{auditStatus},
			</if>
			<if test="auditOpinion != null and auditOpinion != ''">
				audit_opinion = #{auditOpinion},
			</if>
			<if test="transferStatus != null and transferStatus != ''">
				transfer_status = #{transferStatus},
			</if>
			<if test="transferTime != null and transferTime != ''">
				transfer_time = #{transferTime},
			</if>
			<if test="updateUserName != null and updateUserName != ''">
				update_user_name = #{updateUserName},
			</if>
			<if test="updateUserId != null">
				update_user_id = #{updateUserId},
			</if>
			<if test="delFlag != null and delFlag != ''">
				del_flag = #{delFlag},
			</if>
		</set>
		WHERE id = #{id}
	</update>
	<update id="audit">
		UPDATE da_ky_transfer_apply
		<set>
			<if test="auditStatus != null and auditStatus != ''">
				audit_status = #{auditStatus},
			</if>
			<if test="auditOpinion != null and auditOpinion != ''">
				audit_opinion = #{auditOpinion},
			</if>
			<if test="auditUser != null">
				audit_user = #{auditUserName},
			</if>
			audit_time = now()
		</set>
		WHERE id = #{id}
	</update>
	<update id="updateTransferRecordFile">
		UPDATE da_ky_transfer_file
		SET file_name = #{fileName}
		WHERE file_source_id = #{id}
	</update>
	<update id="transferReceive">
		UPDATE da_ky_transfer_file
		SET receive_status = '1',
		receive_time = now()
		WHERE id = #{id}
	</update>
	<update id="updateTransferStatus">
		UPDATE da_ky_transfer_apply
		SET transfer_status = '1'
		WHERE id = #{transferApplyId}
	</update>
	<update id="updateTransferRecordFilesStatus">
		UPDATE da_ky_transfer_file
		SET transfer_status = #{transferStatus},
			transfer_time = now()
		WHERE file_source_id = #{id}
	</update>
	<update id="setTransferTime">
		UPDATE da_ky_transfer_apply
		SET transfer_time = now()
		WHERE id = #{transferApplyId}
	</update>
	<update id="updateReceiveStatus">
		UPDATE da_ky_transfer_apply
		SET receive_status = '1'
		WHERE id = #{transferApplyId}
	</update>
	<update id="updateProjectFileStatus">
		UPDATE da_ky_project
		SET file_status = '2'
		WHERE id = #{proId}
	</update>
	<delete id="delTransferFiles">
		DELETE FROM da_ky_transfer_file
		WHERE transfer_apply_id = #{id}
	</delete>
	<delete id="del">
		DELETE FROM da_ky_transfer_apply
		WHERE id = #{id}
	</delete>
	<delete id="delRecord">
		DELETE FROM da_ky_transfer_audit_record
		WHERE transfer_apply_id = #{id}
	</delete>

	<select id="list" resultType="org.springblade.system.domain.TransferApplyDto">
		SELECT
		dkta.id,
		dkta.pro_id AS proId,
		dkta.pro_name AS proName,
		dkta.single_pro_name AS singleProName,
		dkta.dept_id AS deptId,
        (SELECT
        IF(
        d.ancestors IS NULL
        OR d.ancestors = ''
        OR d.ancestors = '0',
        d.dept_name,
        CONCAT((
        SELECT
        GROUP_CONCAT( dt.dept_name SEPARATOR ' / ' )
        FROM
        blade_dept dt
        WHERE
        FIND_IN_SET( dt.id, d.ancestors )),
        ' / ',
        d.dept_name
        ))) AS deptName,
		dkta.apply_user AS applyUser,
		dkta.apply_time AS applyTime,
		dkta.audit_status AS auditStatus,
		dkta.receive_status AS receiveStatus,
		dkta.audit_opinion AS auditOpinion,
		dkta.transfer_status AS transferStatus,
		dkta.transfer_time AS transferTime,
		dkta.create_time AS createTime,
		dkta.update_time AS updateTime,
		dkta.create_user_id AS createUserId,
		dkta.create_user_name AS createUserName,
		dkta.update_user_name AS updateUserName,
		dkta.update_user_id AS updateUserId,
		dkta.del_flag AS delFlag
		FROM da_ky_transfer_apply dkta
		left join da_ky_project dkp on dkta.pro_id = dkp.id
		LEFT JOIN blade_dept d ON dkta.dept_id = d.id AND d.is_deleted = '0'
		where dkta.del_flag = '1'
		<if test="userId != null and userId != ''">
			and dkta.create_user_id = #{userId}
		</if>
		<if test="proName != null and proName != ''">
			AND INSTR(dkta.pro_name, #{proName}) > 0
		</if>
		<if test="singleProName != null and singleProName != ''">
			AND INSTR(dkta.single_pro_name, #{singleProName}) > 0
		</if>
		<if test="transferTime != null and transferTime != ''">
			and DATE(dkta.transfer_time) = #{transferTime}
		</if>
		<if test="deptIds != null">
			AND dkta.dept_id IN
			<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
				#{deptId}
			</foreach>
		</if>
		<if test="proType != null and proType != ''">
			and dkp.pro_type = #{proType}
		</if>
		<if test="voltageLevel != null and voltageLevel != ''">
			and dkp.voltage_level = #{voltageLevel}
		</if>
		<if test="auditStatus != null and auditStatus != ''">
			and dkta.audit_status = #{auditStatus}
		</if>
		ORDER BY dkta.create_time DESC
	</select>
	<select id="getTransferApply" resultType="org.springblade.system.domain.TransferApplyDto">
		WITH RECURSIVE DeptTree AS (
			SELECT
				id,
				dept_name,
				parent_id,
				dept_name AS full_path,
				0 AS level
			FROM blade_dept
			WHERE id = (SELECT dept_id FROM da_ky_transfer_apply WHERE id = #{id})

			UNION ALL

			SELECT
				d.id,
				d.dept_name,
				d.parent_id,
				CONCAT(d.dept_name, ' / ', dt.full_path) AS full_path,
				dt.level + 1
			FROM blade_dept d
					 INNER JOIN DeptTree dt ON d.id = dt.parent_id
		)
		SELECT
			dt.full_path AS deptName,
			dkta.pro_name AS proName,
			dkta.apply_user AS applyUser,
			dkta.apply_time AS applyTime,
			dkta.audit_user AS auditUser,
			dkta.audit_time AS auditTime,
			dkta.audit_opinion AS auditOpinion,
			CASE dkta.audit_status
				WHEN '0' THEN '待审批'
				WHEN '1' THEN '审批通过'
				WHEN '2' THEN '审批驳回'
				ELSE ''
				END AS auditStatus
		FROM DeptTree dt
				 CROSS JOIN da_ky_transfer_apply dkta
		WHERE dkta.del_flag = '1'
		  AND dkta.id = #{id}
		  <if test="transferStatus != null and transferStatus != ''">
			AND dkta.transfer_status = #{transferStatus}
		  </if>
		  AND dt.level = (SELECT MAX(level) FROM DeptTree)
	</select>
	<select id="getProSelect" resultType="org.springblade.system.domain.ProSelectDto">
		SELECT
			id,
			single_pro_name AS name,
			pro_name AS proName
		FROM
			da_ky_project
		WHERE
			del_flag = '1' and file_status = '1'
	</select>
	<select id="getTransferFile" resultType="org.springblade.system.domain.TransferFileDto">
		SELECT DISTINCT
			dkp.pro_name AS proName,
			dkp.id AS proId,
			dkp.single_pro_name AS singleProName,
			dktf.file_name AS fileName,
			dktf.id AS id,
			dkfs.id AS fileId,
			dkpfc.content_name AS contentName,
			concat(dkpfc3.content_name,'/',dkpfc2.content_name) AS parParentName,
			dkpfc1.content_name AS parentName,
			dktf.transfer_time AS transferTime,
			dktf.receive_status AS receiveStatus
		FROM da_ky_pro_files_contents dkpfc
				 left join da_ky_pro_files_contents dkpfc1 on dkpfc.parent_id = dkpfc1.id
				 left join da_ky_pro_files_contents dkpfc2 on dkpfc1.parent_id = dkpfc2.id
				 left join da_ky_pro_files_contents dkpfc3 on dkpfc2.parent_id = dkpfc3.id
				 LEFT JOIN da_ky_sys_file_source dkfs ON dkpfc.id = dkfs.business_id
				 LEFT JOIN da_ky_transfer_file dktf ON dkfs.id = dktf.file_source_id
				 left join da_ky_project dkp on dkp.id = dktf.pro_id
			where dktf.transfer_apply_id = #{id}
			and dkpfc3.pro_id = #{proId} and dkpfc2.pro_id = #{proId} and dkpfc1.pro_id = #{proId} and dkpfc.pro_id = #{proId}
	</select>
	<select id="getDeptSelect" resultType="org.springblade.common.core.domain.entity.SysDept">
        SELECT dept_id   AS deptId,
               parent_id AS parentId,
               ancestors,
               dept_name AS deptName,
               order_num AS orderNum,
               leader,
               phone,
               email,
               status,
               del_flag  AS delFlag
        FROM da_ky_sys_dept
        WHERE del_flag = '0'
          and status = '0'
    </select>
	<select id="getTransferApplyFilesContents" resultType="java.lang.String">
		WITH RECURSIVE sub_tree AS (
		SELECT
		id,
		pro_id,
		level
		FROM da_ky_pro_files_contents
		WHERE id = #{id}
		AND pro_id = #{proId}

		UNION ALL

		SELECT
		c.id,
		c.pro_id,
		c.level
		FROM da_ky_pro_files_contents c
		INNER JOIN sub_tree st ON c.parent_id = st.id
		WHERE c.level &lt;= 4
		AND c.pro_id = #{proId}
		)
		SELECT DISTINCT id
		FROM sub_tree
		WHERE level = 4
		ORDER BY id
	</select>
	<select id="getTransferApplyFiles" resultType="org.springblade.system.domain.DaKyProFilesContentsDto">
		SELECT distinct
			dkpfc.id AS id,
			dkpfc.pro_id AS proId,
			dkpfc.content_name AS contentName,
			dkpfc.parent_id AS parentId,
			dkpfc.LEVEL AS LEVEL,
			dkpfc.sort AS sort,
			dkpfc.mark_code AS markCode,
			dkpfc.term AS term,
			concat(dkpfc3.content_name,'/',dkpfc2.content_name) AS parParentName,
			dkpfc1.content_name AS parentName,
			dkpfc.unit_name AS unitName,
			CASE

				WHEN dkpfc.data_source = '1' THEN
					'本系统上传'
				WHEN dkpfc.data_source = '2' THEN
					'智慧现场' ELSE ''
				END AS dataSource,
			dkpfc.is_unique AS isUnique,
			dkpfc.integrity_status AS integrityStatus,
			dkfs.id AS fileId,
			dkfs.file_name AS fileName,
			dkfs.file_path AS filePath,
			dkfs.create_time AS createTime,
			dkfs.source_file_name AS sourceFileName,
			dkfs.create_user_name AS createUserName
		FROM
			da_ky_pro_files_contents dkpfc
			    left join da_ky_pro_files_contents dkpfc1 on dkpfc.parent_id = dkpfc1.id
			    left join da_ky_pro_files_contents dkpfc2 on dkpfc1.parent_id = dkpfc2.id
			    left join da_ky_pro_files_contents dkpfc3 on dkpfc2.parent_id = dkpfc3.id
				LEFT JOIN da_ky_sys_file_source dkfs ON dkpfc.id = dkfs.business_id
				LEFT JOIN da_ky_transfer_file fs ON dkfs.id = fs.file_source_id
		WHERE
			dkpfc.del_flag = '1'
		  AND dkpfc.parent_id = #{parentId}
		  AND dkpfc.pro_id = #{proId}
		  AND dkpfc.LEVEL = 5
		  AND NOT EXISTS ( SELECT 1 FROM da_ky_transfer_file tf WHERE tf.file_source_id = dkfs.id )
	</select>
	<select id="getTransferRecordFiles" resultType="org.springblade.system.domain.TransferFileDto">
		SELECT DISTINCT
			dkfs.id as fileId,
			dktf.file_name AS fileName,
			CONCAT( dkpfc3.content_name, '/', dkpfc2.content_name ) AS parParentName,
			dkpfc1.content_name AS parentName,
			dktf.transfer_status AS transferStatus,
			dktf.receive_status AS receiveStatus
		FROM
			da_ky_transfer_file dktf
			    left join da_ky_sys_file_source dkfs ON dktf.file_source_id = dkfs.id
				LEFT JOIN da_ky_pro_files_contents dkpfc ON dktf.pro_files_contents_id = dkpfc.id
				LEFT JOIN da_ky_pro_files_contents dkpfc1 ON dkpfc.parent_id = dkpfc1.id
				LEFT JOIN da_ky_pro_files_contents dkpfc2 ON dkpfc1.parent_id = dkpfc2.id
				LEFT JOIN da_ky_pro_files_contents dkpfc3 ON dkpfc2.parent_id = dkpfc3.id
		WHERE
			dktf.transfer_apply_id = #{transferApplyId} and dktf.pro_id = dkpfc3.pro_id
	</select>
	<select id="getProNameById" resultType="java.lang.String">
		SELECT
			pro_name AS proName
		FROM
			da_ky_project
		WHERE
			id = #{proId}
	</select>
	<select id="getTransferApplyFilesByApplyId" resultType="org.springblade.system.domain.DaKyProFilesContentsDto">
		SELECT distinct
			dkpfc.id AS id,
			dkpfc.pro_id AS proId,
			dkpfc.content_name AS contentName,
			dkpfc.parent_id AS parentId,
			dkpfc.LEVEL AS LEVEL,
			dkpfc.sort AS sort,
			dkpfc.mark_code AS markCode,
			dkpfc.term AS term,
			tfs.pro_name AS proName,
			tfs.single_pro_name AS singleProName,
			tfs.create_time AS createTime,
			concat(dkpfc3.content_name,'/',dkpfc2.content_name) AS parParentName,
			dkpfc1.content_name AS parentName,
			dkpfc.unit_name AS unitName,
			CASE

				WHEN dkpfc.data_source = '1' THEN
					'本系统上传'
				WHEN dkpfc.data_source = '2' THEN
					'智慧现场' ELSE ''
				END AS dataSource,
			dkpfc.is_unique AS isUnique,
			dkpfc.integrity_status AS integrityStatus,
			dkfs.id AS fileId,
			dkfs.file_name AS fileName,
			dkfs.file_path AS filePath,
			dkfs.source_file_name AS sourceFileName,
			dkfs.create_user_name AS createUserName
		FROM
			da_ky_pro_files_contents dkpfc
				left join da_ky_pro_files_contents dkpfc1 on dkpfc.parent_id = dkpfc1.id
				left join da_ky_pro_files_contents dkpfc2 on dkpfc1.parent_id = dkpfc2.id
				left join da_ky_pro_files_contents dkpfc3 on dkpfc2.parent_id = dkpfc3.id
				LEFT JOIN da_ky_sys_file_source dkfs ON dkpfc.id = dkfs.business_id
				LEFT JOIN da_ky_transfer_file fs ON dkfs.id = fs.file_source_id
				left join da_ky_transfer_apply tfs on tfs.id = fs.transfer_apply_id
		WHERE
			dkpfc.del_flag = '1' and
			fs.transfer_apply_id = #{id}
			and dkpfc3.pro_id = #{proId} and dkpfc2.pro_id = #{proId} and dkpfc1.pro_id = #{proId} and dkpfc.pro_id = #{proId}
		  AND dkpfc.LEVEL = 5
	</select>
	<select id="isAllReceive" resultType="java.lang.Integer">
		SELECT
			CASE
				WHEN
					COUNT(*) = SUM( CASE WHEN receive_status = '1' THEN 1 ELSE 0 END ) THEN
					1 ELSE 0
				END AS all_received
		FROM
			da_ky_transfer_file
		WHERE
			transfer_apply_id = #{transferApplyId}
	</select>
	<select id="getDeptList" resultType="java.lang.String">
		SELECT
			id
		FROM
            blade_dept
		WHERE
            is_deleted = '0'
		  AND (
			id = #{deptId}
		  OR FIND_IN_SET( #{deptId}, ancestors )
			)
	</select>
	<select id="getTransferApplyTransferTime" resultType="java.lang.String">
		SELECT
			transfer_time AS transferTime
		FROM
			da_ky_transfer_apply
		WHERE
			id = #{transferApplyId}
	</select>
	<select id="getAllTransferStatus" resultType="java.lang.Integer">
		SELECT
			CASE
				WHEN
					COUNT(*) = SUM( CASE WHEN transfer_status = '1' THEN 1 ELSE 0 END ) THEN
					1 ELSE 0
				END AS all_received
		FROM
			da_ky_transfer_file
		WHERE
			transfer_apply_id = #{transferApplyId}
	</select>
	<select id="isAllReceiveByProject" resultType="java.lang.Integer">
		SELECT CASE
		WHEN (
			(
			SELECT
				COUNT(*)
			FROM
				da_ky_sys_file_source dksfs
				LEFT JOIN da_ky_pro_files_contents dkpfc ON dksfs.business_id = dkpfc.id
			WHERE
				dkpfc.pro_id = #{proId}

		AND dkpfc.integrity_status = '1'
		AND dkpfc.LEVEL = 5
		) > 0
		)
		AND ( ( SELECT COUNT(*) FROM da_ky_transfer_file WHERE file_source_id IS NOT NULL AND receive_status = '1' ) > 0 )
		AND (
		(
		SELECT
		COUNT(*)
		FROM
		(
		SELECT
		dksfs.id
		FROM
		da_ky_sys_file_source dksfs
		LEFT JOIN da_ky_pro_files_contents dkpfc ON dksfs.business_id = dkpfc.id
		WHERE
		dkpfc.pro_id = #{proId}

		AND dkpfc.integrity_status = '1'
		AND dkpfc.LEVEL = 5
		) src
		WHERE
		src.id NOT IN ( SELECT file_source_id FROM da_ky_transfer_file WHERE file_source_id IS NOT NULL AND receive_status = '1' )
		) + (
		SELECT
		COUNT(*)
		FROM
		da_ky_transfer_file tf
		WHERE
		tf.file_source_id NOT IN (
		SELECT
		dksfs.id
		FROM
		da_ky_sys_file_source dksfs
		LEFT JOIN da_ky_pro_files_contents dkpfc ON dksfs.business_id = dkpfc.id
		WHERE
		dkpfc.pro_id = #{proId}

		AND dkpfc.integrity_status = '1'
		AND dkpfc.LEVEL = 5
		)
		AND tf.file_source_id IS NOT NULL
		AND tf.receive_status = '1'
		)
		) = 0 THEN
		1 ELSE 0
		END AS result
	</select>

</mapper>
