119 分钟以前 55d694aaae4e421b5e55cd941500e08f85cb5d4d
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
<?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.device.mapper.DeviceLedgerMapper">
 
    <select id="queryPage" resultType="com.ruoyi.device.dto.DeviceLedgerDto">
        SELECT
        dl.id,
        dl.device_name,
        dl.device_model,
        dl.supplier_name,
        dl.device_brand,
        dl.storage_location,
        dl.unit,
        dl.number,
        dl.status,
        dl.plan_runtime_time,
        dl.start_runtime_time,
        dl.end_runtime_time,
        dl.runtime_duration,
        dl.tax_including_price_unit,
        dl.tax_including_price_total,
        dl.tax_rate,
        dl.un_tax_including_price_total,
        dl.create_time,
        dl.update_time ,
        su.nick_name AS createUser,
        dl.update_user,
        dl.tenant_id,
        dl.is_depr,
        dl.annual_depreciation_amount,
        dl.type,
        dl.area_id,
        da.name AS area_name
        FROM device_ledger dl
        left join sys_user su on dl.create_user = su.user_id
        left join device_area da on dl.area_id = da.id
        <where>
            <!-- 设备名称 -->
            <if test="deviceLedger.deviceName != null and deviceLedger.deviceName != ''">
                AND device_name LIKE CONCAT('%', #{deviceLedger.deviceName}, '%')
            </if>
 
            <!-- 规格型号 -->
            <if test="deviceLedger.deviceModel != null and deviceLedger.deviceModel != ''">
                AND device_model LIKE CONCAT('%', #{deviceLedger.deviceModel}, '%')
            </if>
 
            <!-- 供应商名称 -->
            <if test="deviceLedger.supplierName != null and deviceLedger.supplierName != ''">
                AND supplier_name LIKE CONCAT('%', #{deviceLedger.supplierName}, '%')
            </if>
 
            <!-- 单位 -->
            <if test="deviceLedger.unit != null and deviceLedger.unit != ''">
                AND unit = #{deviceLedger.unit}
            </if>
 
            <!-- 录入人 -->
            <if test="deviceLedger.createUser != null and deviceLedger.createUser != ''">
                AND create_user LIKE CONCAT('%', #{deviceLedger.createUser}, '%')
            </if>
 
            <!-- 更新人 -->
            <if test="deviceLedger.updateUser != null and deviceLedger.updateUser != ''">
                AND update_user LIKE CONCAT('%', #{deviceLedger.updateUser}, '%')
            </if>
 
            <if test="deviceLedger.entryDateStart != null and deviceLedger.entryDateStart != '' ">
                AND dl.create_time &gt;= DATE_FORMAT(#{deviceLedger.entryDateStart},'%Y-%m-%d')
            </if>
            <if test="deviceLedger.entryDateEnd != null and deviceLedger.entryDateEnd != '' ">
                AND dl.create_time &lt;= DATE_FORMAT(#{deviceLedger.entryDateEnd},'%Y-%m-%d')
            </if>
 
            <!-- 租户ID -->
            <if test="deviceLedger.tenantId != null">
                AND tenant_id = #{deviceLedger.tenantId}
            </if>
 
            <!-- 区域ID:含该区域及其所有子级(通过祖级路径匹配) -->
            <if test="deviceLedger.areaId != null">
                AND (
                    dl.area_id = #{deviceLedger.areaId}
                    OR EXISTS (
                        SELECT 1 FROM device_area da2
                        WHERE da2.id = dl.area_id
                          AND (da2.ancestors = #{deviceLedger.areaId}
                               OR da2.ancestors LIKE CONCAT(#{deviceLedger.areaId}, ',%')
                               OR da2.ancestors LIKE CONCAT('%,', #{deviceLedger.areaId}, ',%')
                               OR da2.ancestors LIKE CONCAT('%,', #{deviceLedger.areaId}))
                    )
                )
            </if>
        </where>
        ORDER BY create_time DESC
    </select>
    <select id="selectDeviceOptions" resultType="com.ruoyi.device.dto.DeviceLedgerDto">
        SELECT
        dl.id,
        dl.device_name,
        dl.device_model,
        dl.device_brand,
        dl.type,
        dl.area_id,
        da.name AS area_name
        FROM device_ledger dl
        left join device_area da on dl.area_id = da.id
        <where>
            <if test="areaId != null">
                AND (
                    dl.area_id = #{areaId}
                    OR EXISTS (
                        SELECT 1 FROM device_area da2
                        WHERE da2.id = dl.area_id
                          AND (da2.ancestors = #{areaId}
                               OR da2.ancestors LIKE CONCAT(#{areaId}, ',%')
                               OR da2.ancestors LIKE CONCAT('%,', #{areaId}, ',%')
                               OR da2.ancestors LIKE CONCAT('%,', #{areaId}))
                    )
                )
            </if>
        </where>
        ORDER BY dl.create_time DESC
    </select>
 
    <select id="deviceLedgerExportList" resultType="com.ruoyi.device.execl.DeviceLedgerExeclDto">
 
    </select>
    <select id="selectById1" resultType="com.ruoyi.device.pojo.DeviceLedger">
        select *
        from device_ledger
        where id = #{id}
    </select>
    <select id="getDeviceTypeDistributionByYear"
            resultType="com.ruoyi.account.bean.dto.DeviceTypeDetail"
            parameterType="java.lang.Integer">
        SELECT
            `type`,
            SUM(`number`) AS `count`,
            SUM(tax_including_price_unit) AS amount
        FROM device_ledger
        WHERE YEAR(create_time) = #{year}
          AND type IS NOT NULL
        GROUP BY type
    </select>
 
 
</mapper>