sap 定时任务

highway
zhaoxiaolin 1 year ago
parent 97e5b56b03
commit eb87002be9

@ -22,9 +22,6 @@ public interface RemoteSapService {
@PostMapping("/sap/shopOrderSync") @PostMapping("/sap/shopOrderSync")
public R<List<SapProOrder>> shopOrderSync(@RequestBody SapShopOrderQuery sapProOrder); public R<List<SapProOrder>> shopOrderSync(@RequestBody SapShopOrderQuery sapProOrder);
@PostMapping("/bomSync")
public R<Boolean> bomSync();
@PostMapping("/sap/sapRouterSync") @PostMapping("/sap/sapRouterSync")
public R<Boolean> sapRouterSync(); public R<Boolean> sapRouterSync();
@ -54,4 +51,13 @@ public interface RemoteSapService {
/**客户**/ /**客户**/
@PostMapping("/sap/sapCustomSync") @PostMapping("/sap/sapCustomSync")
public R sapCustomSync(); public R sapCustomSync();
/**product同步**/
@PostMapping("/sap/itemSync")
public R sapProductSync();
/**bom同步接口**/
@PostMapping("/sap/bomSync")
public R sapBomSync();
} }

@ -22,11 +22,6 @@ public class RemoteSapFallbackFactory implements FallbackFactory<RemoteSapServic
return R.fail("SAP服务获取SAP订单失败:" + throwable.getMessage()); return R.fail("SAP服务获取SAP订单失败:" + throwable.getMessage());
} }
@Override
public R<Boolean> bomSync() {
return null;
}
@Override @Override
public R<Boolean> sapRouterSync() { public R<Boolean> sapRouterSync() {
return R.fail("SAP服务同步工艺失败:" + throwable.getMessage()); return R.fail("SAP服务同步工艺失败:" + throwable.getMessage());
@ -67,6 +62,17 @@ public class RemoteSapFallbackFactory implements FallbackFactory<RemoteSapServic
return R.fail("sap客户同步失败" + throwable.getMessage()); return R.fail("sap客户同步失败" + throwable.getMessage());
} }
@Override
public R sapProductSync() {
return R.fail("sap product同步失败" + throwable.getMessage());
}
@Override
public R sapBomSync() {
return R.fail("sap bom同步失败" + throwable.getMessage());
}
}; };
} }
} }

@ -90,4 +90,15 @@ public class RyTask {
logger.info("++客户接口+开始++sapCustomTask+++++"); logger.info("++客户接口+开始++sapCustomTask+++++");
remoteSapService.sapCustomSync(); remoteSapService.sapCustomSync();
} }
/**每天执行040一次**/
public void sapProductTask(){
logger.info("++物料接口+开始++sapProductTask+++++");
remoteSapService.sapProductSync();
}
/**每天执行050一次**/
public void sapBomTask(){
logger.info("++物料接口+开始++sapBomTask+++++");
remoteSapService.sapBomSync();
}
} }

@ -477,6 +477,7 @@ public class ProOrderServiceImpl implements IProOrderService {
if (orderExit==null) {//不存在就插入 if (orderExit==null) {//不存在就插入
proOrder.setId(IdUtils.fastSimpleUUID()); proOrder.setId(IdUtils.fastSimpleUUID());
proOrderMapper.insertProOrder(proOrder); proOrderMapper.insertProOrder(proOrder);
logger.info("=======订单"+proOrder.getOrderCode()+"同步成功");
} else {//存在,如果没活动更新,否则不允许更新,关闭订单 } else {//存在,如果没活动更新,否则不允许更新,关闭订单
proOrder.setId(orderExit.getId()); proOrder.setId(orderExit.getId());
proOrder.setQuantitySplit(0L); proOrder.setQuantitySplit(0L);
@ -498,8 +499,10 @@ public class ProOrderServiceImpl implements IProOrderService {
//删除工单pro_order_workorder //删除工单pro_order_workorder
proOrderWorkorderMapper.deleteProOrderWorkorderByWorkorderIds(ids); proOrderWorkorderMapper.deleteProOrderWorkorderByWorkorderIds(ids);
} }
logger.info("=======订单"+proOrder.getOrderCode()+"同步成功");
}else{ }else{
failOrder = proOrder.getOrderCode(); failOrder = proOrder.getOrderCode();
logger.info("=======订单"+failOrder+"同步失败");
} }
// else {//关闭订单 // else {//关闭订单
// remoteSapService.sapCloseOrder(proOrder.getOrderCode()); // remoteSapService.sapCloseOrder(proOrder.getOrderCode());

@ -7,6 +7,11 @@
<facet type="web" name="Web"> <facet type="web" name="Web">
<configuration> <configuration>
<webroots /> <webroots />
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
<root url="file://$MODULE_DIR$/src/main/lib" />
<root url="file://$MODULE_DIR$/src/main/resources" />
</sourceRoots>
</configuration> </configuration>
</facet> </facet>
</component> </component>
@ -16,6 +21,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/lib" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
@ -216,7 +222,15 @@
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.24" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.24" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.3.24" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-core:5.3.24" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.3.24" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.3.24" level="project" />
<orderEntry type="library" name="Maven: com.sap:sapjco3:1.0.0" level="project" /> <orderEntry type="module-library">
<library name="Maven: com.sap:sapjco3:1.0.0">
<CLASSES>
<root url="jar://$MODULE_DIR$/src/main/lib/sapjco3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: junit:junit:4.13.2" level="project" /> <orderEntry type="library" name="Maven: junit:junit:4.13.2" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:2.2" level="project" /> <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:2.2" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest:2.2" level="project" /> <orderEntry type="library" name="Maven: org.hamcrest:hamcrest:2.2" level="project" />

@ -63,13 +63,35 @@ public class SapController extends BaseController {
/** /**
* *
* @param sapItemQuery * @param
* @return * @return
*/ */
@PostMapping("/itemSync") @PostMapping("/itemSync")
@Log(title = "同步SAP物料清单", businessType = BusinessType.SAP) @Log(title = "同步SAP物料清单", businessType = BusinessType.SAP)
public R itemSync(@RequestBody SapItemQuery sapItemQuery){ public R itemSync(){
return sapItemSyncService.itemSync(sapItemQuery); SapItemQuery qo = new SapItemQuery();
// 加载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") + "++++product同步开始++++++++++");
DynamicDataSourceContextHolder.push(dateSource.get("poolName"));// 这是数据源的key
Date maxTime = sapBomMapper.getProductMaxTime();
if(maxTime != null){
qo.setLaeda(DateFormatUtils.format(maxTime, "yyyyMMdd"));//修改日期20230923
}
R r = sapItemSyncService.itemSync(qo);
if(r.getCode()!=200){
logger.error("++++++++++++" + dateSource.get("poolName")+"同步product失败错误信息"+ r.getMsg());
}
logger.error("++++++++++++" + dateSource.get("poolName") + "++++product同步结束++++++++++");
});
return R.ok();
} }
/** /**
@ -78,8 +100,31 @@ public class SapController extends BaseController {
*/ */
@PostMapping("/bomSync") @PostMapping("/bomSync")
@Log(title = "同步SAP物料组件清单", businessType = BusinessType.SAP) @Log(title = "同步SAP物料组件清单", businessType = BusinessType.SAP)
public R bomSync(@RequestBody SapBomQuery sapBomQuery){ public R bomSync(){
return sapBomService.bomSync(sapBomQuery); SapBomQuery qo = new SapBomQuery();
// 加载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") + "++++bom同步开始++++++++++");
DynamicDataSourceContextHolder.push(dateSource.get("poolName"));// 这是数据源的key
Date maxTime = sapBomMapper.getProductMaxTime();
if(maxTime != null){
qo.setAedat(DateFormatUtils.format(maxTime, "yyyyMMdd"));//修改日期20230923
}
R r = sapBomService.bomSync(qo);
if(r.getCode()!=200){
logger.error("++++++++++++" + dateSource.get("poolName")+"同步bom失败错误信息"+ r.getMsg());
}
logger.error("++++++++++++" + dateSource.get("poolName") + "++++bom同步结束++++++++++");
});
return R.ok();
} }

@ -43,4 +43,6 @@ public interface SapBomMapper {
int addCustomBatchs(@Param("list")List<SapCustom> adds); int addCustomBatchs(@Param("list")List<SapCustom> adds);
String getParentId(String factoryCode); String getParentId(String factoryCode);
Date getProductMaxTime();
} }

@ -78,7 +78,7 @@ public class SapBomServiceImpl implements SapBomService {
S_MATNR.setValue(Constants.LOW, sapBomQuery.getMatnr()); S_MATNR.setValue(Constants.LOW, sapBomQuery.getMatnr());
} }
if (!StringUtils.isNull(sapBomQuery.getMatnr())){ if (!StringUtils.isNull(sapBomQuery.getMatkl())){
JCoTable S_MATKL = func.getTableParameterList().getTable("S_MATKL"); JCoTable S_MATKL = func.getTableParameterList().getTable("S_MATKL");
S_MATKL.appendRow(); S_MATKL.appendRow();
S_MATKL.setValue(Constants.SIGN, "I"); S_MATKL.setValue(Constants.SIGN, "I");
@ -86,7 +86,7 @@ public class SapBomServiceImpl implements SapBomService {
S_MATKL.setValue(Constants.LOW, sapBomQuery.getMatkl()); S_MATKL.setValue(Constants.LOW, sapBomQuery.getMatkl());
} }
if (!StringUtils.isNull(sapBomQuery.getMatnr())){ if (!StringUtils.isNull(sapBomQuery.getVerid())){
JCoTable S_VERID = func.getTableParameterList().getTable("S_VERID"); JCoTable S_VERID = func.getTableParameterList().getTable("S_VERID");
S_VERID.appendRow(); S_VERID.appendRow();
S_VERID.setValue(Constants.SIGN, "I"); S_VERID.setValue(Constants.SIGN, "I");
@ -94,7 +94,7 @@ public class SapBomServiceImpl implements SapBomService {
S_VERID.setValue(Constants.LOW, sapBomQuery.getVerid()); S_VERID.setValue(Constants.LOW, sapBomQuery.getVerid());
} }
if (!StringUtils.isNull(sapBomQuery.getMatnr())){ if (!StringUtils.isNull(sapBomQuery.getStlnr())){
JCoTable S_STLNR = func.getTableParameterList().getTable("S_STLNR"); JCoTable S_STLNR = func.getTableParameterList().getTable("S_STLNR");
S_STLNR.appendRow(); S_STLNR.appendRow();
S_STLNR.setValue(Constants.SIGN, "I"); S_STLNR.setValue(Constants.SIGN, "I");
@ -102,7 +102,7 @@ public class SapBomServiceImpl implements SapBomService {
S_STLNR.setValue(Constants.LOW, sapBomQuery.getStlnr()); S_STLNR.setValue(Constants.LOW, sapBomQuery.getStlnr());
} }
if (!StringUtils.isNull(sapBomQuery.getMatnr())){ if (!StringUtils.isNull(sapBomQuery.getAndat())){
JCoTable S_ANDAT = func.getTableParameterList().getTable("S_ANDAT"); JCoTable S_ANDAT = func.getTableParameterList().getTable("S_ANDAT");
S_ANDAT.appendRow(); S_ANDAT.appendRow();
S_ANDAT.setValue(Constants.SIGN, "I"); S_ANDAT.setValue(Constants.SIGN, "I");
@ -111,7 +111,7 @@ public class SapBomServiceImpl implements SapBomService {
S_ANDAT.setValue("HIGH", END_DATE); S_ANDAT.setValue("HIGH", END_DATE);
} }
if (!StringUtils.isNull(sapBomQuery.getMatnr())){ if (!StringUtils.isNull(sapBomQuery.getAedat())){
JCoTable S_AEDAT = func.getTableParameterList().getTable("S_AEDAT"); JCoTable S_AEDAT = func.getTableParameterList().getTable("S_AEDAT");
S_AEDAT.appendRow(); S_AEDAT.appendRow();
S_AEDAT.setValue(Constants.SIGN, "I"); S_AEDAT.setValue(Constants.SIGN, "I");

@ -208,13 +208,14 @@ public class SapItemSyncImpl implements SapItemSyncService {
if (StringUtils.isNull(u)) if (StringUtils.isNull(u))
{ {
BeanValidators.validateWithException(validator, sapBaseProduct); BeanValidators.validateWithException(validator, sapBaseProduct);
sapBaseProduct.setCreateBy(SecurityUtils.getUsername()); sapBaseProduct.setCreateBy("job");
sapBaseProductMapper.insertBaseProduct(sapBaseProduct); sapBaseProductMapper.insertBaseProduct(sapBaseProduct);
successNum++; successNum++;
successMsg.append("<br/>" + successNum + "、物料 " + sapBaseProduct.getProductCode() + " 同步成功"); successMsg.append("<br/>" + successNum + "、物料 " + sapBaseProduct.getProductCode() + " 同步成功");
} }
else if (!StringUtils.isNull(u)){ else if (!StringUtils.isNull(u)){
sapBaseProduct.setProductId(u.getProductId()); sapBaseProduct.setProductId(u.getProductId());
sapBaseProduct.setCreateBy("job");
sapBaseProductMapper.updateBaseProduct(sapBaseProduct); sapBaseProductMapper.updateBaseProduct(sapBaseProduct);
successNum++; successNum++;
successMsg.append("<br/>" + successNum + "、物料 " + sapBaseProduct.getProductCode() + " 更新成功"); successMsg.append("<br/>" + successNum + "、物料 " + sapBaseProduct.getProductCode() + " 更新成功");

@ -324,8 +324,23 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
adds.stream().forEach(e->{ adds.stream().forEach(e->{
e.setRecordId(IdUtils.fastSimpleUUID()); e.setRecordId(IdUtils.fastSimpleUUID());
}); });
int n = sapBomMapper.addSupplierBatchs(adds);
System.out.println("供应商新增成功条数:"+ n); int allsize = adds.size();
int inserttimes = allsize/100+1;
for(int m=0;m<inserttimes;m++){
List<SapSupplier> everyList;
if(m<(inserttimes-1)){
everyList = adds.subList(m*100,(m+1)*100);
}else{
everyList = adds.subList(m*100,allsize);
}
if(everyList.size()>0){
sapBomMapper.addSupplierBatchs(everyList);
}
}
System.out.println("供应商新增成功条数:"+ allsize);
} }
} }
@ -347,22 +362,32 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService {
for(String exsitCode:exsitCodes){ for(String exsitCode:exsitCodes){
updates = dtos.stream().filter(dto -> dto.getKunnr().equals(exsitCode)).collect(Collectors.toList()); updates = dtos.stream().filter(dto -> dto.getKunnr().equals(exsitCode)).collect(Collectors.toList());
} }
if(CollectionUtils.isEmpty(updates)){ if(!CollectionUtils.isEmpty(updates)){
int m = sapBomMapper.updateCustomBatchs(updates); int m = sapBomMapper.updateCustomBatchs(updates);
System.out.println("客户更新成功条数:"+m); System.out.println("客户更新成功条数:"+m);
} }
List<SapCustom> adds = new ArrayList<>(); List<SapCustom> adds = new ArrayList<>();
for(String noExsitCode:noExsitCodes){ for(String noExsitCode:noExsitCodes){
adds = dtos.stream().filter(dto -> dto.getKunnr().equals(noExsitCode)).collect(Collectors.toList()); List<SapCustom> adds0 = dtos.stream().filter(dto -> dto.getKunnr().equals(noExsitCode)).collect(Collectors.toList());
adds.addAll(adds0);
} }
if(CollectionUtils.isEmpty(adds)){ if(!CollectionUtils.isEmpty(adds)){
//工厂parentId
/*String parentId = sapBomMapper.getParentId(adds.get(0).getBukrs()); int allsize = adds.size();
adds.stream().forEach(e->{ int inserttimes = allsize/100+1;
e.setParentId(parentId); for(int m=0;m<inserttimes;m++){
});*/ List<SapCustom> everyList;
int n = sapBomMapper.addCustomBatchs(adds); if(m<(inserttimes-1)){
System.out.println("客户新增成功条数:"+ n); everyList = adds.subList(m*100,(m+1)*100);
}else{
everyList = adds.subList(m*100,allsize);
}
if(everyList.size()>0){
sapBomMapper.addCustomBatchs(everyList);
}
}
System.out.println("客户新增成功条数:"+ allsize);
} }
} }

@ -77,8 +77,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getParentId" resultType="java.lang.String"> <select id="getParentId" resultType="java.lang.String">
select factory_id from sys_factory where factory_code = #{factoryCode} select factory_id from sys_factory where factory_code = #{factoryCode}
</select> </select>
<select id="getProductMaxTime" resultType="java.util.Date">
select max(create_time) from sys_factory where create_by = 'job'
</select>
<insert id="insertBaseBom" parameterType="com.op.system.api.domain.sap.SapBom"> <insert id="insertBaseBom" parameterType="com.op.system.api.domain.sap.SapBom">
insert into base_bom insert into base_bom
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="bomBo != null">bom_bo,</if> <if test="bomBo != null">bom_bo,</if>
@ -284,7 +287,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
set set
zh_desc = #{item.name1}, zh_desc = #{item.name1},
contact_phone = #{item.telf1}, contact_phone = #{item.telf1},
address = #{item.stars}, address = #{item.stras},
factory_code = #{item.bukrs} factory_code = #{item.bukrs}
where where
supplier_code = #{item.lifnr} supplier_code = #{item.lifnr}
@ -299,7 +302,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_time) update_time)
VALUES VALUES
<foreach collection="list" index="index" item="item" separator=","> <foreach collection="list" index="index" item="item" separator=",">
(#{item.lifnr},#{item.name1},#{item.telf1},#{item.stars},#{item.bukrs} (#{item.lifnr},#{item.name1},#{item.telf1},#{item.stras},#{item.bukrs},
'job', 'job',
#{item.erdat}, #{item.erdat},
#{item.erdat}) #{item.erdat})
@ -312,7 +315,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
set set
client_name = #{item.name1}, client_name = #{item.name1},
contact1_tel = #{item.telf1}, contact1_tel = #{item.telf1},
address = #{item.stars}, address = #{item.stras},
factory_code = #{item.bukrs} factory_code = #{item.bukrs}
where where
client_code = #{item.kunnr} client_code = #{item.kunnr}
@ -321,13 +324,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!--批量添加客户建模表--> <!--批量添加客户建模表-->
<insert id="addCustomBatchs"> <insert id="addCustomBatchs">
insert into sys_customer insert into sys_customer
(client_code,client_name,contact1_tel,address,factory_code, (client_id,client_code,client_name,contact1_tel,address,factory_code,
create_by, create_by,
create_time, create_time,
update_time) update_time)
VALUES VALUES
<foreach collection="list" index="index" item="item" separator=","> <foreach collection="list" index="index" item="item" separator=",">
(#{item.kunnr},#{item.name1},#{item.telf1},#{item.stars},#{item.bukrs}, (#{item.kunnr},#{item.kunnr},#{item.name1},#{item.telf1},#{item.stras},#{item.bukrs},
'job', 'job',
#{item.erdat}, #{item.erdat},
#{item.erdat}) #{item.erdat})

Loading…
Cancel
Save