zhoushihao
2025-04-15 c6cb57f307b0c62a05cac78cfd828c313f10e611
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
<?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.mes.edgstoragecage.mapper.EdgStorageCageDetailsMapper">
 
    <resultMap id="baseMap" type="com.mes.edgstoragecage.entity.EdgStorageCageDetails">
        <id column="id" property="id"/>
        <result column="engineer_id" property="engineerId"/>
        <result column="device_id" property="deviceId"/>
        <result column="slot" property="slot"/>
        <result column="glass_id" property="glassId"/>
        <result column="sequence" property="sequence"/>
        <result column="flow_card_id" property="flowCardId"/>
        <result column="glass_type" property="glassType"/>
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="thickness" property="thickness"/>
        <result column="edg_width" property="edgWidth"/>
        <result column="edg_height" property="edgHeight"/>
        <result column="tempering_layout_id" property="temperingLayoutId"/>
        <result column="tempering_feed_sequence" property="temperingFeedSequence"/>
        <result column="pattern_sequence" property="patternSequence"/>
        <result column="state" property="state"/>
        <result column="gap" property="gap"/>
        <result column="glass_count" property="count"/>
    </resultMap>
 
    <select id="queryEdgStorageDetailsBySize" resultMap="baseMap">
        with min_id_temp as (
        select slot, min(id) as id, count(*) as glass_count
        from edg_storage_cage_details
        where state = 100
        and device_id = #{deviceId}
        group by slot
        ),
        size_max_temp as (
        select width, height, count(*) as total_count
        from edg_storage_cage_details t
        inner join min_id_temp t1 on t.id = t1.id
        group by width, height
        ),
        slot_temp as (
        select t.*, t1.glass_count
        from edg_storage_cage_details t
        inner join min_id_temp t1 on t.id = t1.id
        inner join size_max_temp t2 on t.width = t2.width and t.height = t2.height
        <where>
            <if test="width != 0">
                and t.width = #{width}
            </if>
            <if test="height != 0">
                and t.height = #{height}
            </if>
        </where>
        order by total_count desc, glass_count, abs(t.slot - #{currentSlot})
        )
        select *
        from slot_temp limit 1
    </select>
    <select id="queryCutDrawingByEngineerId" resultType="com.mes.edgstoragecage.entity.vo.CutDrawingVO">
        with glass_temp as (
        select * from glass_info where engineer_id = #{engineerId} and pattern_sequence = #{patternSequence}
        ), cut_drawing_temp as (
        select t.*,
        case when t2.glass_id is not null then t2.type
        when t1.glass_id is not null then t1.state
        else 0 end as state
        from glass_temp t
        left join edg_storage_cage_details t1 on t.glass_id = t1.glass_id
        left join damage t2 on t.glass_id = t2.glass_id and t2.type in (8,9)
        )select * from cut_drawing_temp where 1=1
        <if test="isAll == 1">
            and state = 0
        </if>
 
    </select>
    <select id="querySlotRemainWidth" resultType="com.mes.edgstoragecage.entity.vo.EdgSlotRemainVO">
        select device_id,
               slot,
               if(#{cellLength} - sum(GREATEST(width, height) + #{glassGap}) &lt; 0, 0, #{cellLength} -
                                                                                        sum(GREATEST(width, height) + #{glassGap})) as
                   remain_width
        from edg_storage_cage_details
        where state = 100
        group by device_id, slot
    </select>
    <select id="queryEdgStorageDetailsByLimitSize" resultMap="baseMap">
        SELECT t1.*
        FROM edg_storage_cage t
        LEFT JOIN edg_storage_cage_details t1 ON t.device_id = t1.device_id
        AND t.slot = t1.slot
        <where>
            t.enable_state = 1
            AND t1.state = 100
            AND t1.device_id = #{deviceId}
            <if test="width != 0">
                and t.width = #{width}
            </if>
            <if test="height != 0">
                and t.height = #{height}
            </if>
            <if test="cell == 1">
                and #{minOneFirstLength} &lt;= GREATEST(t.width, t.width)
                and #{minOneSecondLength} &lt;= least(t.width, t.width)
            </if>
            <if test="cell == 2">
                and #{maxTwoFirstLength} &gt;= GREATEST(t.width, t.width)
                and #{maxTwoSecondLength} &gt;= least(t.width, t.width)
            </if>
        </where>
        ORDER BY abs(t.slot - #{currentCell})
        limit 1
    </select>
    <select id="queryPieChart" resultType="com.mes.largenscreen.entity.PieChartVO">
        SELECT round(sum(CASE WHEN e.station_cell = 5 THEN 1 ELSE 0 END), 2)                                                   as oneCompletedQuantity,
               round(sum(CASE WHEN e.station_cell = 5 THEN escd.width * escd.height / 1000000 ELSE 0 END),
                     2)                                                                                                        as oneCompletedArea,
               round(sum(CASE WHEN e.station_cell = 6 THEN 1 ELSE 0 END), 2)                                                   as twoCompletedQuantity,
               round(sum(CASE WHEN e.station_cell = 6 THEN escd.width * escd.height / 1000000 ELSE 0 END),
                     2)                                                                                                        as twoCompletedArea,
               round(sum(CASE WHEN e.station_cell = 5 and escd.device_id is null THEN 1 ELSE 0 END),
                     2)                                                                                                        as oneUncompletedQuantity,
               round(sum(CASE
                             WHEN e.station_cell = 5 and escd.device_id is null THEN gi.width * gi.height / 1000000
                             ELSE 0 END),
                     2)                                                                                                        as oneUncompletedArea,
               round(sum(CASE WHEN e.station_cell = 6 and escd.device_id is null THEN 1 ELSE 0 END),
                     2)                                                                                                        as twoUncompletedQuantity,
            round(sum( CASE WHEN e.station_cell = 6 and escd.device_id is null THEN gi.width*gi.height/1000000 ELSE 0 END ),2) as twoUncompletedArea
        FROM
            glass_info gi
                left join edg_storage_cage_details escd ON gi.glass_id = escd.glass_id
                left join engineering e on gi.engineer_id=e.engineer_id
        WHERE
            date(e.create_time) = date(now())
    </select>
</mapper>