package com.fjhx.controller.contract;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.params.JumpVo;
import com.fjhx.params.contract.ContractVo;
import com.fjhx.service.contract.ContractService;
import com.fjhx.service.flow.ContractFlowService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 采购合同 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-09-19
 */
@RestController
@RequestMapping("/contract")
public class ContractController {

    @Autowired
    private ContractService contractService;

    @Autowired
    private ContractFlowService contractFlowService;

    @PostMapping("/delete")
    public R delete(@RequestBody ContractVo contractVo) {
        contractService.delete(contractVo);
        return R.success();
    }

    /**
     * 金额统计
     */
    @PostMapping("/amountStatistics")
    public R amountStatistics(@RequestBody Condition condition) {
        Map<Integer, Map<String, Object>> result = contractService.amountStatistics(condition);
        return R.success(result);
    }

    /**
     * 分页
     */
    @PostMapping("/page")
    public R page(@RequestBody Condition condition) {
        Page<Map<String, Object>> result = contractService.getPage(condition);
        return R.success(result);
    }

    /**
     * 列表
     */
    @PostMapping("/list")
    public R list(@RequestBody Condition condition) {
        List<Map<String, Object>> result = contractService.getList(condition);
        return R.success(result);
    }

    /**
     * 发起合同审批
     */
    @PostMapping("/flowCreate")
    public R flowCreate(@RequestBody ContractVo contractVo) {
        contractFlowService.create(contractVo);
        return R.success();
    }

    /**
     * 合同审批跳转
     */
    @PostMapping("/flowJump")
    public R flowJump(@RequestBody JumpVo jumpVo) {
        contractFlowService.jump(jumpVo);
        return R.success();
    }

}

