You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
746 lines
41 KiB
Java
746 lines
41 KiB
Java
package com.glxp.api.service.sync;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import com.glxp.api.dao.basic.ProductInfoDao;
|
|
import com.glxp.api.dao.basic.UdiCompanyDao;
|
|
import com.glxp.api.dao.inout.*;
|
|
import com.glxp.api.entity.basic.ProductInfoEntity;
|
|
import com.glxp.api.entity.basic.UdiCompanyEntity;
|
|
import com.glxp.api.entity.inout.*;
|
|
import com.glxp.api.res.sync.*;
|
|
import com.glxp.api.service.inout.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.ibatis.session.ExecutorType;
|
|
import org.apache.ibatis.session.SqlSession;
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
import org.apache.ibatis.session.TransactionIsolationLevel;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
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.sync.BasicDownloadStatusEntity;
|
|
import com.glxp.api.entity.sync.BasicExportStatusEntity;
|
|
import com.glxp.api.entity.sync.BasicExportStatusTimeEntity;
|
|
import com.glxp.api.http.sync.SpGetHttpClient;
|
|
import com.glxp.api.req.sync.SpsSyncDataRequest;
|
|
import com.glxp.api.util.CustomUtil;
|
|
import com.glxp.api.util.DateUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
@Slf4j
|
|
@Service
|
|
public class HeartService {
|
|
@Resource
|
|
BasicExportService basicExportService;
|
|
@Resource
|
|
UpBasicService upBasicService;
|
|
@Resource
|
|
SpGetHttpClient spGetHttp;
|
|
@Resource
|
|
BasicExportTimeService basicExportTimeService;
|
|
@Resource
|
|
BasicDownloadService basicDownloadService;
|
|
@Resource
|
|
SqlSessionFactory sqlSessionFactory;
|
|
@Resource
|
|
IoOrderService orderService;
|
|
@Resource
|
|
IoAddInoutService addInoutService;
|
|
@Resource
|
|
IoCheckInoutService ioCheckInoutService;
|
|
@Resource
|
|
private UpThrDataService upThrDataService;
|
|
|
|
@Resource
|
|
IoCodeTempService codeTempService;
|
|
@Resource
|
|
IoOrderDetailBizService orderDetailBizService;
|
|
@Resource
|
|
IoOrderDetailCodeService orderDetailCodeService;
|
|
@Resource
|
|
IoOrderDetailResultService orderDetailResultService;
|
|
@Resource
|
|
IoOrderInvoiceService orderInvoiceService;
|
|
|
|
//上传最近更新扫码单据
|
|
public BaseResponse uploadAllOrder(String syncTime) {
|
|
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
|
|
if (syncTime == null) {
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_SCAN_ORDER);
|
|
if (basicExportStatusTimeEntity == null) {
|
|
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
|
|
}
|
|
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
|
|
} else {
|
|
spsSyncDataRequest.setLastUpdateTime(syncTime);
|
|
}
|
|
SpsSyncOrderResponse spsSyncOrderResponse = upBasicService.upAllOrder(spsSyncDataRequest);
|
|
if (CollUtil.isEmpty(spsSyncOrderResponse.getOrderEntities())
|
|
&& CollUtil.isEmpty(spsSyncOrderResponse.getCodeEntities())) {
|
|
//无数据不记录日志
|
|
return ResultVOUtils.success("无数据");
|
|
}
|
|
|
|
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_SCAN_ORDER, 0);
|
|
if (basicExportStatusEntity1 == null) {
|
|
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.setStartTime(new Date());
|
|
orderStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
|
|
orderStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
|
basicExportService.insertExportStatus(orderStatusEntity);
|
|
basicExportStatusEntity1 = orderStatusEntity;
|
|
}
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
|
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_SCAN_ORDER);
|
|
spsSyncOrderResponse.setTaskId(basicExportStatusEntity1.getId());
|
|
BaseResponse<String> baseResponse1 = spGetHttp.postAllOrder(spsSyncOrderResponse);
|
|
if (baseResponse1.getCode() == 20000) {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
} else {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
|
|
}
|
|
basicExportStatusEntity1.setEndTime(new Date());
|
|
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
|
|
|
|
//拼接日志
|
|
String logs = "";
|
|
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getOrderEntities()))
|
|
logs = logs + "单据:" + spsSyncOrderResponse.getOrderEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getOrderDetailBizEntities()))
|
|
logs = logs + "单据详情:" + spsSyncOrderResponse.getOrderDetailBizEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getCodeEntities()))
|
|
logs = logs + "单据条码信息:" + spsSyncOrderResponse.getCodeEntities().size() + "条\n";
|
|
basicExportStatusEntity1.setRemark(logs);
|
|
basicExportStatusEntity1.setUpdateTime(new Date());
|
|
basicExportService.updateExportStatus(basicExportStatusEntity1);
|
|
return ResultVOUtils.success();
|
|
}
|
|
|
|
//上传最近更新业务单据
|
|
public BaseResponse uploadAllBusOrder(String syncTime) {
|
|
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
|
|
if (syncTime == null) {
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_BUS_ORDER);
|
|
if (basicExportStatusTimeEntity == null) {
|
|
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
|
|
}
|
|
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
|
|
} else {
|
|
spsSyncDataRequest.setLastUpdateTime(syncTime);
|
|
}
|
|
SpsSyncBusOrderResponse spsSyncOrderResponse = upBasicService.upAllBusOrder(spsSyncDataRequest);
|
|
if (CollUtil.isEmpty(spsSyncOrderResponse.getPurOrderEntities())
|
|
&& CollUtil.isEmpty(spsSyncOrderResponse.getPurOrderDetailEntities())) {
|
|
//无数据不记录日志
|
|
return ResultVOUtils.success("无数据");
|
|
}
|
|
|
|
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_BUS_ORDER, 0);
|
|
if (basicExportStatusEntity1 == null) {
|
|
BasicExportStatusEntity orderStatusEntity = new BasicExportStatusEntity();
|
|
orderStatusEntity.setId(CustomUtil.getId());
|
|
orderStatusEntity.setIdDatas(ConstantStatus.SYNC_BUS_ORDER);
|
|
orderStatusEntity.setType(BasicProcessStatus.ALL_BUS_ORDER);
|
|
orderStatusEntity.setUpdateTime(new Date());
|
|
orderStatusEntity.setStartTime(new Date());
|
|
orderStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
|
|
orderStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
|
basicExportService.insertExportStatus(orderStatusEntity);
|
|
basicExportStatusEntity1 = orderStatusEntity;
|
|
}
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
|
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_BUS_ORDER);
|
|
spsSyncOrderResponse.setTaskId(basicExportStatusEntity1.getId());
|
|
BaseResponse<String> baseResponse1 = spGetHttp.postAllBusOrder(spsSyncOrderResponse);
|
|
if (baseResponse1.getCode() == 20000) {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
} else {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
|
|
}
|
|
basicExportStatusEntity1.setEndTime(new Date());
|
|
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
|
|
|
|
//拼接日志
|
|
String logs = "";
|
|
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getPurOrderEntities()))
|
|
logs = logs + "采购订单单据:" + spsSyncOrderResponse.getPurOrderEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getPurOrderDetailEntities()))
|
|
logs = logs + "采购订单详情:" + spsSyncOrderResponse.getPurOrderDetailEntities().size() + "条\n";
|
|
basicExportStatusEntity1.setRemark(logs);
|
|
basicExportStatusEntity1.setUpdateTime(new Date());
|
|
basicExportService.updateExportStatus(basicExportStatusEntity1);
|
|
return ResultVOUtils.success();
|
|
}
|
|
|
|
//上传最近更新单据类型
|
|
public BaseResponse uploadAllBus(String syncTime) {
|
|
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
|
|
if (syncTime == null) {
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_BUS_TYPE);
|
|
if (basicExportStatusTimeEntity == null) {
|
|
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
|
|
}
|
|
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
|
|
} else {
|
|
spsSyncDataRequest.setLastUpdateTime(syncTime);
|
|
}
|
|
SpsSyncBusResponse spsSyncBusResponse = upBasicService.upAllBus(spsSyncDataRequest);
|
|
if (CollUtil.isEmpty(spsSyncBusResponse.getBussinessTypeEntities())
|
|
&& CollUtil.isEmpty(spsSyncBusResponse.getBusTypeChangeEntities())
|
|
&& CollUtil.isEmpty(spsSyncBusResponse.getThrBusTypeOriginEntities())
|
|
) {
|
|
return ResultVOUtils.success("无数据");
|
|
}
|
|
BasicExportStatusEntity basicExportStatusEntity2 = basicExportService.findByData(ConstantStatus.SYNC_BUS_TYPE, 0);
|
|
if (basicExportStatusEntity2 == null) {
|
|
BasicExportStatusEntity busTypetatusEntity = new BasicExportStatusEntity();
|
|
busTypetatusEntity.setId(CustomUtil.getId());
|
|
busTypetatusEntity.setIdDatas(ConstantStatus.SYNC_BUS_TYPE);
|
|
busTypetatusEntity.setType(BasicProcessStatus.NEW_ALL_BUS);
|
|
busTypetatusEntity.setUpdateTime(new Date());
|
|
busTypetatusEntity.setStartTime(new Date());
|
|
busTypetatusEntity.setStatus(0);
|
|
busTypetatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
|
basicExportService.insertExportStatus(busTypetatusEntity);
|
|
basicExportStatusEntity2 = busTypetatusEntity;
|
|
}
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
|
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_BUS_TYPE);
|
|
spsSyncBusResponse.setTaskId(basicExportStatusEntity2.getId());
|
|
BaseResponse<String> baseResponse2 = spGetHttp.postAllBusType(spsSyncBusResponse);
|
|
if (baseResponse2.getCode() == 20000) {
|
|
basicExportStatusEntity2.setStatus(1);
|
|
} else {
|
|
basicExportStatusEntity2.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
|
|
}
|
|
basicExportStatusEntity2.setEndTime(new Date());
|
|
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
|
|
//拼接日志
|
|
String logs = "";
|
|
if (CollUtil.isNotEmpty(spsSyncBusResponse.getBussinessTypeEntities()))
|
|
logs = logs + "扫码单据类型:" + spsSyncBusResponse.getBussinessTypeEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(spsSyncBusResponse.getBusTypeChangeEntities()))
|
|
logs = logs + "业务单据类型:" + spsSyncBusResponse.getBusTypeChangeEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(spsSyncBusResponse.getThrBusTypeOriginEntities()))
|
|
logs = logs + "第三方单据类型:" + spsSyncBusResponse.getThrBusTypeOriginEntities().size() + "条\n";
|
|
basicExportStatusEntity2.setRemark(logs);
|
|
basicExportStatusEntity2.setUpdateTime(new Date());
|
|
basicExportService.updateExportStatus(basicExportStatusEntity2);
|
|
return ResultVOUtils.success();
|
|
}
|
|
|
|
//上传用户信息
|
|
public BaseResponse uploadAllUserData(String syncTime) {
|
|
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
|
|
if (syncTime == null) {
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_BASIC_DATA);
|
|
if (basicExportStatusTimeEntity == null) {
|
|
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
|
|
}
|
|
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
|
|
|
|
} else {
|
|
spsSyncDataRequest.setLastUpdateTime(syncTime);
|
|
}
|
|
|
|
SpsSyncDataResponse syncDataResponse = upBasicService.uploadAllUserData(spsSyncDataRequest);
|
|
if (CollUtil.isEmpty(syncDataResponse.getInvWarehouseEntities())
|
|
&& CollUtil.isEmpty(syncDataResponse.getAuthAdminList())
|
|
&& CollUtil.isEmpty(syncDataResponse.getDeptEntityList())
|
|
&& CollUtil.isEmpty(syncDataResponse.getWarehouseBussinessTypeEntities())
|
|
&& CollUtil.isEmpty(syncDataResponse.getWarehouseUserEntities())
|
|
) {
|
|
//数据不记录日志
|
|
return ResultVOUtils.success("无数据");
|
|
}
|
|
|
|
BasicExportStatusEntity basicExportStatusEntity3 = basicExportService.findByData(ConstantStatus.SYNC_BASIC_DATA, 0);
|
|
if (basicExportStatusEntity3 == null) {
|
|
BasicExportStatusEntity basicExportStatusEntity = new BasicExportStatusEntity();
|
|
basicExportStatusEntity.setId(CustomUtil.getId());
|
|
basicExportStatusEntity.setIdDatas(ConstantStatus.SYNC_BASIC_DATA);
|
|
basicExportStatusEntity.setType(BasicProcessStatus.NEW_ALL_DATA);
|
|
basicExportStatusEntity.setUpdateTime(new Date());
|
|
basicExportStatusEntity.setStartTime(new Date());
|
|
basicExportStatusEntity.setStatus(0);
|
|
basicExportStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
|
basicExportService.insertExportStatus(basicExportStatusEntity);
|
|
basicExportStatusEntity3 = basicExportStatusEntity;
|
|
}
|
|
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
|
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_BASIC_DATA);
|
|
syncDataResponse.setTaskId(basicExportStatusEntity3.getId());
|
|
BaseResponse<String> baseResponse = spGetHttp.postAllUser(syncDataResponse);
|
|
if (baseResponse.getCode() == 20000) {
|
|
basicExportStatusEntity3.setStatus(1);
|
|
} else {
|
|
basicExportStatusEntity3.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
|
|
}
|
|
basicExportStatusEntity3.setEndTime(new Date());
|
|
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
|
|
String logs = "";
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getInvWarehouseEntities()))
|
|
logs = logs + "仓库字典:" + syncDataResponse.getInvWarehouseEntities().size() + "条\n";
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getWarehouseUserEntities())) {
|
|
logs = logs + "仓库用户信息:" + syncDataResponse.getWarehouseUserEntities().size() + "条\n";
|
|
}
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getWarehouseBussinessTypeEntities())) {
|
|
logs = logs + "仓库单据类型:" + syncDataResponse.getWarehouseBussinessTypeEntities().size() + "条\n";
|
|
}
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getAuthAdminList()))
|
|
logs = logs + "系统用户信息:" + syncDataResponse.getAuthAdminList().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getInvBusUserEntities()))
|
|
logs = logs + "用户关联单据类型信息:" + syncDataResponse.getInvBusUserEntities().size() + "条\n";
|
|
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getDeptEntityList()))
|
|
logs = logs + "部门信息:" + syncDataResponse.getDeptEntityList().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getDeptUserEntities()))
|
|
logs = logs + "部门用户信息:" + syncDataResponse.getDeptUserEntities().size() + "条\n";
|
|
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getInvSpaces()))
|
|
logs = logs + "货位信息:" + syncDataResponse.getInvSpaces().size() + "条\n";
|
|
|
|
basicExportStatusEntity3.setRemark(logs);
|
|
basicExportStatusEntity3.setUpdateTime(new Date());
|
|
basicExportService.updateExportStatus(basicExportStatusEntity3);
|
|
return ResultVOUtils.success();
|
|
}
|
|
|
|
// 上传系统参数设置
|
|
public BaseResponse uploadAllConfig(String syncTime) {
|
|
return null;
|
|
}
|
|
|
|
//
|
|
// //上传最近更新第三方基础数据
|
|
// public BaseResponse uploadThirdData(String syncTime) {
|
|
//
|
|
// }
|
|
|
|
|
|
//下载最近更新扫码单据--上级服务
|
|
public void dlAllOrder() {
|
|
BaseResponse<List<BasicExportStatusEntity>> baseResponse = spGetHttp.getBasicStatus(BasicProcessStatus.NEW_ALL_ORDER + "");
|
|
List<BasicExportStatusEntity> pageSimpleResponse = baseResponse != null ? baseResponse.getData() : new ArrayList<>();
|
|
if (pageSimpleResponse != null) {
|
|
List<BasicExportStatusEntity> basicExportStatusEntities = pageSimpleResponse;
|
|
if (basicExportStatusEntities != null && basicExportStatusEntities.size() > 0) {
|
|
for (BasicExportStatusEntity basicExportStatusEntity : basicExportStatusEntities) {
|
|
String datas = spGetHttp.getBasicData(basicExportStatusEntity.getId(), BasicProcessStatus.NEW_ALL_ORDER);
|
|
BaseResponse<String> response = JSONObject.parseObject(datas, new TypeReference<BaseResponse<String>>() {
|
|
});
|
|
if (response.getCode() == 20000 && response.getData() != null) {
|
|
|
|
SpsSyncOrderResponse syncDataResponse = JSONObject.parseObject(response.getData(), new TypeReference<SpsSyncOrderResponse>() {
|
|
});
|
|
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
|
|
basicDownloadStatusEntity.setId(CustomUtil.getId());
|
|
basicDownloadStatusEntity.setTaskId(syncDataResponse.getTaskId());
|
|
basicDownloadStatusEntity.setStartTime(new Date());
|
|
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_SCAN_ORDER);
|
|
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT); //下载中
|
|
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_ORDER);
|
|
basicDownloadStatusEntity.setScheduleType(1);
|
|
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
|
|
StringBuffer remark = new StringBuffer();
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities())) {
|
|
try {
|
|
List<IoOrderEntity> orderEntities = syncDataResponse.getOrderEntities();
|
|
for (IoOrderEntity orderEntity : orderEntities) {
|
|
orderEntity.setUpdateTime(null);
|
|
orderEntity.setFromType(ConstantStatus.FROM_UDISP);
|
|
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESS);
|
|
IoOrderEntity temp = orderService.findByBillNo(orderEntity.getBillNo());
|
|
if (temp == null) {
|
|
orderEntity.setId(null);
|
|
orderService.insertOrder(orderEntity);
|
|
insetOrderDb(syncDataResponse, orderEntity);
|
|
orderEntity = orderService.findByBillNo(orderEntity.getBillNo());
|
|
addInoutService.dealProcess(orderEntity);
|
|
orderEntity = orderService.findByBillNo(orderEntity.getBillNo());
|
|
if (orderEntity.getStatus() != ConstantStatus.ORDER_STATS_ERROR && !ioCheckInoutService.checkManual(orderEntity.getBillNo())) {
|
|
ioCheckInoutService.check(orderEntity.getBillNo());
|
|
}
|
|
}
|
|
}
|
|
|
|
String logs = "";
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities()))
|
|
logs = logs + "单据:" + syncDataResponse.getOrderEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailBizEntities()))
|
|
logs = logs + "业务详情:" + syncDataResponse.getOrderDetailBizEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities()))
|
|
logs = logs + "单据扫码详情:" + syncDataResponse.getOrderDetailCodeEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailResultEntities()))
|
|
logs = logs + "单据结果详情:" + syncDataResponse.getOrderDetailResultEntities().size() + "条\n";
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getCodeEntities()))
|
|
logs = logs + "单据条码信息:" + syncDataResponse.getCodeEntities().size() + "条\n";
|
|
remark.append(logs);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
|
|
}
|
|
spGetHttp.postBasicStatus(basicExportStatusEntity.getId());
|
|
|
|
basicDownloadStatusEntity.setUpdateTime(new Date());
|
|
basicDownloadStatusEntity.setEndTime(new Date());
|
|
basicDownloadStatusEntity.setRemark(remark.toString());
|
|
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 下载最近更新国家库数据-上级服务
|
|
public void dlAllDiProducts() {
|
|
BaseResponse<List<BasicExportStatusEntity>> baseResponse = spGetHttp.getBasicStatus(BasicProcessStatus.NEW_ALL_DI + "");
|
|
List<BasicExportStatusEntity> pageSimpleResponse = baseResponse.getData();
|
|
if (pageSimpleResponse != null) {
|
|
List<BasicExportStatusEntity> basicExportStatusEntities = pageSimpleResponse;
|
|
if (basicExportStatusEntities != null && basicExportStatusEntities.size() > 0) {
|
|
for (BasicExportStatusEntity basicExportStatusEntity : basicExportStatusEntities) {
|
|
long curTime = System.currentTimeMillis();
|
|
// log.info("--------等待时间------" + curTime);
|
|
String datas = spGetHttp.getBasicData(basicExportStatusEntity.getId(), BasicProcessStatus.NEW_ALL_DI);
|
|
// logger.info("--------等待时间1------" + (System.currentTimeMillis() - curTime) / 1000);
|
|
long curTime2 = System.currentTimeMillis();
|
|
BaseResponse<SpSyncUdiResponse> response = JSONObject.parseObject(datas, new TypeReference<BaseResponse<SpSyncUdiResponse>>() {
|
|
});
|
|
// logger.info("--------等待时间2------" + (System.currentTimeMillis() - curTime2) / 1000);
|
|
if (response.getCode() == 20000 && response.getData() != null) {
|
|
SpSyncUdiResponse spSyncUdiResponse = response.getData();
|
|
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
|
|
basicDownloadStatusEntity.setId(CustomUtil.getId());
|
|
basicDownloadStatusEntity.setTaskId(spSyncUdiResponse.getTaskId());
|
|
basicDownloadStatusEntity.setStartTime(new Date());
|
|
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_DI_PRODUCTS);
|
|
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT); //下载中
|
|
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_DI);
|
|
basicDownloadStatusEntity.setScheduleType(1);
|
|
|
|
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
|
|
StringBuffer remark = new StringBuffer();
|
|
|
|
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
|
|
if (CollUtil.isNotEmpty(spSyncUdiResponse.getUdiCompanyEntities())) {
|
|
List<UdiCompanyEntity> udiCompanyEntities = spSyncUdiResponse.getUdiCompanyEntities();
|
|
UdiCompanyDao mapper = batchSession.getMapper(UdiCompanyDao.class);
|
|
for (UdiCompanyEntity udiCompanyEntity : udiCompanyEntities) {
|
|
mapper.insertUdiCompany(udiCompanyEntity);
|
|
}
|
|
batchSession.commit();
|
|
remark.append("公司信息:").append(spSyncUdiResponse.getUdiCompanyEntities().size()).append("条\n");
|
|
}
|
|
|
|
if (CollUtil.isNotEmpty(spSyncUdiResponse.getProductInfoEntityList())) {
|
|
List<ProductInfoEntity> productInfoEntities = spSyncUdiResponse.getProductInfoEntityList();
|
|
ProductInfoDao mapper = batchSession.getMapper(ProductInfoDao.class);
|
|
for (ProductInfoEntity productInfoEntity : productInfoEntities) {
|
|
mapper.insertProductInfo(productInfoEntity);
|
|
}
|
|
batchSession.commit();
|
|
remark.append("产品信息:").append(spSyncUdiResponse.getProductInfoEntityList().size()).append("条\n");
|
|
}
|
|
batchSession.close();
|
|
spGetHttp.postBasicStatus(basicExportStatusEntity.getId());
|
|
|
|
basicDownloadStatusEntity.setUpdateTime(new Date());
|
|
basicDownloadStatusEntity.setEndTime(new Date());
|
|
basicDownloadStatusEntity.setRemark(remark.toString());
|
|
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void insetOrderDb(SpsSyncOrderResponse syncDataResponse, IoOrderEntity orderEntity) {
|
|
//更新码详情
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) {
|
|
List<IoCodeEntity> warehouseEntityList = syncDataResponse.getCodeEntities();
|
|
for (IoCodeEntity warehouseEntity : warehouseEntityList) {
|
|
if (warehouseEntity.getOrderId().equals(orderEntity.getBillNo())) {
|
|
IoCodeTempEntity codeTempEntity = new IoCodeTempEntity();
|
|
BeanUtils.copyProperties(warehouseEntity, codeTempEntity);
|
|
codeTempEntity.setId(null);
|
|
codeTempService.insert(codeTempEntity);
|
|
}
|
|
}
|
|
}
|
|
|
|
//更新业务详情
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailBizEntities())) {
|
|
List<IoOrderDetailBizEntity> orderDetailBizEntities = syncDataResponse.getOrderDetailBizEntities();
|
|
for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) {
|
|
if (bizEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
|
|
bizEntity.setId(null);
|
|
orderDetailBizService.insert(bizEntity);
|
|
}
|
|
}
|
|
}
|
|
|
|
//更新码详情
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) {
|
|
List<IoOrderDetailCodeEntity> orderDetailCodeEntities = syncDataResponse.getOrderDetailCodeEntities();
|
|
for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) {
|
|
if (codeEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
|
|
codeEntity.setId(null);
|
|
orderDetailCodeService.insert(codeEntity);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//更新结果详情
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailResultEntities())) {
|
|
List<IoOrderDetailResultEntity> orderDetailResultEntities = syncDataResponse.getOrderDetailResultEntities();
|
|
for (IoOrderDetailResultEntity detailResultEntity : orderDetailResultEntities) {
|
|
if (detailResultEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
|
|
detailResultEntity.setId(null);
|
|
orderDetailResultService.insert(detailResultEntity);
|
|
}
|
|
}
|
|
}
|
|
|
|
//更新发票信息
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderInvoiceEntities())) {
|
|
List<IoOrderInvoiceEntity> orderInvoiceEntities = syncDataResponse.getOrderInvoiceEntities();
|
|
for (IoOrderInvoiceEntity orderInvoiceEntity : orderInvoiceEntities) {
|
|
if (orderInvoiceEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
|
|
orderInvoiceService.insertInvoice(orderInvoiceEntity);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 同步第三方基础数据
|
|
*
|
|
* @param syncTime 同步时间
|
|
*/
|
|
public BaseResponse uploadThrData(String syncTime) {
|
|
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
|
|
if (syncTime == null) {
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_THR_DATA);
|
|
if (basicExportStatusTimeEntity == null) {
|
|
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
|
|
}
|
|
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
|
|
} else {
|
|
spsSyncDataRequest.setLastUpdateTime(syncTime);
|
|
}
|
|
SpsSyncThrDataResponse spsSyncThrDataResponse = upThrDataService.upThrData(spsSyncDataRequest);
|
|
if (CollUtil.isEmpty(spsSyncThrDataResponse.getDeptEntities()) && CollUtil.isEmpty(spsSyncThrDataResponse.getInvWarehouseEntities())
|
|
&& CollUtil.isEmpty(spsSyncThrDataResponse.getCorpEntities())) {
|
|
//无数据不记录
|
|
log.info("无第三方基础数据需要同步");
|
|
return ResultVOUtils.success("无数据");
|
|
}
|
|
|
|
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_THR_DATA, 0);
|
|
if (basicExportStatusEntity1 == null) {
|
|
BasicExportStatusEntity thrDataStatusEntity = new BasicExportStatusEntity();
|
|
thrDataStatusEntity.setId(CustomUtil.getId());
|
|
thrDataStatusEntity.setIdDatas(ConstantStatus.SYNC_THR_DATA);
|
|
thrDataStatusEntity.setType(BasicProcessStatus.NEW_ALL_THR_DATA);
|
|
thrDataStatusEntity.setUpdateTime(new Date());
|
|
thrDataStatusEntity.setStartTime(new Date());
|
|
thrDataStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
|
|
thrDataStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
|
basicExportService.insertExportStatus(thrDataStatusEntity);
|
|
basicExportStatusEntity1 = thrDataStatusEntity;
|
|
}
|
|
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_THR_DATA);
|
|
spsSyncThrDataResponse.setTaskId(basicExportStatusEntity1.getId());
|
|
BaseResponse<String> baseResponse = spGetHttp.postThrData(spsSyncThrDataResponse);
|
|
if (baseResponse.getCode() == 20000) {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
} else {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
|
|
}
|
|
basicExportStatusEntity1.setEndTime(new Date());
|
|
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
|
|
|
|
//拼接日志
|
|
StringBuilder logs = new StringBuilder();
|
|
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getDeptEntities())) {
|
|
logs.append("第三方部门信息:").append(spsSyncThrDataResponse.getDeptEntities().size()).append("条\n");
|
|
}
|
|
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getInvWarehouseEntities())) {
|
|
logs.append("第三方仓库信息:").append(spsSyncThrDataResponse.getInvWarehouseEntities().size()).append("条\n");
|
|
}
|
|
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getCorpEntities())) {
|
|
logs.append("第三方往来单位信息:").append(spsSyncThrDataResponse.getCorpEntities().size()).append("条\n");
|
|
}
|
|
basicExportStatusEntity1.setRemark(logs.toString());
|
|
basicExportStatusEntity1.setUpdateTime(new Date());
|
|
basicExportService.updateExportStatus(basicExportStatusEntity1);
|
|
return ResultVOUtils.success();
|
|
}
|
|
|
|
/**
|
|
* 同步系统设置
|
|
*
|
|
* @param syncTime 同步时间
|
|
* @return
|
|
*/
|
|
public BaseResponse uploadSysSetting(String syncTime) {
|
|
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
|
|
if (syncTime == null) {
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_SYS_SETTING);
|
|
if (basicExportStatusTimeEntity == null) {
|
|
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
|
|
}
|
|
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
|
|
} else {
|
|
spsSyncDataRequest.setLastUpdateTime(syncTime);
|
|
}
|
|
SpsSyncSysSettingResponse spsSyncSysSettingResponse = upBasicService.upSysSetting(spsSyncDataRequest);
|
|
if (BeanUtil.isEmpty(spsSyncSysSettingResponse)) {
|
|
//无数据不记录
|
|
log.info("无第系统设置需要同步");
|
|
return ResultVOUtils.success("无数据");
|
|
}
|
|
|
|
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_SYS_SETTING, 0);
|
|
if (basicExportStatusEntity1 == null) {
|
|
BasicExportStatusEntity thrDataStatusEntity = new BasicExportStatusEntity();
|
|
thrDataStatusEntity.setId(CustomUtil.getId());
|
|
thrDataStatusEntity.setIdDatas(ConstantStatus.SYNC_SYS_SETTING);
|
|
thrDataStatusEntity.setType(BasicProcessStatus.NEW_ALL_SYS_SETTING);
|
|
thrDataStatusEntity.setUpdateTime(new Date());
|
|
thrDataStatusEntity.setStartTime(new Date());
|
|
thrDataStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
|
|
thrDataStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
|
basicExportService.insertExportStatus(thrDataStatusEntity);
|
|
basicExportStatusEntity1 = thrDataStatusEntity;
|
|
}
|
|
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_SYS_SETTING);
|
|
spsSyncSysSettingResponse.setTaskId(basicExportStatusEntity1.getId());
|
|
BaseResponse<String> baseResponse = spGetHttp.postSysSetting(spsSyncSysSettingResponse);
|
|
if (baseResponse.getCode() == 20000) {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
} else {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
|
|
}
|
|
basicExportStatusEntity1.setEndTime(new Date());
|
|
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
|
|
|
|
basicExportStatusEntity1.setRemark(spsSyncSysSettingResponse.logs());
|
|
basicExportStatusEntity1.setUpdateTime(new Date());
|
|
basicExportService.updateExportStatus(basicExportStatusEntity1);
|
|
return ResultVOUtils.success();
|
|
}
|
|
|
|
/**
|
|
* 同步第三方产品数据
|
|
*
|
|
* @param syncTime
|
|
* @return
|
|
*/
|
|
public BaseResponse uploadThrProducts(String syncTime) {
|
|
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
|
|
if (syncTime == null) {
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_THR_PRODUCTS);
|
|
if (basicExportStatusTimeEntity == null) {
|
|
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
|
|
}
|
|
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
|
|
} else {
|
|
spsSyncDataRequest.setLastUpdateTime(syncTime);
|
|
}
|
|
SpsSyncThrProductsResponse spsSyncThrProductsResponse = upThrDataService.upThrProducts(spsSyncDataRequest);
|
|
if (CollUtil.isEmpty(spsSyncThrProductsResponse.getProductsEntities())) {
|
|
//无数据不记录
|
|
log.info("无第三方产品数据需要同步");
|
|
return ResultVOUtils.success("无数据");
|
|
}
|
|
|
|
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_THR_PRODUCTS, 0);
|
|
if (basicExportStatusEntity1 == null) {
|
|
BasicExportStatusEntity thrDataStatusEntity = new BasicExportStatusEntity();
|
|
thrDataStatusEntity.setId(CustomUtil.getId());
|
|
thrDataStatusEntity.setIdDatas(ConstantStatus.SYNC_THR_PRODUCTS);
|
|
thrDataStatusEntity.setType(BasicProcessStatus.NEW_ALL_THR_PRODUCTS);
|
|
thrDataStatusEntity.setUpdateTime(new Date());
|
|
thrDataStatusEntity.setStartTime(new Date());
|
|
thrDataStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
|
|
thrDataStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
|
|
basicExportService.insertExportStatus(thrDataStatusEntity);
|
|
basicExportStatusEntity1 = thrDataStatusEntity;
|
|
}
|
|
|
|
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
|
|
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_THR_PRODUCTS);
|
|
spsSyncThrProductsResponse.setTaskId(basicExportStatusEntity1.getId());
|
|
BaseResponse<String> baseResponse = spGetHttp.postThrProducts(spsSyncThrProductsResponse);
|
|
if (baseResponse.getCode() == 20000) {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
} else {
|
|
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
|
|
}
|
|
basicExportStatusEntity1.setEndTime(new Date());
|
|
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
|
|
|
|
//拼接日志
|
|
StringBuilder logs = new StringBuilder();
|
|
if (CollUtil.isNotEmpty(spsSyncThrProductsResponse.getProductsEntities())) {
|
|
logs.append("第三方产品信息:").append(spsSyncThrProductsResponse.getProductsEntities().size()).append("条\n");
|
|
}
|
|
basicExportStatusEntity1.setRemark(logs.toString());
|
|
basicExportStatusEntity1.setUpdateTime(new Date());
|
|
basicExportService.updateExportStatus(basicExportStatusEntity1);
|
|
return ResultVOUtils.success();
|
|
}
|
|
}
|