package com.yunfeiyun.agmp.fms.controller;

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

import com.yunfeiyun.agmp.fms.domain.WmsChange;
import com.yunfeiyun.agmp.fms.domain.reqvo.WmsChangeReqVo;
import com.yunfeiyun.agmp.fms.domain.resvo.WmsChangeResVo;
import com.yunfeiyun.agmp.fms.service.IWmsChangeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;

/**
 * 变动Controller
 * 
 * @author 杨晓辉
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/wms/change")
public class WmsChangeController extends BaseController
{
    @Autowired
    private IWmsChangeService wmsChangeService;

    /**
     * 查询变动列表
     */
    @PreAuthorize("@ss.hasPermi('wms:change:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsChange wmsChange)
    {
        startPage();
        List<WmsChange> list = wmsChangeService.selectWmsChangeList(wmsChange);
        return getDataTable(list);
    }

    /**
     * 出入庫列表
     */
    @PreAuthorize("@ss.hasPermi('wms:change:finishgoods:list')")
    @GetMapping("/finishGoods/list")
    public TableDataInfo listOfFinishGoods(WmsChangeReqVo reqVo)
    {
        startPage();
        List<WmsChangeResVo> list = wmsChangeService.selectWmsChangeListOfFinishGoods(reqVo);
        return getDataTable(list);
    }

    /**
     * 导出变动列表
     */
    @PreAuthorize("@ss.hasPermi('wms:change:export')")
    @Log(title = "变动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsChange wmsChange)
    {
        List<WmsChange> list = wmsChangeService.selectWmsChangeList(wmsChange);
        ExcelUtil<WmsChange> util = new ExcelUtil<WmsChange>(WmsChange.class);
        util.exportExcel(response, list, "变动数据");
    }

    /**
     * 获取变动详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:change:query')")
    @GetMapping(value = "/{changeId}")
    public AjaxResult getInfo(@PathVariable("changeId") String changeId)
    {
        return success(wmsChangeService.selectWmsChangeByChangeId(changeId));
    }

    /**
     * 新增变动
     */
    @PreAuthorize("@ss.hasPermi('wms:change:add')")
    @Log(title = "变动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsChange wmsChange)
    {
        return toAjax(wmsChangeService.insertWmsChange(wmsChange));
    }

    /**
     * 修改变动
     */
    @PreAuthorize("@ss.hasPermi('wms:change:edit')")
    @Log(title = "变动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsChange wmsChange)
    {
        return toAjax(wmsChangeService.updateWmsChange(wmsChange));
    }

    /**
     * 删除变动
     */
    @PreAuthorize("@ss.hasPermi('wms:change:remove')")
    @Log(title = "变动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{changeIds}")
    public AjaxResult remove(@PathVariable String[] changeIds)
    {
        return toAjax(wmsChangeService.deleteWmsChangeByChangeIds(changeIds));
    }
}
