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.common.utils.LogUtil;
import com.njcn.device.pq.pojo.param.NewStationQueryParam;
import com.njcn.device.pq.pojo.po.NewStation;
import com.njcn.device.pq.service.INewStationService;
import io.swagger.annotations.Api;
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 com.njcn.web.controller.BaseController;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  新能源场站高低电压穿越表 前端控制器
 * </p>
 *
 * @author guofeihu
 * @since 2024-08-14
 */
@Api(tags = "新能源场站高低电压穿越表管理")
@Slf4j
@RestController
@RequestMapping("/newStation")
@RequiredArgsConstructor
public class NewStationController extends BaseController {

    private final INewStationService iNewStationService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.QUERY)
    @PostMapping("/queryPage")
    @ApiOperation("新能源场站高低电压穿越表分页查询")
    public HttpResult<Page<NewStation>> queryPage(@RequestBody @Validated NewStationQueryParam newStationQueryParam){
        String methodDescribe = getMethodDescribe("queryPage");
        Page<NewStation> page = iNewStationService.queryPage(newStationQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/editNewStation")
    @ApiOperation("新能源场站高低电压穿越信息更新")
    public HttpResult<Boolean> editNewStation(@RequestBody @Validated NewStationQueryParam.NewStationEdit newStationEdit) {
        String methodDescribe = getMethodDescribe("editNewStation");
        LogUtil.njcnDebug(log, "{}，更新对象为：{}", methodDescribe, newStationEdit);
        iNewStationService.editNewStation(newStationEdit);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
    @DeleteMapping("/delNewStation")
    @ApiOperation("新能源场站高低电压穿越信息删除")
    public HttpResult<Boolean> delNewStation(@RequestParam(name = "ids") String ids) {
        String methodDescribe = getMethodDescribe("delNewStation");
        LogUtil.njcnDebug(log, "{}，删除的Id的集合为：{}", methodDescribe, ids);
        iNewStationService.delNewStation(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @GetMapping("/selectDown")
    @ApiOperation("获取新能源场站高低电压穿越信息下拉框(用于监测点维护界面)")
    public HttpResult<List<Map>> selectDown(@RequestParam(name = "name",required = false) String name) {
        String methodDescribe = getMethodDescribe("selectDown");
        LogUtil.njcnDebug(log, "{}，远程搜索值为：{}", methodDescribe, name);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, iNewStationService.selectDown(name), methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @GetMapping("/selectById")
    @ApiOperation("根据ID获取新能源场站高低电压穿越表信息")
    public HttpResult<NewStation> selectById(@RequestParam(name = "id") String id) {
        String methodDescribe = getMethodDescribe("selectById");
        LogUtil.njcnDebug(log, "{}，id值为：{}", methodDescribe, id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, iNewStationService.selectById(id), methodDescribe);
    }

}

