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.

903 lines
39 KiB

3 months ago
2 months ago
3 weeks ago
3 months ago
2 weeks ago
1 week ago
2 weeks ago
3 months ago
3 months ago
3 months ago
3 weeks 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
2 months ago
3 months ago
2 weeks ago
2 weeks ago
1 week ago
3 months ago
3 months ago
3 weeks ago
3 months ago
3 months ago
2 weeks ago
1 week ago
3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
1 week ago
3 months ago
1 week ago
3 months ago
3 months ago
3 months ago
3 weeks ago
3 months ago
4 days ago
2 weeks ago
1 week ago
3 months ago
3 months ago
2 months ago
2 weeks ago
1 week ago
2 months ago
3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
2 weeks ago
1 week ago
3 months ago
3 months ago
3 months ago
2 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. <mapper namespace="com.xujie.sys.modules.sampletracking.mapper.SampleProofTrackingMapper">
  4. <select id="searchProofTracking" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingData">
  5. SELECT
  6. t.id as tracking_id,
  7. t.site,
  8. t.project_id,
  9. t.project_part_id,
  10. t.proofing_id,
  11. t.proofing_no,
  12. t.proofing_status,
  13. t.project_phase,
  14. COALESCE(NULLIF(LTRIM(RTRIM(t.project_category)), ''),
  15. NULLIF(LTRIM(RTRIM(p.project_category)), ''),
  16. NULLIF(LTRIM(RTRIM(pp.project_category)), '')) AS project_category,
  17. t.tracker,
  18. t.engineer,
  19. t.priority_level,
  20. t.proofing_number,
  21. t.proofing_number AS sampleQty,
  22. t.pm_inquery_time,
  23. t.importance,
  24. -- 实际完成日期优先;为空时使用预计完成日期,与 Sample making Date 筛选保持一致。
  25. YEAR(COALESCE(t.actuality_delivery_date, t.required_delivery_date)) AS sampleMakingYear,
  26. MONTH(COALESCE(t.actuality_delivery_date, t.required_delivery_date)) AS sampleMakingMonth,
  27. CASE
  28. WHEN t.actuality_delivery_date IS NULL OR t.plan_start_date IS NULL THEN NULL
  29. ELSE DATEDIFF(DAY, t.plan_start_date, t.actuality_delivery_date)
  30. END AS sampleLt,
  31. CASE
  32. WHEN t.actuality_delivery_date IS NULL OR t.pm_inquery_time IS NULL THEN NULL
  33. ELSE DATEDIFF(DAY, t.pm_inquery_time, t.actuality_delivery_date)
  34. END AS sampleLtInquery,
  35. t.plan_start_date,
  36. t.required_delivery_date,
  37. t.baseline,
  38. CASE
  39. WHEN t.baseline IS NULL OR latest_delivery_package.delivery_package_actual_date IS NULL THEN NULL
  40. ELSE DATEDIFF(DAY, latest_delivery_package.delivery_package_actual_date, t.baseline)
  41. END AS deliveryVariance,
  42. t.actuality_delivery_date,
  43. t.comments,
  44. t.remark,
  45. t.create_date,
  46. t.create_by,
  47. t.update_date,
  48. t.update_by,
  49. p.project_no,
  50. p.project_name,
  51. p.project_desc,
  52. pp.customer_no,
  53. p.bu_no,
  54. p.c_project_region,
  55. pp.project_manager,
  56. pp.project_owner,
  57. COALESCE(NULLIF(LTRIM(RTRIM(pp.project_owner)), ''),
  58. NULLIF(LTRIM(RTRIM(p.project_owner)), '')) AS pic,
  59. p.need_date,
  60. pp.test_part_no,
  61. pp.part_desc,
  62. pp.final_part_no,
  63. pp.part_type,
  64. pp.dry_wet_type AS dryWetType,
  65. pp.status as part_status,
  66. pp.build_date,
  67. c.customer_desc,
  68. dbo.get_bu_desc(p.site, p.bu_no) as bu_desc
  69. FROM plm_proofing_information_tracking t
  70. OUTER APPLY (
  71. SELECT TOP 1 pv.actual_date AS delivery_package_actual_date
  72. FROM plm_proofing_process_value pv
  73. WHERE pv.tracking_id = t.id
  74. AND pv.process_code = 'deliveryPackage'
  75. ORDER BY pv.update_date DESC, pv.create_date DESC
  76. ) latest_delivery_package
  77. LEFT JOIN plm_project_info_tracking p ON t.project_id = p.id
  78. LEFT JOIN plm_project_part_tracking pp ON t.project_part_id = pp.id
  79. LEFT JOIN plm_customer_information c ON pp.site = c.site AND pp.customer_no = c.customer_no
  80. <where>
  81. <if test="query.userName != null and query.userName != ''">
  82. p.site in (select site from eam_access_site where username = #{query.userName})
  83. and (p.site + '-' + p.bu_no) in (select * from dbo.query_bu(#{query.userName}))
  84. </if>
  85. <if test="query.site != null and query.site != ''">
  86. and t.site = #{query.site}
  87. </if>
  88. <if test="query.buNo != null and query.buNo != ''">
  89. and p.bu_no = CASE
  90. WHEN CHARINDEX('_', #{query.buNo}) > 0
  91. THEN SUBSTRING(#{query.buNo}, CHARINDEX('_', #{query.buNo}) + 1, LEN(#{query.buNo}))
  92. ELSE #{query.buNo}
  93. END
  94. </if>
  95. <if test="query.projectNo != null and query.projectNo != ''">
  96. and (
  97. UPPER(p.project_no) like '%' + UPPER(#{query.projectNo}) + '%'
  98. or p.project_no in (select value from CKT_MES_II_REAL.dbo.SplitString(#{query.projectNo}, ','))
  99. )
  100. </if>
  101. <if test="query.projectDesc != null and query.projectDesc != ''">
  102. and UPPER(p.project_desc) like '%' + UPPER(#{query.projectDesc}) + '%'
  103. </if>
  104. <if test="query.testPartNo != null and query.testPartNo != ''">
  105. and (
  106. UPPER(pp.test_part_no) like '%' + UPPER(#{query.testPartNo}) + '%'
  107. or pp.test_part_no in (select value from CKT_MES_II_REAL.dbo.SplitString(#{query.testPartNo}, ','))
  108. )
  109. </if>
  110. <if test="query.partDesc != null and query.partDesc != ''">
  111. and UPPER(pp.part_desc) like '%' + UPPER(#{query.partDesc}) + '%'
  112. </if>
  113. <choose>
  114. <!-- __EMPTY__ 为分类筛选“空”的查询专用标识。 -->
  115. <when test="query.dryWetType == '__EMPTY__'">
  116. and (pp.dry_wet_type IS NULL OR pp.dry_wet_type = '')
  117. </when>
  118. <when test="query.dryWetType != null and query.dryWetType != ''">
  119. and pp.dry_wet_type = #{query.dryWetType}
  120. </when>
  121. </choose>
  122. <if test="query.customerNo != null and query.customerNo != ''">
  123. and UPPER(pp.customer_no) like '%' + UPPER(#{query.customerNo}) + '%'
  124. </if>
  125. <if test="query.customerDesc != null and query.customerDesc != ''">
  126. and UPPER(c.customer_desc) like '%' + UPPER(#{query.customerDesc}) + '%'
  127. </if>
  128. <if test="query.proofingNo != null and query.proofingNo != ''">
  129. and UPPER(t.proofing_no) like '%' + UPPER(#{query.proofingNo}) + '%'
  130. </if>
  131. <if test="query.cProjectRegion != null and query.cProjectRegion != ''">
  132. and p.c_project_region = #{query.cProjectRegion}
  133. </if>
  134. <if test="query.engineer != null and query.engineer != ''">
  135. and UPPER(LTRIM(RTRIM(ISNULL(t.engineer, '')))) = UPPER(LTRIM(RTRIM(#{query.engineer})))
  136. </if>
  137. <if test="query.projectManager != null and query.projectManager != ''">
  138. and UPPER(LTRIM(RTRIM(ISNULL(pp.project_manager, '')))) = UPPER(LTRIM(RTRIM(#{query.projectManager})))
  139. </if>
  140. <if test="query.pic != null and query.pic != ''">
  141. <!-- PIC 与列表展示一致:优先物料 PJM,缺失时回退项目 PJM。 -->
  142. and UPPER(LTRIM(RTRIM(COALESCE(
  143. NULLIF(LTRIM(RTRIM(pp.project_owner)), ''),
  144. NULLIF(LTRIM(RTRIM(p.project_owner)), ''),
  145. ''
  146. )))) = UPPER(LTRIM(RTRIM(#{query.pic})))
  147. </if>
  148. <if test="query.proofingStatusList != null and query.proofingStatusList.size > 0">
  149. and t.proofing_status in
  150. <foreach collection="query.proofingStatusList" item="status" open="(" separator="," close=")">
  151. #{status}
  152. </foreach>
  153. </if>
  154. <if test="(query.proofingStatusList == null or query.proofingStatusList.size == 0) and query.proofingStatus != null and query.proofingStatus != ''">
  155. and t.proofing_status = #{query.proofingStatus}
  156. </if>
  157. <if test="query.projectPartSyncFlag != null and query.projectPartSyncFlag != ''">
  158. <!-- 同步判定规则:ID < 100000 视为已对齐到 NPI 正式数据。 -->
  159. <choose>
  160. <when test='query.projectPartSyncFlag == "Y"'>
  161. and t.project_part_id is not null
  162. and t.project_part_id &lt; 100000
  163. </when>
  164. <otherwise>
  165. and t.project_part_id &gt;= 100000
  166. </otherwise>
  167. </choose>
  168. </if>
  169. <if test="query.proofSyncFlag != null and query.proofSyncFlag != ''">
  170. <!-- 打样同步优先按 proofing_id 判定;为空时回退 tracking id 保持与前端显示一致。 -->
  171. <choose>
  172. <when test='query.proofSyncFlag == "Y"'>
  173. and ISNULL(t.proofing_id, t.id) &lt; 100000
  174. </when>
  175. <otherwise>
  176. and ISNULL(t.proofing_id, t.id) &gt;= 100000
  177. </otherwise>
  178. </choose>
  179. </if>
  180. <if test="query.projectCategory != null and query.projectCategory != ''">
  181. and p.project_category = #{query.projectCategory}
  182. </if>
  183. <if test="query.startDate != null">
  184. and t.plan_start_date >= #{query.startDate,jdbcType=DATE}
  185. </if>
  186. <if test="query.endDate != null">
  187. and #{query.endDate,jdbcType=DATE} >= t.plan_start_date
  188. </if>
  189. <if test="query.sampleMakingDateStart != null">
  190. and COALESCE(t.actuality_delivery_date, t.required_delivery_date) >= #{query.sampleMakingDateStart,jdbcType=DATE}
  191. </if>
  192. <if test="query.sampleMakingDateEnd != null">
  193. <!-- 包含结束日期当天的所有时间,不遗漏带时分秒的实际完成记录。 -->
  194. and COALESCE(t.actuality_delivery_date, t.required_delivery_date) &lt; DATEADD(DAY, 1, #{query.sampleMakingDateEnd,jdbcType=DATE})
  195. </if>
  196. <if test="query.pmInqueryTimeStart != null">
  197. and t.pm_inquery_time >= #{query.pmInqueryTimeStart,jdbcType=DATE}
  198. </if>
  199. <if test="query.pmInqueryTimeEnd != null">
  200. and #{query.pmInqueryTimeEnd,jdbcType=DATE} >= t.pm_inquery_time
  201. </if>
  202. <if test="query.importance != null and query.importance != ''">
  203. <choose>
  204. <when test='query.importance == "Y"'>
  205. and UPPER(ISNULL(t.importance, '')) = 'Y'
  206. </when>
  207. <otherwise>
  208. and UPPER(ISNULL(t.importance, '')) &lt;&gt; 'Y'
  209. </otherwise>
  210. </choose>
  211. </if>
  212. </where>
  213. order by t.create_date desc
  214. </select>
  215. <select id="querySearchCustomerOptions" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingCustomerOptionData">
  216. SELECT
  217. p.customer_no AS customerNo,
  218. MAX(ISNULL(c.customer_desc, '')) AS customerDesc
  219. FROM plm_project_info_tracking p
  220. LEFT JOIN plm_customer_information c ON p.site = c.site AND p.customer_no = c.customer_no
  221. <where>
  222. p.customer_no IS NOT NULL
  223. AND LTRIM(RTRIM(p.customer_no)) &lt;&gt; ''
  224. <if test="query.userName != null and query.userName != ''">
  225. and p.site in (select site from eam_access_site where username = #{query.userName})
  226. and (p.site + '-' + p.bu_no) in (select * from dbo.query_bu(#{query.userName}))
  227. </if>
  228. <if test="query.site != null and query.site != ''">
  229. and p.site = #{query.site}
  230. </if>
  231. <if test="query.buNo != null and query.buNo != ''">
  232. and p.bu_no = CASE
  233. WHEN CHARINDEX('_', #{query.buNo}) > 0
  234. THEN SUBSTRING(#{query.buNo}, CHARINDEX('_', #{query.buNo}) + 1, LEN(#{query.buNo}))
  235. ELSE #{query.buNo}
  236. END
  237. </if>
  238. <if test="query.customerNo != null and query.customerNo != ''">
  239. and (
  240. UPPER(p.customer_no) like '%' + UPPER(#{query.customerNo}) + '%'
  241. or UPPER(ISNULL(c.customer_desc, '')) like '%' + UPPER(#{query.customerNo}) + '%'
  242. )
  243. </if>
  244. </where>
  245. GROUP BY p.customer_no
  246. ORDER BY p.customer_no
  247. </select>
  248. <select id="selectProofTrackingById" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingData">
  249. SELECT
  250. id as tracking_id,
  251. site,
  252. project_id,
  253. project_part_id,
  254. proofing_id,
  255. proofing_no,
  256. proofing_status,
  257. project_phase,
  258. project_category,
  259. tracker,
  260. engineer,
  261. priority_level,
  262. proofing_number,
  263. plan_start_date,
  264. required_delivery_date,
  265. baseline,
  266. actuality_delivery_date,
  267. pm_inquery_time,
  268. importance,
  269. comments,
  270. remark,
  271. create_date,
  272. create_by,
  273. update_date,
  274. update_by
  275. FROM plm_proofing_information_tracking
  276. WHERE id = #{trackingId}
  277. </select>
  278. <select id="selectProjectInfoTrackingIdBySiteBuAndProjectNo" resultType="java.lang.Integer">
  279. SELECT TOP 1 id
  280. FROM plm_project_info_tracking
  281. WHERE site = #{site}
  282. AND bu_no = #{buNo}
  283. AND UPPER(LTRIM(RTRIM(project_no))) = UPPER(#{projectNo})
  284. ORDER BY
  285. CASE WHEN id &lt; 100000 THEN 0 ELSE 1 END,
  286. id DESC
  287. </select>
  288. <select id="selectProjectPartTrackingIdBySiteProjectAndPartNo" resultType="java.lang.Integer">
  289. SELECT TOP 1 id
  290. FROM plm_project_part_tracking
  291. WHERE site = #{site}
  292. AND project_id = #{projectId}
  293. AND UPPER(LTRIM(RTRIM(test_part_no))) = UPPER(#{testPartNo})
  294. ORDER BY
  295. CASE WHEN id &lt; 100000 THEN 0 ELSE 1 END,
  296. id DESC
  297. </select>
  298. <insert id="insertProjectInfoTrackingFromNpi">
  299. INSERT INTO plm_project_info_tracking
  300. (id, site, bu_no, project_no, ori_project_id, project_category, project_name, project_desc, status, project_source,
  301. customer_no, final_customer_id, priority, customer_remark, remark, need_date, parent_project_no, c_project_region,
  302. project_manager, project_owner, engineer, c_quality_engineer1, c_quality_engineer2, c_quality_engineer3,
  303. c_quality_engineer4, c_quality_engineer5, c_quality_engineer6, c_manufacture_engineer, doc_engineer,
  304. ipqc_hard_tag, c_quality_engineer7, doc_engineer2, project_creation_date, project_close_date,
  305. create_date, create_by, update_date, update_by)
  306. SELECT
  307. p.id,
  308. p.site,
  309. p.bu_no,
  310. p.project_no,
  311. p.ori_project_id,
  312. p.project_category,
  313. p.project_name,
  314. p.project_desc,
  315. ISNULL(p.status, N'草稿'),
  316. p.project_source,
  317. p.customer_no,
  318. p.final_customer_id,
  319. p.priority,
  320. '',
  321. p.remark,
  322. p.need_date,
  323. '',
  324. p.c_project_region,
  325. p.project_manager,
  326. p.project_owner,
  327. p.engineer,
  328. p.c_quality_engineer1,
  329. p.c_quality_engineer2,
  330. p.c_quality_engineer3,
  331. p.c_quality_engineer4,
  332. p.c_quality_engineer5,
  333. p.c_quality_engineer6,
  334. p.c_manufacture_engineer,
  335. p.doc_engineer,
  336. p.ipqc_hard_tag,
  337. p.c_quality_engineer7,
  338. p.doc_engineer2,
  339. p.project_creation_date,
  340. p.project_close_date,
  341. GETDATE(),
  342. #{operateUser},
  343. GETDATE(),
  344. #{operateUser}
  345. FROM plm_project_info p
  346. WHERE p.id = #{projectId}
  347. AND NOT EXISTS (
  348. SELECT 1
  349. FROM plm_project_info_tracking t
  350. WHERE t.id = p.id
  351. )
  352. </insert>
  353. <insert id="insertProjectPartTrackingFromNpi">
  354. INSERT INTO plm_project_part_tracking
  355. (id, site, project_id, test_part_no, part_type, dry_wet_type, part_desc, part_spec, material_number, final_part_desc,
  356. create_date, create_by, update_date, update_by, part_name, final_part_no, base_no, rev_no,
  357. project_manager, project_owner, build_date, c_quality_engineer1, c_quality_engineer2, c_quality_engineer3,
  358. c_manufacture_engineer, close_date, engineer, status, priority, project_category, need_date, doc_engineer,
  359. c_quality_engineer4, c_quality_engineer5, c_quality_engineer6, customer_no, ipqc_hard_tag, c_quality_engineer7, doc_engineer2, remark)
  360. SELECT
  361. pp.id,
  362. pp.site,
  363. pp.project_id,
  364. pp.test_part_no,
  365. pp.part_type,
  366. pp.dry_wet_type,
  367. pp.part_desc,
  368. pp.part_spec,
  369. pp.material_number,
  370. pp.final_part_desc,
  371. GETDATE(),
  372. #{operateUser},
  373. GETDATE(),
  374. #{operateUser},
  375. pp.part_name,
  376. pp.final_part_no,
  377. pp.base_no,
  378. pp.rev_no,
  379. pp.project_manager,
  380. pp.project_owner,
  381. pp.build_date,
  382. pp.c_quality_engineer1,
  383. pp.c_quality_engineer2,
  384. pp.c_quality_engineer3,
  385. pp.c_manufacture_engineer,
  386. pp.close_date,
  387. pp.engineer,
  388. ISNULL(pp.status, N'草稿'),
  389. pp.priority,
  390. pp.project_category,
  391. pp.need_date,
  392. pp.doc_engineer,
  393. pp.c_quality_engineer4,
  394. pp.c_quality_engineer5,
  395. pp.c_quality_engineer6,
  396. pp.customer_no,
  397. pp.ipqc_hard_tag,
  398. pp.c_quality_engineer7,
  399. pp.doc_engineer2,
  400. pp.remark
  401. FROM plm_project_part pp
  402. WHERE pp.project_id = #{projectId}
  403. AND pp.id = #{projectPartId}
  404. AND NOT EXISTS (
  405. SELECT 1
  406. FROM plm_project_part_tracking t
  407. WHERE t.id = pp.id
  408. )
  409. </insert>
  410. <insert id="insertProjectInfoFromOneKey">
  411. <selectKey keyProperty="projectId" resultType="int" order="BEFORE">
  412. SELECT ISNULL(MAX(CASE WHEN id >= 100000 THEN id END), 100000) + 1
  413. FROM plm_project_info_tracking WITH (TABLOCKX, HOLDLOCK)
  414. </selectKey>
  415. INSERT INTO plm_project_info_tracking
  416. (id, site, bu_no, project_no, ori_project_id, project_category, project_name, project_desc, status, project_source,
  417. customer_no, final_customer_id, priority, customer_remark, remark, need_date, parent_project_no, c_project_region,
  418. project_manager, project_owner, engineer, c_quality_engineer1, c_quality_engineer2, c_quality_engineer3,
  419. c_quality_engineer4, c_quality_engineer5, c_quality_engineer6, c_manufacture_engineer, doc_engineer,
  420. ipqc_hard_tag, c_quality_engineer7, doc_engineer2, project_creation_date, project_close_date,
  421. create_date, create_by, update_date, update_by)
  422. VALUES
  423. (#{projectId}, #{site}, #{buNo}, #{projectNo}, #{oriProjectId}, #{projectCategory}, #{projectName}, #{projectDesc}, #{projectStatus}, #{projectSource},
  424. #{customerNo}, #{finalCustomerId}, #{priorityLevel}, #{customerRemark}, #{remark}, #{needDate,jdbcType=DATE}, #{parentProjectNo}, #{cProjectRegion},
  425. #{projectManager}, #{projectOwner}, #{engineer}, #{cQualityEngineer1}, #{cQualityEngineer2}, #{cQualityEngineer3},
  426. #{cQualityEngineer4}, #{cQualityEngineer5}, #{cQualityEngineer6}, #{cManufactureEngineer}, #{docEngineer},
  427. #{ipqcHardTag}, #{cQualityEngineer7}, #{docEngineer2}, #{projectCreationDate,jdbcType=DATE}, #{projectCloseDate,jdbcType=DATE},
  428. GETDATE(), #{createBy}, GETDATE(), #{updateBy})
  429. </insert>
  430. <insert id="insertProjectPartFromOneKey">
  431. <selectKey keyProperty="projectPartId" resultType="int" order="BEFORE">
  432. SELECT ISNULL(MAX(CASE WHEN id >= 100000 THEN id END), 100000) + 1
  433. FROM plm_project_part_tracking WITH (TABLOCKX, HOLDLOCK)
  434. </selectKey>
  435. INSERT INTO plm_project_part_tracking
  436. (id, site, project_id, test_part_no, part_type, dry_wet_type, part_desc, part_spec, material_number, final_part_desc,
  437. create_date, create_by, update_date, update_by, part_name, final_part_no, base_no, rev_no,
  438. project_manager, project_owner, build_date, c_quality_engineer1, c_quality_engineer2, c_quality_engineer3,
  439. c_manufacture_engineer, close_date, engineer, status, priority, project_category, need_date, doc_engineer,
  440. c_quality_engineer4, c_quality_engineer5, c_quality_engineer6, customer_no, ipqc_hard_tag, c_quality_engineer7, doc_engineer2, remark)
  441. VALUES
  442. (#{projectPartId}, #{site}, #{projectId}, #{testPartNo}, #{partType}, #{dryWetType}, #{partDesc}, #{partSpec}, #{materialNumber}, #{finalPartDesc},
  443. GETDATE(), #{createBy}, GETDATE(), #{updateBy}, #{partName}, #{finalPartNo}, #{baseNo}, #{revNo},
  444. #{projectManager}, #{projectOwner}, #{buildDate,jdbcType=DATE}, #{cQualityEngineer1}, #{cQualityEngineer2}, #{cQualityEngineer3},
  445. #{cManufactureEngineer}, #{closeDate,jdbcType=DATE}, #{engineer}, #{partStatus}, #{priorityLevel}, #{projectCategory}, #{needDate,jdbcType=DATE}, #{docEngineer},
  446. #{cQualityEngineer4}, #{cQualityEngineer5}, #{cQualityEngineer6}, #{customerNo}, #{ipqcHardTag}, #{cQualityEngineer7}, #{docEngineer2}, #{remark})
  447. </insert>
  448. <insert id="insertProofTracking">
  449. <selectKey keyProperty="trackingId" resultType="int" order="BEFORE">
  450. SELECT CASE
  451. WHEN #{trackingId,jdbcType=INTEGER} IS NOT NULL AND #{trackingId,jdbcType=INTEGER} > 0
  452. THEN #{trackingId,jdbcType=INTEGER}
  453. ELSE (
  454. SELECT ISNULL(MAX(CASE WHEN id >= 100000 THEN id END), 100000) + 1
  455. FROM plm_proofing_information_tracking WITH (TABLOCKX, HOLDLOCK)
  456. )
  457. END
  458. </selectKey>
  459. INSERT INTO plm_proofing_information_tracking
  460. (id, site, project_id, project_part_id, proofing_id, proofing_no, proofing_status, project_phase, project_category,
  461. tracker, engineer, priority_level, proofing_number, plan_start_date, required_delivery_date, baseline, actuality_delivery_date,
  462. pm_inquery_time, importance, comments, remark, create_date, create_by, update_date, update_by)
  463. VALUES
  464. (#{trackingId}, #{site}, #{projectId}, #{projectPartId}, #{proofingId}, #{proofingNo}, #{proofingStatus}, #{projectPhase}, #{projectCategory},
  465. #{tracker}, #{engineer}, #{priorityLevel}, #{proofingNumber}, #{planStartDate,jdbcType=DATE}, #{requiredDeliveryDate,jdbcType=DATE}, #{baseline,jdbcType=DATE}, #{actualityDeliveryDate,jdbcType=DATE},
  466. #{pmInqueryTime,jdbcType=DATE}, #{importance}, #{comments}, #{remark}, GETDATE(), #{createBy}, GETDATE(), #{updateBy})
  467. </insert>
  468. <select id="selectProcessValuesByTrackingIds" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessValueData">
  469. SELECT
  470. tracking_id AS trackingId,
  471. site,
  472. process_code AS processCode,
  473. plan_date AS planDate,
  474. actual_date AS actualDate,
  475. process_status AS status,
  476. create_by AS createBy,
  477. update_by AS updateBy
  478. FROM plm_proofing_process_value
  479. WHERE tracking_id IN
  480. <foreach collection="trackingIds" item="trackingId" open="(" separator="," close=")">
  481. #{trackingId}
  482. </foreach>
  483. </select>
  484. <select id="selectProcessValueByTrackingAndCode" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessValueData">
  485. SELECT
  486. tracking_id AS trackingId,
  487. site,
  488. process_code AS processCode,
  489. plan_date AS planDate,
  490. actual_date AS actualDate,
  491. process_status AS status,
  492. create_by AS createBy,
  493. update_by AS updateBy
  494. FROM plm_proofing_process_value
  495. WHERE tracking_id = #{trackingId}
  496. AND process_code = #{processCode}
  497. </select>
  498. <update id="updateProcessValue">
  499. UPDATE plm_proofing_process_value
  500. SET actual_date = #{actualDate,jdbcType=DATE},
  501. process_status = #{status},
  502. update_date = GETDATE(),
  503. update_by = #{updateBy}
  504. WHERE tracking_id = #{trackingId}
  505. AND process_code = #{processCode}
  506. </update>
  507. <insert id="insertProcessValue">
  508. INSERT INTO plm_proofing_process_value
  509. (tracking_id, site, process_code, plan_date, actual_date, process_status, create_date, create_by, update_date, update_by)
  510. VALUES
  511. (#{trackingId}, #{site}, #{processCode}, #{planDate,jdbcType=DATE}, #{actualDate,jdbcType=DATE}, #{status}, GETDATE(), #{createBy}, GETDATE(), #{updateBy})
  512. </insert>
  513. <update id="finishProofing">
  514. UPDATE plm_proofing_information_tracking
  515. SET proofing_status = N'打样完成',
  516. actuality_delivery_date = ISNULL(#{actualityDeliveryDate,jdbcType=DATE}, GETDATE()),
  517. update_date = GETDATE(),
  518. update_by = #{updateBy}
  519. WHERE id = #{trackingId}
  520. </update>
  521. <update id="updateTrackingProofingStatusAndActualityDate">
  522. UPDATE plm_proofing_information_tracking
  523. SET proofing_status = #{proofingStatus},
  524. actuality_delivery_date = #{actualityDeliveryDate,jdbcType=DATE},
  525. update_date = GETDATE(),
  526. update_by = #{updateBy}
  527. WHERE id = #{trackingId}
  528. </update>
  529. <delete id="deleteProofTrackingLogByTrackingId">
  530. DELETE FROM plm_proofing_information_tracking_log
  531. WHERE tracking_id = #{trackingId}
  532. </delete>
  533. <delete id="deleteProcessValuesByTrackingId">
  534. DELETE FROM plm_proofing_process_value
  535. WHERE tracking_id = #{trackingId}
  536. </delete>
  537. <delete id="deleteProofTrackingByTrackingId">
  538. DELETE FROM plm_proofing_information_tracking
  539. WHERE id = #{trackingId}
  540. </delete>
  541. <update id="updateTrackingProofingInfo">
  542. UPDATE plm_proofing_information_tracking
  543. SET proofing_id = #{proofingId},
  544. proofing_no = #{proofingNo},
  545. proofing_number = #{proofingNumber},
  546. plan_start_date = #{planStartDate,jdbcType=DATE},
  547. required_delivery_date = #{requiredDeliveryDate,jdbcType=DATE},
  548. baseline = #{baseline,jdbcType=DATE},
  549. pm_inquery_time = #{pmInqueryTime,jdbcType=DATE},
  550. importance = #{importance},
  551. project_phase = #{projectPhase},
  552. proofing_status = #{proofingStatus},
  553. update_date = GETDATE(),
  554. update_by = #{updateBy}
  555. WHERE id = #{trackingId}
  556. </update>
  557. <update id="updateTrackingBaseInfo">
  558. UPDATE plm_proofing_information_tracking
  559. SET project_phase = #{projectPhase},
  560. project_category = #{projectCategory},
  561. proofing_no = #{proofingNo},
  562. proofing_status = #{proofingStatus},
  563. proofing_number = #{proofingNumber},
  564. plan_start_date = #{planStartDate,jdbcType=DATE},
  565. required_delivery_date = #{requiredDeliveryDate,jdbcType=DATE},
  566. baseline = #{baseline,jdbcType=DATE},
  567. pm_inquery_time = #{pmInqueryTime,jdbcType=DATE},
  568. importance = #{importance},
  569. tracker = #{tracker},
  570. engineer = #{engineer},
  571. priority_level = #{priorityLevel},
  572. remark = #{remark,jdbcType=NVARCHAR},
  573. update_date = GETDATE(),
  574. update_by = #{updateBy}
  575. WHERE id = #{trackingId}
  576. </update>
  577. <update id="updateTrackingRequiredDeliveryDate">
  578. UPDATE plm_proofing_information_tracking
  579. SET required_delivery_date = #{requiredDeliveryDate,jdbcType=DATE},
  580. update_date = GETDATE(),
  581. update_by = #{updateBy}
  582. WHERE id = #{trackingId}
  583. </update>
  584. <update id="updateTrackingBaselineWhenEmpty">
  585. UPDATE plm_proofing_information_tracking
  586. SET baseline = #{baseline,jdbcType=DATE},
  587. update_date = GETDATE(),
  588. update_by = #{updateBy}
  589. WHERE id = #{trackingId}
  590. AND baseline IS NULL
  591. </update>
  592. <update id="updateTrackingComments">
  593. UPDATE plm_proofing_information_tracking
  594. SET comments = #{comments,jdbcType=NVARCHAR},
  595. update_date = GETDATE(),
  596. update_by = #{updateBy}
  597. WHERE id = #{trackingId}
  598. </update>
  599. <select id="selectTrackingForProofing" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingData">
  600. SELECT
  601. t.id as tracking_id,
  602. t.site,
  603. t.project_id,
  604. t.project_part_id,
  605. t.proofing_id,
  606. t.proofing_no,
  607. t.proofing_status,
  608. t.project_phase,
  609. COALESCE(NULLIF(LTRIM(RTRIM(t.project_category)), ''),
  610. NULLIF(LTRIM(RTRIM(pp.project_category)), ''),
  611. NULLIF(LTRIM(RTRIM(p.project_category)), '')) AS project_category,
  612. t.tracker,
  613. t.engineer,
  614. t.priority_level,
  615. t.proofing_number,
  616. t.plan_start_date,
  617. t.required_delivery_date,
  618. t.baseline,
  619. t.actuality_delivery_date,
  620. t.pm_inquery_time,
  621. t.importance,
  622. t.comments,
  623. t.remark,
  624. t.create_date,
  625. t.create_by,
  626. t.update_date,
  627. t.update_by,
  628. p.project_no,
  629. p.project_name,
  630. p.project_desc,
  631. pp.customer_no,
  632. p.bu_no,
  633. pp.test_part_no,
  634. pp.part_desc,
  635. pp.final_part_no,
  636. pp.dry_wet_type AS dryWetType
  637. FROM plm_proofing_information_tracking t
  638. LEFT JOIN plm_project_info_tracking p ON t.project_id = p.id
  639. LEFT JOIN plm_project_part_tracking pp ON t.project_part_id = pp.id
  640. WHERE t.id = #{trackingId}
  641. </select>
  642. <insert id="insertTrackingFromPart">
  643. <selectKey keyProperty="trackingId" resultType="int" order="BEFORE">
  644. SELECT ISNULL(MAX(CASE WHEN id >= 100000 THEN id END), 100000) + 1
  645. FROM plm_proofing_information_tracking WITH (TABLOCKX, HOLDLOCK)
  646. </selectKey>
  647. INSERT INTO plm_proofing_information_tracking
  648. (id, site, project_id, project_part_id, proofing_id, proofing_no, proofing_status, project_phase, project_category,
  649. tracker, engineer, priority_level, proofing_number, plan_start_date, required_delivery_date, actuality_delivery_date,
  650. comments, remark, create_date, create_by, update_date, update_by)
  651. SELECT
  652. #{trackingId},
  653. pp.site,
  654. pp.project_id,
  655. pp.id,
  656. NULL,
  657. NULL,
  658. N'草稿',
  659. 'Sample',
  660. ISNULL(pp.project_category, p.project_category),
  661. ISNULL(pp.project_owner, ''),
  662. ISNULL(pp.engineer, ''),
  663. ISNULL(pp.priority, p.priority),
  664. 1,
  665. GETDATE(),
  666. NULL,
  667. NULL,
  668. NULL,
  669. NULL,
  670. GETDATE(), #{createBy}, GETDATE(), #{updateBy}
  671. FROM plm_project_part_tracking pp
  672. LEFT JOIN plm_project_info_tracking p ON pp.project_id = p.id
  673. WHERE pp.site = #{site}
  674. AND pp.project_id = #{projectId}
  675. AND pp.id = #{projectPartId}
  676. </insert>
  677. <select id="getSampleDocumentTypeIds" resultType="string">
  678. SELECT document_type_id
  679. FROM bu_document_list_definition
  680. WHERE site = #{site}
  681. AND bu_no = #{buNo}
  682. AND project_category = #{projectCategory}
  683. AND project_phase = 'Sample'
  684. </select>
  685. <select id="countProofDocumentExists" resultType="java.lang.Integer">
  686. SELECT COUNT(1)
  687. FROM plm_document_list_definition
  688. WHERE site = #{site}
  689. AND proofing_id = #{proofingId}
  690. AND project_id = #{projectId}
  691. AND test_part_id = #{projectPartId}
  692. AND document_type_id = #{documentTypeId}
  693. </select>
  694. <insert id="insertProofDocument">
  695. INSERT INTO plm_document_list_definition
  696. (site, proofing_id, test_part_id, project_id, created_by, manual_flag, uploaded_flag, create_date, document_type_id)
  697. VALUES
  698. (#{site}, #{proofingId}, #{projectPartId}, #{projectId}, #{createBy}, 'N', 'N', GETDATE(), #{documentTypeId})
  699. </insert>
  700. <select id="getProcessHistory" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessLogData">
  701. SELECT
  702. id,
  703. tracking_id,
  704. process_code,
  705. process_name,
  706. old_status,
  707. new_status,
  708. old_plan_date,
  709. new_plan_date,
  710. old_actual_date,
  711. new_actual_date,
  712. change_type,
  713. remark,
  714. changed_by,
  715. changed_date
  716. FROM plm_proofing_information_tracking_log
  717. WHERE tracking_id = #{trackingId}
  718. <if test="processCode != null and processCode != ''">
  719. AND process_code = #{processCode}
  720. </if>
  721. ORDER BY changed_date DESC, id DESC
  722. </select>
  723. <insert id="saveProcessLog">
  724. INSERT INTO plm_proofing_information_tracking_log
  725. (tracking_id, process_code, process_name, old_status, new_status, old_plan_date, new_plan_date,
  726. old_actual_date, new_actual_date, change_type, remark, changed_by, changed_date)
  727. VALUES
  728. (#{trackingId}, #{processCode}, #{processName}, #{oldStatus}, #{newStatus}, #{oldPlanDate,jdbcType=DATE},
  729. #{newPlanDate,jdbcType=DATE}, #{oldActualDate,jdbcType=DATE}, #{newActualDate,jdbcType=DATE},
  730. #{changeType}, #{remark}, #{changedBy}, GETDATE())
  731. </insert>
  732. <select id="selectProcessColumnsBySiteAndBu" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessColumnData">
  733. SELECT
  734. cfg.site,
  735. cfg.bu_no AS buNo,
  736. cfg.process_code AS code,
  737. cfg.process_label AS label,
  738. cfg.plan_field AS planField,
  739. cfg.actual_field AS actualField,
  740. cfg.status_field AS statusField,
  741. cfg.process_category_code AS processCategoryCode,
  742. category_ref.category_name AS processCategoryName,
  743. cfg.sort_no AS sortNo,
  744. cfg.active_flag AS activeFlag
  745. FROM plm_proofing_process_column_config cfg
  746. OUTER APPLY (
  747. SELECT TOP 1 category_name
  748. FROM plm_proofing_process_category
  749. WHERE category_code = cfg.process_category_code
  750. AND site = cfg.site
  751. AND bu_no = cfg.bu_no
  752. ORDER BY
  753. sort_no,
  754. category_code
  755. ) category_ref
  756. WHERE cfg.site = #{site}
  757. AND cfg.bu_no = #{buNo}
  758. AND cfg.active_flag = 'Y'
  759. ORDER BY cfg.sort_no, cfg.process_code
  760. </select>
  761. <select id="selectProcessColumnsBySiteAndBuAll" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessColumnData">
  762. SELECT
  763. cfg.site,
  764. cfg.bu_no AS buNo,
  765. cfg.process_code AS code,
  766. cfg.process_label AS label,
  767. cfg.plan_field AS planField,
  768. cfg.actual_field AS actualField,
  769. cfg.status_field AS statusField,
  770. cfg.process_category_code AS processCategoryCode,
  771. category_ref.category_name AS processCategoryName,
  772. cfg.sort_no AS sortNo,
  773. cfg.active_flag AS activeFlag
  774. FROM plm_proofing_process_column_config cfg
  775. OUTER APPLY (
  776. SELECT TOP 1 category_name
  777. FROM plm_proofing_process_category
  778. WHERE category_code = cfg.process_category_code
  779. AND site = cfg.site
  780. AND bu_no = cfg.bu_no
  781. ORDER BY
  782. sort_no,
  783. category_code
  784. ) category_ref
  785. WHERE cfg.site = #{site}
  786. AND cfg.bu_no = #{buNo}
  787. ORDER BY cfg.sort_no, cfg.process_code
  788. </select>
  789. <select id="selectConfiguredBuNosForSite" resultType="string">
  790. SELECT DISTINCT bu_no
  791. FROM plm_proofing_process_column_config
  792. WHERE bu_no != '*'
  793. AND site = #{site}
  794. ORDER BY bu_no
  795. </select>
  796. <update id="updateProcessColumnConfig">
  797. UPDATE plm_proofing_process_column_config
  798. SET sort_no = #{sortNo},
  799. process_category_code = #{processCategoryCode},
  800. active_flag = #{activeFlag},
  801. update_date = GETDATE(),
  802. update_by = #{updateBy}
  803. WHERE site = #{site}
  804. AND bu_no = #{buNo}
  805. AND process_code = #{processCode}
  806. </update>
  807. <delete id="deleteProcessColumnConfigBySiteAndBu">
  808. DELETE FROM plm_proofing_process_column_config
  809. WHERE site = #{site}
  810. AND bu_no = #{buNo}
  811. </delete>
  812. <delete id="deleteProcessColumnConfigBySiteBuAndCodes">
  813. DELETE FROM plm_proofing_process_column_config
  814. WHERE site = #{site}
  815. AND bu_no = #{buNo}
  816. AND process_code IN
  817. <foreach collection="processCodes" item="code" open="(" separator="," close=")">
  818. #{code}
  819. </foreach>
  820. </delete>
  821. <insert id="insertProcessColumnConfig">
  822. INSERT INTO plm_proofing_process_column_config
  823. (site, bu_no, process_code, process_label, plan_field, actual_field, status_field, process_category_code, sort_no, active_flag,
  824. create_date, create_by, update_date, update_by)
  825. VALUES
  826. (#{site}, #{buNo}, #{code}, #{label}, #{planField}, #{actualField}, #{statusField}, #{processCategoryCode}, #{sortNo}, #{activeFlag},
  827. GETDATE(), #{createBy}, GETDATE(), #{updateBy})
  828. </insert>
  829. <select id="selectProcessCategoriesBySiteAndBu" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessCategoryData">
  830. SELECT
  831. site,
  832. bu_no AS buNo,
  833. category_code AS categoryCode,
  834. category_name AS categoryName,
  835. sort_no AS sortNo
  836. FROM plm_proofing_process_category
  837. WHERE site = #{site}
  838. AND bu_no = #{buNo}
  839. ORDER BY sort_no, category_code
  840. </select>
  841. <delete id="deleteProcessCategoryBySiteAndBu">
  842. DELETE FROM plm_proofing_process_category
  843. WHERE site = #{site}
  844. AND bu_no = #{buNo}
  845. </delete>
  846. <select id="selectUsedProcessCategoryCodes" resultType="string">
  847. SELECT DISTINCT process_category_code
  848. FROM plm_proofing_process_column_config
  849. WHERE site = #{site}
  850. AND bu_no = #{buNo}
  851. AND LTRIM(RTRIM(ISNULL(process_category_code, ''))) != ''
  852. </select>
  853. <insert id="insertProcessCategory">
  854. INSERT INTO plm_proofing_process_category
  855. (site, bu_no, category_code, category_name, sort_no, create_date, create_by, update_date, update_by)
  856. VALUES
  857. (#{site}, #{buNo}, #{categoryCode}, #{categoryName}, #{sortNo}, GETDATE(), #{createBy}, GETDATE(), #{updateBy})
  858. </insert>
  859. </mapper>