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
903 lines
39 KiB
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="com.xujie.sys.modules.sampletracking.mapper.SampleProofTrackingMapper">
|
|
|
|
<select id="searchProofTracking" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingData">
|
|
SELECT
|
|
t.id as tracking_id,
|
|
t.site,
|
|
t.project_id,
|
|
t.project_part_id,
|
|
t.proofing_id,
|
|
t.proofing_no,
|
|
t.proofing_status,
|
|
t.project_phase,
|
|
COALESCE(NULLIF(LTRIM(RTRIM(t.project_category)), ''),
|
|
NULLIF(LTRIM(RTRIM(p.project_category)), ''),
|
|
NULLIF(LTRIM(RTRIM(pp.project_category)), '')) AS project_category,
|
|
t.tracker,
|
|
t.engineer,
|
|
t.priority_level,
|
|
t.proofing_number,
|
|
t.proofing_number AS sampleQty,
|
|
t.pm_inquery_time,
|
|
t.importance,
|
|
-- 实际完成日期优先;为空时使用预计完成日期,与 Sample making Date 筛选保持一致。
|
|
YEAR(COALESCE(t.actuality_delivery_date, t.required_delivery_date)) AS sampleMakingYear,
|
|
MONTH(COALESCE(t.actuality_delivery_date, t.required_delivery_date)) AS sampleMakingMonth,
|
|
CASE
|
|
WHEN t.actuality_delivery_date IS NULL OR t.plan_start_date IS NULL THEN NULL
|
|
ELSE DATEDIFF(DAY, t.plan_start_date, t.actuality_delivery_date)
|
|
END AS sampleLt,
|
|
CASE
|
|
WHEN t.actuality_delivery_date IS NULL OR t.pm_inquery_time IS NULL THEN NULL
|
|
ELSE DATEDIFF(DAY, t.pm_inquery_time, t.actuality_delivery_date)
|
|
END AS sampleLtInquery,
|
|
t.plan_start_date,
|
|
t.required_delivery_date,
|
|
t.baseline,
|
|
CASE
|
|
WHEN t.baseline IS NULL OR latest_delivery_package.delivery_package_actual_date IS NULL THEN NULL
|
|
ELSE DATEDIFF(DAY, latest_delivery_package.delivery_package_actual_date, t.baseline)
|
|
END AS deliveryVariance,
|
|
t.actuality_delivery_date,
|
|
t.comments,
|
|
t.remark,
|
|
t.create_date,
|
|
t.create_by,
|
|
t.update_date,
|
|
t.update_by,
|
|
p.project_no,
|
|
p.project_name,
|
|
p.project_desc,
|
|
pp.customer_no,
|
|
p.bu_no,
|
|
p.c_project_region,
|
|
pp.project_manager,
|
|
pp.project_owner,
|
|
COALESCE(NULLIF(LTRIM(RTRIM(pp.project_owner)), ''),
|
|
NULLIF(LTRIM(RTRIM(p.project_owner)), '')) AS pic,
|
|
p.need_date,
|
|
pp.test_part_no,
|
|
pp.part_desc,
|
|
pp.final_part_no,
|
|
pp.part_type,
|
|
pp.dry_wet_type AS dryWetType,
|
|
pp.status as part_status,
|
|
pp.build_date,
|
|
c.customer_desc,
|
|
dbo.get_bu_desc(p.site, p.bu_no) as bu_desc
|
|
FROM plm_proofing_information_tracking t
|
|
OUTER APPLY (
|
|
SELECT TOP 1 pv.actual_date AS delivery_package_actual_date
|
|
FROM plm_proofing_process_value pv
|
|
WHERE pv.tracking_id = t.id
|
|
AND pv.process_code = 'deliveryPackage'
|
|
ORDER BY pv.update_date DESC, pv.create_date DESC
|
|
) latest_delivery_package
|
|
LEFT JOIN plm_project_info_tracking p ON t.project_id = p.id
|
|
LEFT JOIN plm_project_part_tracking pp ON t.project_part_id = pp.id
|
|
LEFT JOIN plm_customer_information c ON pp.site = c.site AND pp.customer_no = c.customer_no
|
|
<where>
|
|
<if test="query.userName != null and query.userName != ''">
|
|
p.site in (select site from eam_access_site where username = #{query.userName})
|
|
and (p.site + '-' + p.bu_no) in (select * from dbo.query_bu(#{query.userName}))
|
|
</if>
|
|
<if test="query.site != null and query.site != ''">
|
|
and t.site = #{query.site}
|
|
</if>
|
|
<if test="query.buNo != null and query.buNo != ''">
|
|
and p.bu_no = CASE
|
|
WHEN CHARINDEX('_', #{query.buNo}) > 0
|
|
THEN SUBSTRING(#{query.buNo}, CHARINDEX('_', #{query.buNo}) + 1, LEN(#{query.buNo}))
|
|
ELSE #{query.buNo}
|
|
END
|
|
</if>
|
|
<if test="query.projectNo != null and query.projectNo != ''">
|
|
and (
|
|
UPPER(p.project_no) like '%' + UPPER(#{query.projectNo}) + '%'
|
|
or p.project_no in (select value from CKT_MES_II_REAL.dbo.SplitString(#{query.projectNo}, ','))
|
|
)
|
|
</if>
|
|
<if test="query.projectDesc != null and query.projectDesc != ''">
|
|
and UPPER(p.project_desc) like '%' + UPPER(#{query.projectDesc}) + '%'
|
|
</if>
|
|
<if test="query.testPartNo != null and query.testPartNo != ''">
|
|
and (
|
|
UPPER(pp.test_part_no) like '%' + UPPER(#{query.testPartNo}) + '%'
|
|
or pp.test_part_no in (select value from CKT_MES_II_REAL.dbo.SplitString(#{query.testPartNo}, ','))
|
|
)
|
|
</if>
|
|
<if test="query.partDesc != null and query.partDesc != ''">
|
|
and UPPER(pp.part_desc) like '%' + UPPER(#{query.partDesc}) + '%'
|
|
</if>
|
|
<choose>
|
|
<!-- __EMPTY__ 为分类筛选“空”的查询专用标识。 -->
|
|
<when test="query.dryWetType == '__EMPTY__'">
|
|
and (pp.dry_wet_type IS NULL OR pp.dry_wet_type = '')
|
|
</when>
|
|
<when test="query.dryWetType != null and query.dryWetType != ''">
|
|
and pp.dry_wet_type = #{query.dryWetType}
|
|
</when>
|
|
</choose>
|
|
<if test="query.customerNo != null and query.customerNo != ''">
|
|
and UPPER(pp.customer_no) like '%' + UPPER(#{query.customerNo}) + '%'
|
|
</if>
|
|
<if test="query.customerDesc != null and query.customerDesc != ''">
|
|
and UPPER(c.customer_desc) like '%' + UPPER(#{query.customerDesc}) + '%'
|
|
</if>
|
|
<if test="query.proofingNo != null and query.proofingNo != ''">
|
|
and UPPER(t.proofing_no) like '%' + UPPER(#{query.proofingNo}) + '%'
|
|
</if>
|
|
<if test="query.cProjectRegion != null and query.cProjectRegion != ''">
|
|
and p.c_project_region = #{query.cProjectRegion}
|
|
</if>
|
|
<if test="query.engineer != null and query.engineer != ''">
|
|
and UPPER(LTRIM(RTRIM(ISNULL(t.engineer, '')))) = UPPER(LTRIM(RTRIM(#{query.engineer})))
|
|
</if>
|
|
<if test="query.projectManager != null and query.projectManager != ''">
|
|
and UPPER(LTRIM(RTRIM(ISNULL(pp.project_manager, '')))) = UPPER(LTRIM(RTRIM(#{query.projectManager})))
|
|
</if>
|
|
<if test="query.pic != null and query.pic != ''">
|
|
<!-- PIC 与列表展示一致:优先物料 PJM,缺失时回退项目 PJM。 -->
|
|
and UPPER(LTRIM(RTRIM(COALESCE(
|
|
NULLIF(LTRIM(RTRIM(pp.project_owner)), ''),
|
|
NULLIF(LTRIM(RTRIM(p.project_owner)), ''),
|
|
''
|
|
)))) = UPPER(LTRIM(RTRIM(#{query.pic})))
|
|
</if>
|
|
<if test="query.proofingStatusList != null and query.proofingStatusList.size > 0">
|
|
and t.proofing_status in
|
|
<foreach collection="query.proofingStatusList" item="status" open="(" separator="," close=")">
|
|
#{status}
|
|
</foreach>
|
|
</if>
|
|
<if test="(query.proofingStatusList == null or query.proofingStatusList.size == 0) and query.proofingStatus != null and query.proofingStatus != ''">
|
|
and t.proofing_status = #{query.proofingStatus}
|
|
</if>
|
|
<if test="query.projectPartSyncFlag != null and query.projectPartSyncFlag != ''">
|
|
<!-- 同步判定规则:ID < 100000 视为已对齐到 NPI 正式数据。 -->
|
|
<choose>
|
|
<when test='query.projectPartSyncFlag == "Y"'>
|
|
and t.project_part_id is not null
|
|
and t.project_part_id < 100000
|
|
</when>
|
|
<otherwise>
|
|
and t.project_part_id >= 100000
|
|
</otherwise>
|
|
</choose>
|
|
</if>
|
|
<if test="query.proofSyncFlag != null and query.proofSyncFlag != ''">
|
|
<!-- 打样同步优先按 proofing_id 判定;为空时回退 tracking id 保持与前端显示一致。 -->
|
|
<choose>
|
|
<when test='query.proofSyncFlag == "Y"'>
|
|
and ISNULL(t.proofing_id, t.id) < 100000
|
|
</when>
|
|
<otherwise>
|
|
and ISNULL(t.proofing_id, t.id) >= 100000
|
|
</otherwise>
|
|
</choose>
|
|
</if>
|
|
<if test="query.projectCategory != null and query.projectCategory != ''">
|
|
and p.project_category = #{query.projectCategory}
|
|
</if>
|
|
<if test="query.startDate != null">
|
|
and t.plan_start_date >= #{query.startDate,jdbcType=DATE}
|
|
</if>
|
|
<if test="query.endDate != null">
|
|
and #{query.endDate,jdbcType=DATE} >= t.plan_start_date
|
|
</if>
|
|
<if test="query.sampleMakingDateStart != null">
|
|
and COALESCE(t.actuality_delivery_date, t.required_delivery_date) >= #{query.sampleMakingDateStart,jdbcType=DATE}
|
|
</if>
|
|
<if test="query.sampleMakingDateEnd != null">
|
|
<!-- 包含结束日期当天的所有时间,不遗漏带时分秒的实际完成记录。 -->
|
|
and COALESCE(t.actuality_delivery_date, t.required_delivery_date) < DATEADD(DAY, 1, #{query.sampleMakingDateEnd,jdbcType=DATE})
|
|
</if>
|
|
<if test="query.pmInqueryTimeStart != null">
|
|
and t.pm_inquery_time >= #{query.pmInqueryTimeStart,jdbcType=DATE}
|
|
</if>
|
|
<if test="query.pmInqueryTimeEnd != null">
|
|
and #{query.pmInqueryTimeEnd,jdbcType=DATE} >= t.pm_inquery_time
|
|
</if>
|
|
<if test="query.importance != null and query.importance != ''">
|
|
<choose>
|
|
<when test='query.importance == "Y"'>
|
|
and UPPER(ISNULL(t.importance, '')) = 'Y'
|
|
</when>
|
|
<otherwise>
|
|
and UPPER(ISNULL(t.importance, '')) <> 'Y'
|
|
</otherwise>
|
|
</choose>
|
|
</if>
|
|
</where>
|
|
order by t.create_date desc
|
|
</select>
|
|
|
|
<select id="querySearchCustomerOptions" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingCustomerOptionData">
|
|
SELECT
|
|
p.customer_no AS customerNo,
|
|
MAX(ISNULL(c.customer_desc, '')) AS customerDesc
|
|
FROM plm_project_info_tracking p
|
|
LEFT JOIN plm_customer_information c ON p.site = c.site AND p.customer_no = c.customer_no
|
|
<where>
|
|
p.customer_no IS NOT NULL
|
|
AND LTRIM(RTRIM(p.customer_no)) <> ''
|
|
<if test="query.userName != null and query.userName != ''">
|
|
and p.site in (select site from eam_access_site where username = #{query.userName})
|
|
and (p.site + '-' + p.bu_no) in (select * from dbo.query_bu(#{query.userName}))
|
|
</if>
|
|
<if test="query.site != null and query.site != ''">
|
|
and p.site = #{query.site}
|
|
</if>
|
|
<if test="query.buNo != null and query.buNo != ''">
|
|
and p.bu_no = CASE
|
|
WHEN CHARINDEX('_', #{query.buNo}) > 0
|
|
THEN SUBSTRING(#{query.buNo}, CHARINDEX('_', #{query.buNo}) + 1, LEN(#{query.buNo}))
|
|
ELSE #{query.buNo}
|
|
END
|
|
</if>
|
|
<if test="query.customerNo != null and query.customerNo != ''">
|
|
and (
|
|
UPPER(p.customer_no) like '%' + UPPER(#{query.customerNo}) + '%'
|
|
or UPPER(ISNULL(c.customer_desc, '')) like '%' + UPPER(#{query.customerNo}) + '%'
|
|
)
|
|
</if>
|
|
</where>
|
|
GROUP BY p.customer_no
|
|
ORDER BY p.customer_no
|
|
</select>
|
|
|
|
<select id="selectProofTrackingById" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingData">
|
|
SELECT
|
|
id as tracking_id,
|
|
site,
|
|
project_id,
|
|
project_part_id,
|
|
proofing_id,
|
|
proofing_no,
|
|
proofing_status,
|
|
project_phase,
|
|
project_category,
|
|
tracker,
|
|
engineer,
|
|
priority_level,
|
|
proofing_number,
|
|
plan_start_date,
|
|
required_delivery_date,
|
|
baseline,
|
|
actuality_delivery_date,
|
|
pm_inquery_time,
|
|
importance,
|
|
comments,
|
|
remark,
|
|
create_date,
|
|
create_by,
|
|
update_date,
|
|
update_by
|
|
FROM plm_proofing_information_tracking
|
|
WHERE id = #{trackingId}
|
|
</select>
|
|
|
|
<select id="selectProjectInfoTrackingIdBySiteBuAndProjectNo" resultType="java.lang.Integer">
|
|
SELECT TOP 1 id
|
|
FROM plm_project_info_tracking
|
|
WHERE site = #{site}
|
|
AND bu_no = #{buNo}
|
|
AND UPPER(LTRIM(RTRIM(project_no))) = UPPER(#{projectNo})
|
|
ORDER BY
|
|
CASE WHEN id < 100000 THEN 0 ELSE 1 END,
|
|
id DESC
|
|
</select>
|
|
|
|
<select id="selectProjectPartTrackingIdBySiteProjectAndPartNo" resultType="java.lang.Integer">
|
|
SELECT TOP 1 id
|
|
FROM plm_project_part_tracking
|
|
WHERE site = #{site}
|
|
AND project_id = #{projectId}
|
|
AND UPPER(LTRIM(RTRIM(test_part_no))) = UPPER(#{testPartNo})
|
|
ORDER BY
|
|
CASE WHEN id < 100000 THEN 0 ELSE 1 END,
|
|
id DESC
|
|
</select>
|
|
|
|
<insert id="insertProjectInfoTrackingFromNpi">
|
|
INSERT INTO plm_project_info_tracking
|
|
(id, site, bu_no, project_no, ori_project_id, project_category, project_name, project_desc, status, project_source,
|
|
customer_no, final_customer_id, priority, customer_remark, remark, need_date, parent_project_no, c_project_region,
|
|
project_manager, project_owner, engineer, c_quality_engineer1, c_quality_engineer2, c_quality_engineer3,
|
|
c_quality_engineer4, c_quality_engineer5, c_quality_engineer6, c_manufacture_engineer, doc_engineer,
|
|
ipqc_hard_tag, c_quality_engineer7, doc_engineer2, project_creation_date, project_close_date,
|
|
create_date, create_by, update_date, update_by)
|
|
SELECT
|
|
p.id,
|
|
p.site,
|
|
p.bu_no,
|
|
p.project_no,
|
|
p.ori_project_id,
|
|
p.project_category,
|
|
p.project_name,
|
|
p.project_desc,
|
|
ISNULL(p.status, N'草稿'),
|
|
p.project_source,
|
|
p.customer_no,
|
|
p.final_customer_id,
|
|
p.priority,
|
|
'',
|
|
p.remark,
|
|
p.need_date,
|
|
'',
|
|
p.c_project_region,
|
|
p.project_manager,
|
|
p.project_owner,
|
|
p.engineer,
|
|
p.c_quality_engineer1,
|
|
p.c_quality_engineer2,
|
|
p.c_quality_engineer3,
|
|
p.c_quality_engineer4,
|
|
p.c_quality_engineer5,
|
|
p.c_quality_engineer6,
|
|
p.c_manufacture_engineer,
|
|
p.doc_engineer,
|
|
p.ipqc_hard_tag,
|
|
p.c_quality_engineer7,
|
|
p.doc_engineer2,
|
|
p.project_creation_date,
|
|
p.project_close_date,
|
|
GETDATE(),
|
|
#{operateUser},
|
|
GETDATE(),
|
|
#{operateUser}
|
|
FROM plm_project_info p
|
|
WHERE p.id = #{projectId}
|
|
AND NOT EXISTS (
|
|
SELECT 1
|
|
FROM plm_project_info_tracking t
|
|
WHERE t.id = p.id
|
|
)
|
|
</insert>
|
|
|
|
<insert id="insertProjectPartTrackingFromNpi">
|
|
INSERT INTO plm_project_part_tracking
|
|
(id, site, project_id, test_part_no, part_type, dry_wet_type, part_desc, part_spec, material_number, final_part_desc,
|
|
create_date, create_by, update_date, update_by, part_name, final_part_no, base_no, rev_no,
|
|
project_manager, project_owner, build_date, c_quality_engineer1, c_quality_engineer2, c_quality_engineer3,
|
|
c_manufacture_engineer, close_date, engineer, status, priority, project_category, need_date, doc_engineer,
|
|
c_quality_engineer4, c_quality_engineer5, c_quality_engineer6, customer_no, ipqc_hard_tag, c_quality_engineer7, doc_engineer2, remark)
|
|
SELECT
|
|
pp.id,
|
|
pp.site,
|
|
pp.project_id,
|
|
pp.test_part_no,
|
|
pp.part_type,
|
|
pp.dry_wet_type,
|
|
pp.part_desc,
|
|
pp.part_spec,
|
|
pp.material_number,
|
|
pp.final_part_desc,
|
|
GETDATE(),
|
|
#{operateUser},
|
|
GETDATE(),
|
|
#{operateUser},
|
|
pp.part_name,
|
|
pp.final_part_no,
|
|
pp.base_no,
|
|
pp.rev_no,
|
|
pp.project_manager,
|
|
pp.project_owner,
|
|
pp.build_date,
|
|
pp.c_quality_engineer1,
|
|
pp.c_quality_engineer2,
|
|
pp.c_quality_engineer3,
|
|
pp.c_manufacture_engineer,
|
|
pp.close_date,
|
|
pp.engineer,
|
|
ISNULL(pp.status, N'草稿'),
|
|
pp.priority,
|
|
pp.project_category,
|
|
pp.need_date,
|
|
pp.doc_engineer,
|
|
pp.c_quality_engineer4,
|
|
pp.c_quality_engineer5,
|
|
pp.c_quality_engineer6,
|
|
pp.customer_no,
|
|
pp.ipqc_hard_tag,
|
|
pp.c_quality_engineer7,
|
|
pp.doc_engineer2,
|
|
pp.remark
|
|
FROM plm_project_part pp
|
|
WHERE pp.project_id = #{projectId}
|
|
AND pp.id = #{projectPartId}
|
|
AND NOT EXISTS (
|
|
SELECT 1
|
|
FROM plm_project_part_tracking t
|
|
WHERE t.id = pp.id
|
|
)
|
|
</insert>
|
|
|
|
<insert id="insertProjectInfoFromOneKey">
|
|
<selectKey keyProperty="projectId" resultType="int" order="BEFORE">
|
|
SELECT ISNULL(MAX(CASE WHEN id >= 100000 THEN id END), 100000) + 1
|
|
FROM plm_project_info_tracking WITH (TABLOCKX, HOLDLOCK)
|
|
</selectKey>
|
|
INSERT INTO plm_project_info_tracking
|
|
(id, site, bu_no, project_no, ori_project_id, project_category, project_name, project_desc, status, project_source,
|
|
customer_no, final_customer_id, priority, customer_remark, remark, need_date, parent_project_no, c_project_region,
|
|
project_manager, project_owner, engineer, c_quality_engineer1, c_quality_engineer2, c_quality_engineer3,
|
|
c_quality_engineer4, c_quality_engineer5, c_quality_engineer6, c_manufacture_engineer, doc_engineer,
|
|
ipqc_hard_tag, c_quality_engineer7, doc_engineer2, project_creation_date, project_close_date,
|
|
create_date, create_by, update_date, update_by)
|
|
VALUES
|
|
(#{projectId}, #{site}, #{buNo}, #{projectNo}, #{oriProjectId}, #{projectCategory}, #{projectName}, #{projectDesc}, #{projectStatus}, #{projectSource},
|
|
#{customerNo}, #{finalCustomerId}, #{priorityLevel}, #{customerRemark}, #{remark}, #{needDate,jdbcType=DATE}, #{parentProjectNo}, #{cProjectRegion},
|
|
#{projectManager}, #{projectOwner}, #{engineer}, #{cQualityEngineer1}, #{cQualityEngineer2}, #{cQualityEngineer3},
|
|
#{cQualityEngineer4}, #{cQualityEngineer5}, #{cQualityEngineer6}, #{cManufactureEngineer}, #{docEngineer},
|
|
#{ipqcHardTag}, #{cQualityEngineer7}, #{docEngineer2}, #{projectCreationDate,jdbcType=DATE}, #{projectCloseDate,jdbcType=DATE},
|
|
GETDATE(), #{createBy}, GETDATE(), #{updateBy})
|
|
</insert>
|
|
|
|
<insert id="insertProjectPartFromOneKey">
|
|
<selectKey keyProperty="projectPartId" resultType="int" order="BEFORE">
|
|
SELECT ISNULL(MAX(CASE WHEN id >= 100000 THEN id END), 100000) + 1
|
|
FROM plm_project_part_tracking WITH (TABLOCKX, HOLDLOCK)
|
|
</selectKey>
|
|
INSERT INTO plm_project_part_tracking
|
|
(id, site, project_id, test_part_no, part_type, dry_wet_type, part_desc, part_spec, material_number, final_part_desc,
|
|
create_date, create_by, update_date, update_by, part_name, final_part_no, base_no, rev_no,
|
|
project_manager, project_owner, build_date, c_quality_engineer1, c_quality_engineer2, c_quality_engineer3,
|
|
c_manufacture_engineer, close_date, engineer, status, priority, project_category, need_date, doc_engineer,
|
|
c_quality_engineer4, c_quality_engineer5, c_quality_engineer6, customer_no, ipqc_hard_tag, c_quality_engineer7, doc_engineer2, remark)
|
|
VALUES
|
|
(#{projectPartId}, #{site}, #{projectId}, #{testPartNo}, #{partType}, #{dryWetType}, #{partDesc}, #{partSpec}, #{materialNumber}, #{finalPartDesc},
|
|
GETDATE(), #{createBy}, GETDATE(), #{updateBy}, #{partName}, #{finalPartNo}, #{baseNo}, #{revNo},
|
|
#{projectManager}, #{projectOwner}, #{buildDate,jdbcType=DATE}, #{cQualityEngineer1}, #{cQualityEngineer2}, #{cQualityEngineer3},
|
|
#{cManufactureEngineer}, #{closeDate,jdbcType=DATE}, #{engineer}, #{partStatus}, #{priorityLevel}, #{projectCategory}, #{needDate,jdbcType=DATE}, #{docEngineer},
|
|
#{cQualityEngineer4}, #{cQualityEngineer5}, #{cQualityEngineer6}, #{customerNo}, #{ipqcHardTag}, #{cQualityEngineer7}, #{docEngineer2}, #{remark})
|
|
</insert>
|
|
|
|
<insert id="insertProofTracking">
|
|
<selectKey keyProperty="trackingId" resultType="int" order="BEFORE">
|
|
SELECT CASE
|
|
WHEN #{trackingId,jdbcType=INTEGER} IS NOT NULL AND #{trackingId,jdbcType=INTEGER} > 0
|
|
THEN #{trackingId,jdbcType=INTEGER}
|
|
ELSE (
|
|
SELECT ISNULL(MAX(CASE WHEN id >= 100000 THEN id END), 100000) + 1
|
|
FROM plm_proofing_information_tracking WITH (TABLOCKX, HOLDLOCK)
|
|
)
|
|
END
|
|
</selectKey>
|
|
INSERT INTO plm_proofing_information_tracking
|
|
(id, site, project_id, project_part_id, proofing_id, proofing_no, proofing_status, project_phase, project_category,
|
|
tracker, engineer, priority_level, proofing_number, plan_start_date, required_delivery_date, baseline, actuality_delivery_date,
|
|
pm_inquery_time, importance, comments, remark, create_date, create_by, update_date, update_by)
|
|
VALUES
|
|
(#{trackingId}, #{site}, #{projectId}, #{projectPartId}, #{proofingId}, #{proofingNo}, #{proofingStatus}, #{projectPhase}, #{projectCategory},
|
|
#{tracker}, #{engineer}, #{priorityLevel}, #{proofingNumber}, #{planStartDate,jdbcType=DATE}, #{requiredDeliveryDate,jdbcType=DATE}, #{baseline,jdbcType=DATE}, #{actualityDeliveryDate,jdbcType=DATE},
|
|
#{pmInqueryTime,jdbcType=DATE}, #{importance}, #{comments}, #{remark}, GETDATE(), #{createBy}, GETDATE(), #{updateBy})
|
|
</insert>
|
|
|
|
<select id="selectProcessValuesByTrackingIds" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessValueData">
|
|
SELECT
|
|
tracking_id AS trackingId,
|
|
site,
|
|
process_code AS processCode,
|
|
plan_date AS planDate,
|
|
actual_date AS actualDate,
|
|
process_status AS status,
|
|
create_by AS createBy,
|
|
update_by AS updateBy
|
|
FROM plm_proofing_process_value
|
|
WHERE tracking_id IN
|
|
<foreach collection="trackingIds" item="trackingId" open="(" separator="," close=")">
|
|
#{trackingId}
|
|
</foreach>
|
|
</select>
|
|
|
|
<select id="selectProcessValueByTrackingAndCode" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessValueData">
|
|
SELECT
|
|
tracking_id AS trackingId,
|
|
site,
|
|
process_code AS processCode,
|
|
plan_date AS planDate,
|
|
actual_date AS actualDate,
|
|
process_status AS status,
|
|
create_by AS createBy,
|
|
update_by AS updateBy
|
|
FROM plm_proofing_process_value
|
|
WHERE tracking_id = #{trackingId}
|
|
AND process_code = #{processCode}
|
|
</select>
|
|
|
|
<update id="updateProcessValue">
|
|
UPDATE plm_proofing_process_value
|
|
SET actual_date = #{actualDate,jdbcType=DATE},
|
|
process_status = #{status},
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE tracking_id = #{trackingId}
|
|
AND process_code = #{processCode}
|
|
</update>
|
|
|
|
<insert id="insertProcessValue">
|
|
INSERT INTO plm_proofing_process_value
|
|
(tracking_id, site, process_code, plan_date, actual_date, process_status, create_date, create_by, update_date, update_by)
|
|
VALUES
|
|
(#{trackingId}, #{site}, #{processCode}, #{planDate,jdbcType=DATE}, #{actualDate,jdbcType=DATE}, #{status}, GETDATE(), #{createBy}, GETDATE(), #{updateBy})
|
|
</insert>
|
|
|
|
<update id="finishProofing">
|
|
UPDATE plm_proofing_information_tracking
|
|
SET proofing_status = N'打样完成',
|
|
actuality_delivery_date = ISNULL(#{actualityDeliveryDate,jdbcType=DATE}, GETDATE()),
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE id = #{trackingId}
|
|
</update>
|
|
|
|
<update id="updateTrackingProofingStatusAndActualityDate">
|
|
UPDATE plm_proofing_information_tracking
|
|
SET proofing_status = #{proofingStatus},
|
|
actuality_delivery_date = #{actualityDeliveryDate,jdbcType=DATE},
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE id = #{trackingId}
|
|
</update>
|
|
|
|
<delete id="deleteProofTrackingLogByTrackingId">
|
|
DELETE FROM plm_proofing_information_tracking_log
|
|
WHERE tracking_id = #{trackingId}
|
|
</delete>
|
|
|
|
<delete id="deleteProcessValuesByTrackingId">
|
|
DELETE FROM plm_proofing_process_value
|
|
WHERE tracking_id = #{trackingId}
|
|
</delete>
|
|
|
|
<delete id="deleteProofTrackingByTrackingId">
|
|
DELETE FROM plm_proofing_information_tracking
|
|
WHERE id = #{trackingId}
|
|
</delete>
|
|
|
|
<update id="updateTrackingProofingInfo">
|
|
UPDATE plm_proofing_information_tracking
|
|
SET proofing_id = #{proofingId},
|
|
proofing_no = #{proofingNo},
|
|
proofing_number = #{proofingNumber},
|
|
plan_start_date = #{planStartDate,jdbcType=DATE},
|
|
required_delivery_date = #{requiredDeliveryDate,jdbcType=DATE},
|
|
baseline = #{baseline,jdbcType=DATE},
|
|
pm_inquery_time = #{pmInqueryTime,jdbcType=DATE},
|
|
importance = #{importance},
|
|
project_phase = #{projectPhase},
|
|
proofing_status = #{proofingStatus},
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE id = #{trackingId}
|
|
</update>
|
|
|
|
<update id="updateTrackingBaseInfo">
|
|
UPDATE plm_proofing_information_tracking
|
|
SET project_phase = #{projectPhase},
|
|
project_category = #{projectCategory},
|
|
proofing_no = #{proofingNo},
|
|
proofing_status = #{proofingStatus},
|
|
proofing_number = #{proofingNumber},
|
|
plan_start_date = #{planStartDate,jdbcType=DATE},
|
|
required_delivery_date = #{requiredDeliveryDate,jdbcType=DATE},
|
|
baseline = #{baseline,jdbcType=DATE},
|
|
pm_inquery_time = #{pmInqueryTime,jdbcType=DATE},
|
|
importance = #{importance},
|
|
tracker = #{tracker},
|
|
engineer = #{engineer},
|
|
priority_level = #{priorityLevel},
|
|
remark = #{remark,jdbcType=NVARCHAR},
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE id = #{trackingId}
|
|
</update>
|
|
|
|
<update id="updateTrackingRequiredDeliveryDate">
|
|
UPDATE plm_proofing_information_tracking
|
|
SET required_delivery_date = #{requiredDeliveryDate,jdbcType=DATE},
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE id = #{trackingId}
|
|
</update>
|
|
|
|
<update id="updateTrackingBaselineWhenEmpty">
|
|
UPDATE plm_proofing_information_tracking
|
|
SET baseline = #{baseline,jdbcType=DATE},
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE id = #{trackingId}
|
|
AND baseline IS NULL
|
|
</update>
|
|
|
|
<update id="updateTrackingComments">
|
|
UPDATE plm_proofing_information_tracking
|
|
SET comments = #{comments,jdbcType=NVARCHAR},
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE id = #{trackingId}
|
|
</update>
|
|
|
|
<select id="selectTrackingForProofing" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingData">
|
|
SELECT
|
|
t.id as tracking_id,
|
|
t.site,
|
|
t.project_id,
|
|
t.project_part_id,
|
|
t.proofing_id,
|
|
t.proofing_no,
|
|
t.proofing_status,
|
|
t.project_phase,
|
|
COALESCE(NULLIF(LTRIM(RTRIM(t.project_category)), ''),
|
|
NULLIF(LTRIM(RTRIM(pp.project_category)), ''),
|
|
NULLIF(LTRIM(RTRIM(p.project_category)), '')) AS project_category,
|
|
t.tracker,
|
|
t.engineer,
|
|
t.priority_level,
|
|
t.proofing_number,
|
|
t.plan_start_date,
|
|
t.required_delivery_date,
|
|
t.baseline,
|
|
t.actuality_delivery_date,
|
|
t.pm_inquery_time,
|
|
t.importance,
|
|
t.comments,
|
|
t.remark,
|
|
t.create_date,
|
|
t.create_by,
|
|
t.update_date,
|
|
t.update_by,
|
|
p.project_no,
|
|
p.project_name,
|
|
p.project_desc,
|
|
pp.customer_no,
|
|
p.bu_no,
|
|
pp.test_part_no,
|
|
pp.part_desc,
|
|
pp.final_part_no,
|
|
pp.dry_wet_type AS dryWetType
|
|
FROM plm_proofing_information_tracking t
|
|
LEFT JOIN plm_project_info_tracking p ON t.project_id = p.id
|
|
LEFT JOIN plm_project_part_tracking pp ON t.project_part_id = pp.id
|
|
WHERE t.id = #{trackingId}
|
|
</select>
|
|
|
|
<insert id="insertTrackingFromPart">
|
|
<selectKey keyProperty="trackingId" resultType="int" order="BEFORE">
|
|
SELECT ISNULL(MAX(CASE WHEN id >= 100000 THEN id END), 100000) + 1
|
|
FROM plm_proofing_information_tracking WITH (TABLOCKX, HOLDLOCK)
|
|
</selectKey>
|
|
INSERT INTO plm_proofing_information_tracking
|
|
(id, site, project_id, project_part_id, proofing_id, proofing_no, proofing_status, project_phase, project_category,
|
|
tracker, engineer, priority_level, proofing_number, plan_start_date, required_delivery_date, actuality_delivery_date,
|
|
comments, remark, create_date, create_by, update_date, update_by)
|
|
SELECT
|
|
#{trackingId},
|
|
pp.site,
|
|
pp.project_id,
|
|
pp.id,
|
|
NULL,
|
|
NULL,
|
|
N'草稿',
|
|
'Sample',
|
|
ISNULL(pp.project_category, p.project_category),
|
|
ISNULL(pp.project_owner, ''),
|
|
ISNULL(pp.engineer, ''),
|
|
ISNULL(pp.priority, p.priority),
|
|
1,
|
|
GETDATE(),
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
GETDATE(), #{createBy}, GETDATE(), #{updateBy}
|
|
FROM plm_project_part_tracking pp
|
|
LEFT JOIN plm_project_info_tracking p ON pp.project_id = p.id
|
|
WHERE pp.site = #{site}
|
|
AND pp.project_id = #{projectId}
|
|
AND pp.id = #{projectPartId}
|
|
</insert>
|
|
|
|
<select id="getSampleDocumentTypeIds" resultType="string">
|
|
SELECT document_type_id
|
|
FROM bu_document_list_definition
|
|
WHERE site = #{site}
|
|
AND bu_no = #{buNo}
|
|
AND project_category = #{projectCategory}
|
|
AND project_phase = 'Sample'
|
|
</select>
|
|
|
|
<select id="countProofDocumentExists" resultType="java.lang.Integer">
|
|
SELECT COUNT(1)
|
|
FROM plm_document_list_definition
|
|
WHERE site = #{site}
|
|
AND proofing_id = #{proofingId}
|
|
AND project_id = #{projectId}
|
|
AND test_part_id = #{projectPartId}
|
|
AND document_type_id = #{documentTypeId}
|
|
</select>
|
|
|
|
<insert id="insertProofDocument">
|
|
INSERT INTO plm_document_list_definition
|
|
(site, proofing_id, test_part_id, project_id, created_by, manual_flag, uploaded_flag, create_date, document_type_id)
|
|
VALUES
|
|
(#{site}, #{proofingId}, #{projectPartId}, #{projectId}, #{createBy}, 'N', 'N', GETDATE(), #{documentTypeId})
|
|
</insert>
|
|
|
|
<select id="getProcessHistory" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessLogData">
|
|
SELECT
|
|
id,
|
|
tracking_id,
|
|
process_code,
|
|
process_name,
|
|
old_status,
|
|
new_status,
|
|
old_plan_date,
|
|
new_plan_date,
|
|
old_actual_date,
|
|
new_actual_date,
|
|
change_type,
|
|
remark,
|
|
changed_by,
|
|
changed_date
|
|
FROM plm_proofing_information_tracking_log
|
|
WHERE tracking_id = #{trackingId}
|
|
<if test="processCode != null and processCode != ''">
|
|
AND process_code = #{processCode}
|
|
</if>
|
|
ORDER BY changed_date DESC, id DESC
|
|
</select>
|
|
|
|
<insert id="saveProcessLog">
|
|
INSERT INTO plm_proofing_information_tracking_log
|
|
(tracking_id, process_code, process_name, old_status, new_status, old_plan_date, new_plan_date,
|
|
old_actual_date, new_actual_date, change_type, remark, changed_by, changed_date)
|
|
VALUES
|
|
(#{trackingId}, #{processCode}, #{processName}, #{oldStatus}, #{newStatus}, #{oldPlanDate,jdbcType=DATE},
|
|
#{newPlanDate,jdbcType=DATE}, #{oldActualDate,jdbcType=DATE}, #{newActualDate,jdbcType=DATE},
|
|
#{changeType}, #{remark}, #{changedBy}, GETDATE())
|
|
</insert>
|
|
|
|
<select id="selectProcessColumnsBySiteAndBu" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessColumnData">
|
|
SELECT
|
|
cfg.site,
|
|
cfg.bu_no AS buNo,
|
|
cfg.process_code AS code,
|
|
cfg.process_label AS label,
|
|
cfg.plan_field AS planField,
|
|
cfg.actual_field AS actualField,
|
|
cfg.status_field AS statusField,
|
|
cfg.process_category_code AS processCategoryCode,
|
|
category_ref.category_name AS processCategoryName,
|
|
cfg.sort_no AS sortNo,
|
|
cfg.active_flag AS activeFlag
|
|
FROM plm_proofing_process_column_config cfg
|
|
OUTER APPLY (
|
|
SELECT TOP 1 category_name
|
|
FROM plm_proofing_process_category
|
|
WHERE category_code = cfg.process_category_code
|
|
AND site = cfg.site
|
|
AND bu_no = cfg.bu_no
|
|
ORDER BY
|
|
sort_no,
|
|
category_code
|
|
) category_ref
|
|
WHERE cfg.site = #{site}
|
|
AND cfg.bu_no = #{buNo}
|
|
AND cfg.active_flag = 'Y'
|
|
ORDER BY cfg.sort_no, cfg.process_code
|
|
</select>
|
|
|
|
<select id="selectProcessColumnsBySiteAndBuAll" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessColumnData">
|
|
SELECT
|
|
cfg.site,
|
|
cfg.bu_no AS buNo,
|
|
cfg.process_code AS code,
|
|
cfg.process_label AS label,
|
|
cfg.plan_field AS planField,
|
|
cfg.actual_field AS actualField,
|
|
cfg.status_field AS statusField,
|
|
cfg.process_category_code AS processCategoryCode,
|
|
category_ref.category_name AS processCategoryName,
|
|
cfg.sort_no AS sortNo,
|
|
cfg.active_flag AS activeFlag
|
|
FROM plm_proofing_process_column_config cfg
|
|
OUTER APPLY (
|
|
SELECT TOP 1 category_name
|
|
FROM plm_proofing_process_category
|
|
WHERE category_code = cfg.process_category_code
|
|
AND site = cfg.site
|
|
AND bu_no = cfg.bu_no
|
|
ORDER BY
|
|
sort_no,
|
|
category_code
|
|
) category_ref
|
|
WHERE cfg.site = #{site}
|
|
AND cfg.bu_no = #{buNo}
|
|
ORDER BY cfg.sort_no, cfg.process_code
|
|
</select>
|
|
|
|
<select id="selectConfiguredBuNosForSite" resultType="string">
|
|
SELECT DISTINCT bu_no
|
|
FROM plm_proofing_process_column_config
|
|
WHERE bu_no != '*'
|
|
AND site = #{site}
|
|
ORDER BY bu_no
|
|
</select>
|
|
|
|
<update id="updateProcessColumnConfig">
|
|
UPDATE plm_proofing_process_column_config
|
|
SET sort_no = #{sortNo},
|
|
process_category_code = #{processCategoryCode},
|
|
active_flag = #{activeFlag},
|
|
update_date = GETDATE(),
|
|
update_by = #{updateBy}
|
|
WHERE site = #{site}
|
|
AND bu_no = #{buNo}
|
|
AND process_code = #{processCode}
|
|
</update>
|
|
|
|
<delete id="deleteProcessColumnConfigBySiteAndBu">
|
|
DELETE FROM plm_proofing_process_column_config
|
|
WHERE site = #{site}
|
|
AND bu_no = #{buNo}
|
|
</delete>
|
|
|
|
<delete id="deleteProcessColumnConfigBySiteBuAndCodes">
|
|
DELETE FROM plm_proofing_process_column_config
|
|
WHERE site = #{site}
|
|
AND bu_no = #{buNo}
|
|
AND process_code IN
|
|
<foreach collection="processCodes" item="code" open="(" separator="," close=")">
|
|
#{code}
|
|
</foreach>
|
|
</delete>
|
|
|
|
<insert id="insertProcessColumnConfig">
|
|
INSERT INTO plm_proofing_process_column_config
|
|
(site, bu_no, process_code, process_label, plan_field, actual_field, status_field, process_category_code, sort_no, active_flag,
|
|
create_date, create_by, update_date, update_by)
|
|
VALUES
|
|
(#{site}, #{buNo}, #{code}, #{label}, #{planField}, #{actualField}, #{statusField}, #{processCategoryCode}, #{sortNo}, #{activeFlag},
|
|
GETDATE(), #{createBy}, GETDATE(), #{updateBy})
|
|
</insert>
|
|
|
|
<select id="selectProcessCategoriesBySiteAndBu" resultType="com.xujie.sys.modules.sampletracking.data.ProofTrackingProcessCategoryData">
|
|
SELECT
|
|
site,
|
|
bu_no AS buNo,
|
|
category_code AS categoryCode,
|
|
category_name AS categoryName,
|
|
sort_no AS sortNo
|
|
FROM plm_proofing_process_category
|
|
WHERE site = #{site}
|
|
AND bu_no = #{buNo}
|
|
ORDER BY sort_no, category_code
|
|
</select>
|
|
|
|
<delete id="deleteProcessCategoryBySiteAndBu">
|
|
DELETE FROM plm_proofing_process_category
|
|
WHERE site = #{site}
|
|
AND bu_no = #{buNo}
|
|
</delete>
|
|
|
|
<select id="selectUsedProcessCategoryCodes" resultType="string">
|
|
SELECT DISTINCT process_category_code
|
|
FROM plm_proofing_process_column_config
|
|
WHERE site = #{site}
|
|
AND bu_no = #{buNo}
|
|
AND LTRIM(RTRIM(ISNULL(process_category_code, ''))) != ''
|
|
</select>
|
|
|
|
<insert id="insertProcessCategory">
|
|
INSERT INTO plm_proofing_process_category
|
|
(site, bu_no, category_code, category_name, sort_no, create_date, create_by, update_date, update_by)
|
|
VALUES
|
|
(#{site}, #{buNo}, #{categoryCode}, #{categoryName}, #{sortNo}, GETDATE(), #{createBy}, GETDATE(), #{updateBy})
|
|
</insert>
|
|
|
|
</mapper>
|
|
|