ProjectMapper.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.bosshand.virgo.api.dao.ProjectDao">
  4. <resultMap type="com.bosshand.virgo.api.model.Project" id="result">
  5. <id column="id" property="id"/>
  6. <result column="generateWeeklyDate" property="generateWeeklyDate"/>
  7. <result column="type" property="type"/>
  8. <result column="name" property="name"/>
  9. <result column="createDate" property="createDate"/>
  10. <result column="organizationId" property="organizationId"/>
  11. <result column="organizationName" property="organizationName"/>
  12. <result column="address" property="address"/>
  13. <result column="addressCode" property="addressCode"/>
  14. <result column="picture" property="picture"/>
  15. <result column="tagIds" property="tagIds"/>
  16. <result column="comment" property="comment"/>
  17. <result column="coordinates" property="coordinates"/>
  18. <result column="supportingFacilities" property="supportingFacilities"/>
  19. <result column="data" property="data"/>
  20. </resultMap>
  21. <resultMap type="com.bosshand.virgo.api.model.Project" id="projectResult">
  22. <id column="id" property="id"/>
  23. <result column="generateWeeklyDate" property="generateWeeklyDate"/>
  24. <result column="type" property="type"/>
  25. <result column="name" property="name"/>
  26. <result column="createDate" property="createDate"/>
  27. <result column="organizationId" property="organizationId"/>
  28. <result column="address" property="address"/>
  29. <result column="addressCode" property="addressCode"/>
  30. <result column="picture" property="picture"/>
  31. <result column="tagIds" property="tagIds"/>
  32. <result column="comment" property="comment"/>
  33. <result column="coordinates" property="coordinates"/>
  34. <result column="supportingFacilities" property="supportingFacilities"/>
  35. <result column="data" property="data"/>
  36. <collection property="projectItemList" ofType="com.bosshand.virgo.api.model.ProjectItem" resultMap="com.bosshand.virgo.api.dao.ProjectItemDao.projectItemResult" columnPrefix="projectItem_"/>
  37. </resultMap>
  38. <sql id="ProjectQuery">
  39. SELECT
  40. p.*,
  41. pi.id as projectItem_id,
  42. pi.name as projectItem_name,
  43. pi.createDate as projectItem_createDate,
  44. pi.area as projectItem_area,
  45. pi.address as projectItem_address,
  46. pi.picture as projectItem_picture,
  47. pi.propertyCertificateNumber as projectItem_propertyCertificateNumber,
  48. pi.tagIds as projectItem_tagIds,
  49. pi.data as projectItem_data
  50. FROM project p
  51. left join project_item pi on p.id = pi.projectId
  52. </sql>
  53. <select id="fuzzyName" resultMap="result">
  54. SELECT a.*, b.name as organizationName FROM project a LEFT JOIN mgr_organization b ON a.organizationId = b.id
  55. <where>
  56. and a.deleteState = 0
  57. <if test="tagIds != null">and
  58. <foreach item="tagId" collection="tagIds.split(',')" open="(" separator=" or " close=")">
  59. FIND_IN_SET (#{tagId}, a.tagIds)
  60. </foreach>
  61. </if>
  62. <if test="name!=null">and a.name LIKE CONCAT('%', #{name}, '%')</if>
  63. </where>
  64. </select>
  65. <select id="getProject" resultMap="result">
  66. SELECT a.*, b.name as organizationName FROM project a LEFT JOIN mgr_organization b ON a.organizationId = b.id WHERE a.id=#{id}
  67. </select>
  68. <select id="getAll" resultMap="result">
  69. SELECT a.*, b.name as organizationName FROM project a LEFT JOIN mgr_organization b ON a.organizationId = b.id where deleteState = 0
  70. </select>
  71. <select id="getIds" resultMap="result">
  72. SELECT a.*, b.name as organizationName FROM project a LEFT JOIN mgr_organization b ON a.organizationId = b.id where a.id in
  73. <foreach collection="list" open="(" separator="," close=")" item="id">
  74. #{id}
  75. </foreach>
  76. </select>
  77. <select id="get" resultMap="projectResult">
  78. <include refid="ProjectQuery"/>
  79. where p.deleteState = 0 and p.id=#{id}
  80. </select>
  81. <select id="getProjectByOrganizationId" resultMap="result">
  82. SELECT a.*, b.name as organizationName FROM project a LEFT JOIN mgr_organization b ON a.organizationId = b.id
  83. where deleteState = 0 and a.organizationId = #{organizationId}
  84. </select>
  85. <insert id="insert" parameterType="com.bosshand.virgo.api.model.Project" useGeneratedKeys="true" keyProperty="id">
  86. INSERT INTO project(`generateWeeklyDate`, `type`, `name`, `createDate`, `organizationId`, `address`, `addressCode`, `picture`, `tagIds`, `comment`, `coordinates`, `supportingFacilities`, `data`)
  87. VALUES (#{generateWeeklyDate}, #{type}, #{name}, now(), #{organizationId}, #{address}, #{addressCode}, #{picture}, #{tagIds}, #{comment}, #{coordinates}, #{supportingFacilities}, #{data})
  88. </insert>
  89. <update id="delete">
  90. UPDATE project SET deleteState = 1 WHERE id=#{id}
  91. </update>
  92. <update id="update" parameterType="com.bosshand.virgo.api.model.Project">
  93. UPDATE project
  94. <trim prefix="set" suffixOverrides=",">
  95. <if test="type!=null">type=#{type},</if>
  96. <if test="name!=null">name=#{name},</if>
  97. <if test="createDate!=null">createDate=#{createDate},</if>
  98. <if test="organizationId!=0">organizationId=#{organizationId},</if>
  99. <if test="address!=null">address=#{address},</if>
  100. <if test="addressCode!=null">addressCode=#{addressCode},</if>
  101. <if test="picture!=null">picture=#{picture},</if>
  102. <if test="tagIds!=null">tagIds=#{tagIds},</if>
  103. <if test="comment!=null">comment=#{comment},</if>
  104. <if test="coordinates!=null">coordinates=#{coordinates},</if>
  105. <if test="supportingFacilities!=null">supportingFacilities=#{supportingFacilities},</if>
  106. <if test="data!=null">data=#{data},</if>
  107. </trim>
  108. WHERE id=#{id}
  109. </update>
  110. <select id="getTotalCount" parameterType="com.bosshand.virgo.api.model.Project" resultType="Integer">
  111. SELECT count(*) FROM project
  112. <where>
  113. and deleteState = 0
  114. <if test="organizationId != 0">and organizationId = #{organizationId}</if>
  115. <if test="tagIds != null">and
  116. <foreach item="tagId" collection="tagIds.split(',')" open="(" separator=" or " close=")">
  117. FIND_IN_SET (#{tagId}, tagIds)
  118. </foreach>
  119. </if>
  120. <if test="type != null">and type = #{type}</if>
  121. <if test="name != null and name !=''">and name = #{name}</if>
  122. <if test="createDate != null and createDate !=''">and createDate = #{createDate}</if>
  123. </where>
  124. </select>
  125. <select id="getLimit" resultMap="result">
  126. SELECT a.*, b.name as organizationName FROM project a LEFT JOIN mgr_organization b ON a.organizationId = b.id
  127. <where>
  128. and a.deleteState = 0
  129. <if test="p.organizationId!=0">and a.organizationId=#{p.organizationId}</if>
  130. <if test="p.tagIds != null">and
  131. <foreach item="tagId" collection="p.tagIds.split(',')" open="(" separator=" or " close=")">
  132. FIND_IN_SET (#{tagId}, a.tagIds)
  133. </foreach>
  134. </if>
  135. <if test="p.type != null">and a.type = #{p.type}</if>
  136. <if test="p.name!=null">and a.name=#{p.name}</if>
  137. <if test="p.createDate!=null and p.createDate !=''">and a.createDate = #{p.createDate}</if>
  138. </where>
  139. limit #{currIndex} , #{pageSize}
  140. </select>
  141. <select id="getAddressCode" resultMap="result">
  142. SELECT id FROM project WHERE addressCode=#{addressCode}
  143. </select>
  144. </mapper>