
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.ext.wms.data.CancelTaskRequest;
import org.nl.acs.ext.wms.data.CreateTaskRequest;
import org.nl.acs.ext.wms.service.WmsToAcsService;
//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.List;

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

    @PostMapping("/task")
    @Log(value = "ACS接收WMS任务")
    @ApiOperation("接收WMS任务")
    @SaIgnore
    public ResponseEntity<Object> createFromWms(@RequestBody List<CreateTaskRequest> reqs) {
        return new ResponseEntity<>(wmstoacsService.crateTask(reqs), HttpStatus.OK);
    }



    @PostMapping("/getAgvInfo")
    @Log("agv信息")
    @ApiOperation("agv信息")
    public ResponseEntity<Object> allDeviceStatus() {
        return new ResponseEntity<>(wmstoacsService.allDeviceStatus(), HttpStatus.OK);
    }





    @PostMapping("/cancelTask")
    @Log(value = "WMS取消任务")
    @ApiOperation("WMS取消任务")
    @SaIgnore
    public ResponseEntity<Object> cancelFromWms(@RequestBody List<CancelTaskRequest> reqs) throws Exception {
        return new ResponseEntity<>(wmstoacsService.cancelFromWms(reqs), HttpStatus.OK);
    }

    @PostMapping("/updateDeviceGoodsFromWms")
    @Log(value = "WMS修改点位状态")
    @ApiOperation("WMS修改点位状态")
    public ResponseEntity<Object> updateDeviceGoodsFromWms(@RequestBody String whereJson) {
        return new ResponseEntity<>(wmstoacsService.updateDeviceGoodsFromWms(whereJson), HttpStatus.OK);
    }

    @PostMapping("/areaControl")
    @Log(value = "区域控制")
    @ApiOperation("区域控制")
    public ResponseEntity<Object> areaControl(@RequestBody JSONObject whereJson) {
        return new ResponseEntity<>(wmstoacsService.areaControl(whereJson), HttpStatus.OK);
    }

    @PostMapping("/action")
    @Log(value = "WMS下发点位信号")
    @ApiOperation("WMS下发点位信号")
    @SaIgnore
    public ResponseEntity<Object> putAction(@RequestBody String whereJson) throws Exception {
        return new ResponseEntity<>(wmstoacsService.putAction(whereJson), HttpStatus.OK);
    }

    @PostMapping("/querydevice")
    @Log(value = "WMS查询设备状态")
    @ApiOperation("WMS查询设备状态")
    @SaIgnore
    public ResponseEntity<Object> queryDevice(@RequestBody String whereJson) throws Exception {
        //todo 接口查询WCS AGV车辆状态
        return new ResponseEntity<>(wmstoacsService.queryDevice(whereJson), HttpStatus.OK);
    }

    @PostMapping("/queryDeviceDBValue")
    @Log(value = "WMS查询设备DB值")
    @ApiOperation("WMS查询设备DB值")
    @SaIgnore
    public ResponseEntity<Object> queryDeviceDBValue(@RequestBody String whereJson){
        return new ResponseEntity<>(wmstoacsService.queryDeviceDBValue(whereJson), HttpStatus.OK);
    }


    @PostMapping("/putPlusPullAction")
    @Log(value = "WMS下发插拔轴动作")
    @ApiOperation("WMS下发插拔轴动作")
    @SaIgnore
    public ResponseEntity<Object> putPlusPullAction(@RequestBody String whereJson){
        return new ResponseEntity<>(wmstoacsService.putPlusPullAction(whereJson), HttpStatus.OK);
    }

    @PostMapping("/notify")
    @Log("wms下发任务动作")
    @ApiOperation("wms下发任务动作")
    @SaIgnore
    public ResponseEntity<Object> notify(@RequestBody JSONObject param) {
        return new ResponseEntity<>(wmstoacsService.notifyAcs(param), HttpStatus.OK);
    }

}
