package com.zy.api.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.R; import com.core.exception.CoolException; import com.zy.api.controller.params.ReceviceTaskParams; import com.zy.api.service.HmesApiService; import com.zy.asrs.entity.BasDevice; import com.zy.asrs.entity.LocAroundBind; import com.zy.asrs.entity.LocMast; import com.zy.asrs.enums.LocStsType; import com.zy.asrs.service.BasDeviceService; import com.zy.asrs.service.LocAroundBindService; import com.zy.asrs.service.LocMastService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @Service public class HmesApiServiceImpl implements HmesApiService { @Autowired private BasDeviceService basDeviceService; @Autowired private LocAroundBindService locAroundBindService; @Autowired private LocMastService locMastService; /** * 接收MES穿线任务 * @author Ryan * @date 2026/1/10 10:54 * @param params * @return com.core.common.R */ @Override @Transactional(rollbackFor = Exception.class) public R pubWorkTask(ReceviceTaskParams params) { if (Objects.isNull(params) || Objects.isNull(params.getDeviceNo())) { return R.error("参数不能为空!!"); } BasDevice basDevice = basDeviceService.selectOne(new EntityWrapper() .eq("status", 1) .eq("dev_no", params.getDeviceNo())); if (Objects.isNull(basDevice)) { throw new CoolException("机台信息不存在或已禁用!!"); } List binds = locAroundBindService.selectList(new EntityWrapper().eq("dev_no", basDevice.getDevNo())); if (Objects.isNull(binds) || binds.isEmpty()) { throw new CoolException("机台未绑定工作站台!!"); } Set locs = binds.stream().map(LocAroundBind::getBLocNo).collect(Collectors.toSet()); LocMast locMasts = locMastService.selectOne(new EntityWrapper() .in("loc_no", locs) .eq("loc_sts", LocStsType.LOC_STS_TYPE_F.type) .orderAsc(Arrays.asList("loc_no")) .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")); if (Objects.isNull(locMasts)) { throw new CoolException("未查到可工作线轴!!"); } //todo 锁库位需WCS锁定(相关库位,不可执行任务操作,不能只在WMS锁定) List locMs = locMastService.selectList(new EntityWrapper() .in("loc_no", locs) .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)); locMs.forEach(loc -> { loc.setLocSts(LocStsType.LOC_STS_TYPE_X.type); if (!locMastService.updateById(loc)) { throw new CoolException("工作台周边库位禁用失败,不可执行穿线操作!!"); } }); return R.ok("可执行穿线动作!!"); } /** * 穿线完成,释放机台周边库位 * @author Ryan * @date 2026/1/10 11:07 * @param params * @return com.core.common.R */ @Override public R releaseLock(ReceviceTaskParams params) { if (Objects.isNull(params) || Objects.isNull(params.getDeviceNo())) { return R.error("参数不能为空!!"); } BasDevice basDevice = basDeviceService.selectOne(new EntityWrapper() .eq("status", 1) .eq("dev_no", params.getDeviceNo())); if (Objects.isNull(basDevice)) { throw new CoolException("机台信息不存在或已禁用!!"); } List binds = locAroundBindService.selectList(new EntityWrapper().eq("dev_no", basDevice.getDevNo())); if (Objects.isNull(binds) || binds.isEmpty()) { throw new CoolException("机台未绑定工作站台!!"); } Set locs = binds.stream().map(LocAroundBind::getBLocNo).collect(Collectors.toSet()); return null; } }