TCutOffWaterMapper.xml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.slibra.business.mapper.TCutOffWaterMapper">
  6. <resultMap type="TCutOffWater" id="TCutOffWaterResult">
  7. <result property="id" column="id" />
  8. <result property="timeBegin" column="time_begin" />
  9. <result property="timeEnd" column="time_end" />
  10. <result property="reason" column="reason" />
  11. <result property="pumpingStationNeighborhoodBuildingId" column="pumping_station_neighborhood_building_id" />
  12. <result property="delFlag" column="del_flag" />
  13. <result property="revision" column="revision" />
  14. <result property="createBy" column="create_by" />
  15. <result property="createTime" column="create_time" />
  16. <result property="updateBy" column="update_by" />
  17. <result property="updateTime" column="update_time" />
  18. <result property="remark" column="remark" />
  19. </resultMap>
  20. <sql id="selectTCutOffWaterVo">
  21. select id, time_begin, time_end, reason, pumping_station_neighborhood_building_id, del_flag, revision, create_by, create_time, update_by, update_time, remark from t_cut_off_water
  22. </sql>
  23. <select id="selectTCutOffWaterList" parameterType="TCutOffWater" resultMap="TCutOffWaterResult">
  24. <include refid="selectTCutOffWaterVo"/>
  25. <where>
  26. 1 = 1
  27. <if test="timeBegin != null "> and time_begin = #{timeBegin}</if>
  28. <if test="timeEnd != null "> and time_end = #{timeEnd}</if>
  29. <if test="reason != null and reason != ''"> and reason = #{reason}</if>
  30. <if test="pumpingStationNeighborhoodBuildingId != null and pumpingStationNeighborhoodBuildingId != ''"> and pumping_station_neighborhood_building_id = #{pumpingStationNeighborhoodBuildingId}</if>
  31. <if test="revision != null "> and revision = #{revision}</if>
  32. </where>
  33. and del_flag = 0 order by id desc
  34. </select>
  35. <select id="selectTCutOffWaterById" parameterType="Long" resultMap="TCutOffWaterResult">
  36. <include refid="selectTCutOffWaterVo"/>
  37. where id = #{id} and del_flag = 0
  38. </select>
  39. <insert id="insertTCutOffWater" parameterType="TCutOffWater" useGeneratedKeys="true" keyProperty="id">
  40. insert into t_cut_off_water
  41. <trim prefix="(" suffix=")" suffixOverrides=",">
  42. <if test="timeBegin != null">time_begin,</if>
  43. <if test="timeEnd != null">time_end,</if>
  44. <if test="reason != null">reason,</if>
  45. <if test="pumpingStationNeighborhoodBuildingId != null and pumpingStationNeighborhoodBuildingId != ''">pumping_station_neighborhood_building_id,</if>
  46. <if test="delFlag != null">del_flag,</if>
  47. <if test="revision != null">revision,</if>
  48. <if test="createBy != null">create_by,</if>
  49. <if test="createTime != null">create_time,</if>
  50. <if test="updateBy != null">update_by,</if>
  51. <if test="updateTime != null">update_time,</if>
  52. <if test="remark != null">remark,</if>
  53. </trim>
  54. <trim prefix="values (" suffix=")" suffixOverrides=",">
  55. <if test="timeBegin != null">#{timeBegin},</if>
  56. <if test="timeEnd != null">#{timeEnd},</if>
  57. <if test="reason != null">#{reason},</if>
  58. <if test="pumpingStationNeighborhoodBuildingId != null and pumpingStationNeighborhoodBuildingId != ''">#{pumpingStationNeighborhoodBuildingId},</if>
  59. <if test="delFlag != null">#{delFlag},</if>
  60. <if test="revision != null">#{revision},</if>
  61. <if test="createBy != null">#{createBy},</if>
  62. <if test="createTime != null">#{createTime},</if>
  63. <if test="updateBy != null">#{updateBy},</if>
  64. <if test="updateTime != null">#{updateTime},</if>
  65. <if test="remark != null">#{remark},</if>
  66. </trim>
  67. </insert>
  68. <update id="updateTCutOffWater" parameterType="TCutOffWater">
  69. update t_cut_off_water
  70. <trim prefix="SET" suffixOverrides=",">
  71. <if test="timeBegin != null">time_begin = #{timeBegin},</if>
  72. <if test="timeEnd != null">time_end = #{timeEnd},</if>
  73. <if test="reason != null">reason = #{reason},</if>
  74. <if test="pumpingStationNeighborhoodBuildingId != null and pumpingStationNeighborhoodBuildingId != ''">pumping_station_neighborhood_building_id = #{pumpingStationNeighborhoodBuildingId},</if>
  75. <if test="delFlag != null">del_flag = #{delFlag},</if>
  76. <if test="revision != null">revision = #{revision},</if>
  77. <if test="createBy != null">create_by = #{createBy},</if>
  78. <if test="createTime != null">create_time = #{createTime},</if>
  79. <if test="updateBy != null">update_by = #{updateBy},</if>
  80. <if test="updateTime != null">update_time = #{updateTime},</if>
  81. <if test="remark != null">remark = #{remark},</if>
  82. </trim>
  83. ,revision = revision + 1
  84. where id = #{id}
  85. </update>
  86. <delete id="deleteTCutOffWaterById" parameterType="Long">
  87. update t_cut_off_water set del_flag = 2,revision = revision + 1 where del_flag = 0 and id = #{id}
  88. </delete>
  89. <delete id="deleteTCutOffWaterByIds" parameterType="String">
  90. update t_cut_off_water set del_flag = 2,revision = revision + 1 where del_flag = 0 and id in
  91. <foreach item="id" collection="array" open="(" separator="," close=")">
  92. #{id}
  93. </foreach>
  94. </delete>
  95. <!-- 2024年11月06日10:18:29 下面是新增的,不允许覆盖 -->
  96. <!-- <select id="getCutOffWaterByUserPhone" resultMap="TCutOffWaterResult">-->
  97. <!-- </select>-->
  98. <select id="getCutOffWaterByNeighbourhoodName" resultMap="TCutOffWaterResult">
  99. <!-- SELECT
  100. *,#{asrText} neighbourhoodName
  101. FROM
  102. t_cut_off_water
  103. WHERE
  104. pumping_station_neighborhood_building_id IN (
  105. SELECT
  106. psnn.id
  107. FROM
  108. t_pumping_station_neighbourhood_number psnn
  109. INNER JOIN t_neighborhood n ON psnn.neighborhood_id = n.id
  110. AND n.`name` LIKE concat('%', #{asrText}, '%')
  111. AND psnn.del_flag = 0
  112. AND n.del_flag = 0
  113. )
  114. AND NOW() BETWEEN time_begin
  115. AND time_end -->
  116. <!-- 2024年11月15日15:15:56,逻辑调整,查询改成下面 -->
  117. SELECT DISTINCT
  118. a.*,
  119. c.`name` neighbourhoodName
  120. FROM
  121. t_cut_off_water a
  122. INNER JOIN t_cut_off_water_extra b ON a.id = b.cut_off_water_id
  123. AND a.del_flag = 0
  124. AND b.del_flag = 0
  125. INNER JOIN t_neighborhood c ON c.id = b.neighborhood_id
  126. AND c.del_flag = 0
  127. WHERE c.`name` LIKE concat('%', #{asrText}, '%')
  128. AND NOW() &gt;= time_begin AND (time_end is NULL or NOW() &lt; time_end)
  129. </select>
  130. <select id="selectgetExtraListByPumpingStationId" resultType="com.slibra.business.res.CutOffExtraRes">
  131. SELECT
  132. b.id pumpingStationId,
  133. b.`name` pumpingStationName,
  134. b.address pumpingStationAddress,
  135. c.id neighbourhoodId,
  136. c.`name` neighbourhoodName,
  137. c.address neighbourhoodAddress,
  138. d.`name` neighbourhoodNumberNames
  139. FROM
  140. ( SELECT * FROM t_pumping_station_neighbourhood_number WHERE pumping_station_id = #{id} AND del_flag = 0 ) a
  141. INNER JOIN t_pumping_station b ON a.pumping_station_id = b.id AND b.del_flag = 0
  142. INNER JOIN t_neighborhood c ON a.neighborhood_id = c.id AND c.del_flag = 0
  143. INNER JOIN t_neighborhood_building d on a.neighborhood_building_id = d.id AND d.del_flag = 0
  144. </select>
  145. <select id="selectgetExtraListByNeighbourhoodId" resultType="com.slibra.business.res.CutOffExtraRes">
  146. SELECT
  147. b.id pumpingStationId,
  148. b.`name` pumpingStationName,
  149. b.address pumpingStationAddress,
  150. c.id neighbourhoodId,
  151. c.`name` neighbourhoodName,
  152. c.address neighbourhoodAddress,
  153. d.`name` neighbourhoodNumberNames
  154. FROM
  155. ( SELECT * FROM t_pumping_station_neighbourhood_number WHERE neighborhood_id = #{id} AND del_flag = 0 ) a
  156. INNER JOIN t_pumping_station b ON a.pumping_station_id = b.id AND b.del_flag = 0
  157. INNER JOIN t_neighborhood c ON a.neighborhood_id = c.id AND c.del_flag = 0
  158. INNER JOIN t_neighborhood_building d on a.neighborhood_building_id = d.id AND d.del_flag = 0
  159. </select>
  160. <select id="selectgetExtraListByPumpingStationIdAndNeighbourhoodId" resultType="com.slibra.business.res.CutOffExtraRes">
  161. SELECT
  162. b.id pumpingStationId,
  163. b.`name` pumpingStationName,
  164. b.address pumpingStationAddress,
  165. c.id neighbourhoodId,
  166. c.`name` neighbourhoodName,
  167. c.address neighbourhoodAddress,
  168. d.`name` neighbourhoodNumberNames
  169. FROM
  170. ( SELECT * FROM t_pumping_station_neighbourhood_number WHERE pumping_station_id = #{pumpingStationId} AND neighborhood_id = #{neighborhoodId} AND del_flag = 0 ) a
  171. INNER JOIN t_pumping_station b ON a.pumping_station_id = b.id AND b.del_flag = 0
  172. INNER JOIN t_neighborhood c ON a.neighborhood_id = c.id AND c.del_flag = 0
  173. INNER JOIN t_neighborhood_building d on a.neighborhood_building_id = d.id AND d.del_flag = 0
  174. </select>
  175. <select id="getDistinctNamesUnionById" resultType="string">
  176. SELECT GROUP_CONCAT(DISTINCT b.`name` SEPARATOR ', ')
  177. FROM
  178. t_cut_off_water_extra a
  179. INNER JOIN t_neighborhood b ON a.neighborhood_id = b.id
  180. AND a.del_flag = 0
  181. AND b.del_flag = 0
  182. WHERE a.cut_off_water_id = #{id}
  183. </select>
  184. </mapper>