package com.hys.app.controller.erp.use;

import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dto.StockTransferDTO;
import com.hys.app.model.erp.dto.StockTransferQueryParams;
import com.hys.app.model.erp.dto.StockTransferStatisticsParam;
import com.hys.app.model.erp.vo.StockTransferVO;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.service.erp.StockTransferManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


/**
 * 库存调拨API
 *
 * @author 张崧
 * @since 2023-12-12 11:59:06
 */
@RestController
@RequestMapping("/admin/erp/stockTransfer")
@Api(tags = "库存调拨API")
@Validated
public class StockTransferManagerController {

    @Autowired
    private StockTransferManager stockTransferManager;

    @ApiOperation(value = "分页列表")
    @GetMapping
    public WebPage<StockTransferVO> list(StockTransferQueryParams queryParams) {
        return stockTransferManager.list(queryParams);
    }

    @ApiOperation(value = "添加")
    @PostMapping
    @Log(client = LogClient.admin, detail = "创建调拨单")
    public void add(@RequestBody @Valid StockTransferDTO stockTransferDTO) {
        stockTransferManager.add(stockTransferDTO);
    }

    @ApiOperation(value = "修改")
    @PutMapping("/{id}")
    @Log(client = LogClient.admin, detail = "编辑ID为[${id}]的调拨单")
    public void edit(@PathVariable String id, @RequestBody @Valid StockTransferDTO stockTransferDTO) {
        stockTransferDTO.setId(id);
        stockTransferManager.edit(stockTransferDTO);
    }

    @ApiOperation(value = "查看詳情")
    @GetMapping("/{id}")
    @Log(client = LogClient.admin, detail = "编辑ID为[${id}]的调拨单")
    public StockTransferVO getDetail(@PathVariable Long id) {
        return stockTransferManager.getDetail(id);
    }

    @ApiOperation(value = "提交调拨单")
    @PostMapping("/{id}/submit")
    @Log(client = LogClient.admin, detail = "提交ID为[${id}]的调拨单")
    public void submit(@PathVariable Long id) {
        stockTransferManager.submit(id);
    }

    @ApiOperation(value = "撤销调拨单")
    @PostMapping("/{id}/withdraw")
    @Log(client = LogClient.admin, detail = "撤销ID为[${id}]的调拨单")
    public void withdraw(@PathVariable Long id) {
        stockTransferManager.withdraw(id);
    }

    @ApiOperation(value = "查询库存调拨统计分页列表数据")
    @GetMapping("/statistics")
    public WebPage statistics(StockTransferStatisticsParam params) {
        return stockTransferManager.statistics(params);
    }

    @ApiOperation(value = "导出库存调拨统计列表")
    @GetMapping("/export")
    public void export(HttpServletResponse response, StockTransferStatisticsParam params) {
        this.stockTransferManager.export(response, params);
    }
}

