REQ-2481: 添加内部方法

This commit is contained in:
yanglin 2024-05-28 16:25:51 +08:00
parent f4d6b1ec96
commit b3dcf3b84b
2 changed files with 22 additions and 19 deletions

View File

@ -20,11 +20,9 @@ import cn.axzo.msg.center.message.xxl.MigrateOldMsgHotDataJob;
import cn.azxo.framework.common.model.CommonResponse;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
import com.google.common.base.Splitter;
import com.google.common.collect.Sets;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.core.env.PropertySource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -33,7 +31,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
/**
@ -93,21 +90,15 @@ public class PrivateMessageController {
}
@PostMapping("/getPersonIdByPhone")
public Object getPersonIdByPhone(@RequestParam("phones") String phones) {
List<String> phonesStr = Splitter.on(",")
.omitEmptyStrings()
.trimResults()
.splitToList(phones);
HashMap<String, Long> phone2PersonId = new HashMap<>();
if (CollectionUtils.isEmpty(phonesStr))
return phone2PersonId;
for (String phone : phonesStr) {
if (phone2PersonId.containsKey(phone))
continue;
Long personId = todoSearchService.getPersonIdByPhone(phone);
phone2PersonId.put(phone, personId);
}
return phone2PersonId;
public Object getPersonIdByPhone(@RequestParam("phone") String phone) {
Long personId = personService.getPersonIdByPhone(phone).orElse(null);
return CommonResponse.success(personId);
}
@PostMapping("/getPersonIdByPhone")
public Object getPhoneByPersonId(@RequestParam("personId") Long personId) {
String phone = personService.getPhoneByPersonId(personId).orElse(null);
return CommonResponse.success(phone);
}
/**

View File

@ -9,6 +9,7 @@ import cn.azxo.framework.common.model.CommonResponse;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -39,9 +40,20 @@ public class PersonService {
}
public Optional<Long> getPersonIdByPhone(String phone) {
if (StringUtils.isBlank(phone))
return Optional.empty();
CommonResponse<PersonProfileDto> profileResp = userProfileServiceApi
.getUnionPersonProfile(null, phone);
PersonProfileDto data = profileResp.getData();
return Optional.ofNullable(data == null ? null : data.getId());
}
}
public Optional<String> getPhoneByPersonId(Long personId) {
if (personId == null)
return Optional.empty();
CommonResponse<PersonProfileDto> profileResp = userProfileServiceApi
.getPersonProfile(personId);
PersonProfileDto data = profileResp.getData();
return Optional.ofNullable(data == null ? null : data.getPhone());
}
}