TaskMapper.xml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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. <result column="charge_one_id" property="chargeOneId" />
  99. <result column="charge_one_status" property="chargeOneStatus" />
  100. <result column="charge_one_time" property="chargeOneTime" />
  101. <result column="charge_two_id" property="chargeTwoId" />
  102. <result column="charge_two_status" property="chargeTwoStatus" />
  103. <result column="charge_two_time" property="chargeTwoTime" />
  104. <result column="charge_stage" property="chargeStage" />
  105. <result column="final_charge_status" property="finalChargeStatus" />
  106. <result column="reject_reason" property="rejectReason"></result>
  107. </resultMap>
  108. <!-- 通用查询结果列 -->
  109. <sql id="Base_Column_List">
  110. 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
  111. </sql>
  112. <select id="simpleList" resultMap="BaseResultMap">
  113. 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
  114. from task
  115. ${ew.customSqlSegment}
  116. <if test="start!=null and size!=null">
  117. limit #{start},#{size}
  118. </if>
  119. </select>
  120. <select id="nameList" resultMap="BaseResultMap">
  121. select id, name, task_level, stages_id, company_id, indate, group_id, seq,task_type,task_desc
  122. from task
  123. ${ew.customSqlSegment}
  124. </select>
  125. <!--计算执行人任务分布-->
  126. <select id="getExecutorPanel" resultType="java.util.Map">
  127. SELECT IFNULL(b.executor_id,0) as executorId,IFNULL( b.executor_name,'待认领') as executorName, count(1) AS taskCount
  128. FROM task a left join task_executor b on b.task_id = a.id
  129. WHERE a.project_id = #{projectId}
  130. GROUP BY b.executor_id
  131. </select>
  132. <!--计算执行人任务计划工时-->
  133. <select id="getExecutorPlanHour" resultType="java.util.Map">
  134. SELECT IFNULL(b.executor_id,0) as executorId,IFNULL( b.executor_name,'待认领') as executorName, sum(a.plan_hours) AS taskHours
  135. FROM task a left join task_executor b on b.task_id = a.id
  136. WHERE a.project_id = #{projectId}
  137. GROUP BY b.executor_id
  138. </select>
  139. <!--计算任务列表的任务分布-->
  140. <select id="getStagesPanel" resultType="java.util.Map">
  141. SELECT a.stages_id AS stagesId, stages.`stages_name` AS name, COUNT(1) AS value
  142. FROM task a
  143. LEFT JOIN stages ON stages.id = a.`stages_id`
  144. WHERE a.project_id = #{projectId}
  145. GROUP BY a.stages_id
  146. ORDER BY stages.`sequence`
  147. </select>
  148. <!--计算耗时排名前十的任务-->
  149. <select id="getTopCostTask" resultType="java.util.Map">
  150. SELECT task.id , task.name AS name, IFNULL(SUM(report.`working_time`),0) AS value FROM task
  151. LEFT JOIN report ON report.`task_id` = task.id
  152. WHERE task.project_id = #{projectId} and report.state = 1
  153. GROUP BY task.id ORDER BY SUM(report.`working_time`) DESC LIMIT 10
  154. </select>
  155. <!-- 查询任务实际工时和计划工时对比,仅查询有实际工时的数据 -->
  156. <select id="getTaskTimeCompare" resultType="java.util.Map">
  157. 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
  158. task_executor te
  159. LEFT JOIN user u ON te.executor_id=u.id
  160. LEFT JOIN task t ON t.id=te.task_id
  161. LEFT JOIN project p ON p.id=t.project_id
  162. WHERE p.id= #{projectId}
  163. <if test="deptId!=null and deptId">
  164. and u.department_id=#{deptId}
  165. </if>
  166. GROUP BY t.id
  167. </select>
  168. <!--查询任务,带实际工时-->
  169. <select id="getTaskWithWorktime" resultMap="timeResultMap">
  170. SELECT task.* , IFNULL(SUM(report.`working_time`),0) AS work_hours FROM task
  171. LEFT JOIN report ON report.`task_id` = task.id and report.state = 1
  172. WHERE task.project_id = #{projectId}
  173. <if test="taskType != null" >
  174. and task.task_type = #{taskType}
  175. </if>
  176. GROUP BY task.id
  177. </select>
  178. <select id="getProjectTask" resultType="java.util.Map">
  179. 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`,
  180. (SELECT IFNULL(SUM(working_time),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS real_hours,
  181. (SELECT IFNULL(SUM(cost),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS real_cost,
  182. task.`task_status`, task.`task_type`,
  183. project.`project_code`, project.`project_name`,tg.name as groupName
  184. FROM task
  185. LEFT JOIN project ON project.id = task.`project_id`
  186. LEFT JOIN task_group tg on tg.id=task.`group_id`
  187. WHERE project.`company_id` = #{companyId}
  188. <if test="projectId != null">
  189. and task.project_id = #{projectId}
  190. </if>
  191. <if test="groupId != null">
  192. and task.group_id = #{groupId}
  193. </if>
  194. <if test="taskType!=null">
  195. and task.task_type=#{taskType}
  196. </if>
  197. <if test="inchagerIds!=null and inchagerIds.size()>0">
  198. and task.project_id in
  199. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  200. #{item}
  201. </foreach>
  202. </if>
  203. ORDER BY project.is_public desc, project.id ASC, task.stages_id asc, task.seq asc
  204. <if test="pageStart != null and pageSize != null">
  205. limit #{pageStart}, #{pageSize}
  206. </if>
  207. </select>
  208. <select id="getProjectTaskCount" resultType="java.lang.Integer">
  209. SELECT count(1) as total FROM task LEFT JOIN project ON project.id = task.`project_id`
  210. WHERE project.`company_id` = #{companyId}
  211. <if test="projectId != null">
  212. and task.project_id = #{projectId}
  213. </if>
  214. <if test="groupId != null">
  215. and task.group_id = #{groupId}
  216. </if>
  217. <if test="taskType!=null">
  218. and task.task_type=#{taskType}
  219. </if>
  220. <if test="inchagerIds!=null and inchagerIds.size()>0">
  221. and task.project_id in
  222. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  223. #{item}
  224. </foreach>
  225. </if>
  226. </select>
  227. <select id="getTaskWithProjectName" resultMap="RichResultMap">
  228. 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,
  229. task.plan_hours, task.task_type, task.task_level, task.task_status, task.`finish_date`, project.`project_name`, stages.stages_name,department.department_name
  230. ,task.charge_one_id,task.charge_one_status,task.charge_two_id,task.charge_two_status,task.charge_stage,task.final_charge_status
  231. FROM task LEFT JOIN project ON project.id = task.`project_id`
  232. left join stages on stages.id = task.stages_id
  233. left join department on department.department_id=project.dept_id
  234. ${ew.customSqlSegment}
  235. <if test="deptIds!=null and deptIds.size()>0">
  236. and project.dept_id in
  237. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  238. #{item}
  239. </foreach>
  240. </if>
  241. ORDER BY task.indate desc
  242. <if test="pageStart != null and pageSize != null">
  243. limit #{pageStart}, #{pageSize}
  244. </if>
  245. </select>
  246. <select id="recentSimpleList" resultType="java.util.Map">
  247. select task.id as taskId, task.name as taskName, stages.stages_name as stagesName,task.group_id as groupId
  248. from task left join stages on stages.id = task.stages_id
  249. where task.project_id = #{projectId}
  250. <if test="userId != null">
  251. and executor_id like '%${userId}%'
  252. </if>
  253. <if test="stage != null">
  254. and stages.stages_name = #{stage}
  255. </if>
  256. <if test="groupId != null">
  257. and task.group_id = #{groupId}
  258. </if>
  259. and task_status = 0 order by task.id desc limit 300
  260. </select>
  261. <select id="selectMilepost" resultType="com.management.platform.entity.Task">
  262. select * from task where
  263. task.task_type=1
  264. <if test="ids!=null">
  265. and task.project_id in
  266. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  267. #{item}
  268. </foreach>
  269. </if>
  270. and task.finish_date in
  271. (select MAX(task.finish_date)from task where
  272. task.task_type=1
  273. <if test="ids!=null">
  274. and task.project_id in
  275. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  276. #{item}
  277. </foreach>
  278. </if>
  279. group by project_id) group by task.project_id
  280. </select>
  281. <select id="userTaskCompleteDetail" resultType="java.util.Map">
  282. SELECT u.id as userId, u.name AS userName,u.corpwx_userid AS corpWxUserId,d.corpwx_deptid AS corpWxDeptId,d.department_name AS deptName,COUNT(t.name) AS allNum,COUNT(CASE WHEN t.task_status=0 THEN 1 END) AS noCompletedNum,COUNT(CASE WHEN t.task_status=1 THEN 1 END) AS completedNum,
  283. COUNT(CASE WHEN t.finish_date &lt;= t.end_date AND t.task_status=1 THEN 1 END) AS onTimeNum,COUNT(CASE WHEN t.finish_date>t.end_date AND t.task_status=1 THEN 1 END) AS noOnTimeNum,
  284. CONCAT(FORMAT(COUNT(CASE WHEN t.task_status=0 THEN 1 END)/COUNT(t.name)*100, 2), '%') AS noCompletedPercent,CONCAT(FORMAT(COUNT(CASE WHEN t.finish_date &lt;= t.end_date AND t.task_status=1 THEN 1 END)/COUNT(t.name)*100, 2), '%') AS onTimePercent
  285. FROM
  286. task_executor te
  287. LEFT JOIN `user` u ON te.executor_id=u.id
  288. LEFT JOIN department d ON u.department_id=d.department_id
  289. LEFT JOIN task t ON te.task_id=t.`id`
  290. WHERE u.company_id=#{companyId}
  291. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  292. AND t.start_date &lt; #{endDate} AND t.end_date &gt; #{startDate}
  293. </if>
  294. <if test="userId!=null and userId!=''">
  295. and u.id=#{userId}
  296. </if>
  297. <if test="deptId!=null">
  298. and d.department_id=#{deptId}
  299. </if>
  300. <if test="list!=null and list.size()>0">
  301. and d.department_id in
  302. <foreach collection="list" item="item" open="(" close=")" separator=",">
  303. #{item}
  304. </foreach>
  305. </if>
  306. group by te.executor_id
  307. <if test="pageStart != null and pageSize != null">
  308. limit #{pageStart}, #{pageSize}
  309. </if>
  310. </select>
  311. <select id="userTaskCompleteDetailCount" resultType="java.lang.Integer">
  312. select count(1) from (
  313. SELECT u.id as userId
  314. FROM
  315. task_executor te
  316. LEFT JOIN `user` u ON te.executor_id=u.id
  317. LEFT JOIN department d ON u.department_id=d.department_id
  318. LEFT JOIN task t ON te.task_id=t.`id`
  319. WHERE u.company_id=#{companyId}
  320. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  321. AND t.start_date &lt; #{endDate} AND t.end_date &gt; #{startDate}
  322. </if>
  323. <if test="userId!=null and userId!=''">
  324. and u.id=#{userId}
  325. </if>
  326. <if test="deptId!=null">
  327. and d.department_id=#{deptId}
  328. </if>
  329. <if test="list!=null and list.size()>0">
  330. and d.department_id in
  331. <foreach collection="list" item="item" open="(" close=")" separator=",">
  332. #{item}
  333. </foreach>
  334. </if>
  335. group by te.executor_id
  336. ) as total
  337. </select>
  338. <select id="getTaskByUserId" resultType="java.util.Map">
  339. SELECT t.`name` AS taskName,GROUP_CONCAT(u.name) AS executorNames,GROUP_CONCAT(u.corpwx_userid) AS executorCorpWxUserIds,
  340. date_format(t.`start_date`,'%Y-%m-%d') AS startDate,date_format(t.`end_date`,'%Y-%m-%d') AS endDate,date_format(t.`finish_date`,'%Y-%m-%d') AS finishDate,
  341. (CASE t.`task_status` WHEN 0 THEN '进行中' WHEN 1 THEN '已完成' ELSE '已撤销' END) AS stateValue
  342. FROM
  343. task_executor te
  344. LEFT JOIN `user` u ON te.executor_id=u.id
  345. LEFT JOIN task t ON te.task_id=t.`id`
  346. WHERE t.start_date &lt; #{endDate} AND t.end_date &gt; #{startDate} AND FIND_IN_SET(#{userId},t.`executor_id`) GROUP BY t.`id`
  347. <if test="pageStart != null and pageSize != null">
  348. limit #{pageStart}, #{pageSize}
  349. </if>
  350. </select>
  351. <select id="getTaskByUserIdCount" resultType="java.lang.Integer">
  352. select count(1) from (
  353. SELECT t.`name` AS taskName
  354. FROM
  355. task_executor te
  356. LEFT JOIN `user` u ON te.executor_id=u.id
  357. LEFT JOIN task t ON te.task_id=t.`id`
  358. WHERE t.start_date &lt; #{endDate} AND t.end_date &gt; #{startDate} AND FIND_IN_SET(#{userId},t.`executor_id`) GROUP BY t.`id`
  359. )as total
  360. </select>
  361. <select id="getTaskWithProjectNameWithCharge" resultMap="RichResultMap">
  362. 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,
  363. task.plan_hours, task.task_type, task.task_level, task.task_status, task.`finish_date`, project.`project_name`, stages.stages_name,department.department_name
  364. ,task.charge_one_id,task.charge_one_status,task.charge_two_id,task.charge_two_status,task.charge_stage,task.final_charge_status
  365. FROM task LEFT JOIN project ON project.id = task.`project_id`
  366. left join stages on stages.id = task.stages_id
  367. left join department on department.department_id=project.dept_id
  368. ${ew.customSqlSegment}
  369. <if test="deptIds!=null and deptIds.size()>0">
  370. and project.dept_id in
  371. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  372. #{item}
  373. </foreach>
  374. </if>
  375. <if test="userId != null and userId != ''">
  376. and task.final_charge_status = 0
  377. and case task.charge_stage
  378. when 1 then task.charge_one_id = #{userId} and task.charge_one_status = 0
  379. when 2 then task.charge_two_id = #{userId} and task.charge_two_status = 0
  380. end
  381. </if>
  382. ORDER BY task.indate desc
  383. <if test="pageStart != null and pageSize != null">
  384. limit #{pageStart}, #{pageSize}
  385. </if>
  386. </select>
  387. <select id="selectCountWithCharge" resultType="java.lang.Integer">
  388. SELECT count(*)
  389. FROM task
  390. ${ew.customSqlSegment}
  391. <if test="userId != null and userId != ''">
  392. and task.final_charge_status = 0
  393. and case task.charge_stage
  394. when 1 then task.charge_one_id = #{userId} and task.charge_one_status = 0
  395. when 2 then task.charge_two_id = #{userId} and task.charge_two_status = 0
  396. end
  397. </if>
  398. </select>
  399. <select id="getTaskChargePage" resultType="com.management.platform.entity.vo.TaskChargePageVO">
  400. select tmp1.*,user.name as finalChargeName
  401. from
  402. (
  403. select tf.task_id,task.creater_id,task.name as taskName,task.charge_stage
  404. ,task.charge_one_id,task.charge_one_status,task.executor_id,task.group_id
  405. ,task.charge_two_id,task.charge_two_status,p.id as projectId,p.project_name,
  406. case task.charge_stage
  407. when 1 then task.charge_one_id
  408. when 2 then task.charge_two_id
  409. end as finalChargeId
  410. from
  411. task_files tf
  412. left join task on tf.task_id = task.id
  413. left join project p on task.project_id = p.id
  414. <where>
  415. task.task_status = 0 and task.final_charge_status = 0
  416. and case task.charge_stage
  417. when 1 then (p.incharger_id = task.charge_one_id and task.charge_one_status != 2)
  418. when 2 then (p.incharger_id = task.charge_two_id and task.charge_two_status != 2)
  419. end
  420. <if test="queryBO.projectId != null">
  421. and tf.project_id = #{queryBO.projectId}
  422. </if>
  423. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  424. and task.name like concat('%',#{queryBO.taskName},'%')
  425. </if>
  426. <if test="deptIds!=null and deptIds.size()>0">
  427. and p.dept_id in
  428. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  429. #{item}
  430. </foreach>
  431. </if>
  432. </where>
  433. )
  434. tmp1 left join user on tmp1.finalChargeId = user.id
  435. where tmp1.finalChargeId = #{queryBO.userId}
  436. group by tmp1.task_id
  437. union all
  438. select tmp1.*,user.name as finalChargeName
  439. from
  440. (
  441. select tf.task_id,task.creater_id,task.name as taskName,task.charge_stage
  442. ,task.charge_one_id,task.charge_one_status,task.executor_id,task.group_id
  443. ,task.charge_two_id,task.charge_two_status,project.id as projectId,project.project_name,
  444. case task.charge_stage
  445. when 1 then task.charge_one_id
  446. when 2 then task.charge_two_id
  447. end as finalChargeId
  448. from
  449. task_files tf
  450. left join task on tf.task_id = task.id
  451. left join project on task.project_id = project.id
  452. left join user on task.creater_id = user.id
  453. left join department d on user.department_id = d.department_id
  454. <where>
  455. task.task_status = 0 and task.final_charge_status = 0
  456. and case task.charge_stage
  457. when 1 then (d.manager_id = task.charge_one_id and task.charge_one_status != 2)
  458. when 2 then (d.manager_id = task.charge_two_id and task.charge_two_status != 2)
  459. end
  460. <if test="queryBO.projectId != null">
  461. and tf.project_id = #{queryBO.projectId}
  462. </if>
  463. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  464. and task.name like concat('%',#{queryBO.taskName},'%')
  465. </if>
  466. <if test="deptIds!=null and deptIds.size()>0">
  467. and project.dept_id in
  468. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  469. #{item}
  470. </foreach>
  471. </if>
  472. </where>
  473. )
  474. tmp1 left join user on tmp1.finalChargeId = user.id
  475. where tmp1.finalChargeId = #{queryBO.userId}
  476. group by tmp1.task_id
  477. ORDER BY task_id desc
  478. <if test="queryBO.pageIndex != null and queryBO.pageSize != null">
  479. limit #{queryBO.pageIndex}, #{queryBO.pageSize}
  480. </if>
  481. </select>
  482. <select id="getTaskChargePageTotal" resultType="java.lang.Integer">
  483. select count(*)
  484. from(
  485. select tmp1.*,user.name as finalChargeName
  486. from
  487. (
  488. select tf.task_id,task.creater_id,task.name,task.charge_stage
  489. ,task.charge_one_id,task.charge_one_status,task.executor_id
  490. ,task.charge_two_id,task.charge_two_status,p.id,p.project_name,
  491. case task.charge_stage
  492. when 1 then task.charge_one_id
  493. when 2 then task.charge_two_id
  494. end as finalChargeId
  495. from
  496. task_files tf
  497. left join task on tf.task_id = task.id
  498. left join project p on task.project_id = p.id
  499. <where>
  500. task.task_status = 0 and task.final_charge_status = 0
  501. and case task.charge_stage
  502. when 1 then (p.incharger_id = task.charge_one_id and task.charge_one_status != 2)
  503. when 2 then (p.incharger_id = task.charge_two_id and task.charge_two_status != 2)
  504. end
  505. <if test="queryBO.projectId != null">
  506. and tf.project_id = #{queryBO.projectId}
  507. </if>
  508. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  509. and task.task_name like concat('%',#{queryBO.taskName},'%')
  510. </if>
  511. <if test="deptIds!=null and deptIds.size()>0">
  512. and p.dept_id in
  513. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  514. #{item}
  515. </foreach>
  516. </if>
  517. </where>
  518. )
  519. tmp1 left join user on tmp1.finalChargeId = user.id
  520. where tmp1.finalChargeId = #{queryBO.userId}
  521. group by tmp1.task_id
  522. union all
  523. select tmp1.*,user.name as finalChargeName
  524. from
  525. (
  526. select tf.task_id,task.creater_id,task.name,task.charge_stage
  527. ,task.charge_one_id,task.charge_one_status,task.executor_id
  528. ,task.charge_two_id,task.charge_two_status,project.id,project.project_name,
  529. case task.charge_stage
  530. when 1 then task.charge_one_id
  531. when 2 then task.charge_two_id
  532. end as finalChargeId
  533. from
  534. task_files tf
  535. left join task on tf.task_id = task.id
  536. left join project on task.project_id = project.id
  537. left join user on task.creater_id = user.id
  538. left join department d on user.department_id = d.department_id
  539. <where>
  540. task.task_status = 0 and task.final_charge_status = 0
  541. and case task.charge_stage
  542. when 1 then (d.manager_id = task.charge_one_id and task.charge_one_status != 2)
  543. when 2 then (d.manager_id = task.charge_two_id and task.charge_two_status != 2)
  544. end
  545. <if test="queryBO.projectId != null">
  546. and tf.project_id = #{queryBO.projectId}
  547. </if>
  548. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  549. and task.task_name like concat('%',#{queryBO.taskName},'%')
  550. </if>
  551. <if test="deptIds!=null and deptIds.size()>0">
  552. and project.dept_id in
  553. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  554. #{item}
  555. </foreach>
  556. </if>
  557. </where>
  558. )
  559. tmp1 left join user on tmp1.finalChargeId = user.id
  560. where tmp1.finalChargeId = #{queryBO.userId}
  561. group by tmp1.task_id
  562. )tmpAll
  563. </select>
  564. </mapper>