package com.jeeplus.finance.projectReportArchive.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.common.excel.ExcelOptions;
import com.jeeplus.common.excel.annotation.ExportMode;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.finance.invoice.util.EasyPoiUtil;
import com.jeeplus.finance.projectReport.domain.CwProjectReportData;
import com.jeeplus.finance.projectReportArchive.service.CwProjectReportArchiveApplyService;
import com.jeeplus.finance.projectReportArchive.service.CwProjectReportArchiveService;
import com.jeeplus.finance.projectReportArchive.service.dto.CwProjectReportArchiveApplyDTO;
import com.jeeplus.finance.projectReportArchive.service.dto.CwProjectReportArchiveDTO;
import com.jeeplus.finance.projectReportArchive.service.dto.CwProjectReportArchiveExportDTO;
import com.jeeplus.finance.projectReportArchive.service.dto.ReportDTO;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import com.jeeplus.sys.feign.IDictApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 财务项目报告归档
 */
@RestController
@Api("财务项目报告归档")
@RequestMapping(value = "/cwProjectReportArchiveApply")
public class CwProjectReportArchiveApplyController {

    @Resource
    private CwProjectReportArchiveApplyService service;


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

    /**
     * 查询报告信息数据
     *
     * @param reportId
     * @return
     */
    /*@ApiLog("查询财务报告数据")
    // @PreAuthorize ("hasAnyAuthority('cwProjectReport:view','cwProjectReport:add','cwProjectReport:edit')")
    @GetMapping("queryReportById")
    public ResponseEntity queryReportById(@RequestParam("id") String reportId) {
        CwProjectReportArchiveApplyDTO projectReportData = service.queryReportByReportId(reportId);
        return ResponseEntity.ok(projectReportData);
    }*/

    /**
     * 保存代归档申请-流程
     * @param cwProjectReportArchiveApplyDTO
     * @return
     */
    @ApiLog(value = "保存代归档申请-流程", type = LogTypeEnum.SAVE)
    @PostMapping("applySave")
    public ResponseEntity applySave(@Valid @RequestBody CwProjectReportArchiveApplyDTO cwProjectReportArchiveApplyDTO) throws Exception {
        String id = service.applySave(cwProjectReportArchiveApplyDTO);
        return ResponseUtil.newInstance().add("businessTable", "cw_project_report_archive_apply").add("businessId", id).ok ("操作成功");
    }


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

}
