<?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.scm.contract.dao.management.ProviderDao">

	<sql id="columns">
		a.`id` AS "id",
		a.`name` AS "name",
		a.`code` AS "code",
		a.`abbr` AS "abbr",
		a.`liaison` AS "liaison",
		a.`phone` AS "phone",
		a.`mail` AS "mail",
		a.`address` AS "address"
	</sql>

	<sql id="joins">
	</sql>

	<select id="list" resultType="com.scm.contract.model.management.Provider">
		SELECT
		<include refid="columns"/>
		FROM provider a
		<include refid="joins"/>
	</select>

	<select id="findList" resultType="com.scm.contract.model.management.Provider">
		SELECT
		<include refid="columns"/>
		FROM provider a
		<include refid="joins"/>
		<where>
			<if test="name != null and name != ''">
				AND a.`name` LIKE '%' #{name} '%'
				OR a.`abbr` LIKE '%' #{name} '%'
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
		</choose>
	</select>

	<select id="get" resultType="com.scm.contract.model.management.Provider">
		SELECT
		<include refid="columns"/>
		FROM provider a
		<include refid="joins"/>
		WHERE
		    a.`id` = #{id}
	</select>

	<select id="listByIds" resultType="com.scm.contract.model.management.Provider">
		SELECT
		<include refid="columns"/>
		FROM provider a
		<include refid="joins"/>
		WHERE
		a.`id` IN
		<foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
			#{id}
		</foreach>
	</select>

</mapper>
