//package com.friday.tooldriver.controller;
//
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.friday.base.common.response.DubboResult;
//import com.friday.base.web.response.ResponseAspect;
//import com.friday.tooldriver.service.rpa.driverimpl.INFODATORDriverServiceImpl;
//import com.friday.tooldriver.service.rpa.supplier.INFODATORService;
//import com.friday.operation.api.tooldriver.dto.common.DriverBase;
//import com.friday.operation.api.tooldriver.dto.rpa.*;
//import com.friday.tooldriver.exception.DriverBusinessException;
//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;
//import java.util.List;
//
//@RestController
//@RequestMapping(value = "driver/infodator")
//@Slf4j
//public class InfodatorDriverController {
//
//    @Autowired
//    private ResponseAspect responseAspect;
//    @Autowired
//    private INFODATORDriverServiceImpl infodatorDriverService;
//    @Autowired
//    private INFODATORService infodatorService;
//
//    @RequestMapping(value = "/getToken", method = RequestMethod.POST)
//    public Object getToken(@RequestBody JSONObject jsonObject) throws DriverBusinessException {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        String result = infodatorService.authenticate(driverBase);
//        return this.responseAspect.success(result);
//    }
//
//    @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"))
//                .build();
//        DubboResult<GroupDto> result = infodatorDriverService.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();
//        GroupFilter filter = new GroupFilter();
//        if (jsonObject.getString("name") != null) {
//            filter.setName(jsonObject.getString("name"));
//        }
//        DubboResult<ArrayList<GroupDto>> result = infodatorDriverService.queryGroups(driverBase, filter);
//        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 = infodatorDriverService.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 = infodatorDriverService.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()
//                .filePath(jsonObject.getString("filePath"))
//                .name(jsonObject.getString("name"))
//                .build();
//        DubboResult<CodePackageDto> result = infodatorDriverService.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 = infodatorDriverService.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 = infodatorDriverService.queryPackages(driverBase, filter);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryPackageByKey", method = RequestMethod.POST)
//    public Object queryPackageByKey(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        DubboResult result = infodatorDriverService.queryPackageByKey(driverBase, jsonObject.getString("packageKey"));
//        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 = infodatorDriverService.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("processKey"))
//                .processVersion(jsonObject.getString("processVersion"))
//                .build();
//        DubboResult<ReleaseDto> result = infodatorDriverService.releaseProcess(driverBase, release);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryProcessReleases", method = RequestMethod.POST)
//    public Object queryProcessReleases(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .groupKey(jsonObject.getString("groupKey"))
//                .build();
//        ReleaseFilter filter = new ReleaseFilter();
//        filter.setName(jsonObject.getString("name"));
//        DubboResult<ArrayList<ReleaseDto>> result = infodatorDriverService.queryProcessReleases(driverBase, filter);
//        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 = infodatorDriverService.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 = infodatorDriverService.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()
//                .name(jsonObject.getString("name"))
//                .machineCode(jsonObject.getString("machineCode"))
//                .build();
//        DubboResult<RobotDto> result = infodatorDriverService.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 = infodatorDriverService.deleteRobotByKey(driverBase, jsonObject.getString("robotKey"));
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//    @RequestMapping(value = "/queryRobots", method = RequestMethod.POST)
//    public Object queryRobots(@RequestBody JSONObject jsonObject) {
//        DriverBase driverBase = DriverBase.builder()
//                .tenantKey(jsonObject.getString("tenant"))
//                .build();
//        RobotFilter filter = new RobotFilter();
//        filter.setName(jsonObject.getString("name"));
//        filter.setState(jsonObject.getString("state"));
//        DubboResult<ArrayList<RobotDto>> result = infodatorDriverService.queryRobots(driverBase, filter);
//        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 = infodatorDriverService.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 = infodatorDriverService.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 = infodatorDriverService.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()
//                .robotKey(jsonObject.getString("robotKey"))
//                .build();
//        DubboResult result = infodatorDriverService.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()
//                .robotKey(jsonObject.getString("robotKey"))
//                .build();
//        DubboResult result = infodatorDriverService.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 = infodatorDriverService.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 = infodatorDriverService.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 = infodatorDriverService.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 = infodatorDriverService.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 = infodatorDriverService.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();
//        String jobIdStr = jsonObject.getString("jobIdList");
//        List<String> jobIdList = JSONArray.parseArray(jobIdStr, String.class);
//        DubboResult result = infodatorDriverService.stopJobs(driverBase, jobIdList);
//        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 = infodatorDriverService.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 = infodatorDriverService.queryJobs(driverBase, filter);
//        if (result.success()){
//            return this.responseAspect.success(result.getObject());
//        } else {
//            return this.responseAspect.fail(result.getMessage());
//        }
//    }
//
//}