<?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.bus.CarBlackListMapper">

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

	<!-- 字段用于新增 -->
	<sql id="Field">
		CARBLACKLIST_ID,
		LICENSE_PLATE,
		AFFILIATED_UNIT,
		CREATORID,
		STATE,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		CORPINFO_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{CARBLACKLIST_ID},
		#{LICENSE_PLATE},
		#{AFFILIATED_UNIT},
		#{CREATORID},
		#{STATE},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{CORPINFO_ID}
	</sql>

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

	<update id="edit" parameterType="pd">
		update
			<include refid="tableName"></include>
		set
			STATE = #{STATE}
		where
			CARBLACKLIST_ID = #{CARBLACKLIST_ID}
	</update>

	<select id="listPage" parameterType="page" resultType="pd">
		select
			<include refid="Field"></include>
		from
			<include refid="tableName"></include>
		where
			ISDELETE = '0'
		and CORPINFO_ID =#{pd.CORPINFO_ID}
		<if test="pd.AFFILIATED_UNIT != null and pd.AFFILIATED_UNIT != ''"><!-- 关键词检索 -->
			AND
			(
			AFFILIATED_UNIT LIKE CONCAT(CONCAT('%', #{pd.AFFILIATED_UNIT}),'%')
			)
		</if>
		<if test="pd.LICENSE_PLATE != null and pd.LICENSE_PLATE != ''"><!-- 关键词检索 -->
			AND
			(
			LICENSE_PLATE LIKE CONCAT(CONCAT('%', #{pd.LICENSE_PLATE}),'%')
			)
		</if>
		<if test="pd.STATE != null and pd.STATE != ''"><!-- 关键词检索 -->
			AND STATE = #{pd.STATE}
		</if>
		order by CREATTIME desc
	</select>

	<select id="findByLicensePlate" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include>
		where
		LICENSE_PLATE = #{LICENSE_PLATE}
		and
		STATE = 0
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
		and CORPINFO_ID = #{CORPINFO_ID}
		</if>
	</select>

</mapper>
