TaskMapper.xml 44 KB

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