<?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.IntFzzDiscountMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="org.springblade.audit.entity.IntFzzDiscount">
        <result column="THEMONTH" property="themonth" />
        <result column="ACCEPT_TIME" property="acceptTime" />
        <result column="DIAL_PHONENUM" property="dialPhonenum" />
        <result column="ACCEPT_PHONENUM" property="acceptPhonenum" />
        <result column="COMPANY" property="company" />
        <result column="SERVICE_STYLE" property="serviceStyle" />
        <result column="SERVICE_TYPE" property="serviceType" />
        <result column="SPCODE" property="spcode" />
        <result column="SPNAME" property="spname" />
        <result column="SPID" property="spid" />
        <result column="PROVINCE" property="province" />
        <result column="REFUND_TYPE" property="refundType" />
        <result column="CHARGE_PHONE" property="chargePhone" />
        <result column="APPLY_MONEY" property="applyMoney" />
        <result column="ACCEPT_WAY" property="acceptWay" />
        <result column="SERVICE_NO" property="serviceNo" />
        <result column="COMPLAINT_TYPE" property="complaintType" />
        <result column="REFUND_REASON" property="refundReason" />
        <result column="DESCRIBE" property="describe" />
        <result column="HANDLE_RESULT" property="handleResult" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        THEMONTH, ACCEPT_TIME, DIAL_PHONENUM, ACCEPT_PHONENUM, COMPANY, SERVICE_STYLE, SERVICE_TYPE, SPCODE, SPNAME, SPID, PROVINCE, REFUND_TYPE, CHARGE_PHONE, APPLY_MONEY, ACCEPT_WAY, SERVICE_NO, COMPLAINT_TYPE, REFUND_REASON, DESCRIBE, HANDLE_RESULT
    </sql>

    <update id="giveTheMonthSoul">
        UPDATE INT_400_DISCOUNT
        SET THEMONTH = to_char ( accept_time, 'yyyymm' )
        WHERE
        themonth IS NULL
    </update>

    <update id="editSpCode">
        UPDATE INT_400_DISCOUNT
        SET spcode = substr( SERVICE_STYLE, instr( SERVICE_STYLE, '(' )+ 1, 5 )
        WHERE
            instr( SERVICE_STYLE, '(' )> 0
        AND THEMONTH = #{theMonth}
        AND spcode IS NULL
    </update>

    <update id="giveSpidSoul">
        UPDATE INT_400_DISCOUNT 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 INT_400_DISCOUNT a
        SET spid = ( SELECT max( spid ) FROM DIM_CS_KC_SPNAME b WHERE a.spname = b.CS_SPNAME )
        WHERE
        themonth = #{theMonth}
        AND spid IS NULL
    </update>

    <update id="settingFileTag">
        UPDATE INT_IMPORT_FLAG
        SET FLAG_400 = 1
        WHERE
        themonth = #{theMonth}
    </update>

    <delete id="removeEmptyData">
        DELETE
        FROM
            INT_400_DISCOUNT
        WHERE
            accept_time IS NULL
        AND themonth = #{theMonth}
    </delete>

</mapper>
