SupplierSyncService.java
6.36 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package com.huaheng.pc.config.supplier.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.bean.BeanUtils;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.customer.domain.Customer;
import com.huaheng.pc.config.customer.domain.CustomerErp;
import com.huaheng.pc.config.customer.service.CustomerErpService;
import com.huaheng.pc.config.customer.service.CustomerServiceImpl;
import com.huaheng.pc.config.supplier.domain.Supplier;
import com.huaheng.pc.config.supplier.mapper.SupplierMapper;
import com.huaheng.pc.config.syncTime.domain.SyncTime;
import com.huaheng.pc.config.syncTime.service.SyncTimeService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.framework.aspectj.lang.annotation.Ds;
import com.huaheng.framework.aspectj.lang.constant.DataSourceName;
import com.huaheng.pc.config.supplier.domain.SupplierErp;
import com.huaheng.pc.config.supplier.mapper.SupplierErpMapper;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* 定时任务同步erp的供应商、客户
*/
@Service
public class SupplierSyncService extends ServiceImpl<SupplierMapper, Supplier>{
@Resource
private SupplierService supplierService;
@Resource
private CustomerServiceImpl customerService;
@Resource
private SupplierErpService supplierErpService;
@Resource
private SyncTimeService syncTimeService;
@Resource
private AddressService addressService;
@Resource
private CustomerErpService customerErpService;
public void syncSupplierData(Integer supplierTime){
String syncName="supplier";
Date date=new Date();
Boolean tag=syncTimeService.isSync(syncName,supplierTime);
if(!tag){
return;
}
SyncTime syncTime=getTimeByName(syncName);
Address address=addressService.selectAddressByParam("ERP", QuantityConstant.WAREHOUSE_CS);
List<SupplierErp> list=supplierErpService.findSupplierData(supplierTime,address,syncTime.getSyncTimes());
System.out.println("=======供应商======="+date+"==========="+list.size());
saveAndUpdateData(list);
syncTimeService.updateStatus("supplier",1,date);
}
public void syncCustomerData(Integer customerTime){
String syncName="customer";
Date date=new Date();
Boolean tag=syncTimeService.isSync(syncName,customerTime);
if(!tag){
return;
}
SyncTime syncTime=getTimeByName(syncName);
Address address=addressService.selectAddressByParam("ERP", QuantityConstant.WAREHOUSE_CS);
List<CustomerErp> list=customerErpService.findCustomerData(customerTime,address,syncTime.getSyncTimes());
System.out.println("======客户数据========"+list.size());
saveAndUpdateDataCustomer(list);
syncTimeService.updateStatus("customer",1,date);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveAndUpdateData(List<SupplierErp> list){
if(list==null||list.size()==0){
return ;
}
List<Supplier> lists=new ArrayList<>();
for (int a=0;a<list.size();a++){
SupplierErp supplierErp=list.get(a);
Supplier supplier=new Supplier();
String code=supplierErp.getPmaa001();
//查找数据库有无该供应商,有则跳过,无则新增
Supplier supplier1 = supplierService.getSuppierByCode(code);
if(supplier1!=null){
// LambdaQueryWrapper<Supplier> lambda = new LambdaQueryWrapper<>();
// lambda.eq(Supplier::getCode,code);
// lambda.ne(Supplier::getId,supplier1.getId());
// supplierService.remove(lambda);
// continue;
if(StringUtils.isNotEmpty(supplierErp.getPmaal())&&!supplierErp.getPmaal().equals(supplier1.getName())){
supplier.setId(supplier1.getId());
}else{
continue;
}
}
supplier.setCode(code);
supplier.setName(supplierErp.getPmaal());
supplier.setDeleted(false);
if(StringUtils.isEmpty(supplierErp.getPmaal())){
supplier.setName(code);
}
lists.add(supplier);
}
if(lists!=null&&lists.size()>0){
supplierService.saveOrUpdateBatch(lists);
// containerSyncService.updateSyncById(ids);
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveAndUpdateDataCustomer(List<CustomerErp> list){
if(list==null||list.size()==0){
return ;
}
List<Customer> lists=new ArrayList<>();
for (int a=0;a<list.size();a++){
CustomerErp supplierErp=list.get(a);
Customer customer=new Customer();
String code=supplierErp.getPmaa001();
Customer customer1 = customerService.getCustomerByCode(code,null);
if(customer1!=null){
if(StringUtils.isNotEmpty(supplierErp.getPmaal())&&!supplierErp.getPmaal().equals(customer1.getName())){
customer.setId(customer1.getId());
}else{
continue;
}
}
customer.setCode(code);
customer.setName(supplierErp.getPmaal());
customer.setDeleted(false);
if(StringUtils.isEmpty(supplierErp.getPmaal())){
customer.setName(code);
}
lists.add(customer);
}
if(lists!=null&&lists.size()>0){
customerService.saveOrUpdateBatch(lists);
}
}
public SyncTime getTimeByName(String syncName){
LambdaQueryWrapper<SyncTime> wrapper=new LambdaQueryWrapper<>();
wrapper.eq(SyncTime::getSyncName,syncName);
wrapper.last("limit 1");
SyncTime syncTime= syncTimeService.getOne(wrapper);
return syncTime;
}
}