U8CustomerService.java
2.54 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
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.U8Customer;
import com.huaheng.pc.U8.mapper.U8CustomerMapper;
import com.huaheng.pc.config.customer.domain.Customer;
import com.huaheng.pc.config.customer.service.CustomerServiceImpl;
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 U8CustomerService extends ServiceImpl<U8CustomerMapper, U8Customer> {
@Resource
private CustomerServiceImpl service;
public List getU8CustomerList() {
// 切换到从库
DynamicDataSource.slave();
List<U8Customer> list = this.list();
return list;
}
public List sync() throws ParseException {
List<U8Customer> list = this.getU8CustomerList();
DynamicDataSource.master();
List<Customer> lst = service.list();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (U8Customer customer : list) {
for (Customer cus : lst) {
if (Objects.equals( customer.getCode() , cus.getCode())) {
if (!sdf.format(customer.getMaintenanceDate()).equals(sdf.format(cus.getMaintenanceDate()))) {
Customer supplier = Customer.builder()
.id(cus.getId())
.name(customer.getName())
.phoneNum(customer.getPhoneNum())
.attentionTo(customer.getAttentionTo())
.maintenanceDate(customer.getMaintenanceDate())
.build();
service.updateById(supplier);
}
}
}
if (lst.stream().noneMatch(w -> String.valueOf(w.getCode()).equals(customer.getCode()))) {
Customer cus = Customer.builder().code(customer.getCode())
.name(customer.getName())
.phoneNum(customer.getPhoneNum())
.attentionTo(customer.getAttentionTo())
.maintenanceDate(sdf.parse(sdf.format(customer.getMaintenanceDate())))
.warehouseCode("CS0001").companyCode("BHF")
.build();
service.save(cus);
}
}
return lst;
}
}