<?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.diagbot.mapper.ProductServiceMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.ProductService">
        <id column="id" property="id"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="creator" property="creator"/>
        <result column="modifier" property="modifier"/>
        <result column="product_id" property="productId"/>
        <result column="service_id" property="serviceId"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultWrapperMap" type="com.diagbot.entity.wrapper.ProductServiceWrapper">
        <id column="id" property="id"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="creator" property="creator"/>
        <result column="modifier" property="modifier"/>
        <result column="product_id" property="productId"/>
        <result column="service_id" property="serviceId"/>
        <result column="remark" property="remark"/>
        <result column="product_name" property="productName"/>
        <result column="product_description" property="productDescription"/>
        <result column="service_name" property="serviceName"/>
        <result column="service_description" property="serviceDescription"/>
    </resultMap>


    <!-- 查询产品与服务端的关联列表（分页） -->
    <select id="selectProductServicePage" resultMap="BaseResultWrapperMap">
        select a.*,d.name as product_name,d.decription as product_description,c.name as service_name,c.description as service_description
        from diag_product_service a,diag_opened_products b,diag_service_info c ,diag_lantone_product d
        where a.product_id=b.product_id
        and a.product_id=d.id
        and a.service_id=c.id
        and a.is_deleted='N'
        and b.is_deleted='N'
        and c.is_deleted='N'
        and b.service_status=1
        and d.is_deleted='N'
        and (find_in_set('1',d.access_type) or FIND_IN_SET('2',d.access_type))
        <if test="productService.userId != null and productService.userId != '' ">
            and b.user_id=#{productService.userId} and c.user_id=#{productService.userId}
        </if>
        order by a.gmt_create desc
    </select>
</mapper>
