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


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.pojo.param.MonitorAuditParam;
import com.njcn.device.pms.pojo.param.TransformerParam;
import com.njcn.device.pms.pojo.po.Transformer;
import com.njcn.device.pms.service.majornetwork.ITransformerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.njcn.web.controller.BaseController;

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

/**
 * <p>
 * 变压器台账 前端控制器
 * </p>
 *
 * @author wr
 * @since 2023-02-20
 */
@RestController
@RequestMapping("/pms/transformer")
@Api(tags = "变压器台账")
@RequiredArgsConstructor
public class TransformerController extends BaseController {

    private final ITransformerService transformerService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getAllTransformerList")
    @ApiOperation("分页获取变压器台账")
    @ApiImplicitParam(name = "baseParam", required = true)
    public HttpResult<Page<Transformer>> getAllTransformerList(@RequestBody MonitorAuditParam baseParam) {
        String methodDescribe = getMethodDescribe("getAllTransformerList");
        Page<Transformer> monitor = transformerService.getAllTransformerList(baseParam);
        if (Objects.isNull(monitor)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, monitor, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/addTransformer")
    @ApiOperation("添加变压器台账信息")
    @ApiImplicitParam(name = "param", value = "添加变压器台账信息", required = true)
    public HttpResult<Boolean> addTransformer(@RequestBody @Validated TransformerParam param) {
        String methodDescribe = getMethodDescribe("addTransformer");
        boolean result = transformerService.addTransformer(param);
        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("/updateTransformer")
    @ApiOperation("修改变压器台账信息")
    @ApiImplicitParam(name = "param", value = "修改变压器台账数据", required = true)
    public HttpResult<Boolean> updateTransformer(@RequestBody @Validated TransformerParam param) {
        String methodDescribe = getMethodDescribe("updateTransformer");
        boolean result = transformerService.updateTransformer(param);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/delTransformer")
    @ApiOperation("删除变压器台账信息")
    @ApiImplicitParam(name = "ids", value = "删除变电站台账id", required = true)
    public HttpResult<Boolean> delTransformer(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("delTransformer");
        boolean result = transformerService.delTransformer(ids);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);

    }

}

