1
0

TdgyMapper.xml 13 KB

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