package com.njcn.device.userledger.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.device.pq.pojo.param.TerminalCheckParam;
import com.njcn.device.userledger.service.UserLedgerService;
import com.njcn.supervision.pojo.param.SensitiveUserParam;
import com.njcn.supervision.pojo.param.user.UserReportParam;
import com.njcn.supervision.pojo.po.file.FileUrl;
import com.njcn.supervision.pojo.po.user.UserReportPO;
import com.njcn.supervision.pojo.vo.user.NewUserReportVO;
import com.njcn.supervision.pojo.vo.user.UserLedgerVO;
import com.njcn.supervision.pojo.vo.user.UserReportVO;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.Terminal;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 干扰源用户管理
 *
 * @author qijian
 * @version 1.0.0
 * @createTime 2022/11/11 - 9:20
 */
@Slf4j
@RestController
@RequestMapping("/userReport")
@Api(tags = "干扰源用户管理")
@AllArgsConstructor
public class UserLedgerController extends BaseController {

    private final UserLedgerService userReportPOService;


    @PostMapping(value = "/selectUserList")
    @ApiOperation("查询用户台账")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<List<UserLedgerVO>> selectUserList(@RequestBody UserReportParam userReportParam) {
        String methodDescribe = getMethodDescribe("selectUserList");
        List<UserLedgerVO> b = userReportPOService.selectUserList(userReportParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }

    @GetMapping(value = "/selectUserInfo")
    @ApiOperation("查询用户基本详情")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<UserLedgerVO> selectUserInfo(@RequestParam String id) {
        String methodDescribe = getMethodDescribe("selectUserInfo");
        UserLedgerVO b = userReportPOService.selectUserInfo(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }


    @PostMapping(value = "/bindUserStation")
    @ApiOperation("绑定用户电站信息")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<List<UserLedgerVO>> bindUserStation(@RequestParam("userId")String userId,@RequestParam("stationId")String stationId) {
        String methodDescribe = getMethodDescribe("bindUserStation");
        userReportPOService.bindUserStation(userId,stationId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }


    @PostMapping("/getUserReportByIds")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据ids获取非电网侧用户信息")
    public HttpResult<List<NewUserReportVO>> getUserReportByIds(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("getUserReportByIds");
        List<NewUserReportVO> userReportByIds = userReportPOService.getUserReportByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userReportByIds, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getSensitiveUserByDept")
    @ApiOperation("根据部门获取敏感用户信息")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<List<UserReportPO>> getSensitiveUserByDept(@RequestBody @Validated SensitiveUserParam param) {
        String methodDescribe = getMethodDescribe("getSensitiveUserByDept");
        List<UserReportPO> list = userReportPOService.getSensitiveUserByDept(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getUserLedgerPage")
    @ApiOperation("分页查询干扰源用户台账")
    @ApiImplicitParam(name = "userReportQueryParam", value = "参数", required = true)
    public HttpResult<Page<UserReportVO>> getUserLedgerPage(@RequestBody @Validated UserReportParam.UserReportQueryParam userReportQueryParam) {
        String methodDescribe = getMethodDescribe("getUserLedgerPage");
        Page<UserReportVO> out = userReportPOService.getUserLedgerPage(userReportQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @GetMapping("/getById")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据id获取用户档案录入的详细数据")
    public HttpResult<UserReportVO.UserReportListVO> getById(String id) {
        String methodDescribe = getMethodDescribe("getById");
        UserReportVO.UserReportListVO userReportVO = userReportPOService.getVOById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userReportVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getFileById")
    @ApiOperation("根据id查询文件信息集合")
    public HttpResult<List<FileUrl>> getFileUrlList(String id) {
        String methodDescribe = getMethodDescribe("getFileUrlList");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, new ArrayList<>(), methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增干扰源用户")
    @ApiImplicitParam(name = "userReportParam", value = "实体参数", required = true)
    public HttpResult<String> addUserReport(@RequestBody @Validated UserReportParam userReportParam) {
        String methodDescribe = getMethodDescribe("addUserReport");
        String userReportId = userReportPOService.addUserReport(userReportParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userReportId, methodDescribe);
    }

    @PostMapping(value = "/deleteUserReport")
    @ApiOperation("干扰源接入功能删除流程")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.DELETE)
    public HttpResult<Boolean> deleteUserReport(@RequestBody List<String> supervisionId) {
        String methodDescribe = getMethodDescribe("deleteUserReport");
        Boolean b = userReportPOService.deleteUserReport(supervisionId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }

    @GetMapping("/getUserReportById")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据id获取用户档案录入数据")
    public HttpResult<UserReportVO> getUserReportById(String id) {
        String methodDescribe = getMethodDescribe("getUserReportById");
        UserReportVO userReportVO = userReportPOService.getUserReportById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userReportVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
    @PostMapping("/userCheckUpload")
    @ApiOperation("周期检测")
    @ApiImplicitParam(name = "terminalCheckParam", value = "实体参数", required = true)
    public HttpResult<Boolean> userCheckUpload(@RequestBody @Validated TerminalCheckParam terminalCheckParam) {
        String methodDescribe = getMethodDescribe("userCheckUpload");
        Boolean f = userReportPOService.userCheckUpload(terminalCheckParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, f, methodDescribe);
    }


}
