| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.Cools; |
| | | import com.zy.asrs.entity.Task; |
| | | import com.zy.asrs.entity.TaskLog; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.LocCache; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.mapper.BasDevpMapper; |
| | | import com.zy.asrs.mapper.BasStationMapper; |
| | | import com.zy.asrs.mapper.WrkMastMapper; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import com.zy.asrs.service.LocCacheService; |
| | | import com.zy.asrs.service.TaskLogService; |
| | | import com.zy.asrs.service.TaskService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.service.WrkMastLogService; |
| | | import com.zy.asrs.entity.WrkMastLog; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.constant.ApiInterfaceConstant; |
| | | import com.zy.common.properties.AgvProperties; |
| | | import com.zy.common.utils.AgvUtils; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private WrkMastLogService wrkMastLogService; |
| | | |
| | | @Resource |
| | | private LocMastService locMastService; |
| | | /** |
| | | * 站点轮询计数器,用于平均分配站点 |
| | | * Key: 站点组标识(如 "east" 或 "west"),Value: 当前轮询索引 |
| | |
| | | * @param taskList 任务列表(通常只包含一个任务) |
| | | * @return 是否成功处理了任务(成功呼叫AGV,状态从7变为8) |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean callAgv(List<Task> taskList) { |
| | | // 记录调用堆栈,确保只能从定时任务调用 |
| | | StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); |
| | |
| | | WrkMast wrkMast = null; |
| | | if (agvTask.getWrkNo() != null) { |
| | | wrkMast = wrkMastService.selectOne( |
| | | new EntityWrapper<WrkMast>().eq("wrk_no", agvTask.getWrkNo()) |
| | | new EntityWrapper<WrkMast>() |
| | | .eq("barcode", agvTask.getBarcode()) |
| | | ); |
| | | } |
| | | |
| | | // 检查历史档是否存在 |
| | | WrkMastLog wrkMastLog = null; |
| | | if (agvTask.getWrkNo() != null) { |
| | | wrkMastLog = wrkMastLogService.selectOne( |
| | | new EntityWrapper<WrkMastLog>().eq("wrk_no", agvTask.getWrkNo()) |
| | | if (agvTask.getBarcode() != null) { |
| | | Wrapper<WrkMastLog> wrkMastLogMapper = new EntityWrapper<WrkMastLog>() |
| | | .eq("barcode", agvTask.getBarcode()); |
| | | if (agvTask.getAppeTime() != null) { |
| | | // 计算AGV创建时间之后6小时的时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(agvTask.getAppeTime()); |
| | | calendar.add(Calendar.HOUR_OF_DAY, 6); // 加6小时 |
| | | Date endTime = calendar.getTime(); |
| | | // 查询条件:历史档创建时间 >= AGV订单创建时间 且 <= AGV创建时间之后6小时 |
| | | wrkMastLogMapper = wrkMastLogMapper.ge("appe_time", agvTask.getAppeTime()) |
| | | .le("appe_time", endTime).eq("barcode", agvTask.getBarcode()).orderBy("appe_time DESC"); |
| | | } |
| | | List<WrkMastLog> wrkMastLogList = wrkMastLogService.selectList( |
| | | wrkMastLogMapper |
| | | ); |
| | | } |
| | | // 如果通过wrk_no没找到,且有条码,则通过条码查询 |
| | | if (wrkMastLog == null && !Cools.isEmpty(agvTask.getBarcode())) { |
| | | List<WrkMastLog> logList = wrkMastLogService.selectList( |
| | | new EntityWrapper<WrkMastLog>().eq("barcode", agvTask.getBarcode()) |
| | | ); |
| | | if (!logList.isEmpty()) { |
| | | wrkMastLog = logList.get(0); |
| | | if(wrkMastLogList.size()==1){ |
| | | wrkMastLog=wrkMastLogList.get(0); |
| | | }else if(wrkMastLogList.size()>1){ |
| | | int locmastCount = locMastService.selectCount(new EntityWrapper<LocMast>().eq("loc_sts", "F").eq("barcode", agvTask.getBarcode())); |
| | | if(locmastCount>0){ |
| | | wrkMastLog=wrkMastLogList.get(0); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * 取消AGV任务(仙工M4接口) |
| | | * |
| | | * @param task 任务对象 |
| | | * @return 是否成功 |
| | | * @return 成功返回 null,失败返回错误原因 |
| | | */ |
| | | public boolean cancelAgvTask(Task task) { |
| | | public String cancelAgvTask(Task task) { |
| | | if (!agvProperties.isSendTask()) { |
| | | return false; |
| | | return "未启用AGV任务下发"; |
| | | } |
| | | |
| | | if (task == null || task.getId() == null) { |
| | | log.error("取消AGV任务失败:任务或任务ID为空"); |
| | | return false; |
| | | return "任务或任务ID为空"; |
| | | } |
| | | |
| | | String response = ""; |
| | |
| | | String displayTaskId = (task.getWrkNo() != null) ? String.valueOf(task.getWrkNo()) : String.valueOf(task.getId()); |
| | | log.info(namespace + "取消AGV任务成功:{}", displayTaskId); |
| | | } else { |
| | | String errMsg = jsonObject.getString("message"); |
| | | if (errMsg == null || errMsg.isEmpty()) { |
| | | errMsg = "response: " + response; |
| | | } |
| | | log.error(namespace + "取消AGV任务失败!!!url:{};request:{};response:{}", url, body, response); |
| | | return errMsg; |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(namespace + "取消AGV任务异常", e); |
| | | return e.getMessage() != null ? e.getMessage() : "取消AGV任务异常"; |
| | | } finally { |
| | | try { |
| | | // 保存接口日志 |
| | |
| | | } |
| | | } |
| | | |
| | | return success; |
| | | return success ? null : "取消AGV任务失败"; |
| | | } |
| | | } |