package com.sunxung.factoring.web.project;

import com.sunxung.factoring.entity.GridPage;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.project.*;
import com.sunxung.factoring.entity.project.vo.SearchBusinessProcessingTask;
import com.sunxung.factoring.service.project.IProjectAuditService;
import com.sunxung.factoring.service.project.IProjectCoreEnterpriseAuditService;
import com.sunxung.factoring.service.project.IProjectCoreEnterpriseService;
import com.sunxung.factoring.service.project.IProjectInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 项目审核
 * @author liutao
 * @date 2023-12-15
 */
@RestController
public class ProjectInformationController {

    @Autowired
    private IProjectAuditService projectAuditService;

    @Autowired
    private IProjectCoreEnterpriseAuditService projectCoreEnterpriseAuditService;

    @Resource(name = "projectInformationService")
    private IProjectInformationService projectInformationService;

    @Resource(name = "projectCoreEnterpriseService")
    private IProjectCoreEnterpriseService projectCoreEnterpriseService;

    /**
     * 查询所有项目授信
     * @param search
     * @return
     */
    @RequestMapping("project/getAllProject")
    public GridPage getAllProject(@RequestBody SearchBusinessProcessingTask search){
        GridPage<ProjectInformation> list = projectInformationService.findAll(search);
        return list;
    }

    /**
     * 查询所有核心企业授信
     * @param search
     * @return
     */
    @RequestMapping("project/getAllCoreEnterprise")
    public GridPage getAllCoreEnterprise(@RequestBody SearchBusinessProcessingTask search){
        GridPage<ProjectCoreEnterprise> page = projectCoreEnterpriseService.findAll(search);
        return page;
    }

    /**
     * 开启项目流程
     * @return
     */
    @RequestMapping("api/startProjectProcess")
    public ResponseJson startProjectProcess(@RequestBody ProjectInformation projectInformation){
        projectInformationService.startProjectProcess(projectInformation);
        return new ResponseJson();
    }

    /**
     * 开启项目核心企业流程
     * @return
     */
    @RequestMapping("api/startProjectCoreEnterpriseProcess")
    public ResponseJson startProjectCoreEnterpriseProcess(@RequestBody ProjectInformation projectInformation){
        projectCoreEnterpriseService.startProjectProcess(projectInformation);
        return new ResponseJson();
    }

    /**
     * 获取项目审核信息
     * @param id
     * @return
     */
    @RequestMapping("project/getProjectAuditInfo")
    public ResponseJson getProjectAuditInfo(@RequestParam Long id){
        ProjectAudit projectAuditInfo = projectAuditService.getProjectAuditInfo(id);
        return new ResponseJson(projectAuditInfo);
    }

    /**
     * 获取项目核心企业审核信息
     * @param id
     * @return
     */
    @RequestMapping("project/getProjectCoreEnterpriseAuditInfo")
    public ResponseJson getProjectCoreEnterpriseAuditInfo(@RequestParam Long id){
        ProjectCoreEnterpriseAudit projectCoreEnterpriseAuditInfo = projectCoreEnterpriseAuditService.getProjectCoreEnterpriseAuditInfo(id);
        return new ResponseJson(projectCoreEnterpriseAuditInfo);
    }


    /**
     * 保存项目审核信息
     * @param projectAuditInfo
     * @return
     */
    @RequestMapping("project/addProjectAuditInfo")
    public ResponseJson addProjectAuditInfo(@RequestBody ProjectAudit projectAuditInfo){
        projectAuditService.addProjectAuditInfo(projectAuditInfo);
        return new ResponseJson();
    }

    /**
     * 保存项目核心企业审核信息
     * @param projectCoreEnterpriseAuditInfo
     * @return
     */
    @RequestMapping("project/addProjectCoreEnterpriseAuditInfo")
    public ResponseJson addProjectCoreEnterpriseAuditInfo(@RequestBody ProjectCoreEnterpriseAudit projectCoreEnterpriseAuditInfo){
        projectCoreEnterpriseAuditService.addProjectCoreEnterpriseAuditInfo(projectCoreEnterpriseAuditInfo);
        return new ResponseJson();
    }

    /**
     * 一键测算
     * @param projectCoreEnterpriseAuditInfo
     * @return
     */
    @RequestMapping("project/addProjectCoreEnterprise/measurement")
    public ResponseJson measurement(@RequestBody ProjectCoreEnterpriseAudit projectCoreEnterpriseAuditInfo){
        ProjectCoreEnterpriseComprehensiveEvaluation measurement = projectCoreEnterpriseAuditService.measurement(null,projectCoreEnterpriseAuditInfo);
        return new ResponseJson(measurement);
    }

    /**
     * 一键测算
     * @param projectAudit
     * @return
     */
    @RequestMapping("project/addProject/measurement")
    public ResponseJson measurement(@RequestBody ProjectAudit projectAudit){
        ProjectOwnerComprehensiveEvaluation measurement = projectAuditService.measurement(null,projectAudit);
        return new ResponseJson(measurement);
    }

    /**
     * 获取项目准入报告
     * @param id
     * @return
     */
    @RequestMapping("project/admission/report")
    public ResponseJson getProjectReport(@RequestParam Long id){
        ProjectOwnerScore projectOwnerScore = projectInformationService.getProjectReport(id);
        return new ResponseJson(projectOwnerScore);
    }

    /**
     * 获取核心企业准入报告
     * @param id
     * @return
     */
    @RequestMapping("enterprise/admission/report")
    public ResponseJson getEnterpriseReport(@RequestParam Long id){
        ProjectCoreEnterpriseScore projectCoreEnterpriseScore = projectCoreEnterpriseService.getEnterpriseReport(id);
        return new ResponseJson(projectCoreEnterpriseScore);
    }

    /**
     * 下载核心企业准入报告
     * @param id
     * @param res
     */
    @RequestMapping("/enterprise/admission/report/download")
    public void downloadEnterpriseReport(@RequestParam Long id, HttpServletResponse res) throws IOException {
        projectCoreEnterpriseService.download(id,res);
    }

    /**
     * 下载项目准入报告
     * @param id
     * @param res
     */
    @RequestMapping("/project/admission/report/download")
    public void downloadProjectReport(@RequestParam Long id, HttpServletResponse res) throws IOException {
        projectInformationService.download(id,res);
    }
}
