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

    <resultMap id="BaseResultMap" type="com.nantian.cloud.dbcapp.entity.ConfigureDataCollectEnable">
        <id column="id" property="id" />
        <result column="enterpriseCode" property="enterpriseCode" />
        <result column="dataCode" property="dataCode" />
        <result column="dataCodeOld" property="dataCodeOld" />
        <result column="collectItemName" property="collectItemName" />
        <result column="startTime" property="startTime" />
        <result column="endTime" property="endTime" />
        <result column="remark" property="remark" />
        <result column="creatTime" property="creatTime" />
        <result column="updateTime" property="updateTime" />
        <result column="delFlag" property="delFlag" />
        <result column="creatUserId" property="creatUserId" />
        <result column="updateUserId" property="updateUserId" />
    </resultMap>

    <select id="getEnableList" resultType="com.nantian.cloud.dbcapp.entity.ConfigureDataCollectEnable">
        SELECT
        id,enterpriseCode,dataCode,dataCodeOld,collectItemName collectItemNameOld,startTime,endTime,remark,creatTime,updateTime,delFlag,isEnable,creatUserId,updateUserId,
        IFNULL((select collectItemName from configure_data_collect where enterpriseCode = t.enterpriseCode and dataCode = t.dataCode),t.collectItemName) collectItemName
        FROM configure_data_collect_enable t
        <trim prefix="where" prefixOverrides="and">
            <if test="enterpriseCode!=null">
                and enterpriseCode = #{enterpriseCode} and delFlag = "1"
            </if>
            <if test="dataCode!=null and dataCode != '' ">
                and dataCode = #{dataCode}
            </if>
        </trim>
    </select>

    <delete id="removeconfigureDataCollectEnableById">
        update configure_data_collect_enable
        <set>
            <if test="delFlag != null">
                delFlag = #{delFlag},
            </if>
        </set>
        where id = #{id}
    </delete>


    <select id="getEnableTimeListByEnterpriseCode" resultType="com.nantian.cloud.dbcapp.entity.ConfigureDataCollectEnable">
        select dataCode,startTime,endTime from configure_data_collect_enable t
        where t.delFlag = '1'
          and t.enterpriseCode = #{enterpriseCode}
          and t.isEnable = '1'
    </select>

</mapper>