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