WorkTaskRecordMapper.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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.dayou.mapper.WorkTaskRecordMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.WorkTaskRecord">
  6. <result column="id" property="id" />
  7. <result column="created" property="created" />
  8. <result column="modified" property="modified" />
  9. <result column="deleted" property="deleted" />
  10. <result column="instance_id" property="instanceId" />
  11. <result column="task_id" property="taskId" />
  12. <result column="handler_id" property="handlerId" />
  13. <result column="finished" property="finished" />
  14. <result column="finish_time" property="finishTime" />
  15. </resultMap>
  16. <!-- 通用查询结果列 -->
  17. <sql id="Base_Column_List">
  18. id,
  19. created,
  20. modified,
  21. deleted,
  22. instance_id, task_id, handler_id, finished, finish_time
  23. </sql>
  24. <update id="finishOpening">
  25. UPDATE work_task_record
  26. SET finished = 1,
  27. finish_time = now()
  28. WHERE
  29. instance_id = #{id}
  30. AND task_id = (
  31. SELECT
  32. wnt.id
  33. FROM
  34. `work_node_task` wnt
  35. LEFT JOIN work_node wn ON wn.id = wnt.node_id
  36. WHERE
  37. task_type = "OPENING"
  38. AND wnt.version = "LATEST"
  39. AND wn.flow_id = #{flowId}
  40. AND wnt.deleted = 0
  41. )
  42. AND deleted = 0
  43. </update>
  44. <select id="instanceNodeTasks" parameterType="java.lang.Long" resultType="com.dayou.dto.WorkNodeInstanceTaskDTO">
  45. SELECT
  46. wtr.id AS recordId,
  47. wtr.finished,
  48. wtr.handler_id,
  49. wnt.task_type,
  50. wnt.handler_permission,
  51. wnt.business_handle
  52. FROM
  53. work_task_record wtr
  54. LEFT JOIN work_node_task wnt ON wnt.id = wtr.task_id
  55. WHERE
  56. wtr.instance_id = #{instanceNodeId}
  57. AND wtr.deleted = 0
  58. </select>
  59. <select id="getNotBusinessHandleTaskId" parameterType="java.lang.Long" resultType="java.lang.Long">
  60. SELECT
  61. wtr.id
  62. FROM
  63. work_task_record wtr
  64. LEFT JOIN work_flow_node_instance wfni ON wtr.instance_id = wfni.id
  65. LEFT JOIN work_node_task wnt ON wtr.task_id = wnt.id
  66. WHERE
  67. wfni.id = #{instanceNodeId}
  68. AND wnt.deleted = 0
  69. AND wfni.deleted = 0
  70. AND wtr.deleted = 0
  71. AND wtr.finished = 0
  72. AND wnt.business_handle = 0
  73. </select>
  74. <select id="getInstanceTask" parameterType="java.lang.Long" resultType="com.dayou.vo.WorkTaskRecordVO">
  75. SELECT
  76. wtr.id,
  77. wfni.id AS instanceId,
  78. t.id AS taskId,
  79. u.name as handler,
  80. (case wtr.finished when 1 then '已完成' else '未完成' end) as finished,
  81. wtr.finish_time,
  82. t.description AS taskName,
  83. wfni.state AS nodeState
  84. FROM
  85. work_task_record wtr
  86. left join user u on u.id = wtr.handler_id
  87. LEFT JOIN work_node_task t ON t.id = wtr.task_id
  88. LEFT JOIN work_flow_node_instance wfni ON wfni.id = wtr.instance_id
  89. where wtr.instance_id = #{instanceId} and wtr.deleted = 0 and t.deleted = 0 and wfni.deleted = 0
  90. </select>
  91. <select id="taskTodoPage" parameterType="com.dayou.vo.TaskTodoVO" resultType="com.dayou.vo.TaskTodoVO">
  92. SELECT
  93. wfni.id,
  94. wtr.id as taskId,
  95. wfni.id AS currentNodeId,
  96. wfni.business_sub_id,
  97. wfni.business_sub_id as statementNo,
  98. wfni.business_min_id as reportNo,
  99. wfni.business_id,
  100. m.name as orderName,
  101. m.order_id,
  102. m.financial,
  103. m.allot_type,
  104. u1.name as clientManager,
  105. u2.name as principal,
  106. d.name as departmentName,
  107. m.business_object_type,
  108. wfni.name AS nodeName,
  109. wfni.code as nodeCode,
  110. u.name AS handler,
  111. wnt.description AS taskName,
  112. wtr.handler_id,
  113. wtr.finished as taskFinished,
  114. m.created,
  115. m.id as majorId,
  116. (select name from major_production where deleted = 0 and major_id = m.id and report_no= ifnull(wfni.business_min_id,wfni.business_sub_id)) as productionName,
  117. cc1.NAME AS cClienteleName,
  118. cc2.NAME AS cClienteleSubName,
  119. cl1.NAME AS cClienteleContactName,
  120. cl1.mobile AS cMobile,
  121. wtr.created as taskCreated
  122. FROM
  123. work_task_record wtr
  124. LEFT JOIN work_node_task wnt ON wnt.id = wtr.task_id
  125. inner JOIN (
  126. SELECT
  127. wn.NAME,
  128. wn.CODE,
  129. wfni.id,
  130. wfni.business_id ,
  131. wfni.business_sub_id,
  132. wfni.business_min_id,
  133. wfni.state
  134. FROM
  135. work_flow_node_instance wfni
  136. LEFT JOIN work_node wn ON wn.id = wfni.node_id
  137. WHERE
  138. wfni.business_type = 'MAJOR_BUSINESS'
  139. AND wfni.state = 'PENDING'
  140. AND wfni.deleted = 0
  141. AND wn.deleted = 0
  142. ) wfni ON wtr.instance_id = wfni.id
  143. LEFT JOIN major m ON m.id = wfni.business_id
  144. LEFT JOIN user u ON u.id = wtr.handler_id
  145. left join user u1 on u1.id = m.client_manager_id
  146. left join user u2 on u2.id = m.principal_id
  147. left join department d on d.id = m.department_id
  148. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  149. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  150. LEFT JOIN customer_linkman cl1 ON cl1.id = m.clientele_contact_id
  151. WHERE
  152. wtr.handler_id =#{todoVO.handlerId}
  153. AND u.deleted = 0
  154. AND wnt.deleted = 0
  155. AND wtr.deleted = 0
  156. <if test="keyword!=null and keyword!='' ">
  157. and(
  158. m.name like concat ('%',#{keyword},'%')
  159. or m.order_id like concat('%',#{keyword},'%')
  160. or wfni.business_sub_id like concat('%',#{keyword},'%')
  161. or u1.name like concat ('%',#{keyword},'%')
  162. or u2.name like concat ('%',#{keyword},'%')
  163. or m.business_object_type like concat ('%',#{keyword},'%')
  164. or u.name like concat ('%',#{keyword},'%')
  165. or wfni.name like concat('%',#{keyword},'%')
  166. )
  167. </if>
  168. <if test="todoVO!=null and todoVO.nodeName!=null and todoVO.nodeName!='' ">
  169. and wfni.name = #{todoVO.nodeName}
  170. </if>
  171. <if test="todoVO!=null and todoVO.startDate!=null and todoVO.startDate!=''">
  172. and m.created &gt;= #{todoVO.startDate}
  173. </if>
  174. <if test="todoVO!=null and todoVO.endDate!=null and todoVO.endDate!=''">
  175. and m.created &lt;= #{todoVO.endDate}
  176. </if>
  177. ORDER BY wtr.created DESC
  178. </select>
  179. <select id="majorTaskDonePage" parameterType="com.dayou.vo.MajorTaskDoneVO" resultType="com.dayou.vo.MajorTaskDoneVO">
  180. SELECT
  181. wf.id,
  182. u.name AS handler,
  183. wf.handler_id,
  184. (case wf.state when 'PASS' then '提交' when 'REVERSE' then '退回' when 'TERMINATE' then '终止' else '-' end) as state,
  185. wf.handing_time as handingTimeLong,
  186. wf.comments,
  187. wf.business_type,
  188. m.id AS majorId,
  189. m.order_id,
  190. m.name AS majorName,
  191. wn.name AS nodeName,
  192. wf.created as finishTime,
  193. ifnull(wf.business_min_id,wf.business_sub_id) as reportNo,
  194. wfni.state as instanceState,
  195. wfni.id as instanceId,
  196. (select name from major_production where deleted = 0 and report_no= (ifnull(wf.business_min_id,wf.business_sub_id))) as productionName
  197. FROM
  198. (
  199. ( SELECT * FROM work_flow_log WHERE handler_id = #{todoVO.handlerId} and business_type='MAJOR_BUSINESS' ) wf
  200. LEFT JOIN ( SELECT id, node_id, business_id ,state FROM work_flow_node_instance ) wfni ON wf.instance_id = wfni.id
  201. LEFT JOIN ( SELECT id, NAME FROM work_node WHERE deleted = 0 ) wn ON wn.id = wfni.node_id
  202. LEFT JOIN ( SELECT id, order_id, NAME FROM major WHERE deleted = 0 ) m ON m.id = wf.business_id
  203. LEFT JOIN user u ON u.id = wf.handler_id
  204. )
  205. <where>
  206. <if test="keyword!=null and keyword!='' ">
  207. and (
  208. m.name like concat ('%',#{keyword},'%')
  209. or m.order_id like concat('%',#{keyword},'%')
  210. or wf.business_sub_id like concat('%',#{keyword},'%')
  211. )
  212. </if>
  213. <if test="todoVO!=null and todoVO.nodeName!=null and todoVO.nodeName!='' ">
  214. and wn.name = #{todoVO.nodeName}
  215. </if>
  216. <if test="todoVO!=null and todoVO.state!=null and todoVO.state!='' ">
  217. and wf.state = #{todoVO.state}
  218. </if>
  219. <if test="todoVO!=null and todoVO.startDate!=null and todoVO.startDate!=''">
  220. and wf.created &gt;= #{todoVO.startDate}
  221. </if>
  222. <if test="todoVO!=null and todoVO.endDate!=null and todoVO.endDate!=''">
  223. and wf.created &lt;= #{todoVO.endDate}
  224. </if>
  225. </where>
  226. ORDER BY
  227. wf.created DESC
  228. </select>
  229. <update id="batchFinishTask" parameterType="java.util.List">
  230. update work_task_record set finished = 1 ,finish_time = now() where id in (
  231. <foreach collection="ids" index="index" separator="," item="item">
  232. #{item}
  233. </foreach>
  234. )
  235. </update>
  236. <select id="personalTodoPage" parameterType="com.dayou.vo.TaskTodoVO" resultType="com.dayou.vo.PersonalTodoVO">
  237. SELECT
  238. wfni.id,
  239. wtr.id AS taskId,
  240. wfni.id AS currentNodeId,
  241. wfni.business_id,
  242. p.location,
  243. p.order_id,
  244. u1.name AS clientManager,
  245. wfni.name AS nodeName,
  246. wfni.code AS nodeCode,
  247. u.name AS handlerName,
  248. wtr.handler_id,
  249. wtr.finished AS taskFinished,
  250. p.created,
  251. cc.name AS clientName,
  252. cc1.name AS clientSubName,
  253. p.agent,
  254. cl.name AS contactName,
  255. cl.mobile AS contactTel,
  256. p.bailorA,
  257. p.bailorB,
  258. p.bailorA_tel,
  259. p.bailorB_tel,
  260. u2.name AS outwardStaffName,
  261. u3.name AS inwardStaffName,
  262. u4.name AS pricingStaffName,
  263. wfni.created AS nodeCreated,
  264. pt.acreage,
  265. pt.amount,
  266. pt.price
  267. FROM
  268. work_task_record wtr
  269. LEFT JOIN work_node_task wnt ON wnt.id = wtr.task_id
  270. INNER JOIN (
  271. SELECT
  272. wn.NAME,
  273. wn.CODE,
  274. wfni.id,
  275. wfni.business_id,
  276. wfni.state,
  277. wfni.created
  278. FROM
  279. work_flow_node_instance wfni
  280. LEFT JOIN work_node wn ON wn.id = wfni.node_id
  281. WHERE
  282. wfni.business_type = 'PERSONAL_BUSINESS'
  283. AND wfni.state = 'PENDING'
  284. AND wfni.deleted = 0
  285. AND wn.deleted = 0
  286. ) wfni ON wtr.instance_id = wfni.id
  287. LEFT JOIN personal p ON p.id = wfni.business_id
  288. LEFT JOIN customer_company cc ON cc.id = p.clientele_id
  289. LEFT JOIN customer_company cc1 ON cc1.id = p.clientele_sub_id
  290. LEFT JOIN customer_linkman cl ON cl.id = p.clientele_contact_id
  291. LEFT JOIN user u ON u.id = wtr.handler_id
  292. LEFT JOIN user u1 ON u1.id = p.client_manager_id
  293. LEFT JOIN user u2 ON u2.id = p.outward_staff
  294. LEFT JOIN user u3 ON u3.id = p.inward_staff
  295. LEFT JOIN user u4 ON u4.id = p.pricing_staff
  296. LEFT JOIN personal_target pt ON pt.personal_id = p.id
  297. WHERE
  298. wtr.handler_id = #{personal.handlerId}
  299. AND u.deleted = 0
  300. AND wnt.deleted = 0
  301. AND wtr.deleted = 0
  302. <if test="keyword!=null and keyword!='' ">
  303. and (
  304. p.location like concat ('%',#{keyword},'%')
  305. or p.order_id like concat('%',#{keyword},'%')
  306. or p.agent like concat('%',#{keyword},'%')
  307. or p.bailorA like concat('%',#{keyword},'%')
  308. or p.bailorB like concat('%',#{keyword},'%')
  309. or cc.name like concat('%',#{keyword},'%')
  310. or cc1.name like concat('%',#{keyword},'%')
  311. or cl.name like concat('%',#{keyword},'%')
  312. )
  313. </if>
  314. <if test="personal!=null and personal.startDate!=null and personal.startDate!=''">
  315. and p.created &gt;= #{personal.startDate}
  316. </if>
  317. <if test="personal!=null and personal.endDate!=null and personal.endDate!=''">
  318. and p.created &lt;= #{personal.endDate}
  319. </if>
  320. <if test="personal!=null and personal.nodeCode!=null and personal.nodeCode!=''">
  321. and wn.code = #{personal.nodeCode}
  322. </if>
  323. <if test="personal!=null and personal.clientName!=null and personal.clientName!=''">
  324. and cc.NAME like concat('%',#{personal.clientName},'%')
  325. </if>
  326. <if test="personal!=null and personal.clientSubName!=null and personal.clientSubName!=''">
  327. and cc1.NAME like concat('%',#{personal.clientSubName},'%')
  328. </if>
  329. <if test="personal!=null and personal.clientManager!=null and personal.clientManager!='' ">
  330. and u.name like concat('%',#{personal.clientManager},'%')
  331. </if>
  332. <if test="personal!=null and personal.outwardStaffName!=null and personal.outwardStaffName!='' ">
  333. and u1.name like concat('%',#{personal.outwardStaffName},'%')
  334. </if>
  335. <if test="personal!=null and personal.inwardStaffName!=null and personal.inwardStaffName!='' ">
  336. and u2.name like concat('%',#{personal.inwardStaffName},'%')
  337. </if>
  338. <if test="personal!=null and personal.pricingStaffName!=null and personal.pricingStaffName!='' ">
  339. and u3.name like concat('%',#{personal.pricingStaffName},'%')
  340. </if>
  341. <if test="personal!=null and personal.handlerName!=null and personal.handlerName!='' ">
  342. and u4.name like concat('%',#{personal.handlerName},'%')
  343. </if>
  344. </select>
  345. <select id="personalTaskDonePage" parameterType="com.dayou.vo.PersonalTaskDoneVO" resultType="com.dayou.vo.PersonalTaskDoneVO">
  346. SELECT
  347. wf.id,
  348. u.name AS handler,
  349. wf.handler_id,
  350. (case wf.state when 'PASS' then '提交' when 'REVERSE' then '退回' when 'TERMINATE' then '终止' else '-' end) as state,
  351. wf.handing_time as handingTimeLong,
  352. wf.comments,
  353. wf.business_type,
  354. p.id AS personalId,
  355. p.order_id,
  356. p.location,
  357. p.clientName,
  358. p.clientSubName,
  359. p.bailorA,
  360. p.bailorB,
  361. wn.name AS nodeName,
  362. wf.created as finishTime,
  363. ifnull(wf.business_min_id,wf.business_sub_id) as reportNo,
  364. wfni.state as instanceState,
  365. wfni.id as instanceId
  366. FROM
  367. (
  368. ( SELECT * FROM work_flow_log WHERE handler_id = #{todoVO.handlerId} and business_type='PERSONAL_BUSINESS' ) wf
  369. LEFT JOIN ( SELECT id, node_id, business_id ,state FROM work_flow_node_instance ) wfni ON wf.instance_id = wfni.id
  370. LEFT JOIN ( SELECT id, name FROM work_node WHERE deleted = 0 ) wn ON wn.id = wfni.node_id
  371. LEFT JOIN ( SELECT p.id, p.order_id, p.location,cc.name as clientName,cc1.name as clientSubName,p.bailorA,p.bailorB FROM personal p left join customer_company cc on cc.id =
  372. p.clientele_id left join customer_company cc1 on cc1.id = p.clientele_sub_id
  373. WHERE p.deleted = 0) p ON p.id = wf.business_id
  374. LEFT JOIN user u ON u.id = wf.handler_id
  375. )
  376. <where>
  377. <if test="keyword!=null and keyword!='' ">
  378. and (
  379. p.location like concat ('%',#{keyword},'%')
  380. or p.order_id like concat('%',#{keyword},'%')
  381. or p.clientName like concat('%',#{keyword},'%')
  382. or p.clientSubName like concat('%',#{keyword},'%')
  383. )
  384. </if>
  385. <if test="todoVO!=null and todoVO.nodeName!=null and todoVO.nodeName!='' ">
  386. and wn.name = #{todoVO.nodeName}
  387. </if>
  388. <if test="todoVO!=null and todoVO.state!=null and todoVO.state!='' ">
  389. and wf.state = #{todoVO.state}
  390. </if>
  391. <if test="todoVO!=null and todoVO.startDate!=null and todoVO.startDate!=''">
  392. and wf.created &gt;= #{todoVO.startDate}
  393. </if>
  394. <if test="todoVO!=null and todoVO.endDate!=null and todoVO.endDate!=''">
  395. and wf.created &lt;= #{todoVO.endDate}
  396. </if>
  397. </where>
  398. ORDER BY
  399. wf.created DESC
  400. </select>
  401. <select id="majorTodoSimpleList" parameterType="java.lang.Long" resultType="com.dayou.vo.TaskTodoVO">
  402. SELECT
  403. wfni.id,
  404. wtr.id as taskId,
  405. wfni.id AS currentNodeId,
  406. wfni.business_sub_id as statementNo,
  407. wfni.business_min_id as reportNo,
  408. wfni.business_id,
  409. m.name as orderName,
  410. m.order_id,
  411. wfni.name AS nodeName,
  412. wfni.code as nodeCode,
  413. wfni.created as instanceCreated
  414. FROM
  415. work_task_record wtr
  416. inner JOIN (
  417. SELECT
  418. wn.NAME,
  419. wn.CODE,
  420. wfni.id,
  421. wfni.business_id ,
  422. wfni.business_sub_id,
  423. wfni.business_min_id,
  424. wfni.state,
  425. wfni.created
  426. FROM
  427. work_flow_node_instance wfni
  428. LEFT JOIN work_node wn ON wn.id = wfni.node_id
  429. WHERE
  430. wfni.business_type = 'MAJOR_BUSINESS'
  431. AND wfni.state = 'PENDING'
  432. AND wfni.deleted = 0
  433. AND wn.deleted = 0
  434. ) wfni ON wtr.instance_id = wfni.id
  435. LEFT JOIN major m ON m.id = wfni.business_id
  436. WHERE
  437. wtr.handler_id = #{handlerId}
  438. AND wtr.deleted = 0
  439. order by wfni.created limit 8
  440. </select>
  441. <select id="personalTodoSimpleList" parameterType="java.lang.Long" resultType="com.dayou.vo.PersonalTodoVO">
  442. SELECT
  443. wfni.id,
  444. wtr.id AS taskId,
  445. wfni.id AS currentNodeId,
  446. wfni.business_id,
  447. p.location,
  448. p.order_id,
  449. wfni.name AS nodeName,
  450. wfni.code AS nodeCode,
  451. wfni.created as instanceCreated
  452. FROM
  453. work_task_record wtr
  454. LEFT JOIN work_node_task wnt ON wnt.id = wtr.task_id
  455. INNER JOIN (
  456. SELECT
  457. wn.NAME,
  458. wn.CODE,
  459. wfni.id,
  460. wfni.business_id,
  461. wfni.state,
  462. wfni.created
  463. FROM
  464. work_flow_node_instance wfni
  465. LEFT JOIN work_node wn ON wn.id = wfni.node_id
  466. WHERE
  467. wfni.business_type = 'PERSONAL_BUSINESS'
  468. AND wfni.state = 'PENDING'
  469. AND wfni.deleted = 0
  470. AND wn.deleted = 0
  471. ) wfni ON wtr.instance_id = wfni.id
  472. LEFT JOIN personal p ON p.id = wfni.business_id
  473. WHERE
  474. wtr.handler_id = #{handlerId}
  475. AND wnt.deleted = 0
  476. AND wtr.deleted = 0
  477. order by wfni.created desc limit 8
  478. </select>
  479. <select id="getTodoTotalNum" parameterType="java.lang.Long" resultType="com.dayou.vo.BusinessTodoNum">
  480. SELECT
  481. wfni.business_type,
  482. count( wfni.id ) AS totalNum
  483. FROM
  484. work_task_record wtr
  485. INNER JOIN ( SELECT wfni.business_type, wfni.id FROM work_flow_node_instance wfni WHERE wfni.state = 'PENDING' AND wfni.deleted = 0 ) wfni ON wtr.instance_id = wfni.id
  486. WHERE
  487. wtr.handler_id = #{handlerId}
  488. AND wtr.deleted = 0
  489. GROUP BY
  490. wfni.business_type
  491. </select>
  492. <!--获取资产业务已办列表-->
  493. <select id="getAssetsTaskDoneList" resultType="com.dayou.vo.AssetsTaskDoneVO">
  494. SELECT DISTINCT
  495. (@i := @i + 1) AS id,
  496. instance.recordId,
  497. log.id AS logId,
  498. user.name AS handlerName,
  499. log.handler_id,
  500. (case log.state
  501. when 'PASS' then '提交'
  502. when 'REVERSE' then '退回'
  503. when 'TERMINATE' then '终止'
  504. else '-' end) AS state,
  505. log.handing_time AS handingTimeLong,
  506. log.comments,
  507. log.business_type,
  508. assets.id AS assetsId,
  509. assets.order_id AS orderId,
  510. assets.name AS assetsName,
  511. node.name AS nodeName,
  512. node.code AS nodeCode,
  513. log.created AS finishTime,
  514. instance.business_sub_id AS statementNo,
  515. (SELECT assets_name FROM assets_production WHERE assets_production.production_no = instance.business_sub_id) AS
  516. statementName,
  517. (SELECT assets_name FROM assets_production WHERE assets_production.production_no = instance.business_min_id) AS
  518. reportName,
  519. instance.business_min_id AS reportNo,
  520. instance.state AS instanceState,
  521. instance.id AS instanceId,
  522. instance.created AS startDate
  523. FROM
  524. (SELECT @i := 0) AS sort,
  525. work_flow_log AS log
  526. LEFT JOIN (SELECT work_flow_node_instance.id, node_id, business_id, state, business_sub_id,
  527. business_min_id,work_task_record.created,work_task_record.id AS recordId
  528. FROM work_flow_node_instance,work_task_record
  529. WHERE state = 'FINISHED'
  530. AND work_flow_node_instance.id = work_task_record.instance_id
  531. AND work_flow_node_instance.deleted = 0) AS instance ON log.instance_id = instance.id
  532. LEFT JOIN (SELECT id, name, code FROM work_node WHERE deleted = 0) AS node ON node.id = instance.node_id
  533. LEFT JOIN (SELECT id, order_id, name, department_id FROM assets WHERE deleted = 0) AS assets ON assets.id = log.business_id
  534. LEFT JOIN user ON user.id = log.handler_id
  535. <if test="assetsSelectDTO != null and assetsSelectDTO.selectByDepartment">
  536. INNER JOIN (
  537. SELECT DISTINCT
  538. department.id,
  539. department.parent_id,
  540. user.id AS userId
  541. FROM
  542. user,
  543. post,
  544. department,
  545. user_post ,
  546. work_task_record AS record
  547. WHERE
  548. user.id = user_post.user_id
  549. AND user_post.post_id = post.id
  550. AND post.department_id = department.id
  551. AND user_post.deleted = 0
  552. ) AS department ON (department.id IN
  553. <foreach collection="assetsSelectDTO.departmentIdList" index="index" item="item" open="(" separator=","
  554. close=")">
  555. #{item}
  556. </foreach>
  557. OR department.parent_id IN
  558. <foreach collection="assetsSelectDTO.departmentIdList" index="index" item="item" open="(" separator=","
  559. close=")">
  560. #{item}
  561. </foreach>
  562. )
  563. AND department.userId = log.handler_id
  564. </if>
  565. WHERE instance.id IS NOT NULL
  566. AND log.business_type = 'ASSET_BUSINESS'
  567. <if test="assetsSelectDTO != null and assetsSelectDTO.handlerId != null">
  568. AND handler_id = #{assetsSelectDTO.handlerId}
  569. </if>
  570. <if test="assetsSelectDTO != null and assetsSelectDTO.keyWord != null and assetsSelectDTO.keyWord != '' ">
  571. AND (
  572. assets.order_id LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  573. assets.name LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  574. instance.business_sub_id LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  575. instance.business_min_id LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%')
  576. )
  577. </if>
  578. <if test="assetsSelectDTO != null and assetsSelectDTO.nodeCode != null">
  579. AND node.code = #{assetsSelectDTO.nodeCode}
  580. </if>
  581. <if test="assetsSelectDTO != null and assetsSelectDTO.departmentId">
  582. AND assets.department_id = #{assetsSelectDTO.departmentId}
  583. </if>
  584. ORDER BY log.created DESC
  585. </select>
  586. </mapper>