Commit db66455c authored by duanruiming's avatar duanruiming

[add] 策略锁定时间计算逻辑

parent e7f03570
......@@ -33,6 +33,7 @@ import net.wanji.opt.vo.StrategyNameCrossVO;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
......@@ -610,9 +611,8 @@ public class StrategyControlServiceImpl implements StrategyControlService {
Map<Integer, GreenwaveInfoPO> greenWaveMap = GreenWaveInfoCache.greenWaveMap;
GreenwaveInfoPO greenwaveInfoPO = greenWaveMap.get(greenId);
String dir = entity.getDir();
String desc = GreenBeltDirEnum.getDesc(dir);
ext.setBizId(String.valueOf(entity.getGreenId()));
ext.setCrossName(greenwaveInfoPO.getName() + desc);
ext.setCrossName(greenwaveInfoPO.getName());
String location = greenwaveInfoPO.getWkt();
ext.setWkt(location);
ext.setOptMethod(optMethod);
......@@ -1284,23 +1284,66 @@ public class StrategyControlServiceImpl implements StrategyControlService {
@Override
public JsonViewObject strategyLockSend(StrategyLockSendVO strategyLockSendVO) throws Exception {
ObjectMapper mapper = JacksonUtils.getInstance();
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
String crossId = strategyLockSendVO.getCrossId();
LambdaQueryWrapper<StrategyDailyPlanInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyDailyPlanInfoEntity::getCrossId, crossId);
List<StrategyDailyPlanInfoEntity> dailyPlanInfos = strategyDailyPlanInfoMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(dailyPlanInfos)) {
for (StrategyDailyPlanInfoEntity dailyPlanInfo : dailyPlanInfos) {
String dailyPlanStr = dailyPlanInfo.getDailyPlanDetails();
StrategyControlDetailList.DailyPlan.DailyPlanDetail dailyPlanDetail = new StrategyControlDetailList.DailyPlan.DailyPlanDetail();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanDetails = mapper.readValue(dailyPlanStr, new TypeReference<List<StrategyControlDetailList.DailyPlan.DailyPlanDetail>>() {});
if (!CollectionUtils.isEmpty(dailyPlanDetails)) {
for (StrategyControlDetailList.DailyPlan.DailyPlanDetail item : dailyPlanDetails) {
String strategyNo = item.getStrategyNo();
try {
ObjectMapper instance = JacksonUtils.getInstance();
LambdaQueryWrapper<StrategyControlDataEntity> queryWrapper = new LambdaQueryWrapper<>();
Date current = new Date();
queryWrapper.eq(StrategyControlDataEntity::getBizId, strategyLockSendVO.getCrossId());
queryWrapper.eq(StrategyControlDataEntity::getBizType, 0);
queryWrapper.le(StrategyControlDataEntity::getScheduleStart, current);
queryWrapper.ge(StrategyControlDataEntity::getScheduleEnd, current);
queryWrapper.orderByAsc(StrategyControlDataEntity::getId);
List<StrategyControlDataEntity> entities = strategyControlInfoMapper.selectList(queryWrapper);
for (StrategyControlDataEntity entity : entities) {
StrategyControlDataEntity result = new StrategyControlDataEntity();
BeanUtils.copyProperties(entity, result);
String time = entity.getTime();
List<StrategyControlDataVO.TimeTable> timeTables = instance.readValue(time, new TypeReference<List<StrategyControlDataVO.TimeTable>>() {});
for (StrategyControlDataVO.TimeTable timeTable : timeTables) {
Integer week = timeTable.getWeek();
int curWeek = DateUtil.getWeek(new Date());
if (curWeek == 0) {
curWeek = 7;
}
if (!Objects.equals(curWeek, week)) {
continue;
}
String[] timeList = timeTable.getTimeList();
for (String s : timeList) {
String[] hours = s.split(",");
for (String hour : hours) {
String[] currentHour = hour.split("-");
String startHour = currentHour[0];
String entHour = currentHour[1];
if (StringUtils.equals("24:00", entHour)) {
entHour = "23:59";
}
String format = DateUtil.format(current, Constants.DATE_FORMAT.E_DATE_FORMAT_HOUR_MINUTE);
Date currentTime = DateUtil.parse(format, "HH:mm");
Date startHourDate = DateUtil.parse(startHour, "HH:mm");
Date endHourDate = DateUtil.parse(entHour, "HH:mm");
if (currentTime.after(startHourDate) && currentTime.before(endHourDate)) {
// 正在执行测策略 0=绿波带,1=失衡,2=溢出,3=空放
Integer strategy = entity.getStrategy();
// 当前策略延长时间
Double lockTime = strategyLockSendVO.getLockTime();
LocalTime lockEndTime = LocalTime.parse(entHour);
if (Objects.equals(lockTime, 0.5)) {
lockEndTime = lockEndTime.plusMinutes(30);
} else {
lockEndTime = lockEndTime.plusHours(lockTime.intValue());
}
log.error("延长之后时间:{}", lockEndTime.toString());
}
}
}
}
}
} catch (Exception e) {
log.error("策略锁定下发失败:{}", e);
return jsonViewObject.success("策略锁定成功");
}
log.error("收到请求参数:{}", strategyLockSendVO);
return jsonViewObject.success("策略锁定成功");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment