ProjectMapper.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ylx.project.mapper.ProjectMapper">
  6. <!-- 结果集映射 -->
  7. <resultMap id="OptionVOMap" type="com.ylx.massage.domain.vo.ProductOptionVO">
  8. <result column="id" property="id"/>
  9. <result column="title" property="title"/>
  10. <result column="productType" property="productType"/>
  11. </resultMap>
  12. <!-- 核心 SQL:UNION ALL 分页查询 -->
  13. <select id="selectOptionUnionPage" resultMap="OptionVOMap">
  14. SELECT * FROM (
  15. <!-- 第一部分:积分商品 -->
  16. SELECT
  17. CAST(id AS CHAR) as id,
  18. name as title,
  19. 1 as productType
  20. FROM product
  21. WHERE status = 1 AND deleted = 0
  22. <if test="dto.title != null and dto.title != ''">
  23. AND name LIKE CONCAT('%', #{dto.title}, '%')
  24. </if>
  25. UNION ALL
  26. <!-- 第二部分:项目商品 -->
  27. SELECT
  28. id,
  29. title as title,
  30. 0 as productType
  31. FROM project
  32. WHERE is_delete = 0
  33. <if test="dto.title != null and dto.title != ''">
  34. AND title LIKE CONCAT('%', #{dto.title}, '%')
  35. </if>
  36. ) as temp_table
  37. </select>
  38. <!-- 结果集映射保持不变 -->
  39. <resultMap id="ServiceOptionsVOMap" type="com.ylx.massage.domain.vo.ProductServiceOptionVO">
  40. <result column="id" property="id"/>
  41. <result column="title" property="title"/>
  42. <result column="productType" property="productType"/>
  43. <result column="serviceAreaCode" property="areaCode"/>
  44. <result column="serviceAreaName" property="areaName"/>
  45. <result column="price" property="price"/>
  46. <result column="merchantName" property="merchantName"/>
  47. <result column="merchantId" property="merchantId"/>
  48. </resultMap>
  49. <resultMap id="ProjectDetailVoMap" type="com.ylx.project.domain.vo.ProjectDetailVo">
  50. <id column="id" property="id"/>
  51. <result column="title" property="title"/>
  52. <result column="category_id" property="categoryId"/>
  53. <result column="category_name" property="categoryName"/>
  54. <result column="cover" property="cover"/>
  55. <result column="price" property="price"/>
  56. <result column="price_min" property="priceMin"/>
  57. <result column="price_max" property="priceMax"/>
  58. <result column="merchant_share_ratio" property="merchantShareRatio"/>
  59. <result column="standard_duration" property="standardDuration"/>
  60. <result column="unit_type" property="unitType"/>
  61. <result column="status" property="status"/>
  62. <result column="is_recommended" property="isRecommended"/>
  63. <result column="is_price_custom" property="isPriceCustom"/>
  64. <result column="highlight_ids" property="highlightIds"/>
  65. <result column="target_audience" property="targetAudience"/>
  66. <result column="detail" property="detail"/>
  67. <result column="create_time" property="createTime"/>
  68. <result column="update_time" property="updateTime"/>
  69. </resultMap>
  70. <select id="selectProjectDetailById" resultMap="ProjectDetailVoMap">
  71. SELECT
  72. p.id,
  73. p.title AS title,
  74. p.category_id,
  75. sc.name AS category_name,
  76. p.cover AS cover,
  77. p.price AS price,
  78. p.price_min,
  79. p.price_max,
  80. p.standard_duration,
  81. p.unit_type,
  82. p.merchant_share_ratio,
  83. p.status,
  84. p.is_recommended,
  85. p.is_price_custom,
  86. p.highlight_ids,
  87. p.target_audience,
  88. p.detail,
  89. p.create_time,
  90. p.update_time
  91. FROM project p
  92. LEFT JOIN service_category sc ON sc.id = p.category_id AND sc.is_delete = 0
  93. WHERE p.id = #{id}
  94. AND p.is_delete = 0
  95. </select>
  96. <select id="selectServiceOptionsPage" resultMap="ServiceOptionsVOMap">
  97. SELECT
  98. p.id AS id,
  99. ANY_VALUE(p.title) AS title,
  100. CASE WHEN p.type = '1' THEN 0 ELSE 0 END AS productType,
  101. ANY_VALUE(p.price) AS price,
  102. '广誉源' AS merchantName,
  103. '10000' AS merchantId,
  104. ANY_VALUE(
  105. CASE
  106. WHEN #{dto.areaCode} IS NOT NULL THEN (SELECT name FROM area WHERE code = #{dto.areaCode})
  107. ELSE agg.area_names
  108. END
  109. ) AS serviceAreaName,
  110. ANY_VALUE(
  111. CASE
  112. WHEN #{dto.areaCode} IS NOT NULL THEN #{dto.areaCode}
  113. ELSE agg.area_codes
  114. END
  115. ) AS serviceAreaCode
  116. FROM project p
  117. INNER JOIN (
  118. SELECT
  119. j_inner.c_bh_list,
  120. GROUP_CONCAT(DISTINCT a.code SEPARATOR ',') AS area_codes, -- code拼接
  121. GROUP_CONCAT(DISTINCT a.name SEPARATOR ',') AS area_names -- 名称拼接
  122. FROM t_js j_inner
  123. JOIN area a ON FIND_IN_SET(a.code, j_inner.service_area_codes)
  124. WHERE j_inner.is_delete = 0
  125. AND j_inner.n_tong = 1
  126. GROUP BY j_inner.c_bh_list
  127. ) agg ON FIND_IN_SET(p.id, agg.c_bh_list)
  128. WHERE
  129. p.is_delete = 0
  130. <if test="dto.productType != null and dto.productType == 0">
  131. AND p.type = 1
  132. </if>
  133. <if test="dto.productType != null and dto.productType == 1">
  134. AND 1 = 0
  135. </if>
  136. <if test="dto.productType != null and dto.productType != 0 and dto.productType != 1">
  137. AND p.type = #{dto.productType}
  138. </if>
  139. <if test="dto.productType == null">
  140. AND p.type = 1
  141. </if>
  142. <if test="dto.title != null and dto.title != ''">
  143. AND p.title LIKE CONCAT('%', #{dto.title}, '%')
  144. </if>
  145. <if test="dto.ids != null and dto.ids.size() > 0">
  146. AND p.id IN
  147. <foreach collection="dto.ids" item="id" open="(" separator="," close=")">
  148. #{id}
  149. </foreach>
  150. </if>
  151. AND EXISTS (
  152. SELECT 1
  153. FROM t_js j
  154. WHERE j.is_delete = 0
  155. AND j.n_tong = 1
  156. AND (#{dto.areaCode} IS NULL OR FIND_IN_SET(#{dto.areaCode}, j.service_area_codes))
  157. AND FIND_IN_SET(p.id, j.c_bh_list)
  158. )
  159. GROUP BY
  160. p.id
  161. ORDER BY
  162. p.create_time DESC
  163. </select>
  164. </mapper>