xuhy
2025-10-13 782cef1a49bb665fd88f3850a9193c08d63ef1d5
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
<?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.TErpProcurementMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.TErpProcurement">
        <id column="id" property="id" />
        <result column="clinic_id" property="clinicId" />
        <result column="procurement_code" property="procurementCode" />
        <result column="pay_money" property="payMoney" />
        <result column="pay_number" property="payNumber" />
        <result column="pay_transaction_id" property="payTransactionId" />
        <result column="status" property="status" />
        <result column="supplier_money" property="supplierMoney" />
        <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, clinic_id, procurement_code, pay_money, pay_number, pay_transaction_id, status, create_time, update_time, create_by, update_by, disabled
    </sql>
    <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.TErpProcurementVo">
        select t1.id,
        t1.procurement_code,
        t1.clinic_id,
        t3.supplier_name,
        sum(t2.total_price) as totalPrice,
        t1.create_time,
        t2.id tErpProcurementGoodsId,
        t4.user_name,
        t1.status
        from t_erp_procurement t1
        left JOIN t_erp_procurement_goods t2 on t1.id = t2.procurement_id
        LEFT JOIN t_crm_supplier t3 on t1.supplier_id = t3.id
        left JOIN sys_user t4 on t1.create_id = t4.user_id
        where t1.disabled = 0 and t1.status !=1
        <if test="user.roleType !=null and user.roleType==4">
            and t2.supplier_id =#{supplierClinicId}
        </if>
        <if test="query.procurementCode != null and query.procurementCode != ''">
            and t1.procurement_code = #{query.procurementCode}
        </if>
        <if test="query.clinicName != null and query.clinicName != ''">
            and t3.supplier_name like concat('%',#{query.clinicName},'%')
        </if>
        <if test="query.userName != null and query.userName != ''">
            and t4.user_name like concat('%',#{query.userName},'%')
        </if>
        <if test="query.status != null">
            and t1.status = #{query.status}
        </if>
        <if test="sTime != null">
            and t1.create_time between #{sTime} and #{eTime}
        </if>
        group by t1.id
 
    </select>
    <select id="inventoryNotEnoughList" resultType="com.ruoyi.system.vo.TErpGoodsVO">
        select * from (
        select <include refid="Base_Column_List1"/>
        COALESCE(sum(t2.goods_count), 0) - COALESCE(sum(t3.outbound_count), 0) as allNum,
        SUM(t2.unit_amount * (t2.goods_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_supplier_warehousing t2  on t1.id = t2.goods_id
        left join  t_erp_supplier_outbound_goods t3 on t2.id = t3.warehousing_id
        where t1.disabled = 0 and t2.id is not null and t1.goods_source =1 and t1.clinic_purchase_price is not null
        GROUP BY t1.id
        ) o where 1=1
        and  o.warning_inventory  > (o.allNum-o.outNum)
        order by o.create_time desc
    </select>
    <select id="pageListWarehouse" resultType="com.ruoyi.system.vo.TErpProcurementVo">
        select t1.id,
               t1.procurement_code,
               t2.clinic_name,
               t2.clinic_address,
               t1.logistics_number,
                t1.send_time,
               t1.clinic_id,
               t1.status
               from t_erp_procurement t1
               left JOIN t_crm_clinic t2 on t1.clinic_id = t2.id
        where t1.disabled = 0 and t1.status in(3,4,5) and t1.supplier_id =#{supplierClinicId}
        <if test="query.procurementCode != null and query.procurementCode != ''">
            and t1.procurement_code = #{query.procurementCode}
        </if>
        <if test="query.clinicName != null and query.clinicName != ''">
            and t2.clinic_name like concat('%',#{query.clinicName},'%')
        </if>
        <if test="query.logisticsNo != null and query.logisticsNo != ''">
            and t1.logistics_number = #{query.logisticsNo}
        </if>
        <if test="sTime != null and eTime != ''">
            and t1.create_time between #{sTime} and #{eTime}
        </if>
        <if test="query.status != null">
            and t1.status = #{query.status}
        </if>
 
 
    </select>
    <select id="supplierThirtyProcurementStatistics"
            resultType="com.ruoyi.system.vo.SupplierThirtyProcurementStatisticsVO">
        select
        date_format(t1.pay_time, '%m.%d') as `time`,
        date_format(t1.pay_time, '%Y-%m-%d') as payTime,
        count(1) as orderCount
        from t_erp_procurement t1
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        and t1.status in (3,4,5)
        and t1.pay_time between #{startTime} and #{endTime}
        <if test="query.roleType != null and query.roleType == 4">
            and t1.supplier_id = #{supplierAndClinicId}
        </if>
        <if test="query.roleType != null and query.roleType == 5">
            and t1.clinic_id = #{supplierAndClinicId}
        </if>
        group by date_format(t1.pay_time, '%m.%d')
    </select>
    <select id="supplierThirtyMoneyProcurementStatistics"
            resultType="com.ruoyi.system.vo.SupplierThirtyMoneyProcurementStatisticsVO">
        select
            date_format(t1.pay_time, '%m.%d') as `time`,
            date_format(t1.pay_time, '%Y-%m-%d') as payTime,
            sum(t1.pay_money) as moneyTotal
        from t_erp_procurement t1
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            and t1.status in (3,4,5)
            and t1.pay_time between #{startTime} and #{endTime}
            <if test="query.roleType != null and query.roleType == 4">
                and t1.supplier_id = #{supplierAndClinicId}
            </if>
            <if test="query.roleType != null and query.roleType == 5">
                and t1.clinic_id = #{supplierAndClinicId}
            </if>
        group by date_format(t1.pay_time, '%m.%d')
    </select>
 
</mapper>