You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
8.5 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  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. <!-- rqrq - 流程实例Mapper XML -->
  4. <mapper namespace="com.xujie.modules.workFlow.mapper.ErfFlowInstanceMapper">
  5. <!-- 查询流程实例列表(分页) - rqrq -->
  6. <select id="searchInstanceList" resultType="ErfFlowInstanceData">
  7. SELECT
  8. i.apply_no,
  9. i.order_ref1,
  10. i.site,
  11. i.order_type,
  12. i.flow_code,
  13. i.flow_version,
  14. i.status,
  15. i.current_node_code,
  16. i.start_time,
  17. i.end_time,
  18. i.remark,
  19. t.flow_name,
  20. n.node_name AS currentNodeName
  21. FROM erf_flow_instance i
  22. LEFT JOIN erf_flow_template t ON t.flow_code = i.flow_code AND t.flow_version = i.flow_version AND t.site = i.site
  23. LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
  24. AND n.site = i.site AND n.node_code = i.current_node_code
  25. <where>
  26. <if test="query.site != null and query.site != ''">
  27. AND i.site = #{query.site}
  28. </if>
  29. <if test="query.applyNo != null and query.applyNo != ''">
  30. AND i.apply_no LIKE '%' + #{query.applyNo} + '%'
  31. </if>
  32. <if test="query.orderRef1 != null and query.orderRef1 != ''">
  33. AND i.order_ref1 LIKE '%' + #{query.orderRef1} + '%'
  34. </if>
  35. <if test="query.orderType != null and query.orderType != ''">
  36. AND i.order_type = #{query.orderType}
  37. </if>
  38. <if test="query.status != null and query.status != ''">
  39. AND i.status = #{query.status}
  40. </if>
  41. </where>
  42. ORDER BY i.start_time DESC
  43. </select>
  44. <!-- 查询节点实例列表 -->
  45. <select id="searchNodeInstanceList" resultType="ErfFlowNodeInstanceData">
  46. SELECT
  47. ni.apply_no,
  48. ni.node_code,
  49. ni.attempt_no,
  50. ni.site,
  51. ni.order_type,
  52. ni.department_id,
  53. ni.department_name,
  54. ni.assignee_user_id,
  55. ni.assignee_name,
  56. ni.status,
  57. ni.comment,
  58. ni.receive_time,
  59. ni.complete_time,
  60. ni.duration_seconds,
  61. n.node_name,
  62. n.node_order,
  63. n.approve_type
  64. FROM erf_flow_node_instance ni
  65. LEFT JOIN erf_flow_instance i ON i.apply_no = ni.apply_no AND i.site = ni.site AND i.order_type = ni.order_type
  66. LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
  67. AND n.site = i.site AND n.node_code = ni.node_code
  68. WHERE ni.apply_no = #{applyNo}
  69. AND ni.site = #{site}
  70. AND ni.order_type = #{orderType}
  71. ORDER BY n.node_order, ni.attempt_no
  72. </select>
  73. <!-- 插入流程实例 - rqrq -->
  74. <insert id="insertInstance">
  75. INSERT INTO erf_flow_instance (
  76. apply_no, order_ref1, site, order_type, flow_code, flow_version,
  77. status, current_node_code, start_time
  78. ) VALUES (
  79. #{applyNo}, #{orderRef1}, #{site}, #{orderType}, #{flowCode}, #{flowVersion},
  80. #{status}, #{currentNodeCode}, GETDATE()
  81. )
  82. </insert>
  83. <!-- 插入节点实例 -->
  84. <insert id="insertNodeInstance">
  85. INSERT INTO erf_flow_node_instance (
  86. apply_no, node_code, attempt_no, site, order_type,
  87. department_id, department_name, assignee_user_id, assignee_name, status, receive_time
  88. ) VALUES (
  89. #{applyNo}, #{nodeCode}, #{attemptNo}, #{site}, #{orderType},
  90. #{departmentId}, #{departmentName}, #{assigneeUserId}, #{assigneeName}, #{status}, GETDATE()
  91. )
  92. </insert>
  93. <!-- 更新流程实例状态 -->
  94. <update id="updateInstanceStatus">
  95. UPDATE erf_flow_instance
  96. SET status = #{status},
  97. current_node_code = #{currentNodeCode}
  98. WHERE apply_no = #{applyNo}
  99. AND site = #{site}
  100. AND order_type = #{orderType}
  101. </update>
  102. <!-- 更新流程实例完成 -->
  103. <update id="updateInstanceCompleted">
  104. UPDATE erf_flow_instance
  105. SET status = 'COMPLETED',
  106. end_time = GETDATE()
  107. WHERE apply_no = #{applyNo}
  108. AND site = #{site}
  109. AND order_type = #{orderType}
  110. </update>
  111. <!-- 更新节点实例状态 -->
  112. <update id="updateNodeInstanceStatus">
  113. UPDATE erf_flow_node_instance
  114. SET status = #{status},
  115. comment = #{comment},
  116. complete_time = GETDATE()
  117. WHERE apply_no = #{applyNo}
  118. AND node_code = #{nodeCode}
  119. AND attempt_no = #{attemptNo}
  120. AND site = #{site}
  121. AND order_type = #{orderType}
  122. </update>
  123. <!-- 获取节点实例详情 -->
  124. <select id="getNodeInstanceDetail" resultType="ErfFlowNodeInstanceData">
  125. SELECT
  126. ni.apply_no,
  127. ni.node_code,
  128. ni.attempt_no,
  129. ni.site,
  130. ni.order_type,
  131. ni.assignee_user_id,
  132. ni.assignee_name,
  133. ni.status,
  134. ni.comment,
  135. ni.receive_time,
  136. ni.complete_time,
  137. n.node_name,
  138. n.node_order,
  139. n.approve_type,
  140. i.flow_code,
  141. i.flow_version
  142. FROM erf_flow_node_instance ni
  143. LEFT JOIN erf_flow_instance i ON i.apply_no = ni.apply_no AND i.site = ni.site AND i.order_type = ni.order_type
  144. LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
  145. AND n.site = i.site AND n.node_code = ni.node_code
  146. WHERE ni.apply_no = #{applyNo}
  147. AND ni.node_code = #{nodeCode}
  148. AND ni.attempt_no = #{attemptNo}
  149. AND ni.site = #{site}
  150. AND ni.order_type = #{orderType}
  151. </select>
  152. <!-- 获取流程实例 - rqrq -->
  153. <select id="getInstanceByApplyNo" resultType="ErfFlowInstanceData">
  154. SELECT
  155. i.apply_no,
  156. i.order_ref1,
  157. i.site,
  158. i.order_type,
  159. i.flow_code,
  160. i.flow_version,
  161. i.status,
  162. i.current_node_code,
  163. i.start_time,
  164. i.end_time,
  165. t.flow_name
  166. FROM erf_flow_instance i
  167. LEFT JOIN erf_flow_template t ON t.flow_code = i.flow_code AND t.flow_version = i.flow_version AND t.site = i.site
  168. WHERE i.apply_no = #{applyNo}
  169. AND i.site = #{site}
  170. AND i.order_type = #{orderType}
  171. </select>
  172. <!-- 获取当前节点的最大尝试次数 -->
  173. <select id="getMaxAttemptNo" resultType="Integer">
  174. SELECT ISNULL(MAX(attempt_no), 0)
  175. FROM erf_flow_node_instance
  176. WHERE apply_no = #{applyNo}
  177. AND node_code = #{nodeCode}
  178. AND site = #{site}
  179. AND order_type = #{orderType}
  180. </select>
  181. <!-- 获取待审批的节点实例 -->
  182. <select id="getPendingNodeInstance" resultType="ErfFlowNodeInstanceData">
  183. SELECT TOP 1
  184. ni.apply_no,
  185. ni.node_code,
  186. ni.attempt_no,
  187. ni.site,
  188. ni.order_type,
  189. ni.assignee_user_id,
  190. ni.assignee_name,
  191. ni.status,
  192. n.node_name,
  193. n.node_order,
  194. n.approve_type
  195. FROM erf_flow_node_instance ni
  196. LEFT JOIN erf_flow_instance i ON i.apply_no = ni.apply_no AND i.site = ni.site AND i.order_type = ni.order_type
  197. LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
  198. AND n.site = i.site AND n.node_code = ni.node_code
  199. WHERE ni.apply_no = #{applyNo}
  200. AND ni.node_code = #{nodeCode}
  201. AND ni.site = #{site}
  202. AND ni.order_type = #{orderType}
  203. AND ni.status = 'PENDING'
  204. ORDER BY ni.attempt_no DESC
  205. </select>
  206. <!-- 删除指定单据的所有节点实例 - rqrq -->
  207. <delete id="deleteNodeInstancesByApplyNo">
  208. DELETE FROM erf_flow_node_instance
  209. WHERE apply_no = #{applyNo}
  210. AND site = #{site}
  211. AND order_type = #{orderType}
  212. </delete>
  213. <!-- 重启流程实例 - rqrq -->
  214. <update id="restartInstance">
  215. UPDATE erf_flow_instance
  216. SET status = 'RUNNING',
  217. current_node_code = #{currentNodeCode},
  218. start_time = GETDATE(),
  219. end_time = NULL
  220. WHERE apply_no = #{applyNo}
  221. AND site = #{site}
  222. AND order_type = #{orderType}
  223. </update>
  224. </mapper>