package com.prolog.eis.controller.shelves;

import com.prolog.eis.dto.inbound.*;
import com.prolog.eis.dto.page.PageDto;
import com.prolog.eis.dto.page.PageUtilDto;
import com.prolog.eis.dto.shelves.StationNoDTO;
import com.prolog.eis.service.shelves.InboundTaskService;
import com.prolog.eis.vo.InboundTaskVO;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.dao.util.PageUtils;
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.apache.commons.lang.StringUtils;
import org.springframework.data.domain.jaxb.SpringDataJaxb;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 *
 * @author zhanghan
 */
@Api(tags = "pda拆零上架")
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/pda")
public class PdaShelvesController {

    private final InboundTaskService inboundTaskService;

    @ApiOperation(value = "获取拆零上架任务列表", notes = "获取拆零上架任务列表")
    @PostMapping("/shelvesTaskList")
    @InterfaceMethod(key = "获取拆零上架任务列表", name = "获取拆零上架任务列表", type = InterfaceType.Receive)
    public RestMessage<Page<ShelvesTaskListDto>> shelvesTaskList(@RequestBody PageUtilDto pageUtilDto) {
        try {
            List<ShelvesTaskListDto> list = inboundTaskService.shelvesTaskList(pageUtilDto);
            return RestMessage.doSuccess(PageUtils.getPage(list));
        } catch (Exception e) {
            log.error("获取拆零上架任务异常：{}", e.getMessage(), e);
            return RestMessage.doError(e.getMessage());
        }
    }

    @ApiOperation(value = "获取拆零上架任务详情", notes = "获取拆零上架任务详情")
    @PostMapping("/shelvesTaskDetail")
    @InterfaceMethod(key = "获取拆零上架任务详情", name = "获取拆零上架任务详情", type = InterfaceType.Receive)
    public RestMessage<List<ShelvesTaskDetailRespDto>> shelvesTaskDetail(@RequestBody ShelvesTaskDetailReqDto req) {
        try {
            List<ShelvesTaskDetailRespDto> list = inboundTaskService.shelvesTaskDetail(req);
            return RestMessage.doSuccess(list);
        } catch (Exception e) {
            log.error("获取拆零上架任务详情异常：{}", e.getMessage(), e);
            return RestMessage.doError(e.getMessage());
        }
    }

    @ApiOperation(value = "拆零上架确认", notes = "拆零上架确认")
    @PostMapping("/shelvesTaskSubmit")
    @InterfaceMethod(key = "拆零上架确认", name = "拆零上架确认", type = InterfaceType.Receive)
    public RestMessage shelvesTaskSubmit(@RequestBody @Valid ShelvesTaskSubmitDto req) {
        try {
            inboundTaskService.shelvesTaskSubmit(req);
            return RestMessage.doSuccess(null);
        } catch (Exception e) {
            log.error("拆零上架确认异常：{}", e.getMessage(), e);
            return RestMessage.doError(e.getMessage());
        }
    }

    @ApiOperation(value = "货架归还", notes = "货架归还")
    @PostMapping("/shelfReturn")
    @InterfaceMethod(key = "货架归还", name = "货架归还", type = InterfaceType.Receive)
    public RestMessage shelfReturn(@RequestBody  @Valid ShelvesReturnDto req) {
        try {
            inboundTaskService.shelfReturnPda(req,true);
            return RestMessage.doSuccess(null);
        } catch (Exception e) {
            log.error("货架归还异常：{}", e.getMessage(), e);
            return RestMessage.doError(e.getMessage());
        }
    }

    @ApiOperation(value = "重新分配查询", notes = "重新分配查询")
    @PostMapping("/againList")
    @InterfaceMethod(key = "重新分配查询", name = "重新分配查询", type = InterfaceType.Receive)
    public RestMessage<Page<AgainListRespDto>> againList(@RequestBody @Valid  AgainListReqDto req) {
        try {
            List<AgainListRespDto> list = inboundTaskService.againList(req);
            return RestMessage.doSuccess(PageUtils.getPage(list));
        } catch (Exception e) {
            log.error("重新分配查询异常：{}", e.getMessage(), e);
            return RestMessage.doError(e.getMessage());
        }
    }

    @ApiOperation(value = "重新分配确认", notes = "重新分配确认")
    @PostMapping("/againConfirm")
    @InterfaceMethod(key = "重新分配确认", name = "重新分配确认", type = InterfaceType.Receive)
    public RestMessage againConfirm(@RequestBody  @Valid AgainConfirmReqDto req) {
        try {
            inboundTaskService.againConfirm(req);
            return RestMessage.doSuccess(null);
        } catch (Exception e) {
            log.error("重新分配确认异常：{}", e.getMessage(), e);
            return RestMessage.doError(e.getMessage());
        }
    }

    @ApiOperation(value = "货位调整确认", notes = "货位调整确认")
    @PostMapping("/locationChange")
    @InterfaceMethod(key = "货位调整确认", name = "货位调整确认", type = InterfaceType.Receive)
    public RestMessage locationChange(@RequestBody @Valid LocationChangeReqDto req) {
        try {
            inboundTaskService.locationChange(req);
            return RestMessage.doSuccess(null);
        } catch (Exception e) {
            log.error("重新分配确认异常：{}", e.getMessage(), e);
            return RestMessage.doError(e.getMessage());
        }
    }
}
