<?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.audit.mapper.CwBalanceDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="cwBalanceDetailResultMap" type="org.springblade.audit.entity.CwBalanceDetail">
        <result column="THEMONTH" property="themonth"/>
        <result column="PROVINCE" property="province"/>
        <result column="SPNAME" property="spname"/>
        <result column="SPID" property="spid"/>
        <result column="FEE1" property="fee1"/>
        <result column="DISCOUNT1" property="discount1"/>
        <result column="FEE2" property="fee2"/>
        <result column="ARREARAGE" property="arrearage"/>
        <result column="DISCOUNT20" property="discount20"/>
        <result column="MONEY1" property="money1"/>
        <result column="IMBALANCE" property="imbalance"/>
        <result column="MONEY2" property="money2"/>
        <result column="MONEY3" property="money3"/>
        <result column="MONEY4" property="money4"/>
        <result column="FEE3" property="fee3"/>
        <result column="SPCODE" property="spcode"/>
    </resultMap>



    <update id="giveSpidSoul">
        UPDATE CW_BALANCE_DETAIL a SET spid =( SELECT max( spid ) FROM dim_product_category b WHERE a.spname = b.spname )
        WHERE
        spid IS NULL
        AND themonth = #{theMonth}
    </update>

    <update id="giveSpidSoulTwo">
        UPDATE CW_BALANCE_DETAIL a
        SET spid = ( SELECT max( spid ) FROM DIM_CS_PRM_SPNAME b WHERE a.spname = b.PRM_SPNAME )
        WHERE
        themonth = #{theMonth}
        AND spid IS NULL
    </update>


</mapper>
