package com.ruoyi.equipmentenergyconsumption.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.equipmentenergyconsumption.pojo.EnergyPeriod; import com.ruoyi.equipmentenergyconsumption.service.EnergyPeriodService; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; import jakarta.servlet.http.HttpServletResponse; import lombok.AllArgsConstructor; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/energyPeriod") @Tag(name = "用电时段") @AllArgsConstructor public class EnergyPeriodController extends BaseController { private final EnergyPeriodService energyPeriodService; @GetMapping("/listPage") @Operation(summary = "用电时段-分页查询") @Log(title = "用电时段-分页查询", businessType = BusinessType.OTHER) public AjaxResult listPage(Page page, EnergyPeriod energyPeriod) { IPage listPage = energyPeriodService.listPage(page, energyPeriod); return AjaxResult.success(listPage); } @PostMapping("/add") @Operation(summary = "用电时段-新增") @Log(title = "用电时段-新增", businessType = BusinessType.INSERT) public AjaxResult add(@RequestBody EnergyPeriod energyPeriod) { boolean save = energyPeriodService.save(energyPeriod); return save ? AjaxResult.success() : AjaxResult.error(); } @PostMapping("/addBatch") @Operation(summary = "用电时段-批量新增") @Log(title = "用电时段-批量新增", businessType = BusinessType.INSERT) public AjaxResult addBatch(@RequestBody List energyPeriods) { boolean save = energyPeriodService.saveBatch(energyPeriods); return save ? AjaxResult.success() : AjaxResult.error(); } @PostMapping("/update") @Operation(summary = "用电时段-修改") @Log(title = "用电时段-修改", businessType = BusinessType.UPDATE) public AjaxResult update(@RequestBody EnergyPeriod energyPeriod) { boolean update = energyPeriodService.updateById(energyPeriod); return update ? AjaxResult.success() : AjaxResult.error(); } @DeleteMapping("/delete") @Operation(summary = "用电时段-删除") @Log(title = "用电时段-删除", businessType = BusinessType.DELETE) public AjaxResult delete(@RequestBody List ids) { if (CollectionUtils.isEmpty(ids)) return AjaxResult.error("请选择至少一条数据"); boolean remove = energyPeriodService.removeBatchByIds(ids); return remove ? AjaxResult.success() : AjaxResult.error("删除失败"); } /** * 导出用电时段 */ @Log(title = "导出用电时段", businessType = BusinessType.EXPORT) @PostMapping("/export") @Operation(summary = "导出用电时段") public void export(HttpServletResponse response) { Page page = new Page(-1, -1); EnergyPeriod energyPeriod = new EnergyPeriod(); IPage listPage = energyPeriodService.listPage(page, energyPeriod); ExcelUtil util = new ExcelUtil(EnergyPeriod.class); util.exportExcel(response, listPage.getRecords(), "用电时段数据"); } }