Files
klp-oa/klp-ems/src/main/java/com/klp/ems/controller/EmsEnergyConsumptionController.java

187 lines
6.6 KiB
Java
Raw Normal View History

package com.klp.ems.controller;
import java.util.List;
import java.util.Arrays;
import java.util.Map;
import com.klp.ems.domain.bo.EmsEnergyConsumptionQueryBo;
import com.klp.ems.domain.vo.*;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.flywaydb.core.internal.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.klp.common.annotation.RepeatSubmit;
import com.klp.common.annotation.Log;
import com.klp.common.core.controller.BaseController;
import com.klp.common.core.domain.PageQuery;
import com.klp.common.core.domain.R;
import com.klp.common.core.validate.AddGroup;
import com.klp.common.core.validate.EditGroup;
import com.klp.common.enums.BusinessType;
import com.klp.common.utils.poi.ExcelUtil;
import com.klp.ems.domain.bo.EmsEnergyConsumptionBo;
import com.klp.ems.service.IEmsEnergyConsumptionService;
import com.klp.common.core.page.TableDataInfo;
/**
* 能耗记录
*
* @author Joshi
* @date 2025-09-28
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ems/energyConsumption")
public class EmsEnergyConsumptionController extends BaseController {
private final IEmsEnergyConsumptionService iEmsEnergyConsumptionService;
/**
* 近期能耗趋势测过了
*/
@GetMapping("/getEnergySummary")
public R getEnergySummary(EmsEnergyConsumptionQueryBo queryBo){
if (StringUtils.hasText(queryBo.getMonth())) {
List<SummaryDailyVo> data = iEmsEnergyConsumptionService.getEnergySummaryDailyFiltered(queryBo);
return R.ok(data);
}else if (StringUtils.hasText(queryBo.getYear())) {
List<SummaryMonthlyVo> data = iEmsEnergyConsumptionService.getEnergySummaryMonthlyFiltered(queryBo);
return R.ok(data);
} else {
return R.fail("year 或 month 必须提供一个");
}
}
/**
* 获取能耗环比概况没写完
*/
@GetMapping("/getEnergyChainRatio")
public R<EnergyChainRatioVo> getEnergyChainRatio(EmsEnergyConsumptionQueryBo queryBo) {
EnergyChainRatioVo energyChainRatioVo = iEmsEnergyConsumptionService.getEnergyChainRatioFiltered(queryBo);
return R.ok(energyChainRatioVo);
}
/**
* 同比分析year 必填
*/
@GetMapping("/getYearOnYear")
public R<YearOnYearVo> getYearOnYear(EmsEnergyConsumptionQueryBo queryBo) {
return R.ok(iEmsEnergyConsumptionService.getYearOnYear(queryBo));
}
/**
* 环比分析periodType=day/week/month/year dateKey
*/
@GetMapping("/getChainAnalysis")
public R<ChainAnalysisVo> getChainAnalysis(EmsEnergyConsumptionQueryBo queryBo) {
return R.ok(iEmsEnergyConsumptionService.getChainAnalysis(queryBo));
}
/**
* 获取能耗统计信息
*/
@GetMapping("/statistics")
public R<Map<String, Object>> getStatistics(EmsEnergyConsumptionBo bo) {
return R.ok(iEmsEnergyConsumptionService.getStatistics(bo));
}
/**
* 查询能耗记录列表
*/
@GetMapping("/list")
public TableDataInfo<EmsEnergyConsumptionVo> list(EmsEnergyConsumptionBo bo, PageQuery pageQuery) {
return iEmsEnergyConsumptionService.queryPageList(bo, pageQuery);
}
/**
* 导出能耗记录列表
*/
@Log(title = "能耗记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(EmsEnergyConsumptionBo bo, HttpServletResponse response) {
List<EmsEnergyConsumptionVo> list = iEmsEnergyConsumptionService.queryList(bo);
ExcelUtil.exportExcel(list, "能耗记录", EmsEnergyConsumptionVo.class, response);
}
/**
* 获取能耗记录详细信息
*
* @param energyConsumptionId 主键
*/
@GetMapping("/{energyConsumptionId}")
public R<EmsEnergyConsumptionVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long energyConsumptionId) {
return R.ok(iEmsEnergyConsumptionService.queryById(energyConsumptionId));
}
/**
* 获取设备的上次抄表记录用于自动填充起始数据
* 如果是首次抄表返回null否则返回上次抄表的结束读数作为本次的起始读数
*
* @param meterId 设备ID
*/
@GetMapping("/lastReading/{meterId}")
public R<EmsEnergyConsumptionVo> getLastReading(@NotNull(message = "设备ID不能为空")
@PathVariable Long meterId) {
EmsEnergyConsumptionVo lastReading = iEmsEnergyConsumptionService.getLastReadingForMeter(meterId);
return R.ok(lastReading);
}
/**
* 获取设备本月的累计消耗量
*
* @param meterId 设备ID
*/
@GetMapping("/monthlyConsumption/{meterId}")
public R<Double> getMonthlyConsumption(@NotNull(message = "设备ID不能为空")
@PathVariable Long meterId) {
Double monthlyConsumption = iEmsEnergyConsumptionService.getMonthlyConsumption(meterId);
return R.ok(monthlyConsumption);
}
2025-12-09 16:43:45 +08:00
/**
* 获取最近一次抄表的时间范围
*/
@GetMapping("/latestMeterReadTime")
public R<com.klp.ems.domain.vo.LatestMeterReadTimeVo> getLatestMeterReadTime() {
com.klp.ems.domain.vo.LatestMeterReadTimeVo meterReadTime = iEmsEnergyConsumptionService.getLatestMeterReadTime();
return R.ok(meterReadTime);
}
/**
* 新增能耗记录
*/
@Log(title = "能耗记录", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody EmsEnergyConsumptionBo bo) {
return toAjax(iEmsEnergyConsumptionService.insertByBo(bo));
}
/**
* 修改能耗记录
*/
@Log(title = "能耗记录", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody EmsEnergyConsumptionBo bo) {
return toAjax(iEmsEnergyConsumptionService.updateByBo(bo));
}
/**
* 删除能耗记录
*
* @param energyConsumptionIds 主键串
*/
@Log(title = "能耗记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{energyConsumptionIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] energyConsumptionIds) {
return toAjax(iEmsEnergyConsumptionService.deleteWithValidByIds(Arrays.asList(energyConsumptionIds), true));
}
}