<?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.jeeplus.test.reimbursementAccountant.mapper.AccountantReimbursementBusinessTwoMapper">
    <sql id="zsReimbursementBusinessAccountantInfoColumns">
        a.id as 'id',
        a.create_by as 'createBy',
        a.create_date as 'createDate',
        a.update_by as 'updateBy',
        a.update_date as 'updateDate',
        a.remarks as 'remarks',
        a.del_flag as 'delFlag',
        a.business_code_id as 'businessCodeId',
        a.user_id as 'userId',
        a.year as 'year',
        a.reimbursement_day as 'reimbursementDay',
        a.reimbursement_amount as 'reimbursementAmount',
        a.reimbursement_type as 'reimbursementType'
    </sql>
    <sql id="joinZsReimbursementBusinessAccountantInfoColumns">
        a.id as 'id',
        a.create_by as 'createBy',
        a.create_date as 'createDate',
        a.update_by as 'updateBy',
        a.update_date as 'updateDate',
        a.remarks as 'remarks',
        a.del_flag as 'delFlag',
        a.business_code_id as 'businessCodeId',
        a.user_id as 'userId',
        a.year as 'year',
        a.reimbursement_day as 'reimbursementDay',
        a.reimbursement_amount as 'reimbursementAmount',
        a.reimbursement_type as 'reimbursementType',
        su.name as 'userName'
    </sql>
    <sql id="reimbursementUserJoinColumns">
        left join sys_user su on su.id = a.user_id
    </sql>
    <insert id="insertAccountantReimbursementBusiness">
        insert into zs_reimbursement_business_accountant_info
        (
                    id,
            create_by,
            create_date,
            update_by,
            update_date,
            remarks,
            del_flag,
            business_code_id,
            user_id,
            year,
            <if test="reimbursementDay != null and reimbursementDay != ''">
                reimbursement_day,
            </if>
            reimbursement_amount,
            reimbursement_type
        )
        values
        (
                    #{id},
            #{createBy},
            #{createDate},
            #{updateBy},
            #{updateDate},
            #{remarks},
            #{delFlag},
            #{businessCodeId},
            #{userId},
            #{year},
            <if test="reimbursementDay != null and reimbursementDay != ''">
                #{reimbursementDay},
            </if>
            #{reimbursementAmount},
            #{reimbursementType}
        )
    </insert>

    <select id="findListPage"
            resultType="com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementBusinessTwoDTO">
        select
        <include refid="joinZsReimbursementBusinessAccountantInfoColumns"/>
        from zs_reimbursement_business_accountant_info a
        <include refid="reimbursementUserJoinColumns"/>
        <where>
            a.del_flag = 0 and (a.business_code_id='' or a.business_code_id=null)
            <if test="accountantReimbursementBusiness.year != null and accountantReimbursementBusiness.year != ''">
                and a.year like concat('%',#{accountantReimbursementBusiness.year},'%')
            </if>
            <if test="accountantReimbursementBusiness.userId != null and accountantReimbursementBusiness.userId != ''">
                and a.user_id = #{accountantReimbursementBusiness.userId}
            </if>
        </where>
        order by a.update_date desc,a.year desc, a.user_id asc
    </select>
    <select id="findSelectList"
            resultType="com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementDTO">

        select id,business_code as businessCode from zs_reimbursement_accountant_info where business_code is not null and business_code != '' group by business_code
    </select>
    <select id="findSelectYearList" resultType="java.lang.String">
        SELECT year FROM `zs_reimbursement_accountant_info` GROUP BY `year` order by `year` desc
    </select>
    <select id="findSelectCodeListByYear"
            resultType="com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementDTO">
        select id,business_code as businessCode
        from zs_reimbursement_accountant_info
        where year = #{year} and business_code is not null and business_code != '' and reimbursement_ratio is not null and reimbursement_ratio !=''
        group by business_code
    </select>
    <select id="findDataById"
            resultType="com.jeeplus.test.reimbursementAccountant.domain.dto.AccountantReimbursementBusinessTwoDTO">
        select
        <include refid="zsReimbursementBusinessAccountantInfoColumns"/>
        from zs_reimbursement_business_accountant_info a
        where id=#{id}
    </select>


    <update id="delPhysicsById">
        update zs_reimbursement_business_accountant_info
        set del_flag = 1
        where id = #{id}
    </update>
    <update id="modifyBindCode">
        update zs_reimbursement_business_accountant_info
        set
                business_code_id=#{businessCode}
        where id=#{ids}
    </update>


</mapper>