#
Junjie
2024-03-27 7bc7f8455d60a4a59e5e23aceddf434b03b740ee
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/service/impl/MotionServiceImpl.java
@@ -1,12 +1,77 @@
package com.zy.asrs.wcs.rcs.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
import com.zy.asrs.wcs.core.model.enums.MotionStsType;
import com.zy.asrs.wcs.core.service.DeviceCtgService;
import com.zy.asrs.wcs.rcs.mapper.MotionMapper;
import com.zy.asrs.wcs.rcs.entity.Motion;
import com.zy.asrs.wcs.rcs.service.MotionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.asrs.wcs.rcs.service.MotionStsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service("motionService")
public class MotionServiceImpl extends ServiceImpl<MotionMapper, Motion> implements MotionService {
    @Autowired
    private DeviceCtgService deviceCtgService;
    @Autowired
    private MotionStsService motionStsService;
    @Override
    public List<Motion> selectUnCompleteByUuidAndDeviceCtg(String uuid, DeviceCtgType deviceCtgType) {
        return this.list(new LambdaQueryWrapper<Motion>()
                .eq(Motion::getUuid, uuid)
                .eq(Motion::getDeviceCtg, deviceCtgService.selectByFlag(deviceCtgType.toString()).getId())
                .lt(Motion::getMotionSts, motionStsService.selectByFlag(MotionStsType.COMPLETE.toString()).getId())
                .orderByDesc(Motion::getPriority)
        );
    }
    @Override
    public Motion selectOfTop1(String uuid, Long motionSts, Long hostId) {
        return this.baseMapper.selectOfTop1(uuid, motionSts, hostId);
    }
    @Override
    public Boolean hasRunningMotion(String uuid, Long hostId) {
        return null != this.selectOfTop1(uuid, MotionStsType.EXECUTING.val(), hostId)
                || null != this.selectOfTop1(uuid, MotionStsType.ERROR.val(), hostId);
    }
    @Override
    public List<Motion> selectBySts(Long motionSts) {
        return this.list(new LambdaQueryWrapper<Motion>()
                .eq(Motion::getMotionSts, motionSts)
                .orderByDesc(Motion::getPriority));
    }
    @Override
    public Boolean theNextBeWaiting(String uuid, Motion motion) {
        Motion next = null;
        if (null == motion) {
            next = this.baseMapper.selectOfTop1(uuid, MotionStsType.INIT.val(), motion.getHostId());
        } else {
            next = this.selectOfNext(uuid, motion);
        }
        if (null != next) {
            next.setMotionSts(MotionStsType.WAITING.val());
            next.setUpdateTime(new Date());
            if (!this.updateById(next)) {
                throw new CoolException(uuid + " - [" + (motion == null ? 0 : (motion.getPriority() - 1)) + "] 动作更新状态失败");
            }
        }
        return Boolean.TRUE;
    }
    @Override
    public Motion selectOfNext(String uuid, Motion motion) {
        return this.baseMapper.selectOfNext(uuid, motion.getPriority(), motion.getHostId());
    }
}