package com.sunxung.factoring.web.ledger;

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.ledger.LedgerFundGoodsAssign;
import com.sunxung.factoring.entity.ledger.vo.LedgerAccountInfoVo;
import com.sunxung.factoring.entity.ledger.vo.LedgerPlanFactoringSearch;
import com.sunxung.factoring.entity.project.vo.SearchBusinessProcessingTask;
import com.sunxung.factoring.service.ledger.LedgerAccountBasicInfoService;
import com.sunxung.factoring.service.ledger.LedgerManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分账管理controller
 *
 * @author liutao
 * @date 2021.11.11
 */
@RestController
@RequestMapping("/ledger")
public class LedgerController {

    @Autowired
    private LedgerManagementService ledgerManagementService;

    @Autowired
    private LedgerAccountBasicInfoService ledgerAccountBasicInfoService;

    /**
     * 列表页查询
     */
    @PostMapping(value = "/doList")
    public Object doList(@RequestBody SearchBusinessProcessingTask search) {
        return ledgerAccountBasicInfoService.list(search);
    }

    /**
     * 获取分账详情
     *
     * @param id 分账管理Id
     * @return
     */
    @GetMapping("/getDetail")
    public Object getDetail(Long id) {
        return new ResponseJson(ledgerManagementService.getById(id));
    }

    /**
     * 分账查看
     *
     * @param id 分账管理Id
     * @return
     */
    @GetMapping("/doView")
    public Object doView(Long id) {
        return ledgerManagementService.getById(id);
    }

    /**
     * 选择已融资货物
     *
     * @return
     */
    @PostMapping("/doFindFinancingGoodsList")
    public Object doFindFinancingGoodsList(@RequestBody LedgerPlanFactoringSearch search) {
        return ledgerManagementService.findFinancingGoodsList(search);
    }

    /**
     * 选择已验收货物
     *
     * @return
     */
    @PostMapping("/doFindAcceptanceGoodsList")
    public Object doFindAcceptanceGoodsList(@RequestBody LedgerPlanFactoringSearch search) {
        return ledgerManagementService.findAcceptanceGoodsList(search);
    }

    /**
     * 查询收支计划
     *
     * @param search 收放款计划查询类
     * @return
     */
    @PostMapping("/doFindPayCollPlanFactoringList")
    public Object doFindPayCollPlanFactoringList(@RequestBody LedgerPlanFactoringSearch search) {
        return ledgerManagementService.findPayCollPlanFactoringList(search);
    }

    /**
     * 查询供应商收款账号
     *
     * @param goodsAssignList 货物信息
     * @return
     */
    @PostMapping("/doFindSupplierBankInfoList")
    public Object doFindSupplierBankInfoList(@RequestBody List<LedgerFundGoodsAssign> goodsAssignList) {
        return ledgerManagementService.findSupplierBankInfoList(goodsAssignList);
    }

    /**
     * 分配计算融资利息、融资本金、平台利润等
     *
     * @param ledgerAccountInfoVo
     * @return
     */
    @PostMapping("/doCalculateAssign")
    public Object doCalculateAssign(@RequestBody LedgerAccountInfoVo ledgerAccountInfoVo) {
        return ledgerManagementService.calculateAssign(ledgerAccountInfoVo);
    }

    /**
     * 提交分账信息
     *
     * @param ledgerAccountInfoVo
     * @return
     */
    @PostMapping("/doAdd")
    @OperationLog(operationModule = "分账管理", operationType = OperationTypeEnum.INSERT, description = "提交分账信息")
    public Object doAdd(@RequestBody LedgerAccountInfoVo ledgerAccountInfoVo) {
        ledgerManagementService.add(ledgerAccountInfoVo);
        return new ResponseJson("提交成功");
    }
}
