package com.fjhx.purchase.controller.purchase;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.purchase.entity.purchase.dto.PurchaseDto;
import com.fjhx.purchase.entity.purchase.dto.PurchaseSelectDto;
import com.fjhx.purchase.entity.purchase.po.Purchase;
import com.fjhx.purchase.entity.purchase.vo.PurchaseVo;
import com.fjhx.purchase.service.purchase.PurchaseService;
import com.ruoyi.common.core.domain.BaseSelectDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


/**
 * <p>
 * 采购 前端控制器
 * </p>
 *
 * @author
 * @since 2023-04-06
 */
//@DS(SourceConstant.PURCHASE)
@RestController
@RequestMapping("/purchase")
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;

    /**
     * 采购分页
     */
    @PostMapping("/page")
    public Page<PurchaseVo> page(@RequestBody PurchaseSelectDto dto) {
        return purchaseService.getPage(dto);
    }

    /**
     * 采购统计（采购列表）
     */
    @PostMapping("/purchaseStatistics")
    public Map<String, Object> purchaseStatistics(@RequestBody PurchaseSelectDto dto) {
        return purchaseService.purchaseStatistics(dto);
    }

//    /**
//     * 采购分页 维多利亚
//     */
//    @PostMapping("/pageByWdly")
//    public Page<PurchaseVo> pageByWdly(@RequestBody PurchaseSelectDto dto) {
//        return purchaseService.getPageByWdly(dto);
//    }

    /**
     * 采购明细
     */
    @PostMapping("/detail")
    public PurchaseVo detail(@RequestBody BaseSelectDto dto) {
        return purchaseService.detail(dto.getId());
    }

    /**
     * 批量查询采购单
     */
    @PostMapping("/getListInId")
    public List<Purchase> getListInId(@RequestBody List<Long> ids) {
        return purchaseService.getListInId(ids);
    }

    /**
     * 采购新增
     */
    @PostMapping("/add")
    public void add(@RequestBody Purchase purchase) {
        purchaseService.add(purchase);
    }

//    /**
//     * 采购编辑
//     */
//    @PostMapping("/edit")
//    public void edit(@RequestBody PurchaseDto purchaseDto) {
//        purchaseService.edit(purchaseDto);
//    }

    /**
     * 采购删除
     */
    @PostMapping("/delete")
    public void delete(@RequestBody BaseSelectDto dto) {
        purchaseService.delete(dto.getId());
    }

    /**
     * 根据供应商查询无发票的采购合同
     */
    @GetMapping("/getNoInvoiceListBySupplyId")
    public List<Purchase> getNoInvoiceListBySupplyId(@RequestParam("supplyId") String supplyId) {
        return purchaseService.getNoInvoiceListBySupplyId(supplyId);
    }
    /**
     * 根据供应商查询采购合同
     */
    @GetMapping("/getListBySupplyId")
    public List<Purchase> getListBySupplyId(@RequestParam("supplyId") String supplyId) {
        return purchaseService.getListBySupplyId(supplyId);
    }
    /**
     * 根据供应商查询采购合同
     */
    @GetMapping("/getAdvanceCode")
    public String getAdvanceCode(@RequestParam("money") String money) {
        String code = System.currentTimeMillis()+money;
        return code;
    }
    /**
     * 货款账单
     */
    @PostMapping("/paymentBill")
    public Page<PurchaseDto> paymentBill(@RequestBody PurchaseSelectDto purchaseDto) {
        return purchaseService.paymentBill(purchaseDto);
    }

}
