wu
2025-10-23 27550ee46778905ab194844ab5247b116f70659e
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
149
150
151
152
<?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.pp.mapper.OptimizeProjectMapper">
 
    <resultMap id="sequenceMap" type="com.mes.uppattenusage.entity.UpPattenUsage">
        <result property="engineeringId" column="project_no"/>
        <result property="filmsId" column="glass_type"/>
        <result property="width" column="width"/>
        <result property="height" column="height"/>
        <result property="thickness" column="glass_thickness"/>
        <result property="layoutSequence" column="heat_layout_sort"/>
        <result property="state" column="state"/>
    </resultMap>
 
    <resultMap id="resultMap" type="com.mes.pp.entity.OptimizeProject">
        <result property="id" column="id"/>
        <result property="projectNo" column="project_no"/>
        <result property="projectName" column="project_name"/>
        <result property="state" column="state"/>
        <result property="type" column="type"/>
        <result property="glassThickness" column="glass_thickness"/>
        <result property="glassType" column="glass_type"/>
        <result property="glassTotal" column="glass_total"/>
        <result property="glassTotalArea" column="glass_total_area"/>
    </resultMap>
    <resultMap id="progressResultMap" type="com.mes.pp.entity.dto.ProgressDTO">
        <!-- 玻璃信息表(a)字段映射 -->
        <result property="engineerId" column="engineer_id"/>    <!-- 玻璃No → a.engineer_id -->
        <result property="flowCardId" column="flow_card_id"/>     <!-- 流程卡号 → a.flow_card_id -->
        <result property="layer" column="layer"/>     <!-- 层号 → a.layer -->
        <result property="glassType" column="glass_type"/>      <!-- 玻璃名称 → a.glass_type -->
        <result property="width" column="width"/>                <!-- 宽 → a.width -->
        <result property="height" column="height"/>              <!-- 高 → a.height -->
        <result property="glassIdCount" column="glassIdCount"/>      <!-- 订单数量 → 统计的 glassIdCount -->
        <result property="cuttingCount" column="cuttingCount"/>       <!-- 切割报工数 → cuttingCount -->
        <result property="edgingCount" column="edgingCount"/>   <!-- 磨边报工数 → edgingCount -->
         <result property="temperingCount" column="temperingCount"/>
         <result property="insulatingCount" column="insulatingCount"/>
    </resultMap>
    <select id="saveProject" parameterType="com.mes.pp.entity.request.OptimizeRequest" resultMap="sequenceMap">
        select a.project_no,
               1                                            as glass_type,
               a.width,
               a.height,
               REGEXP_REPLACE(b.glass_thickness, '\\D', '') as glass_thickness,
               a.heat_layout_sort,
               0                                            as state
        from optimize_detail a
                 left join optimize_project b on a.project_no = b.project_no
        where a.project_no = #{projectNo}
    </select>
 
    <select id="queryEngineer" parameterType="com.mes.pp.entity.OptimizeProject" resultMap="resultMap">
        select p.project_no,
               p.project_name,
               p.glass_thickness,
               p.glass_type,
               p.glass_total,
               p.glass_total_area
        from pp.optimize_project p
        where p.state = 100
          and p.project_no not in (select es.project_no
                                   from north_glass_mes.engineer_scheduling es
                                   where es.project_no is not null)
        order by p.id
    </select>
 
    <select id="engineerScheduling" parameterType="com.mes.pp.entity.request.OptimizeRequest" resultMap="resultMap">
        select es.project_no,
        es.project_name,
        es.type,
        p.glass_thickness,
        p.glass_type,
        p.glass_total,
        p.glass_total_area
        from north_glass_mes.engineer_scheduling es
        left join pp.optimize_project p on es.project_no=p.project_no
        where es.state = 100
        <if test="type != null and type != ''">
            and es.type = #{type}
        </if>
        order by es.id
    </select>
 
    <!-- 根据类型删除engineer_scheduling表中的数据 -->
    <delete id="deleteByType">
        DELETE
        FROM north_glass_mes.engineer_scheduling
        WHERE type = #{type}
    </delete>
    <delete id="deleteByScheduling">
        DELETE
        FROM north_glass_mes.engineer_scheduling
        WHERE project_no = #{engineerId}
        and type in (
        <foreach collection="types" item="item" separator=",">
            #{item}
        </foreach>
        )
    </delete>
 
    <!-- 批量插入数据到engineer_scheduling表 -->
    <insert id="batchInsert">
        INSERT INTO north_glass_mes.engineer_scheduling (
        project_no,
        project_name,
        state,
        type
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.projectNo},
            #{item.projectName},
            #{item.state},
            #{item.type}
            )
        </foreach>
    </insert>
    <select id="selectProgress" parameterType="com.mes.glassinfo.entity.GlassInfo" resultMap="progressResultMap">
        SELECT
        a.engineer_id,
        a.flow_card_id,
        a.layer,
        a.glass_type,
        a.thickness,
        a.filmsid,
        a.width,
        a.height,
        COUNT(a.glass_id) as glassIdCount,
        SUM(CASE WHEN d.working_procedure = '切割' AND d.type = 1 THEN 1 ELSE 0 END) as cuttingCount,
        SUM(CASE WHEN d.working_procedure = '磨边' AND d.type = 1 THEN 1 ELSE 0 END) as edgingCount,
        SUM(CASE WHEN d.working_procedure = '钢化' AND d.type = 1 THEN 1 ELSE 0 END) as temperingCount,
        SUM(CASE WHEN d.working_procedure = '中空' AND d.type = 1 THEN 1 ELSE 0 END) as insulatingCount
        FROM
        north_glass_mes.glass_info a
        LEFT JOIN
        north_glass_mes.damage d
        ON a.glass_id = d.glass_id
        AND a.engineer_id = d.engineer_id
        WHERE
        a.engineer_id = #{engineerId}
        GROUP BY
        a.engineer_id,
        a.flow_card_id,
        a.layer,
        a.glass_type,
        a.thickness,
        a.filmsid,
        a.width,
        a.height
    </select>
</mapper>