第三方接口下载bug修改

pro
anthonywj 2 years ago
parent 7b3cf5a9d1
commit 3e53fea186

@ -1,5 +1,6 @@
package com.glxp.api.controller.thrsys;
import cn.hutool.core.thread.ThreadUtil;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.common.enums.ResultEnum;
@ -23,6 +24,7 @@ import com.glxp.api.service.thrsys.ThrCorpsDlService;
import com.glxp.api.service.thrsys.ThrSystemDetailService;
import com.glxp.api.util.CustomUtil;
import com.glxp.api.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
@ -32,6 +34,7 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@RestController
public class ThrCorpsController {
@Resource
@ -137,7 +140,7 @@ public class ThrCorpsController {
thrCorpImportLogEntity.setUpdateTime(new Date());
thrCorpImportLogEntity.setThirdSysFk(filterThrProductsRequest.getThirdSysFk());
thrCorpImportLogService.insertImportLog(thrCorpImportLogEntity);
thrCorpsDlService.importCorps(genKey,null, filterThrProductsRequest.getThirdSysFk());
thrCorpsDlService.importCorps(genKey, null, filterThrProductsRequest.getThirdSysFk());
return ResultVOUtils.success("后台开始下载更新,请稍后刷新查看");
}
}
@ -146,33 +149,19 @@ public class ThrCorpsController {
@AuthRuleAnnotation("")
@PostMapping("/udiwms/thrsys/corp/corpsDlAll")
public BaseResponse corpsDlAll(@RequestBody ThrUnitMaintainFilterRequest thrUnitMaintainFilterRequest) {
thrUnitMaintainFilterRequest.setThirdSysFk(thrUnitMaintainFilterRequest.getThirdSys());
String data = (String) redisUtil.get(Constant.dlThrProducts);
if (data != null && data.equals("true")) {
return ResultVOUtils.error(500, "当前任务正在下载更新产品信息,请稍后重试!");
} else {
redisUtil.set(Constant.dlThrCorps, "true", 30);
if (thrUnitMaintainFilterRequest.getThirdSysFk() == null) {
return ResultVOUtils.error(500, "未选择第三方系统!");
}
ThrCorpImportLogEntity thrCorpImportLogEntity = new ThrCorpImportLogEntity();
String genKey = CustomUtil.getId();
thrCorpImportLogEntity.setGenKey(genKey);
thrCorpImportLogEntity.setFromType("第三方系统获取");
thrCorpImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_PROCESS);
thrCorpImportLogEntity.setUpdateTime(new Date());
thrCorpImportLogEntity.setThirdSysFk(thrUnitMaintainFilterRequest.getThirdSysFk());
thrCorpImportLogService.insertImportLog(thrCorpImportLogEntity);
if (thrUnitMaintainFilterRequest.getThrCorpEntities() != null && thrUnitMaintainFilterRequest.getThrCorpEntities().size() > 0) {//选中导出
thrCorpsDlService.importSelectCorps(genKey, thrUnitMaintainFilterRequest.getThrCorpEntities(), thrUnitMaintainFilterRequest.getThirdSysFk());
} else { //结果导出
thrCorpsDlService.importCorps(genKey,thrUnitMaintainFilterRequest, thrUnitMaintainFilterRequest.getThirdSysFk());
if (null == thrUnitMaintainFilterRequest) {
return ResultVOUtils.error(500, "参数不能为空");
}
ThreadUtil.execAsync(() -> {
try {
thrCorpService.downloadByRequest(thrUnitMaintainFilterRequest);
} catch (Exception e) {
log.error("下载异常", e);
e.printStackTrace();
}
// thrCorpsDlService.importCorps(genKey, filterThrCorpRequest.getThirdSysFk());
return ResultVOUtils.success("后台开始下载更新,请稍后刷新查看");
}
});
return ResultVOUtils.success("后台正在下载,请稍后刷新查看!");
}
//查询ERP往来单位

@ -24,12 +24,14 @@ import com.glxp.api.res.thrsys.ThrProductsResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.thrsys.ThrProductsService;
import com.glxp.api.service.thrsys.ThrSystemDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.List;
@ -41,6 +43,7 @@ import java.util.List;
* @author ${author}
* @since 2023-01-10
*/
@Slf4j
@RestController
public class ThrProductsController {
@ -74,35 +77,9 @@ public class ThrProductsController {
if (thrSystemDetailEntity.getEnabled()) {
if (thrSystemDetailEntity.getFromType() == 0 || (filterThrProductsRequest.getIsDownThrSys() != null && filterThrProductsRequest.getIsDownThrSys())) {
BaseResponse<PageSimpleResponse<ThrProductsResponse>> udiDlDeviceResponse = erpBasicClient.getErpProducts(filterThrProductsRequest);
if (udiDlDeviceResponse.getCode() == 20000) {
List<ThrProductsResponse> invmandocResponses = udiDlDeviceResponse.getData().getList();
//todo 耗材字典未确认数据库
// if (invmandocResponses != null) {
// for (ThrProductsResponse invmandocResponse : invmandocResponses) {
// UdiRelevanceEntity udiRelevanceEntity = udiRelevanceService.selectByThirdId(invmandocResponse.getCode(), filterErpGoodsRequest.getThirdSys());
// invmandocResponse.setThirdSys(thrProductsRequest.getThirdSys());
// if (udiRelevanceEntity != null) {
// invmandocResponse.setChecked(true);
// } else {
// invmandocResponse.setChecked(false);
// }
// }
// }
}
return udiDlDeviceResponse;
} else {
List<ThrProductsResponse> thrCorpEntities = thrProductsService.filterJoinThrProducts(filterThrProductsRequest);
//todo 耗材字典未确认数据库
// for (ThrProductsEntity thrProductsEntity : thrCorpEntities) {
// UdiRelevanceEntity udiRelevanceEntity = udiRelevanceService.selectByThirdId(thrProductsEntity.getCode(), thrProductsEntity.getThirdSysFk());
// if (udiRelevanceEntity != null) {
// thrProductsEntity.setChecked(true);
// } else {
// thrProductsEntity.setChecked(false);
// }
// }
PageInfo<ThrProductsResponse> pageInfo;
pageInfo = new PageInfo<>(thrCorpEntities);
PageSimpleResponse<ThrProductsResponse> pageSimpleResponse = new PageSimpleResponse<>();
@ -218,7 +195,11 @@ public class ThrProductsController {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "每次只能上传一个文件!");
}
ThreadUtil.execAsync(() -> {
thrProductsService.uploadPi(files, thirdSys);
try {
thrProductsService.uploadPi(files.get(0).getBytes(), files.get(0).getName(), thirdSys);
} catch (IOException e) {
e.printStackTrace();
}
});
return ResultVOUtils.success("正在导入中,稍后请刷新页面查看");
}
@ -254,7 +235,13 @@ public class ThrProductsController {
ThreadUtil.execAsync(() -> {
thrProductsService.downloadByRequest(filterThrProductsRequest);
try {
thrProductsService.downloadByRequest(filterThrProductsRequest);
} catch (Exception e) {
log.error("下载异常", e);
e.printStackTrace();
}
});
return ResultVOUtils.success("后台正在下载,请稍后刷新查看!");
}

@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.util.List;
/**
@ -44,7 +45,6 @@ public class ErpBasicClient {
BeanUtils.copyProperties(thrUnitMaintainFilterRequest, udiwmsUnitRequest);
udiwmsUnitRequest.setUnitId(thrUnitMaintainFilterRequest.getErpId());
ThrSystemEntity thrSystemEntity = basicThirdSysService.selectByThirdId(thrUnitMaintainFilterRequest.getThirdSysFk());
try {
String url = thrSystemEntity.getThridUrl() + "/udiwms/erp/getUnits";
String response = httpOkClient.uCloudPost(url, udiwmsUnitRequest, thrSystemEntity);
@ -158,16 +158,14 @@ public class ErpBasicClient {
* @param thirdSys
* @return
*/
public BaseResponse<PostThrProductsRequest> uploadPi(List<MultipartFile> files, String thirdSys) {
public BaseResponse<PostThrProductsRequest> uploadPi(byte[] bytes, String fileName, String thirdSys) {
ThrSystemEntity thrSystemEntity = basicThirdSysService.selectByThirdId(thirdSys);
String url = thrSystemEntity.getThridUrl() + "/udiwms/erp/pi/upload";
try {
MultipartBody.Builder builder = new MultipartBody.Builder()
.setType(MultipartBody.FORM);
for (MultipartFile file : files) {
builder.addFormDataPart("file", file.getOriginalFilename(), RequestBody.create(MediaType.parse("application/vnd.ms-excel"), file.getBytes()));
}
builder.addFormDataPart("file", fileName, RequestBody.create(MediaType.parse("application/vnd.ms-excel"), bytes));
builder.addFormDataPart("thirdSys", thirdSys);
MultipartBody multipartBody = builder.build();

@ -1,6 +1,7 @@
package com.glxp.api.req.thrsys;
import cn.hutool.core.util.StrUtil;
import com.glxp.api.util.page.ListPageRequest;
import com.glxp.api.res.thrsys.ThrCorpsResponse;
import lombok.Data;
@ -28,4 +29,18 @@ public class ThrUnitMaintainFilterRequest extends ListPageRequest {
private Boolean isDownThrSys;
private String lastUpdateTime;
List<ThrCorpsResponse> thrCorpEntities;
public String getThirdSys() {
if (StrUtil.isEmpty(thirdSys))
return thirdSysFk;
return thirdSys;
}
public String getThirdSysFk() {
if (StrUtil.isEmpty(thirdSysFk))
return thirdSys;
return thirdSysFk;
}
}

@ -31,6 +31,7 @@ import com.glxp.api.http.sync.SpGetHttpClient;
import com.glxp.api.idc.service.FileService;
import com.glxp.api.idc.service.IdcService;
import com.glxp.api.req.sync.SpsSyncDataRequest;
import com.glxp.api.res.inv.InnerOrderPrintResponse;
import com.glxp.api.res.sync.*;
import com.glxp.api.service.auth.*;
import com.glxp.api.service.basic.EntrustReceService;
@ -1614,7 +1615,13 @@ public class HeartService {
supManufacturerDao.replaceBatch(supManufacturerList);
}
if (CollectionUtil.isNotEmpty(supProductList)) {
supProductDao.replaceBatch(supProductList);
List<List<SupProductEntity>> splits = CustomUtil.splitList(supProductList, 100);
if (CollUtil.isNotEmpty(splits)) {
for (List<SupProductEntity> items : splits) {
supProductDao.replaceBatch(items);
}
}
}
if (CollUtil.isNotEmpty(syncFiles)) {
// fileService.download(syncFiles);

@ -6,6 +6,7 @@ import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.entity.thrsys.ThrCorpEntity;
import com.glxp.api.entity.thrsys.ThrSystemDetailEntity;
import com.glxp.api.req.thrsys.FilterThrCorpRequest;
import com.glxp.api.req.thrsys.ThrUnitMaintainFilterRequest;
import com.glxp.api.res.thrsys.ThrCorpsResponse;
import com.glxp.api.res.thrsys.ThrUnitMaintainResponse;
@ -42,4 +43,5 @@ public interface ThrCorpService extends IService<ThrCorpEntity> {
*/
BaseResponse downloadThrCorp(ThrSystemDetailEntity thrSystemDetailEntity);
public BaseResponse downloadByRequest(ThrUnitMaintainFilterRequest request);
}

@ -45,7 +45,7 @@ public class ThrCorpsDlService {
ThrCorpExportLogService thrCorpExportLogService;
@Resource
private ThrCorpImportDetailService thrCorpImportDetailService;
// @Value("${SPSYNC_IP}")
// @Value("${SPSYNC_IP}")
// private String spsSyncUrl;
@Resource
ErpBasicClient erpBasicClient;
@ -353,9 +353,9 @@ public class ThrCorpsDlService {
public List<List<String>> genExcelData(FilterThrCorpRequest filterThrOrderRequest) {
List<List<String>> excelData = new ArrayList<>();
List<ThrCorpEntity> thrCorpEntityList=new ArrayList<>();
List<ThrCorpEntity> thrCorpEntityList = new ArrayList<>();
List<ThrCorpsResponse> thrCorpsResponseList = thrCorpService.filterThrCorps(filterThrOrderRequest);
if(thrCorpsResponseList.size()>0){
if (thrCorpsResponseList.size() > 0) {
thrCorpEntityList = thrCorpsResponseList.stream().map(
item -> {
ThrCorpEntity thrCorpEntity = new ThrCorpEntity();
@ -419,12 +419,12 @@ public class ThrCorpsDlService {
exportData.addAll(thrCorpEntities);
} else {
//根据查询条件一键导出数据库往来单位
List<ThrCorpEntity> thrCorpEntityList=new ArrayList<>();
List<ThrCorpEntity> thrCorpEntityList = new ArrayList<>();
FilterThrCorpRequest filterThrCorpRequest = new FilterThrCorpRequest();
BeanUtils.copyProperties(thrCorpExportRequest, filterThrCorpRequest);
filterThrCorpRequest.setPage(null);
List<ThrCorpsResponse> thrCorpsResponseList = thrCorpService.filterThrCorps(filterThrCorpRequest);
if(thrCorpsResponseList.size()>0){
if (thrCorpsResponseList.size() > 0) {
thrCorpEntityList = thrCorpsResponseList.stream().map(
item -> {
ThrCorpEntity thrCorpEntity = new ThrCorpEntity();
@ -476,12 +476,12 @@ public class ThrCorpsDlService {
exportData.addAll(thrCorpEntities);
} else {
//根据查询条件一键导出数据库往来单位
List<ThrCorpEntity> thrCorpEntityList=new ArrayList<>();
List<ThrCorpEntity> thrCorpEntityList = new ArrayList<>();
FilterThrCorpRequest filterThrCorpRequest = new FilterThrCorpRequest();
BeanUtils.copyProperties(thrCorpExportRequest, filterThrCorpRequest);
filterThrCorpRequest.setPage(null);
List<ThrCorpsResponse> thrCorpsResponseList = thrCorpService.filterThrCorps(filterThrCorpRequest);
if(thrCorpsResponseList.size()>0){
if (thrCorpsResponseList.size() > 0) {
thrCorpEntityList = thrCorpsResponseList.stream().map(
item -> {
ThrCorpEntity thrCorpEntity = new ThrCorpEntity();

@ -49,7 +49,7 @@ public interface ThrProductsService extends IService<ThrProductsEntity> {
* @param thirdSys
* @return
*/
BaseResponse uploadPi(List<MultipartFile> files, String thirdSys);
BaseResponse uploadPi(byte[] bytes, String fileName, String thirdSys);
/**
*

@ -1,6 +1,7 @@
package com.glxp.api.service.thrsys.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.common.res.BaseResponse;
@ -47,11 +48,19 @@ public class ThrCorpServiceImpl extends ServiceImpl<ThrCorpDao, ThrCorpEntity> i
@Override
public boolean insertThrCorps(ThrCorpEntity thrCorpEntity) {
if (thrCorpEntity.getId() == null) {
thrCorpEntity.setId(IdUtil.getSnowflakeNextId());
}
return thrCorpDao.insertThrCorps(thrCorpEntity);
}
@Override
public boolean insertThrCorpss(List<ThrCorpEntity> thrCorpEntitys) {
for (ThrCorpEntity thrCorpEntity : thrCorpEntitys) {
if (thrCorpEntity.getId() == null) {
thrCorpEntity.setId(IdUtil.getSnowflakeNextId());
}
}
return thrCorpDao.insertThrCorpss(thrCorpEntitys);
}
@ -125,7 +134,51 @@ public class ThrCorpServiceImpl extends ServiceImpl<ThrCorpDao, ThrCorpEntity> i
BeanUtil.copyProperties(thrCorpsResponse, thrCorpEntity);
thrCorpEntity.setCreateTime(new Date());
thrCorpEntity.setUpdateTime(new Date());
thrCorpEntity.setId(null);
thrCorpEntity.setId(IdUtil.getSnowflakeNextId());
thrCorpEntity.setThirdSysFk(thrSystemDetailEntity.getThirdSysFk());
thrCorpDao.insertThrCorps(thrCorpEntity);
} else {
boolean isChange = verifyDataChange(thrCorpEntity, thrCorpsResponse);
if (isChange) {
thrCorpEntity.setUpdateTime(new Date());
thrCorpDao.updateThrCorps(thrCorpEntity);
}
}
});
if (list.size() >= limit) {
page++;
} else {
break;
}
} else {
return baseResponse;
}
}
return ResultVOUtils.success("下载完成");
}
@Override
public BaseResponse downloadByRequest(ThrUnitMaintainFilterRequest request) {
int page = 1;
int limit = 100;
while (true) {
request.setPage(page);
request.setLimit(limit);
request.setThirdSysFk(request.getThirdSys());
BaseResponse<PageSimpleResponse<ThrCorpsResponse>> baseResponse = erpBasicClient.getErpCrop(request);
if (baseResponse.getCode() == 20000) {
List<ThrCorpsResponse> list = baseResponse.getData().getList();
list.forEach(thrCorpsResponse -> {
ThrCorpEntity thrCorpEntity = thrCorpDao.selectByUnitIdAndThirdId(thrCorpsResponse.getUnitId(), request.getThirdSys());
if (null == thrCorpEntity) {
thrCorpEntity = new ThrCorpEntity();
BeanUtil.copyProperties(thrCorpsResponse, thrCorpEntity);
thrCorpEntity.setCreateTime(new Date());
thrCorpEntity.setUpdateTime(new Date());
thrCorpEntity.setThirdSysFk(request.getThirdSys());
thrCorpEntity.setId(IdUtil.getSnowflakeNextId());
thrCorpDao.insertThrCorps(thrCorpEntity);
} else {
boolean isChange = verifyDataChange(thrCorpEntity, thrCorpsResponse);

@ -130,8 +130,8 @@ public class ThrProductsServiceImpl extends ServiceImpl<ThrProductsDao, ThrProdu
}
@Override
public BaseResponse uploadPi(List<MultipartFile> files, String thirdSys) {
BaseResponse<PostThrProductsRequest> baseResponse = erpBasicClient.uploadPi(files, thirdSys);
public BaseResponse uploadPi(byte[] bytes, String fileName, String thirdSys) {
BaseResponse<PostThrProductsRequest> baseResponse = erpBasicClient.uploadPi(bytes, fileName, thirdSys);
if (baseResponse.getCode() == 20000) {
return ResultVOUtils.success("导入成功");
} else {
@ -153,10 +153,11 @@ public class ThrProductsServiceImpl extends ServiceImpl<ThrProductsDao, ThrProdu
thrProductsEntity.setThirdSysFk(postThrProductsRequest.getThirdSys());
thrProductsEntity.setCreateTime(DateUtil.date(new Date()));
thrProductsEntity.setUpdateTime(DateUtil.date(new Date()));
thrProductsEntity.setId(IdUtil.getSnowflakeNextId());
try {
mapper.insertThrProducts(thrProductsEntity);
} catch (Exception e) {
e.printStackTrace();
log.error("", e);
}
});
@ -187,6 +188,7 @@ public class ThrProductsServiceImpl extends ServiceImpl<ThrProductsDao, ThrProdu
thrProductsEntity.setCreateTime(new Date());
thrProductsEntity.setUpdateTime(new Date());
thrProductsEntity.setId(IdUtil.getSnowflakeNextId());
thrProductsEntity.setThirdSysFk(thrSystemDetailEntity.getThirdSysFk());
thrProductsDao.insertThrProducts(thrProductsEntity);
} else {
boolean isChange = verifyDataChange(thrProductsEntity, item);
@ -217,7 +219,9 @@ public class ThrProductsServiceImpl extends ServiceImpl<ThrProductsDao, ThrProdu
int limit = 200;
filterThrProductsRequest.setThirdSysFk(filterThrProductsRequest.getThirdSys());
filterThrProductsRequest.setLimit(limit);
log.error("开始下载-------");
while (true) {
log.error("下载分页-------" + page);
filterThrProductsRequest.setPage(page);
BaseResponse<PageSimpleResponse<ThrProductsResponse>> baseResponse = erpBasicClient.getErpProducts(filterThrProductsRequest);
if (baseResponse.getCode() == 20000) {
@ -230,6 +234,7 @@ public class ThrProductsServiceImpl extends ServiceImpl<ThrProductsDao, ThrProdu
thrProductsEntity.setCreateTime(new Date());
thrProductsEntity.setUpdateTime(new Date());
thrProductsEntity.setId(IdUtil.getSnowflakeNextId());
thrProductsEntity.setThirdSysFk(filterThrProductsRequest.getThirdSys());
thrProductsDao.insertThrProducts(thrProductsEntity);
} else {
boolean isChange = verifyDataChange(thrProductsEntity, item);
@ -249,6 +254,7 @@ public class ThrProductsServiceImpl extends ServiceImpl<ThrProductsDao, ThrProdu
return ResultVOUtils.error(500, "下载第三方系统产品信息异常");
}
}
log.error("下载结束-------");
return ResultVOUtils.success("下载成功");
}

@ -1,291 +0,0 @@
package com.glxp.api.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.glxp.api.constant.ThirdSysConstant;
import com.glxp.api.dao.thrsys.ThrSystemDetailDao;
import com.glxp.api.entity.thrsys.ThrSystemDetailEntity;
import com.glxp.api.res.thrsys.ThirdSysInterfaceExecuteVo;
import com.glxp.api.service.inout.IoOrderService;
import com.glxp.api.service.thrsys.IThrBusTypeOriginService;
import com.glxp.api.service.thrsys.ThrCorpService;
import com.glxp.api.service.thrsys.ThrInvWarehouseService;
import com.glxp.api.service.thrsys.ThrProductsService;
import com.glxp.api.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
/**
*
* 线
*/
@Slf4j
//@Component
public class ThirdSysInterfaceTask {
/**
* redis key
*/
private static final Map<String, Map<String, String>> keyMap = new ConcurrentHashMap<>(5);
private volatile ExecutorService executor;
/**
* 线
*
* @return
*/
private ExecutorService getExecutor() {
if (null == executor) {
synchronized (this) {
log.info("初始化第三方系统接口执行线程池");
executor = ThreadUtil.newExecutor(10, 100, Integer.MAX_VALUE);
}
}
return executor;
}
@Resource
private RedisUtil redisUtil;
@Resource
private ThrSystemDetailDao thrSystemDetailDao;
@Resource
private ThrInvWarehouseService thrInvWarehouseService;
@Resource
private ThrCorpService thrCorpService;
@Resource
private ThrProductsService thrProductsService;
@Resource
private IThrBusTypeOriginService thrBusTypeOriginService;
@Resource
private IoOrderService orderService;
@Scheduled(fixedRate = 1 * 1000, initialDelay = 60 * 1000)
public void scanInterface() {
log.info("开始扫描自动执行的第三方接口列表");
List<ThrSystemDetailEntity> list = thrSystemDetailDao.selectAutoExecuteList();
if (CollUtil.isNotEmpty(list)) {
log.info("本次查询到的接口列表数量:{}", list.size());
list.parallelStream().forEach(thrSystemDetailEntity -> {
switch (thrSystemDetailEntity.getKey()) {
case ThirdSysConstant.WAREHOUSE_QUERY_URL:
//下载第三方仓库信息
downloadThrInv(thrSystemDetailEntity);
break;
case ThirdSysConstant.CORP_URL:
//下载往来单位信息
downloadThrCorp(thrSystemDetailEntity);
break;
case ThirdSysConstant.PI_QUERY_URL:
//下载第三方产品信息
downloadThrPi(thrSystemDetailEntity);
break;
case ThirdSysConstant.BUS_TYPE_QUERY_URL:
//下载第三方单据类型
downloadThrBusType(thrSystemDetailEntity);
break;
case ThirdSysConstant.ORDER_SUBMIT_URL:
//提交单据
submitOrder(thrSystemDetailEntity);
break;
default:
//其他接口暂不处理
break;
}
});
} else {
log.info("未配置自动执行的第三方接口列表");
}
}
/**
*
*
* @param thrSystemDetailEntity
*/
private void submitOrder(ThrSystemDetailEntity thrSystemDetailEntity) {
//校验任务并更新redis数据执行标识
if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> {
log.info("开始提交单据到第三方系统");
try {
orderService.submitOrderToThrSys(thrSystemDetailEntity);
} catch (Exception e) {
log.error("提交单据到第三方系统异常", e);
} finally {
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("提交单据到第三方系统完成");
});
}
}
/**
*
*
* @param thrSystemDetailEntity
*/
private void downloadThrBusType(ThrSystemDetailEntity thrSystemDetailEntity) {
//校验任务并更新redis数据执行标识
if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> {
log.info("开始下载第三方单据类型");
try {
thrBusTypeOriginService.downloadThrBusType(thrSystemDetailEntity);
} catch (Exception e) {
log.error("下载第三方单据类型异常", e);
} finally {
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("第三方单据类型下载完成");
});
}
}
/**
*
*
* @param thrSystemDetailEntity
*/
private void downloadThrPi(ThrSystemDetailEntity thrSystemDetailEntity) {
//校验任务并更新redis数据执行标识
if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> {
log.info("开始下载第三方产品信息");
try {
thrProductsService.downloadThrPi(thrSystemDetailEntity);
} catch (Exception e) {
log.error("下载第三方产品信息异常", e);
} finally {
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("第三方产品信息下载完成");
});
}
}
/**
*
*
* @param thrSystemDetailEntity
*/
private void downloadThrCorp(ThrSystemDetailEntity thrSystemDetailEntity) {
//校验任务并更新redis数据执行标识
if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> {
log.info("开始下载第三方往来单位信息");
try {
thrCorpService.downloadThrCorp(thrSystemDetailEntity);
} catch (Exception e) {
log.error("下载第三方往来单位异常", e);
} finally {
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("第三方往来单位信息下载完成");
});
}
}
/**
*
*
* @param thrSystemDetailEntity
*/
private void downloadThrInv(ThrSystemDetailEntity thrSystemDetailEntity) {
//校验任务并更新redis数据执行标识
if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> {
log.info("开始下载第三方仓库信息");
try {
thrInvWarehouseService.downloadThrInv(thrSystemDetailEntity);
} catch (Exception e) {
log.error("下载第三方仓库信息异常", e);
} finally {
//保证任务标识一定会被修改回去
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("第三方仓库信息下载完成");
});
}
}
/**
*
*
* @param taskKey
*/
private void updateTask(String taskKey) {
ThirdSysInterfaceExecuteVo vo = getLastResult(taskKey);
vo.setFinished(true);
redisUtil.set(taskKey, vo);
}
/**
*
*
* @param thrSystemDetailEntity
* @return
*/
private boolean verifyTask(ThrSystemDetailEntity thrSystemDetailEntity) {
String taskKey = getTaskKey(thrSystemDetailEntity);
ThirdSysInterfaceExecuteVo vo = getLastResult(taskKey);
if (null != vo && !vo.isFinished()) {
log.info("有任务尚未执行完成当前任务key{}", taskKey);
return false;
}
long nextTime = DateUtil.offsetMonth(new Date(), thrSystemDetailEntity.getTime()).getTime();
vo = Optional.ofNullable(vo).orElse(new ThirdSysInterfaceExecuteVo());
vo.setKey(taskKey);
vo.setNextTime(nextTime);
vo.setFinished(false);
redisUtil.set(taskKey, vo);
return true;
}
/**
*
*
* @param taskKey
* @return
*/
private ThirdSysInterfaceExecuteVo getLastResult(String taskKey) {
String json = redisUtil.getJSON(taskKey);
return StrUtil.isBlank(json) ? null : JSONUtil.toBean(json, ThirdSysInterfaceExecuteVo.class);
}
/**
* redis Key
*
* @param thrSystemDetailEntity
* @return
*/
private String getTaskKey(ThrSystemDetailEntity thrSystemDetailEntity) {
String key = "";
Map<String, String> keys = keyMap.get(thrSystemDetailEntity.getThirdSysFk());
if (CollUtil.isEmpty(keys)) {
Map<String, String> map = new HashMap<>(1);
key = "thirdI:" + thrSystemDetailEntity.getThirdSysFk() + ":" + thrSystemDetailEntity.getKey();
map.put(thrSystemDetailEntity.getKey(), key);
keyMap.put(thrSystemDetailEntity.getThirdSysFk(), map);
} else {
key = keys.get(thrSystemDetailEntity.getKey());
if (StrUtil.isBlank(key)) {
key = "thirdI:" + thrSystemDetailEntity.getThirdSysFk() + ":" + thrSystemDetailEntity.getKey();
Map<String, String> map = new HashMap<>(1);
map.put(thrSystemDetailEntity.getKey(), key);
keyMap.put(thrSystemDetailEntity.getThirdSysFk(), map);
}
}
return key;
}
}

@ -26,12 +26,12 @@
</select>
<insert id="insertThrCorps" keyProperty="id" parameterType="com.glxp.api.entity.thrsys.ThrCorpEntity">
<insert id="insertThrCorps" parameterType="com.glxp.api.entity.thrsys.ThrCorpEntity">
replace
INTO thr_corp
(unitId, name, spell, addr, creditNo,
contact, mobile, thirdSysFk, updateTime, createUser, createTime, updateUser, remark)
values (#{unitId},
INTO thr_corp
(id, unitId, name, spell, addr, creditNo,
contact, mobile, thirdSysFk, updateTime, createUser, createTime, updateUser, remark)
values (#{id}, #{unitId},
#{name},
#{spell},
#{addr},
@ -48,13 +48,13 @@
<insert id="insertThrCorpss" keyProperty="id" parameterType="java.util.List">
replace INTO thr_corp
(unitId, name, spell, addr, creditNo,
contact, mobile, thirdSysFk, updateTime, createUser, createTime, updateUser, remark)
values
(id, unitId, name, spell, addr, creditNo,
contact, mobile, thirdSysFk, updateTime, createUser, createTime, updateUser, remark)
values
<foreach collection="thrCorpEntitys" item="item" index="index"
separator=",">
(#{item.unitId},
(#{item.id}, #{item.unitId},
#{item.name},
#{item.spell},
#{item.addr},
@ -134,8 +134,8 @@
<insert id="importThrCorp" parameterType="com.glxp.api.entity.thrsys.ThrCorpEntity">
replace
into thr_corp (unitId, spell, addr, creditNo, contact, mobile, thirdSysFk, name, updateTime, createUser,
createTime, updateUser, remark)
into thr_corp (unitId, spell, addr, creditNo, contact, mobile, thirdSysFk, name, updateTime, createUser,
createTime, updateUser, remark)
values (#{unitId},
#{spell},
#{addr},
@ -183,7 +183,7 @@
resultType="com.glxp.api.entity.thrsys.ThrSystemDetailEntity">
select basic_third_sys_detail.*, basic_third_sys.thridUrl
FROM basic_third_sys_detail
inner join basic_third_sys on basic_third_sys_detail.thirdSysFk = basic_third_sys.thirdId
inner join basic_third_sys on basic_third_sys_detail.thirdSysFk = basic_third_sys.thirdId
WHERE basic_third_sys_detail.key = #{key}
and basic_third_sys_detail.thirdSysFk = #{thirdSys}
and basic_third_sys.enabled = 1

Loading…
Cancel
Save