2025-09-28 09:54:42 +08:00
|
|
|
|
package com.klp.ems.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Arrays;
|
2025-12-07 17:23:47 +08:00
|
|
|
|
import java.util.Map;
|
2025-09-28 09:54:42 +08:00
|
|
|
|
|
2025-09-28 23:51:47 +08:00
|
|
|
|
import com.klp.ems.domain.bo.EmsEnergyConsumptionQueryBo;
|
2025-09-30 18:46:57 +08:00
|
|
|
|
import com.klp.ems.domain.vo.*;
|
2025-09-28 09:54:42 +08:00
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import javax.validation.constraints.*;
|
2025-09-28 23:51:47 +08:00
|
|
|
|
|
|
|
|
|
|
import org.flywaydb.core.internal.util.StringUtils;
|
2025-09-28 09:54:42 +08:00
|
|
|
|
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;
|
|
|
|
|
|
|
2025-09-28 23:51:47 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 近期能耗趋势(测过了)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("/getEnergySummary")
|
|
|
|
|
|
public R getEnergySummary(EmsEnergyConsumptionQueryBo queryBo){
|
|
|
|
|
|
if (StringUtils.hasText(queryBo.getMonth())) {
|
2025-09-30 18:46:57 +08:00
|
|
|
|
List<SummaryDailyVo> data = iEmsEnergyConsumptionService.getEnergySummaryDailyFiltered(queryBo);
|
2025-09-28 23:51:47 +08:00
|
|
|
|
return R.ok(data);
|
|
|
|
|
|
}else if (StringUtils.hasText(queryBo.getYear())) {
|
2025-09-30 18:46:57 +08:00
|
|
|
|
List<SummaryMonthlyVo> data = iEmsEnergyConsumptionService.getEnergySummaryMonthlyFiltered(queryBo);
|
2025-09-28 23:51:47 +08:00
|
|
|
|
return R.ok(data);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return R.fail("year 或 month 必须提供一个");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取能耗环比概况(没写完)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("/getEnergyChainRatio")
|
2025-09-30 18:46:57 +08:00
|
|
|
|
public R<EnergyChainRatioVo> getEnergyChainRatio(EmsEnergyConsumptionQueryBo queryBo) {
|
|
|
|
|
|
EnergyChainRatioVo energyChainRatioVo = iEmsEnergyConsumptionService.getEnergyChainRatioFiltered(queryBo);
|
2025-09-28 23:51:47 +08:00
|
|
|
|
return R.ok(energyChainRatioVo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-30 18:46:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 同比分析: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));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-07 17:23:47 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取能耗统计信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("/statistics")
|
|
|
|
|
|
public R<Map<String, Object>> getStatistics(EmsEnergyConsumptionBo bo) {
|
|
|
|
|
|
return R.ok(iEmsEnergyConsumptionService.getStatistics(bo));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-28 09:54:42 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 查询能耗记录列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
@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));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-07 17:23:47 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取设备的上次抄表记录(用于自动填充起始数据)
|
|
|
|
|
|
* 如果是首次抄表,返回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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-28 09:54:42 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 新增能耗记录
|
|
|
|
|
|
*/
|
|
|
|
|
|
@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));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|