// Path: server/src/main/java/com/cloudwise/sap/niping/common/entity/JobDesc.java
// @Data
// @Builder
// public class JobDesc {
// 	private String router;
// 	// 时延
// 	@Builder.Default
// 	private int roundTripTimeB = 1;
// 	@Builder.Default
// 	private int roundTripTimeL = 100;
// 	// 带宽
// 	@Builder.Default
// 	private int bandwidthB = 100000;
// 	@Builder.Default
// 	private int bandwidthL = 10;
// 	// 稳定性
// 	@Builder.Default
// 	private int stabilityB = 200;
// 	@Builder.Default
// 	private int stabilityL = 36000;
// 	@Builder.Default
// 	private int stabilityD = 1000;
// 	// 闲置超时
// 	@Builder.Default
// 	private int idleTimeoutD = 3600000;
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/common/vo/Task.java
// @Data
// @Builder
// public class Task {
// 
//     private String taskId;
//     private String name;
//     private int interval;
//     private String monitorIds;
//     private String monitorNames;
//     private JobDesc jobDesc;
// 
//     private String selectMonitorIdString;
// 
//     private int status;
//     private boolean isAvailable;
// 
//     public enum Status {
//         available(1), partavailable(2), allnotavailable(3), disable(0);
// 
//         @Getter
//         private int status;
// 
//         Status(int status) {this.status = status;}
//     }
// 
//     public Task() {}
// 
//     public Task(String taskId, String name, int interval, String monitorIds, String monitorNames, JobDesc jobDesc, String
//             selectMonitorIdString, int status, boolean isAvailable) {
//         this.taskId = taskId;
//         this.name = name;
//         this.interval = interval;
//         this.monitorIds = monitorIds;
//         this.monitorNames = monitorNames;
//         this.jobDesc = jobDesc;
//         this.selectMonitorIdString = selectMonitorIdString;
//         this.status = status;
//         this.isAvailable = isAvailable;
//     }
// }


import com.cloudwise.sap.niping.common.entity.JobDesc;
import com.cloudwise.sap.niping.common.vo.Task;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jvnet.hk2.annotations.Service;
import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
package com.cloudwise.sap.niping.common.vo.converter;



@Service
public class TaskConverter {

    @Inject
    private ObjectMapper jsonMapper;
    public Optional<List<Task>> convert(Optional<List<com.cloudwise.sap.niping.common.entity.Task>> tasks) {

        Optional<List<Task>> taskVOOptional = Optional.empty();
        if (tasks.isPresent()) {

            List<com.cloudwise.sap.niping.common.entity.Task> tasksList = tasks.get();

            if (CollectionUtils.isNotEmpty(tasksList)) {
                Map<String, List<com.cloudwise.sap.niping.common.entity.Task>> tasksMap = tasksList.stream().collect(Collectors.groupingBy((task)->{return task.getTaskId();}, Collectors.toList()));
                List<Task> tasksVOList = new ArrayList<>(tasksMap.size());
                tasksMap.forEach((key, value) -> {
                    com.cloudwise.sap.niping.common.entity.Task task = value.get(0);
                    try {
                        Task taskVO = Task.builder()
                                .taskId(task.getTaskId())
                                .name(task.getName())
                                .interval(task.getInterval())
// Path: server/src/main/java/com/cloudwise/sap/niping/common/entity/JobDesc.java
// @Data
// @Builder
// public class JobDesc {
// 	private String router;
// 	// 时延
// 	@Builder.Default
// 	private int roundTripTimeB = 1;
// 	@Builder.Default
// 	private int roundTripTimeL = 100;
// 	// 带宽
// 	@Builder.Default
// 	private int bandwidthB = 100000;
// 	@Builder.Default
// 	private int bandwidthL = 10;
// 	// 稳定性
// 	@Builder.Default
// 	private int stabilityB = 200;
// 	@Builder.Default
// 	private int stabilityL = 36000;
// 	@Builder.Default
// 	private int stabilityD = 1000;
// 	// 闲置超时
// 	@Builder.Default
// 	private int idleTimeoutD = 3600000;
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/common/vo/Task.java
// @Data
// @Builder
// public class Task {
// 
//     private String taskId;
//     private String name;
//     private int interval;
//     private String monitorIds;
//     private String monitorNames;
//     private JobDesc jobDesc;
// 
//     private String selectMonitorIdString;
// 
//     private int status;
//     private boolean isAvailable;
// 
//     public enum Status {
//         available(1), partavailable(2), allnotavailable(3), disable(0);
// 
//         @Getter
//         private int status;
// 
//         Status(int status) {this.status = status;}
//     }
// 
//     public Task() {}
// 
//     public Task(String taskId, String name, int interval, String monitorIds, String monitorNames, JobDesc jobDesc, String
//             selectMonitorIdString, int status, boolean isAvailable) {
//         this.taskId = taskId;
//         this.name = name;
//         this.interval = interval;
//         this.monitorIds = monitorIds;
//         this.monitorNames = monitorNames;
//         this.jobDesc = jobDesc;
//         this.selectMonitorIdString = selectMonitorIdString;
//         this.status = status;
//         this.isAvailable = isAvailable;
//     }
// }


// Path: server/src/main/java/com/cloudwise/sap/niping/common/vo/converter/TaskConverter.java
import com.cloudwise.sap.niping.common.entity.JobDesc;
import com.cloudwise.sap.niping.common.vo.Task;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jvnet.hk2.annotations.Service;
import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

package com.cloudwise.sap.niping.common.vo.converter;



@Service
public class TaskConverter {

    @Inject
    private ObjectMapper jsonMapper;
    public Optional<List<Task>> convert(Optional<List<com.cloudwise.sap.niping.common.entity.Task>> tasks) {

        Optional<List<Task>> taskVOOptional = Optional.empty();
        if (tasks.isPresent()) {

            List<com.cloudwise.sap.niping.common.entity.Task> tasksList = tasks.get();

            if (CollectionUtils.isNotEmpty(tasksList)) {
                Map<String, List<com.cloudwise.sap.niping.common.entity.Task>> tasksMap = tasksList.stream().collect(Collectors.groupingBy((task)->{return task.getTaskId();}, Collectors.toList()));
                List<Task> tasksVOList = new ArrayList<>(tasksMap.size());
                tasksMap.forEach((key, value) -> {
                    com.cloudwise.sap.niping.common.entity.Task task = value.get(0);
                    try {
                        Task taskVO = Task.builder()
                                .taskId(task.getTaskId())
                                .name(task.getName())
                                .interval(task.getInterval())
                                .jobDesc(jsonMapper.readValue(task.getConfigJson(), JobDesc.class))