ProjectMapper.xml 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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.ProjectMapper">
  6. <resultMap id="projectMap" type="com.siwei.apply.domain.Project">
  7. <id column="id" property="id"/>
  8. <result column="name" property="name"/>
  9. <result column="code" property="code"/>
  10. <result column="company" property="company"/>
  11. <result column="created_at" property="createAt"/>
  12. <result column="updated_at" property="updateAt"/>
  13. <result column="project_type" property="projectType"/>
  14. <result column="on_chain_num" property="onChainNum"/>
  15. <result column="creator_id" property="creatorId"/>
  16. <result column="first_plot_code" property="firstPlotCode"/>
  17. <result column="second_plot_code" property="secondPlotCode"/>
  18. </resultMap>
  19. <!-- 扩展映射:继承基础映射并添加特有字段 -->
  20. <resultMap id="SearchProjectMap" type="com.siwei.apply.domain.SearchProject" extends="projectMap">
  21. <result property="attachmentInfoList" column="attachmentInfoList" typeHandler="com.siwei.apply.handler.JsonTypeHandler"/>
  22. </resultMap>
  23. <!-- 扩展映射:继承基础映射并添加特有字段 -->
  24. <resultMap id="SearchProjectUnionMap" type="com.siwei.apply.domain.SearchProjectAndAttachment">
  25. </resultMap>
  26. <insert id="add" parameterType="com.siwei.apply.domain.Project">
  27. INSERT INTO t_project (id, name, code, company,
  28. created_at, updated_at, project_type,first_plot_code,second_plot_code, creator_id)
  29. VALUES (#{id}, #{name}, #{code}, #{company}, now(), now(), #{projectType},
  30. #{firstPlotCode},#{secondPlotCode},
  31. #{creatorId})
  32. </insert>
  33. <select id="get" resultMap="projectMap">
  34. SELECT *
  35. FROM t_project
  36. where t_project.id = #{id}
  37. </select>
  38. <select id="getByConditionList" resultMap="projectMap">
  39. SELECT * FROM t_project
  40. <where>
  41. <if test="name != null and name != ''">
  42. OR name = #{name}
  43. </if>
  44. <if test="code != null and code != ''">
  45. OR code = #{code}
  46. </if>
  47. <if test="company != null and company != ''">
  48. OR company = #{company}
  49. </if>
  50. </where>
  51. </select>
  52. <select id="getList" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultMap="projectMap">
  53. SELECT *
  54. FROM t_project
  55. <where>
  56. <if test="name != null and name != ''">
  57. AND name LIKE CONCAT('%', #{name}, '%')
  58. </if>
  59. <if test="code != null and code != ''">
  60. AND code LIKE CONCAT('%', #{code}, '%')
  61. </if>
  62. <if test="keyWord != null and keyWord != ''">
  63. AND (
  64. name LIKE CONCAT('%', #{keyWord}, '%')
  65. OR company LIKE CONCAT('%', #{keyWord}, '%')
  66. )
  67. </if>
  68. <if test="projectType != null and projectType != 0">
  69. AND project_type = #{projectType}
  70. </if>
  71. <if test="isOnchain != null and isOnchain==true">
  72. AND on_chain_num > 0
  73. </if>
  74. <if test="shape != null and shape != ''">
  75. AND EXISTS (
  76. SELECT 1
  77. FROM t_project_workflow pw
  78. JOIN t_node_land nl ON nl.node_id = pw.node_id
  79. JOIN t_geom_db_details gd ON gd.upload_id = nl.geom_db_id
  80. WHERE pw.project_id = t_project.id
  81. AND public.ST_Intersects(gd.geom, public.ST_GeomFromEWKT(#{shape}))
  82. )
  83. </if>
  84. </where>
  85. ORDER BY updated_at DESC
  86. LIMIT #{pageSize} offset #{offset}
  87. </select>
  88. <select id="getListWithoutPage" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultMap="projectMap">
  89. SELECT *
  90. FROM t_project
  91. <where>
  92. <if test="name != null and name != ''">
  93. AND name LIKE CONCAT('%', #{name}, '%')
  94. </if>
  95. <if test="code != null and code != ''">
  96. AND code LIKE CONCAT('%', #{code}, '%')
  97. </if>
  98. <if test="keyWord != null and keyWord != ''">
  99. AND (
  100. name LIKE CONCAT('%', #{keyWord}, '%')
  101. OR company LIKE CONCAT('%', #{keyWord}, '%')
  102. )
  103. </if>
  104. <if test="projectType != null and projectType != 0">
  105. AND project_type = #{projectType}
  106. </if>
  107. <if test="isOnchain != null and isOnchain==true">
  108. AND on_chain_num > 0
  109. </if>
  110. <if test="shape != null and shape != ''">
  111. AND EXISTS (
  112. SELECT 1
  113. FROM t_project_workflow pw
  114. JOIN t_node_land nl ON nl.node_id = pw.node_id
  115. JOIN t_geom_db_details gd ON gd.upload_id = nl.geom_db_id
  116. WHERE pw.project_id = t_project.id
  117. AND public.ST_Intersects(gd.geom, public.ST_GeomFromEWKT(#{shape}))
  118. )
  119. </if>
  120. </where>
  121. ORDER BY updated_at DESC
  122. </select>
  123. <select id="getCount" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
  124. SELECT COUNT(*)
  125. FROM t_project
  126. <where>
  127. <if test="name != null and name != ''">
  128. AND name LIKE CONCAT('%', #{name}, '%')
  129. </if>
  130. <if test="code != null and code != ''">
  131. AND code LIKE CONCAT('%', #{code}, '%')
  132. </if>
  133. <if test="keyWord != null and keyWord != ''">
  134. AND (
  135. name LIKE CONCAT('%', #{keyWord}, '%')
  136. OR company LIKE CONCAT('%', #{keyWord}, '%')
  137. )
  138. </if>
  139. <if test="projectType != null and projectType != 0">
  140. AND project_type = #{projectType}
  141. </if>
  142. <if test="isOnchain != null and isOnchain==true">
  143. AND on_chain_num > 0
  144. </if>
  145. <if test="shape != null and shape != ''">
  146. AND EXISTS (
  147. SELECT 1
  148. FROM t_project_workflow pw
  149. JOIN t_node_land nl ON nl.node_id = pw.node_id
  150. JOIN t_geom_db_details gd ON gd.upload_id = nl.geom_db_id
  151. WHERE pw.project_id = t_project.id
  152. AND public.ST_Intersects(gd.geom, public.ST_GeomFromEWKT(#{shape}))
  153. )
  154. </if>
  155. </where>
  156. </select>
  157. <update id="update" parameterType="com.siwei.apply.domain.vo.ProjectUpdateVo">
  158. UPDATE t_project
  159. <set>
  160. <if test="name != null">name = #{name},</if>
  161. <if test="code != null">code = #{code},</if>
  162. <if test="company != null">company = #{company},</if>
  163. <if test="projectType != null">project_type = #{projectType},</if>
  164. <if test="onChainNum != null">on_chain_num = #{onChainNum},</if>
  165. <if test="firstPlotCode != null">first_plot_code = #{firstPlotCode},</if>
  166. <if test="secondPlotCode != null">second_plot_code = #{secondPlotCode},</if>
  167. updated_at = now()
  168. </set>
  169. WHERE id = #{id}
  170. </update>
  171. <delete id="batchDelete">
  172. DELETE FROM t_project
  173. WHERE id IN
  174. <foreach collection="ids" item="id" open="(" separator="," close=")">
  175. #{id}
  176. </foreach>
  177. </delete>
  178. <select id="getProjectTypeById" parameterType="string" resultType="int">
  179. SELECT project_type
  180. FROM t_project
  181. WHERE id = #{id}
  182. </select>
  183. <!-- 单一方法:一次返回 1/2 和总数的统计结果 -->
  184. <select id="countTypeStats" resultType="com.siwei.apply.domain.res.ProjectNumRes">
  185. SELECT
  186. SUM(CASE WHEN project_type = 1 THEN 1 ELSE 0 END) AS singleCount,
  187. SUM(CASE WHEN project_type = 2 THEN 1 ELSE 0 END) AS batchCount,
  188. COUNT(*) AS total
  189. FROM t_project where on_chain_num>0
  190. </select>
  191. <select id="selectOtherSupply" resultType="com.siwei.apply.domain.res.ProjectSupplyRes">
  192. SELECT
  193. '其他' AS gdType,
  194. '亩' AS gdUnit,
  195. CAST(0 AS double precision) AS gdArea,
  196. CAST(0 AS int) AS count
  197. </select>
  198. <select id="selectOtherSupplyExcludeProject" resultType="com.siwei.apply.domain.res.ProjectSupplyRes">
  199. SELECT
  200. '其他' AS gdType,
  201. '亩' AS gdUnit,
  202. COALESCE(
  203. SUM(
  204. CASE
  205. WHEN gd_unit = '0' THEN COALESCE(gd_area, 0) / 666.6666667
  206. WHEN gd_unit = '1' THEN COALESCE(gd_area, 0) * 15
  207. ELSE COALESCE(gd_area, 0)
  208. END
  209. ), 0
  210. ) AS gdArea,
  211. COUNT(*) AS count
  212. FROM t_tdgy
  213. WHERE project_id IS NULL OR project_id = ''
  214. </select>
  215. <!-- 根据节点获取项目信息-->
  216. <select id="getProjectByNodeId" resultMap="projectMap">
  217. SELECT project.* FROM "public"."t_project" project
  218. LEFT JOIN "public"."t_project_workflow" flow
  219. on flow.project_id=project.id
  220. WHERE flow.node_id = #{nodeId} LIMIT 1
  221. </select>
  222. <select id="getListSearchOld" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultMap="projectMap">
  223. SELECT *
  224. FROM t_project
  225. <where>
  226. <if test="keyWords != null and keyWords.size() > 0">
  227. regexp_like(name,
  228. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  229. , 'i')
  230. OR
  231. regexp_like(code,
  232. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  233. , 'i')
  234. OR
  235. regexp_like(company,
  236. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  237. , 'i')
  238. </if>
  239. <if test="isOnchain != null and isOnchain">
  240. AND on_chain_num > 0
  241. </if>
  242. </where>
  243. ORDER BY updated_at DESC
  244. LIMIT #{pageSize} offset #{offset}
  245. </select>
  246. <select id="getSearchCountOld" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
  247. SELECT COUNT(*)
  248. FROM t_project
  249. <where>
  250. <if test="keyWords != null and keyWords.size() > 0">
  251. regexp_like(name,
  252. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  253. , 'i')
  254. OR
  255. regexp_like(code,
  256. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  257. , 'i')
  258. OR
  259. regexp_like(company,
  260. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  261. , 'i')
  262. </if>
  263. <if test="isOnchain != null and isOnchain">
  264. AND on_chain_num > 0
  265. </if>
  266. </where>
  267. </select>
  268. <select id="getListSearchOld2" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultMap="SearchProjectMap">
  269. SELECT
  270. P."id" AS id,
  271. P."name" AS name,
  272. P."code" AS code,
  273. P."company" AS company,
  274. P."created_at" AS createAt,
  275. P."updated_at" AS updateAt,
  276. P."project_type" AS projectType,
  277. P."on_chain_num" AS onChainNum,
  278. P."creator_id" AS creatorId,
  279. COALESCE(
  280. jsonb_agg(
  281. CASE
  282. WHEN
  283. ${haveKeyWord}
  284. AND A."id" IS NOT NULL
  285. AND A."node_id" IS NOT NULL
  286. AND A."file_name" IS NOT NULL
  287. AND A."file_path" IS NOT NULL THEN
  288. jsonb_build_object('id', A.id,
  289. 'nodeId', A.node_id,
  290. 'fileName', A.file_name,
  291. 'filePath', A.file_path)
  292. ELSE NULL
  293. END
  294. ),'[]' -- 确保返回空数组而不是 null
  295. ) AS attachmentInfoList
  296. FROM
  297. public.t_project P
  298. LEFT JOIN
  299. public.t_project_attachment_info A ON P.id = A.project_id
  300. <if test="keyWords != null and keyWords.size() > 0">
  301. AND regexp_like(A.file_name,
  302. REGEXP_REPLACE(
  303. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  304. , '[\r\n\s]+', '', 'g')
  305. , 'i')
  306. </if>
  307. <where>
  308. <if test="keyWords != null and keyWords.size() > 0">
  309. regexp_like(P.name,
  310. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  311. , 'i')
  312. OR
  313. regexp_like(P.code,
  314. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  315. , 'i')
  316. OR
  317. regexp_like(P.company,
  318. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  319. , 'i')
  320. OR
  321. regexp_like(A.file_name,
  322. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  323. , 'i')
  324. </if>
  325. <if test="isOnchain != null and isOnchain">
  326. AND on_chain_num > 0
  327. </if>
  328. </where>
  329. GROUP BY
  330. P.id, P.name, P.code, P.company, P.created_at, P.updated_at, P.project_type, P.on_chain_num, P.creator_id
  331. ORDER BY
  332. updated_at DESC
  333. LIMIT #{pageSize} OFFSET #{offset}
  334. </select>
  335. <select id="getSearchCountOld2" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
  336. SELECT COUNT(*)
  337. FROM (
  338. SELECT DISTINCT
  339. P."id" AS id,
  340. P."name" AS name,
  341. P."code" AS code,
  342. P."company" AS company,
  343. P."created_at" AS createAt,
  344. P."updated_at" AS updateAt,
  345. P."project_type" AS projectType,
  346. P."on_chain_num" AS onChainNum,
  347. P."creator_id" AS creatorId
  348. FROM "public"."t_project" P
  349. LEFT JOIN public.t_project_attachment_info A ON P.id = A.project_id
  350. <if test="keyWords != null and keyWords.size() > 0">
  351. AND regexp_like(A.file_name,
  352. REGEXP_REPLACE(
  353. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  354. , '[\r\n\s]+', '', 'g')
  355. , 'i')
  356. </if>
  357. <where>
  358. <if test="keyWords != null and keyWords.size() > 0">
  359. regexp_like(P.name,
  360. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  361. , 'i')
  362. OR
  363. regexp_like(P.code,
  364. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  365. , 'i')
  366. OR
  367. regexp_like(P.company,
  368. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  369. , 'i')
  370. OR
  371. regexp_like(A.file_name,
  372. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  373. , 'i')
  374. </if>
  375. <if test="isOnchain != null and isOnchain">
  376. AND on_chain_num > 0
  377. </if>
  378. </where>
  379. ) AS distinct_projects
  380. </select>
  381. <select id="getListSearch" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultMap="SearchProjectUnionMap">
  382. <if test="filterType==0 or filterType==1">
  383. SELECT
  384. "id" AS ID,
  385. "name" AS NAME,
  386. "code" AS code,
  387. "company" AS company,
  388. "created_at" AS createAt,
  389. "updated_at" AS updateAt,
  390. "project_type" AS projectType,
  391. "on_chain_num" AS onChainNum,
  392. "creator_id" AS creatorId,
  393. "updated_at" AS updatedAt,
  394. '1' AS selectType,
  395. '' AS attachmentId,
  396. '' AS nodeId,
  397. '' AS fileName,
  398. '' AS filePath,
  399. '' AS resourceCode,
  400. '' AS zl,
  401. '' AS area
  402. from (
  403. SELECT P.*,
  404. (SELECT hbcrfapfwh FROM "public"."t_tdgy" WHERE project_id = P.id) hbcrfapfwh,
  405. (SELECT hbcrhtbh FROM "public"."t_tdgy" WHERE project_id = P.id) hbcrhtbh,
  406. (SELECT dzjgh FROM "public"."t_tdgy" WHERE project_id = P.id) dzjgh
  407. FROM PUBLIC.t_project P
  408. where 1=1
  409. <if test="isOnchain != null and isOnchain">
  410. AND on_chain_num > 0
  411. </if>
  412. ) as t_out
  413. <where>
  414. <if test="keyWords != null and keyWords.size() > 0">
  415. regexp_like(t_out.name,
  416. REGEXP_REPLACE(
  417. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  418. , '[\r\n\s]+', '', 'g')
  419. , 'i')
  420. OR
  421. regexp_like(t_out.code,
  422. REGEXP_REPLACE(
  423. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  424. , '[\r\n\s]+', '', 'g')
  425. , 'i')
  426. OR
  427. regexp_like(t_out.company,
  428. REGEXP_REPLACE(
  429. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  430. , '[\r\n\s]+', '', 'g')
  431. , 'i')
  432. OR
  433. regexp_like(t_out.hbcrfapfwh,
  434. REGEXP_REPLACE(
  435. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  436. , '[\r\n\s]+', '', 'g')
  437. , 'i')
  438. OR
  439. regexp_like(t_out.hbcrhtbh,
  440. REGEXP_REPLACE(
  441. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  442. , '[\r\n\s]+', '', 'g')
  443. , 'i')
  444. OR
  445. regexp_like(t_out.dzjgh,
  446. REGEXP_REPLACE(
  447. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  448. , '[\r\n\s]+', '', 'g')
  449. , 'i')
  450. </if>
  451. </where>
  452. </if>
  453. <if test="filterType==0">
  454. UNION
  455. </if>
  456. <if test="filterType==0 or filterType==2">
  457. SELECT
  458. project."id" AS ID,
  459. project."name" AS NAME,
  460. project."code" AS code,
  461. project."company" AS company,
  462. project."created_at" AS createAt,
  463. project."updated_at" AS updateAt,
  464. project."project_type" AS projectType,
  465. project."on_chain_num" AS onChainNum,
  466. project."creator_id" AS creatorId,
  467. project."updated_at" AS updatedAt,
  468. '2' AS selectType,
  469. info.ID AS attachmentId,
  470. info.node_id AS nodeId,
  471. info.file_name AS fileName,
  472. info.file_path AS filePath,
  473. '' AS resourceCode,
  474. '' AS zl,
  475. '' AS area
  476. FROM PUBLIC.t_project_attachment_info info
  477. LEFT JOIN t_project project on info.project_id=project.id
  478. <where>
  479. <if test="keyWords != null and keyWords.size() > 0">
  480. regexp_like(info.file_name,
  481. REGEXP_REPLACE(
  482. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  483. , '[\r\n\s]+', '', 'g')
  484. , 'i')
  485. </if>
  486. AND project.id is not null
  487. <if test="isOnchain != null and isOnchain">
  488. AND on_chain_num > 0
  489. </if>
  490. </where>
  491. </if>
  492. <if test="filterType==0">
  493. UNION
  494. </if>
  495. <if test="filterType==0 or filterType==3">
  496. SELECT
  497. project."id" AS ID,
  498. project."name" AS NAME,
  499. project."code" AS code,
  500. project."company" AS company,
  501. project."created_at" AS createAt,
  502. project."updated_at" AS updateAt,
  503. project."project_type" AS projectType,
  504. project."on_chain_num" AS onChainNum,
  505. project."creator_id" AS creatorId,
  506. project."updated_at" AS updatedAt,
  507. '3' AS selectType,
  508. '' AS attachmentId,
  509. '' AS nodeId,
  510. '' AS fileName,
  511. '' AS filePath,
  512. (code.resource_immobile_code) AS resourceCode,
  513. details.zl AS zl,
  514. CAST(ROUND(details.geom_area, 2) AS VARCHAR) AS area
  515. FROM
  516. (SELECT DISTINCT ON (project_id)
  517. project_id,
  518. land_code,
  519. code.resource_immobile_code,
  520. code.resource_business_code,
  521. code.resource_project_code
  522. FROM public.t_land_one_code code
  523. ORDER BY project_id) code
  524. LEFT JOIN "public"."t_node_land" node on code.land_code =node.id
  525. LEFT JOIN "public"."t_geom_db_details" details on node.geom_db_id =details.upload_id
  526. LEFT JOIN "public"."t_project" project on code.project_id =project.id
  527. <where>
  528. <if test="keyWords != null and keyWords.size() > 0">
  529. regexp_like((code.resource_immobile_code || code.resource_business_code || code.resource_project_code),
  530. REGEXP_REPLACE(
  531. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  532. , '[\r\n\s]+', '', 'g')
  533. , 'i')
  534. </if>
  535. AND project.id is not null
  536. <if test="isOnchain != null and isOnchain">
  537. AND on_chain_num > 0
  538. </if>
  539. </where>
  540. </if>
  541. ORDER BY
  542. updatedAt DESC
  543. LIMIT #{pageSize} OFFSET #{offset}
  544. </select>
  545. <select id="getSearchCount" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
  546. SELECT COUNT(*)
  547. FROM (
  548. <if test="filterType==0 or filterType==1">
  549. SELECT
  550. "id" AS ID,
  551. "name" AS NAME,
  552. "code" AS code,
  553. "company" AS company,
  554. "created_at" AS createAt,
  555. "updated_at" AS updateAt,
  556. "project_type" AS projectType,
  557. "on_chain_num" AS onChainNum,
  558. "creator_id" AS creatorId,
  559. "updated_at" AS updatedAt,
  560. '1' AS selectType,
  561. '' AS attachmentId,
  562. '' AS nodeId,
  563. '' AS fileName,
  564. '' AS filePath,
  565. '' AS resourceCode,
  566. '' AS zl,
  567. '' AS area
  568. from (
  569. SELECT P.*,
  570. (SELECT hbcrfapfwh FROM "public"."t_tdgy" WHERE project_id = P.id) hbcrfapfwh,
  571. (SELECT hbcrhtbh FROM "public"."t_tdgy" WHERE project_id = P.id) hbcrhtbh,
  572. (SELECT dzjgh FROM "public"."t_tdgy" WHERE project_id = P.id) dzjgh
  573. FROM PUBLIC.t_project P
  574. where 1=1
  575. <if test="isOnchain != null and isOnchain">
  576. AND on_chain_num > 0
  577. </if>
  578. ) as t_out
  579. <where>
  580. <if test="keyWords != null and keyWords.size() > 0">
  581. regexp_like(t_out.name,
  582. REGEXP_REPLACE(
  583. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  584. , '[\r\n\s]+', '', 'g')
  585. , 'i')
  586. OR
  587. regexp_like(t_out.code,
  588. REGEXP_REPLACE(
  589. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  590. , '[\r\n\s]+', '', 'g')
  591. , 'i')
  592. OR
  593. regexp_like(t_out.company,
  594. REGEXP_REPLACE(
  595. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  596. , '[\r\n\s]+', '', 'g')
  597. , 'i')
  598. OR
  599. regexp_like(t_out.hbcrfapfwh,
  600. REGEXP_REPLACE(
  601. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  602. , '[\r\n\s]+', '', 'g')
  603. , 'i')
  604. OR
  605. regexp_like(t_out.hbcrhtbh,
  606. REGEXP_REPLACE(
  607. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  608. , '[\r\n\s]+', '', 'g')
  609. , 'i')
  610. OR
  611. regexp_like(t_out.dzjgh,
  612. REGEXP_REPLACE(
  613. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  614. , '[\r\n\s]+', '', 'g')
  615. , 'i')
  616. </if>
  617. </where>
  618. </if>
  619. <if test="filterType==0">
  620. UNION
  621. </if>
  622. <if test="filterType==0 or filterType==2">
  623. SELECT
  624. project."id" AS ID,
  625. project."name" AS NAME,
  626. project."code" AS code,
  627. project."company" AS company,
  628. project."created_at" AS createAt,
  629. project."updated_at" AS updateAt,
  630. project."project_type" AS projectType,
  631. project."on_chain_num" AS onChainNum,
  632. project."creator_id" AS creatorId,
  633. project."updated_at" AS updatedAt,
  634. '2' AS selectType,
  635. info.ID AS attachmentId,
  636. info.node_id AS nodeId,
  637. info.file_name AS fileName,
  638. info.file_path AS filePath,
  639. '' AS resourceCode,
  640. '' AS zl,
  641. '' AS area
  642. FROM PUBLIC.t_project_attachment_info info
  643. LEFT JOIN t_project project on info.project_id=project.id
  644. <where>
  645. <if test="keyWords != null and keyWords.size() > 0">
  646. regexp_like(info.file_name,
  647. REGEXP_REPLACE(
  648. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  649. , '[\r\n\s]+', '', 'g')
  650. , 'i')
  651. </if>
  652. AND project.id is not null
  653. <if test="isOnchain != null and isOnchain">
  654. AND on_chain_num > 0
  655. </if>
  656. </where>
  657. </if>
  658. <if test="filterType==0">
  659. UNION
  660. </if>
  661. <if test="filterType==0 or filterType==3">
  662. SELECT
  663. project."id" AS ID,
  664. project."name" AS NAME,
  665. project."code" AS code,
  666. project."company" AS company,
  667. project."created_at" AS createAt,
  668. project."updated_at" AS updateAt,
  669. project."project_type" AS projectType,
  670. project."on_chain_num" AS onChainNum,
  671. project."creator_id" AS creatorId,
  672. project."updated_at" AS updatedAt,
  673. '3' AS selectType,
  674. '' AS attachmentId,
  675. '' AS nodeId ,
  676. '' AS fileName,
  677. '' AS filePath,
  678. (code.resource_immobile_code) AS resourceCode,
  679. details.zl AS zl,
  680. CAST(ROUND(details.geom_area, 2) AS VARCHAR) AS area
  681. FROM
  682. (SELECT DISTINCT ON (project_id)
  683. project_id,
  684. land_code,
  685. code.resource_immobile_code,
  686. code.resource_business_code,
  687. code.resource_project_code
  688. FROM public.t_land_one_code code
  689. ORDER BY project_id) code
  690. LEFT JOIN "public"."t_node_land" node on code.land_code =node.id
  691. LEFT JOIN "public"."t_geom_db_details" details on node.geom_db_id =details.upload_id
  692. LEFT JOIN "public"."t_project" project on code.project_id =project.id
  693. <where>
  694. <if test="keyWords != null and keyWords.size() > 0">
  695. regexp_like((code.resource_immobile_code || code.resource_business_code || code.resource_project_code),
  696. REGEXP_REPLACE(
  697. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  698. , '[\r\n\s]+', '', 'g')
  699. , 'i')
  700. </if>
  701. AND project.id is not null
  702. <if test="isOnchain != null and isOnchain">
  703. AND on_chain_num > 0
  704. </if>
  705. </where>
  706. </if>
  707. ) AS distinct_projects
  708. </select>
  709. <select id="getSearchProjectCount" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
  710. SELECT COUNT(*)
  711. FROM (
  712. SELECT
  713. "id" AS ID,
  714. "name" AS NAME,
  715. "code" AS code,
  716. "company" AS company,
  717. "created_at" AS createAt,
  718. "updated_at" AS updateAt,
  719. "project_type" AS projectType,
  720. "on_chain_num" AS onChainNum,
  721. "creator_id" AS creatorId,
  722. "updated_at" AS updatedAt,
  723. '1' AS selectType,
  724. '' AS attachmentId,
  725. '' AS nodeId,
  726. '' AS fileName,
  727. '' AS filePath,
  728. '' AS resourceCode,
  729. '' AS zl,
  730. '' AS area
  731. from (
  732. SELECT P.*,
  733. (SELECT hbcrfapfwh FROM "public"."t_tdgy" WHERE project_id = P.id) hbcrfapfwh,
  734. (SELECT hbcrhtbh FROM "public"."t_tdgy" WHERE project_id = P.id) hbcrhtbh,
  735. (SELECT dzjgh FROM "public"."t_tdgy" WHERE project_id = P.id) dzjgh
  736. FROM PUBLIC.t_project P
  737. where 1=1
  738. <if test="isOnchain != null and isOnchain">
  739. AND on_chain_num > 0
  740. </if>
  741. ) as t_out
  742. <where>
  743. <if test="keyWords != null and keyWords.size() > 0">
  744. regexp_like(t_out.name,
  745. REGEXP_REPLACE(
  746. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  747. , '[\r\n\s]+', '', 'g')
  748. , 'i')
  749. OR
  750. regexp_like(t_out.code,
  751. REGEXP_REPLACE(
  752. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  753. , '[\r\n\s]+', '', 'g')
  754. , 'i')
  755. OR
  756. regexp_like(t_out.company,
  757. REGEXP_REPLACE(
  758. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  759. , '[\r\n\s]+', '', 'g')
  760. , 'i')
  761. OR
  762. regexp_like(t_out.hbcrfapfwh,
  763. REGEXP_REPLACE(
  764. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  765. , '[\r\n\s]+', '', 'g')
  766. , 'i')
  767. OR
  768. regexp_like(t_out.hbcrhtbh,
  769. REGEXP_REPLACE(
  770. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  771. , '[\r\n\s]+', '', 'g')
  772. , 'i')
  773. OR
  774. regexp_like(t_out.dzjgh,
  775. REGEXP_REPLACE(
  776. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  777. , '[\r\n\s]+', '', 'g')
  778. , 'i')
  779. </if>
  780. </where>
  781. ) AS distinct_projects
  782. </select>
  783. <select id="getSearchAttachmentCount" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
  784. SELECT COUNT(*)
  785. FROM (
  786. SELECT
  787. project."id" AS ID,
  788. project."name" AS NAME,
  789. project."code" AS code,
  790. project."company" AS company,
  791. project."created_at" AS createAt,
  792. project."updated_at" AS updateAt,
  793. project."project_type" AS projectType,
  794. project."on_chain_num" AS onChainNum,
  795. project."creator_id" AS creatorId,
  796. project."updated_at" AS updatedAt,
  797. '2' AS selectType,
  798. info.ID AS attachmentId,
  799. info.node_id AS nodeId,
  800. info.file_name AS fileName,
  801. info.file_path AS filePath
  802. FROM PUBLIC.t_project_attachment_info info
  803. LEFT JOIN t_project project on info.project_id=project.id
  804. <where>
  805. <if test="keyWords != null and keyWords.size() > 0">
  806. regexp_like(info.file_name,
  807. REGEXP_REPLACE(
  808. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  809. , '[\r\n\s]+', '', 'g')
  810. , 'i')
  811. </if>
  812. AND project.id is not null
  813. <if test="isOnchain != null and isOnchain">
  814. AND on_chain_num > 0
  815. </if>
  816. </where>
  817. ) AS distinct_projects
  818. </select>
  819. <select id="getSearchGraphicLayerCount" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
  820. SELECT COUNT(*)
  821. FROM (
  822. SELECT
  823. project."id" AS ID,
  824. project."name" AS NAME,
  825. project."code" AS code,
  826. project."company" AS company,
  827. project."created_at" AS createAt,
  828. project."updated_at" AS updateAt,
  829. project."project_type" AS projectType,
  830. project."on_chain_num" AS onChainNum,
  831. project."creator_id" AS creatorId,
  832. project."updated_at" AS updatedAt,
  833. '3' AS selectType,
  834. '' AS attachmentId,
  835. '' AS nodeId,
  836. '' AS fileName,
  837. '' AS filePath,
  838. (code.resource_immobile_code) AS resourceCode,
  839. details.zl AS zl,
  840. CAST(ROUND(details.geom_area, 2) AS VARCHAR) AS area
  841. FROM
  842. (SELECT DISTINCT ON (project_id)
  843. project_id,
  844. land_code,
  845. code.resource_immobile_code,
  846. code.resource_business_code,
  847. code.resource_project_code
  848. FROM public.t_land_one_code code
  849. ORDER BY project_id) code
  850. LEFT JOIN "public"."t_node_land" node on code.land_code =node.id
  851. LEFT JOIN "public"."t_geom_db_details" details on node.geom_db_id =details.upload_id
  852. LEFT JOIN "public"."t_project" project on code.project_id =project.id
  853. <where>
  854. <if test="keyWords != null and keyWords.size() > 0">
  855. regexp_like((code.resource_immobile_code || code.resource_business_code || code.resource_project_code),
  856. REGEXP_REPLACE(
  857. <foreach collection="keyWords" item="word" open="'(" separator="|" close=")'" >${word}</foreach>
  858. , '[\r\n\s]+', '', 'g')
  859. , 'i')
  860. </if>
  861. AND project.id is not null
  862. <if test="isOnchain != null and isOnchain">
  863. AND on_chain_num > 0
  864. </if>
  865. </where>
  866. ) AS distinct_projects
  867. </select>
  868. <delete id="deleteNodeByTable">
  869. DELETE FROM ${tableName}
  870. WHERE id = #{nodeId}
  871. </delete>
  872. <select id="getNodeSourceIdByTable" resultType="string" >
  873. SELECT source_id FROM ${tableName}
  874. WHERE id = #{nodeId}
  875. </select>
  876. <!-- 1.查询项目代码存在的所有项目,并且工程建设环节无新增数据的条数。2.查询当前环节已经新增数据但是未上链并且未同步过的数据(source_id-同步数据id)) -->
  877. <select id="getZrzysiteProjectList" resultMap="projectMap">
  878. SELECT p.id,p.name,p.code ,p.project_type, '1' as creator_id
  879. from "public"."t_project" p LEFT JOIN "public"."t_project_workflow" w on p.id = w.project_id and w.node_table_name=#{tableName}
  880. where LENGTH(TRIM(p.code))>0 and w.id is null
  881. union
  882. SELECT DISTINCT p.id,p.name,p.code ,p.project_type ,'2' as creator_id
  883. from "public"."t_project" p LEFT JOIN "public".${tableName} node on p.id=node.project_id
  884. where LENGTH(TRIM(p.code))>0 and node.has_onchain=false and node.source_id is null
  885. </select>
  886. <!-- 1.查询不动产单元号未赋值的,没有与不动产交互的。2.前置阶段已经上链的-->
  887. <select id="getTdyProjectList" resultType="map">
  888. SELECT
  889. pro."id" as xmbh,
  890. pro."name" as xmmc,
  891. pro."code" as xmdm,
  892. td.srf as srf,
  893. td.tdyt as tdyt,
  894. td.jswz as jswz,
  895. td.gd_area as gdmj,
  896. td.gd_unit as mjdw,
  897. td.gd_type as gdfs,
  898. td.has_zz as bzzt,
  899. td.hbcrhtbh as hbcrhtbh,
  900. td.hbcrht_date as hbcrhtrq,
  901. COALESCE((SELECT immobile.pre_assign_code
  902. FROM t_project_immobile_code immobile
  903. WHERE immobile.project_id = pro.id
  904. AND immobile.valid_flag = 1
  905. AND immobile.pre_assign_code IS NOT NULL
  906. LIMIT 1),'') as yfbdcdyh,
  907. (SELECT array_to_string(array_agg(ST_AsEWKT(gd.geom)), '|')
  908. FROM t_node_land nl
  909. LEFT JOIN t_geom_db_details gd ON nl.geom_db_id = gd.upload_id
  910. WHERE nl.node_id = td.id
  911. AND gd.geom IS NOT NULL) as geom
  912. FROM "t_tdgy" td
  913. LEFT JOIN "t_project" pro ON td.project_id = pro."id"
  914. WHERE td.has_onchain = 't'
  915. AND pro."id" IS NOT NULL
  916. AND NOT EXISTS (
  917. SELECT 1 FROM t_project_immobile_code immobile2
  918. WHERE immobile2.project_id = pro.id
  919. AND immobile2.valid_flag = 1
  920. AND immobile2.code IS NOT NULL
  921. )
  922. <trim prefix="AND (" suffix=")" prefixOverrides="OR">
  923. <if test="xmmc != null and xmmc != ''">
  924. OR pro."name" LIKE '%' || #{xmmc} || '%'
  925. </if>
  926. <if test="xmdm != null and xmdm != ''">
  927. OR pro."code" LIKE '%' || #{xmdm} || '%'
  928. </if>
  929. <if test="srf != null and srf != ''">
  930. OR td.srf LIKE '%' || #{srf} || '%'
  931. </if>
  932. <if test="yfbdcdyh != null and yfbdcdyh != ''">
  933. OR EXISTS (
  934. SELECT 1 FROM t_project_immobile_code immobile3
  935. WHERE immobile3.project_id = pro.id
  936. AND immobile3.valid_flag = 1
  937. AND immobile3.pre_assign_code LIKE '%' || #{yfbdcdyh} || '%'
  938. )
  939. </if>
  940. <if test="ewkt != null and ewkt != ''">
  941. OR EXISTS (
  942. SELECT 1
  943. FROM t_node_land nl2
  944. LEFT JOIN t_geom_db_details gd2 ON nl2.geom_db_id = gd2.upload_id
  945. WHERE nl2.node_id = td.id
  946. AND gd2.geom IS NOT NULL
  947. AND public.ST_Intersects(gd2.geom, public.ST_GeomFromEWKT(#{ewkt}))
  948. )
  949. </if>
  950. </trim>
  951. </select>
  952. </mapper>