diff --git a/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutobindZxqBox.java b/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutobindZxqBox.java new file mode 100644 index 000000000..33c214000 --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutobindZxqBox.java @@ -0,0 +1,97 @@ +package org.nl.b_lms.sch.tasks.first_floor_area.auto; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.nl.b_lms.sch.point.dao.BstIvtPackageinfoivt; +import org.nl.b_lms.sch.point.dao.mapper.BstIvtPackageinfoivtMapper; +import org.nl.b_lms.storage_manage.ios.enums.IOSEnum; +import org.nl.common.enums.PackageInfoIvtEnum; +import org.nl.modules.common.utils.RedisUtils; +import org.redisson.api.RList; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + + +@Slf4j +@Component +@RequiredArgsConstructor +public class AutobindZxqBox extends Prun { + + private final String THIS_CLASS = AutobindZxqBox.class.getName(); + @Resource + private RedissonClient redissonClient; + + @Autowired + private RedisUtils redisUtils; + + @Resource + private BstIvtPackageinfoivtMapper bstIvtPackageinfoivtMapper; + + //待检区->装箱区agv自动搬运任务 + @Autowired + public void run() { + try { + this.bindZxqBox(); + } catch (Exception ex) { + log.error(ex.getMessage()); + } + + } + + + /** + * 二次分配任务 + */ + @SneakyThrows + public void bindZxqBox() { + log.info(THIS_CLASS + "-装箱对接位绑定木箱开始扫描。"); + RLock lock = redissonClient.getLock(THIS_CLASS); + boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); + try { + if (tryLock) { + //获取当前启用的装箱对接位 + //装箱区对接位 + List bstIvtPackageinfoivtList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper() + .eq(BstIvtPackageinfoivt::getPoint_status, PackageInfoIvtEnum.POINT_STATUS.code("装箱位")) + .eq(BstIvtPackageinfoivt::getIs_used, IOSEnum.IS_NOTANDYES.code("是")) + .eq(BstIvtPackageinfoivt::getPlan, IOSEnum.IS_NOTANDYES.code("是")) + .eq(BstIvtPackageinfoivt::getIvt_status, PackageInfoIvtEnum.IVT_STATUS.code("空")) + .orderByAsc(BstIvtPackageinfoivt::getPoint_code)); + bstIvtPackageinfoivtList.forEach(bstIvtPackage -> { + //判断当前装箱对接位的木箱队列是否有值,有值则取第一个进行赋值 + Object o = redisUtils.lGetIndex(bstIvtPackage.getPoint_code(), 0); + if (ObjectUtil.isNotEmpty(o)) { + String firstElement = o.toString(); + bstIvtPackage.setIvt_status(PackageInfoIvtEnum.IVT_STATUS.code("空载具")); + bstIvtPackage.setContainer_name(firstElement); + bstIvtPackage.setUpdate_time(DateUtil.now()); + bstIvtPackageinfoivtMapper.updateById(bstIvtPackage); + log.info(bstIvtPackage.getPoint_code() + "绑定了木箱" + firstElement); + redisUtils.lRemove(bstIvtPackage.getPoint_code(), 1, firstElement); + } else { + log.info("列表为空,无木箱可绑定。"); + } + + }); + } else { + log.info("满轴->待检区agv自动搬运任务正在创建被锁住。"); + } + } finally { + if (lock.isLocked() && lock.isHeldByCurrentThread()) { + lock.unlock(); + } + } + } + +}