DepartmentMapper.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.dayou.mapper.DepartmentMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.Department">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="created" property="created" />
  9. <result column="modified" property="modified" />
  10. <result column="parent_id" property="parentId" />
  11. <result column="name" property="name" />
  12. <result column="leader_id" property="leaderId" />
  13. <result column="phone" property="phone" />
  14. </resultMap>
  15. <!-- 通用查询结果列 -->
  16. <sql id="Base_Column_List">
  17. id,
  18. deleted,
  19. created,
  20. modified,
  21. parent_id, name, leader_id, phone
  22. </sql>
  23. <select id="xPage" parameterType="com.dayou.entity.Department" resultType="com.dayou.vo.DepartmentVO">
  24. SELECT d.id,d.parent_id,d.name,d.leader_id,d.phone,d.deleted,d.created,d.modified,d.if_allot,
  25. ( SELECT NAME FROM department WHERE id = d.parent_id ) AS parentName ,
  26. (select name from user where id = d.leader_id) as leaderName,
  27. (select count(distinct user_id) from user_post where post_id in ((select id from post where department_id = d.id and user_post.deleted = 0))) as peopleNum
  28. FROM
  29. department d where d.deleted = 0
  30. <if test="department!=null and department.departmentIds!=null and department.departmentIds.size!=0">
  31. and d.id in
  32. <foreach collection="department.departmentIds" open="(" close=")" separator="," item="departmentId">
  33. #{departmentId}
  34. </foreach>
  35. </if>
  36. order by d.id DESC
  37. </select>
  38. <select id="getPage" parameterType="com.dayou.entity.Department" resultType="com.dayou.vo.DepartmentVO">
  39. select d.*,u.name as leaderName from department d left join user u on u.id = d.leader_id
  40. where d.deleted = 0
  41. </select>
  42. <!--根据业务code获取接单部门-->
  43. <select id="getAllotDepartmentByBusiness" resultType="com.dayou.entity.Department">
  44. SELECT department.id, department.name
  45. FROM department,sorted_department
  46. WHERE department.id = sorted_department.department_id
  47. AND department.deleted = 0
  48. AND sorted_department.business_type = #{businessCode}
  49. </select>
  50. <!--通过用户id获取部门信息-->
  51. <select id="getDepartmentByUserId" resultType="java.lang.Long">
  52. SELECT department_id
  53. FROM user,user_post,post
  54. WHERE user.id = user_post.user_id
  55. AND user_post.post_id = post.id
  56. AND user_post.deleted = 0
  57. AND post.deleted = 0
  58. AND user.id = #{userId}
  59. LIMIT 1
  60. </select>
  61. <!--根据部门id获取部门及其下属部门的id集合-->
  62. <select id="getDepIdList" resultType="java.lang.Long">
  63. SELECT DISTINCT
  64. department.id
  65. FROM
  66. ( SELECT department.id FROM department ) AS department
  67. INNER JOIN (
  68. SELECT
  69. id
  70. FROM
  71. ( SELECT id, parent_id FROM department WHERE deleted = 0 ORDER BY parent_id, id ) org_query,
  72. (
  73. SELECT
  74. @id := ( SELECT id FROM department WHERE id = #{depId} AND deleted = 0 )) initialisation
  75. WHERE
  76. ( FIND_IN_SET( parent_id, @id ) > 0 OR FIND_IN_SET( id, @id ) > 0 )
  77. AND @id := CONCAT( @id, ',', id )) AS depId ON depId.id = department.id
  78. </select>
  79. <!--通过客户经理id获取下单部门-->
  80. <select id="getManagerDepId" resultType="java.lang.Long">
  81. SELECT post.department_id
  82. FROM user,user_post,post
  83. WHERE user.id = user_post.user_id
  84. AND user_post.post_id = post.id
  85. AND user_post.deleted = 0
  86. AND post.deleted = 0
  87. AND user.id = #{managerId}
  88. LIMIT 1
  89. </select>
  90. <select id="allotMajor" resultType="com.dayou.vo.MajorDepartmentVO">
  91. SELECT
  92. d.id,
  93. d.NAME,
  94. o.orderOverStock
  95. FROM
  96. (
  97. SELECT
  98. id,
  99. NAME
  100. FROM
  101. department
  102. WHERE
  103. deleted = 0
  104. AND NAME IN ( '评估一部', '评估二部', '评估三部' )) d
  105. LEFT JOIN (
  106. SELECT
  107. department_id,
  108. count(*) AS orderOverStock
  109. FROM
  110. major
  111. WHERE
  112. id IN (
  113. SELECT
  114. business_id
  115. FROM
  116. work_flow_node_instance
  117. WHERE
  118. flow_id = 6
  119. AND business_type = 'MAJOR_BUSINESS'
  120. AND deleted = 0
  121. AND state = 'PENDING'
  122. AND node_id IN ( 55, 56, 57, 58, 59 ))
  123. AND deleted = 0
  124. AND allot_type = '轮单'
  125. and created &lt; DATE_SUB(NOW(), INTERVAL 7 DAY)
  126. GROUP BY
  127. department_id
  128. ) o ON d.id = o.department_id
  129. ORDER BY
  130. d.id
  131. </select>
  132. </mapper>