DepartmentMapper.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.DepartmentMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.Department">
  6. <id column="department_id" property="departmentId" />
  7. <result column="department_name" property="departmentName" />
  8. <result column="seq" property="seq" />
  9. <result column="superior_id" property="superiorId" />
  10. <result column="company_id" property="companyId" />
  11. <result column="manager_id" property="managerId" />
  12. <result column="report_audit_userid" property="reportAuditUserid" />
  13. <result column="corpwx_deptid" property="corpwxDeptid" />
  14. <result column="corpwx_deptpid" property="corpwxDeptpid" />
  15. <result column="dd_deptid" property="ddDeptid" />
  16. <result column="feishu_deptid" property="feishuDeptid" />
  17. <result column="push_to_sap" property="pushToSap" />
  18. <result column="dept_code" property="deptCode" />
  19. </resultMap>
  20. <!-- 通用查询结果列 -->
  21. <sql id="Base_Column_List">
  22. department_id, department_name, seq, superior_id, company_id, manager_id, report_audit_userid, corpwx_deptid, corpwx_deptpid, dd_deptid, feishu_deptid, push_to_sap, dept_code
  23. </sql>
  24. <!--根据部门获取成本-->
  25. <select id="getCostByDepartment" resultType="java.util.Map">
  26. SELECT SUM(b.working_time) AS time, SUM(b.cost) AS money
  27. FROM report AS b
  28. WHERE b.state = 1
  29. <if test="departmentIds != null and departmentIds.size()>0">
  30. AND b.dept_id IN
  31. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  32. #{departmentId}
  33. </foreach>
  34. </if>
  35. <if test="startDate != null and endDate != null">
  36. AND b.create_date between #{startDate} and #{endDate}
  37. </if>
  38. </select>
  39. <!--根据人员获取成本-->
  40. <select id="getCostByUser" resultType="java.util.Map">
  41. SELECT a.id as id, a.name AS user,a.corpwx_userid as corpwxUserId, a.job_number as jobNumber, c.project_name AS project,c.project_code as projectCode, c.project_main_id as projectMainId, project_main.code as mainProjectCode, project_main.name as mainProjectName, ifnull(SUM(b.working_time),0) AS time, ifnull(SUM(b.cost),0) AS
  42. money
  43. FROM user AS a
  44. LEFT JOIN report AS b ON a.id = b.creator_id
  45. LEFT JOIN project AS c ON b.project_id = c.id
  46. left join project_main on project_main.id = c.project_main_id
  47. WHERE b.state = 1
  48. <if test="departmentIds != null and departmentIds.size()>0">
  49. AND b.dept_id IN
  50. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  51. #{departmentId}
  52. </foreach>
  53. </if>
  54. <if test="userIds != null">
  55. AND a.id IN
  56. <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
  57. #{userId}
  58. </foreach>
  59. </if>
  60. <if test="companyId != null">
  61. AND a.company_id = #{companyId}
  62. </if>
  63. <if test="startDate != null and endDate != null">
  64. AND b.create_date between #{startDate} and #{endDate}
  65. </if>
  66. GROUP BY b.project_id, a.id order by a.department_id
  67. </select>
  68. <!--根据人员获取成本-->
  69. <select id="getCostByUserSum" resultType="java.util.Map">
  70. SELECT a.id as id, a.name AS user,a.corpwx_userid as corpwxUserId, a.job_number as jobNumber, ifnull(SUM(b.working_time),0) AS time, ifnull(SUM(b.cost),0) AS
  71. money
  72. FROM user AS a
  73. LEFT JOIN report AS b ON a.id = b.creator_id
  74. WHERE b.state = 1
  75. <if test="departmentIds != null and departmentIds.size()>0">
  76. AND b.dept_id IN
  77. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  78. #{departmentId}
  79. </foreach>
  80. </if>
  81. <if test="companyId != null">
  82. AND a.company_id = #{companyId}
  83. </if>
  84. <if test="startDate != null and endDate != null">
  85. AND b.create_date between #{startDate} and #{endDate}
  86. </if>
  87. GROUP BY a.id order by a.department_id
  88. </select>
  89. <!-- 根据人员获取自定义的日报数值 -->
  90. <select id="getCustomDataByUser" resultType="java.util.Map">
  91. SELECT a.id as id, a.name AS user,a.corpwx_userid as corpwxUserid, a.job_number as jobNumber,c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
  92. FROM user AS a
  93. LEFT JOIN report AS b ON a.id = b.creator_id
  94. LEFT JOIN project AS c ON b.project_id = c.id
  95. WHERE b.state = 1
  96. <if test="departmentIds != null">
  97. AND a.department_id IN
  98. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  99. #{departmentId}
  100. </foreach>
  101. </if>
  102. <if test="userIds != null">
  103. AND a.id IN
  104. <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
  105. #{userId}
  106. </foreach>
  107. </if>
  108. <if test="companyId != null">
  109. AND a.company_id = #{companyId}
  110. </if>
  111. <if test="startDate != null and endDate != null">
  112. AND b.create_date between #{startDate} and #{endDate}
  113. </if>
  114. GROUP BY b.project_id, a.id
  115. having IFNULL(SUM(b.custom_data),0) > 0
  116. </select>
  117. <!-- 根据部门获取自定义的日报数值 -->
  118. <select id="getDeptCustomDataStatistic" resultType="java.util.Map">
  119. SELECT a.department_id as id, a.department_name AS department, c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
  120. FROM department AS a
  121. LEFT JOIN report AS b ON a.department_id = b.dept_id
  122. LEFT JOIN project AS c ON b.project_id = c.id
  123. WHERE b.state = 1
  124. <if test="companyId!=null">
  125. AND a.company_id =#{companyId}
  126. </if>
  127. <if test="departmentIds != null">
  128. AND a.department_id IN
  129. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  130. #{departmentId}
  131. </foreach>
  132. </if>
  133. <if test="startDate!=null and endDate!=null">
  134. AND b.create_date between #{startDate} and #{endDate}
  135. </if>
  136. GROUP BY b.project_id, a.department_id
  137. having IFNULL(SUM(b.custom_data),0) > 0
  138. </select>
  139. <select id="getNameWithProjectRelate" resultType="com.management.platform.entity.vo.ProjectDeptInfo">
  140. select department.department_id,department.department_name
  141. from department
  142. left join project_dept_relate pdr on department.department_id = pdr.department_id
  143. where pdr.project_id = #{id}
  144. </select>
  145. <select id="getNameWithProjectRelates" resultType="com.management.platform.entity.vo.ProjectDeptInfo">
  146. select department.department_id,department.department_name,pdr.project_id
  147. from department
  148. left join project_dept_relate pdr on department.department_id = pdr.department_id
  149. where pdr.project_id in
  150. <foreach collection="projectIds" item="projectId" separator="," open="(" close=")">
  151. #{projectId}
  152. </foreach>
  153. </select>
  154. </mapper>