TaskMapper.xml 46 KB

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