
package org.nl.acs.ext.wms.rest;


import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device_driver.RequestMethodEnum;
import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest;
import org.nl.acs.ext.wms.data.BaseRequest;
import org.nl.acs.ext.wms.data.LiKuApplyTaskRequest;
import org.nl.acs.ext.wms.service.AcsToWmsService;
//import org.nl.modules.logging.InterfaceLogType;
import org.nl.common.logging.annotation.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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.Map;

/**
 * @author ludj
 * @date 2021-07-21
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "wms接口")
@RequestMapping("/api/wms")
@Slf4j
public class AcsToWmsController {
    private final AcsToWmsService acstowmsService;

    @PostMapping("/applyTask")
    @Log(value = "ACS向WMS申请任务")
    @ApiOperation("ACS向WMS申请任务")
    public ResponseEntity<Object> applyTaskToWms(@RequestBody JSONObject jo) {
        return new ResponseEntity<>(acstowmsService.applyTaskToWms(jo), HttpStatus.OK);
    }

    @PostMapping("/taskStatusFeedback")
    @Log(value = "ACS向WMS反馈任务状态")
    @ApiOperation("ACS向WMS反馈任务状态")
    public ResponseEntity<Object> feedbackTaskStatusToWms(@RequestBody Map whereJson) {
        JSONArray data = JSONArray.parseArray(String.valueOf(whereJson));
        return new ResponseEntity<>(acstowmsService.feedbackTaskStatusToWms(data), HttpStatus.OK);
    }

    @PostMapping("/feedbackAgvStatus")
    @Log(value = "反馈AGV设备状态")
    @ApiOperation("反馈AGV设备状态")
    public ResponseEntity<Object> feedbackAgvStatus(@RequestBody String device_code, String error, String error_message) {
        return new ResponseEntity<>(acstowmsService.feedbackAgvStatus(device_code, error, error_message), HttpStatus.OK);
    }

    @PostMapping("/feedbackAgv")
    @Log(value = "反馈AGV设备信息")
    @ApiOperation("反馈AGV设备信息")
    public ResponseEntity<Object> feedbackAgv(@RequestBody JSONArray from) {
        return new ResponseEntity<>(acstowmsService.feedbackAgv(from), HttpStatus.OK);
    }

    @PostMapping("/feedbackDeviceStatus")
    @Log(value = "反馈设备状态")
    @ApiOperation("反馈设备状态")
    public ResponseEntity<Object> feedbackDeviceStatus(@RequestBody String device_code, String code, String value) {
        return new ResponseEntity<>(acstowmsService.feedbackDeviceStatus(device_code, value), HttpStatus.OK);
    }

    @PostMapping("/feedTaskStatus")
    @Log(value = "反馈任务状态")
    @ApiOperation("反馈任务状态")
    @SaIgnore
    public ResponseEntity<Object> feedTaskStatus(@RequestBody String task_code, String status) {
        BaseRequest request = BaseRequest.builder().taskId(task_code).state(status).request_medthod_code(RequestMethodEnum.feedback_task_status.getCode()).request_medthod_name(RequestMethodEnum.feedback_task_status.getName()).build();
        return new ResponseEntity<>(acstowmsService.feedTaskStatus(request), HttpStatus.OK);
    }

    @PostMapping("/feedbackOrderStatus")
    @Log(value = "ACS强制完成向WMS反馈")
    @ApiOperation("acs强制完成向wms反馈")
    public ResponseEntity<Object> feedbackOrderStatus(@RequestBody JSONObject param) {
        return new ResponseEntity<>(acstowmsService.feedbackOrderStatus(param), HttpStatus.OK);
    }


    @PostMapping("/applyInCacheLineTask")
    @Log(value = "ACS申请缓存线入库任务")
    @ApiOperation("ACS申请缓存线入库任务")
    public ResponseEntity<Object> applyInCacheLineTask(@RequestBody JSONObject param) {
        return new ResponseEntity<>(acstowmsService.applyInCacheLineTask(param), HttpStatus.OK);
    }

    @PostMapping("/applyOutCacheLineTask")
    @Log(value = "ACS系统申请出库任务")
    @ApiOperation("ACS系统申请出库任务")
    public ResponseEntity<Object> applyOutCacheLineTask(@RequestBody JSONObject param) {
        return new ResponseEntity<>(acstowmsService.applyOutCacheLineTask(param), HttpStatus.OK);
    }

    @PostMapping("/applyLabelingAndBindingRequest")
    @Log(value = "ACS系统申请贴标、捆扎")
    @ApiOperation("ACS系统申请贴标、捆扎")
    public ResponseEntity<Object> applyLabelingAndBindingRequest(@RequestBody ApplyLabelingAndBindingRequest param) {
        return new ResponseEntity<>(acstowmsService.applyLabelingAndBindingRequest(param), HttpStatus.OK);
    }

    @PostMapping("/liKuApplyTaskRequest")
    @Log(value = "立库申请任务")
    @ApiOperation("立库申请任务")
    public ResponseEntity<Object> liKuApplyTaskRequest(@RequestBody LiKuApplyTaskRequest param) {
        return new ResponseEntity<>(acstowmsService.liKuApplyTaskRequest(param), HttpStatus.OK);
    }

    @PostMapping("/feedAgvTaskStatus")
    @Log(value = "反馈AGV取放货状态")
    @ApiOperation("反馈AGV取放货状态")
    public ResponseEntity<Object> feedAgvTaskStatus(@RequestBody JSONArray from) {
        return new ResponseEntity<>(acstowmsService.feedAgvTaskStatus(from), HttpStatus.OK);
    }
}
