李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?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.technology.mapper.StructureMapper">
 
    <resultMap id="structureMap" type="com.chinaztt.mes.technology.dto.StructureDTO">
        <id property="id" column="id"/>
        <result property="partNo" column="part_no"/>
        <result property="partId" column="part_id"/>
        <result property="structureType" column="structure_type"/>
        <result property="master" column="master"/>
        <result property="remark" column="remark"/>
        <result property="partName" column="part_name"/>
        <result property="drawingNumber" column="drawing_number"/>
        <result property="unit" column="unit"/>
        <result property="version" column="version"/>
        <result property="bomTypeDb" column="bom_type_db"/>
        <result property="alternativeNo" column="alternative_no"/>
        <result property="alternativeDesc" column="alternative_desc"/>
        <result property="ifsSync" column="ifs_sync"/>
    </resultMap>
 
    <resultMap id="structureComponentMap" type="com.chinaztt.mes.technology.dto.StructureComponentDTO">
        <id property="id" column="id"/>
        <result property="structureId" column="structure_id"/>
        <result property="partId" column="part_id"/>
        <result property="qpa" column="qpa"/>
        <result property="discNum" column="disc_num"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="drawingNumber" column="drawing_number"/>
        <result property="unit" column="unit"/>
        <result property="operationId" column="operation_id"/>
        <result property="operationNo" column="operation_no"/>
        <result property="operationName" column="operation_name"/>
        <result property="lineItemNo" column="line_item_no"/>
        <result property="color" column="color"/>
        <result property="planningMethod" column="planning_method"/>
    </resultMap>
 
    <resultMap id="structureComponentDtoMap" type="com.chinaztt.mes.technology.dto.StructureDTO">
        <id property="id" column="id"/>
        <result property="partNo" column="part_no"/>
        <result property="partId" column="part_id"/>
        <result property="structureType" column="structure_type"/>
        <result property="master" column="master"/>
        <result property="remark" column="remark"/>
        <result property="partName" column="part_name"/>
        <result property="drawingNumber" column="drawing_number"/>
        <result property="unit" column="unit"/>
        <result property="version" column="version"/>
        <result property="bomTypeDb" column="bom_type_db"/>
        <result property="alternativeNo" column="alternative_no"/>
        <result property="alternativeDesc" column="alternative_desc"/>
        <result property="ifsSync" column="ifs_sync"/>
        <collection property="components" ofType="com.chinaztt.mes.technology.dto.StructureComponentDTO"
                    select="com.chinaztt.mes.technology.mapper.StructureMapper.getComponentDtoByStructureId"
                    column="id">
        </collection>
    </resultMap>
 
    <sql id="structurePage">
        SELECT A.*,
               P.part_name,
               p.part_no
        FROM
            technology_structure A
                LEFT JOIN basic_part P ON A.part_id = P."id"
        WHERE A.active = TRUE
        ORDER BY A.id DESC
    </sql>
 
    <select id="getStructurePage" resultMap="structureMap">
        select * from (<include refid="structurePage"/>) a
        <if test="ew.emptyOfWhere == false">
            <where>
                ${ew.SqlSegment}
            </where>
        </if>
    </select>
 
    <select id="getDtoById" resultMap="structureMap">
        SELECT
            s.*,
            P.part_name,
            P.part_no
        FROM
            technology_structure s
                LEFT JOIN basic_part P ON P.ID = s.part_id
        WHERE
            s.ID = #{id}
          AND s.active = TRUE
    </select>
 
    <select id="getComponentDtoByStructureId" resultMap="structureComponentMap">
        SELECT
            s.*,
            P.*,
            o.id   operation_id,
            o.name operation_name,
            o.operation_no
        FROM
            technology_structure_component s
                LEFT JOIN basic_part P ON P.ID = s.part_id
                LEFT JOIN technology_operation o ON o.id = s.operation_id
        WHERE
            s.structure_id = #{structureId}
        ORDER BY s."id"
    </select>
 
    <select id="getMasterComponentsByPartId" resultMap="structureComponentMap">
        SELECT
            C.*,
            P.*
        FROM
            technology_structure s,
            technology_structure_component C,
            basic_part P
        WHERE
            s.part_id = #{partId}
          AND s.master = TRUE
          AND s.active = TRUE
          AND C.structure_id = s."id"
          AND C.part_id = P.ID
    </select>
 
    <select id="getParentPartIds" resultType="long">
        SELECT
            s.part_id
        FROM
            technology_structure_component T,
            technology_structure s
        WHERE
            T.part_id = #{partId}
          AND t.structure_id = s.id
          AND s.active = TRUE
    </select>
 
    <select id="getStructureDtoByDocId" resultMap="structureComponentDtoMap">
        SELECT
            ts.*,
            bp.part_no
        FROM
            technology_structure ts
                LEFT JOIN basic_part bp ON bp.ID = ts.part_id
        WHERE
                ts."id" IN (
                SELECT DISTINCT parent_structure_id
                FROM technology_bom_component
                WHERE bom_id IN (
                    SELECT bom_id
                    FROM technology_join_document_bom_routing
                    WHERE document_id = #{docId}));
    </select>
 
    <select id="getStructureDtoByIds" resultMap="structureComponentDtoMap">
        SELECT
            ts.*,
            bp.part_no
        FROM
            technology_structure ts
                LEFT JOIN basic_part bp ON bp.ID = ts.part_id
        WHERE
            ts."id" IN
        <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
 
    <select id="getUnIfsedStructureDtoByDocId" resultType="com.chinaztt.mes.technology.entity.Structure">
        SELECT
            ts.*
        FROM
            technology_structure ts
                LEFT JOIN basic_part bp ON bp.ID = ts.part_id
        WHERE
            ts.ifs_sync = FALSE
          AND ts."id" IN (SELECT DISTINCT parent_structure_id
                          FROM technology_bom_component
                          WHERE bom_id IN (SELECT bom_id
                                           FROM technology_join_document_bom_routing
                                           WHERE document_id = #{docId}));
    </select>
 
    <update id="updateIfsTrue">
        UPDATE technology_structure SET ifs_sync = TRUE WHERE id IN
        <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>
 
</mapper>