package com.huatek.busi.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.dto.BusiDrivepipeEvaluationResultsDto;
import com.huatek.busi.entity.BusiSiteTree;
import com.huatek.busi.entity.GisAssessmentResult;
import com.huatek.busi.service.BusiSiteTreeService;
import com.huatek.busi.service.ITransformerEvaluationService;
import com.huatek.busi.service.gis.GisAssessService;
import com.huatek.busi.service.gis.GisManualAssessmentService;
import com.huatek.busi.vo.BusiTreeNodeVo;
import com.huatek.frame.base.util.BeanUtils;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags={"算法计算管理接口"})
@RestController
@RequestMapping("/api/evaluation")
public class EvaluationController {

    @Reference(check = false)
    ITransformerEvaluationService transformerEvaluationService;

    @Reference(check = false)
    GisAssessService gisAssessService;

    @Reference(check = false)
    GisManualAssessmentService gisManualAssessmentService;

    @Reference(check = false)
    BusiSiteTreeService busiSiteTreeService;

    @ApiOperation(value = "变压器算法计算",httpMethod="POST", notes= "变压器算法计算", produces = "application/json;charset=utf-8", response= Map.class)
    @PostMapping(value = "/transformerEvaluation", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> transformerEvaluation(@RequestHeader("token") String token,
                                                     @RequestParam("siteId") String siteId,
                                                     @RequestParam("mainEquipmentId") String mainEquipmentId){
        return transformerEvaluationService.transformerEvaluation(token, siteId, mainEquipmentId);
    }

    @ApiOperation(value = "套管算法计算",httpMethod="POST", notes= "套管算法计算", produces = "application/json;charset=utf-8", response= Map.class)
    @PostMapping(value = "/drivepipeDiagnosis", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> drivepipeDiagnosis(@RequestHeader("token") String token,
                                                   @RequestBody BusiDrivepipeEvaluationResultsDto dto){
        return transformerEvaluationService.drivepipeDiagnosis(token, dto);
    }

    @ApiOperation(value = "gis算法计算",httpMethod="POST", notes= "GIS算法计算", produces = "application/json;charset=utf-8", response= Map.class)
    @PostMapping(value = "/getGisAssessmentResult")
    public Map<String, Object> getGisAssessmentResult(@RequestParam("siteId") String siteId, @RequestParam ("mainTreeId") String mainTreeId) {
//        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", gisAssessService.assessmentByGis(siteId, mainTreeId));
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", gisManualAssessmentService.assessmentByGis(siteId, mainTreeId));
    }

    @ApiOperation(value = "半自动-gis算法计算",httpMethod="POST", notes= "半自动-GIS算法计算", produces = "application/json;charset=utf-8", response= Map.class)
    @PostMapping(value = "/getSemiAutomaticEvaluateResult")
    public Map<String, Object> semiAutomaticEvaluate(@RequestParam("siteId") String siteId, @RequestParam ("mainTreeId") String mainTreeId) {
        gisAssessService.semiAutoAssessmentForGis(siteId, mainTreeId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @ApiOperation(value = "半自动-变压器算法计算",httpMethod="POST", notes= "半自动-变压器算法计算", produces = "application/json;charset=utf-8", response= Map.class)
    @PostMapping(value = "/transformerSemiAutomaticEvaluation", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> transformerSemiAutomaticEvaluation( @RequestParam("siteId") String siteId,
                                                     @RequestParam("mainEquipmentId") String mainEquipmentId){
        transformerEvaluationService.transformerSemiAutomaticEvaluation(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "BUSINESS.QUERY.SUCCESS", null);
    }
}
