| | |
| | | import com.core.common.R; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.api.controller.params.HmesBackLocParams; |
| | | import com.zy.api.entity.dto.HmesDeviceFreezeStatusDto; |
| | | import com.zy.api.entity.dto.HmesStationFreezeStatusDto; |
| | | import com.zy.api.controller.params.ReceviceTaskParams; |
| | | import com.zy.api.service.HmesApiService; |
| | | import com.zy.api.service.WcsApiService; |
| | |
| | | @Service |
| | | @Slf4j |
| | | public class HmesApiServiceImpl implements HmesApiService { |
| | | |
| | | private static final Long HMES_USER_ID = 9995L; |
| | | |
| | | @Autowired |
| | | private BasDeviceService basDeviceService; |
| | |
| | | private OrderDetlPakoutServiceImpl orderDetlPakoutService; |
| | | @Autowired |
| | | private LocDetlServiceImpl locDetlService; |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | |
| | | @Autowired |
| | | private WorkService workService; |
| | | |
| | | |
| | | /** |
| | |
| | | }); |
| | | return R.ok(s+"成功 !!"); |
| | | } |
| | | |
| | | @Override |
| | | public R getDeviceFreezeStatus() { |
| | | List<BasDevice> devices = basDeviceService.selectList(new EntityWrapper<BasDevice>() |
| | | .eq("status", 1) |
| | | .orderBy("dev_no", true)); |
| | | if (Cools.isEmpty(devices)) { |
| | | return R.ok(Collections.emptyList()); |
| | | } |
| | | |
| | | List<LocAroundBind> binds = locAroundBindService.selectList(new EntityWrapper<LocAroundBind>() |
| | | .orderBy("dev_no", true) |
| | | .orderBy("order_no", true) |
| | | .orderBy("id", true)); |
| | | Map<String, List<LocAroundBind>> bindMap = new HashMap<>(); |
| | | if (!Cools.isEmpty(binds)) { |
| | | bindMap = binds.stream() |
| | | .filter(bind -> !Cools.isEmpty(bind.getDevNo())) |
| | | .collect(Collectors.groupingBy(LocAroundBind::getDevNo, LinkedHashMap::new, Collectors.toList())); |
| | | } |
| | | |
| | | List<HmesDeviceFreezeStatusDto> result = new ArrayList<>(); |
| | | for (BasDevice device : devices) { |
| | | List<LocAroundBind> deviceBinds = bindMap.getOrDefault(device.getType(), Collections.emptyList()); |
| | | List<HmesStationFreezeStatusDto> stationList = deviceBinds.stream() |
| | | .sorted(Comparator.comparing(LocAroundBind::getOrderNo, Comparator.nullsLast(Integer::compareTo)) |
| | | .thenComparing(LocAroundBind::getId, Comparator.nullsLast(Long::compareTo))) |
| | | .map(this::buildStationFreezeStatus) |
| | | .collect(Collectors.toList()); |
| | | boolean frozen = stationList.stream().anyMatch(station -> "Y".equals(station.getFreeze())); |
| | | result.add(new HmesDeviceFreezeStatusDto() |
| | | .setDevNo(device.getDevNo()) |
| | | .setDevType(device.getType()) |
| | | .setFreeze(toFreezeFlag(frozen ? 1 : 0)) |
| | | .setStationList(stationList)); |
| | | } |
| | | return R.ok(result); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R backLoc(HmesBackLocParams params) { |
| | | Integer backType = parseBackType(params.getBackType()); |
| | | if (backType == null) { |
| | | return R.error("回库类型[backType]仅支持 EMPTY/4/空桶/空板 或 SURPLUS/5/余料"); |
| | | } |
| | | |
| | | WrkMast mast = findBackLocWrkMast(params); |
| | | if (Objects.isNull(mast)) { |
| | | return R.error("未查询到可回库的任务档"); |
| | | } |
| | | if (!Objects.equals(mast.getWrkSts(), 15L)) { |
| | | return R.error("当前任务状态不能执行回库!"); |
| | | } |
| | | |
| | | workService.updateWrkIsSuplus(String.valueOf(mast.getWrkNo()), HMES_USER_ID, backType); |
| | | return workService.backLocOperation(String.valueOf(mast.getWrkNo()), HMES_USER_ID); |
| | | } |
| | | |
| | | private HmesStationFreezeStatusDto buildStationFreezeStatus(LocAroundBind bind) { |
| | | return new HmesStationFreezeStatusDto() |
| | | .setLocNo(bind.getBlocNo()) |
| | | .setOrderNo(bind.getOrderNo()) |
| | | .setLocType(bind.getLocType()) |
| | | .setFreeze(toFreezeFlag(bind.getFreeze())); |
| | | } |
| | | |
| | | private String toFreezeFlag(Integer freeze) { |
| | | return Objects.equals(freeze, 1) ? "Y" : "N"; |
| | | } |
| | | |
| | | private Integer parseBackType(String backType) { |
| | | if (Cools.isEmpty(backType)) { |
| | | return null; |
| | | } |
| | | String normalized = backType.trim().toUpperCase(Locale.ROOT); |
| | | if ("4".equals(normalized) || "EMPTY".equals(normalized) || "EMPTY_BUCKET".equals(normalized) |
| | | || "EMPTY_PLATE".equals(normalized) || "空桶".equals(backType.trim()) |
| | | || "空板".equals(backType.trim())) { |
| | | return 4; |
| | | } |
| | | if ("5".equals(normalized) || "SURPLUS".equals(normalized) || "SUPLUS".equals(normalized) |
| | | || "LEFTOVER".equals(normalized) || "余料".equals(backType.trim())) { |
| | | return 5; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private WrkMast findBackLocWrkMast(HmesBackLocParams params) { |
| | | if (!Cools.isEmpty(params.getLocNo())) { |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | .eq("loc_no", params.getLocNo()) |
| | | .orderBy("appe_time", false) |
| | | .orderBy("wrk_no", false)); |
| | | WrkMast matched = pickLatestCompletedWrkMast(wrkMasts); |
| | | if (matched != null) { |
| | | return matched; |
| | | } |
| | | } |
| | | if (!Cools.isEmpty(params.getWorkNo())) { |
| | | return wrkMastService.selectById(params.getWorkNo()); |
| | | } |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | .eq("barcode", params.getBarcode()) |
| | | .orderBy("appe_time", false) |
| | | .orderBy("wrk_no", false)); |
| | | return pickLatestCompletedWrkMast(wrkMasts); |
| | | } |
| | | |
| | | private WrkMast pickLatestCompletedWrkMast(List<WrkMast> wrkMasts) { |
| | | if (Cools.isEmpty(wrkMasts)) { |
| | | return null; |
| | | } |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | if (Objects.equals(wrkMast.getWrkSts(), 15L)) { |
| | | return wrkMast; |
| | | } |
| | | } |
| | | return wrkMasts.get(0); |
| | | } |
| | | } |