//package com.friday.tooldriver.controller;
//
//import com.alibaba.fastjson.JSONObject;
//import com.google.common.collect.Lists;
//import com.friday.base.common.response.DubboResult;
//import com.friday.base.web.response.ResponseAspect;
//import com.friday.operation.api.tooldriver.dto.common.DriverBase;
//import com.friday.operation.api.tooldriver.dto.rpa.*;
//import com.friday.operation.api.tooldriver.service.ICapabilityDriver;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.ArrayList;
//
//@RestController
//@RequestMapping(value = "/driver")
//@Slf4j
//public class CapabilityDriverController {
//
//    @Autowired
//    private ResponseAspect responseAspect;
//    @Autowired
//    private ICapabilityDriver capabilityDriver;
//
//    @RequestMapping(value = "/createGroup", method = RequestMethod.POST)
//    public Object createGroup(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        GroupDto group = GroupDto.builder()
//                .name(jsonObject.getString("name"))
//                .description(jsonObject.getString("description"))
//                .parentKey(jsonObject.getString("parentKey"))
//                .build();
//        DubboResult<GroupDto> result = capabilityDriver.createGroup(driverBase, group);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryGroups", method = RequestMethod.POST)
//    public Object queryGroups(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult<ArrayList<GroupDto>> result = capabilityDriver.queryGroups(driverBase, new GroupFilter());
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryGroupByKey", method = RequestMethod.POST)
//    public Object queryGroupByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult<GroupDto> result = capabilityDriver.queryGroupByKey(driverBase, jsonObject.getString("groupKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/deleteGroupByKey", method = RequestMethod.POST)
//    public Object deleteGroupByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult<GroupDto> result = capabilityDriver.deleteGroupByKey(driverBase, jsonObject.getString("groupKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/uploadPackage", method = RequestMethod.POST)
//    public Object uploadPackage(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        CodePackageDto codePackageDto = CodePackageDto.builder()
//                .name(jsonObject.getString("name"))
//                .filePath(jsonObject.getString("filePath"))
//                .build();
//        DubboResult<CodePackageDto> result = capabilityDriver.uploadPackage(driverBase, codePackageDto);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/deletePackageByKey", method = RequestMethod.POST)
//    public Object deletePackageByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult result = capabilityDriver.deletePackageByKey(driverBase, jsonObject.getString("packageKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryPackages", method = RequestMethod.POST)
//    public Object queryPackages(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        CodePackageFilter filter = new CodePackageFilter();
//        filter.setName(jsonObject.getString("name"));
//        DubboResult<ArrayList<CodePackageDto>> result = capabilityDriver.queryPackages(driverBase, filter);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/downloadPackageByKey", method = RequestMethod.POST)
//    public Object downloadPackageByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult result = capabilityDriver.downloadPackageByKey(driverBase, jsonObject.getString("packageKey"), jsonObject.getString("fileName"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/releaseProcess", method = RequestMethod.POST)
//    public Object releaseProcess(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        ReleaseDto release = ReleaseDto.builder()
//                .name(jsonObject.getString("name"))
//                .description(jsonObject.getString("description"))
//                .codePackageName(jsonObject.getString("codePackageName"))
//                .processVersion(jsonObject.getString("processVersion"))
//                .processType(jsonObject.getString("processType"))
//                .key(jsonObject.getString("key"))
//                .build();
//        DubboResult<ReleaseDto> result = capabilityDriver.releaseProcess(driverBase, release);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/deleteProcessReleaseByKey", method = RequestMethod.POST)
//    public Object deleteProcessReleaseByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        DubboResult result = capabilityDriver.deleteProcessReleaseByKey(driverBase, jsonObject.getString("releaseKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryProcessReleaseByKey", method = RequestMethod.POST)
//    public Object queryProcessReleaseByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        DubboResult<ReleaseDto> result = capabilityDriver.queryProcessReleaseByKey(driverBase, jsonObject.getString("releaseKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/createRobot", method = RequestMethod.POST)
//    public Object createRobot(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        RobotDto robot = RobotDto.builder()
//                .type(jsonObject.getString("type"))
//                .name(jsonObject.getString("name"))
//                .whoAmI(jsonObject.getString("whoAmI"))
//                .password(jsonObject.getString("password"))
//                .ip(jsonObject.getString("ip"))
//                .userName(jsonObject.getString("userName"))
//                .build();
//        DubboResult<RobotDto> result = capabilityDriver.createRobot(driverBase, robot);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/deleteRobotByKey", method = RequestMethod.POST)
//    public Object deleteRobotByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult result = capabilityDriver.deleteRobotByKey(driverBase, jsonObject.getString("robotKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryRobotByKey", method = RequestMethod.POST)
//    public Object queryRobotByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult<RobotDto> result = capabilityDriver.queryRobotByKey(driverBase, jsonObject.getString("robotKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/assignRobotToGroup", method = RequestMethod.POST)
//    public Object assignRobotToGroup(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult result = capabilityDriver.assignRobotToGroup(driverBase, jsonObject.getString("robotKey"), jsonObject.getString("groupKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/removeRobotFromGroup", method = RequestMethod.POST)
//    public Object removeRobotFromGroup(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult result = capabilityDriver.removeRobotFromGroup(driverBase, jsonObject.getString("robotKey"), jsonObject.getString("groupKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/enableLicense", method = RequestMethod.POST)
//    public Object enableLicense(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        LicenseDto license = LicenseDto.builder()
//                .whoAmI(jsonObject.getString("whoAmI"))
//                .licenseType(jsonObject.getString("licenseType"))
//                .robotKey(jsonObject.getString("robotKey"))
//                .build();
//        DubboResult result = capabilityDriver.enableLicense(driverBase, license);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/disableLicense", method = RequestMethod.POST)
//    public Object disableLicense(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        LicenseDto license = LicenseDto.builder()
//                .whoAmI(jsonObject.getString("whoAmI"))
//                .licenseType(jsonObject.getString("licenseType"))
//                .robotKey(jsonObject.getString("robotKey"))
//                .build();
//        DubboResult result = capabilityDriver.disableLicense(driverBase, license);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/startJob", method = RequestMethod.POST)
//    public Object startJob(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        StartJobDto startJob = StartJobDto.builder()
//                .inputArguments(jsonObject.getString("inputArguments"))
//                .processReleaseKey(jsonObject.getString("processReleaseKey"))
//                .robotKey(jsonObject.getString("robotKey"))
//                .build();
//        DubboResult<JobDto> result = capabilityDriver.startJob(driverBase, startJob);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/restartJob", method = RequestMethod.POST)
//    public Object restartJob(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        DubboResult<JobDto> result = capabilityDriver.restartJob(driverBase, jsonObject.getString("jobKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/pauseJob", method = RequestMethod.POST)
//    public Object pauseJob(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        DubboResult result = capabilityDriver.pauseJob(driverBase, jsonObject.getString("jobKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/resumeJob", method = RequestMethod.POST)
//    public Object resumeJob(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        DubboResult result = capabilityDriver.resumeJob(driverBase, jsonObject.getString("jobKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/stopJob", method = RequestMethod.POST)
//    public Object stopJob(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        DubboResult result = capabilityDriver.stopJob(driverBase, jsonObject.getString("jobKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/stopJobs", method = RequestMethod.POST)
//    public Object stopJobs(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        DubboResult result = capabilityDriver.stopJobs(driverBase, Lists.newArrayList(jsonObject.getString("jobKey1"), jsonObject.getString("jobKey2"), jsonObject.getString("jobKey3")));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryJobByKey", method = RequestMethod.POST)
//    public Object queryJobByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        DubboResult<JobDto> result = capabilityDriver.queryJobByKey(driverBase, jsonObject.getString("jobKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryJobs", method = RequestMethod.POST)
//    public Object queryJobs(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        JobFilter filter = new JobFilter();
//        filter.setState(jsonObject.getString("state"));
//        DubboResult<ArrayList<JobDto>> result = capabilityDriver.queryJobs(driverBase, filter);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//}