<?xml version="1.0" encoding="UTF-8"?>
|
|
<!--
|
~
|
~ Copyright (c) 2018-2025, ztt All rights reserved.
|
~
|
~ Redistribution and use in source and binary forms, with or without
|
~ modification, are permitted provided that the following conditions are met:
|
~
|
~ Redistributions of source code must retain the above copyright notice,
|
~ this list of conditions and the following disclaimer.
|
~ Redistributions in binary form must reproduce the above copyright
|
~ notice, this list of conditions and the following disclaimer in the
|
~ documentation and/or other materials provided with the distribution.
|
~ Neither the name of the pig4cloud.com developer nor the names of its
|
~ contributors may be used to endorse or promote products derived from
|
~ this software without specific prior written permission.
|
~ Author: ztt
|
~
|
-->
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="com.chinaztt.mes.aps.mapper.ApsCoreMapper">
|
|
|
<resultMap id="operationBoMap" type="com.chinaztt.mes.aps.core.domain.OperationBo">
|
<result property="id" column="id"/>
|
<result property="no" column="no"/>
|
<collection property="capabilityIds" ofType="long">
|
<id column="capability_id"/>
|
</collection>
|
</resultMap>
|
|
<resultMap id="ganttTaskVo" type="com.chinaztt.mes.aps.vo.GanttTaskVo">
|
<result property="id" column="id"/>
|
<result property="text" column="text"/>
|
<result property="startDate" column="start_time"/>
|
<result property="endDate" column="end_time"/>
|
<result property="parent" column="resource_id"/>
|
<result property="state" column="state"/>
|
<result property="optaskNo" column="optask_no"/>
|
<result property="partName" column="part_name"/>
|
<result property="quantity" column="quantity"/>
|
<result property="partNo" column="part_no"/>
|
<result property="workCenter" column="work_center"/>
|
<result property="customerOrderNo" column="customer_order_no"/>
|
<result property="otcLineNo" column="otc_line_no"/>
|
<result property="mpsNo" column="mps_no"/>
|
</resultMap>
|
|
<resultMap id="resourceVo" type="com.chinaztt.mes.aps.vo.ResourceVo">
|
<result property="id" column="id"/>
|
<result property="resName" column="resName"/>
|
<result property="machineLoad" column="machine_load"/>
|
<result property="workCenter" column="work_center"/>
|
</resultMap>
|
|
<select id="queryOperation" resultMap="operationBoMap">
|
SELECT
|
o.ID,
|
o.operation_no "no",
|
j.capability_id
|
FROM
|
technology_operation o
|
LEFT JOIN aps_join_operation_capability j ON j.operation_id = o.ID
|
WHERE
|
o.id = #{operationId}
|
and o.active = TRUE
|
</select>
|
|
|
<select id="queryOperationTaskByTimeRange" resultMap="ganttTaskVo">
|
SELECT
|
T.id,
|
T.planned_start_date "start_time",
|
t.planned_finish_date "end_time",
|
T.resource_id,
|
o."name" "text",
|
t.state
|
FROM
|
production_operation_task T
|
LEFT JOIN technology_routing_operation ro ON ro.ID = T.routing_operation_id
|
LEFT JOIN technology_operation o ON o.ID = ro.operation_id
|
where
|
t.planned_start_date < #{end}
|
and t.planned_finish_date > #{start}
|
<if test="resourceIds!=null and resourceIds.size>0">
|
and t.resource_id in
|
<foreach collection="resourceIds" item="id" index="index" open="(" close=")" separator=",">
|
#{id}
|
</foreach>
|
</if>
|
</select>
|
|
<select id="querySceneTaskByTimeRange" resultMap="ganttTaskVo">
|
SELECT
|
t.id,
|
t.start_time,
|
t.end_time,
|
t.resource_id,
|
m.mo_no || ' ' || o."name" "text",
|
'scene' state
|
FROM aps_scene_task t
|
LEFT JOIN technology_routing_operation ro ON ro.ID = T.routing_operation_id
|
LEFT JOIN technology_operation o ON o.ID = ro.operation_id
|
LEFT JOIN plan_manufacturing_order m on m.id = t.order_id
|
WHERE t.scene_id = #{sceneId}
|
AND t.start_time < #{end}
|
AND t.end_time > #{start}
|
<if test="resourceIds!=null and resourceIds.size>0">
|
AND t.resource_id IN
|
<foreach collection="resourceIds" item="id" index="index" open="(" close=")" separator=",">
|
#{id}
|
</foreach>
|
</if>
|
</select>
|
|
<select id="queryResourceByGroupId" resultMap="resourceVo">
|
WITH RECURSIVE T ( ID, rsc_group_name, parent_id ) AS (
|
SELECT
|
ID,
|
rsc_group_name,
|
parent_id
|
FROM aps_resource_group WHERE ID = #{ groupId }
|
UNION ALL
|
SELECT
|
t2.ID,
|
t2.rsc_group_name,
|
t2.parent_id
|
FROM
|
aps_resource_group t2
|
JOIN T ON t2.parent_id = T.ID)
|
SELECT DISTINCT
|
r.ID,
|
r.resource_name "resName"
|
FROM
|
T,
|
aps_join_res_group j,
|
aps_resource r
|
WHERE
|
T.ID = j.rsc_group_id
|
AND j.resource_id = r.ID
|
AND r.active = TRUE
|
ORDER BY ID
|
</select>
|
|
<select id="getAllResourceVo" resultMap="resourceVo">
|
SELECT DISTINCT
|
r.ID,
|
r.resource_name "resName"
|
FROM
|
aps_resource r
|
WHERE r.active = TRUE
|
ORDER BY ID
|
</select>
|
|
<select id="queryOperationTaskByTimeRangeGantt" resultMap="ganttTaskVo">
|
SELECT
|
opt.id,
|
opt.planned_start_date "start_time",
|
opt.planned_finish_date "end_time",
|
opt.workstation_id resource_id,
|
opt.optask_no,
|
opt.planned_quantity quantity,
|
opt.work_center,
|
bp.part_name,
|
bp.part_no,
|
too."name" "text",
|
pmps.mps_no,
|
pco.customer_order_no,
|
pco.otc_line_no,
|
opt.state
|
FROM
|
production_operation_task opt
|
LEFT JOIN technology_routing_operation ro ON ro.ID = opt.routing_operation_id
|
LEFT JOIN production_operation_task_supply pots ON opt."id" = pots.operation_task_id
|
LEFT JOIN plan_manufacturing_order pmo ON pots.mo_id = pmo."id"
|
LEFT JOIN plan_master_production_schedule pmps ON pmps."id" = pmo.mps_id
|
LEFT JOIN plan_join_model_customer pjmc
|
ON pjmc.model_id = pmps."id" AND pjmc.model = 'plan_master_production_schedule'
|
LEFT JOIN plan_customer_order pco ON pco."id" = pjmc.customer_order_id
|
LEFT JOIN technology_operation too ON too.ID = ro.operation_id
|
LEFT JOIN basic_part bp on bp.id = opt.part_id
|
WHERE
|
opt.planned_start_date < #{end}
|
AND opt.planned_finish_date > #{start}
|
<if test="workstationIds!=null and workstationIds.size>0">
|
AND opt.workstation_id IN
|
<foreach collection="workstationIds" item="id" index="index" open="(" close=")" separator=",">
|
#{id}
|
</foreach>
|
</if>
|
<if test="stateList!=null and stateList.size>0">
|
AND opt.state IN
|
<foreach collection="stateList" item="id" index="index" open="(" close=")" separator=",">
|
#{id}
|
</foreach>
|
</if>
|
ORDER BY opt.planned_finish_date:: DATE,opt.priority
|
</select>
|
|
<select id="queryResourceByGroupIdGantt" resultMap="resourceVo">
|
SELECT DISTINCT
|
bw.id,
|
bw.name AS "resName",
|
bw.work_center,
|
CASE
|
WHEN EXTRACT(epoch FROM smax.planned_finish_date) -
|
EXTRACT(epoch FROM smin.planned_start_date) IS NULL OR
|
EXTRACT(epoch FROM smax.planned_finish_date) -
|
EXTRACT(epoch FROM smin.planned_start_date) = 0
|
THEN 0.00
|
ELSE ROUND(CAST(ssum.work_hours * 100 / (EXTRACT(epoch FROM smax.planned_finish_date)
|
- EXTRACT(epoch FROM smin.planned_start_date)) AS NUMERIC), 2) END AS machine_load
|
FROM
|
basic_workstation bw
|
LEFT JOIN (SELECT
|
MAX(planned_finish_date) planned_finish_date,
|
workstation_id
|
FROM production_operation_task
|
WHERE "state" IN ('07unsubmit', '01pending', '02inProgress', '03interrupted')
|
GROUP BY workstation_id) smax ON smax.workstation_id = bw.ID
|
LEFT JOIN (SELECT
|
MIN(planned_start_date) planned_start_date,
|
workstation_id
|
FROM production_operation_task
|
WHERE "state" IN ('07unsubmit', '01pending', '02inProgress', '03interrupted')
|
GROUP BY workstation_id) smin ON smin.workstation_id = bw.ID
|
LEFT JOIN (SELECT
|
SUM(EXTRACT(epoch FROM planned_finish_date) -
|
EXTRACT(epoch FROM planned_start_date)) work_hours,
|
workstation_id
|
FROM
|
production_operation_task
|
WHERE
|
"state" IN ('07unsubmit', '01pending', '02inProgress', '03interrupted')
|
GROUP BY
|
workstation_id) ssum ON ssum.workstation_id = bw.ID
|
WHERE bw.active = TRUE
|
<if test="workStationList!=null and workStationList.size>0">
|
AND bw."id" IN
|
<foreach collection="workStationList" item="id" index="index" open="(" close=")" separator=",">
|
#{id}
|
</foreach>
|
</if>
|
<if test="workcenter!=null ">
|
AND bw.work_center = #{workcenter}
|
</if>
|
ORDER BY work_center
|
</select>
|
|
<select id="getAllResourceVoGantt" resultMap="resourceVo">
|
SELECT DISTINCT
|
r."id",
|
r.name "resName"
|
FROM
|
basic_workstation r
|
WHERE r.active = TRUE
|
ORDER BY ID
|
</select>
|
|
<select id="getOperatioTaskMaxPlanEndTime" resultType="java.time.LocalDateTime">
|
SELECT
|
MAX(planned_finish_date)
|
FROM production_operation_task
|
WHERE "state" IN ('07unsubmit', '01pending', '02inProgress', '03interrupted')
|
AND workstation_id = #{workstationId}
|
</select>
|
|
<select id="getWorkstationIdByWorkcenter" resultType="java.lang.Long">
|
SELECT
|
ar.workstation_id
|
FROM aps_resource_duration ard
|
LEFT JOIN aps_resource ar ON ar."id" = ard.resource_id
|
WHERE workstation_id IN (SELECT "id" FROM basic_workstation WHERE work_center = #{workCenter})
|
AND ard.part_id = #{partId}
|
</select>
|
</mapper>
|