src/main/java/com/zy/asrs/controller/OpenController.java
@@ -2,6 +2,9 @@ import com.core.common.R; 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.core.cache.MessageQueue; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.SlaveType; @@ -9,6 +12,8 @@ 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.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; @@ -16,6 +21,8 @@ @Slf4j @RestController public class OpenController { @Autowired private RcsService rcsService; @RequestMapping("/open/toOutSta") public R toOutSta(@RequestBody ToOutStaParam param) { @@ -47,4 +54,11 @@ return R.ok().add(result); } // 反馈任务执行结果 @PostMapping("/api/robot/reporter/task") public RcsReturn reporterTask(@RequestBody RcsReporterTask param){ return rcsService.reporterTask(param); } } src/main/java/com/zy/asrs/entity/AgvTask.java
New file @@ -0,0 +1,486 @@ package com.zy.asrs.entity; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.core.common.SpringUtils; import com.zy.asrs.service.BasCrnpService; import com.zy.asrs.service.LocMastService; import com.zy.system.entity.User; import com.zy.system.service.UserService; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Date; @Data @TableName("agv_task") @Accessors(chain = true) public class AgvTask implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty(value= "") @TableId(value = "id", type = IdType.AUTO) private Long id; /** * 任务类型: agv , crn */ @ApiModelProperty(value= "任务类型: agv , crn") @TableField("task_type") private String taskType; /** * 工作号 */ @ApiModelProperty(value= "工作号") @TableField("wrk_no") private Integer wrkNo; @ApiModelProperty(value= "下发AGV任务计数") @TableField("ctn_type") private Integer ctnType=0; @ApiModelProperty(value= "") @TableField("inv_wh") private String invWh; @ApiModelProperty(value= "") private Date ymd; @ApiModelProperty(value= "") private String mk; @ApiModelProperty(value= "") @TableField("whs_type") private Integer whsType; /** * 工作状态 */ @ApiModelProperty(value= "工作状态") @TableField("wrk_sts") private Long wrkSts; /** * 入出库类型 * 3.站到站 * 4.站到区域 * 5.区域到站 */ @ApiModelProperty(value= "入出库类型") @TableField("io_type") private Integer ioType; /** * 堆垛机 */ @ApiModelProperty(value= "堆垛机") @TableField("crn_no") private Integer crnNo; @ApiModelProperty(value= "") @TableField("sheet_no") private String sheetNo; /** * 优先级 */ @ApiModelProperty(value= "优先级") @TableField("io_pri") private Double ioPri; @ApiModelProperty(value= "") @TableField("wrk_date") private Date wrkDate; /** * 目标库位 */ @ApiModelProperty(value= "目标库位") @TableField("loc_no") private String locNo; /** * 目标站 */ @ApiModelProperty(value= "目标站") @TableField("sta_no") private String staNo; /** * 源站 */ @ApiModelProperty(value= "源站") @TableField("source_sta_no") private String sourceStaNo; /** * 源库位 */ @ApiModelProperty(value= "源库位") @TableField("source_loc_no") private String sourceLocNo; @ApiModelProperty(value= "") @TableField("loc_sts") private String locSts; @ApiModelProperty(value= "1.海康AGV 2.华晓AGV 默认是1.海康") @TableField("plt_type") private Integer pltType=1; @ApiModelProperty(value= "料架号") private String packed; /** * 拣料 */ @ApiModelProperty(value= "拣料") private String picking; @ApiModelProperty(value= "") @TableField("link_mis") private String linkMis; @ApiModelProperty(value= "") @TableField("online_yn") private String onlineYn; @ApiModelProperty(value= "是否任务报错") @TableField("upd_mk") private String updMk; /** * 退出 */ @ApiModelProperty(value= "退出") @TableField("exit_mk") private String exitMk; /** * 空板 */ @ApiModelProperty(value= "空板") @TableField("empty_mk") private String emptyMk; /** * 工作时间 */ @ApiModelProperty(value= "工作时间") @TableField("io_time") private Date ioTime; @ApiModelProperty(value= "") @TableField("ove_mk") private String oveMk; @ApiModelProperty(value= "") @TableField("mtn_type") private Double mtnType; @ApiModelProperty(value= "") @TableField("user_no") private String userNo; /** * 堆垛机启动时间 */ @ApiModelProperty(value= "堆垛机启动时间") @TableField("crn_str_time") private Date crnStrTime; /** * 堆垛机停止时间 */ @ApiModelProperty(value= "堆垛机停止时间") @TableField("crn_end_time") private Date crnEndTime; @ApiModelProperty(value= "") @TableField("plc_str_time") private Date plcStrTime; @ApiModelProperty(value= "") @TableField("crn_pos_time") private Date crnPosTime; @ApiModelProperty(value= "") @TableField("load_time") private Double loadTime; @ApiModelProperty(value= "") @TableField("exp_time") private Double expTime; @ApiModelProperty(value= "") @TableField("ref_wrkno") private Double refWrkno; /** * 拣料时间 */ @ApiModelProperty(value= "拣料时间") @TableField("ref_iotime") private Date refIotime; /** * 修改人员 */ @ApiModelProperty(value= "修改人员") @TableField("modi_user") private Long modiUser; /** * 修改时间 */ @ApiModelProperty(value= "修改时间") @TableField("modi_time") private Date modiTime; /** * 创建者 */ @ApiModelProperty(value= "创建者") @TableField("appe_user") private Long appeUser; /** * 添加时间 */ @ApiModelProperty(value= "添加时间") @TableField("appe_time") private Date appeTime; @ApiModelProperty(value= "") @TableField("pause_mk") private String pauseMk; @ApiModelProperty(value= "") @TableField("error_time") private Date errorTime; @ApiModelProperty(value= "") @TableField("error_memo") private String errorMemo; @ApiModelProperty(value= "") @TableField("ctn_kind") private Integer ctnKind; @ApiModelProperty(value= "") @TableField("manu_type") private String manuType; /** * 备注 */ @ApiModelProperty(value= "备注") private String memo; @ApiModelProperty(value= "") @TableField("sc_weight") private Double scWeight; @ApiModelProperty(value= "") @TableField("log_mk") private String logMk; @ApiModelProperty(value= "") @TableField("log_err_time") private Date logErrTime; @ApiModelProperty(value= "") @TableField("log_err_memo") private String logErrMemo; /** * 条码 */ @ApiModelProperty(value= "条码") private String barcode; // Y:销售订单出库任务 @ApiModelProperty(value= "") @TableField("Pdc_type") private String PdcType; @ApiModelProperty(value= "") @TableField("ctn_no") private String ctnNo; /** * 满板 */ @ApiModelProperty(value= "满板") @TableField("full_plt") private String fullPlt; /** * 先入品 / 双重入库 */ @ApiModelProperty(value= "先入品") @TableField("pre_have") private String preHave; /** * 空操作 / 取货无箱 */ @ApiModelProperty(value= "空操作") @TableField("take_none") private String takeNone; /** * 外部任务编号 */ @ApiModelProperty(value= "外部任务编号") @TableField("task_no") private String taskNo; public String getYmd$(){ if (Cools.isEmpty(this.ymd)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.ymd); } public String getCrnNo$(){ BasCrnpService service = SpringUtils.getBean(BasCrnpService.class); BasCrnp basCrnp = service.selectById(this.crnNo); if (!Cools.isEmpty(basCrnp)){ return String.valueOf(basCrnp.getCrnNo()); } return null; } public String getWrkDate$(){ if (Cools.isEmpty(this.wrkDate)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.wrkDate); } public String getLocNo$(){ LocMastService service = SpringUtils.getBean(LocMastService.class); LocMast locMast = service.selectById(this.locNo); if (!Cools.isEmpty(locMast)){ return String.valueOf(locMast.getLocNo()); } return null; } public String getTaskType$(){ if (Cools.isEmpty(this.taskType)){return null;} if (taskType.equals("AGV")) { return "AGV任务"; } else { return "堆垛机任务"; } } public String getSourceLocNo$(){ LocMastService service = SpringUtils.getBean(LocMastService.class); LocMast locMast = service.selectById(this.sourceLocNo); if (!Cools.isEmpty(locMast)){ return String.valueOf(locMast.getLocNo()); } return null; } public String getIoTime$(){ if (Cools.isEmpty(this.ioTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.ioTime); } public String getCrnStrTime$(){ if (Cools.isEmpty(this.crnStrTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.crnStrTime); } public String getCrnEndTime$(){ if (Cools.isEmpty(this.crnEndTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.crnEndTime); } public String getPlcStrTime$(){ if (Cools.isEmpty(this.plcStrTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.plcStrTime); } public String getCrnPosTime$(){ if (Cools.isEmpty(this.crnPosTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.crnPosTime); } public String getRefIotime$(){ if (Cools.isEmpty(this.refIotime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.refIotime); } public String getModiUser$(){ UserService service = SpringUtils.getBean(UserService.class); User user = service.selectById(this.modiUser); if (!Cools.isEmpty(user)){ return String.valueOf(user.getUsername()); } return null; } public String getModiTime$(){ if (Cools.isEmpty(this.modiTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.modiTime); } public String getAppeUser$(){ UserService service = SpringUtils.getBean(UserService.class); User user = service.selectById(this.appeUser); if (!Cools.isEmpty(user)){ return String.valueOf(user.getUsername()); } return null; } public String getAppeTime$(){ if (Cools.isEmpty(this.appeTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.appeTime); } public String getErrorTime$(){ if (Cools.isEmpty(this.errorTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.errorTime); } public String getLogErrTime$(){ if (Cools.isEmpty(this.logErrTime)){ return ""; } return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.logErrTime); } } src/main/java/com/zy/asrs/entity/RcsReporterTask.java
New file @@ -0,0 +1,21 @@ package com.zy.asrs.entity; import com.alibaba.fastjson.JSONObject; import lombok.Data; // 任务执行反馈 @Data public class RcsReporterTask { // 任务号 private String robotTaskCode; // 当前执行任务的机器人唯一标识。 private String singleRobotCode; // 目标路径序列,0 起点序号,1 终点序号。 private Integer currentSeq; // 详细信息 private JSONObject extra; //华晓AGV任务状态及请求 private String method; } src/main/java/com/zy/asrs/entity/RcsReturn.java
New file @@ -0,0 +1,20 @@ package com.zy.asrs.entity; import com.alibaba.fastjson.JSONObject; import lombok.Data; // 海康返回 @Data public class RcsReturn { // SUCCESS 成功 // Err_TaskTypeNotSupport 任务类型不支持 // Err_RobotGroupsNotMatch 机器人资源组编号与任务不匹配,无法调度 // Err_RobotCodeNotMatch 机器人编号与任务不匹配,无法调度 // Err_TargetRouteError 任务路径参数有误 private String code; private String message; private JSONObject data; } src/main/java/com/zy/asrs/entity/RcsTaskContinue.java
New file @@ -0,0 +1,20 @@ package com.zy.asrs.entity; import lombok.Data; // 继续执行任务 @Data public class RcsTaskContinue { // 任务链编号 private String robotTaskCode; // 触发类型: //SITE 站点编号触发 //CARRIER 载具编号触发 //ROBOT 车号触发 //TASK 任务链编号触发 private String triggerType; // 与 triggerType 对应的触发编号 private String triggerCode; } src/main/java/com/zy/asrs/entity/TransInOutStationAllow.java
New file @@ -0,0 +1,29 @@ package com.zy.asrs.entity; import lombok.Data; import lombok.EqualsAndHashCode; // 入站允许、离站允许 @EqualsAndHashCode(callSuper = true) @Data public class TransInOutStationAllow extends TransParent { //任务编号 private String taskno; //任务名称 private String taskname; //AGV编号 private String AgvCode; //运输类型 private String TransType; //生产线编号 private String ProductLineId; //工位编号 private String StationId; //任务类型 private String taskType; // 是否允许,Y 允许;N,不允许 private String status; } src/main/java/com/zy/asrs/entity/TransParent.java
New file @@ -0,0 +1,39 @@ package com.zy.asrs.entity; import com.alibaba.fastjson.annotation.JSONField; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; // 出入站请求继承父类:入站请求、入站允许、离站请求、离站允许、离站完成 @Data public class TransParent { // 任务编号,wcs_task_header表中的task_no private String taskno; // 任务名称,wcs_task_header表中的task_name private String taskname; // AGV编码 @JsonProperty("AgvCode") @JSONField(name = "AgvCode") private String AgvCode; // 运输类型 @JsonProperty("TransType") @JSONField(name = "TransType") private String TransType; // 生产线编码 @JsonProperty("ProductLineId") @JSONField(name = "ProductLineId") private String ProductLineId; // 工位编码 @JsonProperty("StationId") @JSONField(name = "StationId") private String StationId; // 任务类型 @JsonProperty("TaskType") @JSONField(name = "TaskType") private String TaskType; //请求类型 private String method; } src/main/java/com/zy/asrs/entity/WrkMast.java
@@ -25,6 +25,10 @@ private static final long serialVersionUID = 1L; @ApiModelProperty(value= "") @TableId(value = "id", type = IdType.AUTO) private Long id; /** * 工作号 */ src/main/java/com/zy/asrs/enums/RcsRetMethodEnum.java
New file @@ -0,0 +1,45 @@ package com.zy.asrs.enums; public enum RcsRetMethodEnum { TASK_START("start", "任务开始"), TASK_OUT_BIN("outbin", "走出储位"), APPLY_IN_STATION("applyInStation", "入站请求"), APPLY_OFF_STATION("applyOutStation", "离站请求"), ARRIVE_ON_STATION("arriveOnStation", "到站完成"), ARRIVE_OFF_STATION("arriveOffStation", "离站完成"), APPLY_PUT("applyPut", "放货申请"), TASK_END("end", "任务完成"), APPLY_PICK("applyPick", "取货申请"), PICK_COMPLETE("pickComplete", "rcs取货完成,已退出输送线"); private String code; private String message; RcsRetMethodEnum(String code, String message) { this.code = code; this.message = message; } public static RcsRetMethodEnum getEnum(String code) { for (RcsRetMethodEnum method : RcsRetMethodEnum.values()) { if (method.getCode().equals(code)) { return method; } } return null; } public String getCode() { return code; } public String getMessage() { return message; } } src/main/java/com/zy/asrs/mapper/TaskMapper.java
New file @@ -0,0 +1,10 @@ package com.zy.asrs.mapper; import com.baomidou.mybatisplus.mapper.BaseMapper; import com.zy.asrs.entity.AgvTask; import org.apache.ibatis.annotations.Mapper; @Mapper public interface TaskMapper extends BaseMapper<AgvTask> { } src/main/java/com/zy/asrs/service/RcsService.java
New file @@ -0,0 +1,15 @@ package com.zy.asrs.service; import com.zy.asrs.entity.RcsReporterTask; import com.zy.asrs.entity.RcsReturn; public interface RcsService { /** * 2.2.1任务执行回馈 * * @param rcsReporterTask * @return */ RcsReturn reporterTask(RcsReporterTask rcsReporterTask); } src/main/java/com/zy/asrs/service/TaskService.java
New file @@ -0,0 +1,9 @@ package com.zy.asrs.service; import com.baomidou.mybatisplus.service.IService; import com.zy.asrs.entity.AgvTask; import org.springframework.stereotype.Service; @Service public interface TaskService extends IService<AgvTask> { } src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2436,6 +2436,7 @@ int workNo = commonService.getWorkNo(0); // 保存工作档 WrkMast wrkMast = new WrkMast(); wrkMast.setId(); wrkMast.setWrkNo(workNo); wrkMast.setIoTime(new Date()); wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID src/main/java/com/zy/asrs/service/impl/RcsServiceImpl.java
New file @@ -0,0 +1,318 @@ package com.zy.asrs.service.impl; import com.alibaba.excel.util.StringUtils; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.core.common.R; import com.zy.asrs.entity.*; import com.zy.asrs.enums.RcsRetMethodEnum; import com.zy.asrs.service.RcsService; import com.zy.asrs.service.TaskService; 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.stereotype.Service; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ConnectException; import java.net.SocketTimeoutException; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @Slf4j @Service public class RcsServiceImpl implements RcsService { // 海康RCS地址 @Value("${hik.url}") private String HIK_URL; @Autowired private TaskService taskService; /** * 2.2.1任务执行回馈 * 厂家:海量、华晓 * * @param rcsReporterTask * @return */ @Override public RcsReturn reporterTask(RcsReporterTask rcsReporterTask) { RcsReturn rcsReturn = new RcsReturn(); String robotTaskCode = rcsReporterTask.getRobotTaskCode(); String singleRobotCode = rcsReporterTask.getSingleRobotCode(); String[] split = robotTaskCode.split("-"); robotTaskCode = split[0]; JSONObject values = rcsReporterTask.getExtra().getJSONObject("values"); // start : 任务开始;outbin : 走出储位;end : 任务完成 String method = values.getString("method"); String carrierType = values.getString("carrierType"); String slotCategory = values.getString("slotCategory"); String slotCode = values.getString("slotCode"); EntityWrapper<AgvTask> wrapper = new EntityWrapper<>(); wrapper.eq("task_no", robotTaskCode); AgvTask task = taskService.selectOne(wrapper); if(!Cools.isEmpty(task)){ try { // q3,q8=1 if ("1".equals(carrierType)) { //AGV switch (Objects.requireNonNull(RcsRetMethodEnum.getEnum(method))) { //放货申请 case APPLY_PUT: { Integer sourceStaNo = Integer.valueOf(task.getStaNo()); SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone(); //wcs反馈rcs继续执行 if (staProtocol != null && !staProtocol.isLoading() && !staProtocol.isEmptyOutType()) { RcsTaskContinue rcsTaskContinue = new RcsTaskContinue(); rcsTaskContinue.setRobotTaskCode(task.getTaskNo()); rcsTaskContinue.setTriggerType("TASK"); rcsTaskContinue.setTriggerCode(task.getTaskNo()); String url =HIK_URL + "api/robot/controller/task/extend/continue"; String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue)); if (!StringUtils.isEmpty(response) && response.contains("code")){ RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class); if("200".equals(rcsReturn1.getCode())) { //出发PLC站点的扫码器扫码 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()); if (result) { // 返回RCS rcsReturn.setCode("SUCCESS"); rcsReturn.setMessage(""); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); }else { // 返回RCS rcsReturn.setCode("Err_Internal"); rcsReturn.setMessage(""); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); } } } } } break; //放货完成 --》agv已经离开 case TASK_END: { Integer sourceStaNo = Integer.valueOf(task.getStaNo()); SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone(); //放货完成 --》agv已经离开 --》给PLC站点写9991工作号 if (staProtocol != null && staProtocol.isLoading() && staProtocol.isEmptyOutType() && staProtocol.getWorkNo() ==0) { staProtocol.setWorkNo((short) 9991); staProtocol.setStaNo(Short.valueOf(task.getStaNo())); boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(2, staProtocol)); log.info("AGV放货完成,给站点写9991工作号,下发任务:{},站点:{},agv任务号:{}",result,task.getStaNo(),task.getTaskNo()); if(result){ // 更新任务状态等内部逻辑 task.setWrkSts(304L); // 301 任务下发、302 任务执行、303 任务中断、304 任务结束 task.setModiTime(new Date()); taskService.updateById(task); // 返回RCS rcsReturn.setCode("SUCCESS"); rcsReturn.setMessage(""); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); }else { // 返回RCS rcsReturn.setCode("Err_Internal"); rcsReturn.setMessage(""); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); } } } break; //rcs请求wms取货申请 case APPLY_PICK: { Integer sourceStaNo = Integer.valueOf(task.getSourceStaNo()); SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone(); //判断站点是否有料架和托盘 if (staProtocol != null && staProtocol.isLoading() && staProtocol.isEmptyOutType() && staProtocol.getWorkNo() >0 && staProtocol.getWorkNo() <9990) { RcsTaskContinue rcsTaskContinue = new RcsTaskContinue(); rcsTaskContinue.setRobotTaskCode(task.getTaskNo()); rcsTaskContinue.setTriggerType("TASK"); rcsTaskContinue.setTriggerCode(task.getTaskNo()); String url =HIK_URL + "api/robot/controller/task/extend/continue"; String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue)); if (!StringUtils.isEmpty(response) && response.contains("code")){ RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class); if("200".equals(rcsReturn1.getCode())) { // 返回RCS rcsReturn.setCode("SUCCESS"); rcsReturn.setMessage(""); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); }else { // 返回RCS rcsReturn.setCode("Err_Internal"); rcsReturn.setMessage(""); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); } } } } break; //rcs取货完成,已退出输送线 case PICK_COMPLETE: { Integer sourceStaNo = Integer.valueOf(task.getSourceStaNo()); SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone(); //放货完成 --》agv已经离开 --》给PLC站点写9991工作号 if (staProtocol != null && !staProtocol.isLoading() && !staProtocol.isEmptyOutType() && staProtocol.getWorkNo() >0 && staProtocol.getWorkNo() <9990) { staProtocol.setWorkNo((short) 0); staProtocol.setStaNo((short) 0); boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(2, staProtocol)); log.info("AGV取货完成,给站点写0工作号,下发任务:{},站点:{},agv任务号:{}",result,task.getStaNo(),task.getTaskNo()); if(result){ // 返回RCS rcsReturn.setCode("SUCCESS"); rcsReturn.setMessage(""); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); }else { // 返回RCS rcsReturn.setCode("Err_Internal"); rcsReturn.setMessage(""); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); } } } break; default: { } break; } } } catch (Exception e) { log.error("RCS反馈任务进度处理异常 - {}", rcsReporterTask, e); rcsReturn.setCode("Err_Internal"); rcsReturn.setMessage("内部处理异常"); JSONObject data = new JSONObject(); data.put("robotTaskCode", robotTaskCode); rcsReturn.setData(data); } } return rcsReturn; } /** * 向指定 URL 发送POST方法的请求 * * @param url 发送请求的 URL * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 * @return 所代表远程资源的响应结果 */ public static String sendPost(String url, String param) { PrintWriter out = null; BufferedReader in = null; StringBuilder result = new StringBuilder(); try { log.info("sendPost - {} - {}", url, param); URL realUrl = new URL(url); URLConnection conn = realUrl.openConnection(); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Length", "<calculated when request is sent>"); conn.setRequestProperty("Host", "<calculated when request is sent>"); conn.setRequestProperty("Accept", "*/*"); conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br"); conn.setRequestProperty("Connection", "keep-alive"); conn.setRequestProperty("X-lr-request-id", String.valueOf(new Date().getTime())); conn.setRequestProperty("X-lr-version", "4.3"); conn.setConnectTimeout(5000); conn.setReadTimeout(5000); conn.setDoOutput(true); conn.setDoInput(true); out = new PrintWriter(conn.getOutputStream()); out.print(param); out.flush(); in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); String line; while ((line = in.readLine()) != null) { result.append(line); } log.info("recv - {}", result); } catch (ConnectException e) { log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e); } catch (SocketTimeoutException e) { log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e); } catch (IOException e) { log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e); } catch (Exception e) { log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e); } finally { try { if (out != null) { out.close(); } if (in != null) { in.close(); } } catch (IOException ex) { log.error("调用in.close Exception, url=" + url + ",param=" + param, ex); } } return result.toString(); } } src/main/java/com/zy/asrs/service/impl/TaskServiceImpl.java
New file @@ -0,0 +1,23 @@ package com.zy.asrs.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.core.common.Cools; import com.core.common.DateUtils; import com.core.exception.CoolException; import com.zy.asrs.entity.AgvTask; import com.zy.asrs.entity.WaitPakin; import com.zy.asrs.mapper.TaskMapper; import com.zy.asrs.service.TaskService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; @Service public class TaskServiceImpl extends ServiceImpl<TaskMapper, AgvTask> implements TaskService { } src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -131,6 +131,9 @@ case 2: write((StaProtocol)task.getData()); break; case 3: write1((StaProtocol)task.getData()); break; default: break; } @@ -340,6 +343,29 @@ } } /** * 扫码器触发 */ private void write1(StaProtocol staProtocol) throws InterruptedException { if (null == staProtocol) { return; } ArrayList<Integer> staNos = getStaNo(); int index = staNos.indexOf(staProtocol.getSiteId()); if(staProtocol.getSiteId() == 307){ index = 0; } OperateResult writeResult1 = siemensS7Net.Write("DB100.500" + index, 1); // 扫码器触发 if (!writeResult1.IsSuccess) { OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); } else { OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); log.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}", slave.getId(), JSON.toJSON(staProtocol)); } } // 更新入出库模式 private void updateIoMode() throws InterruptedException { if (this.ioModeOf2F != IoModeType.NONE) { src/main/resources/application.yml
@@ -36,6 +36,11 @@ wms: url: 127.0.0.1:8083/ljqwms #海康对接 hik: switch: false url: http://172.26.11.98:80/rcs/rtas/ zyHikUrl: 10.10.10.200:9091/hik # 下位机配置 @@ -43,13 +48,13 @@ # 双深 doubleDeep: true # 双深库位排号 doubleLocs: 3 doubleLocs: 1 # 左深库位排号 # doubleLocsLeft: 4,7,11,15,19,23 # 右深库位排号 doubleLocsRight: 1 # 左浅库位排号 shallowLocsLeft: 1 shallowLocsLeft: 2 # 右浅库位排号 shallowLocsRight: 2 # 一个堆垛机负责的货架排数 src/main/resources/mapper/TaskMapper.xml
New file @@ -0,0 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.zy.asrs.mapper.TaskMapper"> <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.zy.asrs.entity.AgvTask"> <id column="id" property="id" /> <result column="task_type" property="taskType" /> </resultMap> </mapper>