package com.sunxung.factoring.web.loanmanagement;

import com.sunxung.factoring.component.util.ConstantUtil;
import com.sunxung.factoring.component.util.ThreadLocalUtil;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.financing.payment.PaymentApply;
import com.sunxung.factoring.entity.loanmanagement.ExemptionMatters;
import com.sunxung.factoring.entity.loanmanagement.ExemptionMattersApproval;
import com.sunxung.factoring.service.loanmanagement.IExemptionMattersService;
import com.sunxung.factoring.service.sys.flowable.FlowableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author liutao
 * @date 2023-04-24
 * 豁免事项跟进
 */
@RestController
public class ExemptionMattersFollowController {

    @Autowired
    private IExemptionMattersService exemptionMattersService;

    @Autowired
    private FlowableService flowableService;

    /**
     * 补充豁免事项资料
     *
     * @return
     */
    @RequestMapping("exemption/add")
    public ResponseJson add(@RequestBody PaymentApply paymentApply) {
        exemptionMattersService.add(paymentApply);
        return new ResponseJson("提交成功！");
    }

    /**
     * 补充豁免事项资料处理页数据
     *
     * @return
     */
    @RequestMapping("exemption/get")
    public ResponseJson get(@RequestParam Long exemptionMattersId) {
        ExemptionMatters exemptionMatters = exemptionMattersService.getDetail(exemptionMattersId);
        return new ResponseJson(exemptionMatters);
    }

    /**
     * 补充豁免事项资料审批
     *
     * @return
     */
    @RequestMapping("exemption/approval")
    public ResponseJson approval(@RequestBody ExemptionMattersApproval exemptionMattersApproval) {
        //拾取task
        flowableService.claimTask(exemptionMattersApproval.getTaskId(), ThreadLocalUtil.getUserId(), ConstantUtil.LEGAL_SPECIALIST);
        exemptionMattersService.approval(exemptionMattersApproval);
        return new ResponseJson("审核成功！");
    }

    /**
     * 补充豁免事项资料一键下载
     *
     * @return
     */
    @RequestMapping("exemption/download")
    public ResponseJson download(@RequestParam Long exemptionMattersId, HttpServletResponse response) {
        exemptionMattersService.download(exemptionMattersId, response);
        return new ResponseJson("下载成功！");
    }
    /**
     * 补充豁免事项定时任务
     *
     * @return
     */
//    @RequestMapping("exemption/sendEmailJob")
//    public ResponseJson download() {
//        exemptionMattersService.sendEmailJob();
//        return new ResponseJson("邮件发送成功！");
//    }

}
