TaskMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.TaskMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.Task">
  6. <id column="id" property="id" />
  7. <result column="name" property="name" />
  8. <result column="task_desc" property="taskDesc" />
  9. <result column="creater_id" property="createrId" />
  10. <result column="creater_name" property="createrName" />
  11. <result column="creator_color" property="creatorColor" />
  12. <result column="executor_id" property="executorId" />
  13. <result column="executor_name" property="executorName" />
  14. <result column="executor_color" property="executorColor" />
  15. <result column="task_level" property="taskLevel" />
  16. <result column="task_status" property="taskStatus" />
  17. <result column="create_date" property="createDate" />
  18. <result column="end_date" property="endDate" />
  19. <result column="project_id" property="projectId" />
  20. <result column="stages_id" property="stagesId" />
  21. <result column="company_id" property="companyId" />
  22. <result column="indate" property="indate" />
  23. <result column="parent_tid" property="parentTid" />
  24. <result column="group_id" property="groupId" />
  25. <result column="seq" property="seq" />
  26. <result column="plan_hours" property="planHours" />
  27. <result column="task_type" property="taskType" />
  28. <result column="parent_tname" property="parentTname" />
  29. <result column="finish_date" property="finishDate" />
  30. <result column="start_date" property="startDate" />
  31. </resultMap>
  32. <resultMap id="timeResultMap" type="com.management.platform.entity.TimeTask" >
  33. <id column="id" property="id" />
  34. <result column="name" property="name" />
  35. <result column="task_desc" property="taskDesc" />
  36. <result column="creater_id" property="createrId" />
  37. <result column="creater_name" property="createrName" />
  38. <result column="creator_color" property="creatorColor" />
  39. <result column="executor_id" property="executorId" />
  40. <result column="executor_name" property="executorName" />
  41. <result column="executor_color" property="executorColor" />
  42. <result column="task_level" property="taskLevel" />
  43. <result column="task_status" property="taskStatus" />
  44. <result column="create_date" property="createDate" />
  45. <result column="end_date" property="endDate" />
  46. <result column="project_id" property="projectId" />
  47. <result column="stages_id" property="stagesId" />
  48. <result column="company_id" property="companyId" />
  49. <result column="indate" property="indate" />
  50. <result column="parent_tid" property="parentTid" />
  51. <result column="group_id" property="groupId" />
  52. <result column="seq" property="seq" />
  53. <result column="plan_hours" property="planHours" />
  54. <result column="task_type" property="taskType" />
  55. <result column="parent_tname" property="parentTname" />
  56. <result column="finish_date" property="finishDate" />
  57. <result column="start_date" property="startDate" />
  58. <result column="work_hours" property="workHours" />
  59. </resultMap>
  60. <resultMap id="RichResultMap" type="com.management.platform.entity.Task">
  61. <id column="id" property="id" />
  62. <result column="name" property="name" />
  63. <result column="task_desc" property="taskDesc" />
  64. <result column="creater_id" property="createrId" />
  65. <result column="creater_name" property="createrName" />
  66. <result column="creator_color" property="creatorColor" />
  67. <result column="executor_id" property="executorId" />
  68. <result column="executor_name" property="executorName" />
  69. <result column="executor_color" property="executorColor" />
  70. <result column="task_level" property="taskLevel" />
  71. <result column="task_status" property="taskStatus" />
  72. <result column="create_date" property="createDate" />
  73. <result column="end_date" property="endDate" />
  74. <result column="project_id" property="projectId" />
  75. <result column="stages_id" property="stagesId" />
  76. <result column="company_id" property="companyId" />
  77. <result column="indate" property="indate" />
  78. <result column="parent_tid" property="parentTid" />
  79. <result column="group_id" property="groupId" />
  80. <result column="seq" property="seq" />
  81. <result column="plan_hours" property="planHours" />
  82. <result column="task_type" property="taskType" />
  83. <result column="parent_tname" property="parentTname" />
  84. <result column="finish_date" property="finishDate" />
  85. <result column="project_name" property="projectName" />
  86. <result column="start_date" property="startDate" />
  87. <result column="stages_name" property="stagesName" />
  88. <result column="department_name" property="departmentName" />
  89. </resultMap>
  90. <!-- 通用查询结果列 -->
  91. <sql id="Base_Column_List">
  92. id, name, task_desc, creater_id, creater_name, creator_color, executor_id, executor_name, executor_color, task_level, task_status, create_date, end_date, project_id, stages_id, company_id, indate, parent_tid, group_id, seq, plan_hours, task_type, parent_tname, finish_date, start_date
  93. </sql>
  94. <select id="simpleList" resultMap="BaseResultMap">
  95. select id, name, creater_id, creater_name, creator_color, executor_id, executor_name, executor_color, task_level, task_status, create_date, end_date, project_id, stages_id, company_id, indate, parent_tid, group_id, seq, plan_hours, task_type, parent_tname, finish_date, start_date
  96. from task
  97. ${ew.customSqlSegment}
  98. </select>
  99. <select id="nameList" resultMap="BaseResultMap">
  100. select id, name, task_level, stages_id, company_id, indate, group_id, seq,task_type,task_desc
  101. from task
  102. ${ew.customSqlSegment}
  103. </select>
  104. <!--计算执行人任务分布-->
  105. <select id="getExecutorPanel" resultType="java.util.Map">
  106. SELECT IFNULL(b.executor_id,0) as executorId,IFNULL( b.executor_name,'待认领') as executorName, count(1) AS taskCount
  107. FROM task a left join task_executor b on b.task_id = a.id
  108. WHERE a.project_id = #{projectId}
  109. GROUP BY b.executor_id
  110. </select>
  111. <!--计算执行人任务计划工时-->
  112. <select id="getExecutorPlanHour" resultType="java.util.Map">
  113. SELECT IFNULL(b.executor_id,0) as executorId,IFNULL( b.executor_name,'待认领') as executorName, sum(a.plan_hours) AS taskHours
  114. FROM task a left join task_executor b on b.task_id = a.id
  115. WHERE a.project_id = #{projectId}
  116. GROUP BY b.executor_id
  117. </select>
  118. <!--计算任务列表的任务分布-->
  119. <select id="getStagesPanel" resultType="java.util.Map">
  120. SELECT a.stages_id AS stagesId, stages.`stages_name` AS name, COUNT(1) AS value
  121. FROM task a
  122. LEFT JOIN stages ON stages.id = a.`stages_id`
  123. WHERE a.project_id = #{projectId}
  124. GROUP BY a.stages_id
  125. ORDER BY stages.`sequence`
  126. </select>
  127. <!--计算耗时排名前十的任务-->
  128. <select id="getTopCostTask" resultType="java.util.Map">
  129. SELECT task.id , task.name AS name, IFNULL(SUM(report.`working_time`),0) AS value FROM task
  130. LEFT JOIN report ON report.`task_id` = task.id
  131. WHERE task.project_id = #{projectId} and report.state = 1
  132. GROUP BY task.id ORDER BY SUM(report.`working_time`) DESC LIMIT 10
  133. </select>
  134. <!-- 查询任务实际工时和计划工时对比,仅查询有实际工时的数据 -->
  135. <select id="getTaskTimeCompare" resultType="java.util.Map">
  136. SELECT task.id , task.name AS name, task.plan_hours as planHours, IFNULL(SUM(report.`working_time`),0) AS workHours FROM report
  137. LEFT JOIN task ON report.`task_id` = task.id AND report.state = 1
  138. WHERE task.project_id = #{projectId}
  139. GROUP BY task.id
  140. </select>
  141. <!--查询任务,带实际工时-->
  142. <select id="getTaskWithWorktime" resultMap="timeResultMap">
  143. SELECT task.* , IFNULL(SUM(report.`working_time`),0) AS work_hours FROM task
  144. LEFT JOIN report ON report.`task_id` = task.id and report.state = 1
  145. WHERE task.project_id = #{projectId}
  146. <if test="taskType != null" >
  147. and task.task_type = #{taskType}
  148. </if>
  149. GROUP BY task.id
  150. </select>
  151. <select id="getProjectTask" resultType="java.util.Map">
  152. SELECT task.id, task.`name`,task.executor_name,task.executor_id,DATE_FORMAT(task.`end_date`, '%Y-%m-%d') as end_date, task.`plan_hours`,
  153. (SELECT IFNULL(SUM(working_time),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS real_hours,
  154. task.`task_status`, task.`task_type`,
  155. project.`project_code`, project.`project_name` FROM task LEFT JOIN project ON project.id = task.`project_id`
  156. WHERE project.`company_id` = #{companyId}
  157. <if test="projectId != null">
  158. and task.project_id = #{projectId}
  159. </if>
  160. <if test="taskType!=null">
  161. and task.task_type=#{taskType}
  162. </if>
  163. <if test="inchagerIds!=null and inchagerIds.size()>0">
  164. and task.project_id in
  165. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  166. #{item}
  167. </foreach>
  168. </if>
  169. ORDER BY project.is_public desc, project.id ASC, task.stages_id asc, task.seq asc
  170. <if test="pageStart != null and pageSize != null">
  171. limit #{pageStart}, #{pageSize}
  172. </if>
  173. </select>
  174. <select id="getProjectTaskCount" resultType="java.lang.Integer">
  175. SELECT count(1) as total FROM task LEFT JOIN project ON project.id = task.`project_id`
  176. WHERE project.`company_id` = #{companyId}
  177. <if test="projectId != null">
  178. and task.project_id = #{projectId}
  179. </if>
  180. <if test="taskType!=null">
  181. and task.task_type=#{taskType}
  182. </if>
  183. <if test="inchagerIds!=null and inchagerIds.size()>0">
  184. and task.project_id in
  185. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  186. #{item}
  187. </foreach>
  188. </if>
  189. </select>
  190. <select id="getTaskWithProjectName" resultMap="RichResultMap">
  191. SELECT task.id, task.project_id, task.name, task.executor_name, task.start_date, task.`end_date`,task.create_date, task.`creater_id`, task.`creater_name`, task.group_id,
  192. task.plan_hours, task.task_type, task.task_level, task.task_status, task.`finish_date`, project.`project_name`, stages.stages_name,department.department_name
  193. FROM task LEFT JOIN project ON project.id = task.`project_id`
  194. left join stages on stages.id = task.stages_id
  195. left join department on department.department_id=project.dept_id
  196. ${ew.customSqlSegment}
  197. <if test="deptIds!=null and deptIds.size()>0">
  198. and project.dept_id in
  199. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  200. #{item}
  201. </foreach>
  202. </if>
  203. ORDER BY task.indate desc
  204. <if test="pageStart != null and pageSize != null">
  205. limit #{pageStart}, #{pageSize}
  206. </if>
  207. </select>
  208. <select id="recentSimpleList" resultType="java.util.Map">
  209. select task.id as taskId, task.name as taskName, stages.stages_name as stagesName
  210. from task left join stages on stages.id = task.stages_id
  211. where task.project_id = #{projectId}
  212. <if test="userId != null">
  213. and executor_id like '%${userId}%'
  214. </if>
  215. and task_status = 0 order by task.id desc limit 50
  216. </select>
  217. <select id="selectMilepost" resultType="com.management.platform.entity.Task">
  218. select * from task where
  219. task.task_type=1
  220. <if test="ids!=null">
  221. and task.project_id in
  222. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  223. #{item}
  224. </foreach>
  225. </if>
  226. and task.finish_date in
  227. (select MAX(task.finish_date)from task where
  228. task.task_type=1
  229. <if test="ids!=null">
  230. and task.project_id in
  231. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  232. #{item}
  233. </foreach>
  234. </if>
  235. group by project_id) group by task.project_id
  236. </select>
  237. </mapper>