DepartmentMapper.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. </resultMap>
  19. <!-- 通用查询结果列 -->
  20. <sql id="Base_Column_List">
  21. 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
  22. </sql>
  23. <!--根据部门获取成本-->
  24. <select id="getCostByDepartment" resultType="java.util.Map">
  25. SELECT SUM(b.working_time) AS time, SUM(b.cost) AS money
  26. FROM report AS b
  27. WHERE b.state = 1
  28. <if test="departmentIds != null and departmentIds.size()>0">
  29. AND b.dept_id IN
  30. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  31. #{departmentId}
  32. </foreach>
  33. </if>
  34. <if test="startDate != null and endDate != null">
  35. AND b.create_date between #{startDate} and #{endDate}
  36. </if>
  37. </select>
  38. <!--根据人员获取成本-->
  39. <select id="getCostByUser" resultType="java.util.Map">
  40. 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
  41. money
  42. FROM user AS a
  43. LEFT JOIN report AS b ON a.id = b.creator_id
  44. LEFT JOIN project AS c ON b.project_id = c.id
  45. left join project_main on project_main.id = c.project_main_id
  46. WHERE b.state = 1
  47. <if test="departmentIds != null and departmentIds.size()>0">
  48. AND b.dept_id IN
  49. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  50. #{departmentId}
  51. </foreach>
  52. </if>
  53. <if test="userIds != null">
  54. AND a.id IN
  55. <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
  56. #{userId}
  57. </foreach>
  58. </if>
  59. <if test="companyId != null">
  60. AND a.company_id = #{companyId}
  61. </if>
  62. <if test="startDate != null and endDate != null">
  63. AND b.create_date between #{startDate} and #{endDate}
  64. </if>
  65. GROUP BY b.project_id, a.id order by a.department_id
  66. </select>
  67. <!--根据人员获取成本-->
  68. <select id="getCostByUserSum" resultType="java.util.Map">
  69. 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
  70. money
  71. FROM user AS a
  72. LEFT JOIN report AS b ON a.id = b.creator_id
  73. WHERE b.state = 1
  74. <if test="departmentIds != null and departmentIds.size()>0">
  75. AND b.dept_id IN
  76. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  77. #{departmentId}
  78. </foreach>
  79. </if>
  80. <if test="companyId != null">
  81. AND a.company_id = #{companyId}
  82. </if>
  83. <if test="startDate != null and endDate != null">
  84. AND b.create_date between #{startDate} and #{endDate}
  85. </if>
  86. GROUP BY a.id order by a.department_id
  87. </select>
  88. <!-- 根据人员获取自定义的日报数值 -->
  89. <select id="getCustomDataByUser" resultType="java.util.Map">
  90. 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
  91. FROM user AS a
  92. LEFT JOIN report AS b ON a.id = b.creator_id
  93. LEFT JOIN project AS c ON b.project_id = c.id
  94. WHERE b.state = 1
  95. <if test="departmentIds != null">
  96. AND a.department_id IN
  97. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  98. #{departmentId}
  99. </foreach>
  100. </if>
  101. <if test="userIds != null">
  102. AND a.id IN
  103. <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
  104. #{userId}
  105. </foreach>
  106. </if>
  107. <if test="companyId != null">
  108. AND a.company_id = #{companyId}
  109. </if>
  110. <if test="startDate != null and endDate != null">
  111. AND b.create_date between #{startDate} and #{endDate}
  112. </if>
  113. GROUP BY b.project_id, a.id
  114. having IFNULL(SUM(b.custom_data),0) > 0
  115. </select>
  116. <!-- 根据部门获取自定义的日报数值 -->
  117. <select id="getDeptCustomDataStatistic" resultType="java.util.Map">
  118. SELECT a.department_id as id, a.department_name AS department, c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
  119. FROM department AS a
  120. LEFT JOIN report AS b ON a.department_id = b.dept_id
  121. LEFT JOIN project AS c ON b.project_id = c.id
  122. WHERE b.state = 1
  123. <if test="companyId!=null">
  124. AND a.company_id =#{companyId}
  125. </if>
  126. <if test="departmentIds != null">
  127. AND a.department_id IN
  128. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  129. #{departmentId}
  130. </foreach>
  131. </if>
  132. <if test="startDate!=null and endDate!=null">
  133. AND b.create_date between #{startDate} and #{endDate}
  134. </if>
  135. GROUP BY b.project_id, a.department_id
  136. having IFNULL(SUM(b.custom_data),0) > 0
  137. </select>
  138. </mapper>