TaskMapper.xml 14 KB

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