diff --git a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsSiteConfigController.java b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsSiteConfigController.java index 0ff205f..61bf378 100644 --- a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsSiteConfigController.java +++ b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsSiteConfigController.java @@ -3,7 +3,6 @@ package com.xzzn.web.controller.ems; import com.xzzn.common.core.controller.BaseController; import com.xzzn.common.core.domain.AjaxResult; import com.xzzn.common.core.page.TableDataInfo; -import com.xzzn.ems.domain.EmsDevicesSetting; import com.xzzn.ems.domain.EmsSiteSetting; import com.xzzn.ems.domain.vo.SiteDeviceListVo; import com.xzzn.ems.service.IEmsDeviceSettingService; diff --git a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStrategyController.java b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStrategyController.java new file mode 100644 index 0000000..5f82dda --- /dev/null +++ b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStrategyController.java @@ -0,0 +1,67 @@ +package com.xzzn.web.controller.ems; + +import com.xzzn.ems.domain.EmsStrategyRunning; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import com.xzzn.common.core.controller.BaseController; +import com.xzzn.common.core.domain.AjaxResult; +import com.xzzn.ems.service.IEmsStrategyService; + +/** + * 策略Controller + * + * @author xzzn + * @date 2025-07-10 + */ +@RestController +@RequestMapping("/system/strategyRunning") +public class EmsStrategyController extends BaseController +{ + @Autowired + private IEmsStrategyService emsStrategyService; + + /** + * 获取站点策略配置 + */ + @GetMapping("/list") + public AjaxResult list(String siteId) { + return success(emsStrategyService.selectEmsStrategyRunningList(siteId)); + } + /** + * 停止策略 + */ + @GetMapping(value = "/stop") + public AjaxResult stop(Long id) + { + return toAjax(emsStrategyService.stopRunningStrategy(id)); + } + + /** + * 获取主策略列表 + */ + @GetMapping(value = "/getMainStrategyList") + public AjaxResult getMainStrategyList() + { + return success(emsStrategyService.getMainStrategyList()); + } + + /** + * 获取辅助策略列表 + */ + @GetMapping(value = "/getAuxStrategyList") + public AjaxResult getAuxStrategyList() + { + return success(emsStrategyService.getAuxStrategyList()); + } + + /** + * 配置策略 + */ + @PostMapping(value = "/configStrategy") + public AjaxResult configStrategy(@RequestBody EmsStrategyRunning emsStrategyRunning) + { + emsStrategyRunning.setCreateBy(getUsername()); + emsStrategyRunning.setUpdateBy(getUsername()); + return toAjax(emsStrategyService.configStrategy(emsStrategyRunning)); + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/EmsStrategy.java b/ems-system/src/main/java/com/xzzn/ems/domain/EmsStrategy.java new file mode 100644 index 0000000..1eaea3d --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/domain/EmsStrategy.java @@ -0,0 +1,114 @@ +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_strategy + * + * @author xzzn + * @date 2025-07-10 + */ +public class EmsStrategy extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** */ + private Long id; + + /** 策略名称,如“削峰填谷” */ + @Excel(name = "策略名称,如“削峰填谷”") + private String strategyName; + + /** 策略类型:1 - 主策略;2 - 辅助策略 */ + @Excel(name = "策略类型:1 - 主策略;2 - 辅助策略") + private Long strategyType; + + /** 策略状态:0-未启用 1-已运行 2-已暂停 3-禁用 4-删除 */ + @Excel(name = "策略状态:0-未启用 1-已运行 2-已暂停 3-禁用 4-删除") + private String status; + + /** 描述 */ + @Excel(name = "描述") + private String description; + + /** 主策略id */ + @Excel(name = "主策略id") + private Long mainStrategy; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setStrategyName(String strategyName) + { + this.strategyName = strategyName; + } + + public String getStrategyName() + { + return strategyName; + } + + public void setStrategyType(Long strategyType) + { + this.strategyType = strategyType; + } + + public Long getStrategyType() + { + return strategyType; + } + + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getDescription() + { + return description; + } + + public void setMainStrategy(Long mainStrategy) + { + this.mainStrategy = mainStrategy; + } + + public Long getMainStrategy() + { + return mainStrategy; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("strategyName", getStrategyName()) + .append("strategyType", getStrategyType()) + .append("status", getStatus()) + .append("createTime", getCreateTime()) + .append("updateTime", getUpdateTime()) + .append("description", getDescription()) + .append("mainStrategy", getMainStrategy()) + .toString(); + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/EmsStrategyRunning.java b/ems-system/src/main/java/com/xzzn/ems/domain/EmsStrategyRunning.java new file mode 100644 index 0000000..3b4e26c --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/domain/EmsStrategyRunning.java @@ -0,0 +1,115 @@ +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_strategy_running + * + * @author xzzn + * @date 2025-07-10 + */ +public class EmsStrategyRunning extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 主要策略 */ + @Excel(name = "主要策略") + private Long mainStrategyId; + + /** 辅助策略 */ + @Excel(name = "辅助策略") + private Long auxiliaryStrategyId; + + /** 策略状态:0-未启用 1-已运行 2-已暂停 3-禁用 4-删除 */ + @Excel(name = "策略状态:0-未启用 1-已运行 2-已暂停 3-禁用 4-删除") + private String status; + + /** 站点id */ + @Excel(name = "站点id") + private String siteId; + + /** 设备唯一标识符 */ + @Excel(name = "设备唯一标识符") + private String deviceId; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setMainStrategyId(Long mainStrategyId) + { + this.mainStrategyId = mainStrategyId; + } + + public Long getMainStrategyId() + { + return mainStrategyId; + } + + public void setAuxiliaryStrategyId(Long auxiliaryStrategyId) + { + this.auxiliaryStrategyId = auxiliaryStrategyId; + } + + public Long getAuxiliaryStrategyId() + { + return auxiliaryStrategyId; + } + + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + + public void setSiteId(String siteId) + { + this.siteId = siteId; + } + + public String getSiteId() + { + return siteId; + } + + public void setDeviceId(String deviceId) + { + this.deviceId = deviceId; + } + + public String getDeviceId() + { + return deviceId; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("mainStrategyId", getMainStrategyId()) + .append("auxiliaryStrategyId", getAuxiliaryStrategyId()) + .append("status", getStatus()) + .append("createTime", getCreateTime()) + .append("updateTime", getUpdateTime()) + .append("siteId", getSiteId()) + .append("deviceId", getDeviceId()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/vo/SiteDeviceListVo.java b/ems-system/src/main/java/com/xzzn/ems/domain/vo/SiteDeviceListVo.java index 5dc4155..13e95b0 100644 --- a/ems-system/src/main/java/com/xzzn/ems/domain/vo/SiteDeviceListVo.java +++ b/ems-system/src/main/java/com/xzzn/ems/domain/vo/SiteDeviceListVo.java @@ -17,6 +17,8 @@ public class SiteDeviceListVo { private String deviceType; /** 通信状态 */ private String communicationStatus; + /** 设备类型 */ + private String deviceCategory; public String getSiteId() { return siteId; @@ -65,4 +67,12 @@ public class SiteDeviceListVo { public void setCommunicationStatus(String communicationStatus) { this.communicationStatus = communicationStatus; } + + public String getDeviceCategory() { + return deviceCategory; + } + + public void setDeviceCategory(String deviceCategory) { + this.deviceCategory = deviceCategory; + } } diff --git a/ems-system/src/main/java/com/xzzn/ems/domain/vo/StrategyRunningVo.java b/ems-system/src/main/java/com/xzzn/ems/domain/vo/StrategyRunningVo.java new file mode 100644 index 0000000..5531027 --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/domain/vo/StrategyRunningVo.java @@ -0,0 +1,82 @@ +package com.xzzn.ems.domain.vo; + +/** + * 策略运行对象 + * + * @author xzzn + * @date 2025-07-10 + */ +public class StrategyRunningVo +{ + /** 策略状态:0-未启用 1-已运行 2-已暂停 3-禁用 4-删除 */ + private String status; + + /** 主策略名称 */ + private String mainStrategyName; + + /** 辅助策略名称 */ + private String auxStrategyName; + + /** 站点id */ + private String siteId; + + /** 设备唯一标识符 */ + private String deviceId; + + /** 策略运行id */ + private Long id; + + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + + public String getMainStrategyName() { + return mainStrategyName; + } + + public void setMainStrategyName(String mainStrategyName) { + this.mainStrategyName = mainStrategyName; + } + + public String getAuxStrategyName() { + return auxStrategyName; + } + + public void setAuxStrategyName(String auxStrategyName) { + this.auxStrategyName = auxStrategyName; + } + + public void setSiteId(String siteId) + { + this.siteId = siteId; + } + + public String getSiteId() + { + return siteId; + } + + public void setDeviceId(String deviceId) + { + this.deviceId = deviceId; + } + + public String getDeviceId() + { + return deviceId; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/ems-system/src/main/java/com/xzzn/ems/mapper/EmsStrategyMapper.java b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsStrategyMapper.java new file mode 100644 index 0000000..6d430fc --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsStrategyMapper.java @@ -0,0 +1,63 @@ +package com.xzzn.ems.mapper; + +import java.util.List; +import com.xzzn.ems.domain.EmsStrategy; + +/** + * 策略Mapper接口 + * + * @author xzzn + * @date 2025-07-10 + */ +public interface EmsStrategyMapper +{ + /** + * 查询策略 + * + * @param id 策略主键 + * @return 策略 + */ + public EmsStrategy selectEmsStrategyById(Long id); + + /** + * 查询策略列表 + * + * @param emsStrategy 策略 + * @return 策略集合 + */ + public List selectEmsStrategyList(EmsStrategy emsStrategy); + + /** + * 新增策略 + * + * @param emsStrategy 策略 + * @return 结果 + */ + public int insertEmsStrategy(EmsStrategy emsStrategy); + + /** + * 修改策略 + * + * @param emsStrategy 策略 + * @return 结果 + */ + public int updateEmsStrategy(EmsStrategy emsStrategy); + + /** + * 删除策略 + * + * @param id 策略主键 + * @return 结果 + */ + public int deleteEmsStrategyById(Long id); + + /** + * 批量删除策略 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteEmsStrategyByIds(Long[] ids); + + public List getStrategyListByType(Long type); +} diff --git a/ems-system/src/main/java/com/xzzn/ems/mapper/EmsStrategyRunningMapper.java b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsStrategyRunningMapper.java new file mode 100644 index 0000000..2443df7 --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/mapper/EmsStrategyRunningMapper.java @@ -0,0 +1,71 @@ +package com.xzzn.ems.mapper; + +import java.util.List; +import com.xzzn.ems.domain.EmsStrategyRunning; +import com.xzzn.ems.domain.vo.StrategyRunningVo; + +/** + * 策略运行Mapper接口 + * + * @author xzzn + * @date 2025-07-10 + */ +public interface EmsStrategyRunningMapper +{ + /** + * 查询策略运行 + * + * @param id 策略运行主键 + * @return 策略运行 + */ + public EmsStrategyRunning selectEmsStrategyRunningById(Long id); + + /** + * 查询策略运行列表 + * + * @param emsStrategyRunning 策略运行 + * @return 策略运行集合 + */ + public List selectEmsStrategyRunningList(EmsStrategyRunning emsStrategyRunning); + + /** + * 新增策略运行 + * + * @param emsStrategyRunning 策略运行 + * @return 结果 + */ + public int insertEmsStrategyRunning(EmsStrategyRunning emsStrategyRunning); + + /** + * 修改策略运行 + * + * @param emsStrategyRunning 策略运行 + * @return 结果 + */ + public int updateEmsStrategyRunning(EmsStrategyRunning emsStrategyRunning); + + /** + * 删除策略运行 + * + * @param id 策略运行主键 + * @return 结果 + */ + public int deleteEmsStrategyRunningById(Long id); + + /** + * 批量删除策略运行 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteEmsStrategyRunningByIds(Long[] ids); + + // 获取站点运行策略 + public List getRunningList(String siteId); + + // 停止策略 + public int stopEmsStrategyRunning(Long id); + + // 根据主策略id、辅助策略id、siteId 获取运行策略 + public EmsStrategyRunning selectEmsStrategyRunning(EmsStrategyRunning emsStrategyRunning); +} diff --git a/ems-system/src/main/java/com/xzzn/ems/service/IEmsStrategyService.java b/ems-system/src/main/java/com/xzzn/ems/service/IEmsStrategyService.java new file mode 100644 index 0000000..dfeefff --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/service/IEmsStrategyService.java @@ -0,0 +1,30 @@ +package com.xzzn.ems.service; + +import java.util.List; +import com.xzzn.ems.domain.EmsStrategy; +import com.xzzn.ems.domain.EmsStrategyRunning; +import com.xzzn.ems.domain.vo.StrategyRunningVo; + + +/** + * 策略Service接口 + * + * @author xzzn + * @date 2025-07-10 + */ +public interface IEmsStrategyService +{ + // 获取策略运行列表 + public List selectEmsStrategyRunningList(String siteId); + + // 停止策略 + public int stopRunningStrategy(Long id); + + // 获取主策略 + public List getMainStrategyList(); + + // 获取辅助策略 + public List getAuxStrategyList(); + + public int configStrategy(EmsStrategyRunning emsStrategyRunning); +} diff --git a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStrategyServiceImpl.java b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStrategyServiceImpl.java new file mode 100644 index 0000000..78054e3 --- /dev/null +++ b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStrategyServiceImpl.java @@ -0,0 +1,62 @@ +package com.xzzn.ems.service.impl; + +import java.util.List; +import com.xzzn.common.utils.DateUtils; +import com.xzzn.ems.domain.EmsStrategyRunning; +import com.xzzn.ems.domain.vo.StrategyRunningVo; +import com.xzzn.ems.mapper.EmsStrategyRunningMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.xzzn.ems.mapper.EmsStrategyMapper; +import com.xzzn.ems.domain.EmsStrategy; +import com.xzzn.ems.service.IEmsStrategyService; + +/** + * 策略Service业务层处理 + * + * @author xzzn + * @date 2025-07-10 + */ +@Service +public class EmsStrategyServiceImpl implements IEmsStrategyService +{ + @Autowired + private EmsStrategyMapper emsStrategyMapper; + @Autowired + private EmsStrategyRunningMapper emsStrategyRunningMapper; + + @Override + public List selectEmsStrategyRunningList(String siteId) { + List dataList = emsStrategyRunningMapper.getRunningList(siteId); + return dataList; + } + + @Override + public int stopRunningStrategy(Long id) { + return emsStrategyRunningMapper.stopEmsStrategyRunning(id); + } + + @Override + public List getMainStrategyList() { + return emsStrategyMapper.getStrategyListByType(1L); + } + + @Override + public List getAuxStrategyList() { + return emsStrategyMapper.getStrategyListByType(2L); + } + + @Override + public int configStrategy(EmsStrategyRunning emsStrategyRunning) { + // 校验改策略是否已存在 + EmsStrategyRunning existStrategy = emsStrategyRunningMapper.selectEmsStrategyRunning(emsStrategyRunning); + if (existStrategy != null) { + return -1; + } + // 不存在则插入 + emsStrategyRunning.setStatus("1"); + emsStrategyRunning.setCreateTime(DateUtils.getNowDate()); + emsStrategyRunning.setUpdateTime(DateUtils.getNowDate()); + return emsStrategyRunningMapper.insertEmsStrategyRunning(emsStrategyRunning); + } +} diff --git a/ems-system/src/main/resources/mapper/ems/EmsSiteSettingMapper.xml b/ems-system/src/main/resources/mapper/ems/EmsSiteSettingMapper.xml index e182b46..4968384 100644 --- a/ems-system/src/main/resources/mapper/ems/EmsSiteSettingMapper.xml +++ b/ems-system/src/main/resources/mapper/ems/EmsSiteSettingMapper.xml @@ -136,7 +136,8 @@ + + + and strategy_name like concat('%', #{strategyName}, '%') + and strategy_type = #{strategyType} + and status = #{status} + and description = #{description} + and main_strategy = #{mainStrategy} + + + + + + + insert into ems_strategy + + strategy_name, + strategy_type, + status, + create_time, + update_time, + description, + main_strategy, + + + #{strategyName}, + #{strategyType}, + #{status}, + #{createTime}, + #{updateTime}, + #{description}, + #{mainStrategy}, + + + + + update ems_strategy + + strategy_name = #{strategyName}, + strategy_type = #{strategyType}, + status = #{status}, + create_time = #{createTime}, + update_time = #{updateTime}, + description = #{description}, + main_strategy = #{mainStrategy}, + + where id = #{id} + + + + delete from ems_strategy where id = #{id} + + + + delete from ems_strategy where id in + + #{id} + + + + + \ No newline at end of file diff --git a/ems-system/src/main/resources/mapper/ems/EmsStrategyRunningMapper.xml b/ems-system/src/main/resources/mapper/ems/EmsStrategyRunningMapper.xml new file mode 100644 index 0000000..d35175b --- /dev/null +++ b/ems-system/src/main/resources/mapper/ems/EmsStrategyRunningMapper.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + select id, main_strategy_id, auxiliary_strategy_id, status, create_time, update_time, site_id, device_id, remark from ems_strategy_running + + + + + + + + insert into ems_strategy_running + + main_strategy_id, + auxiliary_strategy_id, + status, + create_time, + update_time, + site_id, + device_id, + remark, + + + #{mainStrategyId}, + #{auxiliaryStrategyId}, + #{status}, + #{createTime}, + #{updateTime}, + #{siteId}, + #{deviceId}, + #{remark}, + + + + + update ems_strategy_running + + main_strategy_id = #{mainStrategyId}, + auxiliary_strategy_id = #{auxiliaryStrategyId}, + status = #{status}, + create_time = #{createTime}, + update_time = #{updateTime}, + site_id = #{siteId}, + device_id = #{deviceId}, + remark = #{remark}, + + where id = #{id} + + + + delete from ems_strategy_running where id = #{id} + + + + delete from ems_strategy_running where id in + + #{id} + + + + + + + update ems_strategy_running set `status`= 4 where id = #{id} + + + + \ No newline at end of file