TaskMapper.xml 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. <result column="plan_cost" property="planCost" />
  35. </resultMap>
  36. <resultMap id="timeResultMap" type="com.management.platform.entity.TimeTask" >
  37. <id column="id" property="id" />
  38. <result column="name" property="name" />
  39. <result column="task_desc" property="taskDesc" />
  40. <result column="creater_id" property="createrId" />
  41. <result column="creater_name" property="createrName" />
  42. <result column="creator_color" property="creatorColor" />
  43. <result column="executor_id" property="executorId" />
  44. <result column="executor_name" property="executorName" />
  45. <result column="executor_color" property="executorColor" />
  46. <result column="task_level" property="taskLevel" />
  47. <result column="task_status" property="taskStatus" />
  48. <result column="create_date" property="createDate" />
  49. <result column="end_date" property="endDate" />
  50. <result column="project_id" property="projectId" />
  51. <result column="stages_id" property="stagesId" />
  52. <result column="company_id" property="companyId" />
  53. <result column="indate" property="indate" />
  54. <result column="parent_tid" property="parentTid" />
  55. <result column="group_id" property="groupId" />
  56. <result column="seq" property="seq" />
  57. <result column="plan_hours" property="planHours" />
  58. <result column="task_type" property="taskType" />
  59. <result column="parent_tname" property="parentTname" />
  60. <result column="finish_date" property="finishDate" />
  61. <result column="start_date" property="startDate" />
  62. <result column="meeting_id" property="meetingId" />
  63. <result column="ahead_tid" property="aheadTid" />
  64. <result column="sap_task_code" property="sapTaskCode" />
  65. <result column="work_hours" property="workHours" />
  66. </resultMap>
  67. <resultMap id="RichResultMap" type="com.management.platform.entity.Task">
  68. <id column="id" property="id" />
  69. <result column="name" property="name" />
  70. <result column="task_desc" property="taskDesc" />
  71. <result column="creater_id" property="createrId" />
  72. <result column="creater_name" property="createrName" />
  73. <result column="creator_color" property="creatorColor" />
  74. <result column="executor_id" property="executorId" />
  75. <result column="executor_name" property="executorName" />
  76. <result column="executor_color" property="executorColor" />
  77. <result column="task_level" property="taskLevel" />
  78. <result column="task_status" property="taskStatus" />
  79. <result column="create_date" property="createDate" />
  80. <result column="end_date" property="endDate" />
  81. <result column="project_id" property="projectId" />
  82. <result column="stages_id" property="stagesId" />
  83. <result column="company_id" property="companyId" />
  84. <result column="indate" property="indate" />
  85. <result column="parent_tid" property="parentTid" />
  86. <result column="group_id" property="groupId" />
  87. <result column="seq" property="seq" />
  88. <result column="plan_hours" property="planHours" />
  89. <result column="task_type" property="taskType" />
  90. <result column="parent_tname" property="parentTname" />
  91. <result column="finish_date" property="finishDate" />
  92. <result column="project_name" property="projectName" />
  93. <result column="start_date" property="startDate" />
  94. <result column="meeting_id" property="meetingId" />
  95. <result column="ahead_tid" property="aheadTid" />
  96. <result column="sap_task_code" property="sapTaskCode" />
  97. <result column="stages_name" property="stagesName" />
  98. <result column="department_name" property="departmentName" />
  99. <!-- <result column="charge_one_id" property="chargeOneId" />-->
  100. <!-- <result column="charge_one_status" property="chargeOneStatus" />-->
  101. <!-- <result column="charge_one_time" property="chargeOneTime" />-->
  102. <!-- <result column="charge_two_id" property="chargeTwoId" />-->
  103. <!-- <result column="charge_two_status" property="chargeTwoStatus" />-->
  104. <!-- <result column="charge_two_time" property="chargeTwoTime" />-->
  105. <!-- <result column="charge_stage" property="chargeStage" />-->
  106. <!-- <result column="final_charge_status" property="finalChargeStatus" />-->
  107. <!-- <result column="file_reject_reason" property="fileRejectReason"></result>-->
  108. </resultMap>
  109. <!-- 通用查询结果列 -->
  110. <sql id="Base_Column_List">
  111. 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, plan_cost
  112. </sql>
  113. <select id="simpleList" resultMap="BaseResultMap">
  114. 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
  115. from task
  116. ${ew.customSqlSegment}
  117. <if test="start!=null and size!=null">
  118. limit #{start},#{size}
  119. </if>
  120. </select>
  121. <select id="nameList" resultMap="BaseResultMap">
  122. select id, name, task_level, stages_id, company_id, indate, group_id, seq,task_type,task_desc
  123. from task
  124. ${ew.customSqlSegment}
  125. </select>
  126. <!--计算执行人任务分布-->
  127. <select id="getExecutorPanel" resultType="java.util.Map">
  128. SELECT IFNULL(b.executor_id,0) as executorId,IFNULL( b.executor_name,'待认领') as executorName, count(1) AS taskCount
  129. FROM task a left join task_executor b on b.task_id = a.id
  130. WHERE a.project_id = #{projectId}
  131. GROUP BY b.executor_id
  132. </select>
  133. <!--计算执行人任务计划工时-->
  134. <select id="getExecutorPlanHour" resultType="java.util.Map">
  135. SELECT IFNULL(b.executor_id,0) as executorId,IFNULL( b.executor_name,'待认领') as executorName, sum(a.plan_hours) AS taskHours
  136. FROM task a left join task_executor b on b.task_id = a.id
  137. WHERE a.project_id = #{projectId}
  138. GROUP BY b.executor_id
  139. </select>
  140. <!--计算任务列表的任务分布-->
  141. <select id="getStagesPanel" resultType="java.util.Map">
  142. SELECT a.stages_id AS stagesId, stages.`stages_name` AS name, COUNT(1) AS value
  143. FROM task a
  144. LEFT JOIN stages ON stages.id = a.`stages_id`
  145. WHERE a.project_id = #{projectId}
  146. GROUP BY a.stages_id
  147. ORDER BY stages.`sequence`
  148. </select>
  149. <!--计算耗时排名前十的任务-->
  150. <select id="getTopCostTask" resultType="java.util.Map">
  151. SELECT task.id , task.name AS name, IFNULL(SUM(report.`working_time`),0) AS value FROM task
  152. LEFT JOIN report ON report.`task_id` = task.id
  153. WHERE task.project_id = #{projectId} and report.state = 1
  154. GROUP BY task.id ORDER BY SUM(report.`working_time`) DESC LIMIT 10
  155. </select>
  156. <!-- 查询任务实际工时和计划工时对比,仅查询有实际工时的数据 -->
  157. <select id="getTaskTimeCompare" resultType="java.util.Map">
  158. 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
  159. task_executor te
  160. LEFT JOIN user u ON te.executor_id=u.id
  161. LEFT JOIN task t ON t.id=te.task_id
  162. LEFT JOIN project p ON p.id=t.project_id
  163. WHERE p.id= #{projectId}
  164. <if test="deptId!=null and deptId">
  165. and u.department_id=#{deptId}
  166. </if>
  167. GROUP BY t.id
  168. </select>
  169. <!--查询任务,带实际工时-->
  170. <select id="getTaskWithWorktime" resultMap="timeResultMap">
  171. SELECT task.* , IFNULL(SUM(report.`working_time`),0) AS work_hours FROM task
  172. LEFT JOIN report ON report.`task_id` = task.id and report.state = 1
  173. WHERE task.project_id = #{projectId}
  174. <if test="taskType != null" >
  175. and task.task_type = #{taskType}
  176. </if>
  177. GROUP BY task.id
  178. </select>
  179. <select id="getProjectTask" resultType="java.util.Map">
  180. 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`,
  181. (SELECT IFNULL(SUM(working_time),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS real_hours,
  182. (SELECT IFNULL(SUM(cost),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS real_cost,
  183. task.`task_status`, task.`task_type`,
  184. project.`project_code`, project.`project_name`,tg.name as groupName
  185. FROM task
  186. LEFT JOIN project ON project.id = task.`project_id`
  187. LEFT JOIN task_group tg on tg.id=task.`group_id`
  188. WHERE project.`company_id` = #{companyId}
  189. <if test="projectId != null">
  190. and task.project_id = #{projectId}
  191. </if>
  192. <if test="groupId != null">
  193. and task.group_id = #{groupId}
  194. </if>
  195. <if test="taskType!=null">
  196. and task.task_type=#{taskType}
  197. </if>
  198. <if test="inchagerIds!=null and inchagerIds.size()>0">
  199. and task.project_id in
  200. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  201. #{item}
  202. </foreach>
  203. </if>
  204. ORDER BY project.is_public desc, project.id ASC, task.stages_id asc, task.seq asc
  205. <if test="pageStart != null and pageSize != null">
  206. limit #{pageStart}, #{pageSize}
  207. </if>
  208. </select>
  209. <select id="getProjectTaskCount" resultType="java.lang.Integer">
  210. SELECT count(1) as total FROM task LEFT JOIN project ON project.id = task.`project_id`
  211. WHERE project.`company_id` = #{companyId}
  212. <if test="projectId != null">
  213. and task.project_id = #{projectId}
  214. </if>
  215. <if test="groupId != null">
  216. and task.group_id = #{groupId}
  217. </if>
  218. <if test="taskType!=null">
  219. and task.task_type=#{taskType}
  220. </if>
  221. <if test="inchagerIds!=null and inchagerIds.size()>0">
  222. and task.project_id in
  223. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  224. #{item}
  225. </foreach>
  226. </if>
  227. </select>
  228. <select id="getTaskPlanRealData" resultType="java.util.Map">
  229. SELECT task.id,task.`name`,task_executor.id as teId, DATE_FORMAT(task.`end_date`, '%Y-%m-%d') as endDate, task_executor.`plan_hours` as planHours,task.plan_cost as planCost,
  230. (SELECT IFNULL(SUM(working_time),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS realHours,
  231. task_executor.executor_id as executorId,task_executor.executor_name AS executorName,
  232. IF(task_executor.real_cost = 0, task.plan_cost, task_executor.real_cost) AS realCost,
  233. task.`task_status` as taskStatus, task.`task_type` as taskType,
  234. project.`project_code` as projectCode, project.`project_name` as projectName
  235. FROM task
  236. LEFT JOIN project ON project.id = task.`project_id`
  237. left join task_executor on task_executor.task_id=task.id
  238. WHERE project.`company_id` = #{companyId}
  239. <if test="projectId != null">
  240. and task.project_id = #{projectId}
  241. </if>
  242. <if test="taskType!=null">
  243. and task.task_type=#{taskType}
  244. </if>
  245. <if test="inchagerIds!=null and inchagerIds.size()>0">
  246. and task.project_id in
  247. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  248. #{item}
  249. </foreach>
  250. </if>
  251. ORDER BY project.is_public desc, project.id ASC, task.stages_id asc, task.seq asc
  252. <if test="pageStart != null and pageSize != null">
  253. limit #{pageStart}, #{pageSize}
  254. </if>
  255. </select>
  256. <select id="getTaskPlanRealCount" resultType="java.lang.Integer">
  257. SELECT count(1) as total FROM task LEFT JOIN project ON project.id = task.`project_id`
  258. left join task_executor on task_executor.task_id=task.id
  259. WHERE project.`company_id` = #{companyId}
  260. <if test="projectId != null">
  261. and task.project_id = #{projectId}
  262. </if>
  263. <if test="taskType!=null">
  264. and task.task_type=#{taskType}
  265. </if>
  266. <if test="inchagerIds!=null and inchagerIds.size()>0">
  267. and task.project_id in
  268. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  269. #{item}
  270. </foreach>
  271. </if>
  272. </select>
  273. <select id="getTaskWithProjectName" resultMap="RichResultMap">
  274. 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,
  275. task.plan_hours, task.task_type, task.task_level, task.task_status, task.`finish_date`, project.`project_name`, stages.stages_name,department.department_name
  276. <!-- ,task.charge_one_id,task.charge_one_status,task.charge_two_id,task.charge_two_status,task.charge_stage,task.final_charge_status -->
  277. FROM task LEFT JOIN project ON project.id = task.`project_id`
  278. left join stages on stages.id = task.stages_id
  279. left join department on department.department_id=project.dept_id
  280. ${ew.customSqlSegment}
  281. <if test="deptIds!=null and deptIds.size()>0">
  282. and project.dept_id in
  283. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  284. #{item}
  285. </foreach>
  286. </if>
  287. ORDER BY task.indate desc
  288. <if test="pageStart != null and pageSize != null">
  289. limit #{pageStart}, #{pageSize}
  290. </if>
  291. </select>
  292. <select id="recentSimpleList" resultType="java.util.Map">
  293. select task.id as taskId, task.name as taskName, stages.stages_name as stagesName,task.group_id as groupId
  294. from task left join stages on stages.id = task.stages_id
  295. where task.project_id = #{projectId}
  296. <if test="userId != null">
  297. and executor_id like '%${userId}%'
  298. </if>
  299. <if test="stage != null">
  300. and stages.stages_name = #{stage}
  301. </if>
  302. <if test="groupId != null">
  303. and task.group_id = #{groupId}
  304. </if>
  305. and task_status = 0 order by task.id desc limit 300
  306. </select>
  307. <select id="selectMilepost" resultType="com.management.platform.entity.Task">
  308. select * from task where
  309. task.task_type=1
  310. <if test="ids!=null">
  311. and task.project_id in
  312. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  313. #{item}
  314. </foreach>
  315. </if>
  316. and task.finish_date in
  317. (select MAX(task.finish_date)from task where
  318. task.task_type=1
  319. <if test="ids!=null">
  320. and task.project_id in
  321. <foreach collection="ids" index="index" close=")" open="(" separator="," item="item">
  322. #{item}
  323. </foreach>
  324. </if>
  325. group by project_id) group by task.project_id
  326. </select>
  327. <select id="userTaskCompleteDetail" resultType="java.util.Map">
  328. 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,
  329. 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,
  330. 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
  331. FROM
  332. task_executor te
  333. LEFT JOIN `user` u ON te.executor_id=u.id
  334. LEFT JOIN department d ON u.department_id=d.department_id
  335. LEFT JOIN task t ON te.task_id=t.`id`
  336. WHERE u.company_id=#{companyId}
  337. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  338. AND t.start_date &lt; #{endDate} AND t.end_date &gt; #{startDate}
  339. </if>
  340. <if test="userId!=null and userId!=''">
  341. and u.id=#{userId}
  342. </if>
  343. <if test="deptId!=null">
  344. and d.department_id=#{deptId}
  345. </if>
  346. <if test="list!=null and list.size()>0">
  347. and d.department_id in
  348. <foreach collection="list" item="item" open="(" close=")" separator=",">
  349. #{item}
  350. </foreach>
  351. </if>
  352. group by te.executor_id
  353. <if test="pageStart != null and pageSize != null">
  354. limit #{pageStart}, #{pageSize}
  355. </if>
  356. </select>
  357. <select id="userTaskCompleteDetailCount" resultType="java.lang.Integer">
  358. select count(1) from (
  359. SELECT u.id as userId
  360. FROM
  361. task_executor te
  362. LEFT JOIN `user` u ON te.executor_id=u.id
  363. LEFT JOIN department d ON u.department_id=d.department_id
  364. LEFT JOIN task t ON te.task_id=t.`id`
  365. WHERE u.company_id=#{companyId}
  366. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  367. AND t.start_date &lt; #{endDate} AND t.end_date &gt; #{startDate}
  368. </if>
  369. <if test="userId!=null and userId!=''">
  370. and u.id=#{userId}
  371. </if>
  372. <if test="deptId!=null">
  373. and d.department_id=#{deptId}
  374. </if>
  375. <if test="list!=null and list.size()>0">
  376. and d.department_id in
  377. <foreach collection="list" item="item" open="(" close=")" separator=",">
  378. #{item}
  379. </foreach>
  380. </if>
  381. group by te.executor_id
  382. ) as total
  383. </select>
  384. <select id="getTaskByUserId" resultType="java.util.Map">
  385. SELECT t.`name` AS taskName,GROUP_CONCAT(u.name) AS executorNames,GROUP_CONCAT(u.corpwx_userid) AS executorCorpWxUserIds,
  386. 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,
  387. (CASE t.`task_status` WHEN 0 THEN '进行中' WHEN 1 THEN '已完成' ELSE '已撤销' END) AS stateValue
  388. FROM
  389. task_executor te
  390. LEFT JOIN `user` u ON te.executor_id=u.id
  391. LEFT JOIN task t ON te.task_id=t.`id`
  392. WHERE t.start_date &lt; #{endDate} AND t.end_date &gt; #{startDate} AND FIND_IN_SET(#{userId},t.`executor_id`) GROUP BY t.`id`
  393. <if test="pageStart != null and pageSize != null">
  394. limit #{pageStart}, #{pageSize}
  395. </if>
  396. </select>
  397. <select id="getTaskByUserIdCount" resultType="java.lang.Integer">
  398. select count(1) from (
  399. SELECT t.`name` AS taskName
  400. FROM
  401. task_executor te
  402. LEFT JOIN `user` u ON te.executor_id=u.id
  403. LEFT JOIN task t ON te.task_id=t.`id`
  404. WHERE t.start_date &lt; #{endDate} AND t.end_date &gt; #{startDate} AND FIND_IN_SET(#{userId},t.`executor_id`) GROUP BY t.`id`
  405. )as total
  406. </select>
  407. <select id="getTaskWithProjectNameWithCharge" resultMap="RichResultMap">
  408. 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,
  409. task.plan_hours, task.task_type, task.task_level, task.task_status, task.`finish_date`, project.`project_name`, stages.stages_name,department.department_name
  410. <!-- ,task.charge_one_id,task.charge_one_status,task.charge_two_id,task.charge_two_status,task.charge_stage,task.final_charge_status-->
  411. FROM task LEFT JOIN project ON project.id = task.`project_id`
  412. left join stages on stages.id = task.stages_id
  413. left join department on department.department_id=project.dept_id
  414. ${ew.customSqlSegment}
  415. <if test="deptIds!=null and deptIds.size()>0">
  416. and project.dept_id in
  417. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  418. #{item}
  419. </foreach>
  420. </if>
  421. <if test="userId != null and userId != ''">
  422. and task.final_charge_status = 0
  423. and case task.charge_stage
  424. when 1 then task.charge_one_id = #{userId} and task.charge_one_status = 0
  425. when 2 then task.charge_two_id = #{userId} and task.charge_two_status = 0
  426. end
  427. </if>
  428. ORDER BY task.indate desc
  429. <if test="pageStart != null and pageSize != null">
  430. limit #{pageStart}, #{pageSize}
  431. </if>
  432. </select>
  433. <select id="selectCountWithCharge" resultType="java.lang.Integer">
  434. SELECT count(*)
  435. FROM task
  436. ${ew.customSqlSegment}
  437. <if test="userId != null and userId != ''">
  438. and task.final_charge_status = 0
  439. and case task.charge_stage
  440. when 1 then task.charge_one_id = #{userId} and task.charge_one_status = 0
  441. when 2 then task.charge_two_id = #{userId} and task.charge_two_status = 0
  442. end
  443. </if>
  444. </select>
  445. <select id="getTaskChargePage" resultType="com.management.platform.entity.vo.TaskChargePageVO">
  446. select tmp1.*,user.name as finalChargeName
  447. from
  448. (
  449. select tf.task_id,task.creater_id,task.name as taskName,task.charge_stage
  450. ,task.charge_one_id,task.charge_one_status,task.executor_id,task.group_id
  451. ,task.charge_two_id,task.charge_two_status,p.id as projectId,p.project_name,
  452. case task.charge_stage
  453. when 1 then task.charge_one_id
  454. when 2 then task.charge_two_id
  455. end as finalChargeId
  456. from
  457. task_files tf
  458. left join task on tf.task_id = task.id
  459. left join project p on task.project_id = p.id
  460. <where>
  461. task.task_status = 0 and task.final_charge_status = 0
  462. and case task.charge_stage
  463. when 1 then (p.incharger_id = task.charge_one_id and task.charge_one_status != 2)
  464. when 2 then (p.incharger_id = task.charge_two_id and task.charge_two_status != 2)
  465. end
  466. <if test="queryBO.projectId != null">
  467. and tf.project_id = #{queryBO.projectId}
  468. </if>
  469. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  470. and task.name like concat('%',#{queryBO.taskName},'%')
  471. </if>
  472. <if test="deptIds!=null and deptIds.size()>0">
  473. and p.dept_id in
  474. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  475. #{item}
  476. </foreach>
  477. </if>
  478. </where>
  479. )
  480. tmp1 left join user on tmp1.finalChargeId = user.id
  481. where tmp1.finalChargeId = #{queryBO.userId}
  482. group by tmp1.task_id
  483. union all
  484. select tmp1.*,user.name as finalChargeName
  485. from
  486. (
  487. select tf.task_id,task.creater_id,task.name as taskName,task.charge_stage
  488. ,task.charge_one_id,task.charge_one_status,task.executor_id,task.group_id
  489. ,task.charge_two_id,task.charge_two_status,project.id as projectId,project.project_name,
  490. case task.charge_stage
  491. when 1 then task.charge_one_id
  492. when 2 then task.charge_two_id
  493. end as finalChargeId
  494. from
  495. task_files tf
  496. left join task on tf.task_id = task.id
  497. left join project on task.project_id = project.id
  498. left join user on task.creater_id = user.id
  499. left join department d on user.department_id = d.department_id
  500. <where>
  501. task.task_status = 0 and task.final_charge_status = 0
  502. and case task.charge_stage
  503. when 1 then (d.manager_id = task.charge_one_id and task.charge_one_status != 2)
  504. when 2 then (d.manager_id = task.charge_two_id and task.charge_two_status != 2)
  505. end
  506. <if test="queryBO.projectId != null">
  507. and tf.project_id = #{queryBO.projectId}
  508. </if>
  509. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  510. and task.name like concat('%',#{queryBO.taskName},'%')
  511. </if>
  512. <if test="deptIds!=null and deptIds.size()>0">
  513. and project.dept_id in
  514. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  515. #{item}
  516. </foreach>
  517. </if>
  518. </where>
  519. )
  520. tmp1 left join user on tmp1.finalChargeId = user.id
  521. where tmp1.finalChargeId = #{queryBO.userId}
  522. group by tmp1.task_id
  523. ORDER BY task_id desc
  524. <if test="queryBO.pageIndex != null and queryBO.pageSize != null">
  525. limit #{queryBO.pageIndex}, #{queryBO.pageSize}
  526. </if>
  527. </select>
  528. <select id="getTaskChargePageTotal" resultType="java.lang.Integer">
  529. select count(*)
  530. from(
  531. select tmp1.*,user.name as finalChargeName
  532. from
  533. (
  534. select tf.task_id,task.creater_id,task.name,task.charge_stage
  535. ,task.charge_one_id,task.charge_one_status,task.executor_id
  536. ,task.charge_two_id,task.charge_two_status,p.id,p.project_name,
  537. case task.charge_stage
  538. when 1 then task.charge_one_id
  539. when 2 then task.charge_two_id
  540. end as finalChargeId
  541. from
  542. task_files tf
  543. left join task on tf.task_id = task.id
  544. left join project p on task.project_id = p.id
  545. <where>
  546. task.task_status = 0 and task.final_charge_status = 0
  547. and case task.charge_stage
  548. when 1 then (p.incharger_id = task.charge_one_id and task.charge_one_status != 2)
  549. when 2 then (p.incharger_id = task.charge_two_id and task.charge_two_status != 2)
  550. end
  551. <if test="queryBO.projectId != null">
  552. and tf.project_id = #{queryBO.projectId}
  553. </if>
  554. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  555. and task.task_name like concat('%',#{queryBO.taskName},'%')
  556. </if>
  557. <if test="deptIds!=null and deptIds.size()>0">
  558. and p.dept_id in
  559. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  560. #{item}
  561. </foreach>
  562. </if>
  563. </where>
  564. )
  565. tmp1 left join user on tmp1.finalChargeId = user.id
  566. where tmp1.finalChargeId = #{queryBO.userId}
  567. group by tmp1.task_id
  568. union all
  569. select tmp1.*,user.name as finalChargeName
  570. from
  571. (
  572. select tf.task_id,task.creater_id,task.name,task.charge_stage
  573. ,task.charge_one_id,task.charge_one_status,task.executor_id
  574. ,task.charge_two_id,task.charge_two_status,project.id,project.project_name,
  575. case task.charge_stage
  576. when 1 then task.charge_one_id
  577. when 2 then task.charge_two_id
  578. end as finalChargeId
  579. from
  580. task_files tf
  581. left join task on tf.task_id = task.id
  582. left join project on task.project_id = project.id
  583. left join user on task.creater_id = user.id
  584. left join department d on user.department_id = d.department_id
  585. <where>
  586. task.task_status = 0 and task.final_charge_status = 0
  587. and case task.charge_stage
  588. when 1 then (d.manager_id = task.charge_one_id and task.charge_one_status != 2)
  589. when 2 then (d.manager_id = task.charge_two_id and task.charge_two_status != 2)
  590. end
  591. <if test="queryBO.projectId != null">
  592. and tf.project_id = #{queryBO.projectId}
  593. </if>
  594. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  595. and task.task_name like concat('%',#{queryBO.taskName},'%')
  596. </if>
  597. <if test="deptIds!=null and deptIds.size()>0">
  598. and project.dept_id in
  599. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  600. #{item}
  601. </foreach>
  602. </if>
  603. </where>
  604. )
  605. tmp1 left join user on tmp1.finalChargeId = user.id
  606. where tmp1.finalChargeId = #{queryBO.userId}
  607. group by tmp1.task_id
  608. )tmpAll
  609. </select>
  610. <resultMap id="taskFileChargeMap" type="com.management.platform.entity.vo.TaskFileChargePageVO">
  611. <result property="taskId" column="task_id"></result>
  612. <result property="taskName" column="taskName"></result>
  613. <result property="groupId" column="group_id"></result>
  614. <result property="executorId" column="executor_id"></result>
  615. <result property="projectId" column="projectId"></result>
  616. <result property="projectName" column="project_name"></result>
  617. <collection property="childFiles" ofType="com.management.platform.entity.TaskFiles">
  618. <result property="id" column="id"></result>
  619. <result property="documentName" column="document_name"></result>
  620. <result property="creatorId" column="creator_id"></result>
  621. <result property="creatorName" column="creator_name"></result>
  622. <result property="chargeOneId" column="charge_one_id"></result>
  623. <result property="chargeOneStatus" column="charge_one_status"></result>
  624. <result property="chargeOneTime" column="charge_one_time"></result>
  625. <result property="chargeTwoId" column="charge_two_id"></result>
  626. <result property="chargeTwoStatus" column="charge_two_status"></result>
  627. <result property="chargeTwoTime" column="charge_two_time"></result>
  628. <result property="chargeStage" column="charge_stage"></result>
  629. <result property="finalChargeStatus" column="final_charge_status"></result>
  630. <result property="fileRejectReason" column="file_reject_reason"></result>
  631. <result property="needFileCharge" column="need_file_charge"></result>
  632. </collection>
  633. </resultMap>
  634. <select id="getTaskFileChargePage" resultMap="taskFileChargeMap">
  635. select tf.task_id,task.name as taskName,task.group_id,task.executor_id
  636. ,p.id as projectId,p.project_name
  637. from task_files tf
  638. left join task on tf.task_id = task.id
  639. left join project p on task.project_id = p.id
  640. <where>
  641. tf.need_file_charge = 1
  642. and tf.final_charge_status = 0
  643. and task.task_status = 0
  644. and task.company_id = #{queryBO.companyId}
  645. and case tf.charge_stage
  646. when 1 then tf.charge_one_id = #{queryBO.userId} and tf.charge_one_status = 0
  647. when 2 then tf.charge_two_id = #{queryBO.userId} and tf.charge_two_status = 0
  648. end
  649. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  650. and task.name like concat('%',#{queryBO.taskName},'%')
  651. </if>
  652. <if test="deptIds!=null and deptIds.size()>0">
  653. and p.dept_id in
  654. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  655. #{item}
  656. </foreach>
  657. </if>
  658. </where>
  659. group by tf.task_id
  660. ORDER BY tf.task_id desc
  661. <if test="queryBO.pageIndex != null and queryBO.pageSize != null">
  662. limit #{queryBO.pageIndex}, #{queryBO.pageSize}
  663. </if>
  664. </select>
  665. <select id="getTaskFileChargePageTotal" resultType="java.lang.Integer">
  666. select count(*)
  667. from
  668. (
  669. select tf.task_id
  670. from task_files tf
  671. left join task on tf.task_id = task.id
  672. left join project p on task.project_id = p.id
  673. <where>
  674. tf.need_file_charge = 1
  675. and tf.final_charge_status = 0
  676. and task.task_status = 0
  677. and task.company_id = #{queryBO.companyId}
  678. and case tf.charge_stage
  679. when 1 then tf.charge_one_id = #{queryBO.userId} and tf.charge_one_status = 0
  680. when 2 then tf.charge_two_id = #{queryBO.userId} and tf.charge_two_status = 0
  681. end
  682. <if test="queryBO.taskName != null and queryBO.taskName != ''">
  683. and task.name like concat('%',#{queryBO.taskName},'%')
  684. </if>
  685. <if test="deptIds!=null and deptIds.size()>0">
  686. and p.dept_id in
  687. <foreach collection="deptIds" open="(" close=")" separator="," item="item">
  688. #{item}
  689. </foreach>
  690. </if>
  691. </where>
  692. group by tf.task_id
  693. )tmp1
  694. </select>
  695. <select id="getProjectAllTaskTimeCost"
  696. resultType="com.management.platform.entity.vo.ProjectTaskTimeCostVO">
  697. SELECT task.id as taskId,ifnull(task_executor.`plan_hours`,0) as planHours,
  698. (SELECT IFNULL(SUM(working_time),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS realHours,
  699. task_executor.executor_id as executorId
  700. FROM task
  701. LEFT JOIN project ON project.id = task.`project_id`
  702. left join task_executor on task_executor.task_id=task.id
  703. WHERE task.project_id = #{projectId}
  704. and project.id = #{projectId}
  705. </select>
  706. <select id="getProjectTaskTimeCostByIds" resultType="com.management.platform.entity.vo.ProjectTimeCostVO">
  707. select project_id,sum(planHours) as planHoursSum,sum(realHours) as realHoursSum
  708. from
  709. (
  710. SELECT task.project_id,task.id as taskId,ifnull(task_executor.`plan_hours`,0) as planHours,
  711. (SELECT IFNULL(SUM(working_time),0) FROM report WHERE report.`task_id` = task.id AND report.`state` = 1) AS realHours,
  712. task_executor.executor_id as executorId
  713. FROM task
  714. LEFT JOIN project ON project.id = task.`project_id`
  715. left join task_executor on task_executor.task_id=task.id
  716. WHERE task.project_id in
  717. <foreach collection="projectIds" item="projectId" separator="," open="(" close=")">
  718. #{projectId}
  719. </foreach>
  720. )tmp1
  721. group by project_id
  722. </select>
  723. </mapper>