<?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="cn.superdesk.uniorder.dao.mapper.organisation.UnifiedSupplierMapperEx">

	<resultMap id="UnifiedSupplierVoResultMap" type="cn.superdesk.uniorder.dto.vo.organisation.UnifiedSupplierVo">
		<id column="id" jdbcType="BIGINT" property="id" />
		<result column="sale_id" jdbcType="BIGINT" property="saleId" />
		<result column="sale_name" jdbcType="VARCHAR" property="saleName" />
		<result column="service_no" jdbcType="VARCHAR" property="serviceNo" />
		<result column="source_from" jdbcType="VARCHAR" property="sourceFrom" />
		<result column="contacts_name" jdbcType="VARCHAR" property="contactsName" />
		<result column="contacts_phone" jdbcType="VARCHAR" property="contactsPhone" />
		<result column="contacts_add" jdbcType="VARCHAR" property="contactsAdd" />
		<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
		<result column="create_user_id" jdbcType="BIGINT" property="createUserId" />
		<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
		<result column="update_user_id" jdbcType="BIGINT" property="updateUserId" />
		<result column="enabled" jdbcType="TINYINT" property="enabled" />
		<result column="deleted" jdbcType="TINYINT" property="deleted" />
	</resultMap>
	<select id="findAll" resultMap="UnifiedSupplierVoResultMap">
		select
			id,
			sale_id,
			sale_name,
			service_no,
			source_from,
			contacts_name,
			contacts_phone,
			contacts_add,
			create_time,
			create_user_id,
			update_time,
			update_user_id,
			enabled,
			deleted
		from
			unified_supplier us
		<where>
			and 1=1
			<if test="saleId != null and saleId != ''">
				and us.sale_id = #{saleId}
			</if>
			<if test="saleName != null and saleName != '' ">
				and us.sale_name like CONCAT('%',#{saleName},'%')
			</if>
			<if test="serviceNo != null and serviceNo != ''">
				and us.service_no = #{serviceNo}
			</if>

			<if test="sourceFromsSelected != null and sourceFromsSelected != '' and sourceFromsSelected.size > 0">
				and us.source_from in
				<foreach collection="sourceFromsSelected" index="index" item="source_from" open="(" close=")" separator=",">
					#{source_from}
				</foreach>
			</if>

			<if test="serviceNosSelected != null and serviceNosSelected != '' and serviceNosSelected.size > 0">
				and us.service_no in
				<foreach collection="serviceNosSelected" index="index" item="service_no" open="(" close=")" separator=",">
					#{service_no}
				</foreach>
			</if>

			<if test="enabled != null and enabled != ''">
				and us.enabled = #{enabled}
			</if>
		</where>
		<choose>
			<when test="orderByClause != null and orderByClause != '' ">
				order by ${orderByClause}

				<!-- order by
					us.update_time desc 更新时间 倒序
					us.id asc 结算中心Id 升序
					us.sale_id asc 第三方商户Id 升序
				-->
			</when>
			<otherwise>
				order by us.update_time desc

			</otherwise>
		</choose>

	</select>

	<select id="getSupplierList" resultMap="cn.superdesk.uniorder.dao.mapper.organisation.UnifiedSupplierMapper.BaseResultMap">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.organisation.UnifiedSupplierMapper.Base_Column_List"/>
		from unified_supplier
		where service_no = 'QYSC_QCH'
		order by create_time
	</select>

</mapper>