<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.ApprovalConfigDAO">
	<resultMap id="ApprovalConfigMap" type="com.jpsoft.shinestar.modules.base.entity.ApprovalConfig">
		<id property="id" column="id_" />
			<result property="companyId" column="company_id" />
			<result property="type" column="type_" />
			<result property="level" column="level_" />
			<result property="days" column="days_" />
			<result property="delFlag" column="del_flag" />
			<result property="createBy" column="create_by" />
			<result property="createTime" column="create_time" />
			<result property="updateBy" column="update_by" />
			<result property="updateTime" column="update_time" />
			<result property="remark" column="remark_" />
			<result property="companyName" column="company_name" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.ApprovalConfig">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_approval_config
	    (id_,company_id,type_,level_,days_,del_flag,create_by,create_time,update_by,update_time,remark_)
		values
		(
#{id,jdbcType=VARCHAR}
,#{companyId,jdbcType=VARCHAR}
,#{type,jdbcType=VARCHAR}
,#{level,jdbcType=VARCHAR}
,#{days,jdbcType=VARCHAR}
,#{delFlag,jdbcType= NUMERIC }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{remark,jdbcType=VARCHAR}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_approval_config where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.ApprovalConfig">
		update base_approval_config
		<set>
				<if test="companyId!=null">
		company_id=#{companyId,jdbcType=VARCHAR},
		</if>
				<if test="type!=null">
		type_=#{type,jdbcType=VARCHAR},
		</if>
				<if test="level!=null">
		level_=#{level,jdbcType=VARCHAR},
		</if>
				<if test="days!=null">
		days_=#{days,jdbcType=VARCHAR},
		</if>
				<if test="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
				<if test="createBy!=null">
		create_by=#{createBy,jdbcType=VARCHAR},
		</if>
				<if test="createTime!=null">
		create_time=#{createTime,jdbcType= TIMESTAMP },
		</if>
				<if test="updateBy!=null">
		update_by=#{updateBy,jdbcType=VARCHAR},
		</if>
				<if test="updateTime!=null">
		update_time=#{updateTime,jdbcType= TIMESTAMP },
		</if>
				<if test="remark!=null">
		remark_=#{remark,jdbcType=VARCHAR},
		</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="ApprovalConfigMap">
		select * from base_approval_config where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_approval_config where id_=#{0}
	</select>
	<select id="list" resultMap="ApprovalConfigMap">
		select * from base_approval_config
	</select>
	<select id="search" parameterType="hashmap" resultMap="ApprovalConfigMap">
		<![CDATA[
			select
			a.*,b.name_ as company_name
			from
			base_approval_config a left join base_company_info b on a.company_id = b.id_
		]]>
		<where>
			a.del_flag = 0
			<if test="searchParams.id != null">
				and a.ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.companyCode != null">
				and b.code_ like #{searchParams.companyCode}
			</if>
			<if test="searchParams.type != null">
				and a.type_ = #{searchParams.type}
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>
	<select id="findByCompanyIdAndType" resultMap="ApprovalConfigMap">
		<![CDATA[
		select * from base_approval_config
		where del_flag = 0
		and company_id = #{companyId}
		and type_ = #{type}
		limit 1
		]]>
	</select>
</mapper>