EmployeeService.java
4.61 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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.ArrayList;
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;
private static final List<String> eightFloorEightdepartmentIdList = new ArrayList<>();
static {
eightFloorEightdepartmentIdList.add("od-3890573b4cd286f437d8e935e10f79bd");
eightFloorEightdepartmentIdList.add("od-80c6807080faabbb1c4db7bd4d9bd3fd");
eightFloorEightdepartmentIdList.add("od-257f04c282e11a4dbb40bbce905dc288");
eightFloorEightdepartmentIdList.add("od-4ff65217e64292e3ff5726258ddb2bd8");
eightFloorEightdepartmentIdList.add("od-5493776cfddf24c28e1c4620b9ee3406");
eightFloorEightdepartmentIdList.add("od-133305bbba80fa87b979453a1ffc689a");
eightFloorEightdepartmentIdList.add("od-2a43207cc2d92d781cb1cdfdcf33dc28");
eightFloorEightdepartmentIdList.add("od-f2a40e56473fbdfbdcca9efb4302cbca");
eightFloorEightdepartmentIdList.add("od-d7ddf7e8b966b0886319ff93f4dac95b");
eightFloorEightdepartmentIdList.add("od-ab7c4b49f80d53ca54f60bb47661bad3");
eightFloorEightdepartmentIdList.add("od-3d56a331c08d44d9cecc31a36b3e4f57");
}
@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) {
SystemFieldsDTO systemFieldsDTO = it.getSystemFields();
if (!currentEmployee.getDepartmentId().equals(systemFieldsDTO.getDepartmentId())
|| !currentEmployee.getName().equals(systemFieldsDTO.getName())
|| !currentEmployee.getMobile().equals(systemFieldsDTO.getMobile())) {
currentEmployee.setDepartmentId(systemFieldsDTO.getDepartmentId());
currentEmployee.setName(systemFieldsDTO.getName());
currentEmployee.setMobile(systemFieldsDTO.getMobile());
this.update(currentEmployee);
}
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());
}
employee.setFloor(eightFloorEightdepartmentIdList.contains(employee.getDepartmentId()) ? 8 : 14);
this.create(employee);
});
}
public List<Employee> findStartList(int startId, int floor, int limit) {
return employeeDao.findStartList(startId, floor, limit);
}
public int findCountByFloor(int floor) {
return employeeDao.findCountByFloor(floor);
}
}