whycxzp
2024-11-07 d3113b2a1c4c7a6c44cb0eeaf728c302cb899792
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?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.whyc.mapper.MaterialMapper">
 
 
    <!--<select id="getMaterialWithoutSub" resultType="com.whyc.pojo.Material">
        select * from  tb_Material  b
        where (select count(1) as num from  tb_material_product_history  c
               where b.id= c.material_id   and c.sub_name=#{subName} and parent_model=#{parentModel}
               and c.e_version=#{version}
             ) = 0
        and b.status=1;
    </select>-->
 
    <!--<resultMap id="productBomList" type="Material">
        <id property="id" column="id"></id>
        <result property="type" column="type"></result>
        <result property="category" column="category"></result>
        <result property="subCode" column="sub_code"></result>
        <result property="subName" column="sub_name"></result>
        <result property="subModel" column="sub_model"></result>
        <result property="unit" column="unit"></result>
        <result property="quantity" column="quantity"></result>
        <result property="producer" column="producer"></result>
        <result property="material" column="material"></result>
        <result property="thickness" column="thickness"></result>
        <result property="surfaceDetail" column="surface_detail"></result>
        <result property="notes" column="notes"></result>
        <result property="pictureUrl" column="picture_url"></result>
        <result property="fileUrl" column="file_url"></result>
        <result property="upUserId" column="up_user_id"></result>
        <result property="createDate" column="create_date"></result>
        <result property="updateDate" column="update_date"></result>
        <result property="dwgUrl" column="dwg_url"></result>
        <collection property="mproductHistorys" javaType="java.util.ArrayList" ofType="com.whyc.pojo.MaterialProductHistory" column="{id=id}" select="selectMaterialProductHistory">
        </collection>
    </resultMap>
-->
    <!--<select id="getAllMaterial" resultMap="productBomList">
        select distinct * from  tb_Material
        <where>
        1=1
            <if test="category!=null&amp;&amp;category!=''">
                and category like '%${category}%'
            </if>
            <if test="subCode!=null&amp;&amp;subCode!=''">
                and sub_code like '%${subCode}%'
            </if>
            <if test="subName!=null&amp;&amp;subName!=''">
                and sub_name like '%${subName}%'
            </if>
            <if test="subModel!=null&amp;&amp;subModel!=''">
                and sub_name like '%${subModel}%'
            </if>
        </where>
        order by id asc
    </select>-->
    <!--<select id="selectMaterialProductHistory"  resultType="com.whyc.pojo.MaterialProductHistory">
        select DISTINCT tb_material_product_history.*  FROM tb_product_bom,tb_material_product_history
        where  tb_product_bom.version=tb_material_product_history.e_version
        and tb_product_bom.parent_model=tb_material_product_history.parent_model and tb_material_product_history.material_id=#{id}
    </select>-->
 
 
    <!--<resultMap id="replaceBom" type="productBom">
       &lt;!&ndash; <result property="parentCode" column="parent_code"></result>
        <result property="parentModel" column="parent_model"></result>
        <result property="parentName" column="parent_name"></result>
        <result property="oldSubName" column="old_subName"></result>&ndash;&gt;
        <result property="type" column="type"></result>
        <result property="category" column="category"></result>
        <result property="subCode" column="sub_code"></result>
        <result property="subName" column="sub_name"></result>
        <result property="subModel" column="sub_model"></result>
        <result property="unit" column="unit"></result>
        <result property="quantity" column="quantity"></result>
        <result property="producer" column="producer"></result>
        <result property="material" column="material"></result>
        <result property="thickness" column="thickness"></result>
        <result property="surfaceDetail" column="surface_detail"></result>
        <result property="notes" column="notes"></result>
        <result property="pictureUrl" column="picture_url"></result>
        <result property="fileUrl" column="file_url"></result>
        <result property="upUserId" column="up_user_id"></result>
        <result property="createDate" column="create_date"></result>
        &lt;!&ndash;<result property="updateDate" column="update_date"></result>&ndash;&gt;
        <result property="dwgUrl" column="dwg_url"></result>
        <result property="version" column="version"></result>
        &lt;!&ndash;<result property="parentVersion" column="parent_version"></result>&ndash;&gt;
    </resultMap>-->
    <!--<select id="getReplaceMaterial" resultMap="replaceBom">
        select distinct tb_Material.*,tb_material_product_history.sub_name as old_subName
             ,tb_product_bom.parent_model,tb_product_bom.parent_code,tb_product_bom.parent_name
        ,tb_material_product_history.e_version as version
        from tb_Material,tb_material_product_history,tb_product_bom
        where tb_Material.id=tb_material_product_history.material_id
        and tb_material_product_history.parent_model=tb_product_bom.parent_model
        and tb_product_bom.version=tb_material_product_history.e_version
        and tb_material_product_history.parent_model=#{parentModel}
        and tb_material_product_history.link_type=2
    </select>-->
   <!-- <resultMap id="replaceHisBom" type="productBomHistory">
        &lt;!&ndash;<result property="parentCode" column="parent_code"></result>
        <result property="parentModel" column="parent_model"></result>
        <result property="parentName" column="parent_name"></result>&ndash;&gt;
        <result property="oldSubName" column="old_subName"></result>
        <result property="type" column="type"></result>
        <result property="category" column="category"></result>
        <result property="subCode" column="sub_code"></result>
        <result property="subName" column="sub_name"></result>
        <result property="subModel" column="sub_model"></result>
        <result property="unit" column="unit"></result>
        <result property="quantity" column="quantity"></result>
        <result property="producer" column="producer"></result>
        <result property="material" column="material"></result>
        <result property="thickness" column="thickness"></result>
        <result property="surfaceDetail" column="surface_detail"></result>
        <result property="notes" column="notes"></result>
        <result property="pictureUrl" column="picture_url"></result>
        <result property="fileUrl" column="file_url"></result>
        <result property="upUserId" column="up_user_id"></result>
        <result property="createDate" column="create_date"></result>
        <result property="dwgUrl" column="dwg_url"></result>
       &lt;!&ndash; <result property="parentVersion" column="parent_version"></result>&ndash;&gt;
    </resultMap>-->
    <!--<select id="getReplaceHisMaterial" resultMap="replaceHisBom">
        select distinct tb_Material.*,tb_material_product_history.sub_name as old_subName
                      ,tb_product_bom.parent_model,tb_product_bom.parent_code,tb_product_bom.parent_name
        from tb_Material,tb_material_product_history,tb_product_bom
        where tb_Material.id=tb_material_product_history.material_id
          and tb_material_product_history.parent_model=tb_product_bom.parent_model
          and tb_material_product_history.parent_model=#{parentModel}
          and tb_material_product_history.link_type=2
          and tb_material_product_history.s_version&lt;=#{version}
          and tb_material_product_history.e_version>=#{version}
    </select>-->
    <update id="updateDwgUrl">
        <foreach collection="list" item="item" separator=";">
            update tb_material set dwg_url = #{item.notes} where sub_model = #{item.subModel}
        </foreach>
    </update>
    <update id="updateDwgUrlAndPicUrl">
        <foreach collection="list" item="item" separator=";">
            update tb_material
            <set>
                <if test="item.dwgUrl!=null">
                    dwg_url = #{item.dwgUrl},
                </if>
                <if test="item.pictureUrl!=null">
                    picture_url = #{item.pictureUrl},
                </if>
            </set>
             where sub_code = #{item.subCode} and sub_model = #{item.subModel}
        </foreach>
    </update>
    <update id="disableStatus">
        update tb_material set status = 0 where sub_code in
        <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item.subCode}
        </foreach>
    </update>
    <resultMap id="materialList" type="Material">
        <id property="id" column="id"></id>
        <result property="type" column="type"></result>
        <!--<result property="category" column="category"></result>-->
        <result property="subCode" column="sub_code"></result>
        <result property="subName" column="sub_name"></result>
        <result property="subModel" column="sub_model"></result>
        <result property="unit" column="unit"></result>
        <!--<result property="producer" column="producer"></result>
        <result property="material" column="material"></result>
        <result property="thickness" column="thickness"></result>
        <result property="surfaceDetail" column="surface_detail"></result>
        <result property="notes" column="notes"></result>-->
        <result property="pictureUrl" column="picture_url"></result>
        <result property="fileUrl" column="file_url"></result>
        <result property="upUserId" column="up_user_id"></result>
        <result property="createDate" column="create_date"></result>
        <result property="updateDate" column="update_date"></result>
        <result property="dwgUrl" column="dwg_url"></result>
        <collection property="mproductHistorys" javaType="java.util.ArrayList" ofType="com.whyc.pojo.MaterialProductHistory" column="{id=id}" select="selectMaterialProductHistory">
        </collection>
        <collection property="products" javaType="java.util.ArrayList" ofType="com.whyc.pojo.Product" column="{id=id}" select="selectMaterialInProduct">
        </collection>
        <collection property="attachLocks" javaType="java.util.ArrayList" ofType="com.whyc.pojo.AttachLock" column="{id=id}" select="selectAttachLock">
        </collection>
    </resultMap>
 
    <select id="getMaterialLimit" resultMap="materialList">
         select * from tb_Material
         <where>
             1=1
             <if test="subCode!=null&amp;&amp;subCode!=''">
                 and sub_code like '%${subCode}%'
             </if>
             <if test="subName!=null&amp;&amp;subName!=''">
                 and sub_name like '%${subName}%'
             </if>
             <if test="subModel!=null&amp;&amp;subModel!=''">
                 and sub_model like '%${subModel}%'
             </if>
         </where>
         order by id asc
    </select>
    <select id="selectMaterialProductHistory"  resultType="com.whyc.pojo.MaterialProductHistory">
        select DISTINCT tb_material_product_history.*  FROM tb_material_product_history,tb_product
        where  tb_product.version>=tb_material_product_history.s_version and tb_product.version&lt;=tb_material_product_history.e_version
          and tb_product.parent_code=tb_material_product_history.parent_code
          and tb_product.custom_code=tb_material_product_history.custom_code
          and tb_material_product_history.sub_material_id=#{id}
    </select>
    <resultMap id="productIds" type="product">
        <id property="id" column="id"></id>
        <result property="parentCode" column="parent_code"></result>
        <result property="parentName" column="parent_name"></result>
        <result property="parentModel" column="parent_model"></result>
        <result property="notes" column="notes"></result>
        <result property="customCode" column="custom_code"></result>
        <result property="createTime" column="create_time"></result>
        <result property="version" column="version"></result>
        <collection property="materialIds" ofType="java.lang.Integer" >
            <result property="materialId" column="material_id"></result>
        </collection>
    </resultMap>
 
    <select id="selectMaterialInProduct"  resultMap="productIds">
        select p.*,tb_material_product_history.material_id  from (select DISTINCT tb_product.*  FROM tb_product, tb_product_bom
        where  tb_product.id=tb_product_bom.product_id  and tb_product_bom.material_id=#{id}) as p
        left  outer join tb_material_product_history on
        tb_material_product_history.parent_code= p.parent_code  and tb_material_product_history.custom_code= p.custom_code
        and  p.version>=tb_material_product_history.s_version and  p.version&lt;=tb_material_product_history.e_version
        and tb_material_product_history.sub_material_id=#{id}
    </select>
    <select id="selectAttachLock"  resultType="com.whyc.pojo.AttachLock">
        select DISTINCT tb_attach_lock.*  FROM tb_attach_lock
          where material_id=#{id}
    </select>
 
    <select id="getListByCodeList" resultType="java.lang.String">
        SELECT sub_code FROM tb_material where sub_code in
        <foreach collection="list" item="code" separator="," open="(" close=")">
            ${code}
        </foreach>
    </select>
    <select id="getListByCodeAndModelList" resultType="com.whyc.pojo.Material">
        <foreach collection="list" item="item" separator=" union ">
            select sub_code,sub_model from tb_material where sub_code = #{item.subCode} and sub_model = #{item.subModel}
        </foreach>
    </select>
    <select id="getListByCodeAndModelList2" resultType="com.whyc.pojo.Material">
        <foreach collection="list" item="item" separator=" union ">
            select id,sub_code,sub_model from tb_material where sub_code = #{item.subCode} and sub_model = #{item.subModel}
        </foreach>
    </select>
    <select id="getListByCodeAndModelList3" resultType="com.whyc.pojo.Material">
        <foreach collection="list" item="item" separator=" union ">
            select id,sub_code,sub_model,dwg_url from tb_material where sub_code = #{item.subCode} and sub_model = #{item.subModel} and dwg_url is not null and dwg_url!=""
        </foreach>
    </select>
    <select id="getAttachByMaterialId" resultType="com.whyc.pojo.Material">
        select * from tb_material WHERE id = #{materialId} limit 1
    </select>
    <select id="getMaterialVersion" resultType="material">
        SELECT distinct *
        FROM tb_material WHERE  sub_model LIKE '${subModel}%'
        ORDER BY create_date DESC
    </select>
    <resultMap id="materialInfo" type="Material">
        <id property="id" column="id"></id>
        <result property="type" column="type"></result>
        <!--<result property="category" column="category"></result>-->
        <result property="subCode" column="sub_code"></result>
        <result property="subName" column="sub_name"></result>
        <result property="subModel" column="sub_model"></result>
        <result property="unit" column="unit"></result>
        <!--<result property="producer" column="producer"></result>
        <result property="material" column="material"></result>
        <result property="thickness" column="thickness"></result>
        <result property="surfaceDetail" column="surface_detail"></result>
        <result property="notes" column="notes"></result>-->
        <result property="pictureUrl" column="picture_url"></result>
        <result property="fileUrl" column="file_url"></result>
        <result property="upUserId" column="up_user_id"></result>
        <result property="createDate" column="create_date"></result>
        <result property="updateDate" column="update_date"></result>
        <result property="dwgUrl" column="dwg_url"></result>
        <collection property="products" javaType="java.util.ArrayList" ofType="com.whyc.pojo.Product" column="{id=id}" select="selectInProduct">
        </collection>
        <collection property="attachLocks" javaType="java.util.ArrayList" ofType="com.whyc.pojo.AttachLock" column="{id=id}" select="selectInAttachLock">
        </collection>
    </resultMap>
    <select id="getMaterialById" resultMap="materialInfo">
        select * from tb_material WHERE id = #{materialId} limit 1
    </select>
    <select id="selectInProduct"  resultType="product">
        select DISTINCT tb_product.*  FROM tb_product,tb_product_bom
        where tb_product.id=tb_product_bom.product_id
        and tb_product_bom.material_id=#{id}
    </select>
    <select id="selectInAttachLock"  resultType="attachLock">
        select DISTINCT tb_attach_lock.*  FROM tb_attach_lock
        where tb_attach_lock.material_id=#{id}
    </select>
 
    <select id="getSameSubCodeAndModel" resultType="com.whyc.pojo.Material">
        select * from tb_material where
        <foreach collection="list" item="item" separator="or">
            (sub_code = #{item.subCode} and sub_model = #{item.subModel})
        </foreach>
    </select>
</mapper>