|
@@ -156,6 +156,12 @@ public class PositionServiceImpl implements PositionService {
|
|
|
|
|
|
@Override
|
|
|
@DSTransactional // 单机+多数据源方案,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
|
|
+ @CacheEvict(cacheNames =
|
|
|
+ {
|
|
|
+ RedisKeyConstants.MDE_POSITION_CHILDREN,
|
|
|
+ RedisKeyConstants.MDE_POSITION_TREE
|
|
|
+ },
|
|
|
+ allEntries = true)
|
|
|
public void syncBossPosition() {
|
|
|
log.info(" ========== 开始解析同步BOSS职业类型到数据库 ========== ");
|
|
|
String url = "https://www.zhipin.com/wapi/zpCommon/data/getCityShowPosition";
|
|
@@ -180,6 +186,79 @@ public class PositionServiceImpl implements PositionService {
|
|
|
log.info(" ========== 同步BOSS职业类型完成 ========== ");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @DSTransactional // 单机+多数据源方案,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
|
|
+ @CacheEvict(cacheNames =
|
|
|
+ {
|
|
|
+ RedisKeyConstants.MDE_POSITION_CHILDREN,
|
|
|
+ RedisKeyConstants.MDE_POSITION_TREE
|
|
|
+ },
|
|
|
+ allEntries = true)
|
|
|
+ public void syncVeryeastPosition() {
|
|
|
+ log.info(" ========== 开始解析同步最佳东方职业类型到数据库 ========== ");
|
|
|
+ String url = "https://dfws-file.veimg.cn/dict/ve/cn/common/job.json";
|
|
|
+ ResponseEntity<Map> responseEntity = restTemplate.getForEntity(url, Map.class);
|
|
|
+ log.debug("[httpRequest][RequestType({}) 的响应结果({})", responseEntity);
|
|
|
+ if (!responseEntity.getStatusCode().is2xxSuccessful()) {
|
|
|
+ log.error("同步最佳东方职位类型错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 获取响应体中的数据
|
|
|
+ Map<String, Object> responseBody = responseEntity.getBody();
|
|
|
+
|
|
|
+ LinkedHashMap<String, Object> resultMap = (LinkedHashMap<String, Object>) responseBody.get("data");
|
|
|
+ // 职位分类
|
|
|
+ List<Map<String, Object>> jobList = (List<Map<String, Object>>) resultMap.get("job");
|
|
|
+
|
|
|
+ // 清空数据
|
|
|
+ positionMapper.truncate();
|
|
|
+
|
|
|
+ // 获取一级职位分类
|
|
|
+ List<Map<String, Object>> positionList = jobList.stream()
|
|
|
+ .filter(map -> map.get("parent_id").toString().equals("0"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (Map<String, Object> position : positionList) {
|
|
|
+
|
|
|
+ PositionDO obj = PositionDO.builder()
|
|
|
+ .nameCn(position.get("value").toString())
|
|
|
+ .parentId(0L)
|
|
|
+ .level(1).build();
|
|
|
+ positionMapper.insert(obj);
|
|
|
+
|
|
|
+ // 递归处理子分类
|
|
|
+ parseAndSavePosition(position,jobList, obj.getId(), obj.getLevel() + 1);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info(" ========== 同步最佳东方职业类型完成 ========== ");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void parseAndSavePosition(Map<String, Object> position,
|
|
|
+ List<Map<String, Object>> jobList,
|
|
|
+ Long parentId,
|
|
|
+ int level) {
|
|
|
+ if (null == parentId) {
|
|
|
+ parentId = 0L;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> childList = jobList.stream()
|
|
|
+ .filter(map -> map.get("parent_id").toString().equals(position.get("code").toString()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (Map<String, Object> child : childList) {
|
|
|
+ PositionDO childObj = PositionDO.builder()
|
|
|
+ .nameCn(child.get("value").toString())
|
|
|
+ .parentId(parentId)
|
|
|
+ .level(level).build();
|
|
|
+ positionMapper.insert(childObj); // 假设insertReturnId方法返回新插入记录的ID
|
|
|
+
|
|
|
+ // 继续递归处理更深层次的子分类
|
|
|
+ parseAndSavePosition(child,jobList, childObj.getId(), level + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Cacheable(cacheNames = RedisKeyConstants.MDE_POSITION_TREE, key = "#reqVO", unless = "#result.size==0")
|
|
|
public List<AppPositionChildrenRespVO> getPosition(AppPositionListReqVO reqVO) {
|
|
@@ -291,7 +370,7 @@ public class PositionServiceImpl implements PositionService {
|
|
|
List<AppPositionSimpleRespVO> list = PositionConvert.INSTANCE.convertList2(positionDOList);
|
|
|
// 将埋点数据按照埋点次数排序
|
|
|
list.sort(Comparator.comparingInt((AppPositionSimpleRespVO o) -> {
|
|
|
- if(!idMap.containsKey(o.getId())) {
|
|
|
+ if (!idMap.containsKey(o.getId())) {
|
|
|
return 0;
|
|
|
}
|
|
|
return idMap.get(o.getId());
|