TaskMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. </resultMap>
  89. <!-- 通用查询结果列 -->
  90. <sql id="Base_Column_List">
  91. 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
  92. </sql>
  93. <select id="simpleList" resultMap="BaseResultMap">
  94. 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
  95. from task
  96. ${ew.customSqlSegment}
  97. </select>
  98. <select id="nameList" resultMap="BaseResultMap">
  99. select id, name, task_level, stages_id, company_id, indate, group_id, seq,task_type
  100. from task
  101. ${ew.customSqlSegment}
  102. </select>
  103. <!--计算执行人任务分布-->
  104. <select id="getExecutorPanel" resultType="java.util.Map">
  105. SELECT IFNULL(b.executor_id,0) as executorId,IFNULL( b.executor_name,'待认领') as executorName, count(1) AS taskCount
  106. FROM task a left join task_executor b on b.task_id = a.id
  107. WHERE a.project_id = #{projectId}
  108. GROUP BY b.executor_id
  109. </select>
  110. <!--计算执行人任务计划工时-->
  111. <select id="getExecutorPlanHour" resultType="java.util.Map">
  112. SELECT IFNULL(b.executor_id,0) as executorId,IFNULL( b.executor_name,'待认领') as executorName, sum(a.plan_hours) AS taskHours
  113. FROM task a left join task_executor b on b.task_id = a.id
  114. WHERE a.project_id = #{projectId}
  115. GROUP BY b.executor_id
  116. </select>
  117. <!--计算任务列表的任务分布-->
  118. <select id="getStagesPanel" resultType="java.util.Map">
  119. SELECT a.stages_id AS stagesId, stages.`stages_name` AS name, COUNT(1) AS value
  120. FROM task a
  121. LEFT JOIN stages ON stages.id = a.`stages_id`
  122. WHERE a.project_id = #{projectId}
  123. GROUP BY a.stages_id
  124. ORDER BY stages.`sequence`
  125. </select>
  126. <!--计算耗时排名前十的任务-->
  127. <select id="getTopCostTask" resultType="java.util.Map">
  128. SELECT task.id , task.name AS name, IFNULL(SUM(report.`working_time`),0) AS value FROM task
  129. LEFT JOIN report ON report.`task_id` = task.id
  130. WHERE task.project_id = #{projectId} and report.state = 1
  131. GROUP BY task.id ORDER BY SUM(report.`working_time`) DESC LIMIT 10
  132. </select>
  133. <!-- 查询任务实际工时和计划工时对比,仅查询有实际工时的数据 -->
  134. <select id="getTaskTimeCompare" resultType="java.util.Map">
  135. SELECT task.id , task.name AS name, task.plan_hours as planHours, IFNULL(SUM(report.`working_time`),0) AS workHours FROM report
  136. LEFT JOIN task ON report.`task_id` = task.id AND report.state = 1
  137. WHERE task.project_id = #{projectId}
  138. GROUP BY task.id
  139. </select>
  140. <!--查询任务,带实际工时-->
  141. <select id="getTaskWithWorktime" resultMap="timeResultMap">
  142. SELECT task.* , IFNULL(SUM(report.`working_time`),0) AS work_hours FROM task
  143. LEFT JOIN report ON report.`task_id` = task.id and report.state = 1
  144. WHERE task.project_id = #{projectId}
  145. <if test="taskType != null" >
  146. and task.task_type = #{taskType}
  147. </if>
  148. GROUP BY task.id
  149. </select>
  150. <select id="getProjectTask" resultType="java.util.Map">
  151. SELECT task.id, task.`name`, DATE_FORMAT(task.`end_date`, '%Y-%m-%d') as end_date, task.`plan_hours`,
  152. (SELECT IFNULL(SUM(working_time),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS real_hours,
  153. task.`task_status`, task.`task_type`,
  154. project.`project_code`, project.`project_name` FROM task LEFT JOIN project ON project.id = task.`project_id`
  155. WHERE project.`company_id` = #{companyId}
  156. <if test="projectId != null">
  157. and task.project_id = #{projectId}
  158. </if>
  159. ORDER BY project.is_public desc, project.id ASC, task.stages_id asc, task.seq asc
  160. <if test="pageStart != null and pageSize != null">
  161. limit #{pageStart}, #{pageSize}
  162. </if>
  163. </select>
  164. <select id="getProjectTaskCount" resultType="java.lang.Integer">
  165. SELECT count(1) as total FROM task LEFT JOIN project ON project.id = task.`project_id`
  166. WHERE project.`company_id` = #{companyId}
  167. <if test="projectId != null">
  168. and task.project_id = #{projectId}
  169. </if>
  170. </select>
  171. <select id="getTaskWithProjectName" resultMap="RichResultMap">
  172. SELECT task.*, project.`project_name`, stages.stages_name FROM task LEFT JOIN project ON project.id = task.`project_id`
  173. left join stages on stages.id = task.stages_id
  174. ${ew.customSqlSegment}
  175. ORDER BY task.indate desc
  176. <if test="pageStart != null and pageSize != null">
  177. limit #{pageStart}, #{pageSize}
  178. </if>
  179. </select>
  180. <select id="recentSimpleList" resultType="java.util.Map">
  181. select task.id as taskId, task.name as taskName, stages.stages_name as stagesName
  182. from task left join stages on stages.id = task.stages_id
  183. where task.project_id = #{projectId}
  184. <if test="userId != null">
  185. and executor_id like '%${userId}%'
  186. </if>
  187. and task_status = 0 order by task.id desc limit 50
  188. </select>
  189. <select id="selectMilepost" resultType="com.management.platform.entity.Task">
  190. select * from task where
  191. task.task_type=1
  192. <if test="ids!=null">
  193. and task.project_id in
  194. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  195. #{item}
  196. </foreach>
  197. </if>
  198. and task.finish_date in
  199. (select MAX(task.finish_date)from task where
  200. task.task_type=1
  201. <if test="ids!=null">
  202. and task.project_id in
  203. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  204. #{item}
  205. </foreach>
  206. </if>
  207. group by project_id) group by task.project_id
  208. </select>
  209. </mapper>