<?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.setting.UnifiedServiceMapperEx">

	<resultMap id="GroupResultMap" type="cn.superdesk.uniorder.dao.entity.unified.UnifiedServiceGroup">
		<id column="id" property="id" jdbcType="BIGINT"/>
		<result column="group_name" property="groupName" jdbcType="VARCHAR"/>
		<result column="group_code" property="groupCode" jdbcType="VARCHAR"/>
		<!-- serviceNo -->
		<result column="Service_no" property="ServiceNo" jdbcType="VARCHAR"/>
	</resultMap>

	<resultMap id="SelectResultMap" type="cn.superdesk.uniorder.dto.vo._function.select.SelectOptionUnifiedService">
		<result column="service_no" property="serviceNo" jdbcType="VARCHAR"/>
		<result column="service_name" property="serviceName" jdbcType="VARCHAR"/>
	</resultMap>

	<select id="findByCode" resultMap="cn.superdesk.uniorder.dao.mapper.setting.UnifiedServiceMapper.BaseResultMap" parameterType="java.lang.String">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.setting.UnifiedServiceMapper.Base_Column_List"/>
		from
			unified_service
		where
			service_no in (
				SELECT
					service_no
				from
					unified_service_group
				where
					group_code =#{code,jdbcType=VARCHAR}
			)
		LIMIT 1
	</select>

	<select id="findByServiceNo"
			resultMap="cn.superdesk.uniorder.dao.mapper.setting.UnifiedServiceMapper.BaseResultMap"
			parameterType="java.lang.String">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.setting.UnifiedServiceMapper.Base_Column_List"/>
		from
			unified_service
		<where>
		<if test="serviceNo !=null and serviceNo != ''">
			and service_no = #{serviceNo}
		</if>
		</where>
		LIMIT 1
	</select>

	<select id="findAllByGroup" resultMap="GroupResultMap">
		SELECT
			id,
			group_name,
			group_code,
			service_no
		FROM
			unified_service_group
		GROUP BY group_code
	</select>

	<select id="findAll" resultMap="cn.superdesk.uniorder.dao.mapper.setting.UnifiedServiceMapper.BaseResultMap">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.setting.UnifiedServiceMapper.Base_Column_List"/>
		from
			unified_service
		<where>
		<if test="orderType !=null and orderType != ''">
			and order_type like CONCAT('%',#{orderType},'%')
		</if>
		<if test="serviceName !=null and serviceName != ''">
			and service_name like CONCAT('%',#{serviceName},'%')
		</if>
		</where>
	</select>

	<select id="getSelectByVirt" resultMap="SelectResultMap">
		SELECT
			group_name as service_name,
			group_code as service_no
		FROM
			unified_service_group
		where service_no in (
			select
				service_no
			from
				unified_order
			<where>
			<if test="virtId != null and virtId != ''">
				and purchase_virt_id=#{virtId}
			</if>
			</where>
		)
		GROUP BY group_code
	</select>

</mapper>