package com.jeeplus.finance.projectReport.controller;

import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.finance.projectReport.domain.CwProjectReportData;
import com.jeeplus.finance.projectReport.service.CwProjectReportReviewService;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author: 王强
 * @create: 2022-12-12 14:45
 **/
@RestController
@Api(tags ="报告审核校对")
@RequestMapping(value = "/projectReport/review")
public class CwProjectReportReviewController {

    @Resource
    private CwProjectReportReviewService service;

    /**
     * 保存财务报告信息-流程
     * @param reportData
     * @return
     */
    @ApiLog(value = "保存财务报告信息-流程", type = LogTypeEnum.SAVE)
    //@PreAuthorize("hasAnyAuthority('cwProjectReportReview:add','cwProjectReportReview:edit')")
    @PostMapping("saveForm")
    public ResponseEntity saveForm(@Valid @RequestBody CwProjectReportData reportData) throws Exception {
        String id = service.saveForm(reportData);
        return ResponseUtil.newInstance().add("businessTable", "cw_project_report_review").add("businessId", id).ok ("操作成功");
    }

    /**
     * 项目登记，生成报告号
     * @param reportData
     * @return
     */
    @ApiLog(value = "项目登记，生成报告号", type = LogTypeEnum.SAVE)
    @PostMapping("saveFormNew")
    public ResponseEntity saveFormNew(@Valid @RequestBody CwProjectReportData reportData) throws Exception {
        String id = service.saveFormNew(reportData);
        return ResponseUtil.newInstance().add("businessTable", "cw_project_report_review").add("businessId", id).ok ("操作成功");
    }
    /**
     * 保存财务报告信息-流程
     * @param reportData
     * @return
     */
    @ApiLog(value = "保存财务报告信息-流程", type = LogTypeEnum.SAVE)
    //@PreAuthorize("hasAnyAuthority('cwProjectReportReview:add','cwProjectReportReview:edit')")
    @PostMapping("saveFormReviewNew")
    public ResponseEntity saveFormReviewNew(@Valid @RequestBody CwProjectReportData reportData) throws Exception {
        String id = service.saveFormReviewNew(reportData);
        return ResponseUtil.newInstance().add("businessTable", "cw_project_report_review_new").add("businessId", id).ok ("操作成功");
    }

    /**
     * 根据id修改状态值status
     * @param data
     * @return
     */
    @ApiOperation(value = "根据id修改状态值status")
    @PostMapping(value = "/updateReviewStatysByReportId")
    public ResponseEntity<String> updateReviewStatysByReportId(@RequestBody CwProjectReportData data) {
        String s = service.updateReviewStatysByReportId(data);
        return ResponseEntity.ok(s);
    }
    /**
     * 根据id修改状态值status
     * @param data
     * @return
     */
    @ApiOperation(value = "根据id修改状态值status")
    @PostMapping(value = "/updateReviewStatusByReportIdNew")
    public ResponseEntity<String> updateReviewStatusByReportIdNew(@RequestBody CwProjectReportData data) {
        String s = service.updateReviewStatusByReportIdNew(data);
        return ResponseEntity.ok(s);
    }

    /**
     * 查询客户信息数据
     * @param id
     * @return
     */
    @ApiLog("查询财务报告数据")
    @PreAuthorize ("hasAnyAuthority('cwProjectReport:view','cwProjectReport:add','cwProjectReport:edit')")
    @GetMapping("queryByReportId")
    public ResponseEntity queryByReportId(@RequestParam("id") String id) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        CwProjectReportData projectReportData = service.queryByReportId(id);
        return ResponseEntity.ok (projectReportData);
    }
    /**
     * 查询陈红星的注册/资格证号，专业信息
     * @return
     */
    @ApiLog("查询陈红星的注册/资格证号，专业信息")
    @GetMapping("getUserInfo")
    public ResponseEntity getUserInfo(@RequestParam("id") String id) {
        CwProjectReportData projectReportData = service.getUserInfo(id);
        return ResponseEntity.ok (projectReportData);
    }

    /**
     * 查询客户信息数据
     * @param id
     * @return
     */
    @ApiLog("查询财务报告数据")
    //@PreAuthorize ("hasAnyAuthority('cwProjectReport:view','cwProjectReport:add','cwProjectReport:edit')")
    @GetMapping("queryByReportIdNew")
    public ResponseEntity queryByReportIdNew(@RequestParam("id") String id) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        CwProjectReportData projectReportData = service.queryByReportIdNew(id);
        return ResponseEntity.ok (projectReportData);
    }

    /**
     * 查询客户信息数据
     * @param procInsId
     * @return
     */
    @ApiLog("查询财务报告数据")
    // @PreAuthorize ("hasAnyAuthority('cwProjectReport:view','cwProjectReport:add','cwProjectReport:edit')")
    @GetMapping("getProcessStatus")
    public ResponseEntity getProcessStatus(@RequestParam("procInsId") String procInsId) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        String taskName = service.getProcessStatus(procInsId);
        return ResponseEntity.ok (taskName);
    }


    /**
     * 根据报告id查询报告是否已生成报告文号
     * @param reportId
     * @return
     */
    @ApiLog("根据报告id查询报告是否已生成报告文号")
    @GetMapping("getHaveReportNo")
    public ResponseEntity getHaveReportNo(@RequestParam("reportId") String reportId) {
        String is = service.getHaveReportNo(reportId);
        return ResponseEntity.ok (is);
    }

    @ApiLog("生成报告文号，并且驳回复核流程")
    @GetMapping("saveReportNo")
    public ResponseEntity saveReportNo(@RequestParam("reportId") String reportId) {
        service.saveReportNo(reportId);
        return ResponseEntity.ok ("驳回成功");
    }
}
