package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.BattTestData;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.BattInfMapper;
|
import com.whyc.mapper.BattRtstateMapper;
|
import com.whyc.mapper.BattdischargePlanMapper;
|
import com.whyc.pojo.*;
|
import com.whyc.util.ActionUtil;
|
import com.whyc.util.DateUtil;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.text.ParseException;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class BattdischargePlanService {
|
@Resource
|
private BattdischargePlanMapper mapper;
|
|
@Resource
|
private BattInfMapper battInfMapper;
|
|
@Resource
|
private BattRtstateMapper rtstateMapper;
|
|
@Resource
|
private BatttestdataInfService testInfService;
|
|
@Resource
|
private BaoJiGroupBattGroupService baoJiGroupBattGroupService;
|
|
@Resource
|
private BattDischargePlanTempService tempService;
|
|
//查询
|
public Response serchByCondition(BattdischargePlan battdischargePlan) {
|
PageHelper.startPage(battdischargePlan.getPage().getPageCurr(), battdischargePlan.getPage().getPageSize());
|
UserInf uinf = ActionUtil.getUser();
|
battdischargePlan.setUId(uinf.getUId().intValue());
|
List list = mapper.serchByCondition(battdischargePlan);
|
PageInfo pageInfo = new PageInfo(list);
|
return new Response().set(1, pageInfo);
|
}
|
//websocket查询,uId通过前端传递
|
public Response searchByConditionOfWebSocket(BattdischargePlan battdischargePlan){
|
PageHelper.startPage(battdischargePlan.getPage().getPageCurr(),battdischargePlan.getPage().getPageSize());
|
List list=mapper.serchByCondition(battdischargePlan);
|
PageInfo pageInfo=new PageInfo(list);
|
return new Response().set(1,pageInfo);
|
}
|
|
//删除
|
public Response delete(int num) {
|
int flag=mapper.deleteById(num);
|
return new Response().set(flag>0?1:0);
|
}
|
//创建计划-查询
|
public Response serchBattPlan(String stationName1,String stationName2,String stationName5,String stationId) {
|
UserInf uinf=ActionUtil.getUser();
|
List list=battInfMapper.serchBattPlan(stationName1,stationName2,stationName5,stationId,uinf.getUId().intValue());
|
PageInfo pageInfo=new PageInfo(list);
|
return new Response().set(1,pageInfo);
|
}
|
//创建计划-创建计划
|
public Response getBattSate(int battGroupId) {
|
BattRtstate brt=rtstateMapper.getCurrentSate(battGroupId);
|
Response response=new Response();
|
if(brt != null){
|
response.setCode(1);
|
Calendar instance = Calendar.getInstance();
|
instance.add(Calendar.MINUTE,-1);
|
Date time = instance.getTime();
|
if(time.compareTo(brt.getRecDatetime())>0){
|
response.setMsg("通讯故障");
|
}else{
|
/**
|
* 0 未知
|
* 1 浮充
|
* 2 充电
|
* 3 放电
|
* 4 均充
|
*/
|
switch (brt.getBattState()){
|
case 0 : response.setMsg("未进行充放电操作"); break;
|
case 1 : response.setMsg("浮充"); break;
|
case 2 : response.setMsg("充电"); break;
|
case 3 : response.setMsg("放电"); break;
|
case 4 : response.setMsg("均充"); break;
|
}
|
|
}
|
}else{
|
response.setMsg("无法查询到该电池当前状态");
|
}
|
return response;
|
}
|
//启用/延时/取消放电计划/修改放电参数
|
public Response updatePro(List<BattdischargePlan> list) {
|
int flag=mapper.updatePro(list);
|
return new Response().set(flag>0?1:0);
|
}
|
//校验需要添加的计划参数 放电计划处于等待启动0,放电延时1,放电计划进行中3,充电进行中5
|
public Response judgePlan(List<BattdischargePlan> bplans) {
|
List<BattdischargePlan> list = new ArrayList();//存放满足计划设定条件的可行计划
|
if(bplans!=null&&bplans.size()>0){
|
for(int i=0;i<bplans.size();i++){
|
List flag=mapper.judgePlan(bplans.get(i));
|
if(flag!=null&&flag.size()>0){//判断通过是否数据库存在同机房放电计划,满足条件
|
if(list.size()>0){
|
int judge=judgeList(bplans.get(i), list);
|
if(judge==1){////判断通过时间相隔3天,满足条件
|
list.add(bplans.get(i));
|
}else{
|
continue;
|
}
|
}else{
|
list.add(bplans.get(i));
|
}
|
|
}
|
}
|
}
|
PageInfo pageInfo = new PageInfo(list);
|
return new Response().set(1,pageInfo);
|
}
|
//放电计划中添加计划时,有没有出现同机房存在电池组有计划
|
public int judgeList(Object obj1,Object obj2){
|
BattdischargePlan bplan=(BattdischargePlan) obj1;
|
List<BattdischargePlan> list=(List<BattdischargePlan>) obj2;
|
int flag=1;
|
if(list!=null&&list.size()>0){
|
for(int i=0;i<list.size();i++){
|
|
if(bplan.getNote().equals(list.get(i).getNote())){
|
int hours=ActionUtil.HoursBetween(bplan.getDischargeStarttime(), list.get(i).getDischargeStarttime1());
|
if(hours< BattTestData.hoursBetween){
|
flag=0;
|
break;
|
}
|
}
|
}
|
}
|
return flag;
|
}
|
|
//创建计划-创建计划
|
public Response addPro(List<BattdischargePlan> list) {
|
int flag = mapper.addPro(list);
|
return new Response().set(flag > 0 ? 1 : 0);
|
}
|
|
public List<BattMapInformation> findTimeoutStation() {
|
return mapper.findTimeoutStation();
|
}
|
|
//监控层首页:今日放电任务统计
|
public Response getPlanStaticToday(int userId) {
|
Response planRes = new Response<>();
|
try {
|
Map<String, Object> map = new HashMap<>();
|
//查询今天所有正在放电的机房总数
|
int disNumAll = testInfService.getPlanStaticToday(userId);
|
|
//Map<String, Integer> stateNumMap = new HashMap<>();
|
Map<String, Object> stateMap = new HashMap<>();
|
List<BattdischargePlan> stateList = mapper.getPlanStaticToday(userId);
|
Map<Integer, List<BattdischargePlan>> stateDisMap = stateList.stream().collect(Collectors.groupingBy(BattdischargePlan::getDischargeState));
|
/* stateNumMap.put("state0", 0);
|
stateNumMap.put("state1", 0);
|
stateNumMap.put("state3", 0);*/
|
stateMap.put("state0", new ArrayList<>());
|
stateMap.put("state1", new ArrayList<>());
|
stateMap.put("state3", new ArrayList<>());
|
for (Integer dischargeState : stateDisMap.keySet()) {
|
//stateNumMap.put("state" + String.valueOf(dischargeState), stateDisMap.get(dischargeState).size());
|
stateMap.put("state" + String.valueOf(dischargeState), stateDisMap.get(dischargeState));
|
}
|
/* Map<String, Integer> nodeNumMap = new HashMap<>();
|
nodeNumMap.put("node0", 0);
|
nodeNumMap.put("node1", 0);*/
|
Map<String, Object> nodeMap = new HashMap<>();
|
nodeMap.put("node0", new ArrayList<>());
|
nodeMap.put("node1", new ArrayList<>());
|
Map<Integer, List<BattdischargePlan>> nodeDisMap = stateList.stream().collect(Collectors.groupingBy(BattdischargePlan::getNodeStation));
|
for (Integer node : nodeDisMap.keySet()) {
|
//nodeNumMap.put("node" + String.valueOf(node), nodeDisMap.get(node).size());
|
nodeMap.put("node" + String.valueOf(node), nodeDisMap.get(node));
|
}
|
//stateNumMap.put("sumNum", stateList.size());
|
//map.put("stateNumMap", stateNumMap);
|
map.put("stateMap", stateMap);
|
// map.put("nodeNumMap", nodeNumMap);
|
map.put("nodeMap", nodeMap);
|
map.put("disNumAll", disNumAll);
|
planRes.setII(1, stateList.size() > 0, map, "今日放电任务统计");
|
} catch (Exception e) {
|
planRes.set(1, false, "出现异常" + e.getMessage());
|
}
|
|
return planRes;
|
}
|
/**
|
* 原则:
|
* 0.每个站点只取第一组电池参与放电计划
|
* 1.每天最多1个节点站,每天最多3个放电站点
|
* 2.各班组尽量扁平,尽量保证各个组完全放电完成时间接近
|
* @return
|
* @param resetCapPercent
|
* @param startTimeStr
|
*/
|
public Response generateDischargePlan(Float resetCapPercent, String startTimeStr) throws ParseException {
|
List<BattDischargePlanTemp> tempList = new LinkedList<>();
|
Date startTime = DateUtil.YYYY_MM_DD_HH_MM_SS.parse(startTimeStr);
|
Calendar planTime = Calendar.getInstance();
|
planTime.setTime(startTime);
|
//一年度只能生成一次放电计划,校验
|
int planYear = planTime.get(Calendar.YEAR);
|
QueryWrapper<BattdischargePlan> query = Wrappers.query();
|
query.likeRight("discharge_starttime",planYear).last(" limit 1");
|
BattdischargePlan battdischargePlan = mapper.selectOne(query);
|
if(battdischargePlan!=null){
|
return new Response().set(1,false,"当前年度已存在计划,无法重复生成");
|
}
|
//查询所有可用的组以及每个组的站点
|
List<BaojiGroupBattGroup> baoJiGroupListWithinBattGroupList = baoJiGroupBattGroupService.getBaoJiGroupListWithinBattGroupList();
|
//List<BattdischargePlan> planList = new LinkedList<>();
|
List<Battinf> planList = new LinkedList<>();
|
int prePlanSize = 3;
|
int planSize = 0;
|
while (prePlanSize != planSize){ //当相等时,说明每天计划已经为0,计划完结
|
prePlanSize = planSize;
|
//List<BattdischargePlan> subPlanList = getDischargePlanList(baoJiGroupListWithinBattGroupList,planTime);
|
List<Battinf> subPlanList = getDischargePlanList2(baoJiGroupListWithinBattGroupList,planTime);
|
//添加到电池放电计划List
|
planList.addAll(subPlanList);
|
//baoJiGroupListWithinBattGroupList重置为当前baoJiGroupListWithinBattGroupList-battGroupList
|
|
//按日递增计划时间
|
planTime.add(Calendar.DAY_OF_MONTH,1);
|
planSize = planList.size();
|
}
|
|
Date date = new Date();
|
for (Battinf battinf : planList) {
|
BattDischargePlanTemp temp = new BattDischargePlanTemp();
|
temp.setBattGroupId(battinf.getBattGroupId());
|
temp.setBattGroupName(battinf.getBattGroupName());
|
temp.setStationId(battinf.getStationId());
|
temp.setStationName(battinf.getStationName());
|
temp.setNodeStation(battinf.getNodeStation());
|
temp.setGroupId(battinf.getNum().longValue());
|
temp.setGroupName(battinf.getInstallUser());
|
temp.setDischargeStartTime(battinf.getDischargeStartTime());
|
temp.setCreateTime(date);
|
temp.setMonCapStd(battinf.getMonCapStd());
|
temp.setMonVolStd(battinf.getMonVolStd());
|
temp.setCapPercent(resetCapPercent);
|
tempList.add(temp);
|
}
|
//存入临时表
|
tempService.truncate();
|
tempService.insertBatch(tempList);
|
|
return new Response().setII(1,true,tempList,null);
|
}
|
|
/**
|
* 根据逻辑获取一天的
|
* 模型1:
|
* 2组2非节(包含本组情况,只是包含本组情况优先级低)
|
* 1组2非节(包含本组情况,只是包含本组情况优先级低)
|
* 1组1节 1组1非节(包含本组情况,只是包含本组情况优先级低)
|
* 0非节
|
*
|
* 模型2:
|
*
|
* 3组3非节
|
* 2组3非节
|
* 0组1节 1组3非节
|
* 2组2非节
|
* 1组2非节
|
* 1组1非节
|
*
|
*
|
*
|
* @param baoJiGroupListWithinBattGroupList
|
* @param planTime
|
* @return
|
*/
|
private List<BattdischargePlan> getDischargePlanList(List<BaojiGroupBattGroup> baoJiGroupListWithinBattGroupList, Calendar planTime) {
|
List<BattdischargePlan> planList = new LinkedList<>();
|
int nodeStationExists = 0;
|
for (int i = 0; i < baoJiGroupListWithinBattGroupList.size(); i++) {
|
//一条记录就是一组,组内包含了所有性质的站点
|
//先确定是否存在节点,存在则加入到计划. 没有则执行没有节点的模型
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(i);
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if(battinf.getNodeStation()==1){
|
//找到节点
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(battinf.getBattGroupId());
|
plan.setBattGroupName(battinf.getBattGroupName());
|
plan.setNodeStation(1);
|
plan.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
plan.setNote(String.valueOf(i));//记录计划内的组号对应的索引
|
planList.add(plan);
|
nodeStationExists = 1;
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(i).setBattGroupList(battStationList);
|
break; //当前组当前排站点级别降低,只要其他组能排,不会再选择当前组.
|
}
|
}
|
//判断是否找到节点,找到节点则退出此次遍历
|
if(nodeStationExists == 1){
|
break;
|
}
|
}
|
|
//判断是否找到节点,找到则执行模型1
|
if(nodeStationExists == 1){
|
//节点在的组优先级降低
|
Integer planedBaoJiGroupId = planList.get(0).getNum();
|
//模型1-1是否成立
|
for (int i = 0; i < baoJiGroupListWithinBattGroupList.size(); i++) {
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(i);
|
Integer baojiGroupId = groupWithBattStationList.getBaojiGroupId();
|
if(planedBaoJiGroupId.equals(baojiGroupId)){
|
continue; //先看能否满足2组2非节(非本组)
|
}
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if(battinf.getNodeStation()==0){
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(battinf.getBattGroupId());
|
plan.setBattGroupName(battinf.getBattGroupName());
|
plan.setNodeStation(0);
|
plan.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
plan.setNote(String.valueOf(i));//记录计划内的组号对应的索引
|
planList.add(plan);
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(i).setBattGroupList(battStationList);
|
break; //当前组当前排站点级别降低,只要其他组能排,不会再选择当前组.
|
}
|
}
|
//遍历过程中,查看计划是否满足3个站点,已经满足则提前结束计划分配
|
if(planList.size()==3){
|
break;
|
}
|
}
|
//遍历完毕,查看计划是否满足3个站点
|
//如果不满足,则把已排组的站点继续允许分配,优先遍历非节点站所在组
|
//如果还不满足,则继续分配,允许遍历节点站所在组
|
int size = planList.size();
|
if(size!=3){
|
//如果计划站点数是2,说明计划1为节点站,计划2为非节点站,优先计划2所在非节点站所在组去分配
|
int notNodeStationExists = 0;
|
if(size==2){
|
int indexNotNode = Integer.parseInt(planList.get(1).getNote());
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(indexNotNode);
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if(battinf.getNodeStation()==0){
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(battinf.getBattGroupId());
|
plan.setBattGroupName(battinf.getBattGroupName());
|
plan.setNodeStation(0);
|
plan.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
planList.add(plan);
|
notNodeStationExists = 1;
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(indexNotNode).setBattGroupList(battStationList);
|
break;//找到可分配的,终止
|
}
|
}
|
if(notNodeStationExists != 1){ //在非节点站所在组没找到其他非节点,只能从节点站所在组去分配
|
int indexNode = Integer.parseInt(planList.get(0).getNote());
|
BaojiGroupBattGroup groupHavingNodeWithBattStationList = baoJiGroupListWithinBattGroupList.get(indexNode);
|
List<Battinf> battStationList2 = groupHavingNodeWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList2.size(); j++) {
|
Battinf battinf = battStationList2.get(j);
|
if(battinf.getNodeStation()==0){
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(battinf.getBattGroupId());
|
plan.setBattGroupName(battinf.getBattGroupName());
|
plan.setNodeStation(0);
|
plan.setNum(groupHavingNodeWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
planList.add(plan);
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(indexNotNode).setBattGroupList(battStationList);
|
break;//找到可分配的,终止
|
}
|
}
|
}
|
}
|
//如果计划站点数是1,说明只有1个节点站,继续从节点站所在组去分配
|
else{
|
int indexNode = Integer.parseInt(planList.get(0).getNote());
|
BaojiGroupBattGroup groupHavingNodeWithBattStationList = baoJiGroupListWithinBattGroupList.get(indexNode);
|
List<Battinf> battStationList2 = groupHavingNodeWithBattStationList.getBattGroupList();
|
List<Integer> indexRemoveList = new LinkedList<>();
|
for (int j = 0; j < battStationList2.size(); j++) {
|
Battinf battinf = battStationList2.get(j);
|
if(battinf.getNodeStation()==0){
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(battinf.getBattGroupId());
|
plan.setBattGroupName(battinf.getBattGroupName());
|
plan.setNodeStation(0);
|
plan.setNum(groupHavingNodeWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
planList.add(plan);
|
indexRemoveList.add(j);
|
if(planList.size()==3) {
|
break;//找到可分配的,终止
|
}
|
}
|
}
|
for (int i = indexRemoveList.size()-1; i >=0; i--) {
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList2.remove(indexRemoveList.get(i).intValue());
|
//baoJiGroupListWithinBattGroupList.get(indexNode).setBattGroupList(battStationList2);
|
}
|
}
|
}
|
}
|
//未找到节点,执行模型2
|
else{
|
for (int i = 0; i < baoJiGroupListWithinBattGroupList.size(); i++) {
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(i);
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
List<Integer> indexRemoveList = new LinkedList<>();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(battinf.getBattGroupId());
|
plan.setBattGroupName(battinf.getBattGroupName());
|
plan.setNodeStation(0);
|
plan.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
plan.setNote(String.valueOf(i));//记录计划内的组号对应的索引
|
planList.add(plan);
|
indexRemoveList.add(j);
|
if(planList.size()==3) {
|
break;//找到可分配的,终止
|
}
|
}
|
for (int i1 = indexRemoveList.size()-1; i1 >=0; i1--) {
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(indexRemoveList.get(i1).intValue());
|
//baoJiGroupListWithinBattGroupList.get(i).setBattGroupList(battStationList);
|
}
|
}
|
//遍历完毕,查看计划是否满足3个站点
|
//如果不满足,则把已排组的站点继续允许分配,遍历非节点站所在组
|
//如果存在1组,说明后续也只能从这1组获取,反复遍历;如果存在2组,那再遍历完一次后无需再遍历,因为如果存在则已经满足要求
|
int size = planList.size();
|
if(size!=3) {
|
if(size==1) { //存在1组,那说明后续也只能从这1组中获取
|
for (int i = 0; i < planList.size(); i++) {
|
BattdischargePlan existsPlan = planList.get(i);
|
int index = Integer.parseInt(existsPlan.getNote());
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(index);
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
List<Integer> indexRemoveList = new LinkedList<>();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if (battinf.getNodeStation() == 0) {
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(battinf.getBattGroupId());
|
plan.setBattGroupName(battinf.getBattGroupName());
|
plan.setNodeStation(0);
|
plan.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
indexRemoveList.add(j);
|
planList.add(plan);
|
if(planList.size()==3){
|
break;//找到可分配的,终止
|
}
|
}
|
}
|
//已经加入到计划组的,从原纪录中剔除
|
for (int i1 = indexRemoveList.size()-1; i1 >=0; i1--) {
|
battStationList.remove(indexRemoveList.get(i1).intValue());
|
baoJiGroupListWithinBattGroupList.get(index).setBattGroupList(battStationList);
|
}
|
}
|
}else{ //已经存在2组
|
for (int i = 0; i < planList.size(); i++) {
|
BattdischargePlan existsPlan = planList.get(i);
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(Integer.parseInt(existsPlan.getNote()));
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if (battinf.getNodeStation() == 0) {
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(battinf.getBattGroupId());
|
plan.setBattGroupName(battinf.getBattGroupName());
|
plan.setNodeStation(0);
|
plan.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
planList.add(plan);
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(Integer.parseInt(existsPlan.getNote())).setBattGroupList(battStationList);
|
break;//找到可分配的,终止
|
}
|
}
|
}
|
//完结
|
}
|
}
|
}
|
|
return planList;
|
}
|
|
private List<Battinf> getDischargePlanList2(List<BaojiGroupBattGroup> baoJiGroupListWithinBattGroupList, Calendar planTime) {
|
List<Battinf> planList = new LinkedList<>();
|
int nodeStationExists = 0;
|
for (int i = 0; i < baoJiGroupListWithinBattGroupList.size(); i++) {
|
//一条记录就是一组,组内包含了所有性质的站点
|
//先确定是否存在节点,存在则加入到计划. 没有则执行没有节点的模型
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(i);
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if(battinf.getNodeStation()==1){
|
//找到节点
|
battinf.setDischargeStartTime(planTime.getTime());;
|
battinf.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
battinf.setInstallUser(groupWithBattStationList.getBaojiGroupName());
|
battinf.setNote(String.valueOf(i));//记录计划内的组号对应的索引
|
planList.add(battinf);
|
nodeStationExists = 1;
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(i).setBattGroupList(battStationList);
|
break; //当前组当前排站点级别降低,只要其他组能排,不会再选择当前组.
|
}
|
}
|
//判断是否找到节点,找到节点则退出此次遍历
|
if(nodeStationExists == 1){
|
break;
|
}
|
}
|
|
//判断是否找到节点,找到则执行模型1
|
if(nodeStationExists == 1){
|
//节点在的组优先级降低
|
Integer planedBaoJiGroupId = planList.get(0).getNum();
|
//模型1-1是否成立
|
for (int i = 0; i < baoJiGroupListWithinBattGroupList.size(); i++) {
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(i);
|
Integer baojiGroupId = groupWithBattStationList.getBaojiGroupId();
|
if(planedBaoJiGroupId.equals(baojiGroupId)){
|
continue; //先看能否满足2组2非节(非本组)
|
}
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if(battinf.getNodeStation()==0){
|
battinf.setDischargeStartTime(planTime.getTime());;
|
battinf.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
battinf.setInstallUser(groupWithBattStationList.getBaojiGroupName());
|
battinf.setNote(String.valueOf(i));//记录计划内的组号对应的索引
|
planList.add(battinf);
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(i).setBattGroupList(battStationList);
|
break; //当前组当前排站点级别降低,只要其他组能排,不会再选择当前组.
|
}
|
}
|
//遍历过程中,查看计划是否满足3个站点,已经满足则提前结束计划分配
|
if(planList.size()==3){
|
break;
|
}
|
}
|
//遍历完毕,查看计划是否满足3个站点
|
//如果不满足,则把已排组的站点继续允许分配,优先遍历非节点站所在组
|
//如果还不满足,则继续分配,允许遍历节点站所在组
|
int size = planList.size();
|
if(size!=3){
|
//如果计划站点数是2,说明计划1为节点站,计划2为非节点站,优先计划2所在非节点站所在组去分配
|
int notNodeStationExists = 0;
|
if(size==2){
|
int indexNotNode = Integer.parseInt(planList.get(1).getNote());
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(indexNotNode);
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if(battinf.getNodeStation()==0){
|
battinf.setDischargeStartTime(planTime.getTime());;
|
battinf.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
battinf.setInstallUser(groupWithBattStationList.getBaojiGroupName());
|
planList.add(battinf);
|
notNodeStationExists = 1;
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(indexNotNode).setBattGroupList(battStationList);
|
break;//找到可分配的,终止
|
}
|
}
|
if(notNodeStationExists != 1){ //在非节点站所在组没找到其他非节点,只能从节点站所在组去分配
|
int indexNode = Integer.parseInt(planList.get(0).getNote());
|
BaojiGroupBattGroup groupHavingNodeWithBattStationList = baoJiGroupListWithinBattGroupList.get(indexNode);
|
List<Battinf> battStationList2 = groupHavingNodeWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList2.size(); j++) {
|
Battinf battinf = battStationList2.get(j);
|
if(battinf.getNodeStation()==0){
|
battinf.setDischargeStartTime(planTime.getTime());;
|
battinf.setNum(groupHavingNodeWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
battinf.setInstallUser(groupHavingNodeWithBattStationList.getBaojiGroupName());
|
planList.add(battinf);
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(indexNotNode).setBattGroupList(battStationList);
|
break;//找到可分配的,终止
|
}
|
}
|
}
|
}
|
//如果计划站点数是1,说明只有1个节点站,继续从节点站所在组去分配
|
else{
|
int indexNode = Integer.parseInt(planList.get(0).getNote());
|
BaojiGroupBattGroup groupHavingNodeWithBattStationList = baoJiGroupListWithinBattGroupList.get(indexNode);
|
List<Battinf> battStationList2 = groupHavingNodeWithBattStationList.getBattGroupList();
|
List<Integer> indexRemoveList = new LinkedList<>();
|
for (int j = 0; j < battStationList2.size(); j++) {
|
Battinf battinf = battStationList2.get(j);
|
if(battinf.getNodeStation()==0){
|
battinf.setDischargeStartTime(planTime.getTime());;
|
battinf.setNum(groupHavingNodeWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
battinf.setInstallUser(groupHavingNodeWithBattStationList.getBaojiGroupName());
|
planList.add(battinf);
|
indexRemoveList.add(j);
|
if(planList.size()==3) {
|
break;//找到可分配的,终止
|
}
|
}
|
}
|
for (int i = indexRemoveList.size()-1; i >=0; i--) {
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList2.remove(indexRemoveList.get(i).intValue());
|
//baoJiGroupListWithinBattGroupList.get(indexNode).setBattGroupList(battStationList2);
|
}
|
}
|
}
|
}
|
//未找到节点,执行模型2
|
else{
|
for (int i = 0; i < baoJiGroupListWithinBattGroupList.size(); i++) {
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(i);
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
List<Integer> indexRemoveList = new LinkedList<>();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
battinf.setDischargeStartTime(planTime.getTime());;
|
battinf.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
battinf.setInstallUser(groupWithBattStationList.getBaojiGroupName());
|
battinf.setNote(String.valueOf(i));//记录计划内的组号对应的索引
|
planList.add(battinf);
|
indexRemoveList.add(j);
|
if(planList.size()==3) {
|
break;//找到可分配的,终止
|
}
|
}
|
for (int i1 = indexRemoveList.size()-1; i1 >=0; i1--) {
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(indexRemoveList.get(i1).intValue());
|
//baoJiGroupListWithinBattGroupList.get(i).setBattGroupList(battStationList);
|
}
|
}
|
//遍历完毕,查看计划是否满足3个站点
|
//如果不满足,则把已排组的站点继续允许分配,遍历非节点站所在组
|
//如果存在1组,说明后续也只能从这1组获取,反复遍历;如果存在2组,那再遍历完一次后无需再遍历,因为如果存在则已经满足要求
|
int size = planList.size();
|
if(size!=3) {
|
if(size==1) { //存在1组,那说明后续也只能从这1组中获取
|
for (int i = 0; i < planList.size(); i++) {
|
Battinf existsPlan = planList.get(i);
|
int index = Integer.parseInt(existsPlan.getNote());
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(index);
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
List<Integer> indexRemoveList = new LinkedList<>();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if (battinf.getNodeStation() == 0) {
|
battinf.setDischargeStartTime(planTime.getTime());;
|
battinf.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
battinf.setInstallUser(groupWithBattStationList.getBaojiGroupName());
|
planList.add(battinf);
|
indexRemoveList.add(j);
|
if(planList.size()==3){
|
break;//找到可分配的,终止
|
}
|
}
|
}
|
//已经加入到计划组的,从原纪录中剔除
|
for (int i1 = indexRemoveList.size()-1; i1 >=0; i1--) {
|
battStationList.remove(indexRemoveList.get(i1).intValue());
|
baoJiGroupListWithinBattGroupList.get(index).setBattGroupList(battStationList);
|
}
|
}
|
}else{ //已经存在2组
|
for (int i = 0; i < planList.size(); i++) {
|
Battinf existsPlan = planList.get(i);
|
BaojiGroupBattGroup groupWithBattStationList = baoJiGroupListWithinBattGroupList.get(Integer.parseInt(existsPlan.getNote()));
|
List<Battinf> battStationList = groupWithBattStationList.getBattGroupList();
|
for (int j = 0; j < battStationList.size(); j++) {
|
Battinf battinf = battStationList.get(j);
|
if (battinf.getNodeStation() == 0) {
|
battinf.setDischargeStartTime(planTime.getTime());;
|
battinf.setNum(groupWithBattStationList.getBaojiGroupId());//记录计划内的组号
|
battinf.setInstallUser(groupWithBattStationList.getBaojiGroupName());
|
planList.add(battinf);
|
//已经加入到计划组的,从原纪录中剔除
|
battStationList.remove(j);
|
baoJiGroupListWithinBattGroupList.get(Integer.parseInt(existsPlan.getNote())).setBattGroupList(battStationList);
|
break;//找到可分配的,终止
|
}
|
}
|
}
|
//完结
|
}
|
}
|
}
|
|
return planList;
|
}
|
|
|
public Response insertConfirmDischargePlan(List<BattDischargePlanTemp> tempList) {
|
List<BattdischargePlan> planList = new LinkedList<>();
|
Date date = new Date();
|
for (BattDischargePlanTemp temp : tempList) {
|
//计算预计停止放电时间
|
Date dischargeStartTime = temp.getDischargeStartTime();
|
Calendar stopTime = Calendar.getInstance();
|
stopTime.setTime(dischargeStartTime);
|
stopTime.add(Calendar.MINUTE,600);
|
Date dischargeStopTime = stopTime.getTime();
|
|
BattdischargePlan plan = new BattdischargePlan();
|
plan.setBattgroupid(temp.getBattGroupId());
|
plan.setDischargeStarttime(dischargeStartTime);
|
plan.setDischargeStoptime(dischargeStopTime);
|
plan.setDischargeState(0);
|
plan.setDischargeCleartype(1);
|
plan.setBattIndexInFbs(0);
|
plan.setPresetTime(600);
|
plan.setPresetCap(temp.getMonCapStd()*temp.getCapPercent());
|
plan.setPresetMonvol(temp.getMonVolStd()*0.9f);
|
plan.setPresetGroupvol(43f);
|
plan.setPresetMon(1);
|
plan.setPresetCurr(temp.getMonCapStd()/10);
|
plan.setDcvolhighlimit(56.4f);
|
plan.setChargecurrset(20f);
|
plan.setPlanCircle(30);
|
plan.setPlanRate(1);
|
plan.setAlreadyCount(0);
|
plan.setDischargeReason("");
|
plan.setNote("");
|
plan.setNodeStation(temp.getNodeStation());
|
plan.setBaojiGroupId(temp.getGroupId().intValue());
|
plan.setCreateTime(date);
|
|
planList.add(plan);
|
}
|
mapper.insertBatchSomeColumn(planList);
|
return new Response().setII(1,"放电计划已生成");
|
}
|
|
public Response getReplaceBattGroupList(int num) {
|
QueryWrapper<BattdischargePlan> query = Wrappers.query();
|
query.eq("discharge_state",0);
|
List<BattdischargePlan> tempList = mapper.selectList(query);
|
List<BattdischargePlan> recommendList = new LinkedList<>();
|
List<BattdischargePlan> list = new LinkedList<>();
|
BattdischargePlan currentTemp = null;
|
for (BattdischargePlan temp : tempList) {
|
if(temp.getNum()==num){
|
currentTemp = temp;
|
break;
|
}
|
}
|
//同类型替换,并且不能是同一天的
|
for (BattdischargePlan temp : tempList) {
|
assert currentTemp != null;
|
if(temp.getNum()!=num &&temp.getDischargeStarttime().compareTo(currentTemp.getDischargeStarttime())!=0 && temp.getNodeStation()==(currentTemp.getNodeStation())){
|
if(temp.getBaojiGroupId().equals(currentTemp.getBaojiGroupId())){ //同班组,推荐
|
recommendList.add(temp);
|
}else{
|
list.add(temp);
|
}
|
}
|
}
|
return new Response().setII(1,recommendList,list,null);
|
}
|
|
public Response getDisabledDischargeTime(int num) {
|
QueryWrapper<BattdischargePlan> query = Wrappers.query();
|
query.eq("discharge_state",0);
|
List<BattdischargePlan> tempList = mapper.selectList(query);
|
BattdischargePlan currentTemp = null;
|
for (BattdischargePlan temp : tempList) {
|
if(temp.getNum()==num){
|
currentTemp = temp;
|
break;
|
}
|
}
|
//不可用的时间,三种方式,层层筛选:1.当前电池组时间 2.其他 满足每天3个站点的时间 3.如果当前为节点站,再其他,存在节点站的时间
|
List<Date> disabledDischargeTimeList = new LinkedList<>();
|
Date dischargeStartTime = currentTemp.getDischargeStarttime();
|
disabledDischargeTimeList.add(dischargeStartTime);
|
Integer nodeStation = currentTemp.getNodeStation();
|
Map<Date, List<BattdischargePlan>> dischargeMap = tempList.stream().collect(Collectors.groupingBy(BattdischargePlan::getDischargeStarttime));
|
Set<Date> dates = dischargeMap.keySet();
|
for (Date date : dates) {
|
if(dischargeStartTime.compareTo(date)==0){
|
continue;
|
}
|
List<BattdischargePlan> dailyTempList = dischargeMap.get(date);
|
if (dailyTempList.size()==3){
|
disabledDischargeTimeList.add(date);
|
}else{ //当天不足3个站点
|
if(nodeStation == 1){ //如果需要插入的站点是节点站,当天存在节点站,也不可用
|
for (BattdischargePlan temp : dailyTempList) {
|
if(temp.getNodeStation()==1){
|
disabledDischargeTimeList.add(date);
|
break;
|
}
|
}
|
}
|
}
|
}
|
disabledDischargeTimeList = disabledDischargeTimeList.stream().sorted().collect(Collectors.toList());
|
return new Response().set(1,disabledDischargeTimeList);
|
}
|
}
|