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

165 lines
6.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.klp.ems.controller;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
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.vo.EmsEnergyRateVo;
import com.klp.ems.domain.vo.EmsRateTierVo;
import com.klp.ems.domain.vo.EmsRateTimePeriodLinkVo;
import com.klp.ems.domain.bo.EmsEnergyRateBo;
import com.klp.ems.domain.bo.EmsRateTierBo;
import com.klp.ems.domain.bo.EmsRateTimePeriodLinkBo;
import com.klp.ems.domain.bo.EmsRateTierPeriodLinkBo;
import com.klp.ems.service.IEmsEnergyRateService;
import com.klp.common.core.page.TableDataInfo;
/**
* 能源费率
* 支持:固定费率、峰谷分时、阶梯电价、峰谷+阶梯组合
*
* @author Joshi
* @date 2025-09-28
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ems/energyRate")
public class EmsEnergyRateController extends BaseController {
private final IEmsEnergyRateService iEmsEnergyRateService;
/**
* 查询能源费率currency 为 INT0=CNY,1=USD,2=EUR列表
*/
@GetMapping("/list")
public TableDataInfo<EmsEnergyRateVo> list(EmsEnergyRateBo bo, PageQuery pageQuery) {
return iEmsEnergyRateService.queryPageList(bo, pageQuery);
}
/**
* 导出能源费率currency 为 INT0=CNY,1=USD,2=EUR列表
*/
@Log(title = "能源费率currency 为 INT0=CNY,1=USD,2=EUR", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(EmsEnergyRateBo bo, HttpServletResponse response) {
List<EmsEnergyRateVo> list = iEmsEnergyRateService.queryList(bo);
ExcelUtil.exportExcel(list, "能源费率currency 为 INT0=CNY,1=USD,2=EUR", EmsEnergyRateVo.class, response);
}
/**
* 获取能源费率currency 为 INT0=CNY,1=USD,2=EUR详细信息
*
* @param energyRateId 主键
*/
@GetMapping("/{energyRateId}")
public R<EmsEnergyRateVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long energyRateId) {
return R.ok(iEmsEnergyRateService.queryById(energyRateId));
}
/**
* 新增能源费率currency 为 INT0=CNY,1=USD,2=EUR
*/
@Log(title = "能源费率currency 为 INT0=CNY,1=USD,2=EUR", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody EmsEnergyRateBo bo) {
return toAjax(iEmsEnergyRateService.insertByBo(bo));
}
/**
* 修改能源费率currency 为 INT0=CNY,1=USD,2=EUR
*/
@Log(title = "能源费率currency 为 INT0=CNY,1=USD,2=EUR", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody EmsEnergyRateBo bo) {
return toAjax(iEmsEnergyRateService.updateByBo(bo));
}
/**
* 删除能源费率(级联删除梯度和时段费率)
*
* @param energyRateIds 主键串
*/
@Log(title = "能源费率", businessType = BusinessType.DELETE)
@DeleteMapping("/{energyRateIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] energyRateIds) {
return toAjax(iEmsEnergyRateService.deleteWithValidByIds(Arrays.asList(energyRateIds), true));
}
/**
* 获取费率的梯度费率列表
*/
@GetMapping("/{energyRateId}/tiers")
public R<List<EmsRateTierVo>> getRateTiers(@NotNull(message = "费率ID不能为空")
@PathVariable Long energyRateId) {
return R.ok(iEmsEnergyRateService.getRateTiers(energyRateId));
}
/**
* 获取费率的时段费率列表
*/
@GetMapping("/{energyRateId}/timePeriods")
public R<List<EmsRateTimePeriodLinkVo>> getRateTimePeriods(@NotNull(message = "费率ID不能为空")
@PathVariable Long energyRateId) {
return R.ok(iEmsEnergyRateService.getRateTimePeriods(energyRateId));
}
/**
* 保存梯度费率返回保存后的梯度列表包含tierId
*/
@Log(title = "能源费率梯度", businessType = BusinessType.UPDATE)
@PostMapping("/{energyRateId}/tiers")
public R<List<EmsRateTierVo>> saveTiers(@NotNull(message = "费率ID不能为空") @PathVariable Long energyRateId,
@RequestBody List<EmsRateTierBo> tiers) {
return R.ok(iEmsEnergyRateService.saveTiers(energyRateId, tiers));
}
/**
* 保存时段费率
*/
@Log(title = "能源费率时段", businessType = BusinessType.UPDATE)
@PostMapping("/{energyRateId}/timePeriods")
public R<Void> saveTimePeriods(@NotNull(message = "费率ID不能为空") @PathVariable Long energyRateId,
@RequestBody List<EmsRateTimePeriodLinkBo> timePeriods) {
return toAjax(iEmsEnergyRateService.saveTimePeriods(energyRateId, timePeriods));
}
/**
* 获取梯度的峰谷时段费率(用于梯度+峰谷组合模式)
*/
@GetMapping("/{energyRateId}/tier/{tierId}/periods")
public R<List<EmsRateTierPeriodLinkBo>> getTierPeriodLinks(@NotNull(message = "费率ID不能为空") @PathVariable Long energyRateId,
@NotNull(message = "梯度ID不能为空") @PathVariable Long tierId) {
// 返回该梯度对应的所有时段费率
return R.ok(iEmsEnergyRateService.getTierPeriodLinks(tierId));
}
/**
* 保存梯度-时段关联费率(用于梯度+峰谷组合模式)
*/
@Log(title = "梯度-时段关联费率", businessType = BusinessType.UPDATE)
@PostMapping("/{energyRateId}/tier/{tierId}/periods")
public R<Void> saveTierPeriodLinks(@NotNull(message = "费率ID不能为空") @PathVariable Long energyRateId,
@NotNull(message = "梯度ID不能为空") @PathVariable Long tierId,
@RequestBody List<EmsRateTierPeriodLinkBo> tierPeriodLinks) {
return toAjax(iEmsEnergyRateService.saveTierPeriodLinks(tierId, tierPeriodLinks));
}
}