EmployeeService.java
2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.pipihelper.project.feishu.service;
import com.pipihelper.project.feishu.dao.EmployeeDao;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.dto.employee.SystemFieldsDTO;
import com.pipihelper.project.feishu.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class EmployeeService {
@Autowired
private EmployeeDao employeeDao;
@Autowired
private FeiShuApiService feiShuApiService;
public Employee findById(Integer id) {
return employeeDao.findById(id);
}
public Employee findByOpenId(String openId) {
return employeeDao.findByOpenId(openId);
}
public void deleteById(Integer id) {
employeeDao.deleteById(id);
}
public void create(Employee employee) {
employeeDao.create(employee);
}
public void update(Employee employee) {
employeeDao.update(employee);
}
public List<Employee> findAll() {
return employeeDao.findAll();
}
/**
* 同步所有花名册
*/
public void uprsetAllEmployee() {
List<FeiShuEmployeeDTO> dtos = feiShuApiService.getEmployeeList();
List<Employee> employeeList = this.findAll();
Map<String, Employee> employeeMap = employeeList.stream().collect(Collectors.toMap(Employee::getOpenId, Function.identity()));
List<String> openIdList = dtos.stream().map(FeiShuEmployeeDTO::getUserId).collect(Collectors.toList());
employeeList.forEach(it -> {
if (!openIdList.contains(it.getOpenId())) {
this.deleteById(it.getId());
}
});
dtos.forEach(it -> {
Employee currentEmployee = employeeMap.get(it.getUserId());
if (currentEmployee != null) {
return;
}
Employee employee = new Employee();
SystemFieldsDTO systemFieldsDTO = it.getSystemFields();
employee.setOpenId(it.getUserId());
if (systemFieldsDTO != null) {
employee.setGender(systemFieldsDTO.getGender());
employee.setStatus(systemFieldsDTO.getStatus());
employee.setDepartmentId(systemFieldsDTO.getDepartmentId());
employee.setName(systemFieldsDTO.getName());
employee.setMobile(systemFieldsDTO.getMobile());
}
this.create(employee);
});
}
public List<Employee> findStartList(int startId, int floor, int limit) {
return employeeDao.findStartList(startId, floor, limit);
}
}