| | |
| | | import com.vincent.rsf.server.manager.service.impl.DeviceSiteServiceImpl; |
| | | import com.vincent.rsf.server.manager.service.impl.MatnrServiceImpl; |
| | | import com.vincent.rsf.server.manager.utils.LocManageUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class AgvServiceImpl implements AgvService { |
| | | |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R AGVBindAndInTaskStart(WaitPakinParam waitPakinPda, Long loginUserId) { |
| | | //先绑定 |
| | | getAGVStaBind(waitPakinPda); |
| | | try{ |
| | | getAGVStaBind(waitPakinPda); |
| | | } catch (CoolException e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | //生成任务 |
| | | AGVInTaskStart(waitPakinPda, loginUserId); |
| | | return R.ok(); |
| | |
| | | if (Cools.isEmpty(param.getPalletBarcode())) { |
| | | throw new CoolException("托盘码不能为空!!"); |
| | | } |
| | | if (Cools.isEmpty(param.getPalletSta())) { |
| | | throw new CoolException("操作站点不能为空!!"); |
| | | } |
| | | |
| | | checkPalletBarcodeAvailable(param.getPalletBarcode()); |
| | | |
| | |
| | | .setAnfme(1.0) |
| | | .setOrderItems(Collections.singletonList(buildOrderItem(param, matnr, nowMillis, nowSeconds).setBarcode(param.getPalletBarcode()))); |
| | | syncOrder.setStationId(param.getPalletSta()); |
| | | receiveMsgService.syncCheckOrder(Collections.singletonList(syncOrder), loginUserId); |
| | | |
| | | R r = receiveMsgService.syncCheckOrder(Collections.singletonList(syncOrder), loginUserId); |
| | | if (!Objects.isNull(r) && Objects.equals(String.valueOf(r.get("code")), "200")) { |
| | | autoCallAgvInTask(param, loginUserId); |
| | | } |
| | | return R.ok(Cools.add("orderNo", orderNo).add("palletBarcode", param.getPalletBarcode())); |
| | | } |
| | | |
| | | private void autoCallAgvInTask(AgvBindAndInTParam param, Long loginUserId) { |
| | | CompletableFuture.runAsync(() -> { |
| | | int retry = 0; |
| | | while (retry < 5) { |
| | | retry++; |
| | | try { |
| | | Thread.sleep(3000); |
| | | WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>() |
| | | .eq(WaitPakin::getBarcode, param.getPalletBarcode()) |
| | | .eq(WaitPakin::getIoStatus, PakinIOStatus.PAKIN_IO_STATUS_DONE.val) |
| | | .last("limit 1")); |
| | | if (Objects.isNull(waitPakin)) { |
| | | continue; |
| | | } |
| | | |
| | | BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>() |
| | | .eq(BasStation::getStationName, param.getPalletSta()) |
| | | .last("limit 1")); |
| | | if (Objects.isNull(basStation)) { |
| | | return; |
| | | } |
| | | // if (Objects.isNull(basStation) || Objects.isNull(basStation.getArea())) { |
| | | // return; |
| | | // } |
| | | |
| | | WaitPakinParam waitPakinPda = new WaitPakinParam() |
| | | .setBarcode(param.getPalletBarcode()) |
| | | .setStaNo(param.getPalletSta()) |
| | | .setArea(param.getArea()); |
| | | AGVBindAndInTaskStart(waitPakinPda, loginUserId); |
| | | return; |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private SyncOrdersItem buildOrderItem(AgvBindAndInTParam param, Matnr matnr, long uniqueSeed, long nowSeconds) { |
| | | String suffix = String.valueOf(uniqueSeed); |
| | | String batch = LocalDateTime.ofInstant(Instant.ofEpochSecond(nowSeconds), ZoneId.systemDefault()) |