package com.hw.wms.controller;

import com.hw.common.core.constant.WmsConstants;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.wms.domain.WmsRawOutstock;
import com.hw.wms.domain.WmsRawOutstockDetail;
import com.hw.wms.domain.WmsRawReturn;
import com.hw.wms.domain.WmsRawReturnDetail;
import com.hw.wms.domain.vo.*;
import com.hw.wms.service.IWmsRawInstockService;
import com.hw.wms.service.IWmsRawOutstockService;
import com.hw.wms.service.IWmsRawReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * scada Controller,提供给上位机调用
 *
 * @author xins
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/wms/scada")
public class WmsScadaController extends BaseController {

    @Autowired
    private IWmsRawOutstockService wmsRawOutstockService;

    @Autowired
    private IWmsRawReturnService wmsRawReturnService;


    /**
     * 申请领料
     */
//    @RequiresPermissions("wms:mobile:addrawinstock")
    @Log(title = "原材料出库记录", businessType = BusinessType.APPLY)
    @PostMapping(("/applyRawOutstock"))
    public AjaxResult applyRawOutstock(@Validated @RequestBody WmsRawOutstock wmsRawOutstock) {
        return toAjax(wmsRawOutstockService.applyRawOutstock(wmsRawOutstock));
        //如果申请时不审核，需要agv输送的，需要上位机调度WCS调度AGV
    }


    /**
     * 查询原材料待审核状态的出库记录列表
     */
//    @RequiresPermissions("wms:rawoutstock:list")
    @GetMapping("/getToAuditedRawOutstocks")
    public AjaxResult getToAuditedRawOutstocks() {
        startPage();
        WmsRawOutstock wmsRawOutstock = new WmsRawOutstock();
        wmsRawOutstock.setAuditStatus(WmsConstants.WMS_AUDIT_STATUS_TOAUDIT);
        List<WmsRawOutstock> list = wmsRawOutstockService.selectWmsRawOutstockList(wmsRawOutstock);
        return success(list);
    }

    /**
     * 获取原材料出库记录详细信息
     */
//    @RequiresPermissions("wms:rawoutstock:query")
    @GetMapping(value = "/getRawOutstockByOutstockId/{rawOutstockId}")
    public AjaxResult getRawOutstockByOutstockId(@PathVariable("rawOutstockId") Long rawOutstockId) {
        return success(wmsRawOutstockService.selectWmsRawOutstockByRawOutstockId(rawOutstockId));
    }

    /**
     * 审核原材料出库记录
     */
    @Log(title = "原材料出库记录", businessType = BusinessType.AUDIT)
    @PostMapping(("/auditRawOutstock"))
    public AjaxResult auditRawOutstock(@Validated @RequestBody WmsRawOutstockAuditVo wmsRawOutstockAuditVo) {
        return success(wmsRawOutstockService.auditWmsRawOutstock(wmsRawOutstockAuditVo));
        //审核通过后，如果是需要agv出库，则由上位机通知WCS进行调度AGV
    }



    @Log(title = "原材料出库记录", businessType = BusinessType.AUDIT)
    @PostMapping(("/applyAgvRawOutstock"))
    public AjaxResult applyAgvRawOutstock(@Validated @RequestBody WmsAgvRawOutstockVo wmsAgvRawOutstockVo) {
        return success(wmsRawOutstockService.applyAgvRawOutstock(wmsAgvRawOutstockVo));
        //审核通过后，如果是需要agv出库，则由上位机通知WCS进行调度AGV
    }





}
