ProjectMapper.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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="creator_id" property="creatorId"/>
  15. </resultMap>
  16. <insert id="add" parameterType="com.siwei.apply.domain.Project">
  17. INSERT INTO t_project (id, name, code, company,
  18. created_at, updated_at, project_type, creator_id)
  19. VALUES (#{id}, #{name}, #{code}, #{company}, now(), now(), #{projectType},
  20. #{creatorId})
  21. </insert>
  22. <select id="get" resultMap="projectMap">
  23. SELECT *
  24. FROM t_project
  25. where t_project.id = #{id}
  26. </select>
  27. <select id="getList" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultMap="projectMap">
  28. SELECT *
  29. FROM t_project
  30. <where>
  31. <if test="name != null and name != ''">
  32. AND name LIKE CONCAT('%', #{name}, '%')
  33. </if>
  34. <if test="code != null and code != ''">
  35. AND code LIKE CONCAT('%', #{code}, '%')
  36. </if>
  37. <if test="keyWord != null and keyWord != ''">
  38. AND (
  39. name LIKE CONCAT('%', #{keyWord}, '%')
  40. OR company LIKE CONCAT('%', #{keyWord}, '%')
  41. )
  42. </if>
  43. <if test="projectType != null and projectType != 0">
  44. AND project_type = #{projectType}
  45. </if>
  46. </where>
  47. ORDER BY updated_at DESC
  48. LIMIT #{pageSize} offset #{offset}
  49. </select>
  50. <select id="getCount" parameterType="com.siwei.apply.domain.vo.ProjectFilterVo" resultType="int">
  51. SELECT COUNT(*)
  52. FROM t_project
  53. <where>
  54. <if test="name != null and name != ''">
  55. AND name LIKE CONCAT('%', #{name}, '%')
  56. </if>
  57. <if test="code != null and code != ''">
  58. AND code LIKE CONCAT('%', #{code}, '%')
  59. </if>
  60. <if test="keyWord != null and keyWord != ''">
  61. AND (
  62. name LIKE CONCAT('%', #{keyWord}, '%')
  63. OR company LIKE CONCAT('%', #{keyWord}, '%')
  64. )
  65. </if>
  66. <if test="projectType != null and projectType != 0">
  67. AND project_type = #{projectType}
  68. </if>
  69. </where>
  70. </select>
  71. <update id="update" parameterType="com.siwei.apply.domain.vo.ProjectUpdateVo">
  72. UPDATE t_project
  73. <set>
  74. <if test="name != null">name = #{name},</if>
  75. <if test="code != null">code = #{code},</if>
  76. <if test="company != null">company = #{company},</if>
  77. <if test="projectType != null">project_type = #{projectType},</if>
  78. updated_at = now()
  79. </set>
  80. WHERE id = #{id}
  81. </update>
  82. <delete id="batchDelete">
  83. DELETE FROM t_project
  84. WHERE id IN
  85. <foreach collection="ids" item="id" open="(" separator="," close=")">
  86. #{id}
  87. </foreach>
  88. </delete>
  89. <select id="getProjectTypeById" parameterType="string" resultType="int">
  90. SELECT project_type
  91. FROM t_project
  92. WHERE id = #{id}
  93. </select>
  94. <!-- 单一方法:一次返回 1/2 和总数的统计结果 -->
  95. <select id="countTypeStats" resultType="com.siwei.apply.domain.res.ProjectNumRes">
  96. SELECT
  97. SUM(CASE WHEN project_type = 1 THEN 1 ELSE 0 END) AS singleCount,
  98. SUM(CASE WHEN project_type = 2 THEN 1 ELSE 0 END) AS batchCount,
  99. COUNT(*) AS total
  100. FROM t_project
  101. </select>
  102. <select id="selectOtherSupply" resultType="com.siwei.apply.domain.res.ProjectSupplyRes">
  103. SELECT
  104. '其他' AS gdType,
  105. '亩' AS gdUnit,
  106. CAST(0 AS double precision) AS gdArea,
  107. CAST(0 AS int) AS count
  108. </select>
  109. <select id="selectOtherSupplyExcludeProject" resultType="com.siwei.apply.domain.res.ProjectSupplyRes">
  110. SELECT
  111. '其他' AS gdType,
  112. '亩' AS gdUnit,
  113. COALESCE(
  114. SUM(
  115. CASE
  116. WHEN gd_unit = '0' THEN COALESCE(gd_area, 0) / 666.6666667
  117. WHEN gd_unit = '1' THEN COALESCE(gd_area, 0) * 15
  118. ELSE COALESCE(gd_area, 0)
  119. END
  120. ), 0
  121. ) AS gdArea,
  122. COUNT(*) AS count
  123. FROM t_tdgy
  124. WHERE project_id IS NULL OR project_id = ''
  125. </select>
  126. <!-- 根据节点获取项目信息-->
  127. <select id="getProjectByNodeId" resultMap="projectMap">
  128. SELECT project.* FROM "public"."t_project" project
  129. LEFT JOIN "public"."t_project_workflow" flow
  130. on flow.project_id=project.id
  131. WHERE flow.node_id = #{nodeId} LIMIT 1
  132. </select>
  133. </mapper>