package com.njcn.device.pq.controller.jb;


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.PowerGenerationUserParam;
import com.njcn.device.pq.pojo.po.jb.GenerationUser;
import com.njcn.device.pq.service.IPowerGenerationUserService;
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.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

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

    private final IPowerGenerationUserService iPowerGenerationUserService;

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

    }

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


}

