1
0

TdgyMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. <result property="nf" column="nf"/>
  24. <result property="bz" column="bz"/>
  25. </resultMap>
  26. <select id="isExit" resultType="Boolean">
  27. SELECT COUNT(1) > 0
  28. FROM t_tdgy
  29. WHERE project_id = #{projectId}
  30. </select>
  31. <!-- 添加记录 -->
  32. <insert id="add" parameterType="com.siwei.apply.domain.Tdgy">
  33. INSERT INTO t_tdgy (id, project_id, srf, tdyt, jswz,
  34. gd_area, gd_type, has_zz, hbcrfapfwh, hbcrhtbh,
  35. hbcrht_date, gd_unit, bz, has_onchain, creator_id,
  36. created_at, updated_at)
  37. VALUES (#{id}, #{projectId}, #{srf}, #{tdyt}, #{jswz},
  38. #{gdArea}, #{gdType}, #{hasZz}, #{hbcrfapfwh}, #{hbcrhtbh},
  39. #{hbcrhtDate}, #{gdUnit}, #{bz}, false, #{creatorId},
  40. now(), now())
  41. </insert>
  42. <!-- 根据项目ID获取记录 -->
  43. <select id="get" resultMap="BaseResultMap" parameterType="String">
  44. SELECT *
  45. FROM t_tdgy
  46. WHERE project_id = #{projectId}
  47. </select>
  48. <!-- 新增:根据主键ID获取记录 -->
  49. <select id="getById" resultMap="BaseResultMap" parameterType="String">
  50. SELECT *
  51. FROM t_tdgy
  52. WHERE id = #{id}
  53. </select>
  54. <!-- 更新记录 -->
  55. <update id="update" parameterType="com.siwei.apply.domain.vo.TdgyUpdateVo">
  56. UPDATE t_tdgy
  57. <set>
  58. <if test="projectId != null">project_id = #{projectId},</if>
  59. <if test="srf != null">srf = #{srf},</if>
  60. <if test="tdyt != null">tdyt = #{tdyt},</if>
  61. <if test="jswz != null">jswz = #{jswz},</if>
  62. <if test="gdArea != null">gd_area = #{gdArea},</if>
  63. <if test="gdType != null">gd_type = #{gdType},</if>
  64. <if test="hasZz != null">has_zz = #{hasZz},</if>
  65. <if test="hbcrfapfwh != null">hbcrfapfwh = #{hbcrfapfwh},</if>
  66. <if test="hbcrhtbh != null">hbcrhtbh = #{hbcrhtbh},</if>
  67. <if test="hbcrhtDate != null">hbcrht_date = #{hbcrhtDate},</if>
  68. <if test="hasOnchain != null">has_onchain = #{hasOnchain},</if>
  69. <if test="gdUnit != null">gd_unit = #{gdUnit},</if>
  70. <if test="bz != null">bz = #{bz},</if>
  71. updated_at = now()
  72. </set>
  73. WHERE id = #{id}
  74. </update>
  75. <!-- 更新has_onchain字段 -->
  76. <update id="updateHasOnchain">
  77. UPDATE t_tdgy
  78. SET has_onchain = #{hasOnchain}, updated_at = now()
  79. WHERE id = #{id}
  80. </update>
  81. <!-- 按 gd_type 统计数量与面积求和(面积统一换算成“亩”):返回 gdType(空值为“其他”), count, gdArea, gdUnit='亩'
  82. 当传入 projectType 时,仅统计其对应项目的记录(关联 t_project.project_type) -->
  83. <select id="countAndSumByGdType" resultType="com.siwei.apply.domain.res.ProjectSupplyRes">
  84. SELECT
  85. COALESCE(NULLIF(TRIM(td.gd_type), ''), '其他') AS gdType,
  86. '亩' AS gdUnit,
  87. COUNT(*) AS count,
  88. COALESCE(
  89. SUM(
  90. CASE
  91. WHEN td.gd_unit = '平方米' THEN COALESCE(td.gd_area, 0) / 666.6666667 -- 平方米 -> 亩
  92. WHEN td.gd_unit = '公顷' THEN COALESCE(td.gd_area, 0) * 15 -- 公顷 -> 亩
  93. ELSE COALESCE(td.gd_area, 0) -- 默认当作亩(含 '2')
  94. END
  95. ), 0
  96. ) AS gdArea
  97. FROM (SELECT * from t_tdgy WHERE has_onchain =TRUE ) td
  98. <where>
  99. <choose>
  100. <when test="projectType == null">
  101. EXISTS (
  102. SELECT 1 FROM t_project p
  103. WHERE p.id = td.project_id and p.on_chain_num > 0
  104. )
  105. </when>
  106. <when test="projectType != null">
  107. EXISTS (
  108. SELECT 1 FROM t_project p
  109. WHERE p.id = td.project_id AND p.project_type = #{projectType} and p.on_chain_num > 0
  110. )
  111. </when>
  112. </choose>
  113. </where>
  114. GROUP BY COALESCE(NULLIF(TRIM(td.gd_type), ''), '其他')
  115. </select>
  116. <!-- 跟年份查询当前土地实际供应情况! -->
  117. <select id="getListByYear" resultType="com.siwei.apply.domain.res.TdgyStatisticsRes" parameterType="String">
  118. SELECT
  119. project.ID AS projectId,
  120. project.NAME AS xmmc,
  121. project.company ,
  122. t_node.ID AS nodeId,
  123. t_node.tdyt,
  124. t_node.gd_type AS gyfs,
  125. t_node.hbcrht_date AS gysj,
  126. COALESCE (
  127. CASE
  128. WHEN t_node.gd_unit = '平方米' THEN
  129. COALESCE ( t_node.gd_area, 0 ) / 666.6666667-- 平方米 -> 亩
  130. WHEN t_node.gd_unit = '公顷' THEN
  131. COALESCE ( t_node.gd_area, 0 ) * 15-- 公顷 -> 亩
  132. ELSE COALESCE ( t_node.gd_area, 0 ) -- 默认当作亩(含 '2')
  133. END,
  134. 0
  135. ) AS mjMu,
  136. land.geom_db_id as geomDbId,
  137. details.upload_id as uploadId,
  138. details.geom_json as geomJson,
  139. details.sort,
  140. details.geom_area as geomArea,
  141. ST_AsEWKT(details.geom) as geom
  142. FROM
  143. t_geom_db_details details
  144. LEFT JOIN t_node_land land ON details.upload_id :: TEXT = land.geom_db_id ::TEXT
  145. LEFT JOIN t_tdgy t_node ON land.node_id :: TEXT = t_node.ID ::TEXT
  146. LEFT JOIN t_project project ON project.ID :: TEXT = t_node.project_id :: TEXT
  147. WHERE
  148. t_node.has_onchain = TRUE
  149. AND project.ID IS NOT NULL
  150. <if test="year != null">
  151. AND LEFT(t_node.hbcrht_date, 4) = #{year}
  152. </if>
  153. <if test="landTypeCode != null">
  154. AND LEFT(t_node.tdyt,2)=#{landTypeCode}
  155. </if>
  156. <if test="startTime != null and startTime != ''">
  157. AND t_node.hbcrht_date &gt;= #{startTime}
  158. </if>
  159. <if test="endTime != null and endTime != ''">
  160. AND t_node.hbcrht_date &lt;= #{endTime}
  161. </if>
  162. </select>
  163. <!-- 查询当前存量土地实际供应情况! -->
  164. <select id="getSjgdListByYear" resultType="com.siwei.apply.domain.res.TdgyStatisticsRes" parameterType="String">
  165. SELECT
  166. '' AS projectId,
  167. xmmc AS xmmc,
  168. srr AS company,
  169. gid AS nodeId,
  170. COALESCE(NULLIF(land.code, ''), '23') AS tdyt,
  171. gyfs,
  172. qdrq AS gysj,
  173. ROUND(COALESCE ( gymj, 0 ) / 666.6666667,2) AS mjMu,-- 平方米 -> 亩
  174. '' AS geomDbId,
  175. '' AS uploadId,
  176. '' AS geomJson,
  177. 0 AS sort,
  178. COALESCE(left(nf,4), '其它') AS nf,
  179. shape_area AS geomArea,
  180. ST_AsEWKT ( geom ) AS geom
  181. FROM
  182. vector.gj_gd_data
  183. LEFT JOIN public.land_type land ON land.NAME = gj_gd_data.tdyt
  184. WHERE 1=1
  185. <if test="year != null">
  186. AND LEFT(CAST(gj_gd_data.qdrq AS VARCHAR), 4) = #{year}
  187. </if>
  188. <if test="landTypeCode != null">
  189. AND LEFT(land.code,2)=#{landTypeCode}
  190. </if>
  191. <if test="startTime != null and startTime != ''">
  192. AND CAST(gj_gd_data.qdrq AS VARCHAR) &gt;= #{startTime}
  193. </if>
  194. <if test="endTime != null and endTime != ''">
  195. AND CAST(gj_gd_data.qdrq AS VARCHAR) &lt;= #{endTime}
  196. </if>
  197. </select>
  198. <!-- 根据年份查询当前存量土地实际供应情况! -->
  199. <select id="getSjgdListByNf" resultType="com.siwei.apply.domain.res.TdgyStatisticsRes" parameterType="String">
  200. SELECT
  201. '' AS projectId,
  202. xmmc AS xmmc,
  203. srr AS company,
  204. gid AS nodeId,
  205. tdyt,
  206. COALESCE ( land.code, '23' ) AS tdyt2,
  207. gyfs,
  208. qdrq AS gysj,
  209. ROUND(COALESCE ( gymj, 0 ) / 666.6666667,2) AS mjMu,-- 平方米 -> 亩
  210. '' AS geomDbId,
  211. '' AS uploadId,
  212. '' AS geomJson,
  213. left(gj_gd_data.nf,4) as nf,
  214. 0 AS sort
  215. FROM
  216. vector.gj_gd_data
  217. LEFT JOIN public.land_type land ON land.NAME = gj_gd_data.tdyt
  218. WHERE 1=1
  219. <if test="(startYear != null and startYear != null) and (endYear != '' and endYear != '')">
  220. AND left(gj_gd_data.nf,4)::NUMERIC BETWEEN #{startYear}::NUMERIC AND #{endYear}::NUMERIC
  221. </if>
  222. </select>
  223. <select id="getActualProject" resultType="Map" parameterType="String">
  224. SELECT
  225. "gid",
  226. "objectid",
  227. "xzq_dm",
  228. "gyfs",
  229. "nf",
  230. "dzjgh",
  231. "hthbbh",
  232. "qdrq",
  233. "xmmc",
  234. "srr",
  235. "srrlxdh",
  236. "zdbh",
  237. "tdzl",
  238. "tdly",
  239. "xmzmj",
  240. "gymj",
  241. "shape_area",
  242. ST_AsEWKT ( geom ) AS geom
  243. FROM
  244. vector.gj_gd_data
  245. WHERE 1=1
  246. <if test="gid != null and gid != ''">
  247. AND gj_gd_data.gid::varchar = #{gid}
  248. </if>
  249. LIMIT 1
  250. </select>
  251. <select id="getTdgyList" resultMap="BaseResultMap">
  252. SELECT
  253. gd.id AS id,
  254. pro.ID AS project_id,
  255. pro.name AS project_name,
  256. '1' AS batch_type,
  257. gd.hbcrht_date,
  258. gd.srf,
  259. gd.gd_type,
  260. gd.hbcrht_date,
  261. gd.has_zz,
  262. gd.hbcrfapfwh,
  263. gd.hbcrht_date,
  264. COALESCE(NULLIF(gd.tdyt, ''), '23') AS tdyt,
  265. COALESCE (
  266. CASE
  267. WHEN gd.gd_unit = '平方米' THEN
  268. COALESCE ( gd.gd_area, 0 ) / 666.6666667
  269. WHEN gd.gd_unit = '公顷' THEN
  270. COALESCE ( gd.gd_area, 0 ) * 15
  271. WHEN gd.gd_unit = '亩' THEN
  272. COALESCE ( gd.gd_area, 0 ) * 1
  273. END,
  274. 0
  275. ) AS gd_area,
  276. COALESCE(left(gd.hbcrht_date,4), '其它') AS nf,
  277. '亩' as gd_unit
  278. FROM
  279. t_tdgy gd
  280. LEFT JOIN t_project pro ON gd.project_id = pro."id"
  281. WHERE
  282. pro.on_chain_num > 0
  283. AND gd.has_onchain = 't'
  284. <if test="(startYear != null and startYear != null) and (endYear != '' and endYear != '')">
  285. AND left(gd.hbcrht_date,4)::NUMERIC BETWEEN #{startYear}::NUMERIC AND #{endYear}::NUMERIC
  286. </if>
  287. </select>
  288. <!-- ========================================这里数据治理的相关sql====================================================== -->
  289. <select id="getTdgyGeomList" resultType="map">
  290. SELECT project.id AS project_id,
  291. t_table.id AS node_id,
  292. details.id AS details_id
  293. FROM t_geom_db_details details
  294. LEFT JOIN t_node_land land ON details.upload_id = land.geom_db_id
  295. LEFT JOIN t_tdgy t_table ON land.node_id = t_table.id
  296. LEFT JOIN t_project project ON project.id = t_table.project_id
  297. WHERE project."name" LIKE 'pro3%' or project."name" LIKE 'xxxx3%' ;
  298. </select>
  299. <!-- <select id="getIntersectsGeomZdList" resultType="map">-->
  300. <!-- SELECT project.id AS project_id,-->
  301. <!-- t_table.id AS node_id,-->
  302. <!-- details.id AS details_id,-->
  303. <!-- FROM t_geom_db_details details-->
  304. <!-- LEFT JOIN t_node_land land ON details.upload_id = land.geom_db_id-->
  305. <!-- LEFT JOIN t_tdgy t_table ON land.node_id = t_table.id-->
  306. <!-- LEFT JOIN t_project project ON project.id = t_table.project_id-->
  307. <!-- WHERE t_table.has_onchain = true-->
  308. <!-- </select>-->
  309. </mapper>