YdbpMapper.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.YdbpMapper">
  6. <!-- ResultMap 映射 -->
  7. <resultMap id="YdbpResultMap" type="com.siwei.apply.domain.Ydbp">
  8. <id property="id" column="id"/>
  9. <result property="projectId" column="project_id"/>
  10. <result property="tdyt" column="tdyt"/>
  11. <result property="ydArea" column="yd_area"/>
  12. <result property="ydUnit" column="yd_unit"/>
  13. <result property="zsArea" column="zs_area"/>
  14. <result property="zsUnit" column="zs_unit"/>
  15. <result property="hasZz" column="has_zz"/>
  16. <result property="bpDate" column="bp_date"/>
  17. <result property="pfwh" column="pfwh"/>
  18. <result property="pfDate" column="pf_date"/>
  19. <result property="hasOnchain" column="has_onchain"/>
  20. <result property="creatorId" column="creator_id"/>
  21. <result property="createdAt" column="created_at"/>
  22. <result property="updatedAt" column="updated_at"/>
  23. </resultMap>
  24. <select id="isExit" resultType="Boolean">
  25. SELECT COUNT(1) > 0
  26. FROM t_ydbp
  27. WHERE project_id = #{projectId}
  28. </select>
  29. <!-- 插入语句 -->
  30. <insert id="add" parameterType="com.siwei.apply.domain.Ydbp">
  31. INSERT INTO t_ydbp (id, project_id, tdyt, yd_area, yd_unit, zs_area, zs_unit, has_zz,
  32. bp_date, pfwh, pf_date, has_onchain, creator_id, created_at, updated_at)
  33. VALUES (#{id}, #{projectId}, #{tdyt}, #{ydArea}, #{ydUnit}, #{zsArea}, #{zsUnit}, #{hasZz},
  34. #{bpDate}, #{pfwh}, #{pfDate}, false, #{creatorId}, now(), now())
  35. </insert>
  36. <!-- 查询语句 -->
  37. <select id="get" resultMap="YdbpResultMap">
  38. SELECT *
  39. FROM t_ydbp
  40. WHERE project_id = #{projectId}
  41. </select>
  42. <!-- 新增:根据主键id获取记录 -->
  43. <select id="getById" resultMap="YdbpResultMap">
  44. SELECT *
  45. FROM t_ydbp
  46. WHERE id = #{id}
  47. </select>
  48. <select id="getStatisticsList" resultType="map">
  49. SELECT
  50. bp.id AS id,
  51. pro.ID AS project_id,
  52. pro.name AS project_name,
  53. '1' AS batch_type,
  54. COALESCE (
  55. CASE
  56. WHEN bp.yd_unit = '平方米' THEN
  57. COALESCE ( bp.yd_area, 0 ) / 666.6666667
  58. WHEN bp.yd_unit = '公顷' THEN
  59. COALESCE ( bp.yd_area, 0 ) * 15
  60. WHEN bp.yd_unit = '亩' THEN
  61. COALESCE ( bp.yd_area, 0 ) * 1
  62. END,
  63. 0
  64. ) AS yd_area, -- 用地面积(亩)
  65. bp.bp_date,
  66. bp.pfwh,
  67. bp.pf_date,
  68. left(bp.pf_date,4) AS nf,
  69. '亩' as yd_unit,
  70. '亩' as zs_unit,
  71. <if test="hasGeom != null and hasGeom">
  72. COALESCE((
  73. SELECT ST_AsEWKT(ST_Union(gd.geom))
  74. FROM t_node_land nl
  75. LEFT JOIN t_geom_db_details gd ON nl.geom_db_id = gd.upload_id
  76. WHERE nl.node_id = bp.id AND gd.geom IS NOT NULL
  77. ), '') AS geom,
  78. </if>
  79. COALESCE (
  80. CASE
  81. WHEN bp.zs_unit = '平方米' THEN
  82. COALESCE ( bp.zs_area, 0 ) / 666.6666667
  83. WHEN bp.zs_unit = '公顷' THEN
  84. COALESCE ( bp.zs_area, 0 ) * 15
  85. WHEN bp.zs_unit = '亩' THEN
  86. COALESCE ( bp.zs_area, 0 ) * 1
  87. END,
  88. 0
  89. ) AS mj_mu
  90. FROM
  91. t_ydbp bp
  92. LEFT JOIN t_project pro ON bp.project_id = pro."id"
  93. WHERE
  94. pro.on_chain_num > 0
  95. AND bp.has_onchain = 't'
  96. <if test="year != null and year != '' ">
  97. AND left(bp.pf_date,4) = #{year}
  98. </if>
  99. <if test="keyWord != null and keyWord != ''">
  100. AND (
  101. COALESCE(pro.name, '') LIKE CONCAT('%', #{keyWord}, '%')
  102. OR COALESCE(pro.company, '') LIKE CONCAT('%', #{keyWord}, '%')
  103. )
  104. </if>
  105. </select>
  106. <!-- 更新语句 -->
  107. <update id="update" parameterType="com.siwei.apply.domain.vo.YdbpUpdateVo">
  108. UPDATE t_ydbp
  109. <set>
  110. <if test="projectId != null">project_id = #{projectId},</if>
  111. <if test="tdyt != null">tdyt = #{tdyt},</if>
  112. <if test="ydArea != null">yd_area = #{ydArea},</if>
  113. <if test="ydUnit != null">yd_unit = #{ydUnit},</if>
  114. <if test="zsArea != null">zs_area = #{zsArea},</if>
  115. <if test="zsUnit != null">zs_unit = #{zsUnit},</if>
  116. <if test="hasZz != null">has_zz = #{hasZz},</if>
  117. <if test="bpDate != null">bp_date = #{bpDate},</if>
  118. <if test="pfwh != null">pfwh = #{pfwh},</if>
  119. <if test="pfDate != null">pf_date = #{pfDate},</if>
  120. <if test="hasOnchain != null">has_onchain = #{hasOnchain},</if>
  121. updated_at = now()
  122. </set>
  123. WHERE id = #{id}
  124. </update>
  125. <update id="updateHasOnchain">
  126. UPDATE t_ydbp
  127. SET has_onchain = #{hasOnchain}, updated_at = now()
  128. WHERE id = #{id}
  129. </update>
  130. </mapper>