<?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="cn.cslg.report.mapper.AvoidDesignLittleDirectionMapper">
    <!--批量插入回避设计方向表数据-->
    <!--int insertBatch(List<AvoidDesignLittleDirection> avoidDesignLittleDirections);-->
    <insert id="insertBatch" useGeneratedKeys="true" keyProperty="id">
        insert into AVOIDDESIGN_LITTLE_DIRECTION (REPORT_ID, FEATURE_ID, LITTLE_DIRECTION)
        VALUES
        <foreach collection="list" item="n" separator=",">
            (#{n.reportId}, #{n.featureId}, #{n.littleDirection})
        </foreach>
    </insert>

    <!--根据报告id删除回避设计方向表数据-->
    <!--int deleteByReportId(Integer reportId);-->
    <delete id="deleteByReportId">
        delete
        from AVOIDDESIGN_LITTLE_DIRECTION
        where REPORT_ID = #{reportId}
    </delete>

    <!--根据报告id查询专利号(查报告表)-->
    <!--String selectSignPatentNoByReportId(Integer reportId);-->
    <select id="selectSignPatentNoByReportId" resultType="String">
        select SIGN_PATENT_NO
        from REPORT
        where ID = #{reportId}
    </select>

    <!--根据报告id关联特征表查询特征和回避设计方向数据-->
    <!--List<AvoidFeaturesVO> selectWholeByReportId(Integer reportId);-->
    <select id="selectWholeByReportId" resultMap="AllResultMap">
        select f.ID,
               SIGN_PATENT_NO,
               CONTENT_OUT,
               RIGHT_ID,
               PARTNER_ID,
               IS_FINAL,
               f.REPORT_ID,
               CONTENT,
               EXPLAIN_TEXT,
               SPLIT_BY,
               RIGHT_NAME,
               RIGHT_TYPE,
               FEATURES_ORDER,
               SPLIT_TYPE,
               TASK_ID,
               LITTLE_DIRECTION
        from FEATURES f
                 left join AVOIDDESIGN_LITTLE_DIRECTION l on f.ID = l.FEATURE_ID
        where f.REPORT_ID = #{reportId}
        order by f.ID
    </select>

    <!--根据权要id和报告id关联查询特征和回避设计方向数据-->
    <!--List<AvoidFeaturesVO> selectWholeByRightIdAndReportId(Integer rightId, Integer reportId);-->
    <select id="selectWholeByRightIdAndReportId" resultMap="AllResultMap">
        select f.ID,
               SIGN_PATENT_NO,
               CONTENT_OUT,
               RIGHT_ID,
               PARTNER_ID,
               IS_FINAL,
               f.REPORT_ID,
               CONTENT,
               EXPLAIN_TEXT,
               SPLIT_BY,
               RIGHT_NAME,
               RIGHT_TYPE,
               FEATURES_ORDER,
               SPLIT_TYPE,
               TASK_ID,
               LITTLE_DIRECTION
        from FEATURES f
                 left join AVOIDDESIGN_LITTLE_DIRECTION l on f.ID = l.FEATURE_ID
        where RIGHT_ID = #{rightId}
          and f.REPORT_ID = #{reportId}
        order by f.ID
    </select>

    <resultMap id="AllResultMap" type="cn.cslg.report.common.model.vo.AvoidFeaturesVO">
        <id column="ID" property="id"/>
        <result column="SIGN_PATENT_NO" property="signPatentNo"/>
        <result column="CONTENT_OUT" property="contentOut"/>
        <result column="RIGHT_ID" property="rightId"/>
        <result column="PARTNER_ID" property="partnerId"/>
        <result column="IS_FINAL" property="isFinal"/>
        <result column="REPORT_ID" property="reportId"/>
        <result column="CONTENT" property="content"/>
        <result column="EXPLAIN_TEXT" property="explainText"/>
        <result column="SPLIT_BY" property="splitBy"/>
        <result column="RIGHT_NAME" property="rightName"/>
        <result column="RIGHT_TYPE" property="rightType"/>
        <result column="FEATURES_ORDER" property="featuresOrder"/>
        <result column="SPLIT_TYPE" property="splitType"/>
        <result column="TASK_ID" property="taskId"/>
        <result column="LITTLE_DIRECTION" property="littleDirection"/>
        <result column="WHOLE_DIRECTION" property="wholeDirection"/>
    </resultMap>

</mapper>
