yangys
2025-11-18 8e944cfabb253fc2556588e308e282586043f7b0
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
<?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.qianwen.smartman.modules.smis.mapper.ProductMapper">
 
    <update id="removeBindCraft">
        update blade_craft_routing set product_id = null where product_id
        in
        <foreach collection="ids" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </update>
 
    <select id="selectListByIds" resultType="com.qianwen.smartman.modules.smis.vo.ProductVO">
        SELECT bp.*, bp2.code AS parentCode , bp2.name AS parentName ,bpt.name AS typeName FROM blade_product bp
        left join blade_product bp2
        on bp.parent_id =
        bp2.id left join blade_product_type bpt on bp.type_id = bpt.id
        <where>
            bp.is_deleted = 0 AND
            bp.id in
            <foreach collection="ids" index="index" open="(" close=")" separator="," item="item">
                #{item}
            </foreach>
        </where>
        order by bp.${orderBy}
    </select>
 
    <select id="selectIdById" resultType="com.qianwen.smartman.modules.smis.entity.Product">
        SELECT id FROM blade_product
        <where>
            is_deleted = 0 AND
            id in
            <foreach collection="param.ids" index="index" open="(" close=")" separator="," item="item">
                #{item}
            </foreach>
            <if test="param.keyWord != null and param.keyWord != ''">
                AND (code LIKE CONCAT(#{param.keyWord}, '%')
                OR name LIKE CONCAT(#{param.keyWord}, '%') )
            </if>
            <if test="param.standardModel != null and param.standardModel != ''">
                AND standard_model LIKE CONCAT(#{param.standardModel}, '%')
            </if>
            <if test="param.status != null ">
                AND status = #{param.status}
            </if>
            <if test="param.typeIds != null and  param.typeIds != '' ">
                AND type_id in
                <foreach collection="param.typeIds" index="index" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
            order by ${param.orderBy}
        </where>
 
    </select>
 
    <select id="getParentStatusCount" resultType="int">
        select count(1) from blade_product where is_deleted = 0 and status = 1 and parent_id
        in
        <foreach collection="ids" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </select>
 
    <select id="getParentDetail" parameterType="long" resultType="com.qianwen.smartman.modules.smis.entity.Product">
        SELECT id, parent_id, status
        FROM `blade_product`
        where id = (SELECT parent_id from blade_product where id = #{id})
    </select>
    <select id="selectListByParam" resultType="com.qianwen.smartman.modules.smis.vo.ProductVO">
        SELECT bp.*, bp2.code AS parentCode , bp2.name AS parentName ,bpt.name AS typeName FROM blade_product bp
        left join blade_product bp2
        on bp.parent_id =
        bp2.id left join blade_product_type bpt on bp.type_id = bpt.id
        <where>
            bp.is_deleted = 0
            <if test="param.keyWord != null and param.keyWord != ''">
                AND (bp.code LIKE CONCAT(#{param.keyWord}, '%')
                OR bp.name LIKE CONCAT(#{param.keyWord}, '%') )
            </if>
            <if test="param.parentId != null">
                AND bp.parent_id = #{param.parentId}
            </if>
            <if test="param.standardModel != null and param.standardModel != ''">
                AND bp.standard_model LIKE CONCAT(#{param.standardModel}, '%')
            </if>
            <if test="param.status != null ">
                AND bp.status = #{param.status}
            </if>
            <if test="param.typeIds != null and  param.typeIds != '' ">
                AND bp.type_id in
                <foreach collection="param.typeIds" index="index" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
        order by bp.create_time desc
    </select>
 
    <select id="notBandProduct" resultType="com.qianwen.smartman.modules.smis.entity.Product">
        select id,
               tenant_id,
               code,
               name,
               parent_id,
               type_id,
               unit,
               standard_model,
               description,
               documents,
               create_user,
               create_dept,
               create_time,
               update_user,
               update_time,
               status,
               is_deleted
        from blade_product bp
        where not exists(select *
                         from blade_craft_routing bcr
                         where bcr.is_deleted = 0
                           and bcr.product_id = bp.id
                           and bcr.id != #{craftId})
          and bp.is_deleted = 0;
    </select>
 
    <select id="exportProduct" resultType="com.qianwen.smartman.modules.smis.excel.ProductExcel">
        select bp1.code,
        bp1.name,
        bp2.code parentId,
        bpt.name typeName,
        bp1.extend_field ,
        bp1.unit,
        bp1.standard_model,
        bp1.description,
        bp1.documents,
        bp1.status,
        bp1.extend_field
        from blade_product bp1
        left join blade_product bp2 on bp1.parent_id = bp2.id and bp2.is_deleted = 0
        left join blade_product_type bpt on bp1.type_id = bpt.id and bpt.is_deleted = 0
        where bp1.is_deleted = 0
        <if test="ew!=null">
            and ${ew.sqlSegment}
        </if>
        <if test="fieldSql != null and fieldSql != ''">
            and ${fieldSql}
        </if>
        order by bp1.create_time desc,bp1.id desc ;
    </select>
 
    <select id="lazyTree" resultType="com.qianwen.smartman.modules.smis.vo.ProductEasyVO">
        select bp1.id,
        bp1.code,
        bp1.name,
        bp1.parent_id,
        bp1.type_id,
        bp1.unit,
        bp1.standard_model,
        bp1.description,
        bp1.documents,
        bp1.status,
        bp1.extend_field,
        bpt.name typeName
        from blade_product bp1
        left join blade_product_type bpt on bp1.type_id = bpt.id
        where bp1.is_deleted = 0
        <if test="ew!=null">
            and ${ew.sqlSegment}
        </if>
        <if test="fieldSql != null and fieldSql != ''">
            and ${fieldSql}
        </if>
        order by bp1.create_time desc,bp1.id desc ;
    </select>
    <select id="hasChild"
            resultType="com.qianwen.smartman.modules.smis.dto.ProductCountDTO">
        SELECT
        parent_id AS productId,
        count( parent_id ) AS count
        FROM
        blade_product
        WHERE
        is_deleted = 0
        <if test="status == 1">
            and status = 1
        </if>
        <if test="status == 0">
            and status = 0
        </if>
        and parent_id IN
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        GROUP BY
        parent_id
 
    </select>
    <select id="lazyTreeCount" resultType="java.lang.Integer">
        select
        count(1)
        from blade_product bp1
        left join blade_product_type bpt on bp1.type_id = bpt.id
        where bp1.is_deleted = 0
        <if test="ew!=null">
            and ${ew.sqlSegment}
        </if>
        <if test="fieldSql != null and fieldSql != ''">
            and ${fieldSql}
        </if>
    </select>
</mapper>