<?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.hzya.frame.sys.viewFiled.dao.impl.ViewFiledMapperImpl">
    <resultMap id="get-entity-result" type="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
        <!--主键ID -->
        <result property="id" column="id"/>
        <!--表缓存表id -->
        <result property="tableCacheId" column="table_cache_id"/>
        <!--服务名 -->
        <result property="serverName" column="server_name"/>
        <!--显示名称 -->
        <result property="viewName" column="view_name"/>
        <!--显示字段 -->
        <result property="viewFiled" column="view_filed"/>
        <!--数据库字段名称 -->
        <result property="datebaseName" column="datebase_name"/>
        <!--前端字段类型 -->
        <result property="tag" column="tag"/>
        <!--数据类型 -->
        <result property="valueType" column="value_type"/>
        <!--展示类型 1、显示 2、不显示 -->
        <result property="showType" column="show_type"/>
        <!--查询类型 1、查询 2、不查询 -->
        <result property="queryType" column="query_type"/>
        <!--新增展示类型 1、显示 2、不显示 -->
        <result property="addShowType" column="add_show_type"/>
        <!--新增是否必填类型 1、必填 2、不必填 -->
        <result property="addRequiredType" column="add_required_type"/>
        <!--修改展示类型 1、显示 2、不显示 -->
        <result property="updateShowType" column="update_show_type"/>
        <!--修改是否必填类型 1、必填 2、不必填 -->
        <result property="updateRequiredType" column="update_required_type"/>
        <!--排序 -->
        <result property="sorts" column="sorts"/>
        <!--创建人id -->
        <result property="createUserId" column="create_user_id"/>
        <!--创建时间 -->
        <result property="createTime" column="create_time"/>
        <!--修改人id -->
        <result property="modifyUserId" column="modify_user_id"/>
        <!--修改时间 -->
        <result property="modifyTime" column="modify_time"/>
        <!--状态(Y正常N删除) -->
        <result property="sts" column="sts"/>
        <!--组织机构ID -->
        <result property="orgId" column="org_id"/>
    </resultMap>

    <sql id="Base_Column_List">
		id,
		table_cache_id,
		server_name,
		view_name,
		view_filed,
		datebase_name,
		tag,
		value_type,
		show_type,
		query_type,
		add_show_type,
		add_required_type,
		update_show_type,
		update_required_type,
		sorts,
		create_user_id,
		create_time,
		modify_user_id,
		modify_time,
		sts,
		org_id
	</sql>

    <!--通过ID获取数据 -->
    <select id="entity_get" resultMap="get-entity-result">
        select
        <include refid="Base_Column_List"/>
        from sys_view_filed where id = #{ id } and sts='Y'
    </select>

    <!-- 查询 采用==查询 -->
    <select id="entity_list_base" resultMap="get-entity-result"
            parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
        select
        <include refid="Base_Column_List"/>
        from sys_view_filed
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id !='' ">id = #{id}</if>
            <if test="tableCacheId != null and tableCacheId !='' ">and table_cache_id = #{tableCacheId}</if>
            <if test="serverName != null and serverName !='' ">and server_name = #{serverName}</if>
            <if test="viewName != null and viewName !='' ">and view_name = #{viewName}</if>
            <if test="viewFiled != null and viewFiled !='' ">and view_filed = #{viewFiled}</if>
            <if test="datebaseName != null and datebaseName !='' ">and datebase_name = #{datebaseName}</if>
            <if test="tag != null and tag !='' ">and tag = #{tag}</if>
            <if test="valueType != null and valueType !='' ">and value_type = #{valueType}</if>
            <if test="showType != null and showType !='' ">and show_type = #{showType}</if>
            <if test="queryType != null and queryType !='' ">and query_type = #{queryType}</if>
            <if test="addShowType != null and addShowType !='' ">and add_show_type = #{addShowType}</if>
            <if test="addRequiredType != null and addRequiredType !='' ">and add_required_type = #{addRequiredType}</if>
            <if test="updateShowType != null and updateShowType !='' ">and update_show_type = #{updateShowType}</if>
            <if test="updateRequiredType != null and updateRequiredType !='' ">and update_required_type =
                #{updateRequiredType}
            </if>
            <if test="sorts != null ">and sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId !='' ">and create_user_id = #{createUserId}</if>
            <if test="createTime != null ">and create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId !='' ">and modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null ">and modify_time = #{modifyTime}</if>
            <if test="sts != null and sts !='' ">and sts = #{sts}</if>
            <if test="orgId != null and orgId !='' ">and org_id = #{orgId}</if>
            <if test="userViewFileds != null and userViewFileds.size>0">
                AND id in
                <foreach collection="userViewFileds" item="item" index="index" open="(" close=")" separator=",">
                    #{item.viewFiledId}
                </foreach>
            </if>
        </trim>
        <if test=" sort == null or sort =='' ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 查询符合条件的数量 -->
    <select id="entity_count" resultType="Integer" parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
        select count(1) from sys_view_filed
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id !='' ">id = #{id}</if>
            <if test="tableCacheId != null and tableCacheId !='' ">and table_cache_id = #{tableCacheId}</if>
            <if test="serverName != null and serverName !='' ">and server_name = #{serverName}</if>
            <if test="viewName != null and viewName !='' ">and view_name = #{viewName}</if>
            <if test="viewFiled != null and viewFiled !='' ">and view_filed = #{viewFiled}</if>
            <if test="datebaseName != null and datebaseName !='' ">and datebase_name = #{datebaseName}</if>
            <if test="tag != null and tag !='' ">and tag = #{tag}</if>
            <if test="valueType != null and valueType !='' ">and value_type = #{valueType}</if>
            <if test="showType != null and showType !='' ">and show_type = #{showType}</if>
            <if test="queryType != null and queryType !='' ">and query_type = #{queryType}</if>
            <if test="addShowType != null and addShowType !='' ">and add_show_type = #{addShowType}</if>
            <if test="addRequiredType != null and addRequiredType !='' ">and add_required_type = #{addRequiredType}</if>
            <if test="updateShowType != null and updateShowType !='' ">and update_show_type = #{updateShowType}</if>
            <if test="updateRequiredType != null and updateRequiredType !='' ">and update_required_type =
                #{updateRequiredType}
            </if>
            <if test="sorts != null ">and sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId !='' ">and create_user_id = #{createUserId}</if>
            <if test="createTime != null ">and create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId !='' ">and modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null ">and modify_time = #{modifyTime}</if>
            <if test="sts != null and sts !='' ">and sts = #{sts}</if>
            <if test="orgId != null and orgId !='' ">and org_id = #{orgId}</if>
        </trim>
    </select>

    <!-- 分页查询列表 采用like格式 -->
    <select id="entity_list_like" resultMap="get-entity-result"
            parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
        select
        <include refid="Base_Column_List"/>
        from sys_view_filed
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id !='' ">id like concat('%',#{id},'%')</if>
            <if test="tableCacheId != null and tableCacheId !='' ">and table_cache_id like
                concat('%',#{tableCacheId},'%')
            </if>
            <if test="serverName != null and serverName !='' ">and server_name like concat('%',#{serverName},'%')</if>
            <if test="viewName != null and viewName !='' ">and view_name like concat('%',#{viewName},'%')</if>
            <if test="viewFiled != null and viewFiled !='' ">and view_filed like concat('%',#{viewFiled},'%')</if>
            <if test="datebaseName != null and datebaseName !='' ">and datebase_name like
                concat('%',#{datebaseName},'%')
            </if>
            <if test="tag != null and tag !='' ">and tag like concat('%',#{tag},'%')</if>
            <if test="valueType != null and valueType !='' ">and value_type like concat('%',#{valueType},'%')</if>
            <if test="showType != null and showType !='' ">and show_type like concat('%',#{showType},'%')</if>
            <if test="queryType != null and queryType !='' ">and query_type like concat('%',#{queryType},'%')</if>
            <if test="addShowType != null and addShowType !='' ">and add_show_type like concat('%',#{addShowType},'%')
            </if>
            <if test="addRequiredType != null and addRequiredType !='' ">and add_required_type like
                concat('%',#{addRequiredType},'%')
            </if>
            <if test="updateShowType != null and updateShowType !='' ">and update_show_type like
                concat('%',#{updateShowType},'%')
            </if>
            <if test="updateRequiredType != null and updateRequiredType !='' ">and update_required_type like
                concat('%',#{updateRequiredType},'%')
            </if>
            <if test="sorts != null ">and sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId !='' ">and create_user_id like
                concat('%',#{createUserId},'%')
            </if>
            <if test="createTime != null and createTime !='' ">and create_time like concat('%',#{createTime},'%')</if>
            <if test="modifyUserId != null and modifyUserId !='' ">and modify_user_id like
                concat('%',#{modifyUserId},'%')
            </if>
            <if test="modifyTime != null and modifyTime !='' ">and modify_time like concat('%',#{modifyTime},'%')</if>
            <if test="sts != null and sts !='' ">and sts like concat('%',#{sts},'%')</if>
            <if test="orgId != null and orgId !='' ">and org_id like concat('%',#{orgId},'%')</if>
        </trim>
        <if test=" sort == null or sort =='' ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>

    <!-- 查询列表 字段采用or格式 -->
    <select id="entity_list_or" resultMap="get-entity-result"
            parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
        select
        <include refid="Base_Column_List"/>
        from sys_view_filed
        <trim prefix="where" prefixOverrides="or">
            <if test="id != null and id !='' ">id = #{id}</if>
            <if test="tableCacheId != null and tableCacheId !='' ">or table_cache_id = #{tableCacheId}</if>
            <if test="serverName != null and serverName !='' ">or server_name = #{serverName}</if>
            <if test="viewName != null and viewName !='' ">or view_name = #{viewName}</if>
            <if test="viewFiled != null and viewFiled !='' ">or view_filed = #{viewFiled}</if>
            <if test="datebaseName != null and datebaseName !='' ">or datebase_name = #{datebaseName}</if>
            <if test="tag != null and tag !='' ">or tag = #{tag}</if>
            <if test="valueType != null and valueType !='' ">or value_type = #{valueType}</if>
            <if test="showType != null and showType !='' ">or show_type = #{showType}</if>
            <if test="queryType != null and queryType !='' ">or query_type = #{queryType}</if>
            <if test="addShowType != null and addShowType !='' ">or add_show_type = #{addShowType}</if>
            <if test="addRequiredType != null and addRequiredType !='' ">or add_required_type = #{addRequiredType}</if>
            <if test="updateShowType != null and updateShowType !='' ">or update_show_type = #{updateShowType}</if>
            <if test="updateRequiredType != null and updateRequiredType !='' ">or update_required_type =
                #{updateRequiredType}
            </if>
            <if test="sorts != null ">or sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId !='' ">or create_user_id = #{createUserId}</if>
            <if test="createTime != null and createTime !='' ">or create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId !='' ">or modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null and modifyTime !='' ">or modify_time = #{modifyTime}</if>
            <if test="sts != null and sts !='' ">or sts = #{sts}</if>
            <if test="orgId != null and orgId !='' ">or org_id = #{orgId}</if>
        </trim>
        <if test=" sort == null or sort =='' ">order by sorts asc</if>
        <if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
    </select>
    <!-- 新增 -->
    <insert id="entity_insert" parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
        insert into sys_view_filed(
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id !='' ">id,</if>
            <if test="tableCacheId != null and tableCacheId !='' ">table_cache_id,</if>
            <if test="serverName != null and serverName !='' ">server_name,</if>
            <if test="viewName != null and viewName !='' ">view_name,</if>
            <if test="viewFiled != null and viewFiled !='' ">view_filed,</if>
            <if test="datebaseName != null and datebaseName !='' ">datebase_name,</if>
            <if test="tag != null and tag !='' ">tag,</if>
            <if test="valueType != null and valueType !='' ">value_type,</if>
            <if test="showType != null and showType !='' ">show_type,</if>
            <if test="queryType != null and queryType !='' ">query_type,</if>
            <if test="addShowType != null and addShowType !='' ">add_show_type,</if>
            <if test="addRequiredType != null and addRequiredType !='' ">add_required_type,</if>
            <if test="updateShowType != null and updateShowType !='' ">update_show_type,</if>
            <if test="updateRequiredType != null and updateRequiredType !='' ">update_required_type,</if>
            <if test="sorts != null ">sorts,</if>
            <if test="createUserId != null and createUserId !='' ">create_user_id,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="modifyUserId != null and modifyUserId !='' ">modify_user_id,</if>
            <if test="modifyTime != null ">modify_time,</if>
            <if test="sts != null and sts !='' ">sts,</if>
            <if test="orgId != null and orgId !='' ">org_id,</if>
        </trim>
        )values
        (
        <trim suffix="" suffixOverrides=",">
            <if test="id != null and id !='' ">#{id},</if>
            <if test="tableCacheId != null and tableCacheId !='' ">#{tableCacheId},</if>
            <if test="serverName != null and serverName !='' ">#{serverName},</if>
            <if test="viewName != null and viewName !='' ">#{viewName},</if>
            <if test="viewFiled != null and viewFiled !='' ">#{viewFiled},</if>
            <if test="datebaseName != null and datebaseName !='' ">#{datebaseName},</if>
            <if test="tag != null and tag !='' ">#{tag},</if>
            <if test="valueType != null and valueType !='' ">#{valueType},</if>
            <if test="showType != null and showType !='' ">#{showType},</if>
            <if test="queryType != null and queryType !='' ">#{queryType},</if>
            <if test="addShowType != null and addShowType !='' ">#{addShowType},</if>
            <if test="addRequiredType != null and addRequiredType !='' ">#{addRequiredType},</if>
            <if test="updateShowType != null and updateShowType !='' ">#{updateShowType},</if>
            <if test="updateRequiredType != null and updateRequiredType !='' ">#{updateRequiredType},</if>
            <if test="sorts != null ">#{sorts},</if>
            <if test="createUserId != null and createUserId !='' ">#{createUserId},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="modifyUserId != null and modifyUserId !='' ">#{modifyUserId},</if>
            <if test="modifyTime != null ">#{modifyTime},</if>
            <if test="sts != null and sts !='' ">#{sts},</if>
            <if test="orgId != null and orgId !='' ">#{orgId},</if>
        </trim>
        )
    </insert>

    <!-- 修改 -->
    <update id="entity_update" parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
        update sys_view_filed set
        <trim suffix="" suffixOverrides=",">
            <if test="tableCacheId != null and tableCacheId !='' ">table_cache_id = #{tableCacheId},</if>
            <if test="serverName != null and serverName !='' ">server_name = #{serverName},</if>
            <if test="viewName != null and viewName !='' ">view_name = #{viewName},</if>
            <if test="viewFiled != null and viewFiled !='' ">view_filed = #{viewFiled},</if>
            <if test="datebaseName != null and datebaseName !='' ">datebase_name = #{datebaseName},</if>
            <if test="tag != null and tag !='' ">tag = #{tag},</if>
            <if test="valueType != null and valueType !='' ">value_type = #{valueType},</if>
            <if test="showType != null and showType !='' ">show_type = #{showType},</if>
            <if test="queryType != null and queryType !='' ">query_type = #{queryType},</if>
            <if test="addShowType != null and addShowType !='' ">add_show_type = #{addShowType},</if>
            <if test="addRequiredType != null and addRequiredType !='' ">add_required_type = #{addRequiredType},</if>
            <if test="updateShowType != null and updateShowType !='' ">update_show_type = #{updateShowType},</if>
            <if test="updateRequiredType != null and updateRequiredType !='' ">update_required_type =
                #{updateRequiredType},
            </if>
            <if test="sorts != null ">sorts = #{sorts},</if>
            <if test="createUserId != null and createUserId !='' ">create_user_id = #{createUserId},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="modifyUserId != null and modifyUserId !='' ">modify_user_id = #{modifyUserId},</if>
            <if test="modifyTime != null ">modify_time = #{modifyTime},</if>
            <if test="sts != null and sts !='' ">sts = #{sts},</if>
            <if test="orgId != null and orgId !='' ">org_id = #{orgId},</if>
        </trim>
        where id = #{id}
    </update>

    <!-- 逻辑删除 -->
    <update id="entity_logicDelete" parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
		update sys_view_filed set
		sts='N',modify_time = now(),modify_user_id = #{modifyUserId} where
		id = #{id}
	</update>

    <!-- 逻辑删除多条件 -->
    <update id="entity_logicDelete_Multi_Condition" parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
        update sys_view_filed set
        sts='N',modify_time = now(),modify_user_id = #{modifyUserId}
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id !='' ">id = #{id}</if>
            <if test="tableCacheId != null and tableCacheId !='' ">and table_cache_id = #{tableCacheId}</if>
            <if test="serverName != null and serverName !='' ">and server_name = #{serverName}</if>
            <if test="viewName != null and viewName !='' ">and view_name = #{viewName}</if>
            <if test="viewFiled != null and viewFiled !='' ">and view_filed = #{viewFiled}</if>
            <if test="datebaseName != null and datebaseName !='' ">and datebase_name = #{datebaseName}</if>
            <if test="tag != null and tag !='' ">and tag = #{tag}</if>
            <if test="valueType != null and valueType !='' ">and value_type = #{valueType}</if>
            <if test="showType != null and showType !='' ">and show_type = #{showType}</if>
            <if test="queryType != null and queryType !='' ">and query_type = #{queryType}</if>
            <if test="addShowType != null and addShowType !='' ">and add_show_type = #{addShowType}</if>
            <if test="addRequiredType != null and addRequiredType !='' ">and add_required_type = #{addRequiredType}</if>
            <if test="updateShowType != null and updateShowType !='' ">and update_show_type = #{updateShowType}</if>
            <if test="updateRequiredType != null and updateRequiredType !='' ">and update_required_type =
                #{updateRequiredType}
            </if>
            <if test="sorts != null ">and sorts = #{sorts}</if>
            <if test="createUserId != null and createUserId !='' ">and create_user_id = #{createUserId}</if>
            <if test="createTime != null and createTime !='' ">and create_time = #{createTime}</if>
            <if test="modifyUserId != null and modifyUserId !='' ">and modify_user_id = #{modifyUserId}</if>
            <if test="modifyTime != null and modifyTime !='' ">and modify_time = #{modifyTime}</if>
            <if test="sts != null and sts !='' ">and sts = #{sts}</if>
            <if test="orgId != null and orgId !='' ">and org_id = #{orgId}</if>
        </trim>
    </update>

    <!-- 物理删除 -->
    <delete id="entity_delete" parameterType="com.hzya.frame.sys.viewFiled.entity.ViewFiled">
		delete from sys_view_filed where id =#{id}
	</delete>

    <sql id="Base_Column_user_filed_List">
		a.id,
		a.table_cache_id,
		a.server_name,
		a.view_name,
		a.view_filed,
		a.datebase_name,
		a.tag,
		a.value_type,
		a.show_type,
		a.query_type,
		a.add_show_type,
		a.add_required_type,
		a.update_show_type,
		a.update_required_type,
		a.sorts,
		a.create_user_id,
		a.create_time,
		a.modify_user_id,
		a.modify_time,
		a.sts,
		a.org_id
	</sql>
    <!-- 查询 采用==查询 -->
    <select id="query_table_cache" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.tableCache.entity.TableCache">

SELECT

 	#{id} as table_cache_id, -- '表缓存表id',
	#{tableService} as  server_name, -- '服务名',
  	COLUMN_COMMENT as view_name, -- '显示名称',
 	COLUMN_NAME as view_filed, -- '显示字段',
 	COLUMN_NAME as datebase_name, -- '数据库字段名称',
         CASE
        DATA_TYPE
        WHEN 'varchar' THEN 'elInput'
        WHEN 'char' THEN 'elInput'
        WHEN 'bigint' THEN 'elInput'
        WHEN 'datetime' THEN 'elDatePicker'
        ELSE ''
        END tag, -- '前端字段类型',
				         CASE
        DATA_TYPE
        WHEN 'varchar' THEN 'string'
        WHEN 'char' THEN 'string'
        WHEN 'bigint' THEN 'int'
        WHEN 'datetime' THEN 'date'
        ELSE ''
        END value_type -- '数据类型',





FROM
    INFORMATION_SCHEMA.COLUMNS
WHERE
     TABLE_NAME = #{tableName}
		and TABLE_SCHEMA = 'businesscenter'




	</select>
</mapper>
