TaPersonIntentionRecordMapper.xml 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.huiju.estateagents.mapper.TaPersonIntentionRecordMapper">
  4. <select id="selectAll" resultType="com.huiju.estateagents.entity.TaPersonIntentionRecord">
  5. SELECT
  6. *,
  7. tp.phone as phone,
  8. SUM(tpir.intention) as intentionCount
  9. FROM
  10. ta_person_intention_record tpir
  11. LEFT JOIN ta_person tp ON tpir.person_id = tp.person_id
  12. GROUP BY tpir.person_id
  13. </select>
  14. <select id="selectIntentionUser" resultType="map">
  15. SELECT
  16. tpir.person_name as personName,
  17. tp.phone as phone,
  18. tpir.building_name as buildingName,
  19. SUM(tpir.intention) as intention
  20. FROM
  21. ta_person_intention_record tpir
  22. LEFT JOIN ta_person tp on tpir.person_id = tp.person_id
  23. <trim prefix="where" prefixOverrides="and | or">
  24. <if test="buildingId != null and buildingId != ''">
  25. tpir.building_id = #{buildingId}
  26. </if>
  27. <if test="orgId != null">
  28. AND tpir.org_id = #{orgId}
  29. AND tp.org_id = #{orgId}
  30. </if>
  31. <if test="userId != null">
  32. AND tpir.building_id IN ( SELECT t3.building_id FROM ta_person_building t3 WHERE t3.user_id = #{userId} )
  33. </if>
  34. </trim>
  35. GROUP BY
  36. tpir.person_id, tpir.building_id
  37. ORDER BY SUM(tpir.intention) DESC
  38. </select>
  39. </mapper>