<?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.storlead.sales.mapper.target.TargetQuotaMapper">

        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.storlead.sales.pojo.entity.target.TargetQuotaEntity">
                    <id column="id" property="id" />
                <result column="create_time" property="createTime" />
                <result column="update_time" property="updateTime" />
                <result column="is_delete" property="isDelete" />
                <result column="enabled" property="enabled" />
                <result column="create_by" property="createBy" />
                <result column="owner_by" property="ownerBy" />
                <result column="update_by" property="updateBy" />
                <result column="sort" property="sort" />
                    <result column="target_plan_id" property="targetPlanId" />
                    <result column="organizational_type" property="organizationalType" />
                    <result column="organizational_id" property="organizationalId" />
                    <result column="sub_scope_id" property="subScopeId" />
                    <result column="sub_scope_name" property="subScopeName" />
                    <result column="parent_id" property="parentId" />
                    <result column="month_or_quarter1" property="monthOrQuarter1" />
                    <result column="month_or_quarter2" property="monthOrQuarter2" />
                    <result column="month_or_quarter3" property="monthOrQuarter3" />
                    <result column="month_or_quarter4" property="monthOrQuarter4" />
                    <result column="month_or_quarter5" property="monthOrQuarter5" />
                    <result column="month_or_quarter6" property="monthOrQuarter6" />
                    <result column="month_or_quarter7" property="monthOrQuarter7" />
                    <result column="month_or_quarter8" property="monthOrQuarter8" />
                    <result column="month_or_quarter9" property="monthOrQuarter9" />
                    <result column="month_or_quarter10" property="monthOrQuarter10" />
                    <result column="month_or_quarter11" property="monthOrQuarter11" />
                    <result column="month_or_quarter12" property="monthOrQuarter12" />
                    <result column="total" property="total" />
                    <result column="former_owner_by" property="formerOwnerBy" />
        </resultMap>

        <!-- 通用查询结果列 -->
        <sql id="Base_Column_List">
                create_time,
                update_time,
                is_delete,
                enabled,
                create_by,
                owner_by,
                update_by,
                sort,
            id, target_plan, organizational_type, organizational_id, sub_scope_id, sub_scope_name, parent_id, month_or_quarter1, month_or_quarter2, month_or_quarter3, month_or_quarter4, month_or_quarter5, month_or_quarter6, month_or_quarter7, month_or_quarter8, month_or_quarter9, month_or_quarter10, month_or_quarter11, month_or_quarter12, total, former_owner_by
        </sql>
    <update id="updateQuarterById">
        UPDATE target_quota tq
            JOIN (
            SELECT

            sum(month_or_quarter1) as month_or_quarter1,
            sum(month_or_quarter2) as month_or_quarter2,
            sum(month_or_quarter3) as month_or_quarter3,
            sum(month_or_quarter4) as month_or_quarter4,
            sum(month_or_quarter5) as month_or_quarter5,
            sum(month_or_quarter6) as month_or_quarter6,
            sum(month_or_quarter7) as month_or_quarter7,
            sum(month_or_quarter8) as month_or_quarter8,
            sum(month_or_quarter9) as month_or_quarter9,
            sum(month_or_quarter10) as month_or_quarter10,
            sum(month_or_quarter11) as month_or_quarter11,
            sum(month_or_quarter12) as month_or_quarter12,
            sum(total) as total
            FROM target_quota
            WHERE  parent_id = #{id}
            and is_delete = 0
            ) as tqs

        set tq.month_or_quarter1 = tqs.month_or_quarter1,
            tq.month_or_quarter2 = tqs.month_or_quarter2,
            tq.month_or_quarter3 = tqs.month_or_quarter3,
            tq.month_or_quarter4 = tqs.month_or_quarter4,
            tq.month_or_quarter5 = tqs.month_or_quarter5,
            tq.month_or_quarter6 = tqs.month_or_quarter6,
            tq.month_or_quarter7 = tqs.month_or_quarter7,
            tq.month_or_quarter8 = tqs.month_or_quarter8,
            tq.month_or_quarter9 = tqs.month_or_quarter9,
            tq.month_or_quarter10 = tqs.month_or_quarter10,
            tq.month_or_quarter11 = tqs.month_or_quarter11,
            tq.month_or_quarter12 = tqs.month_or_quarter12,
            tq.total = tqs.total

        WHERE tq.id = #{id}



    </update>

</mapper>
