package com.njcn.advance.controller.assess;

import com.njcn.advance.pojo.dto.assess.AssessTreeDTO;
import com.njcn.advance.pojo.param.assess.AssessParam;
import com.njcn.advance.pojo.vo.assess.AssessResultVO;
import com.njcn.advance.service.assess.SecondaryEvaluationService;
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.param.StatisticsBizBaseParam;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Description:
 * Date: 2025/06/06  下午 2:43【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */

@RestController
@RequestMapping("secondaryEvaluation")
@Api(tags = "二级评估")
@RequiredArgsConstructor
public class SecondaryEvaluationController extends BaseController {

    private final SecondaryEvaluationService secondaryEvaluationService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/evaluation")
    @ApiOperation("导入数据计算评估结果")
    public HttpResult<Boolean> evaluation(@RequestParam("assessId") String assessId,
                                          @ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file) {
        String methodDescribe = getMethodDescribe("evaluation");
        AssessParam param=new AssessParam();
        param.setAssessId(assessId);
        secondaryEvaluationService.evaluation(param, file);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/lineEvaluation")
    @ApiOperation("监测点数据计算评估结果")
    public HttpResult<Boolean> lineEvaluation(@RequestBody AssessParam param) {
        String methodDescribe = getMethodDescribe("lineEvaluation");
        secondaryEvaluationService.evaluation(param, null);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }




    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/evaluationTree")
    @ApiOperation("评估树")
    public HttpResult<List<AssessTreeDTO>> evaluationTree(@RequestParam("deptId") String deptId) {
        String methodDescribe = getMethodDescribe("evaluationTree");
        List<AssessTreeDTO> tree = secondaryEvaluationService.evaluationTree(deptId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tree, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/assessResult")
    @ApiOperation("评估结果")
    public HttpResult<AssessResultVO> assessResult(@RequestParam("assessId") String assessId) {
        String methodDescribe = getMethodDescribe("assessResult");
        AssessResultVO resultVO = secondaryEvaluationService.assessResult(assessId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resultVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/downAssessResult")
    @ApiOperation("导出评估结果")
    public void assessResult(HttpServletResponse response, @RequestParam("assessId") String assessId) throws IOException {
        secondaryEvaluationService.downAssessResult(response, assessId);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/downTemplateAssessResult")
    @ApiOperation("导出评估结果模板")
    public void assessResult(HttpServletResponse response) throws IOException {
        secondaryEvaluationService.downTemplateAssessResult(response);
    }
}
