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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.DEPARTMENT_ID,
		f.CORPINFO_ID,
		f.SIGN_TIME,
		f.SIGN_USER,
		f.SIGN_PATH,
		f.INPUT1,
		f.INPUT2,
		f.INPUT3,
		f.INPUT4,
		f.INPUT5,
		f.INPUT6,
		f.INPUT7,
		f.INPUT8,
		f.INPUT9,
		f.INPUT10,
		f.RADIO1,
		f.RADIO2,
		f.RADIO3,
		f.START_TIME,
		f.END_TIME,
		f.COMMITMENTCOMPANY_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		DEPARTMENT_ID,
		CORPINFO_ID,
		SIGN_TIME,
		SIGN_USER,
		SIGN_PATH,
		INPUT1,
		INPUT2,
		INPUT3,
		INPUT4,
		INPUT5,
		INPUT6,
		INPUT7,
		INPUT8,
		INPUT9,
		INPUT10,
		RADIO1,
		RADIO2,
		RADIO3,
		START_TIME,
		END_TIME,
		COMMITMENTCOMPANY_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{DEPARTMENT_ID},
		#{CORPINFO_ID},
		#{SIGN_TIME},
		#{SIGN_USER},
		#{SIGN_PATH},
		#{INPUT1},
		#{INPUT2},
		#{INPUT3},
		#{INPUT4},
		#{INPUT5},
		#{INPUT6},
		#{INPUT7},
		#{INPUT8},
		#{INPUT9},
		#{INPUT10},
		#{RADIO1},
		#{RADIO2},
		#{RADIO3},
		#{START_TIME},
		#{END_TIME},
		#{COMMITMENTCOMPANY_ID}
	</sql>

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

	<!-- 删除-->
	<delete id="delete" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			COMMITMENTCOMPANY_ID = #{COMMITMENTCOMPANY_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			DEPARTMENT_ID = #{DEPARTMENT_ID},
			CORPINFO_ID = #{CORPINFO_ID},
			SIGN_TIME = #{SIGN_TIME},
			SIGN_USER = #{SIGN_USER},
			SIGN_PATH = #{SIGN_PATH},
			INPUT1 = #{INPUT1},
			INPUT2 = #{INPUT2},
			INPUT3 = #{INPUT3},
			INPUT4 = #{INPUT4},
			INPUT5 = #{INPUT5},
			INPUT6 = #{INPUT6},
			INPUT7 = #{INPUT7},
			INPUT8 = #{INPUT8},
			INPUT9 = #{INPUT9},
			INPUT10 = #{INPUT10},
			RADIO1 = #{RADIO1},
			RADIO2 = #{RADIO2},
			RADIO3 = #{RADIO3},
			START_TIME = #{START_TIME},
			END_TIME = #{END_TIME},
			COMMITMENTCOMPANY_ID = COMMITMENTCOMPANY_ID
		where
			COMMITMENTCOMPANY_ID = #{COMMITMENTCOMPANY_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,
		c.CORP_NAME,u.NAME as SIGN_USER_NAME
		from
		<include refid="tableName"></include> f
		left join BUS_CORP_INFO c on c.CORPINFO_ID = f.CORPINFO_ID
		left join SYS_USER u on u.USER_ID = f.SIGN_USER
		where
			f.COMMITMENTCOMPANY_ID = #{COMMITMENTCOMPANY_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>,
		c.CORP_NAME,u.NAME as SIGN_USER_NAME
		from
		<include refid="tableName"></include> f
		left join BUS_CORP_INFO c on c.CORPINFO_ID = f.CORPINFO_ID
		left join SYS_USER u on u.USER_ID = f.SIGN_USER
		where 1=1
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
				(
					u.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>
		<if test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''"><!-- 关键词检索 -->
			and f.DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
		</if>
		order by f.SIGN_TIME desc
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,u.NAME as SIGN_USER_NAME
		from
		<include refid="tableName"></include> f
		left join SYS_USER u on u.USER_ID = f.SIGN_USER
		 where 1=1
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		<if test="DEPARTMENT_ID != null and DEPARTMENT_ID != ''"><!-- 关键词检索 -->
			and f.DEPARTMENT_ID = #{DEPARTMENT_ID}
		</if>
		<if test="SIGN_TIME != null and SIGN_TIME != ''"><!-- 关键词检索 -->
			and DATE_FORMAT( NOW(), '%Y-%m-%d' ) between DATE_FORMAT( f.SIGN_TIME, '%Y-%m-%d' ) and DATE_FORMAT( f.END_TIME, '%Y-%m-%d' )
		</if>
	</select>

	<!-- 批量删除 -->
	<delete id="deleteAll" parameterType="String">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			COMMITMENTCOMPANY_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>

</mapper>
