package com.fjhx.purchase.controller.purchase;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.common.constant.SourceConstant;
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 com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * <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("/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("/add")
    public void add(@RequestBody Purchase purchase) {
        purchaseService.add(purchase);
    }

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

    /**
     * 采购修正
     */
    @PostMapping("/purchaseCorrect")
    public void purchaseCorrect(@RequestBody PurchaseDto purchaseDto) {
        purchaseService.purchaseCorrect(purchaseDto);
    }

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

    /**
     * 根据供应商查询采购合同
     */
    @GetMapping("/getListBySupplyId")
    public List<Purchase> getListBySupplyId(@RequestParam("supplyId") String supplyId) {
        return purchaseService.getListBySupplyId(supplyId);
    }

    /**
     * 货款账单
     */
    @PostMapping("/paymentBill")
    public Page<PurchaseDto> paymentBill(@RequestBody PurchaseSelectDto purchaseDto) {
        return purchaseService.paymentBill(purchaseDto);
    }

    /**
     * 获取已采购 采购人列表
     */
    @GetMapping("/getPurchaseUserList")
    public List<SysUser> getPurchaseUserList() {
        return purchaseService.getPurchaseUserList();
    }

    /**
     * 获取已采购产品部门列表
     */
    @GetMapping("/getDepts")
    public List<SysDept> getDepts() {
        return purchaseService.getDepts();
    }

    /**
     * 修改采购状态（采购作废/结束）
     */
    @PostMapping("/editPurchaseStatus")
    public void editPurchaseStatus(@RequestBody PurchaseDto purchaseDto) {
        purchaseService.editPurchaseStatus(purchaseDto);
    }

    /**
     * 采购付款excel导出
     */
    @PostMapping("/purchasePayExcelExport")
    void purchasePayExcelExport(@RequestBody PurchaseSelectDto dto, HttpServletResponse httpServletResponse) {
        purchaseService.purchasePayExcelExport(dto, httpServletResponse);
    }

}
