| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.zy.asrs.entity.BasShuttleOpt; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasShuttleOptService; |
| | | import com.zy.asrs.service.BasShuttleService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.ExecuteSupport; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.utils.NavigateMapUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.common.utils.ShuttleOperaUtils; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.dispatcher.ShuttleDispatchUtils; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.ShuttleAssignCommand; |
| | |
| | | import com.zy.core.model.command.ShuttleRedisCommand; |
| | | import com.zy.core.model.protocol.ShuttleProtocol; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private BasShuttleOptService basShuttleOptService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private ShuttleDispatchUtils shuttleDispatchUtils; |
| | | |
| | | public synchronized boolean assignWork(Integer shuttleNo, ShuttleAssignCommand assignCommand) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | |
| | | // 系统任务 |
| | | if (assignCommand.getAuto()) { |
| | | if (!assignCommand.getCharge()) { |
| | | //对主线程抛出等待确认状态waiting |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING); |
| | | if (command.getMode() == ShuttleCommandModeType.UPDATE_LOCATION.id) { |
| | | //更新坐标任务无需抛出等待确认 |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | shuttleThread.setSyncTaskNo(0); |
| | | }else { |
| | | //对主线程抛出等待确认状态waiting |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING); |
| | | } |
| | | }else { |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); |
| | | } |
| | |
| | | return true; |
| | | } |
| | | |
| | | //演示模式 |
| | | public synchronized void demo(Integer shuttleNo) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | | if (shuttleThread == null) { |
| | | return; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | return; |
| | | } |
| | | |
| | | if (!shuttleProtocol.getDemo()) { |
| | | return; |
| | | } |
| | | |
| | | WrkMast moveWorking = wrkMastService.selectShuttleHasMoveWorking(shuttleNo); |
| | | if (moveWorking != null) { |
| | | return; |
| | | } |
| | | |
| | | WrkMast shuttleWorking = wrkMastService.selectShuttleWorking(shuttleNo); |
| | | if(shuttleWorking != null) { |
| | | return; |
| | | } |
| | | |
| | | WrkMast chargeWorking = wrkMastService.selectChargeWorking(shuttleNo); |
| | | if (chargeWorking != null) { |
| | | return; |
| | | } |
| | | |
| | | if (shuttleThread.isRequireCharge()) { |
| | | return; |
| | | } |
| | | |
| | | if (!shuttleThread.isIdle()) { |
| | | return; |
| | | } |
| | | |
| | | boolean demoSwitchLev = false; |
| | | Config demoSwitchLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoSwitchLev")); |
| | | if (demoSwitchLevConfig != null) { |
| | | if (demoSwitchLevConfig.getValue().equals("Y")) { |
| | | demoSwitchLev = true; |
| | | } |
| | | } |
| | | |
| | | Config demoRunLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoRunLev")); |
| | | if (demoRunLevConfig == null) { |
| | | return; |
| | | } |
| | | List<Integer> levList = JSON.parseArray(demoRunLevConfig.getValue(), Integer.class); |
| | | |
| | | if (!demoSwitchLev) { |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | levList = new ArrayList<>(); |
| | | levList.add(Utils.getLev(currentLocNo)); |
| | | } |
| | | |
| | | LocMast targetLoc = null; |
| | | EntityWrapper<LocMast> wrapper = new EntityWrapper<>(); |
| | | wrapper.in("lev1", levList); |
| | | wrapper.eq("loc_sts", "O"); |
| | | wrapper.last("ORDER BY RAND() LIMIT 1"); |
| | | for (int i = 0; i < 3; i++) { |
| | | LocMast locMast = locMastService.selectOne(wrapper); |
| | | if(locMast == null) { |
| | | continue; |
| | | } |
| | | |
| | | ArrayList<String> locs = new ArrayList<>(); |
| | | locs.add(locMast.getLocNo()); |
| | | Integer shuttle = Utils.checkGroupLocHasShuttle(locs); |
| | | if(shuttle != null) { |
| | | continue; |
| | | } |
| | | |
| | | targetLoc = locMast; |
| | | break; |
| | | } |
| | | |
| | | if(targetLoc == null) { |
| | | return; |
| | | } |
| | | |
| | | shuttleDispatchUtils.dispatchShuttle(null, targetLoc.getLocNo(), shuttleNo); |
| | | } |
| | | |
| | | // //跑库程序 |
| | | // public synchronized void moveLoc(Integer shuttleNo) { |
| | | // ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |