<?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.api.manage.dao.chargeManagement.SysChargesTemplateDao">
    <select id="list" resultType="com.api.vo.chargeManagement.VoChargesTemplate">
        select * from sys_charges_template
    </select>

    <insert id="insert" parameterType="com.api.model.chargeManagement.ChargesTemplate">
        insert into sys_charges_template(
            name,
            status,
            create_id,
            create_date
        ) values (
            #{name},
            #{status},
            #{createId},
            #{createDate}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <delete id="delete" parameterType="java.lang.Integer">
        delete from sys_charges_template where id = #{id}
    </delete>

    <select id="findById" resultType="com.api.vo.chargeManagement.VoChargesTemplate">
        select * from sys_charges_template where id = #{id}
    </select>

    <update id="update" parameterType="com.api.model.chargeManagement.ChargesTemplate">
        update sys_charges_template
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            modify_id = #{modifyId},
            modify_date = #{modifyDate}
        </set>
        where id = #{id}
    </update>

    <update id="disableAll">
        update sys_charges_template set status = 0
    </update>

    <update id="enable" parameterType="java.lang.Integer">
        update sys_charges_template set status = 1 where id =#{id}
    </update>

    <update id="disable" parameterType="java.lang.Integer">
        update sys_charges_template set status = 0 where id =#{id}
    </update>

    <select id="findStatusById" parameterType="java.lang.Integer" resultType="java.lang.Integer">
        select status from sys_charges_template where id = #{id}
    </select>

    <select id="findChargesTemplateFromNow" resultType="com.api.vo.chargeManagement.VoFindByIdChargesTemplateDetail">
        select * from sys_charges_template_detail where charges_template_id = (select id from sys_charges_template order by create_date DESC limit 1)
    </select>

</mapper>