<?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.zcloud.mapper.datasource.commitment.PromiseDetailsMapper">

	<!--表名 -->
	<sql id="tableName">
		BUS_PROMISE_DETAILS
	</sql>

	<!--数据字典表名 -->
	<sql id="dicTableName">
		`qa-gwj-prevention`.sys_dictionaries
	</sql>

	<!-- 字段 -->
	<sql id="Field">
		f.PROMISEDETAIL_ID,
		f.PROMISE_ID,
		f.COLLATERAL,
		f.SORTINDEX
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		PROMISEDETAIL_ID,
		PROMISE_ID,
		COLLATERAL,
		SORTINDEX
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{PROMISEDETAIL_ID},
		#{PROMISE_ID},
		#{COLLATERAL},
		#{SORTINDEX}
	</sql>

	<!-- 新增-->
	<insert id="save" parameterType="pd">
		insert into
	<include refid="tableName"></include>
		(
	<include refid="Field2"></include>
		) values (
	<include refid="FieldValue"></include>
		)
	</insert>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>,d.NAME
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d on f.LEVEL = d.BIANMA
		where 1=1
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->

		</if>
		<if test="pd.CREATOR != null and pd.CREATOR != ''"><!-- 关键词检索 -->

		</if>
		order by CREATTIME desc
	</select>

	<!-- 列表 -->
	<select id="findByPromiseId" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where 1=1
		<if test="PROMISE_ID != null and PROMISE_ID != ''"><!-- 关键词检索 -->
			and f.PROMISE_ID = #{PROMISE_ID}
		</if>
		ORDER BY f.SORTINDEX asc
	</select>

	<!-- 删除-->
	<delete id="deletePromiseId" parameterType="pd">
		delete from
		<include refid="tableName"></include>
		where
		PROMISE_ID = #{PROMISE_ID}
	</delete>

</mapper>
