DepartmentMapper.xml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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="superior_id" property="superiorId" />
  9. <result column="company_id" property="companyId" />
  10. <result column="manager_id" property="managerId" />
  11. <result column="report_audit_userid" property="reportAuditUserid" />
  12. <result column="corpwx_deptid" property="corpwxDeptid" />
  13. <result column="corpwx_deptpid" property="corpwxDeptpid" />
  14. </resultMap>
  15. <!-- 通用查询结果列 -->
  16. <sql id="Base_Column_List">
  17. department_id, department_name, superior_id, company_id, manager_id, report_audit_userid, corpwx_deptid, corpwx_deptpid
  18. </sql>
  19. <!--根据部门获取成本-->
  20. <select id="getCostByDepartment" resultType="java.util.Map">
  21. SELECT SUM(b.working_time) AS time, SUM(b.cost) AS money
  22. FROM report AS b
  23. WHERE b.state = 1
  24. <if test="departmentIds != null and departmentIds.size()>0">
  25. AND b.dept_id IN
  26. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  27. #{departmentId}
  28. </foreach>
  29. </if>
  30. <if test="startDate != null and endDate != null">
  31. AND b.create_date between #{startDate} and #{endDate}
  32. </if>
  33. </select>
  34. <!--根据人员获取成本-->
  35. <select id="getCostByUser" resultType="java.util.Map">
  36. SELECT a.id as id, a.name AS user, a.job_number as jobNumber, c.project_name AS project, SUM(b.working_time) AS time, SUM(b.cost) AS
  37. money
  38. FROM user AS a
  39. LEFT JOIN report AS b ON a.id = b.creator_id
  40. LEFT JOIN project AS c ON b.project_id = c.id
  41. WHERE b.state = 1
  42. <if test="departmentIds != null and departmentIds.size()>0">
  43. AND b.dept_id IN
  44. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  45. #{departmentId}
  46. </foreach>
  47. </if>
  48. <if test="userIds != null">
  49. AND a.id IN
  50. <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
  51. #{userId}
  52. </foreach>
  53. </if>
  54. <if test="companyId != null">
  55. AND a.company_id = #{companyId}
  56. </if>
  57. <if test="startDate != null and endDate != null">
  58. AND b.create_date between #{startDate} and #{endDate}
  59. </if>
  60. GROUP BY b.project_id, a.id order by a.department_id
  61. </select>
  62. <!-- 根据人员获取自定义的日报数值 -->
  63. <select id="getCustomDataByUser" resultType="java.util.Map">
  64. SELECT a.id as id, a.name AS user, a.job_number as jobNumber,c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
  65. FROM user AS a
  66. LEFT JOIN report AS b ON a.id = b.creator_id
  67. LEFT JOIN project AS c ON b.project_id = c.id
  68. WHERE b.state = 1
  69. <if test="departmentIds != null">
  70. AND a.department_id IN
  71. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  72. #{departmentId}
  73. </foreach>
  74. </if>
  75. <if test="userIds != null">
  76. AND a.id IN
  77. <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
  78. #{userId}
  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 b.project_id, a.id
  88. having IFNULL(SUM(b.custom_data),0) > 0
  89. </select>
  90. <!-- 根据部门获取自定义的日报数值 -->
  91. <select id="getDeptCustomDataStatistic" resultType="java.util.Map">
  92. SELECT a.department_id as id, a.department_name AS department, c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
  93. FROM department AS a
  94. LEFT JOIN report AS b ON a.department_id = b.dept_id
  95. LEFT JOIN project AS c ON b.project_id = c.id
  96. WHERE b.state = 1
  97. <if test="companyId!=null">
  98. AND a.company_id =#{companyId}
  99. </if>
  100. <if test="departmentIds != null">
  101. AND a.department_id IN
  102. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  103. #{departmentId}
  104. </foreach>
  105. </if>
  106. <if test="startDate!=null and endDate!=null">
  107. AND b.create_date between #{startDate} and #{endDate}
  108. </if>
  109. GROUP BY b.project_id, a.department_id
  110. having IFNULL(SUM(b.custom_data),0) > 0
  111. </select>
  112. </mapper>