U8DepartmentService.java
2.13 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
package com.huaheng.pc.U8.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.framework.datasource.DynamicDataSource;
import com.huaheng.pc.U8.domain.U8Department;
import com.huaheng.pc.U8.mapper.U8DepartmentMapper;
import com.huaheng.pc.system.dept.domain.Dept;
import com.huaheng.pc.system.dept.service.IDeptService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Objects;
@Service
public class U8DepartmentService extends ServiceImpl<U8DepartmentMapper, U8Department> {
@Resource
private IDeptService service;
public List getU8DepartmentList() {
// 切换到从库
DynamicDataSource.slave();
List<U8Department> list = this.list();
DynamicDataSource.master();
return list;
}
public List sync() throws ParseException {
List<U8Department> list = this.getU8DepartmentList();
List<Dept> lst = service.selectDeptAll();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (U8Department dep : list) {
for (Dept de : lst) {
if (Objects.equals( dep.getCode() , de.getCode())) {
if (!sdf.format(dep.getMaintenanceDate()).equals(sdf.format(de.getMaintenanceDate()))) {
Dept dept = new Dept();
dept.setId(de.getId());
dept.setDeptName(dep.getName());
dept.setMaintenanceDate(sdf.parse(sdf.format(dep.getMaintenanceDate())));
service.updateDepts(dept);
}
}
}
if (lst.stream().noneMatch(w -> String.valueOf(w.getCode()).equals(dep.getCode()))) {
Dept dept = new Dept();
dept.setCode(dep.getCode());
dept.setDeptName(dep.getName());
dept.setMaintenanceDate(sdf.parse(sdf.format(dep.getMaintenanceDate())));
service.insertDepts(dept);
}
}
return lst;
}
}