package com.huatek.busi.controller;

import java.util.List;
import java.util.Map;

import com.huatek.busi.entity.BusiParamTransformer;
import com.huatek.busi.vo.BusiParamTransformerVo;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.entity.BusiParamGis;
import com.huatek.busi.service.param.BusiParamGisService;
import com.huatek.busi.vo.BusiParamGisVo;
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.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * gis的权重系数维护表 控制层
 *
 * @author anker_cheng
 * @date Jul 12, 2019 2:57:13 PM
 */
@Api(tags = {Tags.BUSI_GIS_PARAM})
@Slf4j
@RestController
@RequestMapping("/api/BusiParamGis")
public class BusiParamGisController {

    @Reference(check = false)
    private BusiParamGisService busiParamGisService;

    @ApiOperation(value = "列表查询", response = BusiParamGisVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "siteId", value = "站点ID"),
        @ApiImplicitParam(name = "mainEquipmentId", value = "主设备ID")
    })
    @GetMapping(value = "/list", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> queryList(@RequestParam("siteId") String siteId,
                                         @RequestParam("mainEquipmentId") String mainEquipmentId) {
        List<BusiParamTransformerVo> busiParamGis = busiParamGisService.findBusiParamGis(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiParamGis);
    }

    @ApiOperation(value = "计算权重查询", response = BusiParamGisVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "siteId", value = "站点ID"),
            @ApiImplicitParam(name = "mainEquipmentId", value = "主设备ID")
    })
    @GetMapping(value = "/notValueList", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> notValueList(@RequestParam("siteId") String siteId,
                                            @RequestParam("mainEquipmentId") String mainEquipmentId) {
        List<BusiParamTransformerVo> list = busiParamGisService.findNotValueBusiParamGis(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }
    @ApiOperation(value = "计算权重参数更新")
    @PostMapping(value = "/updateCalculate", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> updateCalculateBusiSite(String token, @RequestBody List<BusiParamGis> busiParams) {
        int count = busiParamGisService.updateCalculateBusiParam(token, busiParams);
        log.debug("busi param gis update: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @ApiOperation(value = "参数更新")
    @PostMapping(value = "/update", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> updateBusiSite(String token, @RequestBody List<BusiParamGis> busiParams) {
        int count = busiParamGisService.updateBusiParamGis(token, busiParams);
        log.debug("busi param gis update: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }
}
