ContactsMapper.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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.management.platform.mapper.ContactsMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.Contacts">
  6. <id column="id" property="id" />
  7. <result column="company_id" property="companyId" />
  8. <result column="sex" property="sex" />
  9. <result column="name" property="name" />
  10. <result column="custom_id" property="customId" />
  11. <result column="email" property="email" />
  12. <result column="phone" property="phone" />
  13. <result column="owner_id" property="ownerId" />
  14. <result column="creator_id" property="creatorId" />
  15. <result column="address" property="address" />
  16. <result column="remark" property="remark" />
  17. <result column="is_delete" property="isDelete" />
  18. <result column="create_time" property="createTime" />
  19. <result column="position" property="position" />
  20. <result column="plate1" property="plate1" />
  21. <result column="plate2" property="plate2" />
  22. <result column="plate3" property="plate3" />
  23. <result column="plate4" property="plate4" />
  24. <result column="plate5" property="plate5" />
  25. <result column="is_frequent" property="isFrequent"></result>
  26. </resultMap>
  27. <!-- 通用查询结果列 -->
  28. <sql id="Base_Column_List">
  29. id, company_id, sex, name, custom_id, email, phone, owner_id, creator_id, address, remark, is_delete, create_time, position, plate1, plate2, plate3, plate4, plate5, is_frequent
  30. </sql>
  31. <select id="pageContacts" parameterType="java.util.Map" resultType="com.management.platform.entity.vo.ContactsVo">
  32. SELECT c.*, cust.custom_name as customName, own.name as ownerName,u.name as creatorName
  33. FROM contacts c
  34. LEFT JOIN custom cust ON c.custom_id = cust.id
  35. LEFT JOIN user own ON c.owner_id = own.id
  36. LEFT JOIN user u ON c.creator_id = u.id
  37. <where>
  38. <if test="map.isDelete != null ">
  39. AND c.is_delete =#{map.isDelete}
  40. </if>
  41. <if test="map.customName != null and map.customName != ''">
  42. AND cust.custom_name LIKE CONCAT('%', #{map.customName}, '%')
  43. </if>
  44. <if test="map.ownerName != null and map.ownerName != ''">
  45. AND own.name LIKE CONCAT('%', #{map.ownerName}, '%')
  46. </if>
  47. <if test="map.creatorName != null and map.creatorName != ''">
  48. AND own.name LIKE CONCAT('%', #{map.creatorName}, '%')
  49. </if>
  50. <if test="map.customId != null and map.customId != ''">
  51. AND cust.id =#{map.customId}
  52. </if>
  53. <if test="map.ownerId != null and map.ownerId != ''">
  54. AND own.id =#{map.ownerId}
  55. </if>
  56. <if test="map.creatorId != null and map.creatorId != ''">
  57. AND u.id =#{map.creatorId}
  58. </if>
  59. <if test="map.phone != null and map.phone != ''">
  60. AND c.phone LIKE CONCAT('%', #{map.phone}, '%')
  61. </if>
  62. <if test="map.name != null and map.name != ''">
  63. AND c.name LIKE CONCAT('%', #{map.name}, '%')
  64. </if>
  65. <if test="map.email != null and map.email != ''">
  66. AND c.email LIKE CONCAT('%', #{map.email}, '%')
  67. </if>
  68. <if test="map.companyId != null">
  69. AND c.company_id=#{map.companyId}
  70. </if>
  71. <if test="map.departmentId != null">
  72. AND own.department_id=#{map.departmentId}
  73. </if>
  74. <if test="map.ownerIdByMyselfAndNull != null and map.ownerIdByMyselfAndNull != ''">
  75. AND ( own.id=#{map.ownerIdByMyselfAndNull} or own.id is null )
  76. </if>
  77. </where>
  78. order by create_time desc
  79. </select>
  80. <select id="selectListByIds" resultType="com.management.platform.entity.Contacts">
  81. select id,
  82. `name`,
  83. phone,
  84. email,
  85. position,
  86. CASE sex
  87. WHEN 0 THEN '女' WHEN 1 THEN '男' ELSE NULL
  88. END AS sexValue,
  89. (select `name` from `user` where id = creator_id) creatorName,
  90. (select `name` from `user` where id = owner_id) ownerName
  91. from contacts
  92. <where>
  93. <if test="ids != null and ids.size() > 0">
  94. AND id IN
  95. <foreach collection="ids" item="id" open="(" separator="," close=")">
  96. #{id}
  97. </foreach>
  98. </if>
  99. </where>
  100. </select>
  101. <select id="pageContactsByPin" resultType="com.management.platform.entity.vo.ContactsVo">
  102. SELECT c.*, cust.custom_name as customName, own.name as ownerName,u.name as creatorName
  103. FROM contacts c
  104. LEFT JOIN custom cust ON c.custom_id = cust.id
  105. LEFT JOIN user own ON c.owner_id = own.id
  106. LEFT JOIN user u ON c.creator_id = u.id
  107. <where>
  108. <if test="map.isDelete != null ">
  109. AND c.is_delete =#{map.isDelete}
  110. </if>
  111. <if test="map.customName != null and map.customName != ''">
  112. AND cust.custom_name LIKE CONCAT('%', #{map.customName}, '%')
  113. </if>
  114. <if test="map.ownerName != null and map.ownerName != ''">
  115. AND own.name LIKE CONCAT('%', #{map.ownerName}, '%')
  116. </if>
  117. <if test="map.creatorName != null and map.creatorName != ''">
  118. AND own.name LIKE CONCAT('%', #{map.creatorName}, '%')
  119. </if>
  120. <if test="map.customId != null and map.customId != ''">
  121. AND cust.id =#{map.customId}
  122. </if>
  123. <if test="map.ownerId != null and map.ownerId != ''">
  124. AND own.id =#{map.ownerId}
  125. </if>
  126. <if test="map.creatorId != null and map.creatorId != ''">
  127. AND u.id =#{map.creatorId}
  128. </if>
  129. <if test="map.phone != null and map.phone != ''">
  130. AND c.phone LIKE CONCAT('%', #{map.phone}, '%')
  131. </if>
  132. <if test="map.name != null and map.name != ''">
  133. AND c.name LIKE CONCAT('%', #{map.name}, '%')
  134. </if>
  135. <if test="map.email != null and map.email != ''">
  136. AND c.email LIKE CONCAT('%', #{map.email}, '%')
  137. </if>
  138. <if test="map.companyId != null">
  139. AND c.company_id=#{map.companyId}
  140. </if>
  141. <if test="map.departmentId != null">
  142. AND own.department_id=#{map.departmentId}
  143. </if>
  144. <if test="map.ownerIdByMyselfAndNull != null and map.ownerIdByMyselfAndNull != ''">
  145. AND ( own.id=#{map.ownerIdByMyselfAndNull} or own.id is null )
  146. </if>
  147. </where>
  148. ORDER BY c.need_pin desc,c.pin_time desc ,c.create_time desc
  149. </select>
  150. </mapper>