src/main/java/com/zy/asrs/controller/OpenController.java
@@ -1,10 +1,15 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.common.R;
import com.zy.asrs.domain.param.ToInStaParam;
import com.zy.asrs.domain.param.ToOutStaParam;
import com.zy.asrs.entity.RcsReporterTask;
import com.zy.asrs.entity.RcsReturn;
import com.zy.asrs.service.RcsService;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
@@ -13,16 +18,18 @@
import com.zy.core.thread.SiemensDevpThread;
import lombok.extern.slf4j.Slf4j;
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 org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
@Slf4j
@RestController
public class OpenController {
    @Autowired
    private RcsService rcsService;
    @Value("${zyHikUrl}")
    private String zyHikUrl;
    @RequestMapping("/open/toOutSta")
    public R toOutSta(@RequestBody ToOutStaParam param) {
@@ -61,4 +68,55 @@
        return rcsService.reporterTask(param);
    }
    @RequestMapping("/open/toInSta")
    public R toInSta(@RequestBody ToInStaParam param) {
        log.info("toInSta:{}",param);
        SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
        if(siemensDevpThread == null) {
            return R.error("线程不存在");
        }
        StaProtocol staProtocol = siemensDevpThread.getStation().get(param.getStaNo()).clone();
        if(staProtocol == null) {
            return R.error("站点不存在");
        }
        if (!staProtocol.isLoading()) {
            return R.error("站点无物");
        }
        Short s = 301;
        if (param.getStaNo() == 304 || param.getStaNo() == 305 || param.getStaNo() == 306) {
            s = 304;
        }
        staProtocol.setWorkNo(param.getWrkNo().shortValue());
        staProtocol.setStaNo(s);
        boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
        log.info("发生成功:{}",result);
        return R.ok().add(result);
    }
    @RequestMapping("/open/capture")
    public void startPic(@RequestParam String ip,@RequestParam String filename) {
        try {
            HashMap<String, Object> data = new HashMap<>();
            data.put("ip", ip);
            data.put("filename", filename);
            String response = new HttpHandler.Builder()
                    .setUri(zyHikUrl)
                    .setPath("/capture")
                    .setJson(JSON.toJSONString(data))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getBoolean("success")) {
                News.error("请求接口成功!!!url:{};request:{};response:{}", zyHikUrl + "/startPic", JSON.toJSONString(data), response);
            } else {
                News.error("请求接口失败!!!url:{};request:{};response:{}", zyHikUrl + "/startPic", JSON.toJSONString(data), response);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}