TXiangmuMapper.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.ylx.massage.mapper.TXiangmuMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.ylx.massage.domain.TXiangmu">
  6. <id column="c_id" property="cId" />
  7. <result column="c_title" property="cTitle" />
  8. <result column="c_cover" property="cCover" />
  9. <result column="d_yuan_price" property="dYuanPrice" />
  10. <result column="d_price" property="dPrice" />
  11. <result column="n_minute" property="nMinute" />
  12. <result column="c_ld_list" property="cLdList" />
  13. <result column="n_sex_limit" property="nSexLimit" />
  14. <result column="c_syrq" property="cSyrq" />
  15. <result column="c_detail" property="cDetail" />
  16. <result column="n_sale_number" property="nSaleNumber" />
  17. <result column="dt_create_time" property="dtCreateTime" />
  18. </resultMap>
  19. <!-- 通用查询结果列 -->
  20. <sql id="Base_Column_List">
  21. c_id, c_title, c_cover, d_yuan_price, d_price, n_minute, c_ld_list, n_sex_limit, c_syrq, c_detail, n_sale_number, dt_create_time
  22. </sql>
  23. <!-- 结果集映射 -->
  24. <resultMap id="OptionVOMap" type="com.ylx.massage.domain.vo.ProductOptionVO">
  25. <result column="id" property="id"/>
  26. <result column="title" property="title"/>
  27. <result column="productType" property="productType"/>
  28. </resultMap>
  29. <!-- 核心 SQL:UNION ALL 分页查询 -->
  30. <select id="selectOptionUnionPage" resultMap="OptionVOMap">
  31. SELECT * FROM (
  32. <!-- 第一部分:积分商品 -->
  33. SELECT
  34. CAST(id AS CHAR) as id,
  35. name as title,
  36. 1 as productType
  37. FROM product
  38. WHERE status = 1 AND deleted = 0
  39. <if test="dto.title != null and dto.title != ''">
  40. AND name LIKE CONCAT('%', #{dto.title}, '%')
  41. </if>
  42. UNION ALL
  43. <!-- 第二部分:项目商品 -->
  44. SELECT
  45. c_id as id,
  46. c_title as title,
  47. 0 as productType
  48. FROM t_xiangmu
  49. WHERE is_delete = 0
  50. <if test="dto.title != null and dto.title != ''">
  51. AND c_title LIKE CONCAT('%', #{dto.title}, '%')
  52. </if>
  53. ) as temp_table
  54. </select>
  55. <!-- 结果集映射保持不变 -->
  56. <resultMap id="ServiceOptionsVOMap" type="com.ylx.massage.domain.vo.ProductServiceOptionVO">
  57. <result column="id" property="id"/>
  58. <result column="title" property="title"/>
  59. <result column="productType" property="productType"/>
  60. <result column="serviceAreaCode" property="areaCode"/>
  61. <result column="serviceAreaName" property="areaName"/>
  62. <result column="price" property="price"/>
  63. <result column="merchantName" property="merchantName"/>
  64. <result column="merchantId" property="merchantId"/>
  65. </resultMap>
  66. <select id="selectServiceOptionsPage" resultMap="ServiceOptionsVOMap">
  67. SELECT
  68. p.c_id AS id,
  69. ANY_VALUE(p.c_title) AS title,
  70. CASE WHEN p.project_type = '1' THEN 0 ELSE 0 END AS productType,
  71. ANY_VALUE(p.d_price) AS price,
  72. '广誉源' AS merchantName,
  73. '10000' AS merchantId,
  74. ANY_VALUE(
  75. CASE
  76. WHEN #{dto.areaCode} IS NOT NULL THEN (SELECT name FROM area WHERE code = #{dto.areaCode})
  77. ELSE agg.area_names
  78. END
  79. ) AS serviceAreaName,
  80. ANY_VALUE(
  81. CASE
  82. WHEN #{dto.areaCode} IS NOT NULL THEN #{dto.areaCode}
  83. ELSE agg.area_codes
  84. END
  85. ) AS serviceAreaCode
  86. FROM t_xiangmu p
  87. INNER JOIN (
  88. SELECT
  89. j_inner.c_bh_list,
  90. GROUP_CONCAT(DISTINCT a.code SEPARATOR ',') AS area_codes, -- code拼接
  91. GROUP_CONCAT(DISTINCT a.name SEPARATOR ',') AS area_names -- 名称拼接
  92. FROM t_js j_inner
  93. JOIN area a ON FIND_IN_SET(a.code, j_inner.service_area_codes)
  94. WHERE j_inner.is_delete = 0
  95. AND j_inner.n_tong = 1
  96. GROUP BY j_inner.c_bh_list
  97. ) agg ON FIND_IN_SET(p.c_id, agg.c_bh_list)
  98. WHERE
  99. p.is_delete = 0
  100. <if test="dto.productType != null and dto.productType == 0">
  101. AND p.project_type = 1
  102. </if>
  103. <if test="dto.productType != null and dto.productType == 1">
  104. AND 1 = 0
  105. </if>
  106. <if test="dto.productType != null and dto.productType != 0 and dto.productType != 1">
  107. AND p.project_type = #{dto.productType}
  108. </if>
  109. <if test="dto.productType == null">
  110. AND p.project_type = 1
  111. </if>
  112. <if test="dto.title != null and dto.title != ''">
  113. AND p.c_title LIKE CONCAT('%', #{dto.title}, '%')
  114. </if>
  115. <if test="dto.ids != null and dto.ids.size() > 0">
  116. AND p.c_id IN
  117. <foreach collection="dto.ids" item="id" open="(" separator="," close=")">
  118. #{id}
  119. </foreach>
  120. </if>
  121. AND EXISTS (
  122. SELECT 1
  123. FROM t_js j
  124. WHERE j.is_delete = 0
  125. AND j.n_tong = 1
  126. AND (#{dto.areaCode} IS NULL OR FIND_IN_SET(#{dto.areaCode}, j.service_area_codes))
  127. AND FIND_IN_SET(p.c_id, j.c_bh_list)
  128. )
  129. GROUP BY
  130. p.c_id
  131. ORDER BY
  132. p.create_time DESC
  133. </select>
  134. </mapper>