<?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.dayou.mapper.MajorTargetMapper">

    <update id="updateSubReportNo" parameterType="com.dayou.vo.IdNameVO">
        <foreach collection="list" index="index" item="item" separator=";">
            update major_target set report_no = #{item.name},statement_no= #{exist} where id = #{item.id} and deleted = 0
        </foreach>
    </update>

    <update id="updateSubStatementNo" parameterType="com.dayou.vo.IdNameVO">
        <foreach collection="list" index="index" item="item" separator=";">
            update major_target set statement_no = #{item.name} where id = #{item.id} and deleted = 0
        </foreach>
    </update>

    <update id="updateSubLetterNo" parameterType="com.dayou.vo.IdNameVO">
        <foreach collection="list" index="index" item="item" separator=";">
            update major_target set letter_no = #{item.name} where id = #{item.id} and deleted = 0
        </foreach>
    </update>

    <update id="updateMainLetterNo">
        update major_target set letter_no = #{mainNumber} where major_id = #{businessId}
        <if test="statementNo!=null and statementNo!=''">
            and statement_no = #{statementNo}
        </if>
        and deleted = 0;
    </update>

    <update id="updateMainReportNo">
        update major_target set report_no = #{mainNumber} where major_id = #{businessId}
        <if test="statementNo!=null and statementNo!=''">
            and statement_no = #{statementNo}
        </if>
        and deleted = 0;
    </update>

    <update id="updateMainStatementNo">
        update major_target set statement_no = #{mainNumber} where major_id = #{businessId} and deleted = 0;
    </update>

    <update id="cleanSubReportNoByBusinessId">
        update major_target set report_no = null where major_id = #{businessId} and deleted = 0;
    </update>

    <update id="xCleanSubReportNo">
        update major_target set report_no = null where major_id = #{businessId} and report_no = #{businessSubId} and deleted = 0;
    </update>

    <select id="getSubReportNo" parameterType="java.lang.Long" resultType="com.dayou.entity.MajorTarget">
        select statement_no,report_no , letter_no from major_target where major_id = #{businessId} and deleted = 0
    </select>

    <update id="cleanSubStatementNo" parameterType="java.util.Set">
        update  major_target set statement_no = null where statement_no in (
            <foreach collection="set" item="item" index="index" separator=",">
                #{item}
            </foreach>
            )
    </update>

    <update id="cleanSubReportNo" parameterType="java.util.Set">
        update  major_target set report_no = null where report_no in (
        <foreach collection="set" item="item" index="index" separator=",">
            #{item}
        </foreach>
        )
    </update>

    <update id="cleanSubLetterNo" parameterType="java.util.Set">
        update  major_target set letter_no = null where letter_no in (
        <foreach collection="set" item="item" index="index" separator=",">
            #{item}
        </foreach>
        )
    </update>

    <select id="getList" parameterType="com.dayou.entity.MajorTarget" resultType="com.dayou.entity.MajorTarget">
        select * from major_target where deleted = 0 and major_id = #{vo.majorId}
        <if test="vo!=null and vo.statementNo!=null and vo.statementNo!=''">
            and statement_no = #{vo.statementNo}
        </if>
        <if test="vo!=null and vo.reportNo!=null and vo.reportNo!=''">
            and report_no = #{vo.reportNo}
        </if>
        <if test="vo!=null and vo.letterNo!=null and vo.letterNo!=''">
            and letter_no = #{vo.letterNo}
        </if>
        or (
        major_id = #{vo.majorId} and statement_no is null and report_no is null and letter_no is null
        )
    </select>

    <select id="getEvaluateAmountByTargetId" parameterType="java.util.List" resultType="java.math.BigDecimal">
        select sum(evaluate_value) from major_target where evaluate_value is not null and deleted = 0 and id in (
            <foreach collection="targetIds" item="item" separator="," index="index">
                #{item}
            </foreach>
            )
    </select>
</mapper>
