package com.usky.oa.controller.web;


import com.alibaba.fastjson.JSONObject;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.common.mybatis.core.CrudService;
import com.usky.oa.domain.OaDocument;
import com.usky.oa.service.OaDocumentService;
import com.usky.oa.service.vo.OaApprovalCountVO;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 单据总表 前端控制器
 * </p>
 *
 * @author fu
 * @since 2024-12-26
 */
@RestController
@RequestMapping("/oaDocument")
public class OaDocumentController {

    @Autowired
    private OaDocumentService oaDocumentService;

    // 我的申请
    @GetMapping("/myApplication")
    public CommonPage<OaDocument> myApplication(@RequestParam(value = "docNo", required = false) String docNo,
                                                @RequestParam(value = "type", required = false) String type,
                                                @RequestParam(value = "docStatus", required = false) Integer status,
                                                @RequestParam(value = "startTime", required = false) String startTime,
                                                @RequestParam(value = "endTime", required = false) String endTime,
                                                @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return oaDocumentService.myApplication(docNo, type, status, startTime, endTime, pageNum, pageSize);
    }

    /**
     * @description: 新增单据
     * @author: fyc
     * @email yuchuan.fu@chinausky.com
     * @date: 2025/1/17 14:19
     * @param: [oaDocument]
     * @return: void
     **/
    @Log(title = "新增单据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void addDocument(@RequestBody JSONObject oaDocument) {
        oaDocumentService.addDoc(oaDocument);
    }

    // 删除单据
    @Log(title = "删除单据", businessType = BusinessType.DELETE)
    @DeleteMapping("/delDoc/{docNo}")
    public void delDocument(@PathVariable(value = "docNo") String docNo) {
        oaDocumentService.delDocument(docNo);
    }

    // 单据详情
    @GetMapping("/documentDetails")
    public Object documentDetails(@RequestParam(value = "docNo") String docNo) {
        return oaDocumentService.documentDetails(docNo);
    }


    /**
     * @description: 更新单据
     * @author: fyc
     * @email yuchuan.fu@chinausky.com
     * @date: 2025/1/20 15:47
     * @param: [jsonDocument]
     * @return: void
     **/
    @Log(title = "更新单据", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public void approvalCount(@RequestBody JSONObject jsonDocument) {
        oaDocumentService.updateDoc(jsonDocument);
    }

    // 提交单据
    @Log(title = "提交单据", businessType = BusinessType.UPDATE)
    @PutMapping("/submit")
    public void submit(@RequestParam(value = "docNo") String docNo,
                       @RequestParam(value = "docStatus") Integer docStatus){
        oaDocumentService.submit(docNo, docStatus);
    }

}

