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-wms-java/src/main/java/com/glxp/api/service/thrsys/ThrOrdersDlService.java

682 lines
39 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.service.thrsys;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.config.WebSocketServer;
import com.glxp.api.constant.BasicProcessStatus;
import com.glxp.api.constant.Constant;
import com.glxp.api.entity.system.SyncDataSetEntity;
import com.glxp.api.entity.thrsys.*;
import com.glxp.api.http.ErpOrderClient;
import com.glxp.api.http.HttpOkClient;
import com.glxp.api.req.thrsys.FilterThrOrderDetailRequest;
import com.glxp.api.req.thrsys.FilterThrOrderRequest;
import com.glxp.api.req.thrsys.PostThrOrderRequest;
import com.glxp.api.req.thrsys.ThrOrderExportRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.thrsys.ThrOrderResponse;
import com.glxp.api.service.system.SyncDataSetService;
import com.glxp.api.util.RedisUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class ThrOrdersDlService {
// @Value("${SPSYNC_IP}")
// private String spsSyncUrl;
@Resource
ThrOrderService thrOrderService;
@Resource
ThrOrderDetailService thrOrderDetailService;
@Resource
ThrSystemDetailService thrSystemDetailService;
@Resource
RedisUtil redisUtil;
@Resource
private ThrOrderImportLogService thrOrderImportLogService;
@Resource
ThrOrderExportLogService thrOrderExportLogService;
@Resource
ThrOrderImportDetailService thrOrderImportDetailService;
// @Resource
// ThrOrderImportService thrOrderImportService;
@Resource
private ErpOrderClient erpOrderClient;
@Resource
SyncDataSetService syncDataSetService;
@Resource
HttpOkClient httpOkClient;
public String getIpUrl() {
SyncDataSetEntity syncDataSetEntity = syncDataSetService.findSet();
return syncDataSetEntity.getSyncIp();
}
@Async
public void importOrders(String genKey, String action, FilterThrOrderRequest filterThrProductsRequest) {
ThrOrderImportLogEntity thrOrderImportLogEntity = thrOrderImportLogService.selectByGenKey(genKey);
//todo单据还没设计好
// BasicThirdSysDetailEntity basicThirdSysDetailEntity = bussinessTypeService.findByActionKey(action, "orderQueryUrl");
// if (basicThirdSysDetailEntity == null || basicThirdSysDetailEntity.getValue() == null) {
// WebSocketServer.sendInfo("业务单据查询接口未设置!", "sid");
// return;
// }
ThrSystemDetailEntity thrSystemDetailEntity=new ThrSystemDetailEntity();
int page = 1;
int limit = 100;
while (page != -1) {
page = getOrders(page, limit, thrSystemDetailEntity.getValue(), thrSystemDetailEntity.getThirdSysFk(), thrOrderImportLogEntity, action, filterThrProductsRequest);
}
thrOrderImportLogService.importThrOrder(genKey);
redisUtil.set(Constant.dlThrProducts, "false");
WebSocketServer.sendInfo("业务单据信息下载已完成,请刷新查看!", "sid");
thrOrderImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
thrOrderImportLogService.updateImportLog(thrOrderImportLogEntity);
}
@Async
public void importSelectOrders(String genKey, List<ThrOrderResponse> erpOrderResponses, String thirdSys) {
ThrOrderImportLogEntity thrOrderImportLogEntity = thrOrderImportLogService.selectByGenKey(genKey);
if (erpOrderResponses != null && erpOrderResponses.size() > 0) {
for (ThrOrderResponse erpOrderResponse : erpOrderResponses) {
List<ThrOrderImportDetailEntity> thrOrderDetailEntities = new ArrayList<>();
for (ThrOrderResponse.SubErpOrder subPurchase : erpOrderResponse.getSubErpOrders()) {
ThrOrderImportDetailEntity thrOrderDetailEntity = new ThrOrderImportDetailEntity();
BeanUtils.copyProperties(subPurchase, thrOrderDetailEntity);
BeanUtils.copyProperties(erpOrderResponse, thrOrderDetailEntity);
thrOrderDetailEntity.setGenKeyFk(thrOrderImportLogEntity.getGenKey());
thrOrderDetailEntity.setThirdSysFk(thirdSys);
thrOrderDetailEntity.setUpdateTime(new Date());
thrOrderDetailEntities.add(thrOrderDetailEntity);
}
thrOrderImportDetailService.insertOrderImportDetails(thrOrderDetailEntities);
}
}
thrOrderImportLogService.importThrOrder(genKey);
redisUtil.set(Constant.dlThrProducts, "false");
WebSocketServer.sendInfo("业务单据信息下载已完成,请刷新查看!", "sid");
thrOrderImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
thrOrderImportLogService.updateImportLog(thrOrderImportLogEntity);
}
@Async
public void genExcel(String genKey, ThrOrderExportRequest thrOrderExportRequest) {
ThrOrderExportLogEntity thrOrderExportLogEntity = thrOrderExportLogService.selectByGenKey(genKey);
List<List<String>> excelData = new ArrayList<>();
List<String> head = new ArrayList<>();
head.add("单据号");
head.add("单据日期");
head.add("往来单位ID");
head.add("往来单位名称");
head.add("单据类型");
head.add("单据状态");
head.add("产品ID");
head.add("产品名称");
head.add("规格型号");
head.add("批次号");
head.add("生产日期");
head.add("失效日期");
head.add("订单数量");
head.add("实际数量");
head.add("原单据类型");
excelData.add(head);
//todo改功能有关表还未设计
// BussinessTypeEntity bussinessTypeEntity = bussinessTypeService.findBTByAction(thrOrderExportRequest.getBillAction());
//
// //选中导出
// if (thrOrderExportRequest.getErpOrderResponses() != null && thrOrderExportRequest.getErpOrderResponses().size() > 0) {
// BussinessTypeFilterRequest bussinessTypeFilterRequest = new BussinessTypeFilterRequest();
// bussinessTypeFilterRequest.setEnabled(true);
// List<BussinessTypeEntity> bussinessTypeEntities = bussinessTypeService.filterList(bussinessTypeFilterRequest);
// List<ErpOrderResponse> erpOrderResponses = thrOrderExportRequest.getErpOrderResponses();
// for (ErpOrderResponse erpOrderResponse : erpOrderResponses) {
// List<ErpOrderResponse.SubErpOrder> subErpOrders = erpOrderResponse.getSubErpOrders();
// for (ErpOrderResponse.SubErpOrder subErpOrder : subErpOrders) {
// List<String> rows = new ArrayList<>();
// rows.add(erpOrderResponse.getBillNo());
// rows.add(erpOrderResponse.getBilldate());
//// BasicUnitMaintainEntity basicUnitMaintainEntity = basicUnitMaintainService.selectByThirdId(erpOrderResponse.getCorpId(), bussinessTypeEntity.getThirdSysFk());
//// if (basicUnitMaintainEntity != null)
//// rows.add(basicUnitMaintainEntity.getErpId());
//// else
// rows.add(erpOrderResponse.getCorpId());
//
// rows.add(erpOrderResponse.getCorpName());
// rows.add(getName(bussinessTypeEntities, erpOrderResponse.getBillType()));
// rows.add(erpOrderResponse.getBillFlag());
// rows.add(subErpOrder.getProductId());
// rows.add(subErpOrder.getProductName());
// rows.add(subErpOrder.getSpec());
// rows.add(subErpOrder.getBatchNo());
// rows.add(subErpOrder.getProductDate());
// rows.add(subErpOrder.getExpireDate());
// rows.add(subErpOrder.getCount() + "");
// rows.add(subErpOrder.getReCount() + "");
// rows.add(erpOrderResponse.getOriginType());
// excelData.add(rows);
// }
//
// }
//
// } else {//一键导出
//
// BasicThirdSysDetailEntity basicThirdSysDetailEntity = thrSystemDetailService.selectByKey("orderQueryUrl", bussinessTypeEntity.getThirdSysFk());
//
// if (basicThirdSysDetailEntity == null || basicThirdSysDetailEntity.getValue() == null) {
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
// thrOrderExportLogEntity.setRemark("业务单据接口地址未定义");
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// return;
// }
// if (!basicThirdSysDetailEntity.getEnabled() || basicThirdSysDetailEntity.getThirdSysFk() == null) {
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
// thrOrderExportLogEntity.setRemark("第三方系统业务单据接口服务未启用");
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// return;
// }
//
//
// if (basicThirdSysDetailEntity.getFromType() == 0) {
// FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
// filterThrOrderRequest.setThirdSysFk(bussinessTypeEntity.getThirdSysFk());
// BeanUtils.copyProperties(thrOrderExportRequest, filterThrOrderRequest);
// List<List<String>> datas = exportThrOrders(filterThrOrderRequest);
// excelData.addAll(datas);
// } else {
// FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
// BeanUtils.copyProperties(thrOrderExportRequest, filterThrOrderRequest);
// List<List<String>> genDatas = genExcelData(filterThrOrderRequest);
// if (genDatas != null && genDatas.size() > 0) {
// excelData.addAll(genDatas);
// }
// }
//
// }
// String sheetName = "业务单据";
// new ExcelUtil().exportExcel(excelData, sheetName, thrOrderExportLogEntity.getFilePath(), 20);
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
}
//
//
// @Async
// public void genJsonFile(String genKey, ThrOrderExportRequest thrOrderExportRequest) {
// ThrOrderExportJsonResponse thrOrderExportJsonResponse = new ThrOrderExportJsonResponse();
// ThrOrderExportLogEntity thrOrderExportLogEntity = thrOrderExportLogService.selectByGenKey(genKey);
// BussinessTypeEntity bussinessTypeEntity = bussinessTypeService.findBTByAction(thrOrderExportRequest.getBillAction());
// List<ErpOrderResponse> erpOrderResponses = thrOrderExportRequest.getErpOrderResponses();
// //选中导出
// if (thrOrderExportRequest.getErpOrderResponses() != null && thrOrderExportRequest.getErpOrderResponses().size() > 0) {
// BussinessTypeFilterRequest bussinessTypeFilterRequest = new BussinessTypeFilterRequest();
// bussinessTypeFilterRequest.setEnabled(true);
// if (erpOrderResponses != null && erpOrderResponses.size() > 0) {
// List<ThrOrderEntity> thrOrderEntities = new ArrayList<>();
// List<ThrOrderDetailEntity> thrOrderDetailEntities = new ArrayList<>();
// for (ErpOrderResponse erpOrderResponse : erpOrderResponses) {
// ThrOrderEntity thrOrderEntity = new ThrOrderEntity();
// BeanUtils.copyProperties(erpOrderResponse, thrOrderEntity);
// thrOrderEntities.add(thrOrderEntity);
// if (erpOrderResponse.getSubErpOrders() != null && erpOrderResponse.getSubErpOrders().size() > 0) {
// for (ErpOrderResponse.SubErpOrder subErpOrder : erpOrderResponse.getSubErpOrders()) {
// ThrOrderDetailEntity thrOrderDetailEntity = new ThrOrderDetailEntity();
// BeanUtils.copyProperties(subErpOrder, thrOrderDetailEntity);
// thrOrderDetailEntities.add(thrOrderDetailEntity);
// }
// }
// }
// thrOrderExportJsonResponse.setThrOrderEntityList(thrOrderEntities);
// thrOrderExportJsonResponse.setThrOrderDetailEntities(thrOrderDetailEntities);
// }
// } else {//一键导出
// BasicThirdSysDetailEntity basicThirdSysDetailEntity = basicThirdSysDetailService.selectByKey("orderQueryUrl", bussinessTypeEntity.getThirdSysFk());
// if (basicThirdSysDetailEntity == null || basicThirdSysDetailEntity.getValue() == null) {
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
// thrOrderExportLogEntity.setRemark("业务单据接口地址未定义");
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// return;
// }
// if (!basicThirdSysDetailEntity.getEnabled() || basicThirdSysDetailEntity.getThirdSysFk() == null) {
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
// thrOrderExportLogEntity.setRemark("第三方系统业务单据接口服务未启用");
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// return;
// }
// if (basicThirdSysDetailEntity.getFromType() == 0) {
// FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
// filterThrOrderRequest.setThirdSysFk(bussinessTypeEntity.getThirdSysFk());
// BeanUtils.copyProperties(thrOrderExportRequest, filterThrOrderRequest);
// erpOrderResponses = getThrOrders(filterThrOrderRequest);
// if (erpOrderResponses != null && erpOrderResponses.size() > 0) {
// List<ThrOrderEntity> thrOrderEntities = new ArrayList<>();
// List<ThrOrderDetailEntity> thrOrderDetailEntities = new ArrayList<>();
// for (ErpOrderResponse erpOrderResponse : erpOrderResponses) {
// ThrOrderEntity thrOrderEntity = new ThrOrderEntity();
// BeanUtils.copyProperties(erpOrderResponse, thrOrderEntity);
// thrOrderEntities.add(thrOrderEntity);
// if (erpOrderResponse.getSubErpOrders() != null && erpOrderResponse.getSubErpOrders().size() > 0) {
// for (ErpOrderResponse.SubErpOrder subErpOrder : erpOrderResponse.getSubErpOrders()) {
// ThrOrderDetailEntity thrOrderDetailEntity = new ThrOrderDetailEntity();
// BeanUtils.copyProperties(subErpOrder, thrOrderDetailEntity);
// thrOrderDetailEntities.add(thrOrderDetailEntity);
// }
// }
// }
// thrOrderExportJsonResponse.setThrOrderEntityList(thrOrderEntities);
// thrOrderExportJsonResponse.setThrOrderDetailEntities(thrOrderDetailEntities);
// }
// } else {
// FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
// BeanUtils.copyProperties(thrOrderExportRequest, filterThrOrderRequest);
// List<ThrOrderEntity> thrOrderEntities = thrOrderService.filterThrOrder(filterThrOrderRequest);
// List<ThrOrderDetailEntity> results = new ArrayList<>();
// for (ThrOrderEntity thrOrderEntity : thrOrderEntities) {
// FilterThrOrderDetailRequest filterThrOrderDetailRequest = new FilterThrOrderDetailRequest();
// filterThrOrderDetailRequest.setOrderIdFk(thrOrderEntity.getId() + "");
// List<ThrOrderDetailEntity> thrOrderDetailEntities = thrOrderDetailService.filterThrOrderDetailDetail(filterThrOrderDetailRequest);
// if (thrOrderDetailEntities != null) {
// results.addAll(thrOrderDetailEntities);
// }
//
// }
//
// thrOrderExportJsonResponse.setThrOrderEntityList(thrOrderEntities);
// thrOrderExportJsonResponse.setThrOrderDetailEntities(results);
// }
//
// }
// FileWriter writer = new FileWriter(thrOrderExportLogEntity.getFilePath());
// writer.write(JSONUtil.toJsonStr(thrOrderExportJsonResponse));
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// }
//
//
// @Async
// public void uploadSpssync(String genKey, ThrOrderExportRequest thrOrderExportRequest) {
//
// ThrOrderExportJsonResponse thrOrderExportJsonResponse = new ThrOrderExportJsonResponse();
// ThrOrderExportLogEntity thrOrderExportLogEntity = thrOrderExportLogService.selectByGenKey(genKey);
// BussinessTypeEntity bussinessTypeEntity = bussinessTypeService.findBTByAction(thrOrderExportRequest.getBillAction());
// List<ErpOrderResponse> erpOrderResponses = thrOrderExportRequest.getErpOrderResponses();
// //选中导出
// if (thrOrderExportRequest.getErpOrderResponses() != null && thrOrderExportRequest.getErpOrderResponses().size() > 0) {
// BussinessTypeFilterRequest bussinessTypeFilterRequest = new BussinessTypeFilterRequest();
// bussinessTypeFilterRequest.setEnabled(true);
// if (erpOrderResponses != null && erpOrderResponses.size() > 0) {
// List<ThrOrderEntity> thrOrderEntities = new ArrayList<>();
// List<ThrOrderDetailEntity> thrOrderDetailEntities = new ArrayList<>();
// for (ErpOrderResponse erpOrderResponse : erpOrderResponses) {
// ThrOrderEntity thrOrderEntity = new ThrOrderEntity();
// BeanUtils.copyProperties(erpOrderResponse, thrOrderEntity);
// thrOrderEntities.add(thrOrderEntity);
// if (erpOrderResponse.getSubErpOrders() != null && erpOrderResponse.getSubErpOrders().size() > 0) {
// for (ErpOrderResponse.SubErpOrder subErpOrder : erpOrderResponse.getSubErpOrders()) {
// ThrOrderDetailEntity thrOrderDetailEntity = new ThrOrderDetailEntity();
// BeanUtils.copyProperties(subErpOrder, thrOrderDetailEntity);
// thrOrderDetailEntities.add(thrOrderDetailEntity);
// }
// }
// }
// thrOrderExportJsonResponse.setThrOrderEntityList(thrOrderEntities);
// thrOrderExportJsonResponse.setThrOrderDetailEntities(thrOrderDetailEntities);
// }
// } else {//一键导出
// BasicThirdSysDetailEntity basicThirdSysDetailEntity = basicThirdSysDetailService.selectByKey("orderQueryUrl", bussinessTypeEntity.getThirdSysFk());
// if (basicThirdSysDetailEntity == null || basicThirdSysDetailEntity.getValue() == null) {
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
// thrOrderExportLogEntity.setRemark("业务单据接口地址未定义");
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// return;
// }
// if (!basicThirdSysDetailEntity.getEnabled() || basicThirdSysDetailEntity.getThirdSysFk() == null) {
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
// thrOrderExportLogEntity.setRemark("第三方系统业务单据接口服务未启用");
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// return;
// }
// if (basicThirdSysDetailEntity.getFromType() == 0) {
// FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
// filterThrOrderRequest.setThirdSysFk(bussinessTypeEntity.getThirdSysFk());
// BeanUtils.copyProperties(thrOrderExportRequest, filterThrOrderRequest);
// erpOrderResponses = getThrOrders(filterThrOrderRequest);
// if (erpOrderResponses != null && erpOrderResponses.size() > 0) {
// List<ThrOrderEntity> thrOrderEntities = new ArrayList<>();
// List<ThrOrderDetailEntity> thrOrderDetailEntities = new ArrayList<>();
// for (ErpOrderResponse erpOrderResponse : erpOrderResponses) {
// ThrOrderEntity thrOrderEntity = new ThrOrderEntity();
// BeanUtils.copyProperties(erpOrderResponse, thrOrderEntity);
// thrOrderEntities.add(thrOrderEntity);
// if (erpOrderResponse.getSubErpOrders() != null && erpOrderResponse.getSubErpOrders().size() > 0) {
// for (ErpOrderResponse.SubErpOrder subErpOrder : erpOrderResponse.getSubErpOrders()) {
// ThrOrderDetailEntity thrOrderDetailEntity = new ThrOrderDetailEntity();
// BeanUtils.copyProperties(subErpOrder, thrOrderDetailEntity);
// thrOrderDetailEntities.add(thrOrderDetailEntity);
// }
// }
// }
// thrOrderExportJsonResponse.setThrOrderEntityList(thrOrderEntities);
// thrOrderExportJsonResponse.setThrOrderDetailEntities(thrOrderDetailEntities);
// }
// } else {
// FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
// BeanUtils.copyProperties(thrOrderExportRequest, filterThrOrderRequest);
// List<ThrOrderEntity> thrOrderEntities = thrOrderService.filterThrOrder(filterThrOrderRequest);
// List<ThrOrderDetailEntity> results = new ArrayList<>();
// for (ThrOrderEntity thrOrderEntity : thrOrderEntities) {
// FilterThrOrderDetailRequest filterThrOrderDetailRequest = new FilterThrOrderDetailRequest();
// filterThrOrderDetailRequest.setOrderIdFk(thrOrderEntity.getId() + "");
// List<ThrOrderDetailEntity> thrOrderDetailEntities = thrOrderDetailService.filterThrOrderDetailDetail(filterThrOrderDetailRequest);
// if (thrOrderDetailEntities != null) {
// results.addAll(thrOrderDetailEntities);
// }
//
// }
//
// thrOrderExportJsonResponse.setThrOrderEntityList(thrOrderEntities);
// thrOrderExportJsonResponse.setThrOrderDetailEntities(results);
// }
//
// }
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// String response = httpOkClient.uCloudPost(getIpUrl() + "/spssync/thirdsys/order/upload", thrOrderExportJsonResponse);
// BaseResponse baseResponse = JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
// });
// if (baseResponse.getCode() == 20000) {
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
// } else {
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
// }
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
// thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
// }
//
// public String getName(List<BussinessTypeEntity> bussinessTypeEntities, String action) {
// for (BussinessTypeEntity bussinessTypeEntity : bussinessTypeEntities) {
// if (bussinessTypeEntity.getAction().equals(action)) {
// return bussinessTypeEntity.getName();
// }
// }
// return action;
// }
//
@Async
public void uploadSmp(String genKey, ThrOrderExportRequest thrOrderExportRequest) {
ThrOrderExportLogEntity thrOrderExportLogEntity = thrOrderExportLogService.selectByGenKey(genKey);
PostThrOrderRequest postThrOrderRequest = new PostThrOrderRequest();
//选中导出
if (thrOrderExportRequest.getErpOrderResponses() != null && thrOrderExportRequest.getErpOrderResponses().size() > 0) {
List<ThrOrderResponse> erpOrderResponses = thrOrderExportRequest.getErpOrderResponses();
postThrOrderRequest.setDatas(erpOrderResponses);
} else {//一键导出
List<ThrOrderResponse> erpOrderResponses = new ArrayList<>();
ThrSystemDetailEntity thrSystemDetailEntity = thrSystemDetailService.selectByKey("orderQueryUrl", thrOrderExportRequest.getThirdSysFk());
if (thrSystemDetailEntity == null || thrSystemDetailEntity.getValue() == null) {
thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
thrOrderExportLogEntity.setRemark("往来单位接口地址未定义");
thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
return;
}
if (!thrSystemDetailEntity.getEnabled()) {
thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
thrOrderExportLogEntity.setRemark("第三方接口往来单位服务接口未启用");
thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
return;
}
if (thrSystemDetailEntity.getFromType() == 0) {
FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
BeanUtils.copyProperties(thrOrderExportRequest, filterThrOrderRequest);
List<ThrOrderResponse> datas = getThrOrders(filterThrOrderRequest);
erpOrderResponses.addAll(datas);
} else {
FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
BeanUtils.copyProperties(thrOrderExportRequest, filterThrOrderRequest);
List<ThrOrderEntity> thrOrderEntities = thrOrderService.filterThrOrder(filterThrOrderRequest);
for (ThrOrderEntity thrOrderEntity : thrOrderEntities) {
ThrOrderResponse erpOrderResponse = new ThrOrderResponse();
BeanUtils.copyProperties(thrOrderEntity, erpOrderResponse);
FilterThrOrderDetailRequest filterThrOrderDetailRequest = new FilterThrOrderDetailRequest();
filterThrOrderDetailRequest.setOrderIdFk(thrOrderEntity.getId() + "");
List<ThrOrderDetailEntity> thrOrderDetailEntities = thrOrderDetailService.filterThrOrderDetailDetail(filterThrOrderDetailRequest);
if (thrOrderDetailEntities != null) {
List<ThrOrderResponse.SubErpOrder> subErpOrders = new ArrayList<>();
for (ThrOrderDetailEntity thrOrderDetailEntity : thrOrderDetailEntities) {
ThrOrderResponse.SubErpOrder subErpOrder = new ThrOrderResponse.SubErpOrder();
BeanUtils.copyProperties(thrOrderDetailEntity, subErpOrder);
subErpOrders.add(subErpOrder);
}
erpOrderResponse.setSubErpOrders(subErpOrders);
}
erpOrderResponses.add(erpOrderResponse);
}
}
postThrOrderRequest.setDatas(erpOrderResponses);
}
//toDo 上傳SMP
postThrOrderRequest.setGenKey(genKey);
postThrOrderRequest.setThirdSys(thrOrderExportRequest.getThirdSysFk());
// SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("smp_service_ip");
// if (systemParamConfigEntity != null) {
String response = httpOkClient.uCloudPost(getIpUrl() + "/udiwms/thrsys/postOrderDetail", postThrOrderRequest);
BaseResponse baseResponse = JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
});
if (baseResponse.getCode() == 20000) {
thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
} else {
thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
}
// } else {
// thrOrderExportLogEntity.setRemark("SMP服务IP地址未定义");
// thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
// }
thrOrderExportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_SUCCESS);
thrOrderExportLogService.updateThrOrderExportLog(thrOrderExportLogEntity);
}
public int getOrders(int page, int limit, String orderUrl, String thirdSys, ThrOrderImportLogEntity
thrOrderImportLogEntity, String action, FilterThrOrderRequest filterThrOrderRequest) {
if (filterThrOrderRequest == null)
filterThrOrderRequest = new FilterThrOrderRequest();
filterThrOrderRequest.setPage(page);
filterThrOrderRequest.setLimit(limit);
filterThrOrderRequest.setBillAction(action);
FilterThrOrderRequest filterOrderRequest = new FilterThrOrderRequest();
BeanUtils.copyProperties(filterThrOrderRequest, filterOrderRequest);
BaseResponse<PageSimpleResponse<ThrOrderResponse>> responseBaseResponse = erpOrderClient.getThrOrderResponse(filterOrderRequest);
if (responseBaseResponse != null && responseBaseResponse.getCode() == 20000) {
List<ThrOrderResponse> erpOrderResponses = responseBaseResponse.getData().getList();
if (erpOrderResponses != null && erpOrderResponses.size() > 0) {
for (ThrOrderResponse erpOrderResponse : erpOrderResponses) {
ThrOrderEntity thrOrderEntity = new ThrOrderEntity();
BeanUtils.copyProperties(erpOrderResponse, thrOrderEntity);
thrOrderEntity.setThirdSysFk(thirdSys);
thrOrderEntity.setUpdateTime(new Date());
thrOrderService.insertThrOrder(thrOrderEntity);
// thrOrderEntity = thrOrderService.findByUnique(thrOrderEntity.getBillNo(), thrOrderEntity.getThirdSysFk());
List<ThrOrderImportDetailEntity> thrOrderDetailEntities = new ArrayList<>();
for (ThrOrderResponse.SubErpOrder subPurchase : erpOrderResponse.getSubErpOrders()) {
ThrOrderImportDetailEntity thrOrderDetailEntity = new ThrOrderImportDetailEntity();
BeanUtils.copyProperties(subPurchase, thrOrderDetailEntity);
BeanUtils.copyProperties(erpOrderResponse, thrOrderDetailEntity);
thrOrderDetailEntity.setGenKeyFk(thrOrderImportLogEntity.getGenKey());
thrOrderDetailEntity.setThirdSysFk(thirdSys);
thrOrderDetailEntity.setUpdateTime(new Date());
thrOrderDetailEntities.add(thrOrderDetailEntity);
}
thrOrderImportDetailService.insertOrderImportDetails(thrOrderDetailEntities);
}
page++;
if (page * limit < responseBaseResponse.getData().getTotal()) {
return page;
}
}
} else {
thrOrderImportLogEntity.setStatus(BasicProcessStatus.UDIINFO_IMPORT_FAIL);
if (responseBaseResponse != null) {
thrOrderImportLogEntity.setRemark(responseBaseResponse.getMessage());
} else {
thrOrderImportLogEntity.setRemark("第三方服务出错!");
}
thrOrderImportLogService.updateImportLog(thrOrderImportLogEntity);
return -1;
}
return -1;
}
//
// public List<List<String>> exportThrOrders(FilterThrOrderRequest filterThrOrderRequest) {
// BussinessTypeFilterRequest bussinessTypeFilterRequest = new BussinessTypeFilterRequest();
// bussinessTypeFilterRequest.setEnabled(true);
// List<BussinessTypeEntity> bussinessTypeEntities = bussinessTypeService.filterList(bussinessTypeFilterRequest);
// BasicThirdSysDetailEntity basicThirdSysDetailEntity = basicThirdSysDetailService.selectByKey("orderQueryUrl", filterThrOrderRequest.getThirdSysFk());
// int page = 1;
// int limit = 100;
// List<ErpOrderResponse> erpOrderResponseList = new ArrayList<>();
// while (true) {
// List<ErpOrderResponse> datas = getThrOrders(page, limit, basicThirdSysDetailEntity.getValue(), filterThrOrderRequest);
// if (datas != null && datas.size() >= limit) {
// erpOrderResponseList.addAll(datas);
// page++;
//
// } else {
// if (datas != null) {
// erpOrderResponseList.addAll(datas);
// }
// break;
// }
// }
// List<List<String>> excelData = new ArrayList<>();
// for (ErpOrderResponse erpOrderResponse : erpOrderResponseList) {
// for (ErpOrderResponse.SubErpOrder subPurchase : erpOrderResponse.getSubErpOrders()) {
// List<String> rows = new ArrayList<>();
// rows.add(erpOrderResponse.getBillNo());
// rows.add(erpOrderResponse.getBilldate());
// BasicUnitMaintainEntity basicUnitMaintainEntity = basicUnitMaintainService.selectByThirdId(erpOrderResponse.getCorpId(), filterThrOrderRequest.getThirdSysFk());
//// if (basicUnitMaintainEntity != null)
//// rows.add(basicUnitMaintainEntity.getErpId());
//// else
// rows.add(erpOrderResponse.getCorpId());
//// rows.add(basicUnitMaintainEntity.getErpId());
//// rows.add(erpOrderResponse.getCorpId());
// rows.add(erpOrderResponse.getCorpName());
// rows.add(getName(bussinessTypeEntities, erpOrderResponse.getBillType()));
//// rows.add(erpOrderResponse.getBillType());
// rows.add(erpOrderResponse.getBillFlag());
// rows.add(subPurchase.getProductId());
// rows.add(subPurchase.getProductName());
// rows.add(subPurchase.getSpec());
// rows.add(subPurchase.getBatchNo());
// rows.add(subPurchase.getProductDate());
// rows.add(subPurchase.getExpireDate());
// rows.add(subPurchase.getCount() + "");
// rows.add(subPurchase.getReCount() + "");
// rows.add(erpOrderResponse.getOriginType());
// excelData.add(rows);
// }
// }
// return excelData;
// }
//
public List<ThrOrderResponse> getThrOrders(FilterThrOrderRequest filterThrOrderRequest) {
ThrSystemDetailEntity thrSystemDetailEntity = thrSystemDetailService.selectByKey("orderQueryUrl", filterThrOrderRequest.getThirdSysFk());
int page = 1;
int limit = 100;
List<ThrOrderResponse> erpOrderResponseList = new ArrayList<>();
while (true) {
List<ThrOrderResponse> datas = getThrOrders(page, limit, thrSystemDetailEntity.getValue(), filterThrOrderRequest);
if (datas != null && datas.size() >= limit) {
erpOrderResponseList.addAll(datas);
page++;
} else {
if (datas != null) {
erpOrderResponseList.addAll(datas);
}
break;
}
}
return erpOrderResponseList;
}
public List<ThrOrderResponse> getThrOrders(int page, int limit, String orderQueryUrl, FilterThrOrderRequest
filterThrOrderRequest) {
FilterThrOrderRequest filterOrderRequest = new FilterThrOrderRequest();
BeanUtils.copyProperties(filterThrOrderRequest, filterOrderRequest);
filterOrderRequest.setPage(page);
filterOrderRequest.setLimit(limit);
BaseResponse<PageSimpleResponse<ThrOrderResponse>> responseBaseResponse = erpOrderClient.getThrOrderResponse(filterOrderRequest);
if (responseBaseResponse != null && responseBaseResponse.getCode() == 20000) {
List<ThrOrderResponse> erpOrderResponses = responseBaseResponse.getData().getList();
if (erpOrderResponses != null && erpOrderResponses.size() > 0) {
return erpOrderResponses;
}
}
return null;
}
//
// public List<List<String>> genExcelData(FilterThrOrderRequest filterThrOrderRequest) {
//
// BussinessTypeFilterRequest bussinessTypeFilterRequest = new BussinessTypeFilterRequest();
// bussinessTypeFilterRequest.setEnabled(true);
// List<BussinessTypeEntity> bussinessTypeEntities = bussinessTypeService.filterList(bussinessTypeFilterRequest);
// List<List<String>> excelData = new ArrayList<>();
// List<ThrOrderEntity> thrOrderEntities = thrOrderService.filterThrOrder(filterThrOrderRequest);
// for (ThrOrderEntity thrOrderEntity : thrOrderEntities) {
// FilterThrOrderDetailRequest filterThrOrderDetailRequest = new FilterThrOrderDetailRequest();
// filterThrOrderDetailRequest.setOrderIdFk(thrOrderEntity.getId() + "");
// List<ThrOrderDetailEntity> thrOrderDetailEntities = thrOrderDetailService.filterThrOrderDetailDetail(filterThrOrderDetailRequest);
// if (thrOrderDetailEntities != null) {
// for (ThrOrderDetailEntity thrOrderDetailEntity : thrOrderDetailEntities) {
// List<String> rows = new ArrayList<>();
// rows.add(thrOrderEntity.getBillNo());
// rows.add(thrOrderEntity.getBilldate());
//
//// BasicUnitMaintainEntity basicUnitMaintainEntity = basicUnitMaintainService.selectByThirdId(thrOrderEntity.getCorpId(), filterThrOrderRequest.getThirdSysFk());
//// if (basicUnitMaintainEntity != null)
//// rows.add(basicUnitMaintainEntity.getErpId());
//// else
// rows.add(thrOrderEntity.getCorpId());
//
//// rows.add(thrOrderEntity.getCorpId());
// rows.add(thrOrderEntity.getCorpName());
// rows.add(getName(bussinessTypeEntities, thrOrderEntity.getBillType()));
// rows.add(thrOrderEntity.getBillFlag());
// rows.add(thrOrderDetailEntity.getProductId());
// rows.add(thrOrderDetailEntity.getProductName());
// rows.add(thrOrderDetailEntity.getSpec());
// rows.add(thrOrderDetailEntity.getBatchNo());
// rows.add(thrOrderDetailEntity.getProductDate());
// rows.add(thrOrderDetailEntity.getExpireDate());
// rows.add(thrOrderDetailEntity.getCount() + "");
// rows.add(thrOrderDetailEntity.getReCount() + "");
// rows.add(thrOrderEntity.getOriginType());
// excelData.add(rows);
// }
// }
//
// }
// return excelData;
// }
}