package com.ruoyi.web.controller.app;

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

import com.ruoyi.app.domain.AppPendingStorage;
import com.ruoyi.app.domain.AppPendingStorageRequest;
import com.ruoyi.app.domain.DTO.OtherStockInRequest;
import com.ruoyi.app.service.IAppPendingStorageService;
import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库码盘Controller
 *
 * @author ruoyi
 * @date 2025-02-22
 */
@Anonymous
@RestController
@RequestMapping("/system/storage")
public class AppPendingStorageController extends BaseController
{
    @Autowired
    private IAppPendingStorageService appPendingStorageService;

    /**
     * 查询入库码盘列表
     */
    @PreAuthorize("@ss.hasPermi('system:storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppPendingStorage appPendingStorage)
    {
        startPage();
        List<AppPendingStorage> list = appPendingStorageService.selectAppPendingStorageList(appPendingStorage);
        return getDataTable(list);
    }

    /**
     * 导出入库码盘列表
     */
    @PreAuthorize("@ss.hasPermi('system:storage:export')")
    @Log(title = "入库码盘", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppPendingStorage appPendingStorage)
    {
        List<AppPendingStorage> list = appPendingStorageService.selectAppPendingStorageList(appPendingStorage);
        ExcelUtil<AppPendingStorage> util = new ExcelUtil<AppPendingStorage>(AppPendingStorage.class);
        util.exportExcel(response, list, "入库码盘数据");
    }

    /**
     * 获取入库码盘详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:storage:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") String recordId)
    {
        return success(appPendingStorageService.selectAppPendingStorageByRecordId(recordId));
    }

    /**
     * 新增入库码盘
     */
    @PreAuthorize("@ss.hasPermi('system:storage:add')")
    @Log(title = "入库码盘", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppPendingStorage appPendingStorage)
    {
        return toAjax(appPendingStorageService.insertAppPendingStorage(appPendingStorage));
    }

    /**
     * 修改入库码盘
     */
    @PreAuthorize("@ss.hasPermi('system:storage:edit')")
    @Log(title = "入库码盘", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppPendingStorage appPendingStorage)
    {
        return toAjax(appPendingStorageService.updateAppPendingStorage(appPendingStorage));
    }

    /**
     * 删除入库码盘
     */
    @PreAuthorize("@ss.hasPermi('system:storage:remove')")
    @Log(title = "入库码盘", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable String[] recordIds)
    {
        return toAjax(appPendingStorageService.deleteAppPendingStorageByRecordIds(recordIds));
    }


    /**
     * 空载具入库码盘
     * PDA 请求此接口
     * @param vehicleNo 载具号
     * @return 返回结果
     */
    @Log(title = "空载具入库码盘", businessType = BusinessType.INSERT)
    @PostMapping("/addEmpty")
    public AjaxResult addEmpty(@RequestParam String vehicleNo) {
        return toAjax(appPendingStorageService.addAppEmptyPmsOrderIn(vehicleNo));
    }



    @PostMapping("/addOtherList")
    public AjaxResult addOtherList(@RequestBody OtherStockInRequest otherStockInRequest) {
        return toAjax(appPendingStorageService.addAppListPmsOrderIn(otherStockInRequest));
    }
}
