From d8d0a83c87f038b2695055cd487adb68cf9bf853 Mon Sep 17 00:00:00 2001 From: mashili Date: Thu, 9 Oct 2025 19:58:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E4=BB=B7=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ems/EmsEnergyPriceConfigController.java | 89 ++++++++ .../xzzn/ems/domain/EmsEnergyPriceConfig.java | 134 ++++++++++++ .../xzzn/ems/domain/EmsPriceTimeConfig.java | 102 +++++++++ .../ems/domain/vo/EnergyPriceTimeRange.java | 45 ++++ .../com/xzzn/ems/domain/vo/EnergyPriceVo.java | 99 +++++++++ .../mapper/EmsEnergyPriceConfigMapper.java | 69 ++++++ .../ems/mapper/EmsPriceTimeConfigMapper.java | 70 +++++++ .../service/IEmsEnergyPriceConfigService.java | 61 ++++++ .../impl/EmsEnergyPriceConfigServiceImpl.java | 198 ++++++++++++++++++ .../mapper/ems/EmsEnergyPriceConfigMapper.xml | 151 +++++++++++++ .../mapper/ems/EmsPriceTimeConfigMapper.xml | 127 +++++++++++ 11 files changed, 1145 insertions(+) create mode 100644 ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsEnergyPriceConfigController.java create mode 100644 ems-system/src/main/java/com/xzzn/ems/domain/EmsEnergyPriceConfig.java create mode 100644 ems-system/src/main/java/com/xzzn/ems/domain/EmsPriceTimeConfig.java create mode 100644 ems-system/src/main/java/com/xzzn/ems/domain/vo/EnergyPriceTimeRange.java create mode 100644 ems-system/src/main/java/com/xzzn/ems/domain/vo/EnergyPriceVo.java create mode 100644 ems-system/src/main/java/com/xzzn/ems/mapper/EmsEnergyPriceConfigMapper.java create mode 100644 ems-system/src/main/java/com/xzzn/ems/mapper/EmsPriceTimeConfigMapper.java create mode 100644 ems-system/src/main/java/com/xzzn/ems/service/IEmsEnergyPriceConfigService.java create mode 100644 ems-system/src/main/java/com/xzzn/ems/service/impl/EmsEnergyPriceConfigServiceImpl.java create mode 100644 ems-system/src/main/resources/mapper/ems/EmsEnergyPriceConfigMapper.xml create mode 100644 ems-system/src/main/resources/mapper/ems/EmsPriceTimeConfigMapper.xml diff --git a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsEnergyPriceConfigController.java b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsEnergyPriceConfigController.java new file mode 100644 index 0000000..e8818d2 --- /dev/null +++ b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsEnergyPriceConfigController.java @@ -0,0 +1,89 @@ +package com.xzzn.web.controller.ems; + +import java.util.List; + +import com.xzzn.ems.domain.vo.EnergyPriceVo; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.xzzn.common.annotation.Log; +import com.xzzn.common.core.controller.BaseController; +import com.xzzn.common.core.domain.AjaxResult; +import com.xzzn.common.enums.BusinessType; +import com.xzzn.ems.service.IEmsEnergyPriceConfigService; +import com.xzzn.common.core.page.TableDataInfo; + +/** + * 电价配置Controller + * + * @author xzzn + * @date 2025-09-28 + */ +@RestController +@RequestMapping("/ems/energyPriceConfig") +public class EmsEnergyPriceConfigController extends BaseController +{ + @Autowired + private IEmsEnergyPriceConfigService emsEnergyPriceConfigService; + + /** + * 查询电价配置列表 + */ + @PreAuthorize("@ss.hasPermi('system:config:list')") + @GetMapping("/list") + public TableDataInfo list() + { + List list = emsEnergyPriceConfigService.selectEmsEnergyPriceConfigList(); + return getDataTable2(list); + } + + /** + * 获取电价配置详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:config:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(emsEnergyPriceConfigService.selectEmsEnergyPriceConfigById(id)); + } + + /** + * 新增电价配置 + */ + @PreAuthorize("@ss.hasPermi('system:config:add')") + @Log(title = "电价配置", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody EnergyPriceVo priceVo) + { + return toAjax(emsEnergyPriceConfigService.insertEmsEnergyPriceConfig(priceVo)); + } + + /** + * 修改电价配置 + */ + @PreAuthorize("@ss.hasPermi('system:config:edit')") + @Log(title = "电价配置", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody EnergyPriceVo priceVo) + { + return toAjax(emsEnergyPriceConfigService.updateEmsEnergyPriceConfig(priceVo)); + } + + /** + * 删除电价配置 + */ + @PreAuthorize("@ss.hasPermi('system:config:remove')") + @Log(title = "电价配置", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(emsEnergyPriceConfigService.deleteEmsEnergyPriceConfigByIds(ids)); + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/EmsEnergyPriceConfig.java b/ems-system/src/main/java/com/xzzn/ems/domain/EmsEnergyPriceConfig.java new file mode 100644 index 0000000..c4c45c1 --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/domain/EmsEnergyPriceConfig.java @@ -0,0 +1,134 @@ +package com.xzzn.ems.domain; + +import java.math.BigDecimal; + +import com.xzzn.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.xzzn.common.annotation.Excel; + +/** + * 电价配置对象 ems_energy_price_config + * + * @author xzzn + * @date 2025-10-09 + */ +public class EmsEnergyPriceConfig extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** */ + private Long id; + + /** 年份,如2025 */ + @Excel(name = "年份,如2025") + private String year; + + /** 月份,如"9"表示9月 */ + @Excel(name = "月份,如\"9\"表示9月") + private String month; + + /** 尖-peak电价(元/kWh) */ + @Excel(name = "尖-peak电价(元/kWh)") + private BigDecimal peak; + + /** 峰-high电价(元/kWh) */ + @Excel(name = "峰-high电价(元/kWh)") + private BigDecimal high; + + /** 平-flat电价(元/kWh) */ + @Excel(name = "平-flat电价(元/kWh)") + private BigDecimal flat; + + /** 谷-valley电价(元/kWh) */ + @Excel(name = "谷-valley电价(元/kWh)") + private BigDecimal valley; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setYear(String year) + { + this.year = year; + } + + public String getYear() + { + return year; + } + + public void setMonth(String month) + { + this.month = month; + } + + public String getMonth() + { + return month; + } + + public void setPeak(BigDecimal peak) + { + this.peak = peak; + } + + public BigDecimal getPeak() + { + return peak; + } + + public void setHigh(BigDecimal high) + { + this.high = high; + } + + public BigDecimal getHigh() + { + return high; + } + + public void setFlat(BigDecimal flat) + { + this.flat = flat; + } + + public BigDecimal getFlat() + { + return flat; + } + + public void setValley(BigDecimal valley) + { + this.valley = valley; + } + + public BigDecimal getValley() + { + return valley; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("year", getYear()) + .append("month", getMonth()) + .append("peak", getPeak()) + .append("high", getHigh()) + .append("flat", getFlat()) + .append("valley", getValley()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/EmsPriceTimeConfig.java b/ems-system/src/main/java/com/xzzn/ems/domain/EmsPriceTimeConfig.java new file mode 100644 index 0000000..2bdc7ab --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/domain/EmsPriceTimeConfig.java @@ -0,0 +1,102 @@ +package com.xzzn.ems.domain; + +import com.xzzn.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.xzzn.common.annotation.Excel; + +/** + * 电价时间配置对象 ems_price_time_config + * + * @author xzzn + * @date 2025-10-09 + */ +public class EmsPriceTimeConfig extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** */ + private Long id; + + /** 时段开始时间 */ + @Excel(name = "时段开始时间") + private String startTime; + + /** 时段结束时间 */ + @Excel(name = "时段结束时间") + private String endTime; + + /** 电价类型: 尖-peak,峰-high,平-flat,谷-valley */ + @Excel(name = "电价类型: 尖-peak,峰-high,平-flat,谷-valley") + private String costType; + + /** 电价配置id */ + @Excel(name = "电价配置id") + private Long priceId; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setStartTime(String startTime) + { + this.startTime = startTime; + } + + public String getStartTime() + { + return startTime; + } + + public void setEndTime(String endTime) + { + this.endTime = endTime; + } + + public String getEndTime() + { + return endTime; + } + + public void setCostType(String costType) + { + this.costType = costType; + } + + public String getCostType() + { + return costType; + } + + public void setPriceId(Long priceId) + { + this.priceId = priceId; + } + + public Long getPriceId() + { + return priceId; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("startTime", getStartTime()) + .append("endTime", getEndTime()) + .append("costType", getCostType()) + .append("priceId", getPriceId()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/vo/EnergyPriceTimeRange.java b/ems-system/src/main/java/com/xzzn/ems/domain/vo/EnergyPriceTimeRange.java new file mode 100644 index 0000000..eff9d04 --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/domain/vo/EnergyPriceTimeRange.java @@ -0,0 +1,45 @@ +package com.xzzn.ems.domain.vo; + +import com.xzzn.common.annotation.Excel; + +/** + * 电价配置-电价列表-电价范围 + * + */ +public class EnergyPriceTimeRange { + /** 时段开始时间 */ + @Excel(name = "时段开始时间") + private String startTime; + + /** 时段结束时间 */ + @Excel(name = "时段结束时间") + private String endTime; + + /** 电价类型: 尖-peak,峰-high,平-flat,谷=valley */ + @Excel(name = "电价类型: 尖-peak,峰-high,平-flat,谷=valley") + private String costType; + + public String getCostType() { + return costType; + } + + public void setCostType(String costType) { + this.costType = costType; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/vo/EnergyPriceVo.java b/ems-system/src/main/java/com/xzzn/ems/domain/vo/EnergyPriceVo.java new file mode 100644 index 0000000..4614dca --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/domain/vo/EnergyPriceVo.java @@ -0,0 +1,99 @@ +package com.xzzn.ems.domain.vo; + +import com.xzzn.common.annotation.Excel; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 电价配置-电价列表-对象 + * + */ +public class EnergyPriceVo { + /** */ + private Long id; + /** 年份 */ + @Excel(name = "年份") + private String year; + /** 月份,如"9"表示9月 */ + @Excel(name = "月份,如\"9\"表示9月") + private String month; + /** 尖电价(元/kWh) */ + @Excel(name = "尖电价(元/kWh)") + private BigDecimal peak; + /** 峰电价(元/kWh) */ + @Excel(name = "峰电价(元/kWh)") + private BigDecimal high; + /** 平电价(元/kWh) */ + @Excel(name = "平电价(元/kWh)") + private BigDecimal flat; + /** 谷电价(元/kWh) */ + @Excel(name = "谷电价(元/kWh)") + private BigDecimal valley; + /** 电价时间范围对象 */ + private List range; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getYear() { + return year; + } + + public void setYear(String year) { + this.year = year; + } + + public String getMonth() { + return month; + } + + public void setMonth(String month) { + this.month = month; + } + + public BigDecimal getPeak() { + return peak; + } + + public void setPeak(BigDecimal peak) { + this.peak = peak; + } + + public BigDecimal getHigh() { + return high; + } + + public void setHigh(BigDecimal high) { + this.high = high; + } + + public BigDecimal getFlat() { + return flat; + } + + public void setFlat(BigDecimal flat) { + this.flat = flat; + } + + public BigDecimal getValley() { + return valley; + } + + public void setValley(BigDecimal valley) { + this.valley = valley; + } + + public List getRange() { + return range; + } + + public void setRange(List range) { + this.range = range; + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/mapper/EmsEnergyPriceConfigMapper.java b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsEnergyPriceConfigMapper.java new file mode 100644 index 0000000..8609ff3 --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsEnergyPriceConfigMapper.java @@ -0,0 +1,69 @@ +package com.xzzn.ems.mapper; + +import java.util.List; + +import com.xzzn.ems.domain.EmsEnergyPriceConfig; +import org.apache.ibatis.annotations.Param; + +/** + * 电价配置Mapper接口 + * + * @author xzzn + * @date 2025-09-28 + */ +public interface EmsEnergyPriceConfigMapper +{ + /** + * 查询电价配置 + * + * @param id 电价配置主键 + * @return 电价配置 + */ + public EmsEnergyPriceConfig selectEmsEnergyPriceConfigById(Long id); + + /** + * 查询当年电价配置列表 + * + * @return 电价配置集合 + */ + public List selectEmsEnergyPriceConfigList(int currentYear); + + /** + * 新增电价配置 + * + * @param emsEnergyPriceConfig 电价配置 + * @return 结果 + */ + public int insertEmsEnergyPriceConfig(EmsEnergyPriceConfig emsEnergyPriceConfig); + + /** + * 修改电价配置 + * + * @param emsEnergyPriceConfig 电价配置 + * @return 结果 + */ + public int updateEmsEnergyPriceConfig(EmsEnergyPriceConfig emsEnergyPriceConfig); + + /** + * 删除电价配置 + * + * @param id 电价配置主键 + * @return 结果 + */ + public int deleteEmsEnergyPriceConfigById(Long id); + + /** + * 批量删除电价配置 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteEmsEnergyPriceConfigByIds(Long[] ids); + + // 查询当年电价配置列表 + public List getCurrentYearConfigList(int currentYear); + // 根据指定年月获取电价配置 + public EmsEnergyPriceConfig getConfigListByYearAndMonth(@Param("currentYear") String currentYear, @Param("month")String month); + // 插入或更新 + public void insertOrUpdateEmsEnergyPriceConfig(EmsEnergyPriceConfig priceConfig); +} diff --git a/ems-system/src/main/java/com/xzzn/ems/mapper/EmsPriceTimeConfigMapper.java b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsPriceTimeConfigMapper.java new file mode 100644 index 0000000..a4ef73d --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsPriceTimeConfigMapper.java @@ -0,0 +1,70 @@ +package com.xzzn.ems.mapper; + +import java.util.List; +import com.xzzn.ems.domain.EmsPriceTimeConfig; +import com.xzzn.ems.domain.vo.EnergyPriceTimeRange; +import org.apache.ibatis.annotations.Param; + +/** + * 电价时间配置Mapper接口 + * + * @author xzzn + * @date 2025-10-09 + */ +public interface EmsPriceTimeConfigMapper +{ + /** + * 查询电价时间配置 + * + * @param id 电价时间配置主键 + * @return 电价时间配置 + */ + public EmsPriceTimeConfig selectEmsPriceTimeConfigById(Long id); + + /** + * 查询电价时间配置列表 + * + * @param emsPriceTimeConfig 电价时间配置 + * @return 电价时间配置集合 + */ + public List selectEmsPriceTimeConfigList(EmsPriceTimeConfig emsPriceTimeConfig); + + /** + * 新增电价时间配置 + * + * @param emsPriceTimeConfig 电价时间配置 + * @return 结果 + */ + public int insertEmsPriceTimeConfig(EmsPriceTimeConfig emsPriceTimeConfig); + + /** + * 修改电价时间配置 + * + * @param emsPriceTimeConfig 电价时间配置 + * @return 结果 + */ + public int updateEmsPriceTimeConfig(EmsPriceTimeConfig emsPriceTimeConfig); + + /** + * 删除电价时间配置 + * + * @param id 电价时间配置主键 + * @return 结果 + */ + public int deleteEmsPriceTimeConfigById(Long id); + + /** + * 批量删除电价时间配置 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteEmsPriceTimeConfigByIds(Long[] ids); + + // 获取年月的电价时间范围 + public List getTimeRangeByPriceId(Long priceId); + // 批量插入 + public int batchInsert(List timeConfigs); + // 删除priceId对应的时间范围配置 + public void deleteTimeRangeByPriceId(Long[] priceIds); +} diff --git a/ems-system/src/main/java/com/xzzn/ems/service/IEmsEnergyPriceConfigService.java b/ems-system/src/main/java/com/xzzn/ems/service/IEmsEnergyPriceConfigService.java new file mode 100644 index 0000000..ae44a2e --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/service/IEmsEnergyPriceConfigService.java @@ -0,0 +1,61 @@ +package com.xzzn.ems.service; + +import java.util.List; +import com.xzzn.ems.domain.EmsEnergyPriceConfig; +import com.xzzn.ems.domain.vo.EnergyPriceVo; + +/** + * 电价配置Service接口 + * + * @author xzzn + * @date 2025-09-28 + */ +public interface IEmsEnergyPriceConfigService +{ + /** + * 查询电价配置 + * + * @param id 电价配置主键 + * @return 电价配置 + */ + public EnergyPriceVo selectEmsEnergyPriceConfigById(Long id); + + /** + * 查询电价配置列表 + * + * @return 电价配置集合 + */ + public List selectEmsEnergyPriceConfigList(); + + /** + * 新增电价配置-按月 + * + * @param priceVo 电价配置 + * @return 结果 + */ + public int insertEmsEnergyPriceConfig(EnergyPriceVo priceVo); + + /** + * 修改电价配置 + * + * @param priceVo 电价配置 + * @return 结果 + */ + public int updateEmsEnergyPriceConfig(EnergyPriceVo priceVo); + + /** + * 批量删除电价配置 + * + * @param ids 需要删除的电价配置主键集合 + * @return 结果 + */ + public int deleteEmsEnergyPriceConfigByIds(Long[] ids); + + /** + * 删除电价配置信息 + * + * @param id 电价配置主键 + * @return 结果 + */ + public int deleteEmsEnergyPriceConfigById(Long id); +} diff --git a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsEnergyPriceConfigServiceImpl.java b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsEnergyPriceConfigServiceImpl.java new file mode 100644 index 0000000..d288835 --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsEnergyPriceConfigServiceImpl.java @@ -0,0 +1,198 @@ +package com.xzzn.ems.service.impl; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +import com.xzzn.common.utils.DateUtils; +import com.xzzn.common.utils.StringUtils; +import com.xzzn.ems.domain.EmsPriceTimeConfig; +import com.xzzn.ems.domain.vo.EnergyPriceTimeRange; +import com.xzzn.ems.domain.vo.EnergyPriceVo; +import com.xzzn.ems.mapper.EmsPriceTimeConfigMapper; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.xzzn.ems.mapper.EmsEnergyPriceConfigMapper; +import com.xzzn.ems.domain.EmsEnergyPriceConfig; +import com.xzzn.ems.service.IEmsEnergyPriceConfigService; + +/** + * 电价配置Service业务层处理 + * + * @author xzzn + * @date 2025-09-28 + */ +@Service +public class EmsEnergyPriceConfigServiceImpl implements IEmsEnergyPriceConfigService +{ + @Autowired + private EmsEnergyPriceConfigMapper emsEnergyPriceConfigMapper; + @Autowired + private EmsPriceTimeConfigMapper emsPriceTimeConfigMapper; + + /** + * 查询电价配置 + * + * @param id 电价配置主键 + * @return 电价配置 + */ + @Override + public EnergyPriceVo selectEmsEnergyPriceConfigById(Long id) + { + EnergyPriceVo vo = new EnergyPriceVo(); + EmsEnergyPriceConfig priceConfig = emsEnergyPriceConfigMapper.selectEmsEnergyPriceConfigById(id); + if(priceConfig != null) { + BeanUtils.copyProperties(priceConfig,vo); + // 时间范围 + if (priceConfig.getId() != null) { + List priceVos = emsPriceTimeConfigMapper.getTimeRangeByPriceId(priceConfig.getId()); + vo.setRange(priceVos); + } + } else { + return null; + } + return vo; + } + + /** + * 查询电价配置列表 + * + * @return 电价配置 + */ + @Override + public List selectEmsEnergyPriceConfigList() + { + List responses = new ArrayList<>(); + // 仅查询当年配置 + LocalDate currentDate = LocalDate.now(); + int currentYear = currentDate.getYear(); + + List priceConfigs = emsEnergyPriceConfigMapper.getCurrentYearConfigList(currentYear); + + if (priceConfigs != null && priceConfigs.size() > 0) { + for (EmsEnergyPriceConfig priceConfig : priceConfigs) { + EnergyPriceVo vo = new EnergyPriceVo(); + BeanUtils.copyProperties(priceConfig, vo); + // 时间范围 + if (priceConfig.getId() != null) { + List priceVos = emsPriceTimeConfigMapper.getTimeRangeByPriceId(priceConfig.getId()); + vo.setRange(priceVos); + } + responses.add(vo); + } + } + + return responses; + } + + /** + * 新增电价配置 + * + * @param priceVo 电价配置 + * @return 结果 + */ + @Override + public int insertEmsEnergyPriceConfig(EnergyPriceVo priceVo) + { + String year = priceVo.getYear(); + String month = priceVo.getMonth(); + + // 判断入参 + if(StringUtils.isEmpty(year) || StringUtils.isEmpty(month)){ + return 0; + } + + // 校验当前月电价设置是否已存在,不存在则新增,存在则更新 + EmsEnergyPriceConfig priceConfig = emsEnergyPriceConfigMapper.getConfigListByYearAndMonth(year,month); + if (priceConfig != null){ + return 0; + } else { + priceConfig = new EmsEnergyPriceConfig(); + } + BeanUtils.copyProperties(priceVo,priceConfig); + priceConfig.setCreateTime(DateUtils.getNowDate()); + priceConfig.setUpdateTime(DateUtils.getNowDate()); + priceConfig.setCreateBy("system"); + priceConfig.setUpdateBy("system"); + emsEnergyPriceConfigMapper.insertOrUpdateEmsEnergyPriceConfig(priceConfig); + + return batchInsetPriceTimeRange(priceVo,priceConfig.getId()); + } + + private int batchInsetPriceTimeRange(EnergyPriceVo priceVo, Long priceId) { + List timeConfigs = new ArrayList<>(); + List rangeVos = priceVo.getRange(); + if (rangeVos != null && rangeVos.size() > 0) { + for (EnergyPriceTimeRange rangeVo : rangeVos) { + EmsPriceTimeConfig timeConfig = new EmsPriceTimeConfig(); + BeanUtils.copyProperties(rangeVo,timeConfig); + timeConfig.setCreateTime(DateUtils.getNowDate()); + timeConfig.setUpdateTime(DateUtils.getNowDate()); + timeConfig.setCreateBy("system"); + timeConfig.setUpdateBy("system"); + timeConfig.setPriceId(priceId); + timeConfigs.add(timeConfig); + } + } + // 批量插入 + return emsPriceTimeConfigMapper.batchInsert(timeConfigs); + } + + /** + * 修改电价配置 + * + * @param priceVo 电价配置 + * @return 结果 + */ + @Override + public int updateEmsEnergyPriceConfig(EnergyPriceVo priceVo) + { + if (priceVo == null || priceVo.getId() == null) { + return 0; + } + // 不存在 + EmsEnergyPriceConfig priceConfig = emsEnergyPriceConfigMapper.selectEmsEnergyPriceConfigById(priceVo.getId()); + if (priceConfig == null) { + return 0; + } + + // 存在更新 + BeanUtils.copyProperties(priceVo, priceConfig); + priceConfig.setUpdateTime(DateUtils.getNowDate()); + priceConfig.setUpdateBy("system"); + emsEnergyPriceConfigMapper.updateEmsEnergyPriceConfig(priceConfig); + + // 时间配置,全删,全插入 + Long[] priceIds = {priceVo.getId()}; + emsPriceTimeConfigMapper.deleteTimeRangeByPriceId(priceIds); + return batchInsetPriceTimeRange(priceVo,priceConfig.getId()); + } + + /** + * 批量删除电价配置 + * + * @param ids 需要删除的电价配置主键 + * @return 结果 + */ + @Override + public int deleteEmsEnergyPriceConfigByIds(Long[] ids) + { + // 先删时间配置 + emsPriceTimeConfigMapper.deleteTimeRangeByPriceId(ids); + // 再删月电价 + return emsEnergyPriceConfigMapper.deleteEmsEnergyPriceConfigByIds(ids); + } + + /** + * 删除电价配置信息 + * + * @param id 电价配置主键 + * @return 结果 + */ + @Override + public int deleteEmsEnergyPriceConfigById(Long id) + { + return emsEnergyPriceConfigMapper.deleteEmsEnergyPriceConfigById(id); + } +} diff --git a/ems-system/src/main/resources/mapper/ems/EmsEnergyPriceConfigMapper.xml b/ems-system/src/main/resources/mapper/ems/EmsEnergyPriceConfigMapper.xml new file mode 100644 index 0000000..8be7131 --- /dev/null +++ b/ems-system/src/main/resources/mapper/ems/EmsEnergyPriceConfigMapper.xml @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + select id, year, month, peak, high, flat, valley, create_by, create_time, update_by, update_time, remark from ems_energy_price_config + + + + + + + + insert into ems_energy_price_config + + year, + month, + peak, + high, + flat, + valley, + create_by, + create_time, + update_by, + update_time, + remark, + + + #{year}, + #{month}, + #{peak}, + #{high}, + #{flat}, + #{valley}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + + + + + update ems_energy_price_config + + year = #{year}, + month = #{month}, + peak = #{peak}, + high = #{high}, + flat = #{flat}, + valley = #{valley}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + + where id = #{id} + + + + delete from ems_energy_price_config where id = #{id} + + + + delete from ems_energy_price_config where id in + + #{id} + + + + + + + INSERT INTO ems_energy_price_config ( + id, + year, + month, + peak, + high, + flat, + valley, + create_by, + create_time, + update_by, + update_time, + remark + ) VALUES ( + #{id}, + #{year}, + #{month}, + #{peak}, + #{high}, + #{flat}, + #{valley}, + 'system', + NOW(), + 'system', + NOW(), + #{remark} + ) ON DUPLICATE KEY UPDATE + peak = #{peak}, + high = #{high}, + flat = #{flat}, + valley = #{valley}, + update_time = NOW(); + + + + \ No newline at end of file diff --git a/ems-system/src/main/resources/mapper/ems/EmsPriceTimeConfigMapper.xml b/ems-system/src/main/resources/mapper/ems/EmsPriceTimeConfigMapper.xml new file mode 100644 index 0000000..887441a --- /dev/null +++ b/ems-system/src/main/resources/mapper/ems/EmsPriceTimeConfigMapper.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + select id, start_time, end_time, cost_type, price_id, create_by, create_time, update_by, update_time, remark from ems_price_time_config + + + + + + + + insert into ems_price_time_config + + start_time, + end_time, + cost_type, + price_id, + create_by, + create_time, + update_by, + update_time, + remark, + + + #{startTime}, + #{endTime}, + #{costType}, + #{priceId}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + + + + + update ems_price_time_config + + start_time = #{startTime}, + end_time = #{endTime}, + cost_type = #{costType}, + price_id = #{priceId}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + + where id = #{id} + + + + delete from ems_price_time_config where id = #{id} + + + + delete from ems_price_time_config where id in + + #{id} + + + + + + + + INSERT INTO ems_price_time_config ( + start_time, end_time, cost_type, price_id, create_by, create_time, update_by, update_time, remark + ) VALUES + + + ( + #{item.startTime}, + #{item.endTime}, + #{item.costType}, + #{item.priceId}, + #{item.createBy}, + #{item.createTime}, + #{item.updateBy}, + #{item.updateTime}, + #{item.remark} + ) + + + + + delete from ems_price_time_config where price_id in + + #{priceId} + + + \ No newline at end of file