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.annotation.TerminalOperationLogDesc;
import com.njcn.device.pms.pojo.param.PowerClientParam;
import com.njcn.device.pms.pojo.param.PowerUserParam;
import com.njcn.device.pms.pojo.po.PowerClient;
import com.njcn.device.pms.pojo.vo.PowerClientVO;
import com.njcn.device.pms.service.majornetwork.IPowerClientService;
import com.njcn.web.pojo.param.BaseParam;
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.*;

import com.njcn.web.controller.BaseController;

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

/**
 * <p>
 *  用电用户控制器
 * </p>
 *
 * @author hongawen
 * @since 2022-10-14
 */
@RestController
@RequestMapping("/pms/powerClient")
@RequiredArgsConstructor
@Api(tags = "台账-用电用户")
public class PmsPowerClientController extends BaseController {

    private final IPowerClientService iPowerClientService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/addPowerClient")
    @ApiOperation("新增用电用户")
    @ApiImplicitParam(name = "powerClientParam", value = "用电用户实体", required = true)
    @TerminalOperationLogDesc(value = "新增用电用户",module = 5)
    public HttpResult<Boolean> addPowerClient(@RequestBody @Validated PowerClientParam powerClientParam) {
        String methodDescribe = getMethodDescribe("addPowerClient");
        boolean result = iPowerClientService.addPowerClient(powerClientParam);
        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("/updatePowerClient")
    @ApiOperation("修改用电用户")
    @ApiImplicitParam(name = "powerClientParam", value = "用电用户实体", required = true)
    @TerminalOperationLogDesc(value = "修改用电用户",module = 5)
    public HttpResult<Boolean> updatePowerClient(@RequestBody @Validated PowerClientParam powerClientParam) {
        String methodDescribe = getMethodDescribe("updatePowerClient");
        boolean result = iPowerClientService.updatePowerClient(powerClientParam);
        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("/delPowerClient")
    @ApiOperation("删除用电用户")
    @ApiImplicitParam(name = "powerClientIds", value = "用电用户ids", required = true)
    @TerminalOperationLogDesc(value = "删除用电用户",module = 5)
    public HttpResult<Boolean> delPowerClient(@RequestBody @NotEmpty(message = "用电用户id不可为空") List<String> powerClientIds) {
        String methodDescribe = getMethodDescribe("delPowerClient");
        boolean result = iPowerClientService.delPowerClient(powerClientIds);
        if(result){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getPowerClientById")
    @ApiOperation("根据用电用户id获取用电用户")
    @ApiImplicitParam(name = "powerClientId", value = "用电用户id", required = true)
    public HttpResult<PowerClient> getPowerClientById(@RequestParam("powerClientId") String powerClientId) {
        String methodDescribe = getMethodDescribe("getPowerClientById");
        PowerClient result = iPowerClientService.getPowerClientById(powerClientId);
        if(Objects.nonNull(result)){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPowerClientList")
    @ApiOperation("获取用电用户列表")
    public HttpResult<List<PowerClientVO>> getPowerClientList(@RequestBody PowerClientParam powerClientParam) {
        String methodDescribe = getMethodDescribe("getPowerClientList");
        List<PowerClientVO> result = iPowerClientService.getPowerClientList(powerClientParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

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

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getPowerUtilizationUserList")
    @ApiOperation("获取用户列表")
    @ApiImplicitParam(name = "powerUserParam", value = "参数", required = true)
    public HttpResult<List<PowerClient>> getPowerUtilizationUserList(@RequestBody PowerUserParam powerUserParam) {
        String methodDescribe = getMethodDescribe("getPowerUtilizationUserList");
        List<PowerClient> result = iPowerClientService.getPowerUtilizationUserList(powerUserParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }

}

