<?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.dsno2.dockingManagement.ResponsiblePersonMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.CORPINFO_ID,
		f.DOCKING_KEY,
		f.DOCKING_IV,
		f.DOCKING_URL,
		f.CODE,
		 f.APPID,
		 f.SECRET,
		f.ISDELETE,
	   f.CREATTOR,
	   f.CREATTIME,
	   f.OPERATTOR,
	   f.OPERATTIME
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		CORPINFO_ID,
		DOCKING_KEY,
		DOCKING_IV,
		DOCKING_URL,
		CODE,
		APPID,
		SECRET,
	   ISDELETE,
	   CREATTOR,
	   CREATTIME,
	   OPERATTOR,
	   OPERATTIME
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{CORPINFO_ID},
		#{DOCKING_KEY},
		#{DOCKING_IV},
		#{DOCKING_URL},
		#{CODE},
		#{APPID},
		#{SECRET},
		#{ISDELETE},
		#{CREATTOR},
		#{CREATTIME},
		#{OPERATTOR},
		#{OPERATTIME}
	</sql>

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

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

	</update>

	<select id="CorplistAll" parameterType="pd" resultType="pd">
		select
		f.*
		from
		`integrated_whb`.bus_corp_info f where f.ISDELETE = '0'
		and not exists(
		    select 1 from BUS_RESPONSIBLE_PERSON i where i.CORPINFO_ID = f.CORPINFO_ID and i.ISDELETE = '0'
		)
		<if test="CREATOR != null and CREATOR != ''"><!-- 关键词检索 -->
			and
			(
			f.CREATOR = #{CREATOR}
			)
		</if>

	</select>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			DOCKING_KEY = #{DOCKING_KEY},
			DOCKING_IV = #{DOCKING_IV},
			DOCKING_URL = #{DOCKING_URL},
			CODE = #{CODE},
			APPID = #{APPID},
			SECRET = #{SECRET},
			ISDELETE = #{ISDELETE},
			CREATTOR=#{CREATTOR},
			CREATTIME = #{CREATTIME},
			OPERATTOR =	#{OPERATTOR},
			OPERATTIME = #{OPERATTIME}
		where
			CORPINFO_ID = #{CORPINFO_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,
		    i.CORP_NAME
		from
		<include refid="tableName"></include> f
		left join `integrated_whb`.bus_corp_info i on i.CORPINFO_ID = f.CORPINFO_ID
		where
			f.CORPINFO_ID = #{CORPINFO_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>,
		    i.CORP_NAME
		from
		<include refid="tableName"></include> f
		left join `integrated_whb`.bus_corp_info i on i.CORPINFO_ID = f.CORPINFO_ID
		where 1=1 and f.ISDELETE = '0'
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
				(
					i.CORPNAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				)
		</if>
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
	</select>

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

</mapper>
