<?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.finance.projectReport.mapper.CwProofreadDetailMapper">
	<select id="findByInfoId" resultType="com.jeeplus.finance.projectReport.domain.CwProofreadDetail">
        SELECT
			a.id,
			a.create_by_id,
			a.create_time,
			a.update_by_id,
			a.update_time,
			a.del_flag,
			a.info_id,
			a.type_id,
			b.`name` AS type_name,
			ifnull(a.review_comments,"") as "reviewComments",
			ifnull(a.reply_comments,"") as "replyComments",
			b.sort
		FROM cw_proofread_type b
		LEFT JOIN cw_proofread_detail a ON a.type_id = b.id
		AND a.del_flag = 0
		AND a.info_id = #{id}
		ORDER BY b.sort
    </select>
	<select id="findList" resultType="com.jeeplus.finance.projectReport.domain.CwProofreadDetail">
		SELECT
			id AS type_id,
			create_by_id,
			create_time,
			update_by_id,
			update_time,
			del_flag,
			parent_id,
			parent_ids,
			`level`,
			`name` AS type_name,
			sort
		FROM
			cw_proofread_type
		WHERE
			del_flag = 0
			AND `type` = #{type}
		ORDER BY sort
	</select>
	<select id="findByReportInfoId" resultType="com.jeeplus.finance.projectReport.domain.CwProofreadDetail">
		select a.*,b.`name` AS type_name,b.sort from cw_proofread_detail a
		left join cw_proofread_type b on a.type_id = b.id
		where info_id = #{id}
		ORDER BY b.sort asc
	</select>
	<select id="getByTypeIdAndInfoId" resultType="com.jeeplus.finance.projectReport.domain.CwProofreadDetail">
		select * from cw_proofread_detail where type_id = #{typeId} and info_id = #{infoId}
	</select>

	<update id="updateReportReviewInfoById">
		UPDATE cw_proofread_detail
		SET
		<if test="infoId != null and infoId != ''">
			info_id = #{infoId},
		</if>
		<if test="typeId != null and typeId != ''">
			type_id = #{typeId},
		</if>
		<if test="reviewComments != null and reviewComments != ''">
			review_comments = #{reviewComments},
		</if>
		<if test="tenantId != null and tenantId != ''">
			tenant_id = #{tenantId},
		</if>
		update_by_id = #{updateById},
		update_time = #{updateTime}
		WHERE
			id = #{id}
			AND del_flag = 0
	</update>
</mapper>
