|
@@ -10,6 +10,7 @@ import com.usky.dxtop.common.utils.http.HttpUtils;
|
|
|
import com.usky.dxtop.model.Dept;
|
|
|
import com.usky.dxtop.model.Staff;
|
|
|
import com.usky.dxtop.model.SysDept;
|
|
|
+import com.usky.dxtop.model.SysUser;
|
|
|
import com.usky.dxtop.service.DeptService;
|
|
|
import com.usky.dxtop.service.StaffService;
|
|
|
import com.usky.dxtop.service.api.SmApi;
|
|
@@ -21,6 +22,7 @@ import org.springframework.stereotype.Component;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 世贸定时任务
|
|
@@ -65,9 +67,10 @@ public class SmJob {
|
|
|
List<Staff> checkStaffList = new ArrayList<>();
|
|
|
common(SmApi.PERSON_URL,treeMap,staffList -> {
|
|
|
List<Staff> list = staffList.toJavaList(Staff.class);
|
|
|
+ List<Staff> userListByNames = getUserListByNames(list.stream().map(Staff::getId).collect(Collectors.toList()));
|
|
|
list.forEach(date -> {
|
|
|
try {
|
|
|
- if (enhanceStaff(date,depts)){
|
|
|
+ if (enhanceStaff(date,depts,userListByNames)){
|
|
|
checkStaffList.add(date);
|
|
|
//发送人员信息
|
|
|
if (StringUtils.isNotBlank(date.getCardId()) && Double.parseDouble(date.getCardId()) > 60000){
|
|
@@ -88,15 +91,21 @@ public class SmJob {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public List<Staff> getUserListByNames(List<String> ids){
|
|
|
+ LambdaQueryWrapper<Staff> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.in(Staff::getId,ids);
|
|
|
+ return staffService.list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 增强人员信息
|
|
|
* @param data
|
|
|
*/
|
|
|
- public boolean enhanceStaff(Staff data,List<Dept> depts){
|
|
|
+ public boolean enhanceStaff(Staff data,List<Dept> depts,List<Staff> list){
|
|
|
data.setCardId(new BigDecimal(data.getCardId()).toString());
|
|
|
LambdaQueryWrapper<Staff> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(Staff::getId,data.getId());
|
|
|
- Staff staff = staffService.getOne(queryWrapper);
|
|
|
+ Staff staff = list.stream().filter(s -> s.getId().equals(data.getId())).findAny().orElse(null);
|
|
|
Map deptMap = JSON.parseObject(data.getDept(), Map.class);
|
|
|
return depts.stream().filter(dept -> dept.getId().equals(deptMap.get("id").toString())).findAny()
|
|
|
.map(s -> {
|
|
@@ -124,18 +133,14 @@ public class SmJob {
|
|
|
List<Dept> checkDeptList = new ArrayList<>();
|
|
|
common(SmApi.DEPT_URL,treeMap,deptList -> {
|
|
|
List<Dept> list = deptList.toJavaList(Dept.class);
|
|
|
+ List<Dept> deptListById = getDeptListById(list.stream().map(Dept::getId).collect(Collectors.toList()));
|
|
|
list.forEach(date -> {
|
|
|
try {
|
|
|
//只负责同步
|
|
|
- LambdaQueryWrapper<Dept> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.eq(Dept::getId,date.getId());
|
|
|
if (StringUtils.isBlank(date.getPid())){
|
|
|
date.setPid("0");
|
|
|
}
|
|
|
- Dept dept = deptService.getOne(queryWrapper);
|
|
|
- if (null != dept){
|
|
|
- date.setDId(dept.getDId());
|
|
|
- }
|
|
|
+ deptListById.stream().filter(d -> d.getId().equals(date.getId())).findAny().ifPresent(dept -> date.setDId(dept.getDId()));
|
|
|
checkDeptList.add(date);
|
|
|
}catch (Exception e){
|
|
|
log.error("smJob-group:"+e.getMessage());
|
|
@@ -150,6 +155,15 @@ public class SmJob {
|
|
|
deptService.buildDeptTree(list);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ public List<Dept> getDeptListById(List<String> ids){
|
|
|
+ LambdaQueryWrapper<Dept> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.in(Dept::getId,ids);
|
|
|
+ return deptService.list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public void common(String url, TreeMap<String,Object> param, Function<JSONArray,Boolean> function){
|
|
|
boolean isNext = true;
|
|
|
int page = 0;
|