package com.prolog.eis.controller.pda;

import com.prolog.eis.dto.outbound.SpecifyContainerCarryDto;
import com.prolog.eis.dto.rf.ConfirmMoveContainerReqDto;
import com.prolog.eis.dto.rf.ContainerStockRespDto;
import com.prolog.eis.dto.rf.WMSAreaRespDto;
import com.prolog.eis.service.page.PdaService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.fx.inf.core.InterfaceType;
import com.prolog.fx.inf.core.annotation.InterfaceMethod;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/v1/pda")
@RequiredArgsConstructor
@Api(tags = "PDA接口服务")
public class PdaMoveController {

    @Resource
    private PdaService pdaService;

    @ApiOperation(value = "移库出库容器查询", notes = "移库出库容器查询")
    @RequestMapping(method = RequestMethod.GET, value = "/queryMoveContainer")
    @InterfaceMethod(key = "queryMoveContainer", name = "移库出库容器查询", type = InterfaceType.Receive)
    public RestMessage<ContainerStockRespDto> queryMoveContainer(@RequestParam("containerSubNo") String containerSubNo) {
        try {
            ContainerStockRespDto result = pdaService.findMoveContainer(containerSubNo);
            return RestMessage.success("请求成功", result);
        } catch (Exception e) {
            log.error("移库出库容器查询:{}", e.getMessage());
            return RestMessage.error("请求异常" + e.getMessage());
        }
    }

    @ApiOperation(value = "查询WMS区域", notes = "查询WMS区域")
    @RequestMapping(method = RequestMethod.GET, value = "/queryWMSArea")
    @InterfaceMethod(key = "queryWMSArea", name = "查询WMS区域", type = InterfaceType.Receive)
    public RestMessage<List<WMSAreaRespDto>> queryWMSArea() {
        try {
            List<WMSAreaRespDto> result = pdaService.queryArea();
            return RestMessage.success("请求成功", result);
        } catch (Exception e) {
            log.error("查询WMS区域:{}", e.getMessage());
            return RestMessage.error("请求异常" + e.getMessage());
        }
    }

    @ApiOperation(value = "确认移库", notes = "确认移库")
    @RequestMapping(method = RequestMethod.POST, value = "/confirmMoveContainer")
    @InterfaceMethod(key = "confirmMoveContainer", name = "确认移库", type = InterfaceType.Receive)
    public RestMessage<?> confirmMoveContainer(@Valid @RequestBody ConfirmMoveContainerReqDto req) {
        try {
            pdaService.confirmMoveContainer(req);
            return RestMessage.success("请求成功", null);
        } catch (Exception e) {
            log.error("确认移库:{}",e.getMessage());
            return RestMessage.error("请求异常" + e.getMessage());
        }
    }

}
