package com.njcn.energy.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.energy.pojo.param.LineParam;
import com.njcn.energy.pojo.po.EleLine;
import com.njcn.energy.pojo.po.LogicDev;
import com.njcn.energy.service.IEleLineService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/8 14:28
 */
@Slf4j
@RestController
@RequestMapping("/line")
@RequiredArgsConstructor
@Api(tags = "监测点管理")
public class EleLineController extends BaseController {

    private final IEleLineService lineService;

    @PostMapping("/add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增监测点信息")
    @ApiImplicitParam(name = "lineParam", value = "监测点信息", required = true)
    public HttpResult<LogicDev> add(@RequestBody LineParam lineParam){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，监测点信息为：{}", methodDescribe, lineParam);
        EleLine line = lineService.add(lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @PostMapping("/delete")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.DELETE)
    @ApiOperation("删除监测点信息")
    @ApiImplicitParam(name = "list", value = "逻辑装置id集合", required = true)
    public HttpResult<Boolean> delete(@RequestParam List<String> list){
        String methodDescribe = getMethodDescribe("delete");
        LogUtil.njcnDebug(log, "{}，逻辑装置id集合：{}", methodDescribe,list);
        boolean result = lineService.deleteByList(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @GetMapping("/getAllLine")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取所有注册监测点")
    public HttpResult<List<EleLine>> getAllLine(@RequestParam String netDevName){
        String methodDescribe = getMethodDescribe("getAllLine");
        List<EleLine> lineRes = lineService.getAllLine(netDevName);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineRes, methodDescribe);
    }



}
