DepartmentMapper.xml 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. </resultMap>
  13. <!-- 通用查询结果列 -->
  14. <sql id="Base_Column_List">
  15. department_id, department_name, superior_id, company_id, manager_id, report_audit_userid
  16. </sql>
  17. <!--根据部门获取成本-->
  18. <select id="getCostByDepartment" resultType="java.util.Map">
  19. SELECT SUM(b.working_time) AS time, SUM(b.cost) AS money
  20. FROM report AS b
  21. WHERE b.state = 1
  22. AND b.dept_id IN
  23. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  24. #{departmentId}
  25. </foreach>
  26. <if test="startDate != null and endDate != null">
  27. AND b.create_date between #{startDate} and #{endDate}
  28. </if>
  29. </select>
  30. <!--根据人员获取成本-->
  31. <select id="getCostByUser" resultType="java.util.Map">
  32. SELECT a.id as id, a.name AS user, c.project_name AS project, SUM(b.working_time) AS time, SUM(b.cost) AS
  33. money
  34. FROM user AS a
  35. LEFT JOIN report AS b ON a.id = b.creator_id
  36. LEFT JOIN project AS c ON b.project_id = c.id
  37. WHERE b.state = 1
  38. <if test="departmentIds != null">
  39. AND b.dept_id IN
  40. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  41. #{departmentId}
  42. </foreach>
  43. </if>
  44. <if test="userIds != null">
  45. AND a.id IN
  46. <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
  47. #{userId}
  48. </foreach>
  49. </if>
  50. <if test="companyId != null">
  51. AND a.company_id = #{companyId}
  52. </if>
  53. <if test="startDate != null and endDate != null">
  54. AND b.create_date between #{startDate} and #{endDate}
  55. </if>
  56. GROUP BY b.project_id, a.id order by a.department_id
  57. </select>
  58. <!-- 根据人员获取自定义的日报数值 -->
  59. <select id="getCustomDataByUser" resultType="java.util.Map">
  60. SELECT a.id as id, a.name AS user, c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
  61. FROM user AS a
  62. LEFT JOIN report AS b ON a.id = b.creator_id
  63. LEFT JOIN project AS c ON b.project_id = c.id
  64. WHERE b.state = 1
  65. <if test="departmentIds != null">
  66. AND a.department_id IN
  67. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  68. #{departmentId}
  69. </foreach>
  70. </if>
  71. <if test="userIds != null">
  72. AND a.id IN
  73. <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
  74. #{userId}
  75. </foreach>
  76. </if>
  77. <if test="companyId != null">
  78. AND a.company_id = #{companyId}
  79. </if>
  80. <if test="startDate != null and endDate != null">
  81. AND b.create_date between #{startDate} and #{endDate}
  82. </if>
  83. GROUP BY b.project_id, a.id
  84. </select>
  85. </mapper>