U8PersonService.java
4.15 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
package com.huaheng.pc.U8.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.datasource.DynamicDataSource;
import com.huaheng.framework.shiro.service.PasswordService;
import com.huaheng.pc.U8.domain.U8Person;
import com.huaheng.pc.U8.mapper.U8PersonMapper;
import com.huaheng.pc.system.dept.domain.Dept;
import com.huaheng.pc.system.dept.service.IDeptService;
import com.huaheng.pc.system.user.domain.SysUserWarehouse;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.domain.UserCompany;
import com.huaheng.pc.system.user.domain.UserRole;
import com.huaheng.pc.system.user.mapper.SysUserWarehouseMapper;
import com.huaheng.pc.system.user.mapper.UserCompanyMapper;
import com.huaheng.pc.system.user.mapper.UserRoleMapper;
import com.huaheng.pc.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
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 U8PersonService extends ServiceImpl<U8PersonMapper, U8Person> {
@Resource
private IUserService service;
@Resource
private IDeptService deptService;
@Resource
private SysUserWarehouseMapper sysUserWarehouseMapper;
@Resource
private UserCompanyMapper userCompanyMapper;
@Autowired
private PasswordService passwordService;
@Resource
private UserRoleMapper userRoleMapper;
public List getU8PersonList() {
// 切换到从库
DynamicDataSource.slave();
List<U8Person> list = this.list();
DynamicDataSource.master();
return list;
}
public List sync() throws ParseException {
List<U8Person> list = this.getU8PersonList();
List<User> lst = service.selectAll();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (U8Person dep : list) {
for (User de : lst) {
if (Objects.equals(dep.getCode(), de.getLoginName())) {
if (!sdf.format(dep.getMaintenanceDate()).equals(sdf.format(de.getMaintenanceDate()))) {
Dept dept = deptService.selectDepts(dep.getDeptCode());
User user = new User();
user.setId(de.getId());
user.setUserName(dep.getName());
user.setDeptId(dept.getId());
user.setMaintenanceDate(sdf.parse(sdf.format(dep.getMaintenanceDate())));
service.updateUsers(user);
}
}
}
if (lst.stream().noneMatch(w -> String.valueOf(w.getLoginName()).equals(dep.getCode()))) {
Dept dept = deptService.selectDepts(dep.getDeptCode());
User user = new User();
user.setLoginName(dep.getCode());
user.setUserName(dep.getName());
user.randomSalt();
user.setPassword(passwordService.encryptPassword(user.getLoginName(), "123456", user.getSalt()));
user.setDeptId(dept.getId());
user.setMaintenanceDate(sdf.parse(sdf.format(dep.getMaintenanceDate())));
Integer id = service.insertUsers(user);
//用户绑定仓库
SysUserWarehouse warehouse = new SysUserWarehouse();
warehouse.setUserId(id);
warehouse.setWarehouseCode(QuantityConstant.WAREHOUSECODE);
sysUserWarehouseMapper.insert(warehouse);
//用户绑定货主
UserCompany company = new UserCompany();
company.setUserId(id);
company.setCompanyId(QuantityConstant.COMPANYID);
userCompanyMapper.insert(company);
//用户绑定角色
UserRole role = new UserRole();
role.setUserId(id);
role.setRoleId(QuantityConstant.ROLE_ID);
userRoleMapper.insert(role);
}
}
return lst;
}
}