liujie
23 小时以前 c8e080d65e26158ea62c98548a11e9aa75c2112e
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
<?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.TErpClinicWarehousingMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.TErpClinicWarehousing">
        <id column="id" property="id" />
        <result column="procurement_id" property="procurementId" />
        <result column="clinic_id" property="clinicId" />
        <result column="goods_id" property="goodsId" />
        <result column="goods_name" property="goodsName" />
        <result column="supplier_name" property="supplierName" />
        <result column="quasi_number" property="quasiNumber" />
        <result column="sales_amount" property="salesAmount" />
        <result column="purchase_count" property="purchaseCount" />
        <result column="total_price" property="totalPrice" />
        <result column="warehousing_type" property="warehousingType" />
        <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, procurement_id, clinic_id, goods_id, goods_name, supplier_name, quasi_number, sales_amount, purchase_count, total_price, warehousing_type, create_time, update_time, create_by, update_by, disabled
    </sql>
    <select id="pageInventoryList" resultType="com.ruoyi.system.vo.PageInventoryListVo">
        select t1.id,t1.create_time,t2.user_name createBy,t3.warehouse_name
        from t_erp_clinic_inventory t1 left join sys_user t2 on t1.create_id = t2.user_id
        left join t_crm_warehouse t3 on t1.warehouse_id =t3.id
        where t1.disabled = 0
        <if test="user.roleType !=null and user.roleType ==5">
            and t1.clinic_id = #{supplierClinicId}
        </if>
        <if test="query.createBy != null and query.createBy != ''">
            and t2.user_name like concat('%',#{query.createBy},'%')
        </if>
        <if test="sTime != null and eTime !=null ">
            and t1.create_time between #{sTime} and #{eTime}
        </if>
        order by t1.create_time desc
    </select>
 
 
    <select id="validityPeriodWarning" resultType="com.ruoyi.system.vo.ValidityPeriodWarningVo">
        select t2.warehouse_no warehousingNo, t4.goods_name, t4.quasi_number, t1.batch_number, t1.id as batchId,t1.expiry_date, t4.id as goodsId,t5.type_name,t6.unit_name packingUnitName,
        case
        when t3.id is null then t1.warehousing_number
        else t1.warehousing_number -t3.outbound_count
        end as num
        from t_erp_clinic_warehousing_batch t1
        left join t_erp_clinic_warehousing t2 on t1.warehousing_id = t2.id
        LEFT JOIN t_erp_clinic_outbound_goods t3 on t3.warehousing_batch_id = t1.id
        LEFT JOIN t_erp_goods t4 on t2.goods_id = t4.id
        left join t_erp_goods_type t5 on t4.type_id = t5.id
        left join t_erp_goods_unit t6 on t4.packing_unit_id = t6.id
        where #{time} > t1.expiry_date
        and (t1.warehousing_number - t3.outbound_count > 0 or t3.id is null)
        <if test="user.roleType !=null and user.roleType ==5">
            and t2.clinic_id =#{supplierClinicId}
        </if>
        <if test="query.name != null and query.name != ''">
            and t4.goods_name like concat('%',#{query.goodsName},'%')
        </if>
        <if test="query.quasiNumber != null and query.quasiNumber != ''">
            and t4.quasi_number like concat('%',#{query.quasiNumber},'%')
        </if>
        <if test="query.batchNumber != null and query.batchNumber != ''">
            and t1.batch_number like concat('%',#{query.batchNumber},'%')
        </if>
        <if test="query.typeId != null and query.typeId != ''">
            and t4.type_id = #{query.typeId}
        </if>
        order by t1.expiry_date
 
    </select>
 
    <sql id="Base_Column_List1">
        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.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,
    </sql>
    <select id="pageList" resultType="com.ruoyi.system.vo.TErpGoodsVO">
        select * from (
        select <include refid="Base_Column_List1"/>
        COALESCE(sum(t2.purchase_count), 0) - COALESCE(sum(t3.outbound_count), 0) as allNum,
        SUM(t2.unit_amount * (t2.purchase_count - COALESCE(t3.outbound_count, 0))) as allTotalPrice,
 
        COALESCE(sum(t3.outbound_count), 0) as outNum
        from t_erp_goods t1  left join  t_erp_clinic_warehousing_batch t2  on t1.id = t2.goods_id
        left join  t_erp_clinic_outbound_goods t3 on t2.id = t3.warehousing_id
        where t1.disabled = 0 and t2.id is not null
        <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) )
        </if>
        GROUP BY t1.id
        ) o where 1=1
        <if test="query.type != null and query.type ==1">
            and  o.warning_inventory  > (o.allNum-o.outNum)
        </if>
        order by o.create_time desc
    </select>
 
    <select id="warehousePageList" resultType="com.ruoyi.system.vo.TErpClinicWarehousePageListVO">
        select t1.id,t1.warehouse_no,t2.supplier_name,t3.procurement_code,t3.pay_money allTotalPrice,t1.create_time warehouseTime,t1.type
        from t_erp_clinic_warehousing t1 left join t_erp_procurement t3 on t1.procurement_id = t3.id
        left join t_crm_supplier t2 on t3.supplier_id = t2.id
        where t1.disabled = 0 and t1.clinic_id = #{supplierClinicId}
        <if test="query.warehouseNo != null and query.warehouseNo != ''">
            and t1.warehouse_no like concat('%',#{query.warehouseNo},'%')
        </if>
        <if test="query.supplierName != null and query.supplierName != ''">
            and t2.supplier_name like concat('%',#{query.supplierName},'%')
        </if>
        <if test="sTime != null">
            and t1.create_time between #{sTime} and #{eTime}
        </if>
        <if test="query.type != null">
            and t1.type = #{query.type}
        </if>
        order by t1.create_time desc
 
    </select>
    <select id="outboundPageList" resultType="com.ruoyi.system.vo.TErpClinicOutboundPageListVO">
        select t1.id,t1.outbound_number,t1.order_number,t1.total_money allTotalPrice,t1.create_time ,t1.outbound_type,t2.user_name,t1.type_num
        from t_erp_clinic_outbound t1 left join sys_user t2 on t1.create_by = t2.user_id
        where t1.disabled = 0 and t1.clinic_id = #{query.supplierClinicId}
        <if test="query.outboundNumber != null and query.outboundNumber != ''">
            and t1.outbound_number like concat('%',#{query.outboundNumber},'%')
        </if>
        <if test="sTime != null">
            and t1.create_time between #{sTime} and #{eTime}
        </if>
        <if test="query.userName != null and query.userName !=''">
            and t2.user_name  like concat('%',#{query.userName},'%')
        </if>
        <if test="type != null">
            and t1.outbound_type = #{query.type}
        </if>
        order by t1.create_time desc
    </select>
    <select id="pageList1" resultType="com.ruoyi.system.vo.TErpGoodsVO">
        select * from (
        select <include refid="Base_Column_List1"/>
        COALESCE(sum(t2.purchase_count), 0) - COALESCE(sum(t3.outbound_count), 0) as allNum,
        SUM(t2.unit_amount * (t2.purchase_count - COALESCE(t3.outbound_count, 0))) as allTotalPrice,
 
        COALESCE(sum(t3.outbound_count), 0) as outNum
        from t_erp_goods t1  left join  t_erp_clinic_warehousing_batch t2  on t1.id = t2.goods_id
        left join  t_erp_clinic_outbound_goods t3 on t2.id = t3.warehousing_id
        where t1.disabled = 0 and t2.id is not null
         and   t1.goods_source =2 and  t1.supplier_clinic_id =#{query.supplierClinicId}
        GROUP BY t1.id
        ) o where 1=1
        <if test="query.type != null and query.type ==1">
            and  o.warning_inventory  > (o.allNum-o.outNum)
        </if>
        order by o.create_time desc
    </select>
 
</mapper>