U8CustomerService.java
2.96 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
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.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.ArrayList;
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();
ArrayList<Customer> list1 = new ArrayList<>();
ArrayList<Customer> list2 = new ArrayList<>();
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 customer1 = new Customer();
customer1.setId(cus.getId());
customer1.setName(customer.getName());
customer1.setPhoneNum(customer.getPhoneNum());
customer1.setAttentionTo(customer.getAttentionTo());
customer1.setMaintenanceDate(customer.getMaintenanceDate());
list1.add(customer1);
}
}
}
if (lst.stream().noneMatch(w -> String.valueOf(w.getCode()).equals(customer.getCode()))) {
Customer customer1 = new Customer();
customer1.setCode(customer.getCode());
customer1.setName(customer.getName());
customer1.setPhoneNum(customer.getPhoneNum());
customer1.setAttentionTo(customer.getAttentionTo());
customer1.setMaintenanceDate(sdf.parse(sdf.format(customer.getMaintenanceDate())));
customer1.setWarehouseCode(QuantityConstant.WAREHOUSECODE);
customer1.setCompanyCode(QuantityConstant.COMPANYCODE);
list2.add(customer1);
}
}
if (!list1.isEmpty()){
service.updateBatchById(list1);
}
if (!list2.isEmpty()){
service.saveBatch(list2);
}
return lst;
}
}