package com.njcn.device.pms.controller.ledgerManger;

import cn.hutool.core.collection.CollectionUtil;
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.pms.annotation.TerminalOperationLogDesc;
import com.njcn.device.pms.pojo.dto.PmsStatationStatInfoDTO;
import com.njcn.device.pms.pojo.param.PmsBaseParam;
import com.njcn.device.pms.pojo.param.StatationStatParam;
import com.njcn.device.pms.pojo.param.PmsStatationStatInfoParam;
import com.njcn.device.pms.pojo.param.TerminalQueryParam;
import com.njcn.device.pms.pojo.po.PmsMidLedger;
import com.njcn.device.pms.pojo.po.StatationStat;
import com.njcn.device.pms.pojo.vo.StatationStatVO;
import com.njcn.device.pms.service.majornetwork.IStatationStatService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 电站监测点设置信息
 * </p>
 *
 * @author hongawen
 * @since 2022-10-14
 */
@RestController
@RequestMapping("/pms/statationStat")
@Slf4j
@Api(tags = "台账-变电站")
@RequiredArgsConstructor
public class PmsStatationStatController extends BaseController {

    private final IStatationStatService statationStatService;

    /**
     * 获取监测点信息
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getStatationStat")
    @ApiOperation("获取指定的变电站信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", value = "获取指定的变电站信息条件", required = true)
    })
    public HttpResult<List<PmsStatationStatInfoDTO>> getStatationStatInfo(@RequestBody PmsStatationStatInfoParam param) {
        String methodDescribe = getMethodDescribe("getStatationStatInfo");
        List<PmsStatationStatInfoDTO> monitorInfo = statationStatService.getStatationStatInfo(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, monitorInfo, methodDescribe);
    }

    /*台账部分***************************/

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/addstatationStat")
    @ApiOperation("新增电站")
    @ApiImplicitParam(name = "statationStatParam", value = "电站实体", required = true)
    @TerminalOperationLogDesc(value = "新增电站",module = 0, events = "")
    public HttpResult<Boolean> addstatationStat(@RequestBody @Validated StatationStatParam statationStatParam) {
        String methodDescribe = getMethodDescribe("addstatationStat");
        boolean result = statationStatService.addStatationStat(statationStatParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);



    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/updatestatationStat")
    @ApiOperation("修改电站")
    @ApiImplicitParam(name = "statationStatParam", value = "电站实体", required = true)
    @TerminalOperationLogDesc(value = "修改电站",module = 0)
    public HttpResult<Boolean> updatestatationStat(@RequestBody @Validated StatationStatParam statationStatParam) {
        String methodDescribe = getMethodDescribe("updatestatationStat");
        boolean result = statationStatService.updateStatationStat(statationStatParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @DeleteMapping("/delstatationStat")
    @ApiOperation("删除电站")
    @ApiImplicitParam(name = "statationStatIds", value = "电站ids", required = true)
    @TerminalOperationLogDesc(value = "删除电站",module = 0, events = "")
    public HttpResult<Boolean> delstatationStat(@RequestBody @NotEmpty(message = "电站id不可为空") List<String> statationStatIds) {
        String methodDescribe = getMethodDescribe("delstatationStat");
        boolean result = statationStatService.delStatationStat(statationStatIds);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getstatationStatById")
    @ApiOperation("根据电站id获取电站")
    @ApiImplicitParam(name = "statationStatId", value = "电站id", required = true)
    public HttpResult<StatationStat> getstatationStatById(@RequestParam("statationStatId") String statationStatId) {
        String methodDescribe = getMethodDescribe("getstatationStatById");
        StatationStat result = statationStatService.getStatationStatById(statationStatId);
        if (Objects.nonNull(result)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getstatationStatList")
    @ApiOperation("获取电站列表")
    public HttpResult<List<StatationStat>> getstatationStatList(@RequestBody @Validated PmsBaseParam pmsBaseParam) {
        String methodDescribe = getMethodDescribe("getstatationStatList");
        List<StatationStat> result = statationStatService.getStatationStatList(pmsBaseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getStatationStatPageList")
    @ApiOperation("分页获取电站列表")
    @ApiImplicitParam(name = "baseParam", value = "基本查询体", required = true)
    public HttpResult<Page<StatationStatVO>> getStatationStatPageList(@RequestBody TerminalQueryParam baseParam) {
        String methodDescribe = getMethodDescribe("getStatationStatPageList");
        Page<StatationStatVO> result = statationStatService.getStatationStatPageList(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 获取变电站信息
     *
     * @param param 条件参数
     * @return com.njcn.common.pojo.response.HttpResult<java.util.List < com.njcn.device.pms.pojo.po.PmsStatationStat>>
     * @author yzh
     * @date 2022/11/21
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPowerInfo")
    @ApiOperation("获取变电站信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", value = "条件参数", required = true)
    })
    public HttpResult<List<StatationStat>> getPowerInfo(@RequestBody PmsStatationStatInfoParam param) {
        String methodDescribe = getMethodDescribe("getPowerInfo");
        List<StatationStat> powerInfo = statationStatService.getPowerInfo(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, powerInfo, methodDescribe);
    }

    /**
     * 通过isc单位获取该组织下的电站信息
     * @author cdf
     * @date 2023/12/15
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getStationByDeptCode")
    @ApiOperation("通过isc单位获取该组织下的电站信息")
    @ApiImplicitParam(name = "deptCode", value = "isc单位code", required = true)
    public HttpResult<List<PmsMidLedger>> getStationByDeptCode(@RequestParam("deptCode") String deptCode) {
        String methodDescribe = getMethodDescribe("getStationByDeptCode");
        List<PmsMidLedger> pmsMidLedgerList = statationStatService.getStationByDeptCode(deptCode);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pmsMidLedgerList, methodDescribe);
    }


    /**
     * 批量同步中台电站id
     * @author cdf
     * @date 2023/12/19
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/batchSync")
    @ApiOperation("批量同步中台电站id")
    public HttpResult<Boolean> batchSync() {
        String methodDescribe = getMethodDescribe("batchSync");
        statationStatService.batchSync();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }






}

