package com.prolog.cs.biz.outbound.controller;

import com.alibaba.fastjson.JSON;
import com.prolog.cs.biz.outbound.model.dto.MoveTaskDODTO;
import com.prolog.cs.biz.outbound.model.dto.MoveTaskPrintQueryDTO;
import com.prolog.cs.biz.outbound.model.dto.MoveTaskStatusSyncDTO;
import com.prolog.cs.biz.outbound.model.dto.MoveTaskUpdateDTO;
import com.prolog.cs.biz.outbound.service.MoveTaskService;
import com.prolog.framework.bz.common.print.PrintData;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;

@Api(tags = "移库任务")
@RestController
@RequestMapping("/moveTask")
public class MoveTaskController {

    private static Logger log = LoggerFactory.getLogger(MoveTaskController.class);

    @Autowired
    private MoveTaskService moveTaskService;

    @UserLog
    @ApiOperation(value = "更新移库任务状态")
    @PostMapping("/updateStatus")
    public RestMessage<Boolean> updateStatus(@RequestBody List<MoveTaskUpdateDTO> moveTaskUpdateDTOS) {
        return moveTaskService.updateStatus(moveTaskUpdateDTOS);
    }

    @UserLog
    @ApiOperation(value = "补货任务状态同步")
    @PostMapping("/instore")
    public RestMessage<Long> instore(@RequestBody MoveTaskStatusSyncDTO syncDTO) {
        return moveTaskService.instore(syncDTO);
    }

    @UserLog
    @ApiOperation(value = "增加补货任务")
    @PostMapping("/add")
    public RestMessage<Boolean> addMoveTask(@RequestBody List<MoveTaskDODTO> moveTaskDODTOS) {
        try {
            return RestMessage.doSuccess(moveTaskService.addMoveTask(moveTaskDODTOS));
        } catch (Exception e) {
            log.error("addMoveTask,moveTaskDODTOS:{}"+ JSON.toJSONString(moveTaskDODTOS),e);
            return RestMessage.doError(e.getMessage());
        }

    }

    //未使用
    @UserLog
    @ApiOperation(value = "打印补货任务")
    @PostMapping("/print")
    @Deprecated
    public RestMessage<PrintData> print(@RequestBody MoveTaskPrintQueryDTO moveTaskPrintQueryDTO) {
        PrintData result = moveTaskService.print(moveTaskPrintQueryDTO);
        return RestMessage.doSuccess(result);
    }

    @UserLog
    @ApiOperation(value = "更新补货任务")
    @PostMapping("/changeQty")
    public RestMessage changeQty(@RequestBody List<MoveTaskDODTO> moveTaskDODTOS) {
        try {
            moveTaskService.changeQty(moveTaskDODTOS);
            return RestMessage.doSuccess(null);
        } catch (Exception e) {
            log.error("changeQty,moveTaskDODTOS:{}"+ JSON.toJSONString(moveTaskDODTOS),e);
            return RestMessage.doError(e.getMessage());
        }

    }

}
