|
@@ -7,13 +7,16 @@ import com.citu.module.menduner.system.controller.admin.position.vo.PositionPage
|
|
|
import com.citu.module.menduner.system.controller.admin.position.vo.PositionSaveReqVO;
|
|
|
import com.citu.module.menduner.system.dal.dataobject.position.PositionDO;
|
|
|
import com.citu.module.menduner.system.dal.mysql.position.PositionMapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static com.citu.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static com.citu.module.menduner.system.enums.ErrorCodeConstants.POSITION_NOT_EXISTS;
|
|
@@ -23,6 +26,7 @@ import static com.citu.module.menduner.system.enums.ErrorCodeConstants.POSITION_
|
|
|
*
|
|
|
* @author Rayson
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@Validated
|
|
|
public class PositionServiceImpl implements PositionService {
|
|
@@ -30,7 +34,39 @@ public class PositionServiceImpl implements PositionService {
|
|
|
@Resource
|
|
|
private PositionMapper positionMapper;
|
|
|
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param position 职位对象
|
|
|
+ * @param parentId 上级职位code
|
|
|
+ * @param level 当前层级
|
|
|
+ * @return void
|
|
|
+ * @description 递归解析position
|
|
|
+ * @author rayson
|
|
|
+ * @date 2024/5/8 上午11:47
|
|
|
+ **/
|
|
|
+ private void parseAndSavePosition(Map<String, Object> position, Long parentId, int level) {
|
|
|
+ if (null == parentId) {
|
|
|
+ parentId = 0L;
|
|
|
+ }
|
|
|
+ String name = position.get("name").toString();
|
|
|
+ PositionDO obj = PositionDO.builder().nameCn(name).parentId(parentId).level(level).build();
|
|
|
+
|
|
|
+ positionMapper.insert(obj);
|
|
|
+
|
|
|
+ // 解析子集并保存
|
|
|
+ List<Map<String, Object>> subLevelModelList = (List<Map<String, Object>>) position.get("subLevelModelList");
|
|
|
+ if (null != subLevelModelList) {
|
|
|
+ for (Map<String, Object> subLevel : subLevelModelList) {
|
|
|
+ parseAndSavePosition(subLevel, obj.getId(), obj.getLevel() + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Long createPosition(PositionSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
|
PositionDO position = BeanUtils.toBean(createReqVO, PositionDO.class);
|
|
@@ -76,4 +112,28 @@ public class PositionServiceImpl implements PositionService {
|
|
|
public List<PositionDO> getPositionList(PositionListReqVO pageReqVO) {
|
|
|
return positionMapper.selectList(pageReqVO);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void syncBossPosition() {
|
|
|
+ String url = "https://www.zhipin.com/wapi/zpCommon/data/getCityShowPosition";
|
|
|
+ ResponseEntity<Map> responseEntity = restTemplate.getForEntity(url, Map.class);
|
|
|
+ log.debug("[httpRequest][RequestType({}) 的响应结果({})", responseEntity);
|
|
|
+ if (!responseEntity.getStatusCode().is2xxSuccessful()) {
|
|
|
+ log.error("同步Boss职位类型错误");
|
|
|
+ }
|
|
|
+ // 获取响应体中的数据
|
|
|
+ Map<String, Object> responseBody = responseEntity.getBody();
|
|
|
+ Map<String, Object> zpData = (Map<String, Object>) responseBody.get("zpData");
|
|
|
+ List<Map<String, Object>> positionList = (List<Map<String, Object>>) zpData.get("position");
|
|
|
+
|
|
|
+ // 清空数据
|
|
|
+ positionMapper.truncate();
|
|
|
+ // 解析JSON数据并构建对象列表
|
|
|
+ for (Map<String, Object> position : positionList) {
|
|
|
+ parseAndSavePosition(position, null, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|