package com.fjhx.controller.apply;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.params.JumpVo;
import com.fjhx.params.apply.ApplyPurchaseVo;
import com.fjhx.service.apply.ApplyPurchaseService;
import com.fjhx.service.flow.InitiateApplyFlowService;
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-14
 */
@RestController
@RequestMapping("/applyPurchase")
public class ApplyPurchaseController {

    @Autowired
    private ApplyPurchaseService applyPurchaseService;

    @Autowired
    private InitiateApplyFlowService initiateApplyFlowService;

    /**
     * 发起申购流程
     */
    @PostMapping("/addFlowCreate")
    public R addFlowCreate(@RequestBody ApplyPurchaseVo applyPurchaseVo) {
        initiateApplyFlowService.create(applyPurchaseVo);
        return R.success();
    }

    /**
     * 发起申购跳转
     */
    @PostMapping("/addFlowJump")
    public R addFlowJump(@RequestBody JumpVo jumpVo) {
        initiateApplyFlowService.jump(jumpVo);
        return R.success();
    }

    /**
     * 物料类型统计
     */
    @PostMapping("typeStatistics")
    public R getTypeStatistics(@RequestBody Condition condition) {
        Map<Integer, Map<String, Object>> result = applyPurchaseService.typeStatistics(condition);
        return R.success(result);
    }

    /**
     * 按审批状态统计
     */
    @PostMapping("/flowStatistics")
    public R flowStatistics(@RequestBody Condition condition) {
        List<Map<String, Object>> result = applyPurchaseService.flowStatistics(condition);
        return R.success(result);
    }

    /**
     * 物料申购
     */
    @PostMapping("/page")
    public R page(@RequestBody Condition condition) {
        Page<Map<String, Object>> result = applyPurchaseService.getPage(condition);
        return R.success(result);
    }

    /**
     * 申购单分页
     */
    @PostMapping("/applyPurchasePage")
    public R applyPurchasePage(@RequestBody Condition condition) {
        Page<Map<String, Object>> result = applyPurchaseService.getApplyPurchasePage(condition);
        return R.success(result);
    }

    /**
     * 根据申购id获取申购明细
     */
    @PostMapping("/applyPurchaseDetailsList")
    public R applyPurchaseDetailsList(@RequestBody Condition condition) {
        Map<String, Object> result = applyPurchaseService.getApplyPurchaseDetailsList(condition);
        return R.success(result);
    }

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

    /**
     * 申购金额分页
     */
    @PostMapping("/amountPage")
    public R amountPage(@RequestBody Condition condition) {
        Page<Map<String, Object>> result = applyPurchaseService.amountPage(condition);
        return R.success(result);
    }

}

