TaskMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 task.id , task.name AS name, task.plan_hours as planHours, IFNULL(SUM(report.`working_time`),0) AS workHours FROM report
  149. LEFT JOIN task ON report.`task_id` = task.id AND report.state = 1
  150. WHERE task.project_id = #{projectId}
  151. GROUP BY task.id
  152. </select>
  153. <!--查询任务,带实际工时-->
  154. <select id="getTaskWithWorktime" resultMap="timeResultMap">
  155. SELECT task.* , IFNULL(SUM(report.`working_time`),0) AS work_hours FROM task
  156. LEFT JOIN report ON report.`task_id` = task.id and report.state = 1
  157. WHERE task.project_id = #{projectId}
  158. <if test="taskType != null" >
  159. and task.task_type = #{taskType}
  160. </if>
  161. GROUP BY task.id
  162. </select>
  163. <select id="getProjectTask" resultType="java.util.Map">
  164. 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`,
  165. (SELECT IFNULL(SUM(working_time),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS real_hours,
  166. task.`task_status`, task.`task_type`,
  167. project.`project_code`, project.`project_name` FROM task LEFT JOIN project ON project.id = task.`project_id`
  168. WHERE project.`company_id` = #{companyId}
  169. <if test="projectId != null">
  170. and task.project_id = #{projectId}
  171. </if>
  172. <if test="taskType!=null">
  173. and task.task_type=#{taskType}
  174. </if>
  175. <if test="inchagerIds!=null and inchagerIds.size()>0">
  176. and task.project_id in
  177. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  178. #{item}
  179. </foreach>
  180. </if>
  181. ORDER BY project.is_public desc, project.id ASC, task.stages_id asc, task.seq asc
  182. <if test="pageStart != null and pageSize != null">
  183. limit #{pageStart}, #{pageSize}
  184. </if>
  185. </select>
  186. <select id="getProjectTaskCount" resultType="java.lang.Integer">
  187. SELECT count(1) as total FROM task LEFT JOIN project ON project.id = task.`project_id`
  188. WHERE project.`company_id` = #{companyId}
  189. <if test="projectId != null">
  190. and task.project_id = #{projectId}
  191. </if>
  192. <if test="taskType!=null">
  193. and task.task_type=#{taskType}
  194. </if>
  195. <if test="inchagerIds!=null and inchagerIds.size()>0">
  196. and task.project_id in
  197. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  198. #{item}
  199. </foreach>
  200. </if>
  201. </select>
  202. <select id="getTaskWithProjectName" resultMap="RichResultMap">
  203. 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,
  204. task.plan_hours, task.task_type, task.task_level, task.task_status, task.`finish_date`, project.`project_name`, stages.stages_name,department.department_name
  205. FROM task LEFT JOIN project ON project.id = task.`project_id`
  206. left join stages on stages.id = task.stages_id
  207. left join department on department.department_id=project.dept_id
  208. ${ew.customSqlSegment}
  209. <if test="deptIds!=null and deptIds.size()>0">
  210. and project.dept_id in
  211. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  212. #{item}
  213. </foreach>
  214. </if>
  215. ORDER BY task.indate desc
  216. <if test="pageStart != null and pageSize != null">
  217. limit #{pageStart}, #{pageSize}
  218. </if>
  219. </select>
  220. <select id="recentSimpleList" resultType="java.util.Map">
  221. select task.id as taskId, task.name as taskName, stages.stages_name as stagesName,task.group_id as groupId
  222. from task left join stages on stages.id = task.stages_id
  223. where task.project_id = #{projectId}
  224. <if test="userId != null">
  225. and executor_id like '%${userId}%'
  226. </if>
  227. <if test="stage != null">
  228. and stages.stages_name = #{stage}
  229. </if>
  230. <if test="groupId != null">
  231. and task.group_id = #{groupId}
  232. </if>
  233. and task_status = 0 order by task.id desc limit 50
  234. </select>
  235. <select id="selectMilepost" resultType="com.management.platform.entity.Task">
  236. select * from task where
  237. task.task_type=1
  238. <if test="ids!=null">
  239. and task.project_id in
  240. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  241. #{item}
  242. </foreach>
  243. </if>
  244. and task.finish_date in
  245. (select MAX(task.finish_date)from task where
  246. task.task_type=1
  247. <if test="ids!=null">
  248. and task.project_id in
  249. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  250. #{item}
  251. </foreach>
  252. </if>
  253. group by project_id) group by task.project_id
  254. </select>
  255. </mapper>