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.

456 lines
19 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
4 days ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
4 weeks ago
4 days ago
4 weeks ago
1 month 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. <mapper namespace="com.xujie.sys.modules.erf.mapper.ErfExpApplyMapper">
  4. <!-- 结果映射 -->
  5. <resultMap id="ExpApplyResultMap" type="com.xujie.sys.modules.erf.data.ErfExpApplyData">
  6. <result column="apply_no" property="applyNo"/>
  7. <result column="bu_no" property="buNo"/>
  8. <result column="buDesc" property="buDesc"/>
  9. <result column="experiment_type" property="experimentType"/>
  10. <result column="project_no" property="projectNo"/>
  11. <result column="title" property="title"/>
  12. <result column="purpose" property="purpose"/>
  13. <result column="justification" property="justification"/>
  14. <result column="product_type" property="productType"/>
  15. <result column="quantity_req" property="quantityReq"/>
  16. <result column="expected_finish_date" property="expectedFinishDate"/>
  17. <result column="project_leader" property="projectLeader"/>
  18. <result column="contact_method" property="contactMethod"/>
  19. <result column="process_requirement" property="processRequirement"/>
  20. <result column="actual_finish_date" property="actualFinishDate"/>
  21. <result column="final_status" property="finalStatus"/>
  22. <result column="final_quantity" property="finalQuantity"/>
  23. <result column="planner_user_id" property="plannerUserId"/>
  24. <result column="planner_name" property="plannerName"/>
  25. <result column="work_order_no" property="workOrderNo"/>
  26. <result column="scheduled_date" property="scheduledDate"/>
  27. <result column="status" property="status"/>
  28. <result column="current_step" property="currentStep"/>
  29. <result column="creator_user_id" property="creatorUserId"/>
  30. <result column="creator_name" property="creatorName"/>
  31. <result column="create_time" property="createTime"/>
  32. <result column="update_time" property="updateTime"/>
  33. <result column="submit_time" property="submitTime"/>
  34. </resultMap>
  35. <!-- 查询申请单列表 -->
  36. <select id="searchExpApplyList" resultMap="ExpApplyResultMap">
  37. SELECT
  38. site,
  39. apply_no,
  40. bu_no,
  41. dbo.get_bu_desc(site,bu_no) as buDesc,
  42. experiment_type,
  43. project_no,
  44. title,
  45. purpose,
  46. justification,
  47. product_type,
  48. quantity_req,
  49. expected_finish_date,
  50. project_leader,
  51. contact_method,
  52. process_requirement,
  53. actual_finish_date,
  54. final_status,
  55. final_quantity,
  56. planner_user_id,
  57. planner_name,
  58. work_order_no,
  59. scheduled_date,
  60. status,
  61. current_step,
  62. creator_user_id,
  63. creator_name,
  64. create_time,
  65. update_time,
  66. submit_time
  67. FROM erf_exp_apply
  68. <where>
  69. <if test="data.applyNo != null and data.applyNo != ''">
  70. AND apply_no LIKE '%' + #{data.applyNo} + '%'
  71. </if>
  72. <if test="data.buNo != null and data.buNo != ''">
  73. AND bu_no = #{data.buNo}
  74. </if>
  75. <if test="data.experimentType != null and data.experimentType != ''">
  76. AND experiment_type = #{data.experimentType}
  77. </if>
  78. <if test="data.status != null and data.status != ''">
  79. AND status = #{data.status}
  80. </if>
  81. <if test="data.creatorUserId != null">
  82. AND creator_user_id = #{data.creatorUserId}
  83. </if>
  84. <if test="data.createStartDate != null">
  85. AND CAST(create_time AS DATE) &gt;= #{data.createStartDate}
  86. </if>
  87. <if test="data.createEndDate != null">
  88. AND CAST(create_time AS DATE) &lt;= #{data.createEndDate}
  89. </if>
  90. <if test="data.title != null and data.title != ''">
  91. AND title LIKE '%' + #{data.title} + '%'
  92. </if>
  93. <if test="data.projectNo != null and data.projectNo != ''">
  94. AND project_no LIKE '%' + #{data.projectNo} + '%'
  95. </if>
  96. <if test="data.productType != null and data.productType != ''">
  97. AND product_type LIKE '%' + #{data.productType} + '%'
  98. </if>
  99. <if test="data.creatorName != null and data.creatorName != ''">
  100. AND creator_name LIKE '%' + #{data.creatorName} + '%'
  101. </if>
  102. <if test="data.expectedFinishStartDate != null">
  103. AND CAST(expected_finish_date AS DATE) &gt;= #{data.expectedFinishStartDate}
  104. </if>
  105. <if test="data.expectedFinishEndDate != null">
  106. AND CAST(expected_finish_date AS DATE) &lt;= #{data.expectedFinishEndDate}
  107. </if>
  108. <if test="data.actualFinishStartDate != null">
  109. AND CAST(actual_finish_date AS DATE) &gt;= #{data.actualFinishStartDate}
  110. </if>
  111. <if test="data.actualFinishEndDate != null">
  112. AND CAST(actual_finish_date AS DATE) &lt;= #{data.actualFinishEndDate}
  113. </if>
  114. </where>
  115. ORDER BY create_time DESC
  116. </select>
  117. <!-- 根据申请单号查询详情 -->
  118. <select id="getExpApplyDetail" resultMap="ExpApplyResultMap">
  119. SELECT
  120. apply_no,
  121. bu_no,
  122. dbo.get_bu_desc(site,bu_no) as buDesc,
  123. experiment_type,
  124. project_no,
  125. title,
  126. purpose,
  127. justification,
  128. product_type,
  129. quantity_req,
  130. expected_finish_date,
  131. project_leader,
  132. contact_method,
  133. process_requirement,
  134. actual_finish_date,
  135. final_status,
  136. final_quantity,
  137. planner_user_id,
  138. planner_name,
  139. work_order_no,
  140. scheduled_date,
  141. status,
  142. current_step,
  143. creator_user_id,
  144. creator_name,
  145. create_time,
  146. update_time,
  147. submit_time
  148. FROM erf_exp_apply
  149. WHERE apply_no = #{applyNo}
  150. </select>
  151. <!-- 查询用户的待办申请单 -->
  152. <select id="getPendingApplyList" resultMap="ExpApplyResultMap">
  153. SELECT DISTINCT
  154. a.apply_no,
  155. a.bu_no,
  156. dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
  157. a.experiment_type,
  158. a.project_no,
  159. a.title,
  160. a.purpose,
  161. a.justification,
  162. a.product_type,
  163. a.quantity_req,
  164. a.expected_finish_date,
  165. a.project_leader,
  166. a.contact_method,
  167. a.process_requirement,
  168. a.actual_finish_date,
  169. a.final_status,
  170. a.final_quantity,
  171. a.planner_user_id,
  172. a.planner_name,
  173. a.work_order_no,
  174. a.scheduled_date,
  175. a.status,
  176. a.current_step,
  177. a.creator_user_id,
  178. a.creator_name,
  179. a.create_time,
  180. a.update_time,
  181. a.submit_time
  182. FROM erf_exp_apply a
  183. INNER JOIN erf_flow_node_instance n ON a.apply_no = n.apply_no
  184. <where>
  185. n.assignee_user_id = #{data.currentUserId}
  186. AND n.status = '待审核'
  187. <!-- 根据不同页面类型,过滤不同的节点类型 -->
  188. <if test="data.pageType != null and data.pageType == 'MANAGER'">
  189. AND n.node_code IN ('技术经理审批', '生产经理审批', '质量经理审批')
  190. </if>
  191. <if test="data.pageType != null and data.pageType == 'PLANNER'">
  192. AND n.node_code = '计划员排产'
  193. </if>
  194. <if test="data.pageType != null and data.pageType == 'TRI_CONFIRM'">
  195. AND n.node_code = '三方确认'
  196. </if>
  197. <if test="data.pendingStatus != null and data.pendingStatus != ''">
  198. AND a.status = #{data.pendingStatus}
  199. </if>
  200. <if test="data.pendingStatus == null or data.pendingStatus == ''">
  201. AND a.status IN ('已下达','已批准', '生产中')
  202. </if>
  203. <if test="data.applyNo != null and data.applyNo != ''">
  204. AND a.apply_no LIKE '%' + #{data.applyNo} + '%'
  205. </if>
  206. <if test="data.buNo != null and data.buNo != ''">
  207. AND a.bu_no = #{data.buNo}
  208. </if>
  209. <if test="data.experimentType != null and data.experimentType != ''">
  210. AND a.experiment_type = #{data.experimentType}
  211. </if>
  212. <if test="data.title != null and data.title != ''">
  213. AND a.title LIKE '%' + #{data.title} + '%'
  214. </if>
  215. <if test="data.projectNo != null and data.projectNo != ''">
  216. AND a.project_no LIKE '%' + #{data.projectNo} + '%'
  217. </if>
  218. <if test="data.productType != null and data.productType != ''">
  219. AND a.product_type LIKE '%' + #{data.productType} + '%'
  220. </if>
  221. <if test="data.creatorName != null and data.creatorName != ''">
  222. AND a.creator_name LIKE '%' + #{data.creatorName} + '%'
  223. </if>
  224. <if test="data.createStartDate != null">
  225. AND CAST(a.create_time AS DATE) &gt;= #{data.createStartDate}
  226. </if>
  227. <if test="data.createEndDate != null">
  228. AND CAST(a.create_time AS DATE) &lt;= #{data.createEndDate}
  229. </if>
  230. <if test="data.expectedFinishStartDate != null">
  231. AND CAST(a.expected_finish_date AS DATE) &gt;= #{data.expectedFinishStartDate}
  232. </if>
  233. <if test="data.expectedFinishEndDate != null">
  234. AND CAST(a.expected_finish_date AS DATE) &lt;= #{data.expectedFinishEndDate}
  235. </if>
  236. </where>
  237. ORDER BY a.create_time DESC
  238. </select>
  239. <select id="getSiteByBu" resultType="String">
  240. select top 1 site from BU where bu_no=#{buNo}
  241. </select>
  242. <!-- 删除三方确认明细 -->
  243. <delete id="deleteTriConfirmDetail">
  244. DELETE FROM erf_exp_tri_confirm_detail
  245. WHERE apply_no = #{applyNo}
  246. </delete>
  247. <!-- 删除三方确认主表 -->
  248. <delete id="deleteTriConfirm">
  249. DELETE FROM erf_exp_tri_confirm
  250. WHERE apply_no = #{applyNo}
  251. </delete>
  252. <!-- 删除申请单附件 -->
  253. <delete id="deleteAttachments">
  254. DELETE FROM sys_oss
  255. WHERE order_ref1 = #{orderRef1}
  256. AND order_ref2 = #{orderRef2}
  257. AND order_ref6 = #{orderRef6}
  258. </delete>
  259. <!-- 删除流程节点实例 -->
  260. <delete id="deleteFlowNodeInstances">
  261. DELETE FROM erf_flow_node_instance
  262. WHERE apply_no = #{applyNo}
  263. </delete>
  264. <!-- 查询附件列表 -->
  265. <select id="getAttachmentList" resultType="map">
  266. SELECT url, new_file_name, file_name, created_by, file_type,
  267. order_ref3, order_ref4, order_ref5, file_suffix, file_type_code,
  268. order_reftype, conclusion, c_additional_info, project_ispush
  269. FROM sys_oss
  270. WHERE order_ref1 = #{orderRef1}
  271. AND order_ref2 = #{orderRef2}
  272. AND order_ref6 = #{orderRef6}
  273. </select>
  274. <!-- 审批周期报表结果映射 -->
  275. <resultMap id="ApprovalCycleResultMap" type="com.xujie.sys.modules.erf.dto.ErfApprovalCycleReportDto">
  276. <result column="apply_no" property="applyNo"/>
  277. <result column="bu_no" property="buNo"/>
  278. <result column="buDesc" property="buName"/>
  279. <result column="experiment_type" property="experimentType"/>
  280. <result column="title" property="title"/>
  281. <result column="creator_name" property="creatorName"/>
  282. <result column="status" property="status"/>
  283. <result column="create_time" property="createTime"/>
  284. <result column="submit_time" property="submitTime"/>
  285. <result column="tech_manager_name" property="techManagerName"/>
  286. <result column="tech_approve_time" property="techApproveTime"/>
  287. <result column="prod_manager_name" property="prodManagerName"/>
  288. <result column="prod_approve_time" property="prodApproveTime"/>
  289. <result column="qual_manager_name" property="qualManagerName"/>
  290. <result column="qual_approve_time" property="qualApproveTime"/>
  291. </resultMap>
  292. <!-- 查询审批周期报表列表 -->
  293. <!-- 统计从申请单发起日(submit_time)到技术/生产/质量三类经理全部审批完成的周期 -->
  294. <select id="getApprovalCycleReportList" resultMap="ApprovalCycleResultMap">
  295. SELECT
  296. a.apply_no,
  297. a.bu_no,
  298. dbo.get_bu_desc(a.site, a.bu_no) AS buDesc,
  299. a.experiment_type,
  300. a.title,
  301. a.creator_name,
  302. a.status,
  303. a.create_time,
  304. a.submit_time,
  305. -- 技术经理审批(单人,取已批准记录的最晚完成时间)
  306. tech.assignee_name AS tech_manager_name,
  307. tech.complete_time AS tech_approve_time,
  308. -- 生产经理审批(可能多人,合并姓名,取最晚完成时间)
  309. prod.assignee_names AS prod_manager_name,
  310. prod.max_complete_time AS prod_approve_time,
  311. -- 质量经理审批(可能多人,合并姓名,取最晚完成时间)
  312. qual.assignee_names AS qual_manager_name,
  313. qual.max_complete_time AS qual_approve_time
  314. FROM erf_exp_apply a
  315. -- 技术经理审批:取该申请单最新一次审批通过的记录
  316. LEFT JOIN (
  317. SELECT
  318. n1.apply_no,
  319. n1.assignee_name,
  320. n1.complete_time
  321. FROM erf_flow_node_instance n1
  322. INNER JOIN (
  323. SELECT apply_no, MAX(attempt_no) AS max_attempt
  324. FROM erf_flow_node_instance
  325. WHERE node_code = '技术经理审批'
  326. GROUP BY apply_no
  327. ) n1a ON n1.apply_no = n1a.apply_no AND n1.attempt_no = n1a.max_attempt
  328. WHERE n1.node_code = '技术经理审批'
  329. ) tech ON a.apply_no = tech.apply_no
  330. -- 生产经理审批:取最新一次attempt中所有已批准的记录,合并姓名,取最晚完成时间
  331. -- 使用 STUFF+FOR XML PATH 兼容 SQL Server 2017 以下版本
  332. LEFT JOIN (
  333. SELECT
  334. p.apply_no,
  335. STUFF((
  336. SELECT '、' + p2.assignee_name
  337. FROM erf_flow_node_instance p2
  338. WHERE p2.node_code = '生产经理审批'
  339. AND p2.apply_no = p.apply_no
  340. AND p2.attempt_no = (
  341. SELECT MAX(p3.attempt_no)
  342. FROM erf_flow_node_instance p3
  343. WHERE p3.apply_no = p.apply_no
  344. AND p3.node_code = '生产经理审批'
  345. )
  346. FOR XML PATH('')
  347. ), 1, 1, '') AS assignee_names,
  348. MAX(p.complete_time) AS max_complete_time
  349. FROM erf_flow_node_instance p
  350. INNER JOIN (
  351. SELECT apply_no, MAX(attempt_no) AS max_attempt
  352. FROM erf_flow_node_instance
  353. WHERE node_code = '生产经理审批'
  354. GROUP BY apply_no
  355. ) pa ON p.apply_no = pa.apply_no AND p.attempt_no = pa.max_attempt
  356. WHERE p.node_code = '生产经理审批'
  357. GROUP BY p.apply_no
  358. ) prod ON a.apply_no = prod.apply_no
  359. -- 质量经理审批:取最新一次attempt中所有已批准的记录,合并姓名,取最晚完成时间
  360. LEFT JOIN (
  361. SELECT
  362. q.apply_no,
  363. STUFF((
  364. SELECT '、' + q2.assignee_name
  365. FROM erf_flow_node_instance q2
  366. WHERE q2.node_code = '质量经理审批'
  367. AND q2.apply_no = q.apply_no
  368. AND q2.attempt_no = (
  369. SELECT MAX(q3.attempt_no)
  370. FROM erf_flow_node_instance q3
  371. WHERE q3.apply_no = q.apply_no
  372. AND q3.node_code = '质量经理审批'
  373. )
  374. FOR XML PATH('')
  375. ), 1, 1, '') AS assignee_names,
  376. MAX(q.complete_time) AS max_complete_time
  377. FROM erf_flow_node_instance q
  378. INNER JOIN (
  379. SELECT apply_no, MAX(attempt_no) AS max_attempt
  380. FROM erf_flow_node_instance
  381. WHERE node_code = '质量经理审批'
  382. GROUP BY apply_no
  383. ) qa ON q.apply_no = qa.apply_no AND q.attempt_no = qa.max_attempt
  384. WHERE q.node_code = '质量经理审批'
  385. GROUP BY q.apply_no
  386. ) qual ON a.apply_no = qual.apply_no
  387. <where>
  388. -- 只查询已下达(有发起日)的申请单
  389. a.submit_time IS NOT NULL
  390. <if test="data.applyNo != null and data.applyNo != ''">
  391. AND a.apply_no LIKE '%' + #{data.applyNo} + '%'
  392. </if>
  393. <if test="data.buNo != null and data.buNo != ''">
  394. AND a.bu_no = #{data.buNo}
  395. </if>
  396. <if test="data.experimentType != null and data.experimentType != ''">
  397. AND a.experiment_type = #{data.experimentType}
  398. </if>
  399. <if test="data.creatorName != null and data.creatorName != ''">
  400. AND a.creator_name LIKE '%' + #{data.creatorName} + '%'
  401. </if>
  402. <if test="data.submitStartDate != null">
  403. AND CAST(a.submit_time AS DATE) &gt;= #{data.submitStartDate}
  404. </if>
  405. <if test="data.submitEndDate != null">
  406. AND CAST(a.submit_time AS DATE) &lt;= #{data.submitEndDate}
  407. </if>
  408. <if test="data.status != null and data.status != ''">
  409. AND a.status = #{data.status}
  410. </if>
  411. </where>
  412. ORDER BY a.submit_time DESC
  413. </select>
  414. <!-- 复制附件 -->
  415. <insert id="copyAttachment">
  416. INSERT INTO sys_oss
  417. (url, create_date, new_file_name, file_name, created_by, file_type,
  418. order_ref1, order_ref2, order_ref3, order_ref4, order_ref5, order_ref6,
  419. file_suffix, file_type_code, order_reftype, conclusion, c_additional_info, project_ispush)
  420. VALUES (
  421. #{attachment.url},
  422. GETDATE(),
  423. #{attachment.new_file_name},
  424. #{attachment.file_name},
  425. #{attachment.created_by},
  426. #{attachment.file_type},
  427. 'ERF',
  428. #{targetApplyNo},
  429. #{attachment.order_ref3},
  430. #{attachment.order_ref4},
  431. #{attachment.order_ref5},
  432. 'EXP_APPLY',
  433. #{attachment.file_suffix},
  434. #{attachment.file_type_code},
  435. #{attachment.order_reftype},
  436. #{attachment.conclusion},
  437. #{attachment.c_additional_info},
  438. #{attachment.project_ispush}
  439. )
  440. </insert>
  441. </mapper>