package com.njcn.device.pq.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.device.pq.pojo.dto.transformer.EntityLogicDTO;
import com.njcn.device.pq.pojo.param.PqsTransformerParam;
import com.njcn.device.pq.pojo.vo.PqsTflgassVO;
import com.njcn.device.pq.pojo.vo.PqsTransformerVO;
import com.njcn.device.pq.pojo.vo.TerminalTree;
import com.njcn.device.pq.service.IPqsTransformerService;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.njcn.web.controller.BaseController;

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

/**
 * <p>
 *  变压器查询
 * </p>
 *
 * @author wr
 * @since 2023-07-19
 */
@Api(tags = "变压器详细")
@RestController
@RequestMapping("/pqsTransformer")
@RequiredArgsConstructor
public class PqsTransformerController extends BaseController {

    private final IPqsTransformerService iPqsTransformerService;

    @PostMapping("/transformerPage")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("变压器台账分页查询")
    public HttpResult<Page<PqsTransformerVO>> transformerPage(@RequestBody BaseParam param) {
        String methodDescribe = getMethodDescribe("transformerPage");
        Page<PqsTransformerVO> page = iPqsTransformerService.transformerPage(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @PostMapping("/insertTransformer")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @ApiOperation("变压器台账新增")
    public HttpResult<Boolean> insertTransformer(@RequestBody @Validated PqsTransformerParam.TransformerAddParam param) {
        String methodDescribe = getMethodDescribe("insertTransformer");
        Boolean flag = iPqsTransformerService.insertTransformer(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @PostMapping("/updateTransformer")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @ApiOperation("变压器台账修改")
    public HttpResult<Boolean> updateTransformer(@RequestBody @Validated PqsTransformerParam.TransformerUpdateParam  param) {
        String methodDescribe = getMethodDescribe("updateTransformer");
        Boolean flag = iPqsTransformerService.updateTransformer(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @PostMapping("/delTransformer")
    @ApiOperation(value = "变压器台账删除")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    public HttpResult<Boolean> delTransformer(@RequestBody  List<String> ids) {
        String methodDescribe = getMethodDescribe("delTransformer");
        Boolean flag = iPqsTransformerService.delTransformer(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @PostMapping("/selectFlgAss")
    @ApiOperation(value = "查询变电站节点信息")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<PqsTflgassVO> selectFlgAss(@RequestBody String id) {
        String methodDescribe = getMethodDescribe("selectFlgAss");
        PqsTflgassVO pqsTflgassVO = iPqsTransformerService.selectFlgAss(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsTflgassVO, methodDescribe);
    }

    @PostMapping("/nodeMaintenance")
    @ApiOperation(value = "变电站节点维护")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<Boolean> nodeMaintenance(@RequestBody @Validated PqsTransformerParam param) {
        String methodDescribe = getMethodDescribe("nodeMaintenance");
        Boolean flag = iPqsTransformerService.nodeMaintenance(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @GetMapping("/getGeneratrix")
    @ApiOperation(value = "获取上下节点信息")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<Map<String, Object>> getGeneratrix(String subId,String id) {
        String methodDescribe = getMethodDescribe("getGeneratrix");
        Map<String, Object> generatrix = iPqsTransformerService.getGeneratrix(subId,id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, generatrix, methodDescribe);
    }

    @GetMapping("/getTransformerTree")
    @ApiOperation(value = "获取变压器台账")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<List<TerminalTree>> getTransformerTree() {
        String methodDescribe = getMethodDescribe("getTransformerTree");
        List<TerminalTree> terminalTree = iPqsTransformerService.getTransformerTree();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, terminalTree, methodDescribe);
    }

    @GetMapping("/getLogic")
    @ApiOperation(value = "获取变压器策略详情")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<List<EntityLogicDTO>> getLogic() {
        String methodDescribe = getMethodDescribe("getLogic");
        List<EntityLogicDTO> entityLogicDTOList = iPqsTransformerService.getLogic();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, entityLogicDTOList, methodDescribe);
    }

}

