<?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.userTemplateView.dao.impl.UserTemplateViewMapperImpl">
	<resultMap id="get-entity-result" type="com.hzya.frame.sys.userTemplateView.entity.UserTemplateView">
		<!--唯一标识码 -->
		<result property="id" column="id" />
		<!--模版id -->
		<result property="templateId" column="template_id" />
		<!--用户id -->
		<result property="userId" column="user_id" />
		<!--模版字段表id -->
		<result property="templateFieldsId" column="template_fields_id" />
		<!--类型(查询 列表 新增 编辑） -->
		<result property="templateViewType" column="template_view_type" />
		<!--类型(查询 列表 新增 编辑） -->
		<result property="serviceName" column="service_name" />
		<!--排序 -->
		<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,
		template_id,
		user_id,
		template_fields_id,
		template_view_type,
		service_name,
		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_user_template_view where id = #{ id } and sts='Y'
	</select>

	<!-- 查询 采用==查询 -->
	<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.userTemplateView.entity.UserTemplateView">
		select
		<include refid="Base_Column_List" />
		from sys_user_template_view
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="templateId != null and templateId !='' "> and template_id = #{templateId}</if>
			<if test="userId != null and userId !='' "> and user_id = #{userId}</if>
			<if test="templateFieldsId != null and templateFieldsId !='' "> and template_fields_id = #{templateFieldsId}</if>
			<if test="templateViewType != null and templateViewType !='' "> and template_view_type = #{templateViewType}</if>
			<if test="serviceName != null and serviceName !='' "> and service_name = #{serviceName}</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>
		<if test=" 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.userTemplateView.entity.UserTemplateView">
		select count(1) from sys_user_template_view
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="templateId != null and templateId !='' "> and template_id = #{templateId}</if>
			<if test="userId != null and userId !='' "> and user_id = #{userId}</if>
			<if test="templateFieldsId != null and templateFieldsId !='' "> and template_fields_id = #{templateFieldsId}</if>
			<if test="templateViewType != null and templateViewType !='' "> and template_view_type = #{templateViewType}</if>
			<if test="serviceName != null and serviceName !='' "> and service_name = #{serviceName}</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.userTemplateView.entity.UserTemplateView">
		select
		<include refid="Base_Column_List" />
		from sys_user_template_view
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' "> id like concat('%',#{id},'%') </if>
			<if test="templateId != null and templateId !='' "> and template_id like concat('%',#{templateId},'%') </if>
			<if test="userId != null and userId !='' "> and user_id like concat('%',#{userId},'%') </if>
			<if test="templateFieldsId != null and templateFieldsId !='' "> and template_fields_id like concat('%',#{templateFieldsId},'%') </if>
			<if test="templateViewType != null and templateViewType !='' "> and template_view_type like concat('%',#{templateViewType},'%') </if>
			<if test="serviceName != null and serviceName !='' "> and service_name like concat('%',#{serviceName},'%') </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 =='' "> 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.userTemplateView.entity.UserTemplateView">
		select
		<include refid="Base_Column_List" />
		from sys_user_template_view
		<trim prefix="where" prefixOverrides="or">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="templateId != null and templateId !='' "> or template_id = #{templateId} </if>
			<if test="userId != null and userId !='' "> or user_id = #{userId} </if>
			<if test="templateFieldsId != null and templateFieldsId !='' "> or template_fields_id = #{templateFieldsId} </if>
			<if test="templateViewType != null and templateViewType !='' "> or template_view_type = #{templateViewType} </if>
			<if test="serviceName != null and serviceName !='' "> or service_name = #{serviceName} </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 =='' "> 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.userTemplateView.entity.UserTemplateView">
		insert into sys_user_template_view(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id, </if>
			<if test="templateId != null and templateId !='' "> template_id, </if>
			<if test="userId != null and userId !='' "> user_id, </if>
			<if test="templateFieldsId != null and templateFieldsId !='' "> template_fields_id, </if>
			<if test="templateViewType != null and templateViewType !='' "> template_view_type, </if>
			<if test="serviceName != null and serviceName !='' "> service_name, </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="templateId != null and templateId !='' "> #{templateId}, </if>
			<if test="userId != null and userId !='' "> #{userId}, </if>
			<if test="templateFieldsId != null and templateFieldsId !='' "> #{templateFieldsId}, </if>
			<if test="templateViewType != null and templateViewType !='' "> #{templateViewType}, </if>
			<if test="serviceName != null and serviceName !='' "> #{serviceName}, </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.userTemplateView.entity.UserTemplateView">
		update sys_user_template_view set
		<trim suffix="" suffixOverrides=",">
				<if test="templateId != null and templateId !='' "> template_id = #{templateId},</if>
				<if test="userId != null and userId !='' "> user_id = #{userId},</if>
				<if test="templateFieldsId != null and templateFieldsId !='' "> template_fields_id = #{templateFieldsId},</if>
				<if test="templateViewType != null and templateViewType !='' "> template_view_type = #{templateViewType},</if>
				<if test="serviceName != null and serviceName !='' "> service_name = #{serviceName},</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.userTemplateView.entity.UserTemplateView">
		update sys_user_template_view 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.userTemplateView.entity.UserTemplateView">
		update sys_user_template_view 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="templateId != null and templateId !='' "> and template_id = #{templateId}</if>
			<if test="userId != null and userId !='' "> and user_id = #{userId}</if>
			<if test="templateFieldsId != null and templateFieldsId !='' "> and template_fields_id = #{templateFieldsId}</if>
			<if test="templateViewType != null and templateViewType !='' "> and template_view_type = #{templateViewType}</if>
			<if test="serviceName != null and serviceName !='' "> and service_name = #{serviceName}</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.userTemplateView.entity.UserTemplateView">
		delete from sys_user_template_view where id =#{id}
	</delete>
</mapper>
