package com.fjhx.purchase.controller;

import com.fjhx.base.ListPageMap;
import com.fjhx.entity.purchase.PurchaseContract;
import com.fjhx.purchase.service.PurchaseContractService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 采购合同 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-07-14
 */
@RestController
@RequestMapping("/purchaseContract")
public class PurchaseContractController {

    @Autowired
    private PurchaseContractService purchaseContractService;

    /**
     * 校验是否为新供应商
     *
     * @param supplierId
     * @param materialCode
     * @return
     */
    @GetMapping("/check/isNewSu")
    public R monthGetSum(@RequestParam("supplierId") String supplierId,
                         @RequestParam("materialCode") String materialCode) {
        Long count = purchaseContractService.checkNewSupplier(supplierId, materialCode);
        return R.success(count);
    }

    /**
     * 上次面料采购
     *
     * @param materialCode
     * @return
     */
    @GetMapping("last/newPur")
    public R newPur(@RequestParam("materialCode") String materialCode) {
        PurchaseContract data = purchaseContractService.newPur(materialCode);
        return R.success(data);
    }

    /**
     * 合同历史付款记录
     *
     * @return
     */
    @GetMapping("history/list")
    public R newPur() {
        List<Map<String, Object>> data = purchaseContractService.historyPayList();
        return R.success(data);
    }

    /**
     * 列表
     *
     * @param condition
     * @return
     */
    @PostMapping("/pay/list")
    public R list(@RequestBody Map<String, Object> condition) throws ParseException {
        ListPageMap.getListPageMap(condition);
        List<PurchaseContract> result = purchaseContractService.getPayList(condition);
        return R.success(result);
    }

    /**
     * 列表条数
     *
     * @param condition
     * @return
     */
    @PostMapping("/pay/list/count")
    public R listCount(@RequestBody Map<String, Object> condition) {
        ListPageMap.getListPageMap(condition);
        Integer count = purchaseContractService.getPayListCount(condition);
        return R.success(count);
    }

    /**
     * 统计
     *
     * @param condition
     * @return
     */
    @PostMapping("/pay/statistics")
    public R statistics(@RequestBody Map<String, Object> condition) {
        List<Map<String, Object>> list = purchaseContractService.getPayGroupBySu(condition);
        return R.success(list);
    }

}

