package com.bonus.sgzb.material.controller;

import cn.hutool.core.convert.Convert;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.material.domain.*;
import com.bonus.sgzb.material.service.SecondaryWarehouseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author c liu
 * @date 2024/2/29
 */
@RestController
@RequestMapping("/secondaryWarehouse")
public class SecondaryWarehouseController extends BaseController {
    @Autowired
    private SecondaryWarehouseService service;

    /**
     * 获取二级库列表
     */
    @ApiOperation(value = "获取二级库列表")
    @GetMapping("/getList")
    public TableDataInfo getList(SecondaryWarehouse bean){
        startPage();
        List<SecondaryWarehouse> list = service.getList(bean);
        return getDataTable(list);
    }

    /**
     * 二级库导出
     */
    @Log(title = "二级库导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportList")
    public void exportList(HttpServletResponse response, @RequestBody SecondaryWarehouse bean)
    {
        List<SecondaryWarehouse> list = service.getList(bean);
        ExcelUtil<SecondaryWarehouse> util = new ExcelUtil<SecondaryWarehouse>(SecondaryWarehouse.class);
        util.exportExcel(response, list, "二级库导出");
    }

    /**
     * 出库/退库操作
     */
    @ApiOperation(value = "出库/退库操作")
    @PostMapping("/operate")
    @Log(title = "二级库管理--出库退库操作")
    public AjaxResult operate(@RequestBody TeamLeaseInfo bean){
        int i = service.addNewOperate(bean);
        return toAjax(i);
    }

    /**
     * 获取操作记录
     */
    @ApiOperation(value = "获取操作记录")
    @GetMapping("/getOperateList")
    public TableDataInfo getOperateList(TeamLeaseInfo bean){
        startPage();
        List<TeamLeaseInfo> list = service.getOperateList(bean);
        return getDataTable(list);
    }

    /**
     * 出库台账导出
     */
    @Log(title = "出库台账导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportOperateList")
    public void exportOperateList(HttpServletResponse response, @RequestBody TeamLeaseInfo bean)
    {
        List<TeamLeaseInfo> list = service.getOperateList(bean);
        ExcelUtil<TeamLeaseInfo> util = new ExcelUtil<TeamLeaseInfo>(TeamLeaseInfo.class);
        util.exportExcel(response, list, "出库台账导出");
    }

    /**
     * 回库台账导出
     */
    @Log(title = "回库台账导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIntOperateList")
    public void exportIntOperateList(HttpServletResponse response, @RequestBody TeamLeaseInfo bean)
    {
        List<TeamLeaseInfo> list = service.getOperateList(bean);
        List<TeamLeaseInfoTwo> listTwo = Convert.toList(TeamLeaseInfoTwo.class,list);
        ExcelUtil<TeamLeaseInfoTwo> util = new ExcelUtil<TeamLeaseInfoTwo>(TeamLeaseInfoTwo.class);
        util.exportExcel(response, listTwo, "回库台账导出");
    }

    /**
     * 获取进场、退场、场内库存记录
     */
    @ApiOperation(value = "获取进场、退场、场内库存记录")
    @GetMapping("/getRecords")
    public TableDataInfo getRecords(TeamLeaseInfo bean){
        startPage();
        List<TeamLeaseInfo> list = service.getRecords(bean);
        return getDataTable(list);
    }

}
