package com.sunxung.factoring.web.fundmanagement;

import com.sunxung.factoring.component.annotation.OperationLog;
import com.sunxung.factoring.component.enums.OperationTypeEnum;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.fundmanagement.FinancialCustomerExpenditureApprovalInfo;
import com.sunxung.factoring.entity.fundmanagement.vo.FinancialCustomerExpenditureDetailVo;
import com.sunxung.factoring.service.fundmanagement.FinancialCustomerExpenditureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description : 客户支用信息控制层
 * @Author : L.Jia
 * @Date: 2023-02-23 09:56
 */

@Controller
@RequestMapping("/financialCustomerExpenditure")
public class FinancialCustomerExpenditureController {

    @Autowired
    private FinancialCustomerExpenditureService financialCustomerExpenditureService;


    /***
     * 跳转编辑资料
     * @param id
     * @return
     */
    @GetMapping("/edit")
    @ResponseBody
    public ResponseJson edit(Long id) {
        return new ResponseJson(financialCustomerExpenditureService.edit(id));
    }

    /**
     * 提交或暂存
     *
     * @param detailVo
     */
    @PostMapping("/doEdit")
    @ResponseBody
    @OperationLog(operationModule = "客户支用信息",operationType = OperationTypeEnum.INSERT,description = "提交或暂存")
    public ResponseJson doEdit(@RequestBody FinancialCustomerExpenditureDetailVo detailVo) {
        financialCustomerExpenditureService.claimFinancialCustomerExpenditureTask(detailVo.getTaskId());
        financialCustomerExpenditureService.doEdit(detailVo);
        return new ResponseJson("操作成功！");
    }

    /**
     * 审核提交
     *
     * @param approvalInfo
     * @return
     */
    @PostMapping("/approval/doEdit")
    @ResponseBody
    @OperationLog(operationModule = "客户支用信息",operationType = OperationTypeEnum.INSERT,description = "审核提交")
    public ResponseJson doApproval(@RequestBody FinancialCustomerExpenditureApprovalInfo approvalInfo) {
        financialCustomerExpenditureService.doApproval(approvalInfo);
        return new ResponseJson("提交成功！");
    }

    /**
     * 资料下载
     *
     * @param response
     * @param id
     */
    @GetMapping("/downloadFileZip")
    @ResponseBody
    @OperationLog(operationModule = "客户支用信息",operationType = OperationTypeEnum.OTHER,description = "资料下载")
    public ResponseJson downloadFileZip(HttpServletResponse response, Long id) {
        financialCustomerExpenditureService.downloadAllFile(response, id);
        return new ResponseJson("下载成功！");
    }

    /**
     * 合同清单上传
     *
     * @param detailVo
     */
    @PostMapping("/uploadContractList")
    @ResponseBody
    public ResponseJson uploadContractList(@RequestBody FinancialCustomerExpenditureDetailVo detailVo) {
        financialCustomerExpenditureService.uploadContractList(detailVo);
        return new ResponseJson("上传成功！");
    }
}
