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.FinancialCustomerApprovalInfo;
import com.sunxung.factoring.entity.fundmanagement.vo.FinancialBasicVo;
import com.sunxung.factoring.service.fundmanagement.FinancialCustomerApprovalInfoService;
import com.sunxung.factoring.service.fundmanagement.FinancialCustomerInfoService;
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 Yafan Wang
 * @Date 2023/2/9 15:50
 */
@Controller
@RequestMapping
public class FinancialCustomerController {
    @Autowired
    private FinancialCustomerInfoService financialCustomerInfoService;
    @Autowired
    private FinancialCustomerApprovalInfoService financialCustomerApprovalInfoService;

    /***
     * 客户管理-编辑页
     * @param id
     * @return
     */
    @GetMapping("/financialCustomer/editFile")
    @ResponseBody
    public ResponseJson editFile(Long id) {
        return new ResponseJson(financialCustomerInfoService.editBasicFile(id));
    }

    /**
     * 提交或暂存
     *
     * @param financialBasicVo
     */
    @PostMapping("/financialCustomer/doEditFile")
    @ResponseBody
    @OperationLog(operationModule = "客户信息",operationType = OperationTypeEnum.INSERT,description = "提交或暂存")
    public ResponseJson doEditFile(@RequestBody FinancialBasicVo financialBasicVo) {
        financialCustomerInfoService.claimFinancialCustomerTask(financialBasicVo.getTaskId());
        financialCustomerInfoService.doEditBasicFile(financialBasicVo);
        return new ResponseJson("操作成功！");
    }

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

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