package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.entity.BusiParamArrester;
import com.huatek.busi.entity.BusiParamGis;
import com.huatek.busi.service.param.BusiParamArresterService;
import com.huatek.busi.service.param.BusiParamGisService;
import com.huatek.busi.vo.BusiParamArresterVo;
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;
import org.springframework.web.bind.annotation.*;

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

/**
 * 避雷器的权重系数维护表 控制层
 *
 * @author vent
 * @date 3 31, 2023 2:57:13 PM
 */
@Api(tags = {Tags.BUSI_ARRESTER})
@Slf4j
@RestController
@RequestMapping("/api/BusiParamArrester")
public class BusiParamArresterController {

    @Reference(check = false)
    private BusiParamArresterService busiParamArresterService;

    @ApiOperation(value = "列表查询", response = BusiParamArresterVo.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<BusiParamArresterVo> busiParamArrester = busiParamArresterService.findBusiParamArrester(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiParamArrester);
    }

    @ApiOperation(value = "计算权重查询", response = BusiParamArresterVo.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<BusiParamArresterVo> list = busiParamArresterService.findNotValueBusiParamArrester(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<BusiParamArrester> busiParamArrester) {
        int count = busiParamArresterService.updateCalculateBusiParam(token, busiParamArrester);
        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<BusiParamArrester> busiParamArrester) {
        int count = busiParamArresterService.updateBusiParamArrester(token, busiParamArrester);
        log.debug("busi param gis update: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @GetMapping(value = "/initBusiParams", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> initBusiParams(@RequestParam("siteId") String siteId,
                                              @RequestParam("mainEquipmentId") String mainEquipmentId) {
        busiParamArresterService.initBusiParams("",siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", null);
    }
}
