package com.shkj.wms.controller.sys;

import java.util.List;

import com.shkj.wms.bo.SysBatchEditBo;
import com.shkj.wms.bo.SysBatchQueryBo;
import com.shkj.wms.service.ISysBatchService;
import lombok.RequiredArgsConstructor;
import com.shkj.wms.config.ValidList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.shkj.common.annotation.Log;
import com.shkj.common.enums.BusinessType;
import com.shkj.common.core.controller.BaseController;
import com.shkj.common.core.domain.Result;
import com.shkj.wms.vo.SysBatchVo;
import com.shkj.wms.bo.SysBatchAddBo;
import com.shkj.common.core.page.TableDataInfo;
import com.shkj.common.utils.poi.ExcelUtil;

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

/**
 * 批次Controller
 *
 * @menu 批次管理
 * @author lch
 * @date 2022-04-09
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/batch")
public class SysBatchController extends BaseController {

    private final ISysBatchService iSysBatchService;

    /**
     * 查询批次列表
     */
    @PreAuthorize("@ss.hasPermi('wms:batch:list')")
    @GetMapping("/list")
    public TableDataInfo<SysBatchVo> list(SysBatchQueryBo bo) {
        startPage();
        List<SysBatchVo> list = iSysBatchService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出批次列表
     */
    @PreAuthorize("@ss.hasPermi('wms:batch:export')")
    @GetMapping("/export")
    public void export(HttpServletResponse response, SysBatchQueryBo bo) {
        List<SysBatchVo> list = iSysBatchService.queryList(bo);
        ExcelUtil<SysBatchVo> util = new ExcelUtil<SysBatchVo>(SysBatchVo.class);
        util.exportExcel(response, list, "批次数据");
    }

    /**
     * 获取批次详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:batch:query')")
    @GetMapping("/{id}")
    public Result<SysBatchVo> getInfo(@PathVariable("id" ) Long id) {
        return iSysBatchService.queryById(id);
    }

    /**
     * 新增批次
     */
    @PreAuthorize("@ss.hasPermi('wms:batch:add')")
    @Log(title = "批次", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result<Boolean> add(@Valid @RequestBody SysBatchAddBo bo) {
        return iSysBatchService.insertByAddBo(bo);
    }

    /**
     * 修改批次
     */
    @PreAuthorize("@ss.hasPermi('wms:batch:edit')")
    @Log(title = "批次", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result<Boolean> edit(@Valid @RequestBody SysBatchEditBo bo) {
        return iSysBatchService.updateByEditBo(bo);
    }

    /**
     * 删除批次
     */
    @PreAuthorize("@ss.hasPermi('wms:batch:remove')")
    @Log(title = "批次" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public Result<Boolean> remove(@Valid @RequestBody ValidList<Long> ids) {
        return iSysBatchService.deleteWithValidById(ids, true);
    }


}
