|  |  | 
 |  |  | import com.zy.asrs.framework.common.Cools; | 
 |  |  | import com.zy.asrs.framework.exception.CoolException; | 
 |  |  | import com.zy.asrs.wcs.asrs.entity.param.FlowLogicCodeParam; | 
 |  |  | import com.zy.asrs.wcs.core.domain.dto.MotionDto; | 
 |  |  | import com.zy.asrs.wcs.core.entity.Motion; | 
 |  |  | import com.zy.asrs.wcs.core.entity.Task; | 
 |  |  | import com.zy.asrs.wcs.core.kernel.KernelService; | 
 |  |  | import com.zy.asrs.wcs.core.service.TaskService; | 
 |  |  | import com.zy.asrs.wcs.core.utils.RedisUtil; | 
 |  |  | import com.zy.asrs.wcs.core.utils.ShuttleDispatcher; | 
 |  |  | 
 |  |  | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; | 
 |  |  | import com.zy.asrs.wcs.rcs.entity.Device; | 
 |  |  | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; | 
 |  |  | import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol; | 
 |  |  | import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; | 
 |  |  | import org.apache.commons.codec.digest.DigestUtils; | 
 |  |  | import org.apache.commons.codec.digest.Md5Crypt; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  |  | 
 |  |  | 
 |  |  |     private TaskService taskService; | 
 |  |  |     @Autowired | 
 |  |  |     private ShuttleDispatcher shuttleDispatcher; | 
 |  |  |     @Autowired | 
 |  |  |     private KernelService kernelService; | 
 |  |  |  | 
 |  |  |     //执行流程图 | 
 |  |  |     public boolean execute(List<JSONObject> list) { | 
 |  |  | 
 |  |  |         for (Task task : tasks) { | 
 |  |  |             String redisKey = DigestUtils.md5Hex(JSON.toJSONString(list)); | 
 |  |  |  | 
 |  |  |             redisSet(redisKey, "motionList", new ArrayList<Motion>()); | 
 |  |  |             while (currentId != null) { | 
 |  |  |                 //获取流程图 | 
 |  |  |                 JSONObject flow = findFLow(list, currentId); | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private boolean executeLiftFlow(Task task, JSONObject data, String redisKey) { | 
 |  |  |         Object object = redisGet(redisKey, "motionList"); | 
 |  |  |         List<Motion> motionList = JSON.parseArray(JSON.toJSONString(object), Motion.class); | 
 |  |  |  | 
 |  |  |         Object liftDeviceObj = redisGet(redisKey, "liftDevice"); | 
 |  |  |         if (liftDeviceObj == null) { | 
 |  |  |             throw new CoolException("提升机缓存为空"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Device device = JSON.parseObject(String.valueOf(liftDeviceObj), Device.class); | 
 |  |  |         if (device == null) { | 
 |  |  |             throw new CoolException("提升机设备不存在"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getId().intValue()); | 
 |  |  |         if (liftThread == null) { | 
 |  |  |             throw new CoolException("提升机不存在"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         LiftProtocol liftProtocol = liftThread.getStatus(); | 
 |  |  |         if (liftProtocol == null) { | 
 |  |  |             throw new CoolException("提升机不存在"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         JSONObject liftType = data.getJSONObject("liftType"); | 
 |  |  |         String oper = liftType.getString("liftOper"); | 
 |  |  |         if (oper.equals("move")) { | 
 |  |  |         String opera = liftType.getString("liftOper"); | 
 |  |  |         if (opera.equals("move")) { | 
 |  |  |             //提升机升降 | 
 |  |  |             String sourceLevStr = liftType.getString("sourceLev"); | 
 |  |  |             String targetLevStr = liftType.getString("targetLev"); | 
 |  |  |             Integer sourceLev = getLiftOperaLev(sourceLevStr, task, redisKey); | 
 |  |  |             Integer targetLev = getLiftOperaLev(targetLevStr, task, redisKey); | 
 |  |  |  | 
 |  |  |             motionList.addAll(kernelService.liftMove( | 
 |  |  |                     MotionDto.build((dto -> { | 
 |  |  |                         dto.setLiftNo(device.getId().intValue()); | 
 |  |  |                         dto.setLev(sourceLev); | 
 |  |  |                     })) | 
 |  |  |                     , MotionDto.build((dto -> { | 
 |  |  |                         dto.setLiftNo(device.getId().intValue()); | 
 |  |  |                         dto.setLev(targetLev); | 
 |  |  |                     })) | 
 |  |  |             )); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return true; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private Integer getLiftOperaLev(String opera, Task task, String redisKey) { | 
 |  |  |         if (opera.equals("sourceLev")) { | 
 |  |  |             return Utils.getLev(task.getOriginLoc()); | 
 |  |  |         } else if (opera.equals("targetLev")) { | 
 |  |  |             return Utils.getLev(task.getDestLoc()); | 
 |  |  |         } else if (opera.equals("shuttleLev")) { | 
 |  |  |             //取出缓存小车 | 
 |  |  |             Object shuttleDeviceObj = redisGet(redisKey, "shuttleDevice"); | 
 |  |  |             if (shuttleDeviceObj == null) { | 
 |  |  |                 throw new CoolException("穿梭车缓存为空"); | 
 |  |  |             } | 
 |  |  |             Device device = JSON.parseObject(String.valueOf(shuttleDeviceObj), Device.class); | 
 |  |  |             if (device == null) { | 
 |  |  |                 throw new CoolException("穿梭车设备不存在"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); | 
 |  |  |             if (shuttleThread == null) { | 
 |  |  |                 throw new CoolException("穿梭车不存在"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); | 
 |  |  |             if (shuttleProtocol == null) { | 
 |  |  |                 throw new CoolException("穿梭车不存在"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             return Utils.getLev(shuttleProtocol.getCurrentLocNo()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         throw new CoolException("类型异常"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private boolean redisSet(String redisKey, String key, Object data) { | 
 |  |  |         if (redisUtil.hasKey(redisKey)) { | 
 |  |  |             Object obj = redisUtil.get(redisKey); |