package com.jeeplus.test.cw.reportCancellApply.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.aop.logging.annotation.ApiLog;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.sys.constant.enums.LogTypeEnum;
import com.jeeplus.test.cw.projectRecords.service.dto.CwProjectRecordsDTO;
import com.jeeplus.test.cw.projectReport.domain.CwProjectReportData;
import com.jeeplus.test.cw.reportCancellApply.service.ReportCancellApplyService;
import com.jeeplus.test.cw.reportCancellApply.service.dto.ReportInfoDto;
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;

/**
 * @author: 王强
 * @create: 2022-11-18 17:32
 **/
@RestController
@Api("财务报告文号报废")
@RequestMapping(value = "/cwProjectReportCancell")
public class ReportCancellApplyController {

    @Resource
    private ReportCancellApplyService applyService;

    /**
     * 查询财务项目报告信息列表
     * @param reportInfoDto
     * @param page
     * @return
     */
    @ApiLog("查询财务项目报告信息列表")
    @PreAuthorize("hasAuthority('cwProjectReportCancell:list')")
    @GetMapping("list")
    public ResponseEntity<IPage<ReportInfoDto>> data(ReportInfoDto reportInfoDto, Page<ReportInfoDto> page) throws Exception {
        IPage<ReportInfoDto> result = new Page<ReportInfoDto>();
        result = applyService.findList (page,reportInfoDto);
        return ResponseEntity.ok (result);
    }

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

    /**
     * 查询客户信息数据
     * @param id
     * @return
     */
    @ApiLog("查询报告作废数据")
    @PreAuthorize ("hasAnyAuthority('cwProjectReportCancell:view','cwProjectReportCancell:add','cwProjectReportCancell:edit')")
    @GetMapping("queryById")
    public ResponseEntity queryById(@RequestParam("id") String id) {
        ReportInfoDto reportInfoDto = applyService.queryById ( id );
        return ResponseEntity.ok (reportInfoDto);
    }

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

    /**
     * 查询信息列表
     * @param projectReportData
     * @param page
     * @return
     */
    @ApiLog("查询信息列表")
    @PreAuthorize("hasAuthority('cwProjectReportCancell:findList')")
    @GetMapping("findList")
    public ResponseEntity<IPage<ReportInfoDto>> findList(ReportInfoDto projectReportData, Page<ReportInfoDto> page) throws Exception {
        IPage<ReportInfoDto> result = new Page<ReportInfoDto>();
        result = applyService.getList (page,projectReportData);
        return ResponseEntity.ok (result);
    }

    /**
     * 删除业务提问
     * @param ids
     * @return
     */
    @ApiLog(value = "删除财务报告信息", type = LogTypeEnum.SAVE)
    @PreAuthorize ("hasAuthority('cwProjectReport:del')")
    @DeleteMapping("delete")
    public ResponseEntity delete(String ids) {
        return applyService.deleteByIds(ids);
    }

    @ApiLog("查询财务报告数据")
    @GetMapping("queryByNo")
    public ResponseEntity queryByNo(@RequestParam("no") String no) {
        CwProjectReportData projectReportData = applyService.queryByNo ( no );
        return ResponseEntity.ok(projectReportData);
    }
}
