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.CwProjectReportSignAndIssueService;
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;

/**
 * @author 王强
 * @version 1.0
 * @date 2024-01-25 14:03
 */
@RestController
@Api("报告签发信息")
@RequestMapping(value = "/cwProjectReport/signAndIssue")
public class CwProjectReportSignAndIssueController {

    @Resource
    private CwProjectReportSignAndIssueService andIssueService;

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

    /**
     * 根据报告id查询报告签发信息
     * @param id
     * @return
     */
    @ApiLog("根据报告id查询报告签发信息")
    //@PreAuthorize("hasAnyAuthority('cwProjectReport:view','cwProjectReport:add','cwProjectReport:edit')")
    @GetMapping("queryByReportId")
    public ResponseEntity queryByReportId(@RequestParam("id") String id) {
        CwProjectReportData projectReportData = andIssueService.queryByReportId(id);
        return ResponseEntity.ok (projectReportData);
    }

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

    /**
     * 删除报告签发信息
     * @param id
     * @return
     */
    @ApiLog(value = "删除报告签发信息", type = LogTypeEnum.SAVE)
    @PreAuthorize ("hasAuthority('signAndIssue:del')")
    @DeleteMapping("delete")
    public ResponseEntity delete(String id) {
        return andIssueService.deleteById(id);
    }
}
