1. 定时器调整
This commit is contained in:
parent
10ee4f532a
commit
d6d6980820
|
@ -293,6 +293,7 @@ public class AppController extends BaseController
|
|||
@PutMapping("/timer/switch")
|
||||
public AjaxResult isSwitch(@RequestBody AsTimer asTimer)
|
||||
{
|
||||
logger.info("开关定时器传参-----"+JSON.toJSONString(asTimer));
|
||||
return toAjax(asTimerService.isSwitch(asTimer));
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,9 @@ import java.time.Instant;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
|
@ -112,7 +110,7 @@ public class AsTimerServiceImpl implements IAsTimerService
|
|||
Boolean once = ds.getOnce();
|
||||
asTimer1.setMode(once?"1":"2");
|
||||
asTimer1.setDeviceId(asTimer.getDeviceId());
|
||||
asTimer1.setIndex(i);
|
||||
asTimer1.setIndex(ds.getId());
|
||||
//将week将10进制转成2进制
|
||||
asTimer1.setWeek(Integer.toBinaryString(ds.getWeek()));
|
||||
asTimer1.setIsSwitch(ds.getSw());
|
||||
|
@ -266,12 +264,16 @@ public class AsTimerServiceImpl implements IAsTimerService
|
|||
for (Datapoint obj:datapoints) {
|
||||
DatapointValue value = JSONObject.parseObject(obj.getValue().toString(), DatapointValue.class);
|
||||
dsArray = value.getDsArray();
|
||||
OptionalInt indexOpt = findIndexOfDsWithSwitchFalse(dsArray);
|
||||
//清除无效的定时器
|
||||
dsArray = cleanInvalidDs(dsArray);
|
||||
ds = getDsItem(asTimer);
|
||||
if("add".equals(type)){
|
||||
//添加定时器
|
||||
ds.setId(dsArray.size());
|
||||
//添加定时器,找一个sw为false的定时器
|
||||
if (indexOpt.isPresent()) {
|
||||
int index = indexOpt.getAsInt();
|
||||
ds.setId(index);
|
||||
}
|
||||
ds.setSw(true);
|
||||
}else if("edit".equals(type)){
|
||||
//编辑定时器
|
||||
|
@ -292,7 +294,7 @@ public class AsTimerServiceImpl implements IAsTimerService
|
|||
* @return 结果
|
||||
*/
|
||||
@Nullable
|
||||
private List<DatapointValue.Ds> getDsInfo(String token, AsDevice device) throws ParseException {
|
||||
private List<DatapointValue.Ds> getDsInfo(String token, AsDevice device) {
|
||||
/**1.请求onenet获取到该设备的定时器信息*/
|
||||
String param = "device_name=" + device.getMac() + "&product_id=" + productId;
|
||||
String sendUrl = iotUrl+ IotConstants.ADDS_HISTORY_DATAPOINTS + "?"+param;
|
||||
|
@ -329,11 +331,21 @@ public class AsTimerServiceImpl implements IAsTimerService
|
|||
@NotNull
|
||||
private List<DatapointValue.Ds> cleanInvalidDs(List<DatapointValue.Ds> dsArray) {
|
||||
List<DatapointValue.Ds> filteredDsList = dsArray.stream()
|
||||
.filter(ds -> ds.getWeek() != 0)
|
||||
.filter(ds -> ds.getSw())
|
||||
.collect(Collectors.toList());
|
||||
dsArray = new ArrayList<>(filteredDsList);
|
||||
return dsArray;
|
||||
}
|
||||
/**
|
||||
* 找到sw为false的定时器
|
||||
* @param dsArray
|
||||
* @return
|
||||
*/
|
||||
private OptionalInt findIndexOfDsWithSwitchFalse(List<DatapointValue.Ds> dsArray) {
|
||||
return IntStream.range(0, dsArray.size())
|
||||
.filter(i -> !dsArray.get(i).getSw())
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
|
@ -417,10 +429,9 @@ public class AsTimerServiceImpl implements IAsTimerService
|
|||
{
|
||||
return "";
|
||||
}
|
||||
StringBuilder command = null;
|
||||
StringBuilder command = new StringBuilder();
|
||||
for (DatapointValue.Ds ds :dsArray) {
|
||||
command = new StringBuilder()
|
||||
.append("sds").append(ds.getId()).append(IotConstants.COMMAND_SEPARATOR)
|
||||
command.append("sds").append(ds.getId()).append(IotConstants.COMMAND_SEPARATOR)
|
||||
.append("week").append(ds.getWeek()).append(IotConstants.COMMAND_SEPARATOR)
|
||||
.append("hour").append(ds.getHour()).append(IotConstants.COMMAND_SEPARATOR)
|
||||
.append("min").append(ds.getMin()).append(IotConstants.COMMAND_SEPARATOR)
|
||||
|
|
Loading…
Reference in New Issue
Block a user