TdgyMapper.xml 13 KB

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