| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.siwei.apply.mapper.TdgyMapper">
- <resultMap id="BaseResultMap" type="com.siwei.apply.domain.Tdgy">
- <id property="id" column="id"/>
- <result property="projectId" column="project_id"/>
- <result property="srf" column="srf"/>
- <result property="tdyt" column="tdyt"/>
- <result property="jswz" column="jswz"/>
- <result property="gdArea" column="gd_area"/>
- <result property="gdType" column="gd_type"/>
- <result property="hasZz" column="has_zz"/>
- <result property="hbcrfapfwh" column="hbcrfapfwh"/>
- <result property="hbcrhtbh" column="hbcrhtbh"/>
- <result property="hbcrhtDate" column="hbcrht_date"/>
- <result property="hasOnchain" column="has_onchain"/>
- <result property="creatorId" column="creator_id"/>
- <result property="createdAt" column="created_at"/>
- <result property="updatedAt" column="updated_at"/>
- <result property="gdUnit" column="gd_unit"/>
- </resultMap>
- <select id="isExit" resultType="Boolean">
- SELECT COUNT(1) > 0
- FROM t_tdgy
- WHERE project_id = #{projectId}
- </select>
- <!-- 添加记录 -->
- <insert id="add" parameterType="com.siwei.apply.domain.Tdgy">
- INSERT INTO t_tdgy (id, project_id, srf, tdyt, jswz,
- gd_area, gd_type, has_zz, hbcrfapfwh, hbcrhtbh,
- hbcrht_date, gd_unit, has_onchain, creator_id,
- created_at, updated_at)
- VALUES (#{id}, #{projectId}, #{srf}, #{tdyt}, #{jswz},
- #{gdArea}, #{gdType}, #{hasZz}, #{hbcrfapfwh}, #{hbcrhtbh},
- #{hbcrhtDate}, #{gdUnit}, false, #{creatorId},
- now(), now())
- </insert>
- <!-- 根据项目ID获取记录 -->
- <select id="get" resultMap="BaseResultMap" parameterType="String">
- SELECT *
- FROM t_tdgy
- WHERE project_id = #{projectId}
- </select>
- <!-- 新增:根据主键ID获取记录 -->
- <select id="getById" resultMap="BaseResultMap" parameterType="String">
- SELECT *
- FROM t_tdgy
- WHERE id = #{id}
- </select>
- <!-- 更新记录 -->
- <update id="update" parameterType="com.siwei.apply.domain.vo.TdgyUpdateVo">
- UPDATE t_tdgy
- <set>
- <if test="projectId != null">project_id = #{projectId},</if>
- <if test="srf != null">srf = #{srf},</if>
- <if test="tdyt != null">tdyt = #{tdyt},</if>
- <if test="jswz != null">jswz = #{jswz},</if>
- <if test="gdArea != null">gd_area = #{gdArea},</if>
- <if test="gdType != null">gd_type = #{gdType},</if>
- <if test="hasZz != null">has_zz = #{hasZz},</if>
- <if test="hbcrfapfwh != null">hbcrfapfwh = #{hbcrfapfwh},</if>
- <if test="hbcrhtbh != null">hbcrhtbh = #{hbcrhtbh},</if>
- <if test="hbcrhtDate != null">hbcrht_date = #{hbcrhtDate},</if>
- <if test="hasOnchain != null">has_onchain = #{hasOnchain},</if>
- <if test="gdUnit != null">gd_unit = #{gdUnit},</if>
- updated_at = now()
- </set>
- WHERE id = #{id}
- </update>
- <!-- 更新has_onchain字段 -->
- <update id="updateHasOnchain">
- UPDATE t_tdgy
- SET has_onchain = #{hasOnchain}, updated_at = now()
- WHERE id = #{id}
- </update>
- <!-- 按 gd_type 统计数量与面积求和(面积统一换算成“亩”):返回 gdType(空值为“其他”), count, gdArea, gdUnit='亩'
- 当传入 projectType 时,仅统计其对应项目的记录(关联 t_project.project_type) -->
- <select id="countAndSumByGdType" resultType="com.siwei.apply.domain.res.ProjectSupplyRes">
- SELECT
- COALESCE(NULLIF(TRIM(td.gd_type), ''), '其他') AS gdType,
- '亩' AS gdUnit,
- COUNT(*) AS count,
- COALESCE(
- SUM(
- CASE
- WHEN td.gd_unit = '平方米' THEN COALESCE(td.gd_area, 0) / 666.6666667 -- 平方米 -> 亩
- WHEN td.gd_unit = '公顷' THEN COALESCE(td.gd_area, 0) * 15 -- 公顷 -> 亩
- ELSE COALESCE(td.gd_area, 0) -- 默认当作亩(含 '2')
- END
- ), 0
- ) AS gdArea
- FROM (SELECT * from t_tdgy WHERE has_onchain =TRUE ) td
- <where>
- <choose>
- <when test="projectType == null">
- EXISTS (
- SELECT 1 FROM t_project p
- WHERE p.id = td.project_id and p.on_chain_num > 0
- )
- </when>
- <when test="projectType != null">
- EXISTS (
- SELECT 1 FROM t_project p
- WHERE p.id = td.project_id AND p.project_type = #{projectType} and p.on_chain_num > 0
- )
- </when>
- </choose>
- </where>
- GROUP BY COALESCE(NULLIF(TRIM(td.gd_type), ''), '其他')
- </select>
- <!-- 跟年份查询当前土地实际供应情况! -->
- <select id="getListByYear" resultType="com.siwei.apply.domain.res.TdgyStatisticsRes" parameterType="String">
- SELECT
- project.ID AS projectId,
- project.NAME AS xmmc,
- project.company ,
- t_node.ID AS nodeId,
- t_node.tdyt,
- t_node.gd_type AS gyfs,
- t_node.hbcrht_date AS gysj,
- COALESCE (
- CASE
- WHEN t_node.gd_unit = '平方米' THEN
- COALESCE ( t_node.gd_area, 0 ) / 666.6666667-- 平方米 -> 亩
- WHEN t_node.gd_unit = '公顷' THEN
- COALESCE ( t_node.gd_area, 0 ) * 15-- 公顷 -> 亩 ELSE COALESCE ( t_node.gd_area, 0 ) -- 默认当作亩(含 '2')
- END,
- 0
- ) AS mjMu,
- land.geom_db_id as geomDbId,
- details.upload_id as uploadId,
- details.geom_json as geomJson,
- details.sort,
- details.geom_area as geomArea,
- ST_AsEWKT(details.geom) as geom
- FROM
- t_geom_db_details details
- LEFT JOIN t_node_land land ON details.upload_id :: TEXT = land.geom_db_id ::TEXT
- LEFT JOIN t_tdgy t_node ON land.node_id :: TEXT = t_node.ID ::TEXT
- LEFT JOIN t_project project ON project.ID :: TEXT = t_node.project_id :: TEXT
- WHERE
- t_node.has_onchain = TRUE
- AND project.ID IS NOT NULL
- <if test="year != null">
- AND LEFT(t_node.hbcrht_date, 4) = #{year}
- </if>
- <if test="landTypeCode != null">
- AND LEFT(t_node.tdyt,2)=#{landTypeCode}
- </if>
- <if test="startTime != null and startTime != ''">
- AND t_node.hbcrht_date >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND t_node.hbcrht_date <= #{endTime}
- </if>
- LIMIT 41
- </select>
- <!-- 查询当前存量土地实际供应情况! -->
- <select id="getSjgdListByYear" resultType="com.siwei.apply.domain.res.TdgyStatisticsRes" parameterType="String">
- SELECT
- '' AS projectId,
- xmmc AS xmmc,
- srr AS company,
- gid AS nodeId,
- COALESCE ( land.code, '23' ) AS tdyt,
- gyfs,
- qdrq AS gysj,
- ROUND(COALESCE ( gymj, 0 ) / 666.6666667,2) AS mjMu,-- 平方米 -> 亩
- '' AS geomDbId,
- '' AS uploadId,
- '' AS geomJson,
- 0 AS sort,
- shape_area AS geomArea,
- ST_AsEWKT ( geom ) AS geom
- FROM
- vector.gj_gd_data
- LEFT JOIN public.land_type land ON land.NAME = gj_gd_data.tdyt
- WHERE 1=1
- <if test="year != null">
- AND LEFT(CAST(gj_gd_data.qdrq AS VARCHAR), 4) = #{year}
- </if>
- <if test="landTypeCode != null">
- AND LEFT(land.code,2)=#{landTypeCode}
- </if>
- <if test="startTime != null and startTime != ''">
- AND CAST(gj_gd_data.qdrq AS VARCHAR) >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND CAST(gj_gd_data.qdrq AS VARCHAR) <= #{endTime}
- </if>
- LIMIT 41
- </select>
- <select id="getActualProject" resultType="Map" parameterType="String">
- SELECT
- "gid",
- "objectid",
- "xzq_dm",
- "gyfs",
- "nf",
- "dzjgh",
- "hthbbh",
- "qdrq",
- "xmmc",
- "srr",
- "srrlxdh",
- "zdbh",
- "tdzl",
- "tdly",
- "xmzmj",
- "gymj",
- "shape_area",
- ST_AsEWKT ( geom ) AS geom
- FROM
- vector.gj_gd_data
- WHERE 1=1
- <if test="gid != null and gid != ''">
- AND gj_gd_data.gid::varchar = #{gid}
- </if>
- LIMIT 1
- </select>
- </mapper>
|