package com.youchain.businessdata.rest;

import com.alibaba.fastjson.JSONObject;
import com.github.s7connector.api.S7Connector;
import com.youchain.annotation.AnonymousAccess;
import com.youchain.annotation.Log;
import com.youchain.businessdata.service.MoService;
import com.youchain.exception.handler.ApiResult;
import com.youchain.utils.S7ConnectorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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 static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.OK;

/**
 * @author huojin
 * @website
 * @date 2024-04-10
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "plc管理")
@RequestMapping("/api/plc")
public class PlcController {

    private final MoService moService;

    @PostMapping("/scanMo")
    @AnonymousAccess
    @Log("PLC扫描容器")
    @ApiOperation("PLC扫描容器")
    public ResponseEntity<Object> scanMo(@RequestBody String moJson) {
        JSONObject json = JSONObject.parseObject(moJson);
        if (json == null) {
            return new ResponseEntity<>(ApiResult.success(BAD_REQUEST.value(), "参数错误", ""), HttpStatus.BAD_REQUEST);
        }
        String mo = json.getString("mo");// MO票
        String lx = json.getString("lx");// 容器
        String[] mos = mo.split("]");
//            LB]A0006897]240625]12125300000145]200]240625104089]]
        String it = mos[3];// 料号
        String labelNo=mos[5];// 标签

        return new ResponseEntity<>(ApiResult.fail(500, "测试入库已关闭", null), HttpStatus.OK);
    }
}
