| | |
| | | import com.zy.acs.manager.core.service.MapService; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.entity.CodeGap; |
| | | import com.zy.acs.manager.manager.entity.Route; |
| | | import com.zy.acs.manager.manager.mapper.CodeGapMapper; |
| | | import com.zy.acs.manager.manager.service.CodeGapService; |
| | | import com.zy.acs.manager.manager.service.RouteService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | |
| | | @Autowired |
| | | private MapService mapService; |
| | | @Autowired |
| | | private RouteService routeService; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | |
| | | return 0.0; |
| | | } |
| | | |
| | | @Override |
| | | public void removeCodeGapIfUnused(Long code0, Long code1) { |
| | | if (code0 == null || code1 == null) { |
| | | return; |
| | | } |
| | | long count = routeService.count(new LambdaQueryWrapper<Route>() |
| | | .eq(Route::getStartCode, code0) |
| | | .eq(Route::getEndCode, code1)) |
| | | + routeService.count(new LambdaQueryWrapper<Route>() |
| | | .eq(Route::getStartCode, code1) |
| | | .eq(Route::getEndCode, code0)); |
| | | if (count > 0) { |
| | | return; |
| | | } |
| | | CodeGap codeGap = findByCodeOfBoth(code0, code1); |
| | | if (codeGap != null && !this.removeById(codeGap.getId())) { |
| | | throw new CoolException("Delete Fail"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean save(CodeGap entity) { |
| | | boolean result = super.save(entity); |
| | | if (result) { |
| | | String gapKey = generateGapKey(entity.getCode0(), entity.getCode1()); |
| | | if (!Cools.isEmpty(gapKey)) { |
| | | GAP_DISTANCE_CACHE.put(gapKey, entity); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean removeById(Serializable id) { |
| | | CodeGap codeGap = this.getById(id); |
| | | boolean result = super.removeById(id); |
| | | if (result && codeGap != null) { |
| | | String gapKey = generateGapKey(codeGap.getCode0(), codeGap.getCode1()); |
| | | if (!Cools.isEmpty(gapKey)) { |
| | | GAP_DISTANCE_CACHE.remove(gapKey); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private static String generateGapKey(Long code0, Long code1) { |
| | | if (Cools.isEmpty(code0, code1)) { |
| | | return null; |