TaskMapper.xml 39 KB

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