<?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.PromiseMapper">

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

	<!--数据字典表名 -->
	<sql id="dicTableName">
		sys_dictionaries
	</sql>

	<!-- 字段 -->
	<sql id="Field">
		f.PROMISE_ID,
		f.PROMISE_NAME,
		f.LEVEL,
		f.TEXT,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.TYPE,
		f.CORPINFO_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		PROMISE_ID,
		PROMISE_NAME,
		LEVEL,
		TEXT,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		TYPE,
		CORPINFO_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{PROMISE_ID},
		#{PROMISE_NAME},
		#{LEVEL},
		#{TEXT},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{TYPE},
		#{CORPINFO_ID}
	</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 as LEVELNAME
		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 != ''"><!-- 关键词检索 -->
			and f.PROMISE_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		order by CREATTIME desc
	</select>

	<!-- 禁用启用-->
	<delete id="editdelete" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ISDELETE = #{ISDELETE}
		where
		PROMISE_ID = #{PROMISE_ID}
	</delete>

	<!-- 列表 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,d.NAME as LEVELNAME
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d on f.LEVEL = d.BIANMA
		where 1=1
		<if test="PROMISE_ID != null and PROMISE_ID != ''"><!-- 关键词检索 -->
			and f.PROMISE_ID = #{PROMISE_ID}
		</if>
		order by CREATTIME desc
	</select>

	<!-- 修改承诺书-->
	<delete id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ISDELETE = #{ISDELETE},
		OPERATTIME = #{OPERATTIME},
		PROMISE_NAME =#{PROMISE_NAME},
		LEVEL = #{LEVEL},
		CORPINFO_ID = #{CORPINFO_ID},
		<if test="TYPE != null and TYPE != ''"><!-- 类型 -->
			TYPE  = #{TYPE},
		</if>
		TEXT = #{TEXT}
		where
		PROMISE_ID = #{PROMISE_ID}
	</delete>

	<delete id="delete" parameterType="pd">
		delete from
		<include refid="tableName"></include>
		where
		PROMISE_ID = #{PROMISE_ID}
	</delete>
</mapper>
