package com.sunxung.factoring.web.refundManagement;

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.ledger.LedgerFundGoodsAssign;
import com.sunxung.factoring.entity.project.vo.SearchBusinessProcessingTask;
import com.sunxung.factoring.entity.refundsManagement.RefundManagementApproval;
import com.sunxung.factoring.entity.refundsManagement.vo.RefundManagementVo;
import com.sunxung.factoring.service.refundsManagement.IRefundManagementApprovalService;
import com.sunxung.factoring.service.refundsManagement.IRefundManagementService;
import com.sunxung.factoring.service.sys.flowable.FlowableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 退款管理Controller
 * @Author Yafan Wang
 * @Date 2024/3/14 15:52
 */
@RestController
@RequestMapping("/refundManagement")
public class RefundManagementController {

    @Autowired
    private IRefundManagementService refundManagementService;
    @Autowired
    private IRefundManagementApprovalService refundManagementApprovalService;
    @Autowired
    private FlowableService flowableService;


    /**
     * @param id 列表id
     * @return
     */
    @GetMapping("/edit")
    public ResponseJson edit(Long id) {
        return new ResponseJson(refundManagementService.edit(id));
    }


    /** 根据页面选中的 应退明细和计划 计算 申请内容
     * @param refundManagementVo
     * @return
     */
    @PostMapping("/findBySelectAmountType")
    public ResponseJson edit(@RequestBody RefundManagementVo refundManagementVo) {
        return new ResponseJson(refundManagementService.findBySelectAmountType(refundManagementVo));
    }


    /**
     * 从sop查询所有公司主体
     * @return
     */
    @GetMapping("/getAllCompanyEntityBySop")
    public ResponseJson edit() {
        return new ResponseJson(refundManagementService.getAllCompanyEntityBySop());
    }


    /** 根据页面选中的 应退明细和计划 计算 申请内容
     * @param refundManagementVo
     * @return
     */
    @PostMapping("/doEdit")
    public ResponseJson doEdit(@RequestBody @Validated RefundManagementVo refundManagementVo) {
        refundManagementService.doEdit(refundManagementVo);
        return new ResponseJson("操作成功！");
    }



    /** 审核提交
     * @param approval
     * @return
     */
    @PostMapping("/approval/doEdit")
    public ResponseJson doEdit(@RequestBody @Validated RefundManagementApproval approval) {
        flowableService.claimTask(approval.getTaskId(), ThreadLocalUtil.getUserId(), ConstantUtil.RISK_CONTROL_MANAGER);
        refundManagementApprovalService.doEdit(approval);
        return new ResponseJson("操作成功！");
    }


    /**
     * 向退款管理推送数据（测试接口）
     * @param ledgerFundGoodsAssign
     * @return
     */
    @PostMapping("/add")
    public ResponseJson doEdit(@RequestBody LedgerFundGoodsAssign ledgerFundGoodsAssign) {
        refundManagementService.add(ledgerFundGoodsAssign);
        return new ResponseJson("操作成功！");
    }

    /**
     * 退款全部列表（测试接口）
     * @param search
     * @return
     */
    @PostMapping("/findBySearch")
    public ResponseJson findBySearch(@RequestBody SearchBusinessProcessingTask search) {
        return new ResponseJson(refundManagementService.findBySearch(search));
    }

}
