李林
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
<?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.basic.mapper.PartMapper">
 
    <resultMap id="partMap" type="com.chinaztt.mes.basic.entity.Part">
        <id property="id" column="id"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="materialType" column="material_type"/>
        <result property="unit" column="unit"/>
        <result property="description" column="description"/>
        <result property="category" column="category"/>
        <result property="assortment" column="assortment"/>
        <result property="specs" column="specs"/>
        <result property="drawingNumber" column="drawing_number"/>
        <result property="ean" column="ean"/>
        <result property="testRuleId" column="test_rule_id"/>
        <result property="partFamilyName" column="part_family_name"/>
        <result property="weight" column="weight"/>
        <result property="useSystemNo" column="use_system_no"/>
        <result property="voltageLevel" column="voltage_level"/>
        <result property="lotTrackingIfs" column="lot_tracking_ifs"/>
        <result property="engChgLevel" column="eng_chg_level"/>
        <result property="planningMethod" column="planning_method"/>
        <result property="threeLevelClassification" column="three_level_classification"/>
        <result property="characteristic1" column="characteristic1"/>
        <result property="characteristic2" column="characteristic2"/>
        <result property="characteristic3" column="characteristic3"/>
        <result property="partModel" column="part_model"/>
        <result property="materialAttribute" column="material_attribute"/>
        <result property="examiner" column="examiner"/>
        <result property="prodName" column="prod_name"/>
        <result property="partPitch" column="part_pitch"/>
    </resultMap>
 
    <sql id="partPage">
        SELECT
            part.*,
            bpf.part_family_name part_family_name
        FROM
            basic_part part
                LEFT JOIN (SELECT * FROM basic_part_family WHERE active = TRUE) bpf ON part.part_family_id = bpf.id
        WHERE part.active = TRUE
        ORDER BY part.create_time DESC
    </sql>
 
    <select id="getPartPage" resultMap="partMap">
        select * from(<include refid="partPage"/>) a
        <where>
            <if test="bomId != null and bomId != 0">
                exists(select 1 from technology_bom_component tbc where tbc.bom_id=#{bomId} and tbc.part_id=a."id"
                and exists(select 1 from technology_bom_component child where child.parent=tbc."id" and
                child.bom_id=tbc.bom_id))
            </if>
            <if test="ew.emptyOfWhere == false">
                and ${ew.SqlSegment}
            </if>
        </where>
    </select>
 
    <select id="query" resultMap="partMap">
        <bind name="searchKey" value="'%' + keyword + '%'"/>
        select * from basic_part a where a.active=true and a.part_no like #{searchKey} or a.part_name like #{searchKey}
        order by id limit 100
    </select>
 
    <sql id="qualityPartPage">
        SELECT
            bp.*
        FROM
            basic_part bp
        WHERE bp."id" IN
              (SELECT part_id FROM quality_join_template_part)
          AND bp."id" NOT IN (SELECT part_id FROM quality_inspection_task WHERE quality_inspection_task.active = TRUE)
    </sql>
 
    <select id="getQualityPartPage" resultMap="partMap">
        select * from (<include refid="qualityPartPage"/>) a
        <if test="ew.emptyOfWhere == false">
            <where>
                ${ew.SqlSegment}
            </where>
        </if>
    </select>
 
    <sql id="notInQualityPartPage">
        SELECT
            bp.*
        FROM
            basic_part bp
        WHERE bp."id" NOT IN
              (SELECT part_id FROM quality_join_template_part)
          AND bp.active = TRUE
    </sql>
 
    <select id="getNotInQualityPartPage" resultMap="partMap">
        select * from (<include refid="notInQualityPartPage"/>) a
        <if test="ew.emptyOfWhere == false">
            <where>
                ${ew.SqlSegment}
            </where>
        </if>
    </select>
 
    <sql id="reportPartPage">
        SELECT
            bp.*
        FROM
            basic_part bp
        WHERE bp."id" IN
              (SELECT part_id FROM quality_inspection_task WHERE quality_inspection_task.active = TRUE)
          AND bp."id" NOT IN
              (SELECT part_id
               FROM quality_inspection_task
               WHERE quality_inspection_task.id IN (SELECT test_task_id FROM quality_test_report WHERE active = TRUE))
          AND bp.active = TRUE
    </sql>
 
    <select id="getReportPartsPage" resultMap="partMap">
        select * from (<include refid="reportPartPage"/>) a
        <if test="ew.emptyOfWhere == false">
            <where>
                ${ew.SqlSegment}
            </where>
        </if>
    </select>
 
    <select id="selectReportIdBySystemNoAndType" resultType="java.lang.Long">
        SELECT
            ap.report_id
        FROM
            quality_apply_part ap
                LEFT JOIN quality_apply a ON a.id = ap.apply_id
        WHERE
            ap.system_no = #{systemNo}
          AND a.apply_type = #{applyType}
    </select>
 
 
    <select id="getPartConcatEcl" resultType="java.lang.String">
        SELECT part_no || '_' || eng_chg_level
        FROM basic_part
    </select>
 
 
    <select id="getByConcateCondition" resultType="com.chinaztt.mes.basic.entity.Part">
        SELECT *
        FROM basic_part
        WHERE part_no || '_' || eng_chg_level = #{partNoEngChgLevel}
    </select>
 
    <select id="countComponentNum" resultType="java.lang.Integer">
        SELECT
            count(1)
        FROM
            technology_bom_component tbc
        WHERE
            tbc.bom_id = #{bomId}
    </select>
 
    <select id="getPartPageIncludeOwn" resultMap="partMap">
        select * from(<include refid="partPage"/>) a
        <where>
            <if test="bomId != null and bomId != 0">
                exists(select 1 from technology_bom_component tbc where tbc.bom_id=#{bomId} and tbc.part_id=a."id")
            </if>
            <if test="ew.emptyOfWhere == false">
                and ${ew.SqlSegment}
            </if>
        </where>
    </select>
</mapper>