Merge remote-tracking branch 'origin/master'
commit
45b2296ded
@ -0,0 +1,48 @@
|
||||
package com.glxp.api.controller.sync;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.glxp.api.annotation.AuthRuleAnnotation;
|
||||
import com.glxp.api.common.res.BaseResponse;
|
||||
import com.glxp.api.constant.ConstantStatus;
|
||||
import com.glxp.api.entity.sync.BasicExportStatusEntity;
|
||||
import com.glxp.api.req.sync.SpsSyncDataRequest;
|
||||
import com.glxp.api.res.sync.SpsSyncOrderResponse;
|
||||
import com.glxp.api.service.sync.BasicExportService;
|
||||
import com.glxp.api.service.sync.SpsSyncDownloadService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
public class SpsSyncDownloadController {
|
||||
|
||||
@Resource
|
||||
SpsSyncDownloadService spsSyncDownloadService;
|
||||
@Resource
|
||||
BasicExportService basicExportService;
|
||||
|
||||
@AuthRuleAnnotation("")
|
||||
@GetMapping("sps/sync/order")
|
||||
public BaseResponse findOrder(SpsSyncDataRequest spsSyncDataRequest) {
|
||||
BaseResponse<SpsSyncOrderResponse> baseResponse = spsSyncDownloadService.findOrder(spsSyncDataRequest);
|
||||
BasicExportStatusEntity basicExportStatusEntity = basicExportService.findByData(ConstantStatus.SYNC_SCAN_ORDER, 0);
|
||||
String logs = "";
|
||||
if (basicExportStatusEntity != null) {
|
||||
logs = logs + "单据:" + baseResponse.getData().getOrderEntities().size() + "条\n";
|
||||
if (CollUtil.isNotEmpty(baseResponse.getData().getOrderDetailBizEntities()))
|
||||
logs = logs + "单据详情:" + baseResponse.getData().getOrderDetailBizEntities().size() + "条\n";
|
||||
if (CollUtil.isNotEmpty(baseResponse.getData().getCodeEntities()))
|
||||
logs = logs + "单据条码信息:" + baseResponse.getData().getCodeEntities().size() + "条\n";
|
||||
|
||||
basicExportStatusEntity.setRemark(logs);
|
||||
basicExportService.updateExportStatus(basicExportStatusEntity);
|
||||
SpsSyncOrderResponse spsSyncOrderResponse = baseResponse.getData();
|
||||
spsSyncOrderResponse.setTaskId(basicExportStatusEntity.getId());
|
||||
baseResponse.setData(spsSyncOrderResponse);
|
||||
}
|
||||
return baseResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.glxp.api.res.sync;
|
||||
|
||||
import com.glxp.api.entity.inout.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SpsSyncOrderResponse {
|
||||
|
||||
//同步任务ID
|
||||
private String taskId;
|
||||
List<IoOrderEntity> orderEntities;
|
||||
List<IoCodeEntity> codeEntities;
|
||||
List<IoOrderDetailBizEntity> orderDetailBizEntities;
|
||||
List<IoOrderDetailCodeEntity> orderDetailCodeEntities;
|
||||
List<IoOrderDetailResultEntity> orderDetailResultEntities;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,204 @@
|
||||
package com.glxp.api.service.sync;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.glxp.api.common.res.BaseResponse;
|
||||
import com.glxp.api.common.util.ResultVOUtils;
|
||||
import com.glxp.api.constant.BasicProcessStatus;
|
||||
import com.glxp.api.constant.ConstantStatus;
|
||||
import com.glxp.api.entity.inout.*;
|
||||
import com.glxp.api.entity.sync.BasicExportStatusEntity;
|
||||
import com.glxp.api.entity.sync.BasicExportStatusTimeEntity;
|
||||
import com.glxp.api.entity.sync.SyncDataBustypeEntity;
|
||||
import com.glxp.api.req.inout.FilterOrderRequest;
|
||||
import com.glxp.api.req.sync.SpsSyncDataRequest;
|
||||
import com.glxp.api.res.sync.SpsSyncOrderResponse;
|
||||
import com.glxp.api.res.system.SyncDataSetResponse;
|
||||
import com.glxp.api.service.inout.*;
|
||||
import com.glxp.api.util.CustomUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SpsSyncDownloadService {
|
||||
|
||||
|
||||
//已完成扫码单据
|
||||
@Resource
|
||||
IoOrderService orderService;
|
||||
@Resource
|
||||
IoCodeService codesService;
|
||||
@Resource
|
||||
SyncDataSetService syncDataSetService;
|
||||
@Resource
|
||||
IoOrderDetailBizService orderDetailBizService;
|
||||
@Resource
|
||||
IoOrderDetailCodeService orderDetailCodeService;
|
||||
@Resource
|
||||
IoOrderDetailResultService orderDetailResultService;
|
||||
@Resource
|
||||
BasicExportService basicExportService;
|
||||
@Resource
|
||||
BasicExportTimeService basicExportTimeService;
|
||||
|
||||
public void syncOrderUpdateTime() {
|
||||
|
||||
log.info("创建单据同步任务");
|
||||
//自动创建要求被下载已完成单据任务
|
||||
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_SCAN_ORDER, 0);
|
||||
if (basicExportStatusEntity1 == null) {
|
||||
BaseResponse<SpsSyncOrderResponse> baseResponse = findOrder(getRequest(ConstantStatus.SYNC_SCAN_ORDER));
|
||||
SpsSyncOrderResponse syncOrderResponse = baseResponse.getData();
|
||||
if (CollUtil.isNotEmpty(syncOrderResponse.getOrderEntities())) {
|
||||
BasicExportStatusEntity orderStatusEntity = new BasicExportStatusEntity();
|
||||
orderStatusEntity.setId(CustomUtil.getId());
|
||||
orderStatusEntity.setIdDatas(ConstantStatus.SYNC_SCAN_ORDER);
|
||||
orderStatusEntity.setType(BasicProcessStatus.NEW_ALL_ORDER);
|
||||
orderStatusEntity.setUpdateTime(new Date());
|
||||
orderStatusEntity.setStatus(0);
|
||||
orderStatusEntity.setStartTime(new Date());
|
||||
orderStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
||||
basicExportService.insertExportStatus(orderStatusEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BaseResponse findOrder(SpsSyncDataRequest spsSyncDataRequest) {
|
||||
SpsSyncOrderResponse syncOrderResponse = new SpsSyncOrderResponse();
|
||||
//查询数据同步设置
|
||||
SyncDataSetResponse syncDataSetEntity = syncDataSetService.selectSet();
|
||||
List<IoOrderEntity> orderEntities = new ArrayList<>();
|
||||
|
||||
|
||||
//待校验
|
||||
if (syncDataSetEntity.isOrderUnCheck()) {
|
||||
FilterOrderRequest orderFilterRequest = new FilterOrderRequest();
|
||||
BeanUtils.copyProperties(spsSyncDataRequest, orderFilterRequest);
|
||||
|
||||
if (CollUtil.isNotEmpty(syncDataSetEntity.getBusTypes())) {
|
||||
for (SyncDataBustypeEntity syncDataBustypeEntity : syncDataSetEntity.getBusTypes()) {
|
||||
List<String> filterList = new ArrayList<>();
|
||||
filterList.add(syncDataBustypeEntity.getAction());
|
||||
orderFilterRequest.setActions(filterList);
|
||||
orderFilterRequest.setStatus(ConstantStatus.ORDER_STATUS_CHECK);
|
||||
List<IoOrderEntity> temps = orderService.filterOrderList(orderFilterRequest);
|
||||
if (CollUtil.isNotEmpty(temps)) {
|
||||
orderEntities.addAll(temps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//待核对
|
||||
if (syncDataSetEntity.isOrderUnCheck()) {
|
||||
FilterOrderRequest orderFilterRequest = new FilterOrderRequest();
|
||||
BeanUtils.copyProperties(spsSyncDataRequest, orderFilterRequest);
|
||||
|
||||
if (CollUtil.isNotEmpty(syncDataSetEntity.getBusTypes())) {
|
||||
for (SyncDataBustypeEntity syncDataBustypeEntity : syncDataSetEntity.getBusTypes()) {
|
||||
List<String> filterList = new ArrayList<>();
|
||||
filterList.add(syncDataBustypeEntity.getAction());
|
||||
orderFilterRequest.setActions(filterList);
|
||||
orderFilterRequest.setStatus(ConstantStatus.ORDER_STATUS_CHECK_SUCCESS);
|
||||
List<IoOrderEntity> temps = orderService.filterOrderList(orderFilterRequest);
|
||||
if (CollUtil.isNotEmpty(temps)) {
|
||||
orderEntities.addAll(temps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//待审核
|
||||
if (syncDataSetEntity.isOrderUnReceive()) {
|
||||
FilterOrderRequest orderFilterRequest = new FilterOrderRequest();
|
||||
BeanUtils.copyProperties(spsSyncDataRequest, orderFilterRequest);
|
||||
|
||||
if (CollUtil.isNotEmpty(syncDataSetEntity.getBusTypes())) {
|
||||
for (SyncDataBustypeEntity syncDataBustypeEntity : syncDataSetEntity.getBusTypes()) {
|
||||
List<String> filterList = new ArrayList<>();
|
||||
filterList.add(syncDataBustypeEntity.getAction());
|
||||
orderFilterRequest.setActions(filterList);
|
||||
orderFilterRequest.setStatus(ConstantStatus.ORDER_STATUS_CHECK_REW);
|
||||
List<IoOrderEntity> temps = orderService.filterOrderList(orderFilterRequest);
|
||||
if (CollUtil.isNotEmpty(temps)) {
|
||||
orderEntities.addAll(temps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//已完成
|
||||
if (syncDataSetEntity.isOrderScanFinish()) {
|
||||
FilterOrderRequest orderFilterRequest = new FilterOrderRequest();
|
||||
BeanUtils.copyProperties(spsSyncDataRequest, orderFilterRequest);
|
||||
|
||||
if (CollUtil.isNotEmpty(syncDataSetEntity.getBusTypes())) {
|
||||
for (SyncDataBustypeEntity syncDataBustypeEntity : syncDataSetEntity.getBusTypes()) {
|
||||
List<String> filterList = new ArrayList<>();
|
||||
filterList.add(syncDataBustypeEntity.getAction());
|
||||
orderFilterRequest.setActions(filterList);
|
||||
orderFilterRequest.setStatus(ConstantStatus.ORDER_STATUS_AUDITED);
|
||||
List<IoOrderEntity> temps = orderService.filterOrderList(orderFilterRequest);
|
||||
if (CollUtil.isNotEmpty(temps)) {
|
||||
orderEntities.addAll(temps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
syncOrderResponse.setOrderEntities(orderEntities);
|
||||
List<IoCodeEntity> codeEntities = new ArrayList<>();
|
||||
List<IoOrderDetailBizEntity> orderDetailBizEntities = new ArrayList<>();
|
||||
List<IoOrderDetailCodeEntity> orderDetailCodeEntities = new ArrayList<>();
|
||||
List<IoOrderDetailResultEntity> orderDetailResultEntities = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(orderEntities)) {
|
||||
for (IoOrderEntity orderEntity : orderEntities) {
|
||||
|
||||
List<IoCodeEntity> codes = codesService.findByOrderId(orderEntity.getBillNo());
|
||||
if (CollUtil.isNotEmpty(codes)) {
|
||||
codeEntities.addAll(codes);
|
||||
}
|
||||
|
||||
List<IoOrderDetailBizEntity> bizEntities = orderDetailBizService.findByOrderId(orderEntity.getBillNo());
|
||||
if (CollUtil.isNotEmpty(bizEntities)) {
|
||||
orderDetailBizEntities.addAll(bizEntities);
|
||||
}
|
||||
|
||||
|
||||
List<IoOrderDetailCodeEntity> detailCodeEntities = orderDetailCodeService.findByOrderId(orderEntity.getBillNo());
|
||||
if (CollUtil.isNotEmpty(detailCodeEntities)) {
|
||||
orderDetailCodeEntities.addAll(detailCodeEntities);
|
||||
}
|
||||
|
||||
|
||||
List<IoOrderDetailResultEntity> detailResultEntities = orderDetailResultService.findByOrderId(orderEntity.getBillNo());
|
||||
if (CollUtil.isNotEmpty(detailResultEntities)) {
|
||||
orderDetailResultEntities.addAll(detailResultEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
syncOrderResponse.setOrderDetailBizEntities(orderDetailBizEntities);
|
||||
syncOrderResponse.setOrderDetailCodeEntities(orderDetailCodeEntities);
|
||||
syncOrderResponse.setOrderDetailResultEntities(orderDetailResultEntities);
|
||||
return ResultVOUtils.success(syncOrderResponse);
|
||||
}
|
||||
|
||||
public SpsSyncDataRequest getRequest(String type) {
|
||||
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
|
||||
spsSyncDataRequest.setPage(1);
|
||||
spsSyncDataRequest.setLimit(1);
|
||||
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByType(type);
|
||||
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
|
||||
return spsSyncDataRequest;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.glxp.api.task;
|
||||
|
||||
import com.glxp.api.dao.schedule.ScheduledDao;
|
||||
import com.glxp.api.entity.system.ScheduledEntity;
|
||||
import com.glxp.api.req.system.ScheduledRequest;
|
||||
import com.glxp.api.res.system.SyncDataSetResponse;
|
||||
import com.glxp.api.service.basic.BasicBackUpdateProductService;
|
||||
import com.glxp.api.service.sync.SpsSyncDownloadService;
|
||||
import com.glxp.api.service.sync.SyncDataSetService;
|
||||
import com.glxp.api.util.RedisUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
||||
@Component
|
||||
@EnableScheduling
|
||||
public class AsyncHeartTask implements SchedulingConfigurer {
|
||||
|
||||
final Logger logger = LoggerFactory.getLogger(AsyncHeartTask.class);
|
||||
@Resource
|
||||
protected ScheduledDao scheduledDao;
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
@Resource
|
||||
private SyncDataSetService syncDataSetService;
|
||||
@Resource
|
||||
SpsSyncDownloadService spsSyncDownloadService;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
||||
|
||||
scheduledTaskRegistrar.addTriggerTask(() -> process(),
|
||||
triggerContext -> {
|
||||
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
||||
scheduledRequest.setCronName("heartTask");
|
||||
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
||||
String cron = scheduledEntity.getCron();
|
||||
if (cron.isEmpty()) {
|
||||
logger.error("cron is null");
|
||||
}
|
||||
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void process() {
|
||||
|
||||
SyncDataSetResponse syncDataSetEntity = syncDataSetService.selectSet();
|
||||
if (syncDataSetEntity.isDownstreamEnable()) {
|
||||
|
||||
//定时同步单据最近更新数据至任务表,等待下载
|
||||
if (syncDataSetEntity.getOrderSyncTime() != null) {
|
||||
long timeInterval = syncDataSetEntity.getOrderSyncTime() * 60 * 1000;
|
||||
long curTime = System.currentTimeMillis();
|
||||
Long lastTime = (Long) redisUtil.get("SPS_ORDER_SYNC_GEN_DATA");
|
||||
if (lastTime == null) {
|
||||
lastTime = System.currentTimeMillis();
|
||||
redisUtil.set("SPS_ORDER_SYNC_GEN_DATA", lastTime);
|
||||
}
|
||||
if (curTime - lastTime > timeInterval) {
|
||||
spsSyncDownloadService.syncOrderUpdateTime();
|
||||
redisUtil.set("SPS_ORDER_SYNC_GEN_DATA", curTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue