package cn.lihongjie.coal.purchaseOrder.controller;

import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.purchaseOrder.dto.*;
import cn.lihongjie.coal.purchaseOrder.service.PurchaseOrderService;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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;

@RestController
@RequestMapping("/purchaseOrder")
@SysLog(module = "采购订单")
@Slf4j
@OrgScope
public class PurchaseOrderController {
    @Autowired private PurchaseOrderService service;

    @PostMapping("/create")
    public PurchaseOrderDto create(@RequestBody CreatePurchaseOrderDto request) {
        return this.service.create(request);
    }

    @PostMapping("/nextPurchaseOrderNumber")
    public String nextPurchaseOrderNumber(@RequestBody CreatePurchaseOrderDto request) {
        return this.service.nextPurchaseOrderNumber(request);
    }

    @PostMapping("/update")
    public PurchaseOrderDto update(@RequestBody UpdatePurchaseOrderDto request) {
        return this.service.update(request);
    }


    @PostMapping("/updateWeightData")
    public PurchaseOrderDto updateWeightData(@RequestBody UpdateWeightDataDto request) {
        return this.service.updateWeightData(request);
    }

    @PostMapping("/delete")
    public Object delete(@RequestBody IdRequest request) {
        this.service.delete(request);
        return true;
    }

    @PostMapping("/getById")
    public PurchaseOrderDto getById(@RequestBody IdRequest request) {
        return this.service.getById(request.getId());
    }

    @PostMapping("/list")
    public Page<PurchaseOrderDto> list(@RequestBody CommonQuery request) {
        return this.service.list(request);
    }

    @PostMapping("/report")
    public Object report(@RequestBody PurchaseOrderReportRequest request) {
        return this.service.report(request);
    }
}
