| | |
| | | package com.zy.acs.manager.core.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.utils.GsonUtils; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.acs.manager.core.domain.Lane; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.service.CodeService; |
| | | import com.zy.acs.manager.manager.service.RouteService; |
| | | import com.zy.acs.manager.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private RouteService routeService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | |
| | | public Boolean isInitialized() { |
| | | return this.initialized; |
| | |
| | | |
| | | @PostConstruct |
| | | public synchronized void init() { |
| | | log.info("the rcs system is starting to initialze lane data..."); |
| | | log.info("the rcs system is starting to initialize lane data..."); |
| | | List<Code> codeList = codeService.list(new LambdaQueryWrapper<Code>().eq(Code::getStatus, 1)); |
| | | |
| | | this.fillAdjacencyCodeMap(codeList); |
| | |
| | | |
| | | this.filterLanesWithFewPoints(); |
| | | |
| | | this.generateLaneHash(); |
| | | |
| | | this.initialized = Boolean.TRUE; |
| | | log.info("the lane data initialzation has been completed in rcs system."); |
| | | log.info("the lane data initialization has been completed in rcs system."); |
| | | |
| | | System.out.println(GsonUtils.toJson(this.lanes)); |
| | | } |
| | | |
| | | private void fillAdjacencyCodeMap(List<Code> codeList) { |
| | |
| | | } |
| | | |
| | | private void filterLanesWithFewPoints() { |
| | | this.lanes.removeIf(next -> next.getCodes().size() <= 2); |
| | | Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); |
| | | this.lanes.removeIf(next -> next.getCodes().size() <= Optional.ofNullable(maxAgvCountInLane).orElse(2)); |
| | | } |
| | | |
| | | |
| | | private void generateLaneHash() { |
| | | for (Lane lane : this.lanes) { |
| | | String hashCode = generateDigest(lane.getCodes()); |
| | | lane.setHashCode(hashCode); |
| | | } |
| | | } |
| | | |
| | | public static String generateDigest(List<String> list) { |
| | | MessageDigest md = null; |
| | | try { |
| | | md = MessageDigest.getInstance("SHA-256"); |
| | | } catch (NoSuchAlgorithmException e) { |
| | | log.error("generateDigest", e); |
| | | throw new RuntimeException(e); |
| | | } |
| | | String combined = list.stream().sorted().collect(Collectors.joining(",")); |
| | | byte[] hashBytes = md.digest(combined.getBytes()); |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (byte b : hashBytes) { |
| | | sb.append(String.format("%02x", b)); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | } |