新增接收下游上传单据接口

master
anthonywj 2 years ago
parent 302e625408
commit d3dc0e9556

@ -2,17 +2,43 @@ 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.dao.inout.IoCodeTempDao;
import com.glxp.api.dao.inout.IoOrderDao;
import com.glxp.api.dao.inout.IoOrderDetailBizDao;
import com.glxp.api.dao.inout.IoOrderDetailCodeDao;
import com.glxp.api.entity.inout.*;
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.SpsSyncOrderResponse;
import com.glxp.api.res.system.SyncDataSetResponse;
import com.glxp.api.service.inout.IoOrderService;
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 {
@ -21,7 +47,15 @@ public class SpsSyncDownloadController {
SpsSyncDownloadService spsSyncDownloadService;
@Resource
BasicExportService basicExportService;
@Resource
BasicDownloadService basicDownloadService;
@Resource
SqlSessionFactory sqlSessionFactory;
@Resource
IoOrderService orderService;
// 下发单据生成单据任务由中继服务UDI管理系统下载
@AuthRuleAnnotation("")
@GetMapping("sps/sync/order")
public BaseResponse findOrder(SpsSyncDataRequest spsSyncDataRequest) {
@ -44,5 +78,94 @@ public class SpsSyncDownloadController {
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 detailCodeEntity : orderDetailCodeEntities) {
if (detailCodeEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
orderDetailCodeDao.insert(detailCodeEntity);
}
}
}
batchSession.commit();
}
}
batchSession.commit();
String logs = "";
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities()))
logs = logs + "单据:" + syncDataResponse.getOrderEntities().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities()))
logs = logs + "单据详情:" + syncDataResponse.getOrderDetailBizEntities().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("上传成功!");
}
}

Loading…
Cancel
Save