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


import com.yh.saas.plugin.yiliangyiyun.entity.SaleOrder;
import com.yh.saas.plugin.yiliangyiyun.exception.ServiceException;
import com.yh.saas.plugin.yiliangyiyun.service.ISaleOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.plugins.Page;

import java.text.ParseException;

/**
 * <p>
 * 销售订单 前端控制器
 * </p>
 *
 * @author Gongdc
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/saleOrder")
public class SaleOrderController {
    @Autowired
    private ISaleOrderService saleOrderService;

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

    /**
     * 平仓
     * @param saleOrder
     * @return
     */
    @PostMapping("/api/closePosition")
    public String closePosition(@RequestBody SaleOrder saleOrder) {
        return saleOrderService.closePosition(saleOrder);
    }

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

    /**
     * 销售订单列表
     * @param saleOrder
     * @return
     */
    @GetMapping("/selectSaleOrder")
    public Page<SaleOrder> selectSaleOrder(SaleOrder saleOrder) {
        return saleOrderService.selectSaleOrder(saleOrder);
    }

    /**
     * 添加销售订单
     * @param saleOrder
     * @return
     */
    @PostMapping("/api/insertSaleOrder")
    public String insertSaleOrder(@RequestBody SaleOrder saleOrder) {
        return saleOrderService.insertSaleOrder(saleOrder);
    }

    /**
     * 删除销售订单
     * @param saleOrder
     */
    @PostMapping("/api/deleteSaleOrder")
    public void deleteSaleOrder(@RequestBody SaleOrder saleOrder) {
        saleOrderService.deleteSaleOrder(saleOrder.getId());
    }
    /**
     * 编辑销售订单
     * @param saleOrder
     * @return
     */
    @PostMapping("/api/editSaleOrder")
    public String editSaleOrder(@RequestBody SaleOrder saleOrder){
        return saleOrderService.editSaleOrder(saleOrder);
    }
    /**
     * 查看销售订单
     */
    @GetMapping("/getInfo")
    public SaleOrder getInfo(@RequestParam String id) {
        return saleOrderService.getInfo(id);
    }

}

