maven
2025-11-19 72a372cb26c4ba489efae6b65dbf9fdfea1b5815
src/main/java/com/ruoyi/device/mapper/DeviceMaintenanceMapper.java
@@ -7,8 +7,11 @@
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;
@@ -21,4 +24,31 @@
    @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);
}