| | |
| | | package com.zy.acs.manager.fake; |
| | | |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.domain.AgvProtocol; |
| | | import com.zy.acs.common.domain.protocol.AGV_11_UP; |
| | | import com.zy.acs.common.enums.AgvCompleteType; |
| | | import com.zy.acs.common.hk.state.HkState; |
| | | import com.zy.acs.common.hk.state.HkStateActionState; |
| | | import com.zy.acs.common.hk.state.HkStateAgvPosition; |
| | | import com.zy.acs.common.hk.state.HkStateBatteryState; |
| | | import com.zy.acs.common.hk.state.HkStateVelocity; |
| | | import com.zy.acs.common.hk.state.type.HkActionStatusType; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.manager.core.cache.CoreCache; |
| | | import com.zy.acs.manager.common.config.HikOrderProperties; |
| | | import com.zy.acs.manager.core.constant.HikAngleConstant; |
| | | import com.zy.acs.manager.core.domain.CodeStepDto; |
| | | import com.zy.acs.manager.core.domain.type.JobType; |
| | | import com.zy.acs.manager.core.scheduler.MapDataWsScheduler; |
| | |
| | | import com.zy.acs.manager.core.service.MapService; |
| | | import com.zy.acs.manager.manager.entity.Action; |
| | | import com.zy.acs.manager.manager.entity.Agv; |
| | | import com.zy.acs.manager.manager.entity.AgvDetail; |
| | | import com.zy.acs.manager.manager.entity.AgvModel; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.enums.ActionStsType; |
| | | import com.zy.acs.manager.manager.enums.ActionTypeType; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.time.Instant; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | |
| | | private final JamService jamService; |
| | | private final MainService mainService; |
| | | private final List<Action> actionList; |
| | | private final HikOrderProperties hikOrderProperties; |
| | | |
| | | private final RedisSupport redis; |
| | | |
| | |
| | | , MapService mapService |
| | | , JamService jamService |
| | | , MainService mainService |
| | | , HikOrderProperties hikOrderProperties |
| | | , List<Action> actionList |
| | | ) { |
| | | this.agv = agv; |
| | |
| | | this.mapService = mapService; |
| | | this.jamService = jamService; |
| | | this.mainService = mainService; |
| | | this.hikOrderProperties = hikOrderProperties; |
| | | this.actionList = actionList; |
| | | |
| | | this.groupId = actionList.get(0).getGroupId(); |
| | |
| | | } |
| | | |
| | | // 2.complete data |
| | | if (isHikAgv()) { |
| | | finishHikActionList(); |
| | | return; |
| | | } |
| | | |
| | | AGV_11_UP agv_11_up = new AGV_11_UP(); |
| | | agv_11_up.setSerialNo(groupId); |
| | | agv_11_up.setCompleteCode(AgvCompleteType.ENTIRE_PATH_COMPLETE.getCode()); |
| | |
| | | mainService.upDataSubscribe(agvProtocol); |
| | | // redis.push(RedisConstant.AGV_COMPLETE_FLAG, agvProtocol); |
| | | } |
| | | |
| | | private void finishHikActionList() { |
| | | HkState state = new HkState(); |
| | | state.setTimestamp(Instant.now().toString()); |
| | | state.setSerialNumber(agv.getUuid()); |
| | | state.setManufacturer(hikOrderProperties.getManufacturer()); |
| | | state.setVersion(hikOrderProperties.getMajorVersion()); |
| | | state.setOrderId(groupId); |
| | | state.setOrderUpdateId(0L); |
| | | state.setZoneSetId(hikOrderProperties.getZoneSetId()); |
| | | state.setDriving(Boolean.FALSE); |
| | | state.setPaused(Boolean.FALSE); |
| | | state.setNodeStates(Collections.emptyList()); |
| | | state.setEdgeStates(Collections.emptyList()); |
| | | state.setActionStates(buildFinishedActionStates()); |
| | | state.setLastNodeSequenceId(actionList.size() * 2L); |
| | | |
| | | Code code = codeService.getCacheByData(actionList.get(actionList.size() - 1).getCode()); |
| | | if (code != null) { |
| | | state.setLastNodeId(code.getData()); |
| | | state.setAgvPosition(buildAgvPosition(code)); |
| | | } |
| | | |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); |
| | | state.setVelocity(new HkStateVelocity()); |
| | | state.setBatteryState(buildBatteryState(agvDetail)); |
| | | |
| | | redis.push(RedisConstant.HK_AGV_DATA_FLAG, state); |
| | | } |
| | | |
| | | private List<HkStateActionState> buildFinishedActionStates() { |
| | | List<HkStateActionState> actionStates = new ArrayList<>(); |
| | | for (Action action : actionList) { |
| | | HkStateActionState actionState = new HkStateActionState(); |
| | | actionState.setActionId("A" + action.getId()); |
| | | actionState.setActionStatus(HkActionStatusType.FINISHED); |
| | | ActionTypeType actionType = ActionTypeType.get(action.getActionTypeEl()); |
| | | actionState.setActionType(actionType == null ? String.valueOf(action.getActionType()) : actionType.name()); |
| | | actionStates.add(actionState); |
| | | } |
| | | return actionStates; |
| | | } |
| | | |
| | | private HkStateAgvPosition buildAgvPosition(Code code) { |
| | | HkStateAgvPosition position = new HkStateAgvPosition(); |
| | | position.setPositionInitialized(Boolean.TRUE); |
| | | position.setLocalizationScore(1.0); |
| | | position.setX(code.getX() * hikOrderProperties.getCoordinateScale()); |
| | | position.setY(code.getY() * hikOrderProperties.getCoordinateScale()); |
| | | position.setMapId(hikOrderProperties.getMapId()); |
| | | |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); |
| | | if (agvDetail != null && agvDetail.getAgvAngle() != null) { |
| | | position.setTheta(HikAngleConstant.toHikAngleRadians(Math.toRadians(agvDetail.getAgvAngle()))); |
| | | } |
| | | return position; |
| | | } |
| | | |
| | | private HkStateBatteryState buildBatteryState(AgvDetail agvDetail) { |
| | | HkStateBatteryState batteryState = new HkStateBatteryState(); |
| | | if (agvDetail == null) { |
| | | return batteryState; |
| | | } |
| | | if (agvDetail.getSoc() != null) { |
| | | batteryState.setBatteryCharge(agvDetail.getSoc().doubleValue()); |
| | | } |
| | | if (agvDetail.getVol() != null) { |
| | | batteryState.setBatteryVoltage(agvDetail.getVol().doubleValue()); |
| | | } |
| | | return batteryState; |
| | | } |
| | | |
| | | private boolean isHikAgv() { |
| | | AgvModel agvModel = agvModelService.getByAgvId(agv.getId()); |
| | | if (agvModel == null) { |
| | | return false; |
| | | } |
| | | String protocol = agvModel.getProtocol(); |
| | | return StringUtils.hasText(protocol) && protocol.toLowerCase(Locale.ROOT).contains("hik"); |
| | | } |
| | | } |