package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.entity.BusiParamAppendix;
import com.huatek.busi.entity.BusiParamArrester;
import com.huatek.busi.service.param.BusiParamAppendixService;
import com.huatek.busi.service.param.BusiParamArresterService;
import com.huatek.busi.vo.BusiParamAppendixVo;
import com.huatek.busi.vo.BusiParamArresterVo;
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_APPENDIX})
@Slf4j
@RestController
@RequestMapping("/api/BusiParamAppendix")
public class BusiParamAppendixController {

    @Reference(check = false)
    private BusiParamAppendixService busiParamAppendixService;

    @ApiOperation(value = "列表查询", response = BusiParamAppendixVo.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<BusiParamAppendixVo> busiParamAppendixVo = busiParamAppendixService.findBusiParamAppendix(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiParamAppendixVo);
    }

    @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<BusiParamAppendixVo> list = busiParamAppendixService.findNotValueBusiParamAppendix(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<BusiParamAppendix> busiParamAppendix) {
        int count = busiParamAppendixService.updateCalculateBusiParam(token, busiParamAppendix);
        log.debug("busi param fujian 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<BusiParamAppendix> busiParamAppendix) {
        int count = busiParamAppendixService.updateBusiParamAppendix(token, busiParamAppendix);
        log.debug("busi param fujian 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) {
        busiParamAppendixService.initBusiParams("",siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", null);
    }
}
