<?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.nantian.cloud.dbcapp.mapper.record.SettlementDataConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.dbcapp.entity.SettlementDataConfig">
        <result column="id" property="id" />
        <result column="enterprise_code" property="enterpriseCode" />
        <result column="enterprise_name" property="enterpriseName" />
        <result column="formul_name" property="formulName" />
        <result column="product_name" property="productName" />
        <result column="product_data_code" property="productDataCode" />
        <result column="month" property="month" />
        <result column="start_date" property="startDate" />
        <result column="end_date" property="endDate" />
        <result column="is_month" property="isMonth" />
        <result column="use_start_date" property="useStartDate" />
        <result column="use_end_date" property="useEndDate" />
        <result column="custom_start_date" property="customStartDate" />
        <result column="custom_end_date" property="customEndDate" />
        <result column="is_user" property="isUser" />
        <result column="created_by" property="createdBy" />
        <result column="created_time" property="createdTime" />
        <result column="updated_by" property="updatedBy" />
        <result column="updated_time" property="updatedTime" />
        <result column="remark" property="remark" />
        <result column="is_user_str" property="isUserStr" />
        <result column="is_month_str" property="isMonthStr" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, enterprise_code, enterprise_name, formul_name, product_name,
        product_data_code, `month`, start_date, end_date,
        case is_month when '0' then '否' else '是' end is_month_str,is_month, use_start_date, use_end_date,
        case is_user when '0' then '否' else '是' end is_user_str,is_user, created_by, created_time, updated_by, updated_time, remark,
        custom_start_date,custom_end_date
    </sql>



    <!--分页查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from settlement_data_config
        <where>
            <if test="query.enterpriseCode != null and query.enterpriseCode != ''">
                and enterprise_code = #{query.enterpriseCode}
            </if>
            <if test="query.enterpriseName != null and query.enterpriseName != ''">
                and enterprise_name = #{query.enterpriseName}
            </if>
            <if test="query.formulName != null and query.formulName != ''">
                and formul_name = #{query.formulName}
            </if>
            <if test="query.isUser != null and query.isUser != ''">
                and is_user = #{query.isUser}
            </if>
        </where>
    </select>

    <select id="getSettleMonthByEnterpriseCode" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"/>
        from settlement_data_config t
        where  enterprise_code = #{enterpriseCode}
        and #{time} BETWEEN t.use_start_date and t.use_end_date
    </select>

</mapper>
