package com.base.plan.controller;

import com.base.orbit.web.Result;
import com.base.plan.mapper.AreaOptimizationResultInfoMapper;
import com.base.plan.mapper.FzIndicatorInfoMapper;
import com.base.plan.model.dto.*;
import com.base.plan.model.dto.request.*;
import com.base.plan.mq.service.PlanMqService;
import com.base.plan.service.PlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(value = "plan")
@RequestMapping("/api/plan")
public class PlanController {

    @Resource
    PlanService planService;

    @Resource
    PlanMqService planMqService;

    @Resource
    AreaOptimizationResultInfoMapper areaOptimizationResultInfoMapper;

    @Resource
    FzIndicatorInfoMapper fzIndicatorInfoMapper;


    @ApiOperation(value = "数传方案优选")
    @PostMapping("/make")
    public Object makePlan(@RequestBody TaskContainDatatransReqDTO req) {
        return Result.success(planService.makePlan(req));
    }

    @ApiOperation(value = "任务方案查询", response = PlanDTO.class)
    @PostMapping("/list")
    public Object getPlanDTOList(@RequestBody PlanReqDTO req) {
        return Result.success(planService.getPlanDTOList(req));
    }

    @ApiOperation(value = "任务下发")
    @PostMapping("/publish")
    public Object publishPlan(@RequestBody PlanReqDTO req) {
        List<PlanDTO> planDTOS = planService.getPlanDTOList(req);
        //  任务下发
        planMqService.sendTask(planDTOS);
        return Result.success();
    }

    @ApiOperation(value = "指标查询", response = FzSystemIndicatorDTO.class)
    @PostMapping("/indicator/detail")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = FzSystemIndicatorDTO.class)
    })
    public Object getFzIndicatorDTOList(@RequestBody IndicatorReqDTO req) {
        return Result.success(planService.getFzSystemIndicatorDTO(req));
    }

    @ApiOperation(value = "指标下发", response = FzSystemIndicatorDTO.class)
    @PostMapping("/indicator/send")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = FzSystemIndicatorDTO.class)
    })
    public Object sendFzIndicatorDTOList(@RequestBody IndicatorReqDTO req) {
        FzSystemIndicatorDTO fzSystemIndicatorDTO = planService.getFzSystemIndicatorDTO(req);
        //  指标下发
        planMqService.sendIndicator(fzSystemIndicatorDTO);
        return Result.success();
    }

    @ApiOperation(value = "计划定制列表查询", response = PlanMakeDTO.class)
    @PostMapping("/satellite/and/trbut/list")
    public Object getSatelliteAndTrbutPlan(@RequestBody PlanMakeReqDTO req) {
        return Result.success(planService.getPlanMakeDTO(req));
    }


    @PostMapping("/trbut/reset")
    public Object resetTrbutPlan(@RequestBody ResetTrbutPlanDTO resetTrbutPlanDTO) {
        if (CollectionUtils.isEmpty(resetTrbutPlanDTO.getStripIdList()) && CollectionUtils.isEmpty(resetTrbutPlanDTO.getReqIds())) {
            return Result.error("必要参数不能为空！");
        }
        planService.resetTrbutPlan(resetTrbutPlanDTO.getStripIdList(), resetTrbutPlanDTO.getReqIds());
        return Result.success();
    }

    @PostMapping("/reset")
    public Object resetPlan(@RequestBody ResetPlanDTO resetPlanDTO) {
        planService.resetPlan(resetPlanDTO.getReqIdList());
        return Result.success();
    }
}