|
|
|
|
package com.glxp.api.controller.sync;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import com.glxp.api.annotation.AuthRuleAnnotation;
|
|
|
|
|
import com.glxp.api.common.enums.ResultEnum;
|
|
|
|
|
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.Constant;
|
|
|
|
|
import com.glxp.api.constant.ConstantStatus;
|
|
|
|
|
import com.glxp.api.controller.purchase.PurOrderController;
|
|
|
|
|
import com.glxp.api.dao.inout.*;
|
|
|
|
|
import com.glxp.api.dao.purchase.PurOrderDao;
|
|
|
|
|
import com.glxp.api.dao.purchase.PurOrderDetailDao;
|
|
|
|
|
import com.glxp.api.entity.inout.*;
|
|
|
|
|
import com.glxp.api.entity.purchase.PurOrderDetailEntity;
|
|
|
|
|
import com.glxp.api.entity.purchase.PurOrderEntity;
|
|
|
|
|
import com.glxp.api.entity.sync.BasicDownloadStatusEntity;
|
|
|
|
|
import com.glxp.api.entity.sync.BasicExportStatusEntity;
|
|
|
|
|
import com.glxp.api.entity.sync.SyncDataBustypeEntity;
|
|
|
|
|
import com.glxp.api.entity.sync.SyncDataSetEntity;
|
|
|
|
|
import com.glxp.api.req.sync.SpsSyncDataRequest;
|
|
|
|
|
import com.glxp.api.res.sync.SpsSyncBusOrderResponse;
|
|
|
|
|
import com.glxp.api.res.sync.SpsSyncOrderResponse;
|
|
|
|
|
import com.glxp.api.res.system.SyncDataSetResponse;
|
|
|
|
|
import com.glxp.api.service.inout.IoAddInoutService;
|
|
|
|
|
import com.glxp.api.service.inout.IoCheckInoutService;
|
|
|
|
|
import com.glxp.api.service.inout.IoOrderService;
|
|
|
|
|
import com.glxp.api.service.purchase.PurOrderDetailService;
|
|
|
|
|
import com.glxp.api.service.purchase.PurOrderService;
|
|
|
|
|
import com.glxp.api.service.sync.BasicDownloadService;
|
|
|
|
|
import com.glxp.api.service.sync.BasicExportService;
|
|
|
|
|
import com.glxp.api.service.sync.SpsSyncDownloadService;
|
|
|
|
|
import com.glxp.api.util.CustomUtil;
|
|
|
|
|
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.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
public class SpsSyncDownloadController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
SpsSyncDownloadService spsSyncDownloadService;
|
|
|
|
|
@Resource
|
|
|
|
|
BasicExportService basicExportService;
|
|
|
|
|
@Resource
|
|
|
|
|
BasicDownloadService basicDownloadService;
|
|
|
|
|
@Resource
|
|
|
|
|
SqlSessionFactory sqlSessionFactory;
|
|
|
|
|
@Resource
|
|
|
|
|
IoOrderService orderService;
|
|
|
|
|
@Resource
|
|
|
|
|
PurOrderService purOrderService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoAddInoutService addInoutService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCheckInoutService ioCheckInoutService;
|
|
|
|
|
@Resource
|
|
|
|
|
PurOrderDetailService purOrderDetailService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 下发单据,生成单据任务由中继服务,UDI管理系统下载
|
|
|
|
|
@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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 接收中继服务、UDI管理系统上传单据
|
|
|
|
|
@AuthRuleAnnotation("sps/sync/order/upload")
|
|
|
|
|
@PostMapping("/sps/sync/order/upload")
|
|
|
|
|
public BaseResponse save(@RequestBody @Valid SpsSyncOrderResponse syncDataResponse) {
|
|
|
|
|
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();
|
|
|
|
|
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
|
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities())) {
|
|
|
|
|
try {
|
|
|
|
|
List<IoOrderEntity> orderEntities = syncDataResponse.getOrderEntities();
|
|
|
|
|
IoOrderDao mapper = batchSession.getMapper(IoOrderDao.class);
|
|
|
|
|
for (IoOrderEntity orderEntity : orderEntities) {
|
|
|
|
|
orderEntity.setUpdateTime(null);
|
|
|
|
|
orderEntity.setFromType(ConstantStatus.FROM_UDISP);
|
|
|
|
|
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESS);
|
|
|
|
|
IoOrderEntity temp = orderService.findById(orderEntity.getBillNo());
|
|
|
|
|
if (temp == null) {
|
|
|
|
|
orderEntity.setId(null);
|
|
|
|
|
mapper.insert(orderEntity);
|
|
|
|
|
|
|
|
|
|
//更新码详情
|
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) {
|
|
|
|
|
IoCodeTempDao codeMappert = batchSession.getMapper(IoCodeTempDao.class);
|
|
|
|
|
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);
|
|
|
|
|
codeMappert.insert(codeTempEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新业务详情
|
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailBizEntities())) {
|
|
|
|
|
IoOrderDetailBizDao orderDetailBizDao = batchSession.getMapper(IoOrderDetailBizDao.class);
|
|
|
|
|
List<IoOrderDetailBizEntity> orderDetailBizEntities = syncDataResponse.getOrderDetailBizEntities();
|
|
|
|
|
for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) {
|
|
|
|
|
if (bizEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
|
|
|
|
|
orderDetailBizDao.insert(bizEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新码详情
|
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) {
|
|
|
|
|
IoOrderDetailCodeDao orderDetailCodeDao = batchSession.getMapper(IoOrderDetailCodeDao.class);
|
|
|
|
|
List<IoOrderDetailCodeEntity> orderDetailCodeEntities = syncDataResponse.getOrderDetailCodeEntities();
|
|
|
|
|
for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) {
|
|
|
|
|
if (codeEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
|
|
|
|
|
orderDetailCodeDao.insert(codeEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新结果详情
|
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailResultEntities())) {
|
|
|
|
|
IoOrderDetailResultDao orderDetailResultDao = batchSession.getMapper(IoOrderDetailResultDao.class);
|
|
|
|
|
List<IoOrderDetailResultEntity> orderDetailResultEntities = syncDataResponse.getOrderDetailResultEntities();
|
|
|
|
|
for (IoOrderDetailResultEntity detailResultEntity : orderDetailResultEntities) {
|
|
|
|
|
if (detailResultEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
|
|
|
|
|
orderDetailResultDao.insert(detailResultEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新发票信息
|
|
|
|
|
if (CollUtil.isNotEmpty(syncDataResponse.getOrderInvoiceEntities())) {
|
|
|
|
|
IoOrderInvoiceMapper orderInvoiceMapper = batchSession.getMapper(IoOrderInvoiceMapper.class);
|
|
|
|
|
List<IoOrderInvoiceEntity> orderInvoiceEntities = syncDataResponse.getOrderInvoiceEntities();
|
|
|
|
|
for (IoOrderInvoiceEntity orderInvoiceEntity : orderInvoiceEntities) {
|
|
|
|
|
if (orderInvoiceEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
|
|
|
|
|
orderInvoiceMapper.insert(orderInvoiceEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
batchSession.commit();
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
batchSession.commit();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
batchSession.close();
|
|
|
|
|
basicDownloadStatusEntity.setUpdateTime(new Date());
|
|
|
|
|
basicDownloadStatusEntity.setEndTime(new Date());
|
|
|
|
|
basicDownloadStatusEntity.setRemark(remark.toString());
|
|
|
|
|
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
|
|
|
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success("上传成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 接收中级服务,UDI管理系统上传业务单据
|
|
|
|
|
@AuthRuleAnnotation("/sps/sync/busOrder/upload")
|
|
|
|
|
@PostMapping("/sps/sync/busOrder/upload")
|
|
|
|
|
public BaseResponse busOrderSava(@RequestBody @Valid SpsSyncBusOrderResponse spsSyncBusOrderResponse) {
|
|
|
|
|
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
|
|
|
|
|
basicDownloadStatusEntity.setId(CustomUtil.getId());
|
|
|
|
|
basicDownloadStatusEntity.setTaskId(spsSyncBusOrderResponse.getTaskId());
|
|
|
|
|
basicDownloadStatusEntity.setStartTime(new Date());
|
|
|
|
|
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_SCAN_ORDER);
|
|
|
|
|
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT); //下载中
|
|
|
|
|
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_BUS_ORDER);
|
|
|
|
|
basicDownloadStatusEntity.setScheduleType(1);
|
|
|
|
|
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
|
|
|
|
|
StringBuffer remark = new StringBuffer();
|
|
|
|
|
if (CollUtil.isNotEmpty(spsSyncBusOrderResponse.getPurOrderEntities())) {
|
|
|
|
|
try {
|
|
|
|
|
List<PurOrderEntity> orderEntities = spsSyncBusOrderResponse.getPurOrderEntities();
|
|
|
|
|
for (PurOrderEntity orderEntity : orderEntities) {
|
|
|
|
|
orderEntity.setUpdateTime(null);
|
|
|
|
|
PurOrderEntity temp = purOrderService.selectByBillNo(orderEntity.getBillNo());
|
|
|
|
|
if (temp == null) {
|
|
|
|
|
orderEntity.setId(null);
|
|
|
|
|
purOrderService.insert(orderEntity);
|
|
|
|
|
if (CollUtil.isNotEmpty(spsSyncBusOrderResponse.getPurOrderDetailEntities())) {
|
|
|
|
|
List<PurOrderDetailEntity> purOrderDetailEntities = spsSyncBusOrderResponse.getPurOrderDetailEntities();
|
|
|
|
|
for (PurOrderDetailEntity purOrderDetailEntity : purOrderDetailEntities) {
|
|
|
|
|
PurOrderDetailEntity codeTempEntity = new PurOrderDetailEntity();
|
|
|
|
|
BeanUtils.copyProperties(purOrderDetailEntity, codeTempEntity);
|
|
|
|
|
codeTempEntity.setId(null);
|
|
|
|
|
codeTempEntity.setOrderIdFk(orderEntity.getId() + "");
|
|
|
|
|
purOrderDetailService.insert(codeTempEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String logs = "";
|
|
|
|
|
if (CollUtil.isNotEmpty(spsSyncBusOrderResponse.getPurOrderEntities()))
|
|
|
|
|
logs = logs + "单据:" + spsSyncBusOrderResponse.getPurOrderEntities().size() + "条\n";
|
|
|
|
|
if (CollUtil.isNotEmpty(spsSyncBusOrderResponse.getPurOrderDetailEntities()))
|
|
|
|
|
logs = logs + "单据详情:" + spsSyncBusOrderResponse.getPurOrderDetailEntities().size() + "条\n";
|
|
|
|
|
remark.append(logs);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
basicDownloadStatusEntity.setUpdateTime(new Date());
|
|
|
|
|
basicDownloadStatusEntity.setEndTime(new Date());
|
|
|
|
|
basicDownloadStatusEntity.setRemark(remark.toString());
|
|
|
|
|
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
|
|
|
|
|
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success("上传成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//接收中继服务、UDI管理系统上传单据类型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//接收中继服务、UDI管理系统上传基础信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|