供应商同步,客户同步

highway
shaoyong 1 year ago
parent 7f5ab75bfd
commit 7356633a0c

@ -183,7 +183,30 @@ public class SapController extends BaseController {
@Log(title = "供应商主数据", businessType = BusinessType.SAP)
public R sapSupplierSync(){
SapSupplierQuery sapSupplierQuery = new SapSupplierQuery();
return sapWorkCenterService.sapSupplierSync(sapSupplierQuery);
// 加载sf-cloud库的sys_datasource
SysUser sysUser = new SysUser();
sysUser.setUserId(1L);
R<List<Map<String, String>>> dateSources0 = remoteUserService.getPoolNameList(sysUser);
List<Map<String, String>> dateSources = dateSources0.getData();
dateSources.forEach(dateSource -> {
logger.info("++++++++++++" + dateSource.get("poolName") + "++++供应商主数据开始++++++++++");
DynamicDataSourceContextHolder.push(dateSource.get("poolName"));// 这是数据源的key
sapSupplierQuery.setBukrs(dateSource.get("poolName").replace("ds_",""));//工厂
Date maxTime = sapBomMapper.getMaxTime();
if(maxTime != null){
sapSupplierQuery.setErdat(DateFormatUtils.format(maxTime, "yyyyMMdd"));//修改日期20230923
}
R r = sapWorkCenterService.sapSupplierSync(sapSupplierQuery);
if(r.getCode()==200){
List<SapSupplier> dtos = (List<SapSupplier>) r.getData();
sapWorkCenterService.syncSupplier(dtos);
}else{
logger.error("++++++++++++" + dateSource.get("poolName")+"错误信息:"+ r.getMsg());
}
logger.error("++++++++++++" + dateSource.get("poolName") + "++++供应商主数据结束++++++++++");
});
return R.ok();
}
/**
@ -195,7 +218,30 @@ public class SapController extends BaseController {
@Log(title = "客户主数据", businessType = BusinessType.SAP)
public R sapCustomSync(){
SapCustom sapCustom = new SapCustom();
return sapWorkCenterService.sapCustomSync(sapCustom);
// 加载sf-cloud库的sys_datasource
SysUser sysUser = new SysUser();
sysUser.setUserId(1L);
R<List<Map<String, String>>> dateSources0 = remoteUserService.getPoolNameList(sysUser);
List<Map<String, String>> dateSources = dateSources0.getData();
dateSources.forEach(dateSource -> {
logger.info("++++++++++++" + dateSource.get("poolName") + "++++客户主数据开始++++++++++");
DynamicDataSourceContextHolder.push(dateSource.get("poolName"));// 这是数据源的key
sapCustom.setBukrs(dateSource.get("poolName").replace("ds_",""));//工厂
Date maxTime = sapBomMapper.getMaxTime();
if(maxTime != null){
sapCustom.setErdat(DateFormatUtils.format(maxTime, "yyyyMMdd"));//修改日期20230923
}
R r = sapWorkCenterService.sapCustomSync(sapCustom);
if(r.getCode()==200){
List<SapCustom> dtos = (List<SapCustom>) r.getData();
sapWorkCenterService.syncCustom(dtos);
}else{
logger.error("++++++++++++" + dateSource.get("poolName")+"错误信息:"+ r.getMsg());
}
logger.error("++++++++++++" + dateSource.get("poolName") + "++++客户主数据结束++++++++++");
});
return R.ok();
}
}

@ -1,8 +1,6 @@
package com.op.sap.mapper;
import com.op.system.api.domain.sap.SapBom;
import com.op.system.api.domain.sap.SapBomComponent;
import com.op.system.api.domain.sap.SapWorkCenter;
import com.op.system.api.domain.sap.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -32,5 +30,11 @@ public interface SapBomMapper {
int addFactoryBatchs(@Param("list")List<SapWorkCenter> adds);
int updateSupplierBatchs(@Param("list")List<SapSupplier> updates);
int addSupplierBatchs(@Param("list")List<SapSupplier> adds);
int updateCustomBatchs(@Param("list")List<SapCustom> updates);
int addCustomBatchs(@Param("list")List<SapCustom> adds);
String getParentId(String factoryCode);
}

@ -19,4 +19,8 @@ public interface SapWorkCenterService {
R sapCustomSync(SapCustom sapCustom);
void syncWorkCenter(List<SapWorkCenter> dtos);
void syncSupplier(List<SapSupplier> dtos);
void syncCustom(List<SapCustom> dtos);
}

@ -260,7 +260,7 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
/**sys_factory**/
@Override
public void syncWorkCenter(List<SapWorkCenter> dtos) {
//sap返回的工作中心编码
//sap返回的供应商编码
List<String> codes = dtos.stream().map(SapWorkCenter::getArbpl).collect(Collectors.toList());
//sap返回的工作中心编码-本地已存在
List<String> exsitCodes = sapBomMapper.getExsitCodes(codes);
@ -290,5 +290,77 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
System.out.println("工作中心新增成功条数:"+ n);
}
}
/**
*
* @param dtos
*/
@Override
public void syncSupplier(List<SapSupplier> dtos) {
//sap返回的供应商编码
List<String> codes = dtos.stream().map(SapSupplier::getLifnr).collect(Collectors.toList());
//sap返回的供应商编码-本地已存在
List<String> exsitCodes = sapBomMapper.getExsitCodes(codes);
//sap返回的供应商编码-本地不存在// 差集 (list2 - list1)
List<String> noExsitCodes = codes.stream().filter(item -> !exsitCodes.contains(item)).collect(Collectors.toList());
List<SapSupplier> updates = new ArrayList<>();
for(String exsitCode:exsitCodes){
updates = dtos.stream().filter(dto -> dto.getLifnr().equals(exsitCode)).collect(Collectors.toList());
}
if(CollectionUtils.isEmpty(updates)){
int m = sapBomMapper.updateSupplierBatchs(updates);
System.out.println("供应商更新成功条数:"+m);
}
List<SapSupplier> adds = new ArrayList<>();
for(String noExsitCode:noExsitCodes){
adds = dtos.stream().filter(dto -> dto.getLifnr().equals(noExsitCode)).collect(Collectors.toList());
}
if(CollectionUtils.isEmpty(adds)){
//工厂parentId
/*String parentId = sapBomMapper.getParentId(adds.get(0).getBukrs());
adds.stream().forEach(e->{
e.setParentId(parentId);
});*/
int n = sapBomMapper.addSupplierBatchs(adds);
System.out.println("供应商新增成功条数:"+ n);
}
}
/**
*
* @param dtos
*/
@Override
public void syncCustom(List<SapCustom> dtos) {
//sap返回的客户编码
List<String> codes = dtos.stream().map(SapCustom::getKunnr).collect(Collectors.toList());
//sap返回的客户编码-本地已存在
List<String> exsitCodes = sapBomMapper.getExsitCodes(codes);
//sap返回的客户编码-本地不存在// 差集 (list2 - list1)
List<String> noExsitCodes = codes.stream().filter(item -> !exsitCodes.contains(item)).collect(Collectors.toList());
List<SapCustom> updates = new ArrayList<>();
for(String exsitCode:exsitCodes){
updates = dtos.stream().filter(dto -> dto.getKunnr().equals(exsitCode)).collect(Collectors.toList());
}
if(CollectionUtils.isEmpty(updates)){
int m = sapBomMapper.updateCustomBatchs(updates);
System.out.println("客户更新成功条数:"+m);
}
List<SapCustom> adds = new ArrayList<>();
for(String noExsitCode:noExsitCodes){
adds = dtos.stream().filter(dto -> dto.getKunnr().equals(noExsitCode)).collect(Collectors.toList());
}
if(CollectionUtils.isEmpty(adds)){
//工厂parentId
/*String parentId = sapBomMapper.getParentId(adds.get(0).getBukrs());
adds.stream().forEach(e->{
e.setParentId(parentId);
});*/
int n = sapBomMapper.addCustomBatchs(adds);
System.out.println("客户新增成功条数:"+ n);
}
}
}

@ -257,4 +257,53 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{factoryCode}
</foreach>
</delete>
<!--批量更新供应商建模表-->
<update id="updateSupplierBatchs">
<foreach collection="list" item="item" separator=";">
update base_supplier
set zh_desc = #{item.name1}
where
supplier_code = #{item.bukrs}
</foreach>
</update>
<!--批量添加供应商建模表-->
<insert id="addSupplierBatchs">
insert into base_supplier
(supplier_code,zh_desc,contact_phone,address,
create_by,
create_time,
update_time)
VALUES
<foreach collection="list" index="index" item="item" separator=",">
(#{item.bukrs},#{item.name1},#{item.telf1},#{item.stars}
'job',
#{item.erdat},
#{item.erdat})
</foreach>
</insert>
<!--批量更新供应商建模表-->
<update id="updateCustomBatchs">
<foreach collection="list" item="item" separator=";">
update sys_customer
set client_name = #{item.name1}
where
client_code = #{item.bukrs}
</foreach>
</update>
<!--批量添加供应商建模表-->
<insert id="addCustomBatchs">
insert into sys_customer
(client_code,client_name,contact1_tel,address,
create_by,
create_time,
update_time)
VALUES
<foreach collection="list" index="index" item="item" separator=",">
(#{item.bukrs},#{item.name1},#{item.telf1},#{item.stars}
'job',
#{item.erdat},
#{item.erdat})
</foreach>
</insert>
</mapper>

Loading…
Cancel
Save