|
@@ -0,0 +1,61 @@
|
|
|
+package com.persagy.fm.person.service.impl;
|
|
|
+
|
|
|
+import com.persagy.fm.person.model.Person;
|
|
|
+import com.persagy.fm.person.service.IPersonService;
|
|
|
+import com.persagy.fm.translate.service.ITranslator;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PersonNameTranslator implements ITranslator {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IPersonService personService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String trans(String parameter) {
|
|
|
+ if(StringUtils.isBlank(parameter)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ Person person = personService.queryPersonDetail(Long.valueOf(parameter));
|
|
|
+ return person.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> transBatch(List<String> parameter) {
|
|
|
+ if(CollectionUtils.isEmpty(parameter)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Set<Long> idSet = new HashSet<>();
|
|
|
+ for(String para:parameter) {
|
|
|
+ String[] ids = StringUtils.split(para, ",");
|
|
|
+ for(String id:ids) {
|
|
|
+ idSet.add(Long.valueOf(id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Long> idList = new ArrayList<>();
|
|
|
+ idList.addAll(idSet);
|
|
|
+ Map<String, Object> idMap = new HashMap<>(16);
|
|
|
+ List<Person> personList = personService.queryByIds(idList);
|
|
|
+ personList.forEach(person -> idMap.put(String.valueOf(person.getId()), person.getName()));
|
|
|
+ Map<String, Object> resultMap = new HashMap<>(16);
|
|
|
+ for(String para:parameter) {
|
|
|
+ String[] ids = StringUtils.split(para, ",");
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for(String id:ids) {
|
|
|
+ sb.append(idMap.get(id)).append(",");
|
|
|
+ }
|
|
|
+ sb.deleteCharAt(sb.length() - 1);
|
|
|
+ Map<String, String> showNameMap = new HashMap<>(1);
|
|
|
+ showNameMap.put("name", sb.toString());
|
|
|
+ resultMap.put(para, showNameMap);
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+}
|