package com.yunfeiyun.agmp.fms.controller;

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.core.page.TableDataInfo;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
import com.yunfeiyun.agmp.fms.domain.WmsChangeapply;
import com.yunfeiyun.agmp.fms.domain.reqvo.WmsChangeApplyAuditReqVo;
import com.yunfeiyun.agmp.fms.domain.reqvo.WmsChangeApplyGoodsListReqVo;
import com.yunfeiyun.agmp.fms.domain.reqvo.WmsChangeApplyListReqVo;
import com.yunfeiyun.agmp.fms.domain.reqvo.WmsChangeApplyReqVo;
import com.yunfeiyun.agmp.fms.domain.resvo.WmsChangeApplyGoodsListResVo;
import com.yunfeiyun.agmp.fms.domain.resvo.WmsChangeApplyListResVo;
import com.yunfeiyun.agmp.fms.service.IWmsChangeapplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 变动申请Controller
 * 
 * @author 杨晓辉
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/wms/changeapply")
public class WmsChangeapplyController extends BaseController
{
    @Autowired
    private IWmsChangeapplyService WmsChangeapplyService;

    /**
     * 查询出入库记录列表-不包含APP的领用和退还
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:list')")
    @GetMapping("/list")
    public TableDataInfo list( WmsChangeApplyListReqVo wmsChangeApplyListReqVo)
    {
        startPage();
        List<WmsChangeApplyListResVo> list = WmsChangeapplyService.selectWmsChangeApplyListResVoList(wmsChangeApplyListReqVo);
        return getDataTable(list);
    }

    /**
     * 查询变动申请列表
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:goods:list')")
    @GetMapping("/goods/list")
    public TableDataInfo goodsList(@Valid WmsChangeApplyGoodsListReqVo wmsChangeApplyGoodsListReqVo)
    {
        startPage();
        List<WmsChangeApplyGoodsListResVo> list = WmsChangeapplyService.selectWmsChangeApplyGoodsListResVoList(wmsChangeApplyGoodsListReqVo);
        return getDataTable(list);
    }

    /**
     * 导出变动申请列表
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:export')")
    @Log(title = "变动申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsChangeapply wmsChangeapply)
    {
        List<WmsChangeapply> list = WmsChangeapplyService.selectWmsChangeapplyList(wmsChangeapply);
        ExcelUtil<WmsChangeapply> util = new ExcelUtil<WmsChangeapply>(WmsChangeapply.class);
        util.exportExcel(response, list, "变动申请数据");
    }

    /**
     * 获取变动申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:query')")
    @GetMapping(value = "/{changeapplyId}")
    public AjaxResult getInfo(@PathVariable("changeapplyId") String changeapplyId)
    {
        return success(WmsChangeapplyService.selectWmsChangeapplyByChangeapplyId(changeapplyId));
    }
    /**
     * 获取变动申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:detail')")
    @GetMapping(value = "/detail")
    public AjaxResult detail(@RequestParam String changeapplyId)
    {
        return success(WmsChangeapplyService.selectWmsChangeapplyDetail(changeapplyId));
    }


    /**
     * 新增变动申请
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:add')")
    @Log(title = "变动申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsChangeapply wmsChangeapply)
    {
        return toAjax(WmsChangeapplyService.insertWmsChangeapply(wmsChangeapply));
    }

    /**
     * 修改变动申请
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:edit')")
    @Log(title = "变动申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsChangeapply wmsChangeapply)
    {
        return toAjax(WmsChangeapplyService.updateWmsChangeapply(wmsChangeapply));
    }

    /**
     * 删除变动申请
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:remove')")
    @Log(title = "删除变动申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{changeapplyIds}")
    public AjaxResult remove(@PathVariable String[] changeapplyIds)
    {
        return toAjax(WmsChangeapplyService.deleteWmsChangeapplyByChangeapplyIds(changeapplyIds));
    }

    /**
     * 变动申请审核
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:audit')")
    @Log(title = "变动申请审核", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody WmsChangeApplyAuditReqVo wmsChangeApplyAuditReqVo)
    {
        return toAjax(WmsChangeapplyService.audit(wmsChangeApplyAuditReqVo));
    }

    /**
     * 变动申请审核
     */
    @PreAuthorize("@ss.hasPermi('wms:changeapply:apply')")
    @Log(title = "变动申请", businessType = BusinessType.INSERT)
    @PostMapping("/apply")
    public AjaxResult apply(@Valid @RequestBody WmsChangeApplyReqVo wmsChangeApplyReqVo)
    {
        return toAjax(WmsChangeapplyService.apply(wmsChangeApplyReqVo));
    }


}
