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.
udi-spms-java/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java

1275 lines
66 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.glxp.api.controller.sync;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.*;
import com.glxp.api.constant.Constant;
import com.glxp.api.dao.auth.*;
import com.glxp.api.dao.basic.*;
import com.glxp.api.dao.inout.*;
import com.glxp.api.dao.purchase.*;
import com.glxp.api.dao.schedule.SystemParamConfigDao;
import com.glxp.api.dao.system.*;
import com.glxp.api.dao.thrsys.*;
import com.glxp.api.entity.auth.*;
import com.glxp.api.entity.basic.*;
import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.purchase.*;
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.system.*;
import com.glxp.api.entity.thrsys.*;
import com.glxp.api.req.sync.SpsSyncDataRequest;
import com.glxp.api.req.sync.SyncUpLoadRequest;
import com.glxp.api.res.sync.*;
import com.glxp.api.service.auth.InvWarehouseService;
import com.glxp.api.service.basic.IBasicBusTypeChangeService;
import com.glxp.api.service.basic.IBasicBussinessTypeService;
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.service.sync.SyncDataBustypeService;
import com.glxp.api.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
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.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;
@RestController
@Api(tags = "同步下载相关")
@RequiredArgsConstructor
@Slf4j
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;
@Resource
AuthAdminDao authAdminDao;
@Resource
InvBusUserDao invBusUserDao;
@Resource
DeptDao deptDao;
@Resource
DeptUserDao deptUserDao;
@Resource
InvWarehouseDao invWarehouseDao;
@Resource
WarehouseBussinessTypeDao warehouseBussinessTypeDao;
@Resource
WarehouseUserDao warehouseUserDao;
private final InvSpaceDao invSpaceDao;
// 下发单据接口 供给中继服务UDI管理系统下载
@AuthRuleAnnotation("")
@GetMapping("sps/sync/order")
public BaseResponse getOrder(SpsSyncDataRequest spsSyncDataRequest) {
BasicExportStatusEntity basicExportStatusEntity = basicExportService.findByData(ConstantStatus.SYNC_SCAN_ORDER, 3);
String logs = "";
BaseResponse<SpsSyncOrderResponse> baseResponse = new BaseResponse<>();
if (basicExportStatusEntity != null) {
if (StrUtil.isBlank(basicExportStatusEntity.getCacheFilePath())) {
baseResponse = spsSyncDownloadService.findOrder(spsSyncDataRequest);
String fileFullPath = null;
try {
fileFullPath = writeFile(filePrefix, BasicProcessStatus.NEW_ALL_BUS_ORDER, JSONUtil.toJsonStr(baseResponse.getData()));
} catch (IOException e) {
e.printStackTrace();
}
basicExportStatusEntity.setCacheFilePath(fileFullPath);
basicExportStatusEntity.setRemark(baseResponse.getData().getSyncRemark());
basicExportService.updateExportStatus(basicExportStatusEntity);
} else {
String content = readDataFile(basicExportStatusEntity.getCacheFilePath());
baseResponse.setData(JSONUtil.toBean(content, SpsSyncOrderResponse.class));
}
SpsSyncOrderResponse spsSyncOrderResponse = baseResponse.getData();
spsSyncOrderResponse.setTaskId(basicExportStatusEntity.getId());
baseResponse.setData(spsSyncOrderResponse);
baseResponse.setCode(20000);
baseResponse.setMessage("success");
}
return baseResponse;
}
// 下发国家库DI数据供给中继服务UDI管理系统下载
@AuthRuleAnnotation("")
@GetMapping("sps/sync/syncUdis")
public BaseResponse getDiProducts(SpsSyncDataRequest spsSyncDataRequest) {
BaseResponse<SpSyncUdiResponse> baseResponse = ResultVOUtils.error(ResultEnum.NOT_NETWORK.getCode(),"");
BasicExportStatusEntity basicExportStatusEntity = basicExportService.findByData(ConstantStatus.SYNC_DI_PRODUCTS, 3);
String logs = "";
if (basicExportStatusEntity != null) {
baseResponse = spsSyncDownloadService.syncUdi(spsSyncDataRequest);
// if (CollUtil.isNotEmpty(baseResponse.getData().getProductInfoEntityList()))
// logs = logs + "DI信息" + baseResponse.getData().getProductInfoEntityList().size() + "条\n";
// if (CollUtil.isNotEmpty(baseResponse.getData().getUdiCompanyEntities()))
// logs = logs + "医疗器械注册人:" + baseResponse.getData().getUdiCompanyEntities().size() + "条\n";
// basicExportStatusEntity.setRemark(logs);
// basicExportService.updateExportStatus(basicExportStatusEntity);
SpSyncUdiResponse spSyncUdiResponse = baseResponse.getData();
spSyncUdiResponse.setTaskId(basicExportStatusEntity.getId());
baseResponse.setData(spSyncUdiResponse);
baseResponse.setCode(20000);
baseResponse.setMessage("success");
}
return baseResponse;
}
// 下发基础数据 供给中继服务UDI管理系统下载
@AuthRuleAnnotation("")
@GetMapping("sps/sync/data")
@ApiOperation("拉取同步任务数据")
public BaseResponse<RelaySyncResponse> data(BasicExportTypeEnum exportType) {
BaseResponse<RelaySyncResponse> baseResponse = new BaseResponse<>();
BasicExportStatusEntity one = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class)
.eq(BasicExportStatusEntity::getType, exportType.getRemark())
.orderByDesc(BasicExportStatusEntity::getStartTime)
.last("limit 1")
);
RelaySyncResponse relaySyncResponse = null;
if (one != null) {
if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) {
basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
.set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode())
.set(BasicExportStatusEntity::getUpdateTime, new Date())
.eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_TRIGGERED.getCode())
.eq(BasicExportStatusEntity::getId, one.getId())
);
} else if (BasicExportStatusEnum.WAIT_SYNC.getCode().equals(one.getStatus())) {
if (StrUtil.isBlank(one.getCacheFilePath())) {
throw new RuntimeException("系统异常,文件名为空");
}
relaySyncResponse = RelaySyncResponse.builder()
.taskId(one.getId())
.filePath(one.getCacheFilePath())
.fileContent(this.readDataFile(one.getCacheFilePath()))
.build();
}
}
baseResponse.setCode(ResultEnum.SUCCESS.getCode());
baseResponse.setData(relaySyncResponse);
return baseResponse;
}
private String readDataFile(String fileFullPath) {
// 读取文件数据
try {
if (StrUtil.isBlank(fileFullPath)) {
throw new RuntimeException("系统异常,文件名为空");
}
FileReader reader = new FileReader(fileFullPath);
StringBuilder str = new StringBuilder();
int data;
while ((data = reader.read()) != -1) {
str.append((char) data);
}
reader.close();
return str.toString();
} catch (FileNotFoundException e) {
throw new RuntimeException("系统异常,未找到对应数据文件");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
// 下发基础数据 供给中继服务UDI管理系统下载
@AuthRuleAnnotation("")
@GetMapping("sps/sync/basicData")
public BaseResponse getBasicData() {
BaseResponse<SpsSyncBasicDataResponse> baseResponse = new BaseResponse<>();
SpsSyncBasicDataResponse spsSyncBasicDataResponse = null;
BasicExportStatusEntity one = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class)
.eq(BasicExportStatusEntity::getType, BasicExportTypeEnum.BASIC_DATA.getRemark())
.orderByDesc(BasicExportStatusEntity::getStartTime)
.last("limit 1")
);
if (one != null) {
if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) {
basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
.set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode())
.set(BasicExportStatusEntity::getUpdateTime, new Date())
.eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_TRIGGERED.getCode())
.eq(BasicExportStatusEntity::getId, one.getId())
);
} else if (BasicExportStatusEnum.WAIT_SYNC.getCode().equals(one.getStatus())) {
// 读取文件数据
try {
FileReader reader = new FileReader(one.getCacheFilePath());
StringBuilder str = new StringBuilder();
int data;
while ((data = reader.read()) != -1) {
str.append((char) data);
}
reader.close();
Dict map = JsonUtils.parseMap(str.toString());
spsSyncBasicDataResponse = new SpsSyncBasicDataResponse();
// 组装返回数据
spsSyncBasicDataResponse.setTaskId(one.getId());
spsSyncBasicDataResponse.setHospTypeList((List<BasicHospTypeEntity>) map.get(BasicHospTypeEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setUdiRelevanceList((List<UdiRelevanceEntity>) map.get(UdiRelevanceEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setProductsList((List<BasicProductsEntity>) map.get(BasicProductsEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setRelevanceList((List<CompanyProductRelevanceEntity>) map.get(CompanyProductRelevanceEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setCorpList((List<BasicCorpEntity>) map.get(BasicCorpEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupCertList((List<SupCertEntity>) map.get(SupCertEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupCertSetList((List<SupCertSetEntity>) map.get(SupCertSetEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupCompanyList((List<SupCompanyEntity>) map.get(SupCompanyEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupManufacturerList((List<SupManufacturerEntity>) map.get(SupManufacturerEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupProductList((List<SupProductEntity>) map.get(SupProductEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSyncRemark(map.getStr(Constant.SYNC_REMARK));
} catch (FileNotFoundException e) {
throw new RuntimeException("系统异常,未找到对应数据文件");
} catch (IOException e) {
throw new RuntimeException(e);
}
// 修改任务状态
// basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
// .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.COMPLETED.getCode())
// .set(BasicExportStatusEntity::getUpdateTime, new Date())
// .set(BasicExportStatusEntity::getEndTime, new Date())
// .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode())
// .eq(BasicExportStatusEntity::getId, one.getId())
// );
}
}
baseResponse.setCode(ResultVOUtils.success().getCode());
baseResponse.setData(spsSyncBasicDataResponse);
return baseResponse;
}
// 下发基础数据 供给中继服务UDI管理系统下载
@AuthRuleAnnotation("")
@GetMapping("sps/sync/otherData")
public BaseResponse getOtherData() {
BaseResponse<SpsSyncOtherDataResponse> baseResponse = new BaseResponse<>();
SpsSyncOtherDataResponse spsSyncOtherDataResponse = null;
BasicExportStatusEntity one = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class)
.eq(BasicExportStatusEntity::getType, BasicExportTypeEnum.OTHER_DATA.getRemark())
.orderByDesc(BasicExportStatusEntity::getStartTime)
.last("limit 1")
);
if (one != null) {
if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) {
basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
.set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode())
.set(BasicExportStatusEntity::getUpdateTime, new Date())
.eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_TRIGGERED.getCode())
.eq(BasicExportStatusEntity::getId, one.getId())
);
} else if (BasicExportStatusEnum.WAIT_SYNC.getCode().equals(one.getStatus())) {
// 读取文件数据
try {
FileReader reader = new FileReader(one.getCacheFilePath());
StringBuilder str = new StringBuilder();
int data;
while ((data = reader.read()) != -1) {
str.append((char) data);
}
reader.close();
Dict map = JsonUtils.parseMap(str.toString());
spsSyncOtherDataResponse = new SpsSyncOtherDataResponse();
// 组装返回数据
spsSyncOtherDataResponse.setTaskId(one.getId());
spsSyncOtherDataResponse.setIoCodeLostList((List<IoCodeLostEntity>) map.get(IoCodeLostEntity.class.getSimpleName()));
spsSyncOtherDataResponse.setIoCodeRelList((List<IoCodeRelEntity>) map.get(IoCodeRelEntity.class.getSimpleName()));
spsSyncOtherDataResponse.setSyncRemark(map.getStr(Constant.SYNC_REMARK));
} catch (FileNotFoundException e) {
throw new RuntimeException("系统异常,未找到对应数据文件");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
baseResponse.setCode(ResultVOUtils.success().getCode());
baseResponse.setData(spsSyncOtherDataResponse);
return baseResponse;
}
@Value("${file_path}")
private String filePrefix;
@ApiOperation("上传同步数据")
@PostMapping("sps/sync/upload/data")
@Transactional
public Object uploadData(@RequestBody SyncUpLoadRequest upLoadRequest) {
try {
JSONObject obj = JSONUtil.parseObj(upLoadRequest.getData());
switch (upLoadRequest.getExportType()) {
case BASIC_DATA:
// saveUploadBasicData(JSONUtil.toBean(obj, SpsSyncBasicDataResponse.class));
break;
case OTHER_DATA:
// saveUploadOtherData(JSONUtil.toBean(obj, SpsSyncOtherDataResponse.class));
break;
case DOCUMENT_TYPE_DATA:
saveUploadDocumentTypeData(JSONUtil.toBean(obj, SpsSyncBusResponse.class));
break;
case USER_DATA:
saveUploadUserData(JSONUtil.toBean(obj, SpsSyncDataResponse.class));
break;
case THIRD_DATA:
saveUploadThrData(JSONUtil.toBean(obj, SpsSyncThrDataResponse.class));
break;
case SYS_SET_DATA:
saveUploadSysSettingData(JSONUtil.toBean(obj, SpsSyncSysSettingResponse.class));
break;
}
String taskId = obj.getStr("taskId");
BasicDownloadStatusEntity downloadStatus = BasicDownloadStatusEntity.builder()
.id(taskId)
.taskId(taskId)
.startTime(new Date())
.endTime(new Date())
.status(StatusEnum.SUCCESS.getCode())
.updateTime(new Date())
.type(upLoadRequest.getExportType().getRemark())
.idDatas(upLoadRequest.getExportType().getKey())
.scheduleType(1)
.build();
String fileFullPath = writeFile(filePrefix, upLoadRequest.getExportType().getRemark(), JSONUtil.toJsonStr(upLoadRequest.getData()));
downloadStatus.setCacheFilePath(fileFullPath);
basicDownloadService.insertDownloadStatus(downloadStatus);
return ResultVOUtils.success();
} catch (Exception e) {
log.error("", e);
e.printStackTrace();
return ResultVOUtils.error(ResultEnum.NOT_NETWORK, e.getMessage());
}
}
private String writeFile(String filePath, String fileDesc, String content) throws IOException {
filePath = String.format("%s/%s", filePath, DateUtil.getDate());
String fileFullPath = String.format("%s/%s-%s.udi", filePath, fileDesc, IdUtil.fastSimpleUUID());
File file = new File(filePath);
if (!file.exists()) {
file.mkdirs();
}
file = new File(fileFullPath);
while (!file.createNewFile()) {
fileFullPath = String.format("%s/%s/%s-%s.udi", filePath, DateUtil.getDate(), fileDesc, IdUtil.fastSimpleUUID());
file = new File(fileFullPath);
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(content);
fileWriter.flush();
fileWriter.close();
return fileFullPath;
}
private final SystemParamConfigDao systemParamConfigDao;
private final EntrustReceDao entrustReceDao;
private final SystemPDFModuleDao systemPDFModuleDao;
private final SystemPDFTemplateDao systemPDFTemplateDao;
private final SysPdfTemplateRelevanceCodeDao sysPdfTemplateRelevanceCodeDao;
private final SysPdfTemplateRelevanceBizDao sysPdfTemplateRelevanceBizDao;
private final SysPdfTemplateRelevanceLabelDao sysPdfTemplateRelevanceLabelDao;
private final SysPdfTemplateRelevanceStatemenDao sysPdfTemplateRelevanceStatemenDao;
private final BasicBusTypePreDao basicBusTypePreDao;
private final BasicBusTypeChangeDao basicBusTypeChangeDao;
private void saveUploadSysSettingData(SpsSyncSysSettingResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getSystemParamConfigEntities())) {
systemParamConfigDao.replaceBatch(bean.getSystemParamConfigEntities());
}
if (CollectionUtil.isNotEmpty(bean.getEntrustReceEntities())) {
entrustReceDao.replaceBatch(bean.getEntrustReceEntities());
}
if (CollectionUtil.isNotEmpty(bean.getSystemPDFModuleEntities())) {
systemPDFModuleDao.replaceBatch(bean.getSystemPDFModuleEntities());
}
if (CollectionUtil.isNotEmpty(bean.getSystemPDFTemplateEntities())) {
systemPDFTemplateDao.replaceBatch(bean.getSystemPDFTemplateEntities());
}
if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceCodeEntities())) {
sysPdfTemplateRelevanceCodeDao.replaceBatch(bean.getSysPdfTemplateRelevanceCodeEntities());
}
if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceBizEntities())) {
sysPdfTemplateRelevanceBizDao.replaceBatch(bean.getSysPdfTemplateRelevanceBizEntities());
}
if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceLabelEntities())) {
sysPdfTemplateRelevanceLabelDao.replaceBatch(bean.getSysPdfTemplateRelevanceLabelEntities());
}
if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceStatemenEntities())) {
sysPdfTemplateRelevanceStatemenDao.replaceBatch(bean.getSysPdfTemplateRelevanceStatemenEntities());
}
if (CollectionUtil.isNotEmpty(bean.getBasicBusTypePreEntities())) {
basicBusTypePreDao.replaceBatch(bean.getBasicBusTypePreEntities());
}
if (CollectionUtil.isNotEmpty(bean.getBasicBusTypeChangeEntities())) {
basicBusTypeChangeDao.replaceBatch(bean.getBasicBusTypeChangeEntities());
}
}
private final ThrDeptDao thrDeptDao;
private final ThrInvWarehouseDao thrInvWarehouseDao;
private final ThrProductsDao thrProductsDao;
private final ThrCorpDao thrCorpDao;
private void saveUploadThrData(SpsSyncThrDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getDeptEntities())) {
thrDeptDao.replaceBatch(bean.getDeptEntities());
}
if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) {
thrInvWarehouseDao.replaceBatch(bean.getInvWarehouseEntities());
}
if (CollectionUtil.isNotEmpty(bean.getProductsEntityList())) {
thrProductsDao.replaceBatch(bean.getProductsEntityList());
}
if (CollectionUtil.isNotEmpty(bean.getCorpEntities())) {
thrCorpDao.replaceBatch(bean.getCorpEntities());
}
}
private void saveUploadUserData(SpsSyncDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getAuthAdminList())) {
authAdminDao.replaceBatch(bean.getAuthAdminList());
}
if (CollectionUtil.isNotEmpty(bean.getDeptEntityList())) {
deptDao.replaceBatch(bean.getDeptEntityList());
}
if (CollectionUtil.isNotEmpty(bean.getDeptUserEntities())) {
deptUserDao.replaceBatch(bean.getDeptUserEntities());
}
if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) {
invWarehouseDao.replaceBatch(bean.getInvWarehouseEntities());
}
if (CollectionUtil.isNotEmpty(bean.getWarehouseUserEntities())) {
warehouseUserDao.replaceBatch(bean.getWarehouseUserEntities());
}
if (CollectionUtil.isNotEmpty(bean.getWarehouseBussinessTypeEntities())) {
warehouseBussinessTypeDao.replaceBatch(bean.getWarehouseBussinessTypeEntities());
}
if (CollectionUtil.isNotEmpty(bean.getInvSpaces())) {
invSpaceDao.replaceBatch(bean.getInvSpaces());
}
if (CollectionUtil.isNotEmpty(bean.getInvBusUserEntities())) {
invBusUserDao.replaceBatch(bean.getInvBusUserEntities());
}
}
private final BasicBussinessTypeDao basicBussinessTypeDao;
private final BasicBusTypeChangeDao busTypeChangeDao;
private final ThrBusTypeOriginDao thrBusTypeOriginDao;
/**
* 保存上传的单据类型数据
*
* @param bean
*/
private void saveUploadDocumentTypeData(SpsSyncBusResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getBussinessTypeEntities())) {
basicBussinessTypeDao.replaceBatch(bean.getBussinessTypeEntities());
}
if (CollectionUtil.isNotEmpty(bean.getBusTypeChangeEntities())) {
busTypeChangeDao.replaceBatch(bean.getBusTypeChangeEntities());
}
if (CollectionUtil.isNotEmpty(bean.getThrBusTypeOriginEntities())) {
thrBusTypeOriginDao.replaceBatch(bean.getThrBusTypeOriginEntities());
}
}
private final IoCodeLostMapper ioCodeLostMapper;
private final IoCodeRelMapper ioCodeRelMapper;
/**
* 保存上传的其他数据
*
* @param bean
*/
private void saveUploadOtherData(SpsSyncOtherDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getIoCodeLostList())) {
ioCodeLostMapper.replaceBatch(bean.getIoCodeLostList());
}
if (CollectionUtil.isNotEmpty(bean.getIoCodeRelList())) {
ioCodeRelMapper.replaceBatch(bean.getIoCodeRelList());
}
}
private final BasicHospTypeDao basicHospTypeDao;
private final UdiRelevanceDao udiRelevanceDao;
private final BasicProductsDao basicProductsDao;
private final CompanyProductRelevanceDao relevanceDao;
private final BasicCorpDao corpDao;
private final SupCertDao supCertDao;
private final SupCertSetDao supCertSetDao;
private final SupCompanyDao supCompanyDao;
private final SupManufacturerDao supManufacturerDao;
private final SupProductDao supProductDao;
/**
* 保存上传的基础数据
*
* @param bean
*/
private void saveUploadBasicData(SpsSyncBasicDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getHospTypeList())) {
basicHospTypeDao.replaceBatch(bean.getHospTypeList());
}
if (CollectionUtil.isNotEmpty(bean.getUdiRelevanceList())) {
udiRelevanceDao.replaceBatch(bean.getUdiRelevanceList());
}
if (CollectionUtil.isNotEmpty(bean.getProductsList())) {
basicProductsDao.replaceBatch(bean.getProductsList());
}
if (CollectionUtil.isNotEmpty(bean.getRelevanceList())) {
relevanceDao.replaceBatch(bean.getRelevanceList());
}
if (CollectionUtil.isNotEmpty(bean.getCorpList())) {
corpDao.replaceBatch(bean.getCorpList());
}
if (CollectionUtil.isNotEmpty(bean.getSupCertList())) {
supCertDao.replaceBatch(bean.getSupCertList());
}
if (CollectionUtil.isNotEmpty(bean.getSupCertSetList())) {
supCertSetDao.replaceBatch(bean.getSupCertSetList());
}
if (CollectionUtil.isNotEmpty(bean.getSupCompanyList())) {
supCompanyDao.replaceBatch(bean.getSupCompanyList());
}
if (CollectionUtil.isNotEmpty(bean.getSupManufacturerList())) {
supManufacturerDao.replaceBatch(bean.getSupManufacturerList());
}
if (CollectionUtil.isNotEmpty(bean.getSupProductList())) {
supProductDao.replaceBatch(bean.getSupProductList());
}
}
@Resource
IoOrderDao orderDao;
@Resource
IoCodeTempDao codeMappert;
@Resource
IoOrderDetailBizDao orderDetailBizDao;
@Resource
IoOrderDetailCodeDao orderDetailCodeDao;
@Resource
IoOrderDetailResultDao orderDetailResultDao;
@Resource
IoOrderInvoiceMapper orderInvoiceMapper;
@Resource
IBasicBussinessTypeService basicBussinessTypeService;
@Resource
InvWarehouseService invWarehouseService;
@Resource
SyncDataBustypeService syncDataBustypeService;
//接收中继服务、UDI管理系统上传单据
@AuthRuleAnnotation("sps/sync/order/upload")
@PostMapping("/sps/sync/order/upload")
public BaseResponse uploadOrder(@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();
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities())) {
List<IoOrderEntity> orderEntities = syncDataResponse.getOrderEntities();
for (IoOrderEntity orderEntity : orderEntities) {
SyncDataBustypeEntity syncDataBustypeEntity = syncDataBustypeService.findByAction(orderEntity.getAction(), 2);
orderEntity.setUpdateTime(null);
orderEntity.setFromType(ConstantStatus.FROM_UDISP);
orderEntity.setProcessStatus(ConstantStatus.ORDER_DEAL_POST);
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESS);
if (syncDataBustypeEntity != null) {
if (IntUtil.value(syncDataBustypeEntity.getSyncStatus()) == 1) {
orderEntity.setProcessStatus(ConstantStatus.ORDER_DEAL_DRAFT);
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE);
}
if (syncDataBustypeEntity.isSyncChange()) {
orderEntity.setOutChangeEnable(syncDataBustypeEntity.isSyncChange());
}
}
IoOrderEntity temp = orderService.findByBillNo(orderEntity.getBillNo());
if (temp == null) {
//过滤使用出库单,转换成一级库出库单(条件:往来类型为客户信息,出入库类型为出库,仓库类型为入账库,是否更改库存为是
BasicBussinessTypeEntity basicBussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
if (basicBussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_INPUT
&& basicBussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)
&& basicBussinessTypeEntity.isInStock() && basicBussinessTypeEntity.getActionType() == 1) {
// orderEntity.getInvCode()
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(orderEntity.getInvCode());
InvWarehouseEntity parentInv = invWarehouseService.findOneLevel(invWarehouseEntity.getParentCode());
if (parentInv == null)
parentInv = invWarehouseEntity;
orderEntity.setInvCode(parentInv.getCode());
orderEntity.setDeptCode(parentInv.getParentId());
orderEntity.setFromCorp("科室使用出库");
}
orderEntity.setId(null);
orderDao.insert(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);
codeMappert.insert(codeTempEntity);
}
}
}
//更新业务详情
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailBizEntities())) {
List<IoOrderDetailBizEntity> orderDetailBizEntities = syncDataResponse.getOrderDetailBizEntities();
for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) {
if (bizEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
orderDetailBizDao.insert(bizEntity);
}
}
}
//更新码详情
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) {
List<IoOrderDetailCodeEntity> orderDetailCodeEntities = syncDataResponse.getOrderDetailCodeEntities();
for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) {
if (codeEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
orderDetailCodeDao.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);
orderDetailResultDao.insert(detailResultEntity);
}
}
}
//更新发票信息
if (CollUtil.isNotEmpty(syncDataResponse.getOrderInvoiceEntities())) {
List<IoOrderInvoiceEntity> orderInvoiceEntities = syncDataResponse.getOrderInvoiceEntities();
for (IoOrderInvoiceEntity orderInvoiceEntity : orderInvoiceEntities) {
if (orderInvoiceEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
orderInvoiceEntity.setId(IdUtil.getSnowflakeNextId());
orderInvoiceMapper.insert(orderInvoiceEntity);
}
}
}
orderEntity = orderService.findByBillNo(orderEntity.getBillNo());
if (orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_TEMP_SAVE) {
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);
}
String fileFullPath = null;
try {
fileFullPath = writeFile(filePrefix, BasicProcessStatus.NEW_ALL_BUS_ORDER, JSONUtil.toJsonStr(syncDataResponse));
} catch (IOException e) {
e.printStackTrace();
}
basicDownloadStatusEntity.setCacheFilePath(fileFullPath);
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 uploadBusOrder(@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) {
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);
String fileFullPath = null;
try {
fileFullPath = writeFile(filePrefix, BasicProcessStatus.NEW_ALL_BUS_ORDER, JSONUtil.toJsonStr(spsSyncBusOrderResponse));
} catch (IOException e) {
e.printStackTrace();
}
basicDownloadStatusEntity.setCacheFilePath(fileFullPath);
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
return ResultVOUtils.success("上传成功!");
}
//接收中继服务、UDI管理系统上传单据类型
@AuthRuleAnnotation("")
@PostMapping("sps/sync/busType/upload")
public BaseResponse uploadBusType(@RequestBody SpsSyncBusResponse syncDataResponse) {
if (syncDataResponse != null) {
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(syncDataResponse.getTaskId());
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_BUS_TYPE);
basicDownloadStatusEntity.setStatus(0);
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_BUS);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
StringBuffer remark = new StringBuffer();
// 扫码单据类型
if (CollUtil.isNotEmpty(syncDataResponse.getBussinessTypeEntities())) {
try {
List<BasicBussinessTypeEntity> bussinessTypeEntities = syncDataResponse.getBussinessTypeEntities();
BasicBussinessTypeDao mapper = batchSession.getMapper(BasicBussinessTypeDao.class);
for (BasicBussinessTypeEntity bussinessTypeEntity : bussinessTypeEntities) {
mapper.insertOrUpdate(bussinessTypeEntity);
}
batchSession.commit();
remark.append("扫码单据类型:").append(syncDataResponse.getBussinessTypeEntities().size()).append("条\n");
} catch (Exception e) {
e.printStackTrace();
}
}
//业务单据
if (CollUtil.isNotEmpty(syncDataResponse.getBusTypeChangeEntities())) {
try {
List<BasicBusTypeChangeEntity> busTypeChangeEntities = syncDataResponse.getBusTypeChangeEntities();
BasicBusTypeChangeDao mapper = batchSession.getMapper(BasicBusTypeChangeDao.class);
busTypeChangeEntities.forEach(busTypeChangeEntity ->
{
mapper.insertOrUpdateEntity(busTypeChangeEntity);
});
batchSession.commit();
remark.append("业务单据类型:").append(syncDataResponse.getBussinessTypeEntities().size()).append("条\n");
} catch (Exception e) {
e.printStackTrace();
}
}
//原始单据
if (CollUtil.isNotEmpty(syncDataResponse.getThrBusTypeOriginEntities())) {
try {
List<ThrBusTypeOriginEntity> bussinessTypeEntities = syncDataResponse.getThrBusTypeOriginEntities();
ThrBusTypeOriginDao mapper = batchSession.getMapper(ThrBusTypeOriginDao.class);
for (ThrBusTypeOriginEntity bussinessTypeEntity : bussinessTypeEntities) {
mapper.insertOrUpdate(bussinessTypeEntity);
}
batchSession.commit();
remark.append("第三方单据类型:").append(syncDataResponse.getBussinessTypeEntities().size()).append("条\n");
} catch (Exception e) {
e.printStackTrace();
}
}
batchSession.close();
basicDownloadStatusEntity.setStatus(1);
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setRemark(remark.toString());
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
}
return ResultVOUtils.success("上传成功!");
}
//接收中继服务、UDI管理系统上传用户数据
@AuthRuleAnnotation("")
@PostMapping("sps/sync/userData/upload")
public BaseResponse uploadUserData(@RequestBody SpsSyncDataResponse syncDataResponse) {
if (syncDataResponse != null) {
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(syncDataResponse.getTaskId());
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_BASIC_DATA);
basicDownloadStatusEntity.setStatus(0);
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_DATA);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
StringBuffer remark = new StringBuffer();
//用户表
if (CollUtil.isNotEmpty(syncDataResponse.getAuthAdminList())) {
for (AuthAdmin authAdmin : syncDataResponse.getAuthAdminList()) {
authAdmin.setId(null);
authAdminDao.insertOrUpdate(authAdmin);
remark.append("用户信息:").append(syncDataResponse.getAuthAdminList().size()).append("条\n");
}
}
//用户对应单据类型
if (CollUtil.isNotEmpty(syncDataResponse.getInvBusUserEntities())) {
for (InvBusUserEntity invBusUserEntity : syncDataResponse.getInvBusUserEntities()) {
invBusUserDao.insertOrUpdate(invBusUserEntity);
}
}
// 部门信息
if (CollUtil.isNotEmpty(syncDataResponse.getDeptEntityList())) {
for (DeptEntity deptEntity : syncDataResponse.getDeptEntityList()) {
deptDao.insertOrUpdate(deptEntity);
}
}
// 部门信息关联用户信息
if (CollUtil.isNotEmpty(syncDataResponse.getDeptUserEntities())) {
for (DeptUserEntity deptUserEntity : syncDataResponse.getDeptUserEntities()) {
deptUserDao.insertOrUpdate(deptUserEntity);
}
}
//仓库字典导入
if (CollUtil.isNotEmpty(syncDataResponse.getInvWarehouseEntities())) {
for (InvWarehouseEntity invWarehouseEntity : syncDataResponse.getInvWarehouseEntities()) {
invWarehouseDao.insertOrUpdate(invWarehouseEntity);
}
remark.append("仓库字典:").append(syncDataResponse.getInvWarehouseEntities().size()).append("条\n");
}
//仓库用户表
if (CollUtil.isNotEmpty(syncDataResponse.getWarehouseUserEntities())) {
for (WarehouseUserEntity warehouseUserEntity : syncDataResponse.getWarehouseUserEntities()) {
warehouseUserDao.insertOrUpdateEntity(warehouseUserEntity);
}
remark.append("仓库用户信息:").append(syncDataResponse.getWarehouseUserEntities().size()).append("条\n");
}
//仓库单据类型表
if (CollUtil.isNotEmpty(syncDataResponse.getWarehouseBussinessTypeEntities())) {
for (WarehouseBussinessTypeEntity warehouseUserEntity : syncDataResponse.getWarehouseBussinessTypeEntities()) {
warehouseBussinessTypeDao.insertOrUpdate(warehouseUserEntity);
}
remark.append("仓库所属单据类型:").append(syncDataResponse.getWarehouseBussinessTypeEntities().size()).append("条\n");
}
batchSession.close();
basicDownloadStatusEntity.setStatus(1);
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setRemark(remark.toString());
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
}
return ResultVOUtils.success("上传成功!");
}
//接收中继服务、UDI管理系统上传基础信息
//@AuthRuleAnnotation("")
@PostMapping("/sps/sync/thrData/upload")
public BaseResponse uploadThrData(@RequestBody @Valid SpsSyncThrDataResponse spsSyncThrDataResponse) {
if (spsSyncThrDataResponse != null) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(spsSyncThrDataResponse.getTaskId());
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_THR_DATA);
basicDownloadStatusEntity.setStatus(0);
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_THR_DATA);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
StringBuilder remark = new StringBuilder();
//第三方部门信息
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getDeptEntities())) {
List<ThrDeptEntity> deptEntities = spsSyncThrDataResponse.getDeptEntities();
ThrDeptDao mapper = sqlSession.getMapper(ThrDeptDao.class);
deptEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("第三方部门信息:").append(spsSyncThrDataResponse.getDeptEntities().size()).append("条\n");
//第三方仓库信息
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getInvWarehouseEntities())) {
List<ThrInvWarehouseEntity> invWarehouseEntities = spsSyncThrDataResponse.getInvWarehouseEntities();
ThrInvWarehouseDao mapper = sqlSession.getMapper(ThrInvWarehouseDao.class);
invWarehouseEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("第三方仓库信息:").append(spsSyncThrDataResponse.getInvWarehouseEntities().size()).append("条\n");
//第三方往来单位信息
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getCorpEntities())) {
List<ThrCorpEntity> corpEntities = spsSyncThrDataResponse.getCorpEntities();
ThrCorpDao mapper = sqlSession.getMapper(ThrCorpDao.class);
corpEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("第三方往来单位信息:").append(spsSyncThrDataResponse.getCorpEntities().size()).append("条\n");
sqlSession.close();
basicDownloadStatusEntity.setStatus(1);
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setRemark(remark.toString());
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
}
return ResultVOUtils.success("上传成功");
}
//接收中继服务、UDI管理系统上传系统设置
//@AuthRuleAnnotation("")
@PostMapping("/sps/sync/sys/setting")
public BaseResponse uploadSysSetting(@RequestBody @Valid SpsSyncSysSettingResponse spsSyncSysSettingResponse) {
if (spsSyncSysSettingResponse != null) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(spsSyncSysSettingResponse.getTaskId());
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_SYS_SETTING);
basicDownloadStatusEntity.setStatus(0);
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_SYS_SETTING);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
StringBuilder remark = new StringBuilder();
//系统运行参数
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSystemParamConfigEntities())) {
List<SystemParamConfigEntity> systemParamConfigEntities = spsSyncSysSettingResponse.getSystemParamConfigEntities();
SystemParamConfigDao mapper = sqlSession.getMapper(SystemParamConfigDao.class);
systemParamConfigEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("系统运行参数:").append(spsSyncSysSettingResponse.getSystemParamConfigEntities().size()).append("条\n");
//委托验收设置
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getEntrustReceEntities())) {
List<EntrustReceEntity> entrustReceEntities = spsSyncSysSettingResponse.getEntrustReceEntities();
EntrustReceDao mapper = sqlSession.getMapper(EntrustReceDao.class);
entrustReceEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("委托验收设置:").append(spsSyncSysSettingResponse.getEntrustReceEntities().size()).append("条\n");
//打印模块
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSystemPDFModuleEntities())) {
List<SystemPDFModuleEntity> systemPDFModuleEntities = spsSyncSysSettingResponse.getSystemPDFModuleEntities();
SystemPDFModuleDao mapper = sqlSession.getMapper(SystemPDFModuleDao.class);
systemPDFModuleEntities.forEach(mapper::insertOrUpdate);
}
sqlSession.commit();
remark.append("打印模块:").append(spsSyncSysSettingResponse.getSystemPDFModuleEntities().size()).append("条\n");
//打印模板
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSystemPDFTemplateEntities())) {
List<SystemPDFTemplateEntity> systemPDFTemplateEntities = spsSyncSysSettingResponse.getSystemPDFTemplateEntities();
SystemPDFTemplateDao mapper = sqlSession.getMapper(SystemPDFTemplateDao.class);
systemPDFTemplateEntities.forEach(mapper::insertOrUpdate);
}
sqlSession.commit();
remark.append("打印模板:").append(spsSyncSysSettingResponse.getSystemPDFTemplateEntities().size()).append("条\n");
//扫码单据关联表
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSysPdfTemplateRelevanceCodeEntities())) {
List<SysPdfTemplateRelevanceCodeEntity> sysPdfTemplateRelevanceCodeEntities = spsSyncSysSettingResponse.getSysPdfTemplateRelevanceCodeEntities();
SysPdfTemplateRelevanceCodeDao mapper = sqlSession.getMapper(SysPdfTemplateRelevanceCodeDao.class);
sysPdfTemplateRelevanceCodeEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("扫码单据关联表:").append(spsSyncSysSettingResponse.getSysPdfTemplateRelevanceCodeEntities().size()).append("条\n");
//业务单据关联表
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSysPdfTemplateRelevanceBizEntities())) {
List<SysPdfTemplateRelevanceBizEntity> sysPdfTemplateRelevanceBizEntities = spsSyncSysSettingResponse.getSysPdfTemplateRelevanceBizEntities();
SysPdfTemplateRelevanceBizDao mapper = sqlSession.getMapper(SysPdfTemplateRelevanceBizDao.class);
sysPdfTemplateRelevanceBizEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("业务单据关联表:").append(spsSyncSysSettingResponse.getSysPdfTemplateRelevanceBizEntities().size()).append("条\n");
//内部码打印关联表
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSysPdfTemplateRelevanceLabelEntities())) {
List<SysPdfTemplateRelevanceLabelEntity> sysPdfTemplateRelevanceLabelEntities = spsSyncSysSettingResponse.getSysPdfTemplateRelevanceLabelEntities();
SysPdfTemplateRelevanceLabelDao mapper = sqlSession.getMapper(SysPdfTemplateRelevanceLabelDao.class);
sysPdfTemplateRelevanceLabelEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("内部码打印关联表:").append(spsSyncSysSettingResponse.getSystemParamConfigEntities().size()).append("条\n");
//资质证书打印关联表
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSysPdfTemplateRelevanceStatemenEntities())) {
List<SysPdfTemplateRelevanceStatemenEntity> sysPdfTemplateRelevanceStatemenEntities = spsSyncSysSettingResponse.getSysPdfTemplateRelevanceStatemenEntities();
SysPdfTemplateRelevanceStatemenDao mapper = sqlSession.getMapper(SysPdfTemplateRelevanceStatemenDao.class);
sysPdfTemplateRelevanceStatemenEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("资质证书打印关联表:").append(spsSyncSysSettingResponse.getSysPdfTemplateRelevanceStatemenEntities().size()).append("条\n");
//自动建出入库单设置
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getBasicBusTypePreEntities())) {
List<BasicBusTypePreEntity> basicBusTypePreEntities = spsSyncSysSettingResponse.getBasicBusTypePreEntities();
BasicBusTypePreDao mapper = sqlSession.getMapper(BasicBusTypePreDao.class);
basicBusTypePreEntities.forEach(mapper::insertOrUpdate);
}
sqlSession.commit();
remark.append("自动建出入库单设置:").append(spsSyncSysSettingResponse.getBasicBusTypePreEntities().size()).append("条\n");
//自动建业务单设置
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getBasicBusTypeChangeEntities())) {
List<BasicBusTypeChangeEntity> basicBusTypeChangeEntities = spsSyncSysSettingResponse.getBasicBusTypeChangeEntities();
BasicBusTypeChangeDao mapper = sqlSession.getMapper(BasicBusTypeChangeDao.class);
basicBusTypeChangeEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("自动建业务单设置:").append(spsSyncSysSettingResponse.getBasicBusTypeChangeEntities().size()).append("条\n");
sqlSession.close();
basicDownloadStatusEntity.setStatus(1);
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setRemark(remark.toString());
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
}
return ResultVOUtils.success("上传成功");
}
//接收中继服务、UDI管理系统上传第三方产品信息
//@AuthRuleAnnotation("")
@PostMapping("/sps/sync/thrData/products/upload")
public BaseResponse uploadThrProducts(@RequestBody @Valid SpsSyncThrProductsResponse spsSyncThrProductsResponse) {
if (spsSyncThrProductsResponse != null) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(spsSyncThrProductsResponse.getTaskId());
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_THR_PRODUCTS);
basicDownloadStatusEntity.setStatus(0);
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_THR_PRODUCTS);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
StringBuilder remark = new StringBuilder();
//第三方产品信息
if (CollUtil.isNotEmpty(spsSyncThrProductsResponse.getProductsEntities())) {
List<ThrProductsEntity> productsEntities = spsSyncThrProductsResponse.getProductsEntities();
ThrProductsDao mapper = sqlSession.getMapper(ThrProductsDao.class);
productsEntities.forEach(mapper::insertOrUpdateEntity);
}
sqlSession.commit();
remark.append("第三方产品信息:").append(spsSyncThrProductsResponse.getProductsEntities().size()).append("条\n");
sqlSession.close();
basicDownloadStatusEntity.setStatus(1);
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setRemark(remark.toString());
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
}
return ResultVOUtils.success("上传成功");
}
@GetMapping("/sps/sync/download/info/file")
public void downloadFile(HttpServletResponse response, String id) {
if (StrUtil.isBlank(id)) {
throw new RuntimeException("缺少唯一标识");
}
BasicDownloadStatusEntity info = basicDownloadService.getById(id);
if (info == null) {
throw new RuntimeException("数据不存在");
}
if (StrUtil.isBlank(info.getCacheFilePath())) {
throw new RuntimeException("文件未生成");
}
File file = new File(info.getCacheFilePath());
if (!file.exists()) {
throw new RuntimeException("文件丢失");
}
String[] split = info.getCacheFilePath().split("/");
String enFileName = URLEncoder.encode(split[split.length - 1], StandardCharsets.UTF_8);
// 设值返回文件属性,浏览器会根据属性调用下载文件方法
response.addHeader("Content-Disposition", "attachment;filename=" + enFileName);
// 前端获取文件名,需要解码
response.addHeader("downLoadName", enFileName);
// 定义输出流
ServletOutputStream outputStream = null;
FileInputStream fileInputStream = null;
try {
outputStream = response.getOutputStream();
// 定义输出类型为二进制流输出
response.setContentType("application/octet-stream");
fileInputStream = new FileInputStream(file);
byte[] bytes = new byte[fileInputStream.available()];
fileInputStream.read(bytes);
// 把流写入response
outputStream.write(bytes);
// flush落盘
outputStream.flush();
// 关闭输出流
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}