<?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.sob.dao.impl.SobDaoImpl">
	<resultMap id="get-SobEntity-result" type="com.hzya.frame.sys.sob.entity.SobEntity">
		<!--主键ID -->
		<result property="id" column="id" />
		<!--账套编号 -->
		<result property="code" column="code" />
		<!--账套名称 -->
		<result property="name" column="name" />
		<!--年度 -->
		<result property="year" column="year" />
		<!--账套号 -->
		<result property="sob_no" column="sob_no" />
		<!--APIID -->
		<result property="api_id" column="api_id" />
		<!--排序 -->
		<result property="sorts" column="sorts" />
		<!--创建人id -->
		<result property="create_user_id" column="create_user_id" />
		<!--创建时间 -->
		<result property="create_time" column="create_time" />
		<!--修改人id -->
		<result property="modify_user_id" column="modify_user_id" />
		<!--修改时间 -->
		<result property="modify_time" column="modify_time" />
		<!--状态(Y正常N删除) -->
		<result property="sts" column="sts" />
		<!--组织机构ID -->
		<result property="org_id" column="org_id" />
	</resultMap>

	<sql id="SobEntity_Base_Column_List">
		id,
		code,
		name,
		year,
		sob_no,
		api_id,
		sorts,
		create_user_id,
		create_time,
		modify_user_id,
		modify_time,
		sts,
		org_id
	</sql>

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

	<!-- 查询 采用==查询 -->
	<select id="entity_list_base" resultMap="get-SobEntity-result" parameterType="com.hzya.frame.sys.sob.entity.SobEntity">
		select
		<include refid="SobEntity_Base_Column_List" />
		from sys_sob
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="code != null and code !='' "> and code = #{code}</if>
			<if test="name != null and name !='' "> and name = #{name}</if>
			<if test="year != null and year !='' "> and year = #{year}</if>
			<if test="sob_no != null and sob_no !='' "> and sob_no = #{sob_no}</if>
			<if test="api_id != null and api_id !='' "> and api_id = #{api_id}</if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id}</if>
			<if test="create_time != null "> and create_time = #{create_time}</if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id}</if>
			<if test="modify_time != null "> and modify_time = #{modify_time}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
			<if test="org_id != null and org_id !='' "> and org_id = #{org_id}</if>
			and sts='Y'
		</trim>
		<if test=" sort == null or sort == ''.toString() "> 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.sob.entity.SobEntity">
		select count(1) from sys_sob
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="code != null and code !='' "> and code = #{code} </if>
			<if test="name != null and name !='' "> and name = #{name} </if>
			<if test="year != null and year !='' "> and year = #{year} </if>
			<if test="sob_no != null and sob_no !='' "> and sob_no = #{sob_no} </if>
			<if test="api_id != null and api_id !='' "> and api_id = #{api_id} </if>
			<if test="sorts != null "> and sorts = #{sorts}  </if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id} </if>
			<if test="create_time != null "> and create_time = #{create_time}  </if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id} </if>
			<if test="modify_time != null "> and modify_time = #{modify_time}  </if>
			<if test="sts != null and sts !='' "> and sts = #{sts} </if>
			<if test="org_id != null and org_id !='' "> and org_id = #{org_id} </if>
			and sts='Y'
		</trim>
		<if test=" sort ==''.toString() "> order by sorts asc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null "> order by ${sort} ${order}</if>
	</select>

	<!-- 分页查询列表 采用like格式 -->
	<select id="entity_list_like" resultMap="get-SobEntity-result" parameterType="com.hzya.frame.sys.sob.entity.SobEntity">
		select
		<include refid="SobEntity_Base_Column_List" />
		from sys_sob
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' "> id like concat('%',#{id},'%') </if>
			<if test="code != null and code !='' "> and code like concat('%',#{code},'%') </if>
			<if test="name != null and name !='' "> and name like concat('%',#{name},'%') </if>
			<if test="year != null and year !='' "> and year like concat('%',#{year},'%') </if>
			<if test="sob_no != null and sob_no !='' "> and sob_no like concat('%',#{sob_no},'%') </if>
			<if test="api_id != null and api_id !='' "> and api_id like concat('%',#{api_id},'%') </if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id like concat('%',#{create_user_id},'%') </if>
			<if test="create_time != null and create_time !='' "> and create_time like concat('%',#{create_time},'%') </if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id like concat('%',#{modify_user_id},'%') </if>
			<if test="modify_time != null and modify_time !='' "> and modify_time like concat('%',#{modify_time},'%') </if>
			<if test="sts != null and sts !='' "> and sts like concat('%',#{sts},'%') </if>
			<if test="org_id != null and org_id !='' "> and org_id like concat('%',#{org_id},'%') </if>
			and sts='Y'
		</trim>
		<if test=" sort ==''.toString() "> 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-SobEntity-result" parameterType="com.hzya.frame.sys.sob.entity.SobEntity">
		select
		<include refid="SobEntity_Base_Column_List" />
		from sys_sob
		<trim prefix="where" prefixOverrides="or">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="code != null and code !='' "> or code = #{code} </if>
			<if test="name != null and name !='' "> or name = #{name} </if>
			<if test="year != null and year !='' "> or year = #{year} </if>
			<if test="sob_no != null and sob_no !='' "> or sob_no = #{sob_no} </if>
			<if test="api_id != null and api_id !='' "> or api_id = #{api_id} </if>
			<if test="sorts != null "> or sorts = #{sorts}</if>
			<if test="create_user_id != null and create_user_id !='' "> or create_user_id = #{create_user_id} </if>
			<if test="create_time != null and create_time !='' "> or create_time = #{create_time} </if>
			<if test="modify_user_id != null and modify_user_id !='' "> or modify_user_id = #{modify_user_id} </if>
			<if test="modify_time != null and modify_time !='' "> or modify_time = #{modify_time} </if>
			<if test="sts != null and sts !='' "> or sts = #{sts} </if>
			<if test="org_id != null and org_id !='' "> or org_id = #{org_id} </if>
			and sts='Y'
		</trim>
		<if test=" sort ==''.toString() "> 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.sob.entity.SobEntity">
		insert into sys_sob(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id, </if>
			<if test="code != null and code !='' "> code, </if>
			<if test="name != null and name !='' "> name, </if>
			<if test="year != null and year !='' "> year, </if>
			<if test="sob_no != null and sob_no !='' "> sob_no, </if>
			<if test="api_id != null and api_id !='' "> api_id, </if>
			<if test="sorts != null ">sorts,</if>
			<if test="create_user_id != null and create_user_id !='' "> create_user_id, </if>
			<if test="modify_user_id != null and modify_user_id !='' "> modify_user_id, </if>
			<if test="org_id != null and org_id !='' "> org_id, </if>
			create_time,
			modify_time,
			sts
		</trim>
		)values
		(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> #{id}, </if>
			<if test="code != null and code !='' "> #{code}, </if>
			<if test="name != null and name !='' "> #{name}, </if>
			<if test="year != null and year !='' "> #{year}, </if>
			<if test="sob_no != null and sob_no !='' "> #{sob_no}, </if>
			<if test="api_id != null and api_id !='' "> #{api_id}, </if>
			<if test="sorts != null ">#{sorts},</if>
			<if test="create_user_id != null and create_user_id !='' "> #{create_user_id}, </if>
			<if test="modify_user_id != null and modify_user_id !='' "> #{modify_user_id}, </if>
			<if test="org_id != null and org_id !='' "> #{org_id}, </if>
			<if test="create_time != null "> #{create_time} ,</if>
			<if test="modify_time != null "> #{modify_time},</if>
			'Y'
		</trim>
		)
	</insert>

	<!-- 修改 -->
	<update id="entity_update" parameterType="com.hzya.frame.sys.sob.entity.SobEntity">
		update sys_sob set
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id = #{id},</if>
			<if test="code != null and code !='' "> code = #{code},</if>
			<if test="name != null and name !='' "> name = #{name},</if>
			<if test="year != null and year !='' "> year = #{year},</if>
			<if test="sob_no != null and sob_no !='' "> sob_no = #{sob_no},</if>
			<if test="api_id != null and api_id !='' "> api_id = #{api_id},</if>
			<if test="sorts != null ">sorts = #{sorts},</if>
			<if test="create_user_id != null and create_user_id !='' "> create_user_id = #{create_user_id},</if>
			<if test="modify_user_id != null and modify_user_id !='' "> modify_user_id = #{modify_user_id},</if>
			<if test="org_id != null and org_id !='' "> org_id = #{org_id},</if>
			<if test="modify_time != null "> modify_time =#{modify_time}  </if>
			<if test="modify_time  == null "> modify_time = now()</if>
		</trim>
		where id = #{id}
	</update>

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

	<!-- 逻辑删除多条件 -->
	<update id="entity_logicDelete_Multi_Condition" parameterType="com.hzya.frame.sys.sob.entity.SobEntity">
		update sys_sob set
		sts='N',modify_time = now(),modify_user_id = #{modify_user_id} 
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="code != null and code !='' "> and code = #{code}</if>
			<if test="name != null and name !='' "> and name = #{name}</if>
			<if test="year != null and year !='' "> and year = #{year}</if>
			<if test="sob_no != null and sob_no !='' "> and sob_no = #{sob_no}</if>
			<if test="api_id != null and api_id !='' "> and api_id = #{api_id}</if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id}</if>
			<if test="create_time != null and create_time !='' "> and create_time = #{create_time}</if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id}</if>
			<if test="modify_time != null and modify_time !='' "> and modify_time = #{modify_time}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
			<if test="org_id != null and org_id !='' "> and org_id = #{org_id}</if>
		</trim>
	</update>

	<!-- 物理删除 -->
	<delete id="entity_delete" parameterType="com.hzya.frame.sys.sob.entity.SobEntity">
		delete from sys_sob where id =#{id}
	</delete>
</mapper>
