maven
2025-11-24 3e451c90f8734835743e9cebcf02ce30e577c28d
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
package com.ruoyi.device.mapper;
 
 
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.device.dto.DeviceMaintenanceDto;
import com.ruoyi.device.dto.DeviceRepairDto;
import com.ruoyi.device.dto.RepairAmountGroupDTO;
import com.ruoyi.device.pojo.DeviceMaintenance;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
import java.util.List;
 
@Mapper
public interface DeviceMaintenanceMapper extends BaseMapper<DeviceMaintenance> {
 
    IPage<DeviceMaintenanceDto> queryPage(Page page, DeviceMaintenanceDto deviceMaintenanceDto);
 
    DeviceMaintenanceDto detailById(Long id);
 
    @InterceptorIgnore(tenantLine = "true")
    List<DeviceMaintenance> list1(Long id);
 
    /**
     * 按“指定年份的年月+设备台账id”分组,求和报修金额
     * @param year 前端传入的年份(如"2025")
     */
    @Select("SELECT " +
            "  DATE_FORMAT(maintenance_actually_time, '%m') AS repairYearMonth, " +
            "  device_ledger_id AS deviceLedgerId, " +
            "  SUM(maintenance_price) AS totalRepairPrice " +
            "FROM device_maintenance " +
            "WHERE DATE_FORMAT(maintenance_actually_time, '%Y') = #{year} " + // 只查询指定年份的数据
            "GROUP BY device_ledger_id,DATE_FORMAT(maintenance_actually_time, '%Y-%m')  " +
            "ORDER BY repairYearMonth ASC") // 按月份排序,方便前端展示
    List<RepairAmountGroupDTO> groupByMonthAndDeviceLedger(@Param("year") String year);
 
    /**
     * 按“设备台账id”分组,求和报修金额
     * @param year 前端传入的年份(如"2025")
     */
    @Select("SELECT " +
            "  device_ledger_id AS deviceLedgerId, " +
            "  SUM(maintenance_price) AS totalRepairPrice " +
            "FROM device_maintenance " +
            "WHERE DATE_FORMAT(maintenance_actually_time, '%Y') = #{year} " + // 只查询指定年份的数据
            "GROUP BY device_ledger_id ") // 按月份排序,方便前端展示
    List<RepairAmountGroupDTO> groupByDeviceLedger(@Param("year") String year);
 
}