package com.yh.saas.plugin.yiliangyiyun.controller;

import com.yh.saas.plugin.yiliangyiyun.entity.PurchaseOrder;
import com.yh.saas.plugin.yiliangyiyun.exception.ServiceException;
import com.yh.saas.plugin.yiliangyiyun.service.IPurchaseOrderService;
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 com.baomidou.mybatisplus.plugins.Page;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.text.ParseException;


/**
 * <p>
 * 采购订单 前端控制器
 * </p>
 *
 * @author Gongdc
 * @since 2021-07-22
 */
@RestController
@RequestMapping("/purchaseOrder")
public class PurchaseOrderController {
    @Autowired
    private IPurchaseOrderService purchaseOrderService;

    /**
     * 成交
     * @param purchaseOrder
     * @return
     */
    @PostMapping("/api/deal")
    public String deal(@RequestBody PurchaseOrder purchaseOrder) {
        return purchaseOrderService.deal(purchaseOrder);
    }
    /**
     * 补充定金/解冻定金/完成/更改基差
     * @param purchaseOrder
     * @return
     */
    @PostMapping("/api/editStatus")
    public String editStatus(@RequestBody PurchaseOrder purchaseOrder) {
        return purchaseOrderService.editStatus(purchaseOrder);
    }

    /**
     * 平仓
     * @param purchaseOrder
     * @return
     */
    @PostMapping("/api/closePosition")
    public String closePosition(@RequestBody PurchaseOrder purchaseOrder) {
        return purchaseOrderService.closePosition(purchaseOrder);
    }

    /**
     * 客户点价
     * @param purchaseOrder
     * @return
     */
    @PostMapping("/api/pointPrice")
    public String pointPrice(@RequestBody PurchaseOrder purchaseOrder) throws ServiceException, ParseException {
        return purchaseOrderService.pointPrice(purchaseOrder.getId(), purchaseOrder.getUnitPrice());
    }

    /**
     * 采购订单列表
     * @param purchaseOrder
     * @return
     */
    @GetMapping("/selectPurchaseOrder")
    public Page<PurchaseOrder> selectPurchaseOrder(PurchaseOrder purchaseOrder) {
        return purchaseOrderService.selectPurchaseOrder(purchaseOrder);
    }

    /**
     * 添加采购订单
     * @param purchaseOrder
     * @return
     */
    @PostMapping("/api/insertPurchaseOrder")
    public String insertPurchaseOrder(@RequestBody PurchaseOrder purchaseOrder) {
        return purchaseOrderService.insertPurchaseOrder(purchaseOrder);
    }


    /**
     * 提交审核采购订单
     * @param purchaseOrder
     * @return
     */
    @PostMapping("/api/submitPurchaseOrder")
    public String submitPurchaseOrder(@RequestBody PurchaseOrder purchaseOrder) {
        return purchaseOrderService.submitPurchaseOrder(purchaseOrder);
    }

    /**
     * 删除采购订单
     * @param purchaseOrder
     */
    @PostMapping("/api/deletePurchaseOrder")
    public void deletePurchaseOrder(@RequestBody PurchaseOrder purchaseOrder) {
        purchaseOrderService.deletePurchaseOrder(purchaseOrder.getId());
    }
    /**
     * 编辑采购订单
     * @param purchaseOrder
     * @return
     */
    @PostMapping("/api/editPurchaseOrder")
    public String editPurchaseOrder(@RequestBody PurchaseOrder purchaseOrder){
        return purchaseOrderService.editPurchaseOrder(purchaseOrder);
    }
    /**
     * 我的合同列表
     * @param purchaseOrder
     * @return
     */
    @GetMapping("/selectPurchaseOrderApp")
    public Page<PurchaseOrder> selectPurchaseOrderApp(PurchaseOrder purchaseOrder) {
        return purchaseOrderService.selectPurchaseOrderApp(purchaseOrder);
    }
    /**
     * 查看采购订单
     */
    @GetMapping("/getInfo")
    public PurchaseOrder getInfo(@RequestParam String id) {
        return purchaseOrderService.getInfo(id);
    }
}

