liujie
2 天以前 c3013bb5d539cf08e8faad076c8ad323f9b683ae
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<?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.ruoyi.system.mapper.TErpGoodsMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.TErpGoods">
        <id column="id" property="id"/>
        <result column="supplier_clinic_id" property="supplierClinicId"/>
        <result column="goods_source" property="goodsSource"/>
        <result column="clinic_id" property="clinicId"/>
        <result column="goods_name" property="goodsName"/>
        <result column="goods_id_code" property="goodsIdCode"/>
        <result column="quasi_number" property="quasiNumber"/>
        <result column="manufacturer" property="manufacturer"/>
        <result column="formulation_spec" property="formulationSpec"/>
        <result column="packing_spec" property="packingSpec"/>
        <result column="type_id" property="typeId"/>
        <result column="goods_yards" property="goodsYards"/>
        <result column="maintenance_interval" property="maintenanceInterval"/>
        <result column="low_purchase_quantity" property="lowPurchaseQuantity"/>
        <result column="low_unit_id" property="lowUnitId"/>
        <result column="is_prescription_drug" property="isPrescriptionDrug"/>
        <result column="goods_spec" property="goodsSpec"/>
        <result column="warning_inventory" property="warningInventory"/>
        <result column="sales_amount" property="salesAmount"/>
        <result column="packing_unit_id" property="packingUnitId"/>
        <result column="instructions_use" property="instructionsUse"/>
        <result column="side_effect" property="sideEffect"/>
        <result column="clinic_purchase_price" property="clinicPurchasePrice"/>
        <result column="platform_commission_price" property="platformCommissionPrice"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by" property="updateBy"/>
        <result column="disabled" property="disabled"/>
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        , supplier_clinic_id, goods_source, goods_name, goods_id_code, quasi_number, manufacturer, formulation_spec, packing_spec, type_id, goods_yards, maintenance_interval,maintenance_interval_unit, low_purchase_quantity, low_unit_id, is_prescription_drug, goods_spec, warning_inventory, sales_amount, packing_unit_id, instructions_use, side_effect, clinic_purchase_price, platform_commission_price, create_time, update_time, create_by,`state`, update_by, disabled,
          simplified_code,
dosage_form,
usage_classification,
product_brand,
place_of_origin,
ingredient,
trait,
indication,
taboo,
precautions,
interaction,
storage,supplier_name
 
    </sql>
 
 
    <select id="pageList" resultType="com.ruoyi.system.vo.TErpGoodsVO">
        select
       t1.id
        ,  t1.supplier_clinic_id,  t1.goods_source,  t1.goods_name,  t1.goods_id_code,  t1.quasi_number,  t1.manufacturer,  t1.formulation_spec,  t1.packing_spec,  t1.type_id,  t1.goods_yards,  t1.maintenance_interval, t1.maintenance_interval_unit,  t1.low_purchase_quantity,  t1.low_unit_id,  t1.is_prescription_drug,  t1.goods_spec,  t1.warning_inventory,  t1.sales_amount,  t1.packing_unit_id,  t1.instructions_use,  t1.side_effect,  t1.clinic_purchase_price,  t1.platform_commission_price,  t1.create_time,  t1.update_time,  t1.create_by, t1.`state`,  t1.update_by,  t1.disabled,
        t1.simplified_code,
        t1.dosage_form,
        t1.usage_classification,
        t1.product_brand,
        t1.place_of_origin,
        t1.ingredient,
        t1.trait,
        t1.indication,
        t1.taboo,
        t1.precautions,
        t1.interaction,
        t1.storage,
        case t1.goods_source
        when 1 then t2.supplier_name
        when 2 then t1.supplier_name
        end as supplierName
        from t_erp_goods t1 left join t_crm_supplier t2 on t1.supplier_clinic_id = t2.id where  t1.disabled = 0
        <if test="query.supplierName != null and query.supplierName != ''">
            and  (t1.supplier_name like concat('%',#{query.supplierName},'%') or t2.supplier_name like concat('%',#{query.supplierName},'%'))
        </if>
        <if test="query.goodsName != null and query.goodsName != ''">
            and  t1.goods_name like concat('%',#{query.goodsName},'%')
        </if>
 
        <if test="query.goodsIdCode != null and query.goodsIdCode != ''">
            and  t1.goods_id_code like concat('%',#{query.goodsIdCode},'%')
        </if>
        <if test="query.typeId != null and query.typeId != ''">
            and  t1.type_id = #{query.typeId}
        </if>
        <if test="query.quasiNumber != null and query.quasiNumber != ''">
            and  t1.quasi_number like concat('%',#{query.quasiNumber},'%')
        </if>
        <if test="query.state != null ">
            and  t1.state = #{query.state}
        </if>
        <if test="user.roleType != null and user.roleType == 4 ">
            and  t1.goods_source =1 and  t1.supplier_clinic_id = #{query.supplierClinicId}
        </if>
        <if test="user.roleType != null and user.roleType == 5 ">
            and  ( ( t1.goods_source =2 and  t1.supplier_clinic_id = #{query.supplierClinicId} ) or (FIND_IN_SET(#{query.supplierClinicId}, t1.clinic_ids) and  t1.state =1))
        </if>
        order by  t1.create_time desc
    </select>
 
 
    <select id="listExport" resultType="com.ruoyi.system.vo.TErpGoodsVO">
        select
        <include refid="Base_Column_List"/>
        from t_erp_goods where disabled = 0
        <if test="query.goodsName != null and query.goodsName != ''">
            and goods_name like concat('%',#{query.goodsName},'%')
        </if>
        <if test="query.goodsIdCode != null and query.goodsIdCode != ''">
            and goods_id_code like concat('%',#{query.goodsIdCode},'%')
        </if>
        <if test="query.typeId != null and query.typeId != ''">
            and type_id = #{query.typeId}
        </if>
        <if test="query.quasiNumber != null and query.quasiNumber != ''">
            and quasi_number like concat('%',#{query.quasiNumber},'%')
        </if>
        <if test="query.state != null ">
            and state = #{query.state}
        </if>
        <if test="user.roleType != null and user.roleType == 4 ">
            and goods_source =1 and supplier_clinic_id =#{query.supplierClinicId}
        </if>
        <if test="user.roleType != null and user.roleType == 5 ">
            and goods_source =2 and supplier_clinic_id =#{query.supplierClinicId}
        </if>
        order by create_time desc
    </select>
 
 
    <select id="pageInventoryGoodsPageList" resultType="com.ruoyi.system.vo.TErpGoodsInventoryVO">
        select * from (
        SELECT t1.id,t2.warehouse_no,
        t3.goods_name,
        t4.supplier_name,
        t3.type_id,
        t3.packing_unit_id,
        t3.quasi_number,
        t3.goods_id_code,
        t1.batch_number,
        coalesce(sum(t5.outbound_count),0) as outbound_count,
        t1.warehousing_number,
        t2.create_time,
        t1.warehousing_number - coalesce(sum(t5.outbound_count),0) as num,
        t2.unit_amount as sales_amount,
        t1.expiry_date
        from t_erp_supplier_warehousing_batch t1
        LEFT JOIN t_erp_supplier_warehousing t2 on t1.warehousing_id = t2.id
        LEFT JOIN t_erp_goods t3 on t2.goods_id = t3.id
        LEFT JOIN t_crm_supplier t4 on t3.supplier_clinic_id = t4.id
        LEFT JOIN t_erp_supplier_outbound_goods t5 on t5.warehousing_batch_id =t1.id
        where t2.disabled = 0 and t2.warehouse_id = #{query.warehouseId}
        <if test="query.type != null and query.type ==1">
            and #{time} > t1.expiry_date
        </if>
        <if test="query.goodsName != null and query.goodsName != ''">
            and t3.goods_name like concat('%',#{query.goodsName},'%')
        </if>
        <if test="user.roleType !=null and user.roleType ==4">
            and t3.supplier_clinic_id =#{supplierClinicId} and t3.goods_source=1
        </if>
        <if test="user.roleType !=null and user.roleType ==5">
            and t3.supplier_clinic_id =#{supplierClinicId} and t3.goods_source=2
        </if>
        <if test="query.supplierName != null and query.supplierName != ''">
            and t4.supplier_name like concat('%',#{query.supplierName},'%')
        </if>
 
        <if test="query.typeId != null and query.typeId != ''">
            and t3.type_id = #{query.typeId}
        </if>
        <if test="query.quasiNumber != null and query.quasiNumber != ''">
            and t3.quasi_number =#{query.quasiNumber}
        </if>
        <if test="query.batchNumber != null and query.batchNumber != ''">
            and t1.batch_number =#{query.batchNumber}
        </if>
        <if test="query.warehouseNo != null and query.warehouseNo != ''">
            and t2.warehouse_no = #{query.warehouseNo}
        </if>
        GROUP BY t1.id
        ) as o
        where (o.warehousing_number -o.outbound_count) >0
        order by o.create_time desc
    </select>
    <select id="pageInventoryGoodsPageList1" resultType="com.ruoyi.system.vo.TErpGoodsInventoryVO">
        select * from (
        SELECT t1.id,t2.warehouse_no,
        t3.goods_name,t3.goods_source,
        case t3.goods_source when 1 then t4.supplier_name when 2 then t3.supplier_name end as supplierName,
        t3.type_id,
        t3.packing_unit_id,
        t3.quasi_number,
        t3.goods_id_code,
        t1.batch_number,
        coalesce(sum(t5.outbound_count),0) as outbound_count,
        t1.warehousing_number,
        t2.create_time,
        t1.warehousing_number - coalesce(sum(t5.outbound_count),0) as num,
        t1.unit_amount as unitAmount,
        t1.sales_amount as salesAmount,
        t1.expiry_date
        from t_erp_clinic_warehousing_batch t1
        LEFT JOIN t_erp_clinic_warehousing t2 on t1.warehousing_id = t2.id
        LEFT JOIN t_erp_goods t3 on t1.goods_id = t3.id
        LEFT JOIN t_crm_supplier t4 on t3.supplier_clinic_id = t4.id
        LEFT JOIN t_erp_clinic_outbound_goods t5 on t5.warehousing_batch_id =t1.id
        where t2.disabled = 0  and t2.clinic_id =#{supplierClinicId}
        <if test="query.type != null and query.type ==1">
            and #{time} > t1.expiry_date
        </if>
        <if test="query.goodsName != null and query.goodsName != ''">
            and t3.goods_name like concat('%',#{query.goodsName},'%')
        </if>
        <if test="query.supplierName != null and query.supplierName != ''">
            and (t4.supplier_name like concat('%',#{query.supplierName},'%') or t3.supplier_name like concat('%',#{query.supplierName},'%'))
        </if>
 
        <if test="query.typeId != null and query.typeId != ''">
            and t3.type_id = #{query.typeId}
        </if>
        <if test="query.quasiNumber != null and query.quasiNumber != ''">
            and t3.quasi_number =#{query.quasiNumber}
        </if>
        <if test="query.batchNumber != null and query.batchNumber != ''">
            and t1.batch_number =#{query.batchNumber}
        </if>
        <if test="query.warehouseNo != null and query.warehouseNo != ''">
            and t2.warehouse_no = #{query.warehouseNo}
        </if>
        GROUP BY t1.id
        ) as o
        where (o.warehousing_number -o.outbound_count) >0
        order by o.create_time desc
    </select>
    <select id="pageInventoryGoodsList" resultType="com.ruoyi.system.vo.TErpGoodsInventoryVO">
        select * from (
        SELECT t1.id,t2.warehouse_no,
        t3.goods_name,
        t4.supplier_name,
        t3.type_id,
        t3.packing_unit_id,
        t3.quasi_number,
        t3.goods_id_code,
        t1.batch_number,
        coalesce(sum(t5.outbound_count),0) as outbound_count,
        t1.warehousing_number,
        t2.create_time,
        t1.warehousing_number - coalesce(sum(t5.outbound_count),0) as num,
        t2.unit_amount as sales_amount,
        t1.expiry_date
        from t_erp_supplier_warehousing_batch t1
        LEFT JOIN t_erp_supplier_warehousing t2 on t1.warehousing_id = t2.id
        LEFT JOIN t_erp_goods t3 on t2.goods_id = t3.id
        LEFT JOIN t_crm_supplier t4 on t3.supplier_clinic_id = t4.id
        left join (
        select warehousing_batch_id, sum(outbound_count) as outbound_count
        from t_erp_supplier_outbound_goods
        group by warehousing_batch_id
        ) t5 on t5.warehousing_batch_id =t1.id
        where t2.disabled = 0 and t2.warehouse_id = #{warehouseId}
        and #{endDate} > t1.expiry_date
        <if test="user.roleType !=null and user.roleType ==4">
            and t3.supplier_clinic_id =#{supplierClinicId} and t3.goods_source=1
        </if>
        <if test="user.roleType !=null and user.roleType ==5">
            and t3.supplier_clinic_id =#{supplierClinicId} and t3.goods_source=2
        </if>
 
        GROUP BY t1.id
        ) as o
        where (o.warehousing_number -o.outbound_count) >0
        order by o.create_time desc
    </select>
    <select id="pageInventoryGoodsList1" resultType="com.ruoyi.system.vo.TErpGoodsInventoryVO">
        select * from (
        SELECT t1.id,t2.warehouse_no,
        t3.goods_name,
        case t3.goods_source when 1 then t4.supplier_name when 2 then t3.supplier_name end as supplierName,
        t3.type_id,
        t3.packing_unit_id,
        t3.quasi_number,
        t3.goods_id_code,
        t1.batch_number,
        coalesce(sum(t5.outbound_count),0) as outbound_count,
        t1.warehousing_number,
        t2.create_time,
        t1.warehousing_number - coalesce(sum(t5.outbound_count),0) as num,
        t1.unit_amount as sales_amount,
        t1.expiry_date
        from t_erp_clinic_warehousing_batch t1
        LEFT JOIN t_erp_clinic_warehousing t2 on t1.warehousing_id = t2.id
        LEFT JOIN t_erp_goods t3 on t1.goods_id = t3.id
        LEFT JOIN t_crm_supplier t4 on t3.supplier_clinic_id = t4.id
        LEFT JOIN t_erp_clinic_outbound_goods t5 on t5.warehousing_batch_id =t1.id
        where t2.disabled = 0
        and #{endDate} > t1.expiry_date
        <if test="user.roleType !=null and user.roleType ==4">
            and t2.clinic_id =#{supplierClinicId}
        </if>
        <if test="user.roleType !=null and user.roleType ==5">
            and t2.clinic_id =#{supplierClinicId}
        </if>
 
        GROUP BY t1.id
        ) as o
        where o.num >0
        order by o.create_time desc
    </select>
    <select id="getGoodsById" resultType="com.ruoyi.system.model.TErpGoods">
        select <include refid="Base_Column_List"/> from t_erp_goods where id = #{goodsId}
    </select>
    <select id="pageAdminList" resultType="com.ruoyi.system.vo.TErpGoodsVO">
        select
        t1.id
        , t1.supplier_clinic_id, t1.goods_source, t1.goods_name, t1.goods_id_code, t1.quasi_number,t1.manufacturer, t1.formulation_spec, t1.packing_spec, t1.type_id, t1.goods_yards,
        t1.maintenance_interval,t1.maintenance_interval_unit, t1.low_purchase_quantity, t1.low_unit_id, t1.is_prescription_drug, t1.goods_spec, t1.warning_inventory,
        t1.sales_amount, t1.packing_unit_id, t1.instructions_use, t1.side_effect, t1.clinic_purchase_price, t1.platform_commission_price, t1.create_time, t1.update_time, t1.create_by,
        t1.`state`, t1.update_by, t1.disabled,
        t1.simplified_code,
        t1.dosage_form,
        t1.usage_classification,
        t1.product_brand,
        t1.place_of_origin,
        t1.ingredient,
        t1.trait,
        t1.indication,
        t1.taboo,
        t1.precautions,
        t1.interaction,
        t1.storage,
        t2.supplier_name
        from t_erp_goods t1 left join t_crm_supplier t2 on t1.supplier_clinic_id = t2.id and t1.goods_source =1
        where t1.disabled = 0 and t1.goods_source =1
        <if test="query.supplierName != null and query.supplierName != ''">
            and t2.supplier_name like concat('%',#{query.supplierName},'%')
        </if>
        <if test="query.goodsName != null and query.goodsName != ''">
            and t1.goods_name like concat('%',#{query.goodsName},'%')
        </if>
        <if test="query.typeId != null and query.typeId != ''">
            and t1.type_id = #{query.typeId}
        </if>
        <if test="query.quasiNumber != null and query.quasiNumber != ''">
            and t1.quasi_number like concat('%',#{query.quasiNumber},'%')
        </if>
        <if test="query.state != null ">
            and t1.state = #{query.state}
        </if>
        order by t1.create_time desc
    </select>
    <select id="pageAddList" resultType="com.ruoyi.system.model.TErpGoods">
        SELECT t1.id,
               t1.supplier_clinic_id,
               t1.goods_source,
               t1.goods_name,
               t1.goods_id_code,
               t1.quasi_number,
               t1.manufacturer,
               t1.formulation_spec,
               t1.packing_spec,
               t1.clinic_purchase_price,
               t1.warning_inventory,
               t1.type_id,
               t1.goods_yards,
               t1.maintenance_interval,
               t1.maintenance_interval_unit,
               t1.low_purchase_quantity,
               t1.low_unit_id,
               t1.is_prescription_drug,
               t1.goods_spec,
               t1.sales_amount,
               t1.packing_unit_id,
               t1.instructions_use,
               t1.side_effect,
               t1.platform_commission_price,
               t1.state,
               t1.simplified_code,
               t1.dosage_form,
               t1.usage_classification,
               t1.product_brand,
               t1.place_of_origin,
               t1.ingredient,
               t1.trait,
               t1.indication,
               t1.taboo,
               t1.precautions,
               t1.interaction,
               t1.storage,
               t1.barcode,
               t2.supplier_name,
               t1.clinic_ids,
               t1.create_by,
               t1.update_by,
               t1.`disabled`,
               t1.create_time,
               t1.update_time,
               t1.create_id,
               t3.type_name
        FROM t_erp_goods t1
         LEFT JOIN t_crm_supplier t2 ON t1.supplier_clinic_id = t2.id
        left join t_erp_goods_type t3 on t1.type_id = t3.id
        WHERE t1.`disabled` = 0
          AND (t1.goods_source = 1 AND t1.state = 1 AND t1.`disabled` = 0 AND t1.platform_commission_price IS NOT NULL)
          and (NOT FIND_IN_SET(#{clinicSupplierId}, t1.clinic_ids) or t1.clinic_ids is null)
        <if test="query.goodsName != null and query.goodsName != ''">
            and t1.goods_name like concat('%',#{query.goodsName},'%')
        </if>
        <if test="query.typeId != null and query.typeId != ''">
            and t1.type_id = #{query.typeId}
        </if>
        <if test="query.quasiNumber != null and query.quasiNumber != ''">
            and t1.quasi_number like concat('%',#{query.quasiNumber},'%')
        </if>
        <if test="query.quasiNumber != null and query.quasiNumber != ''">
            and t2.supplier_name like concat('%',#{query.supplierName},'%')
        </if>
        order by t1.create_time desc
 
 
    </select>
 
</mapper>