package com.njcn.product.advance.responsility.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.njcn.common.pojo.annotation.OperateInfo;
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.product.advance.responsility.pojo.dto.RespDataDTO;
import com.njcn.product.advance.responsility.pojo.dto.ResponsibilityResult;
import com.njcn.product.advance.responsility.pojo.param.RespBaseParam;
import com.njcn.product.advance.responsility.pojo.param.ResponsibilityCalculateParam;
import com.njcn.product.advance.responsility.pojo.param.ResponsibilitySecondCalParam;
import com.njcn.product.advance.responsility.service.IRespDataResultService;
import com.njcn.product.advance.responsility.service.IRespDataService;
import com.njcn.web.controller.BaseController;
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 java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * @author hongawen
 * @version 1.0.0
 * @date 2023年07月21日 10:06
 */
@RestController
@RequestMapping("responsibility")
@Api(tags = "谐波责任划分-谐波责任数据处理")
@RequiredArgsConstructor
public class ResponsibilityController extends BaseController {

    private final IRespDataService respDataService;

    private final IRespDataResultService respDataResultService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/responsibilityList")
    @ApiOperation("查询责任划分列表分页")
    @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
    public HttpResult<Page<RespDataDTO>> responsibilityList(@RequestBody @Validated RespBaseParam queryParam) {
        String methodDescribe = getMethodDescribe("responsibilityList");
        Page<RespDataDTO> list = respDataService.responsibilityList(queryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deleteByIds")
    @ApiOperation("删除责任划分数据")
    @ApiImplicitParam(name = "ids", value = "待删除的责任id集合", required = true)
    public HttpResult<Page<RespDataDTO>> deleteByIds(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("deleteByIds");
        respDataService.deleteByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }



    @PostMapping("getDynamicData")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("动态谐波责任划分")
    @ApiImplicitParam(name = "responsibilityCalculateParam", value = "谐波责任动态划分参数", required = true)
    public HttpResult<ResponsibilityResult> getDynamicData(@RequestBody @Validated ResponsibilityCalculateParam responsibilityCalculateParam) {
        String methodDescribe = getMethodDescribe("getDynamicData");
        ResponsibilityResult datas = respDataService.getDynamicData(responsibilityCalculateParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, datas, methodDescribe);
    }

    @PostMapping("getResponsibilityData")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("二次计算责任划分")
    @ApiImplicitParam(name = "responsibilitySecondCalParam", value = "二次计算责任划分参数", required = true)
    public HttpResult<ResponsibilityResult> getResponsibilityData(@RequestBody @Validated ResponsibilitySecondCalParam responsibilitySecondCalParam) {
        String methodDescribe = getMethodDescribe("getResponsibilityData");
        ResponsibilityResult datas = respDataService.getResponsibilityData(responsibilitySecondCalParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, datas, methodDescribe);
    }


    @GetMapping("displayHistoryData")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("回显历史责任划分结果")
    @ApiImplicitParam(name = "id", value = "责任数据id", required = true)
    public HttpResult<List<ResponsibilityResult>> displayHistoryData(String id,Integer time) {
        String methodDescribe = getMethodDescribe("displayHistoryData");
        List<ResponsibilityResult> datas = respDataResultService.displayHistoryData(id,time);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, datas, methodDescribe);
    }



    @PostMapping("systemDynamicData")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("动态谐波责任划分")
    @ApiImplicitParam(name = "responsibilityCalculateParam", value = "谐波责任动态划分参数", required = true)
    public HttpResult<ResponsibilityResult> systemDynamicData(@RequestBody @Validated ResponsibilityCalculateParam responsibilityCalculateParam) {
        String methodDescribe = getMethodDescribe("getDynamicData");
        ResponsibilityResult datas = respDataService.getDynamicData(responsibilityCalculateParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, datas, methodDescribe);
    }





}
