package com.huatek.busi.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.GisOfflineExperimentReportDto;
import com.huatek.busi.service.gis.GisOfflineExperimentReportService;
import com.huatek.busi.vo.routinetest.gis.GisOfflineExperimentReportVo;
import com.huatek.busi.vo.warning.BusiHomePageWarningVo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * Gis离线试验报告Controller
 * 
 * @author anker_cheng
 * @date 2019/08/24
 */
@Api(tags = {Tags.GIS_OFFLINE_EXPERIMENT_REPORT})
@Slf4j
@RestController
@RequestMapping("/api/GisOfflineExperimentReport")
public class GisOfflineExperimentReportController {
    @Reference(check = false)
    private GisOfflineExperimentReportService gisOfflineExperimentReportService;

    @ApiOperation(value = "Gis离线试验报告列表查询", response = GisOfflineExperimentReportVo.class)
    @PostMapping("/queryList")
    public Map<String, Object> queryList(@RequestBody GisOfflineExperimentReportDto param) {
        PageInfo<GisOfflineExperimentReportVo> pageInfo =
            gisOfflineExperimentReportService.findGisOfflineExperimentReportList(param);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, pageInfo.getTotal(), "", pageInfo.getList());
    }

    @ApiOperation(value = "获取Gis离线试验报告", response = GisOfflineExperimentReportVo.class)
    @GetMapping("/getGisOfflineExperimentReport")
    public Map<String, Object> getGisOfflineExperimentReport(@RequestParam("id") String id) {
        GisOfflineExperimentReportVo vo = gisOfflineExperimentReportService.getGisOfflineExperimentReport(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
    }

    @ApiOperation("保存Gis离线试验报告")
    @PostMapping("/saveGisOfflineExperimentReport")
    public Map<String, Object> saveGisOfflineExperimentReport(@RequestHeader("token") String token,
        @RequestBody GisOfflineExperimentReportDto param) {
        int count = gisOfflineExperimentReportService.saveGisOfflineExperimentReport(token, param);
        log.debug("saveGisOfflineExperimentReport: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @ApiOperation(value = "GIS例行试验详情(告警界面链接调用)", response = BusiHomePageWarningVo.class)
    @ApiImplicitParam(name = "mainTreeId", value = "GIS树ID", required = false)
    @GetMapping(value = "/getByTreeId")
    public Map<String, Object> getByTreeId(@RequestParam(value = "mainTreeId", required = false) String mainTreeId){
        GisOfflineExperimentReportVo vo = gisOfflineExperimentReportService.getByTreeId(mainTreeId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
    }
}
