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
456 lines
19 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.erf.mapper.ErfExpApplyMapper">
|
|
|
|
<!-- 结果映射 -->
|
|
<resultMap id="ExpApplyResultMap" type="com.xujie.sys.modules.erf.data.ErfExpApplyData">
|
|
<result column="apply_no" property="applyNo"/>
|
|
<result column="bu_no" property="buNo"/>
|
|
<result column="buDesc" property="buDesc"/>
|
|
<result column="experiment_type" property="experimentType"/>
|
|
<result column="project_no" property="projectNo"/>
|
|
<result column="title" property="title"/>
|
|
<result column="purpose" property="purpose"/>
|
|
<result column="justification" property="justification"/>
|
|
<result column="product_type" property="productType"/>
|
|
<result column="quantity_req" property="quantityReq"/>
|
|
<result column="expected_finish_date" property="expectedFinishDate"/>
|
|
<result column="project_leader" property="projectLeader"/>
|
|
<result column="contact_method" property="contactMethod"/>
|
|
<result column="process_requirement" property="processRequirement"/>
|
|
<result column="actual_finish_date" property="actualFinishDate"/>
|
|
<result column="final_status" property="finalStatus"/>
|
|
<result column="final_quantity" property="finalQuantity"/>
|
|
<result column="planner_user_id" property="plannerUserId"/>
|
|
<result column="planner_name" property="plannerName"/>
|
|
<result column="work_order_no" property="workOrderNo"/>
|
|
<result column="scheduled_date" property="scheduledDate"/>
|
|
<result column="status" property="status"/>
|
|
<result column="current_step" property="currentStep"/>
|
|
<result column="creator_user_id" property="creatorUserId"/>
|
|
<result column="creator_name" property="creatorName"/>
|
|
<result column="create_time" property="createTime"/>
|
|
<result column="update_time" property="updateTime"/>
|
|
<result column="submit_time" property="submitTime"/>
|
|
</resultMap>
|
|
|
|
<!-- 查询申请单列表 -->
|
|
<select id="searchExpApplyList" resultMap="ExpApplyResultMap">
|
|
SELECT
|
|
site,
|
|
apply_no,
|
|
bu_no,
|
|
dbo.get_bu_desc(site,bu_no) as buDesc,
|
|
experiment_type,
|
|
project_no,
|
|
title,
|
|
purpose,
|
|
justification,
|
|
product_type,
|
|
quantity_req,
|
|
expected_finish_date,
|
|
project_leader,
|
|
contact_method,
|
|
process_requirement,
|
|
actual_finish_date,
|
|
final_status,
|
|
final_quantity,
|
|
planner_user_id,
|
|
planner_name,
|
|
work_order_no,
|
|
scheduled_date,
|
|
status,
|
|
current_step,
|
|
creator_user_id,
|
|
creator_name,
|
|
create_time,
|
|
update_time,
|
|
submit_time
|
|
FROM erf_exp_apply
|
|
<where>
|
|
<if test="data.applyNo != null and data.applyNo != ''">
|
|
AND apply_no LIKE '%' + #{data.applyNo} + '%'
|
|
</if>
|
|
<if test="data.buNo != null and data.buNo != ''">
|
|
AND bu_no = #{data.buNo}
|
|
</if>
|
|
<if test="data.experimentType != null and data.experimentType != ''">
|
|
AND experiment_type = #{data.experimentType}
|
|
</if>
|
|
<if test="data.status != null and data.status != ''">
|
|
AND status = #{data.status}
|
|
</if>
|
|
<if test="data.creatorUserId != null">
|
|
AND creator_user_id = #{data.creatorUserId}
|
|
</if>
|
|
<if test="data.createStartDate != null">
|
|
AND CAST(create_time AS DATE) >= #{data.createStartDate}
|
|
</if>
|
|
<if test="data.createEndDate != null">
|
|
AND CAST(create_time AS DATE) <= #{data.createEndDate}
|
|
</if>
|
|
<if test="data.title != null and data.title != ''">
|
|
AND title LIKE '%' + #{data.title} + '%'
|
|
</if>
|
|
<if test="data.projectNo != null and data.projectNo != ''">
|
|
AND project_no LIKE '%' + #{data.projectNo} + '%'
|
|
</if>
|
|
<if test="data.productType != null and data.productType != ''">
|
|
AND product_type LIKE '%' + #{data.productType} + '%'
|
|
</if>
|
|
<if test="data.creatorName != null and data.creatorName != ''">
|
|
AND creator_name LIKE '%' + #{data.creatorName} + '%'
|
|
</if>
|
|
<if test="data.expectedFinishStartDate != null">
|
|
AND CAST(expected_finish_date AS DATE) >= #{data.expectedFinishStartDate}
|
|
</if>
|
|
<if test="data.expectedFinishEndDate != null">
|
|
AND CAST(expected_finish_date AS DATE) <= #{data.expectedFinishEndDate}
|
|
</if>
|
|
<if test="data.actualFinishStartDate != null">
|
|
AND CAST(actual_finish_date AS DATE) >= #{data.actualFinishStartDate}
|
|
</if>
|
|
<if test="data.actualFinishEndDate != null">
|
|
AND CAST(actual_finish_date AS DATE) <= #{data.actualFinishEndDate}
|
|
</if>
|
|
</where>
|
|
ORDER BY create_time DESC
|
|
</select>
|
|
|
|
<!-- 根据申请单号查询详情 -->
|
|
<select id="getExpApplyDetail" resultMap="ExpApplyResultMap">
|
|
SELECT
|
|
apply_no,
|
|
bu_no,
|
|
dbo.get_bu_desc(site,bu_no) as buDesc,
|
|
experiment_type,
|
|
project_no,
|
|
title,
|
|
purpose,
|
|
justification,
|
|
product_type,
|
|
quantity_req,
|
|
expected_finish_date,
|
|
project_leader,
|
|
contact_method,
|
|
process_requirement,
|
|
actual_finish_date,
|
|
final_status,
|
|
final_quantity,
|
|
planner_user_id,
|
|
planner_name,
|
|
work_order_no,
|
|
scheduled_date,
|
|
status,
|
|
current_step,
|
|
creator_user_id,
|
|
creator_name,
|
|
create_time,
|
|
update_time,
|
|
submit_time
|
|
FROM erf_exp_apply
|
|
WHERE apply_no = #{applyNo}
|
|
</select>
|
|
|
|
<!-- 查询用户的待办申请单 -->
|
|
<select id="getPendingApplyList" resultMap="ExpApplyResultMap">
|
|
SELECT DISTINCT
|
|
a.apply_no,
|
|
a.bu_no,
|
|
dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
|
|
a.experiment_type,
|
|
a.project_no,
|
|
a.title,
|
|
a.purpose,
|
|
a.justification,
|
|
a.product_type,
|
|
a.quantity_req,
|
|
a.expected_finish_date,
|
|
a.project_leader,
|
|
a.contact_method,
|
|
a.process_requirement,
|
|
a.actual_finish_date,
|
|
a.final_status,
|
|
a.final_quantity,
|
|
a.planner_user_id,
|
|
a.planner_name,
|
|
a.work_order_no,
|
|
a.scheduled_date,
|
|
a.status,
|
|
a.current_step,
|
|
a.creator_user_id,
|
|
a.creator_name,
|
|
a.create_time,
|
|
a.update_time,
|
|
a.submit_time
|
|
FROM erf_exp_apply a
|
|
INNER JOIN erf_flow_node_instance n ON a.apply_no = n.apply_no
|
|
<where>
|
|
n.assignee_user_id = #{data.currentUserId}
|
|
AND n.status = '待审核'
|
|
<!-- 根据不同页面类型,过滤不同的节点类型 -->
|
|
<if test="data.pageType != null and data.pageType == 'MANAGER'">
|
|
AND n.node_code IN ('技术经理审批', '生产经理审批', '质量经理审批')
|
|
</if>
|
|
<if test="data.pageType != null and data.pageType == 'PLANNER'">
|
|
AND n.node_code = '计划员排产'
|
|
</if>
|
|
<if test="data.pageType != null and data.pageType == 'TRI_CONFIRM'">
|
|
AND n.node_code = '三方确认'
|
|
</if>
|
|
<if test="data.pendingStatus != null and data.pendingStatus != ''">
|
|
AND a.status = #{data.pendingStatus}
|
|
</if>
|
|
<if test="data.pendingStatus == null or data.pendingStatus == ''">
|
|
AND a.status IN ('已下达','已批准', '生产中')
|
|
</if>
|
|
<if test="data.applyNo != null and data.applyNo != ''">
|
|
AND a.apply_no LIKE '%' + #{data.applyNo} + '%'
|
|
</if>
|
|
<if test="data.buNo != null and data.buNo != ''">
|
|
AND a.bu_no = #{data.buNo}
|
|
</if>
|
|
<if test="data.experimentType != null and data.experimentType != ''">
|
|
AND a.experiment_type = #{data.experimentType}
|
|
</if>
|
|
<if test="data.title != null and data.title != ''">
|
|
AND a.title LIKE '%' + #{data.title} + '%'
|
|
</if>
|
|
<if test="data.projectNo != null and data.projectNo != ''">
|
|
AND a.project_no LIKE '%' + #{data.projectNo} + '%'
|
|
</if>
|
|
<if test="data.productType != null and data.productType != ''">
|
|
AND a.product_type LIKE '%' + #{data.productType} + '%'
|
|
</if>
|
|
<if test="data.creatorName != null and data.creatorName != ''">
|
|
AND a.creator_name LIKE '%' + #{data.creatorName} + '%'
|
|
</if>
|
|
<if test="data.createStartDate != null">
|
|
AND CAST(a.create_time AS DATE) >= #{data.createStartDate}
|
|
</if>
|
|
<if test="data.createEndDate != null">
|
|
AND CAST(a.create_time AS DATE) <= #{data.createEndDate}
|
|
</if>
|
|
<if test="data.expectedFinishStartDate != null">
|
|
AND CAST(a.expected_finish_date AS DATE) >= #{data.expectedFinishStartDate}
|
|
</if>
|
|
<if test="data.expectedFinishEndDate != null">
|
|
AND CAST(a.expected_finish_date AS DATE) <= #{data.expectedFinishEndDate}
|
|
</if>
|
|
</where>
|
|
ORDER BY a.create_time DESC
|
|
</select>
|
|
|
|
<select id="getSiteByBu" resultType="String">
|
|
select top 1 site from BU where bu_no=#{buNo}
|
|
</select>
|
|
|
|
<!-- 删除三方确认明细 -->
|
|
<delete id="deleteTriConfirmDetail">
|
|
DELETE FROM erf_exp_tri_confirm_detail
|
|
WHERE apply_no = #{applyNo}
|
|
</delete>
|
|
|
|
<!-- 删除三方确认主表 -->
|
|
<delete id="deleteTriConfirm">
|
|
DELETE FROM erf_exp_tri_confirm
|
|
WHERE apply_no = #{applyNo}
|
|
</delete>
|
|
|
|
<!-- 删除申请单附件 -->
|
|
<delete id="deleteAttachments">
|
|
DELETE FROM sys_oss
|
|
WHERE order_ref1 = #{orderRef1}
|
|
AND order_ref2 = #{orderRef2}
|
|
AND order_ref6 = #{orderRef6}
|
|
</delete>
|
|
|
|
<!-- 删除流程节点实例 -->
|
|
<delete id="deleteFlowNodeInstances">
|
|
DELETE FROM erf_flow_node_instance
|
|
WHERE apply_no = #{applyNo}
|
|
</delete>
|
|
|
|
<!-- 查询附件列表 -->
|
|
<select id="getAttachmentList" resultType="map">
|
|
SELECT url, new_file_name, file_name, created_by, file_type,
|
|
order_ref3, order_ref4, order_ref5, file_suffix, file_type_code,
|
|
order_reftype, conclusion, c_additional_info, project_ispush
|
|
FROM sys_oss
|
|
WHERE order_ref1 = #{orderRef1}
|
|
AND order_ref2 = #{orderRef2}
|
|
AND order_ref6 = #{orderRef6}
|
|
</select>
|
|
|
|
<!-- 审批周期报表结果映射 -->
|
|
<resultMap id="ApprovalCycleResultMap" type="com.xujie.sys.modules.erf.dto.ErfApprovalCycleReportDto">
|
|
<result column="apply_no" property="applyNo"/>
|
|
<result column="bu_no" property="buNo"/>
|
|
<result column="buDesc" property="buName"/>
|
|
<result column="experiment_type" property="experimentType"/>
|
|
<result column="title" property="title"/>
|
|
<result column="creator_name" property="creatorName"/>
|
|
<result column="status" property="status"/>
|
|
<result column="create_time" property="createTime"/>
|
|
<result column="submit_time" property="submitTime"/>
|
|
<result column="tech_manager_name" property="techManagerName"/>
|
|
<result column="tech_approve_time" property="techApproveTime"/>
|
|
<result column="prod_manager_name" property="prodManagerName"/>
|
|
<result column="prod_approve_time" property="prodApproveTime"/>
|
|
<result column="qual_manager_name" property="qualManagerName"/>
|
|
<result column="qual_approve_time" property="qualApproveTime"/>
|
|
</resultMap>
|
|
|
|
<!-- 查询审批周期报表列表 -->
|
|
<!-- 统计从申请单发起日(submit_time)到技术/生产/质量三类经理全部审批完成的周期 -->
|
|
<select id="getApprovalCycleReportList" resultMap="ApprovalCycleResultMap">
|
|
SELECT
|
|
a.apply_no,
|
|
a.bu_no,
|
|
dbo.get_bu_desc(a.site, a.bu_no) AS buDesc,
|
|
a.experiment_type,
|
|
a.title,
|
|
a.creator_name,
|
|
a.status,
|
|
a.create_time,
|
|
a.submit_time,
|
|
-- 技术经理审批(单人,取已批准记录的最晚完成时间)
|
|
tech.assignee_name AS tech_manager_name,
|
|
tech.complete_time AS tech_approve_time,
|
|
-- 生产经理审批(可能多人,合并姓名,取最晚完成时间)
|
|
prod.assignee_names AS prod_manager_name,
|
|
prod.max_complete_time AS prod_approve_time,
|
|
-- 质量经理审批(可能多人,合并姓名,取最晚完成时间)
|
|
qual.assignee_names AS qual_manager_name,
|
|
qual.max_complete_time AS qual_approve_time
|
|
FROM erf_exp_apply a
|
|
-- 技术经理审批:取该申请单最新一次审批通过的记录
|
|
LEFT JOIN (
|
|
SELECT
|
|
n1.apply_no,
|
|
n1.assignee_name,
|
|
n1.complete_time
|
|
FROM erf_flow_node_instance n1
|
|
INNER JOIN (
|
|
SELECT apply_no, MAX(attempt_no) AS max_attempt
|
|
FROM erf_flow_node_instance
|
|
WHERE node_code = '技术经理审批'
|
|
GROUP BY apply_no
|
|
) n1a ON n1.apply_no = n1a.apply_no AND n1.attempt_no = n1a.max_attempt
|
|
WHERE n1.node_code = '技术经理审批'
|
|
) tech ON a.apply_no = tech.apply_no
|
|
-- 生产经理审批:取最新一次attempt中所有已批准的记录,合并姓名,取最晚完成时间
|
|
-- 使用 STUFF+FOR XML PATH 兼容 SQL Server 2017 以下版本
|
|
LEFT JOIN (
|
|
SELECT
|
|
p.apply_no,
|
|
STUFF((
|
|
SELECT '、' + p2.assignee_name
|
|
FROM erf_flow_node_instance p2
|
|
WHERE p2.node_code = '生产经理审批'
|
|
AND p2.apply_no = p.apply_no
|
|
AND p2.attempt_no = (
|
|
SELECT MAX(p3.attempt_no)
|
|
FROM erf_flow_node_instance p3
|
|
WHERE p3.apply_no = p.apply_no
|
|
AND p3.node_code = '生产经理审批'
|
|
)
|
|
FOR XML PATH('')
|
|
), 1, 1, '') AS assignee_names,
|
|
MAX(p.complete_time) AS max_complete_time
|
|
FROM erf_flow_node_instance p
|
|
INNER JOIN (
|
|
SELECT apply_no, MAX(attempt_no) AS max_attempt
|
|
FROM erf_flow_node_instance
|
|
WHERE node_code = '生产经理审批'
|
|
GROUP BY apply_no
|
|
) pa ON p.apply_no = pa.apply_no AND p.attempt_no = pa.max_attempt
|
|
WHERE p.node_code = '生产经理审批'
|
|
GROUP BY p.apply_no
|
|
) prod ON a.apply_no = prod.apply_no
|
|
-- 质量经理审批:取最新一次attempt中所有已批准的记录,合并姓名,取最晚完成时间
|
|
LEFT JOIN (
|
|
SELECT
|
|
q.apply_no,
|
|
STUFF((
|
|
SELECT '、' + q2.assignee_name
|
|
FROM erf_flow_node_instance q2
|
|
WHERE q2.node_code = '质量经理审批'
|
|
AND q2.apply_no = q.apply_no
|
|
AND q2.attempt_no = (
|
|
SELECT MAX(q3.attempt_no)
|
|
FROM erf_flow_node_instance q3
|
|
WHERE q3.apply_no = q.apply_no
|
|
AND q3.node_code = '质量经理审批'
|
|
)
|
|
FOR XML PATH('')
|
|
), 1, 1, '') AS assignee_names,
|
|
MAX(q.complete_time) AS max_complete_time
|
|
FROM erf_flow_node_instance q
|
|
INNER JOIN (
|
|
SELECT apply_no, MAX(attempt_no) AS max_attempt
|
|
FROM erf_flow_node_instance
|
|
WHERE node_code = '质量经理审批'
|
|
GROUP BY apply_no
|
|
) qa ON q.apply_no = qa.apply_no AND q.attempt_no = qa.max_attempt
|
|
WHERE q.node_code = '质量经理审批'
|
|
GROUP BY q.apply_no
|
|
) qual ON a.apply_no = qual.apply_no
|
|
<where>
|
|
-- 只查询已下达(有发起日)的申请单
|
|
a.submit_time IS NOT NULL
|
|
<if test="data.applyNo != null and data.applyNo != ''">
|
|
AND a.apply_no LIKE '%' + #{data.applyNo} + '%'
|
|
</if>
|
|
<if test="data.buNo != null and data.buNo != ''">
|
|
AND a.bu_no = #{data.buNo}
|
|
</if>
|
|
<if test="data.experimentType != null and data.experimentType != ''">
|
|
AND a.experiment_type = #{data.experimentType}
|
|
</if>
|
|
<if test="data.creatorName != null and data.creatorName != ''">
|
|
AND a.creator_name LIKE '%' + #{data.creatorName} + '%'
|
|
</if>
|
|
<if test="data.submitStartDate != null">
|
|
AND CAST(a.submit_time AS DATE) >= #{data.submitStartDate}
|
|
</if>
|
|
<if test="data.submitEndDate != null">
|
|
AND CAST(a.submit_time AS DATE) <= #{data.submitEndDate}
|
|
</if>
|
|
<if test="data.status != null and data.status != ''">
|
|
AND a.status = #{data.status}
|
|
</if>
|
|
</where>
|
|
ORDER BY a.submit_time DESC
|
|
</select>
|
|
|
|
<!-- 复制附件 -->
|
|
<insert id="copyAttachment">
|
|
INSERT INTO sys_oss
|
|
(url, create_date, new_file_name, file_name, created_by, file_type,
|
|
order_ref1, order_ref2, order_ref3, order_ref4, order_ref5, order_ref6,
|
|
file_suffix, file_type_code, order_reftype, conclusion, c_additional_info, project_ispush)
|
|
VALUES (
|
|
#{attachment.url},
|
|
GETDATE(),
|
|
#{attachment.new_file_name},
|
|
#{attachment.file_name},
|
|
#{attachment.created_by},
|
|
#{attachment.file_type},
|
|
'ERF',
|
|
#{targetApplyNo},
|
|
#{attachment.order_ref3},
|
|
#{attachment.order_ref4},
|
|
#{attachment.order_ref5},
|
|
'EXP_APPLY',
|
|
#{attachment.file_suffix},
|
|
#{attachment.file_type_code},
|
|
#{attachment.order_reftype},
|
|
#{attachment.conclusion},
|
|
#{attachment.c_additional_info},
|
|
#{attachment.project_ispush}
|
|
)
|
|
</insert>
|
|
|
|
</mapper>
|