<?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="cn.com.countrygarden.bi.main.dao.ck.CkCleanerExternaldisplayMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="listDataMap" type="cn.com.countrygarden.bi.main.model.ck.CkCleanerExternaldisplay">
        <id column="id" property="id"/>
        <result column="field_code" property="fieldCode"/>
        <result column="field_name" property="fieldName"/>
        <result column="parent_id" property="parentId"/>
        <result column="comm_name" property="commName"/>
        <result column="path" property="path"/>
        <result column="type" property="type"/>
        <result column="field_length" property="fieldLength"/>
        <result column="show_width" property="showWidth"/>
        <result column="query_flag" property="queryFlag"/>
        <result column="required_flag" property="requiredFlag"/>
        <result column="inherit_flag" property="inheritFlag"/>
        <result column="status" property="status"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="value_type" property="valueType"/>
        <result column="soft" property="soft"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="CleanerFieldCof" resultType="cn.com.countrygarden.bi.main.dto.ck.CkCleanerFieldConfigVo">
        SELECT DISTINCT ce.field_code AS fieldCode,cfk.field_name AS fieldName,ce.value AS `value`,ce.basic_id AS basicId
        FROM ck_ksh_expand ce
        LEFT JOIN ck_cleaner_field_config cfk ON cfk.field_code=ce.field_code
        LEFT JOIN ck_ksh_basic cb ON ce.basic_id=cb.id
        WHERE ce.status=1 AND cb.status=1
        <if test="fieldCodeString!=null and fieldCodeString.size()!=0">
            and ce.field_code in
            <foreach collection="fieldCodeString" item="fieldCodeString"
                     index="index" open="(" close=")" separator=",">
                #{fieldCodeString}
            </foreach>
        </if>
        <if test="ckCleanerBasicdto.commId!=null and ckCleanerBasicdto.commId.size()!=0">
            and cb.comm_code in
            <foreach collection="ckCleanerBasicdto.commId" item="commId"
                     index="index" open="(" close=")" separator=",">
                #{commId}
            </foreach>
        </if>
        <if test="commId!=null and commId!=''">
            and cb.comm_code=#{commId}
        </if>
        <if test="ckCleanerBasicdto.year!=null">
            and cb.year=#{ckCleanerBasicdto.year}
        </if>
        <if test="ckCleanerBasicdto.month!=null">
            and cb.month=#{ckCleanerBasicdto.month}
        </if>
        <if test="ckCleanerBasicdto.basicId!=null">
            and ce.basic_id=#{ckCleanerBasicdto.basicId}
        </if>
    </select>

    <select id="CleanerFieldCof2" resultType="cn.com.countrygarden.bi.main.dto.ck.CkCleanerFieldConfigVo">
        SELECT DISTINCT ce.field_code AS fieldCode,cfk.field_name AS fieldName,ce.value AS `value`,ce.basic_id AS basicId
        FROM ck_ksh_expand ce
        LEFT JOIN ck_cleaner_field_config cfk ON cfk.field_code=ce.field_code
        LEFT JOIN ck_ksh_basic cb ON ce.basic_id=cb.id
        WHERE ce.status=1 AND cb.status=1
        AND FIND_IN_SET(ce.`field_code`,(
        SELECT REPLACE(REPLACE(REPLACE(REPLACE(JSON_EXTRACT(data_config,'$[*].fieldCode'),'[',''),']',''),'"',''),' ','') FROM ck_cleaner_externaldisplay cce WHERE cce.`basic_id`=ce.basic_id LIMIT 1
        ))!=0
        <if test="ckCleanerBasicdto.commId!=null and ckCleanerBasicdto.commId.size()!=0">
            and cb.comm_code in
            <foreach collection="ckCleanerBasicdto.commId" item="commId"
                     index="index" open="(" close=")" separator=",">
                #{commId}
            </foreach>
        </if>
        <if test="commId!=null and commId!=''">
            and cb.comm_code=#{commId}
        </if>
        <if test="ckCleanerBasicdto.year!=null">
            and cb.year=#{ckCleanerBasicdto.year}
        </if>
        <if test="ckCleanerBasicdto.month!=null">
            and cb.month=#{ckCleanerBasicdto.month}
        </if>
        <if test="ckCleanerBasicdto.basicId!=null">
            and ce.basic_id=#{ckCleanerBasicdto.basicId}
        </if>
    </select>

    <select id="ckList" resultType="cn.com.countrygarden.bi.main.model.ck.ksh.CkKshBasic">
        SELECT DISTINCT id AS id,org_code AS orgCode,org_name AS orgName,comm_code AS commCode,comm_name AS commName,`month` AS `month`,`year` AS `year`
        FROM ck_ksh_basic
        WHERE `status`=1 AND `year`=#{ckCleanerBasicdto.year} and `month`=#{ckCleanerBasicdto.month}
        <if test="ckCleanerBasicdto.commId!=null and ckCleanerBasicdto.commId.size()!=0">
            and comm_code in
            <foreach collection="ckCleanerBasicdto.commId" item="commId"
                     index="index" open="(" close=")" separator=",">
                #{commId}
            </foreach>
        </if>
    </select>

    <select id="cleanerBasicList" resultType="cn.com.countrygarden.bi.main.dto.ck.CkCleanerTableVo">
        SELECT DISTINCT ccb.id as id,ccb.org_code as orgCode,ccb.org_name as orgName,ccb.comm_code as commCode,ccb.comm_name as commName,
        ccb.month as `month`,ccb.year as `year`
        FROM ck_ksh_basic ccb
        LEFT JOIN ck_ksh_expand cce ON cce.basic_id=ccb.id
        WHERE ccb.status=1 AND cce.status=1
        <if test="ckCleanerBasicdto.commId!=null and ckCleanerBasicdto.commId.size()!=0">
            and ccb.comm_code in
            <foreach collection="ckCleanerBasicdto.commId" item="commId"
                     index="index" open="(" close=")" separator=",">
                #{commId}
            </foreach>
        </if>
        <if test="ckCleanerBasicdto.year!=null">
            and ccb.year=#{ckCleanerBasicdto.year}
        </if>
        <if test="ckCleanerBasicdto.month!=null">
            and ccb.month=#{ckCleanerBasicdto.month}
        </if>
    </select>
    <select id="selectAllSort" resultType="cn.com.countrygarden.bi.main.model.ck.CkCleanerExternaldisplay">
        SELECT id AS id,basic_id as basicId,data_config as dataConfig,field_code AS fieldCode,field_name AS fieldName,parent_id AS parentId,`type` AS `type`,soft AS soft
        FROM ck_cleaner_externaldisplay
        where basic_id=#{basicId}
    </select>

</mapper>