opt:单据同步优化;
This commit is contained in:
@@ -11,7 +11,6 @@ import org.springframework.expression.spel.SpelEvaluationException;
|
|||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -77,10 +76,20 @@ public class SpelUtil {
|
|||||||
}
|
}
|
||||||
//如果表达式为null,空则返回''
|
//如果表达式为null,空则返回''
|
||||||
private static Map<String, String> Product_Area_Mapping = MapOf.of(
|
private static Map<String, String> Product_Area_Mapping = MapOf.of(
|
||||||
"827083", "A1", "827082", "A1", "827081", "A1", "827080", "A1", "1028689", "A1", "1028688", "A1", "827077", "A1", "827076", "A1"
|
"827083", "A1",
|
||||||
, "827075", "A1", "827074", "A1", "827073"
|
"827082", "A1",
|
||||||
, "827078", "A2", "827079", "A2"
|
"827081", "A1",
|
||||||
, "", "A3");
|
"827080", "A1",
|
||||||
|
"1028689", "A1",
|
||||||
|
"1028688", "A1",
|
||||||
|
"827077", "A1",
|
||||||
|
"827076", "A1",
|
||||||
|
"827075", "A1",
|
||||||
|
"827074", "A1",
|
||||||
|
"827073", "A1",
|
||||||
|
"827078", "A2",
|
||||||
|
"827079", "A2"
|
||||||
|
);
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -97,7 +106,7 @@ public class SpelUtil {
|
|||||||
if (field.equals("product_area")){
|
if (field.equals("product_area")){
|
||||||
String product_area = Product_Area_Mapping.get(value);
|
String product_area = Product_Area_Mapping.get(value);
|
||||||
if (StringUtils.isEmpty(product_area)){
|
if (StringUtils.isEmpty(product_area)){
|
||||||
throw new BadRequestException("当前业务数据product_area"+value+" 对应的车间数据");
|
product_area = "A1";
|
||||||
}
|
}
|
||||||
value = product_area;
|
value = product_area;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class HeartClientServer extends AbstraceServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doConnect() {
|
public void doConnect() {
|
||||||
System.out.println("-------尝试连接服务器-------");
|
// System.out.println("-------尝试连接服务器-------");
|
||||||
try {
|
try {
|
||||||
ChannelFuture connect = ((Bootstrap) server).connect(address);
|
ChannelFuture connect = ((Bootstrap) server).connect(address);
|
||||||
connect.addListener((ChannelFutureListener) channelFuture -> {
|
connect.addListener((ChannelFutureListener) channelFuture -> {
|
||||||
|
|||||||
@@ -320,14 +320,14 @@ public class SyncErpService {
|
|||||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
//String filterString = "FUseOrgId='750572'";
|
//String filterString = "FUseOrgId='750572'";
|
||||||
//String filterString = "FBillNo ='PPBOM240800244'";
|
String filterString = "FBillNo ='XSDD241200129'";
|
||||||
//String filterString = "FCreateDate >= '" + today + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59'";
|
//String filterString = "FCreateDate >= '" + today + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59'";
|
||||||
ErpQuery query = new ErpQuery();
|
ErpQuery query = new ErpQuery();
|
||||||
//query.setFilterString(filterString);
|
//query.setFilterString(filterString);
|
||||||
//query.setFormId(syncFormMapping.getForm_type());
|
//query.setFormId(syncFormMapping.getForm_type());
|
||||||
query.setFormId(syncFormMapping.getForm_type());
|
query.setFormId(syncFormMapping.getForm_type());
|
||||||
query.setFieldKeys("FMATERIALID");
|
query.setFieldKeys("FID");
|
||||||
query.setLimit(1);
|
query.setLimit(0);
|
||||||
String jsonString = JSON.toJSONString(query);
|
String jsonString = JSON.toJSONString(query);
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||||
log.info("同步ERP结果" + lists.size());
|
log.info("同步ERP结果" + lists.size());
|
||||||
|
|||||||
@@ -316,22 +316,30 @@ public class CockpitServiceImpl implements CockpitService {
|
|||||||
r.setProduct_area(pointInfo.getProduct_area());
|
r.setProduct_area(pointInfo.getProduct_area());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InteracteDto<Object> dto = InteracteDto.builder().service("wmsToAcsService")
|
InteracteDto<Object> dto = InteracteDto.builder()
|
||||||
|
.service("wmsToAcsService")
|
||||||
.trace_id(MDC.get("trace_id"))
|
.trace_id(MDC.get("trace_id"))
|
||||||
.type("getWeight")
|
.type("getWeight")
|
||||||
.data(new JSONObject().put("device_code", code))
|
.data(new JSONObject().fluentPut("device_code", code)) // 使用 fluentPut 提高代码简洁性
|
||||||
.build();
|
.build();
|
||||||
|
//查询称重重量
|
||||||
TableDataInfo result = InterationUtil.notifyExt("/api/wmsToAcs/apply", (JSONObject) JSON.toJSON(dto));
|
TableDataInfo result = InterationUtil.notifyExt("/api/wmsToAcs/apply", (JSONObject) JSON.toJSON(dto));
|
||||||
String weight;
|
BigDecimal theoryQty = BigDecimal.ZERO;
|
||||||
//tofix
|
BigDecimal actual_weight = BigDecimal.ZERO;
|
||||||
if (result.getCode().equals("200")) {
|
if ("200".equals(result.getCode())) {
|
||||||
Object sd = result.getData();
|
Object dataObj = result.getData();
|
||||||
JSONObject data = JSONObject.parseObject(sd.toString());
|
if (dataObj != null) {
|
||||||
if (ObjectUtil.isNotEmpty(data)) {
|
JSONObject data = JSONObject.parseObject(dataObj.toString());
|
||||||
weight = data.getString("weight");
|
if (data != null && data.containsKey("weight")) {
|
||||||
|
String weightStr = data.getString("weight");
|
||||||
|
if (ObjectUtil.isNotEmpty(weightStr)) {
|
||||||
|
// 转换为 BigDecimal
|
||||||
|
actual_weight = new BigDecimal(weightStr.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BigDecimal theoryQty = BigDecimal.ZERO;
|
r.setActual_weight(actual_weight);
|
||||||
//根据称重信息计算理论数量
|
//根据称重信息计算理论数量
|
||||||
if (r.getActual_weight().compareTo(BigDecimal.ZERO) > 0) {
|
if (r.getActual_weight().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
//计算理论重量
|
//计算理论重量
|
||||||
|
|||||||
@@ -146,9 +146,10 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
// ex.printStackTrace();
|
||||||
log.error("ERP单据解析异常:" + ex.getMessage());
|
// log.error("ERP单据解析异常:" + ex.getMessage());
|
||||||
throw new BadRequestException(ex.getMessage());
|
// throw new BadRequestException(ex.getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ public class SyncErpBillsScheduleService {
|
|||||||
private static Map<String, String> BillOrg_Mapping = MapOf.of(
|
private static Map<String, String> BillOrg_Mapping = MapOf.of(
|
||||||
"PRD_PPBOM", "FPrdOrgId",
|
"PRD_PPBOM", "FPrdOrgId",
|
||||||
"PRD_MO", "FPrdOrgId",
|
"PRD_MO", "FPrdOrgId",
|
||||||
"SAL_SaleOrder", "StockOrgId",
|
"SAL_SaleOrder", "FStockOrgId",
|
||||||
"PUR_ReceiveBill", "StockOrgId"
|
"PUR_ReceiveBill", "FStockOrgId"
|
||||||
, "ka7c19edf9d4b4b39b8cc4a06802163b0", "F_PMSY_StockOrgId_Id");
|
, "ka7c19edf9d4b4b39b8cc4a06802163b0", "F_PMSY_PrdOrgId");
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -69,22 +69,176 @@ public class SyncErpBillsScheduleService {
|
|||||||
MDC.put("requestIp", "127.0.0.1");
|
MDC.put("requestIp", "127.0.0.1");
|
||||||
MDC.put("requestTime", DateUtil.now());
|
MDC.put("requestTime", DateUtil.now());
|
||||||
LuceneAppender.traceIdTL.set(BaseCode.intToChars(IdUtil.getLongId()));
|
LuceneAppender.traceIdTL.set(BaseCode.intToChars(IdUtil.getLongId()));
|
||||||
List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
//List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
||||||
|
List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "ka7c19edf9d4b4b39b8cc4a06802163b0", "PRD_MO", "PUR_ReceiveBill", "PRD_PPBOM"));
|
||||||
for (SyncFormMapping m : list) {
|
for (SyncFormMapping m : list) {
|
||||||
JSONArray mappingJson = m.getMapping_json();
|
JSONArray mappingJson = m.getMapping_json();
|
||||||
String mappingString = JSON.toJSONString(mappingJson);
|
String mappingString = JSON.toJSONString(mappingJson);
|
||||||
syncData(mappingString, m.getForm_type(), m.getDtl_split());
|
syncData(mappingString, m.getForm_type(), m.getDtl_split());
|
||||||
}
|
}
|
||||||
// list.forEach(this::syncData);
|
|
||||||
} finally {
|
} finally {
|
||||||
LuceneAppender.traceIdTL.remove();
|
LuceneAppender.traceIdTL.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
public void syncData(String mappingJson, String formType, Boolean dtlSplit) {
|
||||||
*/
|
boolean islock = lock.tryLock();
|
||||||
|
try {
|
||||||
|
if (islock) {
|
||||||
|
List<Object> result = new ArrayList<>();
|
||||||
|
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||||
|
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||||
|
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||||
|
//构建查询条件
|
||||||
|
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
|
String filterString = BillOrg_Mapping.get(formType) + " ='750572' AND FDocumentStatus='C' ";
|
||||||
|
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||||
|
filterString += " AND F_PMSY_BillStatus ='A' AND F_PMSY_CreateDate >= '" + today + " 00:00:00' and F_PMSY_CreateDate <= '" + today + " 23:59:59' ";
|
||||||
|
} else {
|
||||||
|
filterString += " AND FCreateDate >= '" + today + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59' ";
|
||||||
|
}
|
||||||
|
// if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||||
|
// filterString += " AND F_PMSY_StockOrgId='750572' AND F_PMSY_BillStatus ='A' AND F_PMSY_CreateDate >= '2024-11-01 00:00:00' and F_PMSY_CreateDate <= '2024-12-04 23:59:59' ";
|
||||||
|
// }else{
|
||||||
|
// filterString += " AND FCreateDate >= '2024-11-01 00:00:00' and FCreateDate <= '2024-12-04 23:59:59' ";
|
||||||
|
// }
|
||||||
|
//String filterString = "FUseOrgId='750572'";
|
||||||
|
ErpQuery query = new ErpQuery();
|
||||||
|
query.setFilterString(filterString);
|
||||||
|
query.setFormId(formType);
|
||||||
|
query.setFieldKeys("FID");
|
||||||
|
query.setLimit(0);
|
||||||
|
String jsonString = JSON.toJSONString(query);
|
||||||
|
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||||
|
Set<String> ids = new HashSet<>();
|
||||||
|
for (List<Object> list : lists) {
|
||||||
|
for (Object r : list) {
|
||||||
|
String fid = r.toString();
|
||||||
|
if (StringUtils.isEmpty(fid)) {
|
||||||
|
log.error("单据同步失败,没有找到FID");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ids.add(fid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OperateParam param = new OperateParam();
|
||||||
|
Map<String, String> error = new HashMap<>();
|
||||||
|
for (String id : ids) {
|
||||||
|
try {
|
||||||
|
param.setId(id);
|
||||||
|
OperatorResult view = cloudApi.view(formType, param);
|
||||||
|
RepoStatus status = view.getResult().getResponseStatus();
|
||||||
|
if (status.isIsSuccess()) {
|
||||||
|
result.add(view.getResult().getResult());
|
||||||
|
} else {
|
||||||
|
ArrayList<RepoError> errors = status.getErrors();
|
||||||
|
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
||||||
|
error.put(id, errorMsg);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理ID [{}] 时出现异常: {}", id, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!CollectionUtils.isEmpty(error)) {
|
||||||
|
log.error("ERP单据同步失败:{}", error);
|
||||||
|
}
|
||||||
|
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
||||||
|
外部:
|
||||||
|
for (Object r : result) {
|
||||||
|
try {
|
||||||
|
jsonString = JSON.toJSONString(r);
|
||||||
|
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||||
|
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
||||||
|
Set<String> materials = formDataList.stream().filter(rd -> StringUtils.isBlank(rd.getCode())).map(PmFormData::getMaterial_id).collect(Collectors.toSet());
|
||||||
|
int materialCount = iMdMeMaterialbaseService.count(new QueryWrapper<MdMeMaterialbase>().in("material_id", materials));
|
||||||
|
if (materialCount != materials.size()) {
|
||||||
|
log.error("保存数据 [{}] 时出现异常: {}", JSON.toJSONString(formDataList), "物料信息不存在" + materials.toString());
|
||||||
|
}
|
||||||
|
for (String id : formDataList.stream().map(PmFormData::getId).collect(Collectors.toList())) {
|
||||||
|
if (exitFormDataList.contains(id)) {
|
||||||
|
continue 外部;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (PmFormData formData : formDataList) {
|
||||||
|
formDataService.save(formData);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
//log.error("解析数据 [{}] 时出现异常: {}", JSON.toJSONString(r), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("同步数据时出现异常: {}", ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void syncData1(String mappingJson, String formType, Boolean dtlSplit) {
|
public void syncData1(String mappingJson, String formType, Boolean dtlSplit) {
|
||||||
|
boolean islock = lock.tryLock();
|
||||||
|
try {
|
||||||
|
if (islock) {
|
||||||
|
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||||
|
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||||
|
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||||
|
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
|
String filterString = "FUseOrgId='750572'";
|
||||||
|
//String filterString = BillOrg + "='750572' AND FDocumentStatus='C' AND FCreateDate >= '" + today + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59'";
|
||||||
|
//构建查询条件
|
||||||
|
// String BillOrg = BillOrg_Mapping.get(formType);
|
||||||
|
// String filterString = BillOrg + "='750572' AND FDocumentStatus='C' ";
|
||||||
|
// if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||||
|
// filterString += " AND F_PMSY_StockOrgId='750572' AND F_PMSY_BillStatus ='A' AND F_PMSY_CreateDate >= '2024-11-01 00:00:00' and F_PMSY_CreateDate <= '2024-12-04 23:59:59' ";
|
||||||
|
// }else{
|
||||||
|
// filterString += " AND FCreateDate >= '2024-11-01 00:00:00' and FCreateDate <= '2024-12-04 23:59:59' ";
|
||||||
|
// }
|
||||||
|
ErpQuery query = new ErpQuery();
|
||||||
|
query.setFilterString(filterString);
|
||||||
|
query.setFormId(formType);
|
||||||
|
query.setFieldKeys("FMATERIALID");
|
||||||
|
query.setLimit(0);
|
||||||
|
String jsonString = JSON.toJSONString(query);
|
||||||
|
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||||
|
// Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
||||||
|
for (List<Object> list : lists) {
|
||||||
|
for (Object r : list) {
|
||||||
|
String fid = r.toString();
|
||||||
|
if (StringUtils.isEmpty(fid)) {
|
||||||
|
log.error("单据同步失败,没有找到FID");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
OperateParam param = new OperateParam();
|
||||||
|
param.setId(fid);
|
||||||
|
OperatorResult view = cloudApi.view(formType, param);
|
||||||
|
RepoStatus status = view.getResult().getResponseStatus();
|
||||||
|
if (status.isIsSuccess()) {
|
||||||
|
List<Object> result = new ArrayList<>();
|
||||||
|
result.add(view.getResult().getResult());
|
||||||
|
getData(mappingJson, formType, dtlSplit, result);
|
||||||
|
} else {
|
||||||
|
ArrayList<RepoError> errors = status.getErrors();
|
||||||
|
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理ID [{}] 时出现异常: {}", fid, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("同步数据时出现异常: {}", ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void syncDataTest(String mappingJson, String formType, Boolean dtlSplit) {
|
||||||
boolean islock = lock.tryLock();
|
boolean islock = lock.tryLock();
|
||||||
try {
|
try {
|
||||||
if (islock) {
|
if (islock) {
|
||||||
@@ -159,95 +313,27 @@ public class SyncErpBillsScheduleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void syncData(String mappingJson, String formType, Boolean dtlSplit) {
|
private void getData(String mappingJson, String formType, Boolean dtlSplit, List<Object> result) {
|
||||||
boolean islock = lock.tryLock();
|
String jsonString;
|
||||||
try {
|
外部:
|
||||||
if (islock) {
|
for (Object r : result) {
|
||||||
List<Object> result = new ArrayList<>();
|
try {
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
||||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
// for (String id : formDataList.stream().map(PmFormData::getId).collect(Collectors.toList())) {
|
||||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
// if (exitFormDataList.contains(id)) {
|
||||||
String filterString = "FBillNo ='PPBOM240800244'";
|
// continue 外部;
|
||||||
//String filterString = BillOrg + "='750572' AND FDocumentStatus='C' AND FCreateDate >= '" + today + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59'";
|
// }
|
||||||
//构建查询条件
|
// }
|
||||||
// String BillOrg = BillOrg_Mapping.get(formType);
|
if (formDataList != null) {
|
||||||
// String filterString = BillOrg + "='750572' AND FDocumentStatus='C' ";
|
List<PmFormData> formDataFilterList = formDataList.stream().filter(rs1 -> "BD_MATERIAL_1".equals(rs1.getForm_type())).collect(Collectors.toList());
|
||||||
// if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
for (PmFormData formData : formDataFilterList) {
|
||||||
// filterString += " AND F_PMSY_StockOrgId='750572' AND F_PMSY_BillStatus ='A' AND F_PMSY_CreateDate >= '2024-11-01 00:00:00' and F_PMSY_CreateDate <= '2024-12-04 23:59:59' ";
|
formDataService.save(formData);
|
||||||
// }else{
|
|
||||||
// filterString += " AND FCreateDate >= '2024-11-01 00:00:00' and FCreateDate <= '2024-12-04 23:59:59' ";
|
|
||||||
// }
|
|
||||||
//String filterString = "FUseOrgId='750572'";
|
|
||||||
ErpQuery query = new ErpQuery();
|
|
||||||
query.setFilterString(filterString);
|
|
||||||
query.setFormId(formType);
|
|
||||||
query.setFieldKeys("FMATERIALID");
|
|
||||||
query.setLimit(0);
|
|
||||||
String jsonString = JSON.toJSONString(query);
|
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
|
||||||
Set<String> ids = new HashSet<>();
|
|
||||||
for (List<Object> list : lists) {
|
|
||||||
for (Object r : list) {
|
|
||||||
String fid = r.toString();
|
|
||||||
if (StringUtils.isEmpty(fid)) {
|
|
||||||
log.error("单据同步失败,没有找到FID");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ids.add(fid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OperateParam param = new OperateParam();
|
|
||||||
Map<String, String> error = new HashMap<>();
|
} catch (Exception e) {
|
||||||
for (String id : ids) {
|
log.error("解析数据 [{}] 时出现异常: {}", JSON.toJSONString(r), e.getMessage());
|
||||||
try {
|
|
||||||
param.setId(id);
|
|
||||||
OperatorResult view = cloudApi.view(formType, param);
|
|
||||||
RepoStatus status = view.getResult().getResponseStatus();
|
|
||||||
if (status.isIsSuccess()) {
|
|
||||||
result.add(view.getResult().getResult());
|
|
||||||
} else {
|
|
||||||
ArrayList<RepoError> errors = status.getErrors();
|
|
||||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
|
||||||
error.put(id, errorMsg);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理ID [{}] 时出现异常: {}", id, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!CollectionUtils.isEmpty(error)) {
|
|
||||||
log.error("ERP单据同步失败:{}", error);
|
|
||||||
}
|
|
||||||
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
|
||||||
外部:
|
|
||||||
for (Object r : result) {
|
|
||||||
try {
|
|
||||||
jsonString = JSON.toJSONString(r);
|
|
||||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
|
||||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
|
||||||
Set<String> materials = formDataList.stream().map(PmFormData::getMaterial_id).collect(Collectors.toSet());
|
|
||||||
int materialCount = iMdMeMaterialbaseService.count(new QueryWrapper<MdMeMaterialbase>().in("material_id", materials));
|
|
||||||
if (materialCount!=materials.size()){
|
|
||||||
log.error("保存数据 [{}] 时出现异常: {}", JSON.toJSONString(formDataList), "物料信息不存在"+materials.toString());
|
|
||||||
}
|
|
||||||
for (String id : formDataList.stream().map(PmFormData::getId).collect(Collectors.toList())) {
|
|
||||||
if (exitFormDataList.contains(id)) {
|
|
||||||
continue 外部;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (PmFormData formData : formDataList) {
|
|
||||||
formDataService.save(formData);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析数据 [{}] 时出现异常: {}", JSON.toJSONString(r), e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user