YdbpDataMapper.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.YdbpDataMapper">
  6. <resultMap id="YdbpDataResultMap" type="com.siwei.apply.domain.YdbpData">
  7. <id property="id" column="id"/>
  8. <result property="name" column="name"/>
  9. <result property="ydArea" column="yd_area"/>
  10. <result property="ydUnit" column="yd_unit"/>
  11. <result property="zsArea" column="zs_area"/>
  12. <result property="zsUnit" column="zs_unit"/>
  13. <result property="hasZz" column="has_zz"/>
  14. <result property="bpDate" column="bp_date"/>
  15. <result property="pfwh" column="pfwh"/>
  16. <result property="pfDate" column="pf_date"/>
  17. <result property="hasOnchain" column="has_onchain"/>
  18. <result property="creatorId" column="creator_id"/>
  19. <result property="createdAt" column="created_at"/>
  20. <result property="updatedAt" column="updated_at"/>
  21. <result property="batchType" column="batch_type"/>
  22. <result property="projectPropertyId" column="project_property_id"/>
  23. </resultMap>
  24. <insert id="add" parameterType="com.siwei.apply.domain.YdbpData">
  25. INSERT INTO t_ydbp_data (
  26. id, name, yd_area, yd_unit, zs_area, zs_unit, has_zz, bp_date, pfwh, pf_date, creator_id, created_at, updated_at
  27. ) VALUES (
  28. #{id}, #{name}, #{ydArea}, #{ydUnit}, #{zsArea}, #{zsUnit}, #{hasZz}, #{bpDate}, #{pfwh}, #{pfDate}, #{creatorId}, now(), now()
  29. )
  30. </insert>
  31. <select id="getById" parameterType="string" resultMap="YdbpDataResultMap">
  32. SELECT id, name, yd_area, yd_unit, zs_area, zs_unit, has_zz, bp_date, pfwh, pf_date, creator_id, created_at, updated_at,has_onchain
  33. FROM t_ydbp_data
  34. WHERE id = #{id}
  35. </select>
  36. <select id="selectPage" resultMap="YdbpDataResultMap">
  37. SELECT id, name, yd_area, yd_unit, zs_area, zs_unit, has_zz, bp_date, pfwh, pf_date, creator_id, created_at, updated_at
  38. FROM t_ydbp_data
  39. where 1=1
  40. <if test="name != null and name != ''">
  41. AND name LIKE CONCAT('%', #{name}, '%')
  42. </if>
  43. <if test="ids != null and ids.size() > 0">
  44. AND id IN
  45. <foreach collection="ids" item="id" open="(" separator="," close=")">
  46. #{id}
  47. </foreach>
  48. </if>
  49. <if test="shape != null and shape != ''">
  50. AND EXISTS (
  51. SELECT 1
  52. FROM t_node_land nl
  53. JOIN t_geom_db_details gd ON gd.upload_id = nl.geom_db_id
  54. WHERE nl.node_id = t_ydbp_data.id
  55. AND public.ST_Intersects(gd.geom, public.ST_GeomFromEWKT(#{shape}))
  56. )
  57. </if>
  58. ORDER BY updated_at DESC
  59. LIMIT #{pageSize} OFFSET #{offset}
  60. </select>
  61. <update id="update" parameterType="com.siwei.apply.domain.YdbpData">
  62. UPDATE t_ydbp_data
  63. <set>
  64. <if test="name != null">name = #{name},</if>
  65. <if test="ydArea != null">yd_area = #{ydArea},</if>
  66. <if test="ydUnit != null">yd_unit = #{ydUnit},</if>
  67. <if test="zsArea != null">zs_area = #{zsArea},</if>
  68. <if test="zsUnit != null">zs_unit = #{zsUnit},</if>
  69. <if test="hasZz != null">has_zz = #{hasZz},</if>
  70. <if test="bpDate != null">bp_date = #{bpDate},</if>
  71. <if test="pfwh != null">pfwh = #{pfwh},</if>
  72. <if test="pfDate != null">pf_date = #{pfDate},</if>
  73. updated_at = #{updatedAt}
  74. </set>
  75. WHERE id = #{id}
  76. </update>
  77. <select id="countAll" resultType="int">
  78. SELECT COUNT(1)
  79. FROM t_ydbp_data
  80. where 1=1
  81. <if test="name != null and name != ''">
  82. AND name LIKE CONCAT('%', #{name}, '%')
  83. </if>
  84. <if test="ids != null and ids.size() > 0">
  85. AND id IN
  86. <foreach collection="ids" item="id" open="(" separator="," close=")">
  87. #{id}
  88. </foreach>
  89. </if>
  90. <if test="shape != null and shape != ''">
  91. AND EXISTS (
  92. SELECT 1
  93. FROM t_node_land nl
  94. JOIN t_geom_db_details gd ON gd.upload_id = nl.geom_db_id
  95. WHERE nl.node_id = t_ydbp_data.id
  96. AND public.ST_Intersects(gd.geom, public.ST_GeomFromEWKT(#{shape}))
  97. )
  98. </if>
  99. </select>
  100. <delete id="batchDelete">
  101. DELETE FROM t_ydbp_data
  102. WHERE id IN
  103. <foreach collection="ids" item="id" open="(" separator="," close=")">
  104. #{id}
  105. </foreach>
  106. </delete>
  107. <update id="updateHasOnchain">
  108. UPDATE t_ydbp_data
  109. SET has_onchain = #{hasOnchain}, updated_at = now()
  110. WHERE id = #{id}
  111. </update>
  112. <select id="getStatisticsList" resultMap="YdbpDataResultMap">
  113. SELECT
  114. id, name, yd_unit,
  115. '2' AS batch_type,
  116. COALESCE (
  117. CASE
  118. WHEN yd_unit = '平方米' THEN
  119. COALESCE ( yd_area, 0 ) / 666.6666667
  120. WHEN yd_unit = '公顷' THEN
  121. COALESCE ( yd_area, 0 ) * 15
  122. WHEN yd_unit = '亩' THEN
  123. COALESCE ( yd_area, 0 ) * 1
  124. END,
  125. 0
  126. ) AS yd_area ,
  127. COALESCE (
  128. CASE
  129. WHEN zs_unit = '平方米' THEN
  130. COALESCE ( zs_area, 0 ) / 666.6666667
  131. WHEN zs_unit = '公顷' THEN
  132. COALESCE ( zs_area, 0 ) * 15
  133. WHEN zs_unit = '亩' THEN
  134. COALESCE ( zs_area, 0 ) * 1
  135. END,
  136. 0
  137. ) AS zs_area,
  138. <if test="hasGeom != null and hasGeom">
  139. COALESCE((
  140. SELECT ST_AsEWKT(ST_Union(gd.geom))
  141. FROM t_node_land nl
  142. LEFT JOIN t_geom_db_details gd ON nl.geom_db_id = gd.upload_id
  143. WHERE nl.node_id = bp.id AND gd.geom IS NOT NULL
  144. ), '') AS geom,
  145. </if>
  146. -- left(pf_date,4) AS nf,
  147. '亩' as zs_unit,
  148. has_zz, bp_date, pfwh, pf_date, creator_id, created_at, updated_at,has_onchain
  149. FROM t_ydbp_data bp
  150. WHERE bp.has_onchain='t'
  151. <if test="year != null and year != '' ">
  152. AND left(bp.pf_date,4) = #{year}
  153. </if>
  154. <if test="keyWord != null and keyWord != ''">
  155. AND (
  156. COALESCE(bp.name, '') LIKE CONCAT('%', #{keyWord}, '%')
  157. )
  158. </if>
  159. </select>
  160. </mapper>