ProjectMapper.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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="name" property="name"/>
  7. <result column="createDate" property="createDate"/>
  8. <result column="organizationId" property="organizationId"/>
  9. <result column="address" property="address"/>
  10. <result column="picture" property="picture"/>
  11. <result column="tagIds" property="tagIds"/>
  12. <result column="comment" property="comment"/>
  13. <result column="data" property="data"/>
  14. </resultMap>
  15. <resultMap type="com.bosshand.virgo.api.model.Project" id="projectResult">
  16. <id column="id" property="id"/>
  17. <result column="name" property="name"/>
  18. <result column="createDate" property="createDate"/>
  19. <result column="organizationId" property="organizationId"/>
  20. <result column="address" property="address"/>
  21. <result column="picture" property="picture"/>
  22. <result column="tagIds" property="tagIds"/>
  23. <result column="comment" property="comment"/>
  24. <result column="data" property="data"/>
  25. <collection property="projectItemList" ofType="com.bosshand.virgo.api.model.ProjectItem" resultMap="com.bosshand.virgo.api.dao.ProjectItemDao.projectItemResult" columnPrefix="projectItem_"/>
  26. </resultMap>
  27. <sql id="ProjectQuery">
  28. SELECT
  29. p.*,
  30. pi.id as projectItem_id,
  31. pi.name as projectItem_name,
  32. pi.createDate as projectItem_createDate,
  33. pi.area as projectItem_area,
  34. pi.address as projectItem_address,
  35. pi.picture as projectItem_picture,
  36. pi.propertyCertificateNumber as projectItem_propertyCertificateNumber,
  37. pi.tagIds as projectItem_tagIds,
  38. pi.data as projectItem_data
  39. FROM project p
  40. left join project_item pi on p.id = pi.projectId
  41. </sql>
  42. <select id="getProject" resultMap="result">
  43. SELECT * FROM project WHERE id=#{id}
  44. </select>
  45. <select id="get" resultMap="projectResult">
  46. <include refid="ProjectQuery"/>
  47. where p.deleteState = 0 and p.id=#{id}
  48. </select>
  49. <select id="getProjectByOrganizationId" resultMap="result">
  50. select * from project where deleteState = 0 and organizationId = #{organizationId}
  51. </select>
  52. <insert id="insert" parameterType="com.bosshand.virgo.api.model.Project" useGeneratedKeys="true" keyProperty="id">
  53. INSERT INTO project(`name`, `createDate`, `organizationId`, `address`, `picture`, `tagIds`, `comment`, `data`)
  54. VALUES (#{name}, now(), #{organizationId}, #{address}, #{picture}, #{tagIds}, #{comment}, #{data})
  55. </insert>
  56. <update id="delete">
  57. UPDATE project SET deleteState = 1 WHERE id=#{id}
  58. </update>
  59. <update id="update" parameterType="com.bosshand.virgo.api.model.Project">
  60. UPDATE project
  61. <trim prefix="set" suffixOverrides=",">
  62. <if test="name!=null">name=#{name},</if>
  63. <if test="createDate!=null">createDate=#{createDate},</if>
  64. <if test="organizationId!=0">organizationId=#{organizationId},</if>
  65. <if test="address!=null">address=#{address},</if>
  66. <if test="picture!=null">picture=#{picture},</if>
  67. <if test="tagIds!=null">tagIds=#{tagIds},</if>
  68. <if test="comment!=null">comment=#{comment},</if>
  69. <if test="data!=null">data=#{data},</if>
  70. </trim>
  71. WHERE id=#{id}
  72. </update>
  73. <select id="getTotalCount" parameterType="com.bosshand.virgo.api.model.Project" resultType="Integer">
  74. SELECT count(*) FROM project
  75. <where>
  76. and deleteState = 0
  77. <if test="organizationId != 0">and organizationId = #{organizationId}</if>
  78. <if test="tagIds != null">and
  79. <foreach item="tagId" collection="tagIds.split(',')" open="(" separator=" and " close=")">
  80. FIND_IN_SET (#{tagId}, tagIds)
  81. </foreach>
  82. </if>
  83. <if test="name != null and name !=''">and name = #{name}</if>
  84. <if test="createDate != null and createDate !=''">and createDate = #{createDate}</if>
  85. </where>
  86. </select>
  87. <select id="getLimit" resultMap="result">
  88. SELECT * FROM project
  89. <where>
  90. and deleteState = 0
  91. <if test="p.organizationId!=0">and organizationId=#{p.organizationId}</if>
  92. <if test="p.tagIds != null">and
  93. <foreach item="tagId" collection="p.tagIds.split(',')" open="(" separator=" and " close=")">
  94. FIND_IN_SET (#{tagId}, tagIds)
  95. </foreach>
  96. </if>
  97. <if test="p.name!=null">and name=#{p.name}</if>
  98. <if test="p.createDate!=null and p.createDate !=''">and createDate = #{p.createDate}</if>
  99. </where>
  100. limit #{currIndex} , #{pageSize}
  101. </select>
  102. </mapper>