1
0

TdgyMapper.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.siwei.apply.mapper.TdgyMapper">
  6. <resultMap id="BaseResultMap" type="com.siwei.apply.domain.Tdgy">
  7. <id property="id" column="id"/>
  8. <result property="projectId" column="project_id"/>
  9. <result property="srf" column="srf"/>
  10. <result property="tdyt" column="tdyt"/>
  11. <result property="jswz" column="jswz"/>
  12. <result property="gdArea" column="gd_area"/>
  13. <result property="gdType" column="gd_type"/>
  14. <result property="hasZz" column="has_zz"/>
  15. <result property="hbcrfapfwh" column="hbcrfapfwh"/>
  16. <result property="hbcrhtbh" column="hbcrhtbh"/>
  17. <result property="hbcrhtDate" column="hbcrht_date"/>
  18. <result property="hasOnchain" column="has_onchain"/>
  19. <result property="creatorId" column="creator_id"/>
  20. <result property="createdAt" column="created_at"/>
  21. <result property="updatedAt" column="updated_at"/>
  22. <result property="gdUnit" column="gd_unit"/>
  23. </resultMap>
  24. <select id="isExit" resultType="Boolean">
  25. SELECT COUNT(1) > 0
  26. FROM t_tdgy
  27. WHERE project_id = #{projectId}
  28. </select>
  29. <!-- 添加记录 -->
  30. <insert id="add" parameterType="com.siwei.apply.domain.Tdgy">
  31. INSERT INTO t_tdgy (id, project_id, srf, tdyt, jswz,
  32. gd_area, gd_type, has_zz, hbcrfapfwh, hbcrhtbh,
  33. hbcrht_date, gd_unit, has_onchain, creator_id,
  34. created_at, updated_at)
  35. VALUES (#{id}, #{projectId}, #{srf}, #{tdyt}, #{jswz},
  36. #{gdArea}, #{gdType}, #{hasZz}, #{hbcrfapfwh}, #{hbcrhtbh},
  37. #{hbcrhtDate}, #{gdUnit}, false, #{creatorId},
  38. now(), now())
  39. </insert>
  40. <!-- 根据项目ID获取记录 -->
  41. <select id="get" resultMap="BaseResultMap" parameterType="String">
  42. SELECT *
  43. FROM t_tdgy
  44. WHERE project_id = #{projectId}
  45. </select>
  46. <!-- 新增:根据主键ID获取记录 -->
  47. <select id="getById" resultMap="BaseResultMap" parameterType="String">
  48. SELECT *
  49. FROM t_tdgy
  50. WHERE id = #{id}
  51. </select>
  52. <!-- 更新记录 -->
  53. <update id="update" parameterType="com.siwei.apply.domain.vo.TdgyUpdateVo">
  54. UPDATE t_tdgy
  55. <set>
  56. <if test="projectId != null">project_id = #{projectId},</if>
  57. <if test="srf != null">srf = #{srf},</if>
  58. <if test="tdyt != null">tdyt = #{tdyt},</if>
  59. <if test="jswz != null">jswz = #{jswz},</if>
  60. <if test="gdArea != null">gd_area = #{gdArea},</if>
  61. <if test="gdType != null">gd_type = #{gdType},</if>
  62. <if test="hasZz != null">has_zz = #{hasZz},</if>
  63. <if test="hbcrfapfwh != null">hbcrfapfwh = #{hbcrfapfwh},</if>
  64. <if test="hbcrhtbh != null">hbcrhtbh = #{hbcrhtbh},</if>
  65. <if test="hbcrhtDate != null">hbcrht_date = #{hbcrhtDate},</if>
  66. <if test="hasOnchain != null">has_onchain = #{hasOnchain},</if>
  67. <if test="gdUnit != null">gd_unit = #{gdUnit},</if>
  68. updated_at = now()
  69. </set>
  70. WHERE id = #{id}
  71. </update>
  72. <!-- 更新has_onchain字段 -->
  73. <update id="updateHasOnchain">
  74. UPDATE t_tdgy
  75. SET has_onchain = #{hasOnchain}, updated_at = now()
  76. WHERE id = #{id}
  77. </update>
  78. <!-- 按 gd_type 统计数量与面积求和(面积统一换算成“亩”):返回 gdType(空值为“其他”), count, gdArea, gdUnit='亩'
  79. 当传入 projectType 时,仅统计其对应项目的记录(关联 t_project.project_type) -->
  80. <select id="countAndSumByGdType" resultType="com.siwei.apply.domain.res.ProjectSupplyRes">
  81. SELECT
  82. COALESCE(NULLIF(TRIM(td.gd_type), ''), '其他') AS gdType,
  83. '亩' AS gdUnit,
  84. COUNT(*) AS count,
  85. COALESCE(
  86. SUM(
  87. CASE
  88. WHEN td.gd_unit = '平方米' THEN COALESCE(td.gd_area, 0) / 666.6666667 -- 平方米 -> 亩
  89. WHEN td.gd_unit = '公顷' THEN COALESCE(td.gd_area, 0) * 15 -- 公顷 -> 亩
  90. ELSE COALESCE(td.gd_area, 0) -- 默认当作亩(含 '2')
  91. END
  92. ), 0
  93. ) AS gdArea
  94. FROM (SELECT * from t_tdgy WHERE has_onchain =TRUE ) td
  95. <where>
  96. <choose>
  97. <when test="projectType == null">
  98. EXISTS (
  99. SELECT 1 FROM t_project p
  100. WHERE p.id = td.project_id and p.on_chain_num > 0
  101. )
  102. </when>
  103. <when test="projectType != null">
  104. EXISTS (
  105. SELECT 1 FROM t_project p
  106. WHERE p.id = td.project_id AND p.project_type = #{projectType} and p.on_chain_num > 0
  107. )
  108. </when>
  109. </choose>
  110. </where>
  111. GROUP BY COALESCE(NULLIF(TRIM(td.gd_type), ''), '其他')
  112. </select>
  113. <!-- 跟年份查询当前土地实际供应情况! -->
  114. <select id="getListByYear" resultType="com.siwei.apply.domain.res.TdgyStatisticsRes" parameterType="String">
  115. SELECT
  116. project.ID AS projectId,
  117. project.NAME AS xmmc,
  118. project.company ,
  119. t_node.ID AS nodeId,
  120. t_node.tdyt,
  121. t_node.gd_type AS gyfs,
  122. t_node.hbcrht_date AS gysj,
  123. COALESCE (
  124. CASE
  125. WHEN t_node.gd_unit = '平方米' THEN
  126. COALESCE ( t_node.gd_area, 0 ) / 666.6666667-- 平方米 -> 亩
  127. WHEN t_node.gd_unit = '公顷' THEN
  128. COALESCE ( t_node.gd_area, 0 ) * 15-- 公顷 -> 亩 ELSE COALESCE ( t_node.gd_area, 0 ) -- 默认当作亩(含 '2')
  129. END,
  130. 0
  131. ) AS mjMu,
  132. land.geom_db_id as geomDbId,
  133. details.upload_id as uploadId,
  134. details.geom_json as geomJson,
  135. details.sort,
  136. details.geom_area as geomArea,
  137. ST_AsEWKT(details.geom) as geom
  138. FROM
  139. t_geom_db_details details
  140. LEFT JOIN t_node_land land ON details.upload_id :: TEXT = land.geom_db_id ::TEXT
  141. LEFT JOIN t_tdgy t_node ON land.node_id :: TEXT = t_node.ID ::TEXT
  142. LEFT JOIN t_project project ON project.ID :: TEXT = t_node.project_id :: TEXT
  143. WHERE
  144. t_node.has_onchain = TRUE
  145. AND project.ID IS NOT NULL
  146. <if test="year != null">
  147. AND LEFT(t_node.hbcrht_date, 4) = #{year}
  148. </if>
  149. <if test="landTypeCode != null">
  150. AND LEFT(t_node.tdyt,2)=#{landTypeCode}
  151. </if>
  152. <if test="startTime != null and startTime != ''">
  153. AND t_node.hbcrht_date &gt;= #{startTime}
  154. </if>
  155. <if test="endTime != null and endTime != ''">
  156. AND t_node.hbcrht_date &lt;= #{endTime}
  157. </if>
  158. LIMIT 41
  159. </select>
  160. <!-- 查询当前存量土地实际供应情况! -->
  161. <select id="getSjgdListByYear" resultType="com.siwei.apply.domain.res.TdgyStatisticsRes" parameterType="String">
  162. SELECT
  163. '' AS projectId,
  164. xmmc AS xmmc,
  165. srr AS company,
  166. gid AS nodeId,
  167. COALESCE ( land.code, '23' ) AS tdyt,
  168. gyfs,
  169. qdrq AS gysj,
  170. ROUND(COALESCE ( gymj, 0 ) / 666.6666667,2) AS mjMu,-- 平方米 -> 亩
  171. '' AS geomDbId,
  172. '' AS uploadId,
  173. '' AS geomJson,
  174. 0 AS sort,
  175. shape_area AS geomArea,
  176. ST_AsEWKT ( geom ) AS geom
  177. FROM
  178. vector.gj_gd_data
  179. LEFT JOIN public.land_type land ON land.NAME = gj_gd_data.tdyt
  180. WHERE 1=1
  181. <if test="year != null">
  182. AND LEFT(CAST(gj_gd_data.qdrq AS VARCHAR), 4) = #{year}
  183. </if>
  184. <if test="landTypeCode != null">
  185. AND LEFT(land.code,2)=#{landTypeCode}
  186. </if>
  187. <if test="startTime != null and startTime != ''">
  188. AND CAST(gj_gd_data.qdrq AS VARCHAR) &gt;= #{startTime}
  189. </if>
  190. <if test="endTime != null and endTime != ''">
  191. AND CAST(gj_gd_data.qdrq AS VARCHAR) &lt;= #{endTime}
  192. </if>
  193. LIMIT 41
  194. </select>
  195. <select id="getActualProject" resultType="Map" parameterType="String">
  196. SELECT
  197. "gid",
  198. "objectid",
  199. "xzq_dm",
  200. "gyfs",
  201. "nf",
  202. "dzjgh",
  203. "hthbbh",
  204. "qdrq",
  205. "xmmc",
  206. "srr",
  207. "srrlxdh",
  208. "zdbh",
  209. "tdzl",
  210. "tdly",
  211. "xmzmj",
  212. "gymj",
  213. "shape_area",
  214. ST_AsEWKT ( geom ) AS geom
  215. FROM
  216. vector.gj_gd_data
  217. WHERE 1=1
  218. <if test="gid != null and gid != ''">
  219. AND gj_gd_data.gid::varchar = #{gid}
  220. </if>
  221. LIMIT 1
  222. </select>
  223. </mapper>