yangys
2025-11-18 8e944cfabb253fc2556588e308e282586043f7b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?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.qianwen.smartman.modules.smis.mapper.CalendarMapper">
    <!-- 与mysql mapper相同,改动需同步 -->
    <resultMap id="calendarMapCopy" type="com.qianwen.smartman.modules.smis.vo.CalendarVO">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="name" property="name"/>
        <result column="year" property="year"/>
        <result column="status" property="status"/>
        <collection property="calendarDayVOList" ofType="com.qianwen.smartman.modules.smis.vo.CalendarDayVO">
            <id column="calendarDayId" property="id"/>
            <result column="calendar_date" property="calendarDate"/>
            <result column="model_id" property="modelId"/>
            <result column="is_high_priority" property="isHighPriority"/>
            <result column="isOffDay" property="isOffDay"/>
            <result column="modelName" property="modelName"/>
            <result column="offDayRemark" property="offDayRemark"/>
        </collection>
    </resultMap>
 
    <!--查询班次模型详情-->
    <select id="getCalendarDetail" resultMap="calendarMapCopy">
        select
        t1.id,
        t1.code,
        t1.name,
        t1.year,
        t1.status,
        t2.id as calendarDayId,
        t2.calendar_date,
        t2.model_id,
        t2.is_high_priority,
        t3.name as modelName,
        nvl(t2.is_off_day, 0) isOffDay,
        t4.remark offDayRemark
        from blade_production_calendar t1
        left join blade_production_calendar_day t2 on t1.id = t2.calendar_id
        left join blade_shift_model t3 on t2.model_id = t3.id
        left join blade_shift_off_day t4 on t2.is_off_day = 1 and t2.off_id = t4.id
        <where>
            t1.id = #{calendarId}
        </where>
        order by t2.calendar_date
    </select>
 
    <select id="getShiftIndexNameByCodeAndYear" resultType="java.lang.String">
        SELECT distinct sd.index_name
        FROM blade_production_calendar pc
                 LEFT JOIN blade_production_calendar_day pdc ON pc.id = pdc.calendar_id AND pdc.is_deleted = 0
                 LEFT JOIN blade_shift_detail sd on pdc.model_id = sd.model_id
        WHERE pc.code = #{calendarCode}
          AND pc.year = #{year}
          AND pdc.calendar_date = TO_DATE(#{factoryDate}, 'yyyy-mm-dd')
          AND pc.tenant_id = #{tenantId}
          AND sd.shift_index = #{shiftIndex}
          AND pc.is_deleted = 0
    </select>
 
 
    <select id="queryShiftIndexName" resultType="com.qianwen.smartman.modules.mdc.dto.ShiftIndexNameDTO">
        SELECT sd.shift_index as shiftIndex,
               sd.index_name as shiftIndexName,
               NVL(sd.index_name,'班次' || sd.shift_index) as indexName
        FROM blade_production_calendar pc
                 INNER JOIN blade_production_calendar_day pdc
                            ON pc.id = pdc.calendar_id AND pdc.is_deleted = 0 AND
                               pdc.calendar_date = TO_DATE(#{day}, 'yyyy-mm-dd')
                 LEFT JOIN blade_shift_detail sd on pdc.model_id = sd.model_id
        WHERE pc.code = #{calendarCode}
          AND pc.year = #{year}
          AND pc.is_deleted = 0
    </select>
 
    <select id="listShiftInfo" resultType="com.qianwen.smartman.modules.smis.dto.ShiftInfoDTO">
        SELECT
        to_char(b.calendar_date,'yyyy-mm-dd') calendarDate,
        c.shift_index shiftIndex,
        c.index_name indexName,
        c.shift_start_time startTime,
        c.shift_end_time endTime,
        d.id workstationId,
        b.model_id modelId
        FROM
        blade_production_calendar a
        LEFT JOIN blade_production_calendar_day b ON a.id = b.calendar_id
        LEFT JOIN blade_shift_detail c on b.model_id = c.model_id
        LEFT JOIN blade_workstation d ON d.calendar_code = a.code
        WHERE b.calendar_date BETWEEN #{startDay} AND #{endDay}
        and a.is_deleted = 0
        and b.is_deleted = 0
        and a.code IN (
        SELECT DISTINCT( d.calendar_code )
        FROM blade_workstation d
        WHERE d.id IN
        <foreach collection="workstationIdList" item="workstationId" index="index" open="(" close=")" separator=",">
            #{workstationId}
        </foreach>
        )
        AND d.id IN
        <foreach collection="workstationIdList" item="workstationId" index="index" open="(" close=")" separator=",">
            #{workstationId}
        </foreach>
    </select>
 
    <select id="getShiftDetailDates" resultType="com.qianwen.smartman.modules.smis.vo.ShiftTimeDetailVO">
        select bpcd.calendar_date as calendarDate,
        bsd.id as id,
        bsd.model_id as modelId,
        shift_index as shiftIndex,
        shift_start_time as shiftStartTime,
        shift_end_time as shiftEndTime,
        rest_number as restNumber,
        index_name as indexName,
        bsm.colour as colour
        from blade_production_calendar bpc
        INNER JOIN blade_production_calendar_day bpcd on bpc.id = bpcd.calendar_id
        INNER JOIN blade_shift_detail bsd on bpcd.model_id = bsd.model_id
        LEFT JOIN blade_shift_model bsm on bsd.model_id = bsm.id and bsm.is_deleted = 0
        where ${ew.sqlSegment}
    </select>
 
    <select id="getTimeShiftAll" resultType="com.qianwen.smartman.modules.smis.dto.CalendarShiftDTO">
        select bpcd.calendar_date, bsd.shift_start_time, bsd.shift_end_time, bsd.shift_index, bsd.index_name
        from blade_production_calendar bpc
                 inner join blade_production_calendar_day bpcd on bpc.id = bpcd.calendar_id
                 inner join blade_shift_detail bsd on bpcd.model_id = bsd.model_id
        where ${ew.sqlSegment}
    </select>
 
    <select id="getWorkstationShiftIndexListByDate"
            resultType="com.qianwen.smartman.modules.smis.dto.ShiftDetailInfoDTO">
        SELECT pdc.calendar_date,sd.shift_index as shiftIndex,
        NVL(sd.index_name,'班次' || sd.shift_index) as indexName,
        sd.shift_start_time,
        sd.shift_end_time
        FROM blade_production_calendar pc
        LEFT JOIN blade_production_calendar_day pdc ON pc.id = pdc.calendar_id
        LEFT JOIN blade_shift_detail sd ON pdc.model_id = sd.model_id
        WHERE pc.code = #{calendarCode}
        AND pc.year = #{year}
        AND pc.is_deleted = 0
        AND pdc.is_deleted = 0
        AND (to_char(pdc.start_time,'yyyy-mm-dd') = #{date} or to_char(pdc.end_time,'yyyy-mm-dd') = #{date})
        ORDER BY pdc.calendar_date,sd.shift_index
    </select>
 
</mapper>