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; import com.zy.core.model.Task; import com.zy.core.model.protocol.StaProtocol; import com.zy.core.thread.SiemensDevpThread; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; 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) { log.info("toOutSta:{}",param); Integer sourceStaNo = param.getSourceStaNo(); SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); if(siemensDevpThread == null) { return R.error("线程不存在"); } StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone(); if(staProtocol == null) { return R.error("站点不存在"); } if (staProtocol.getWorkNo().intValue() != param.getWrkNo()) { return R.error("工作号不一致"); } if (!staProtocol.isLoading()) { return R.error("站点无物"); } staProtocol.setWorkNo(param.getWrkNo().shortValue()); staProtocol.setStaNo(param.getStaNo().shortValue()); staProtocol.setPalletSize((short) 1); boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol)); log.info("发生成功:{}",result); return R.ok().add(result); } // 反馈任务执行结果 @PostMapping("/api/robot/reporter/task") public RcsReturn reporterTask(@RequestBody RcsReporterTask param){ 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 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(); } } @GetMapping("/api/robot/reporter/task1") public void reporterTask1(){ Integer sourceStaNo = 307; SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone(); boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(3, staProtocol)); // log.info("AGV放货完成,给站点写9991工作号,下发任务:{},站点:{},agv任务号:{}", result, task.getStaNo(), task.getTaskNo()); } }