opt:过滤无物料信息的拣选单
This commit is contained in:
@@ -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 ='XSDD241200129'";
|
String filterString = "FBillNo ='SCRK241200094'";
|
||||||
//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("FID");
|
query.setFieldKeys("FID");
|
||||||
query.setLimit(0);
|
query.setLimit(1);
|
||||||
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());
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ public class SyncErpController {
|
|||||||
startTime = datepick.getString(0); //时间格式2024-12-12 12:00:00没选则为空
|
startTime = datepick.getString(0); //时间格式2024-12-12 12:00:00没选则为空
|
||||||
endTime = datepick.getString(0);
|
endTime = datepick.getString(0);
|
||||||
}
|
}
|
||||||
syncErpBillsScheduleService.manualSync(formType,formCode,startTime,endTime);
|
return new ResponseEntity<>(TableDataInfo.buildJson(syncErpBillsScheduleService.manualSync(formType,formCode,startTime,endTime)), HttpStatus.OK);
|
||||||
return new ResponseEntity<>(TableDataInfo.buildJson("同步成功共计100条"), HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ import org.springframework.util.CollectionUtils;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -250,7 +253,7 @@ public class PdaIOService {
|
|||||||
result.setQty(new BigDecimal(dFormJson.getString("ActReceiveQty")));
|
result.setQty(new BigDecimal(dFormJson.getString("ActReceiveQty")));
|
||||||
result.setTaxPrice(dFormJson.getString("taxPrice"));
|
result.setTaxPrice(dFormJson.getString("taxPrice"));
|
||||||
result.setMoNumber(receiveBillData.getPCode());
|
result.setMoNumber(receiveBillData.getPCode());
|
||||||
result.setMoEntryId(receiveBillData.getDId());
|
result.setMoEntryId(receiveBillData.getDId().substring(0, receiveBillData.getDId().indexOf("$")));
|
||||||
//源单信息校验
|
//源单信息校验
|
||||||
if (StringUtils.isBlank(dFormJson.getString("OrderBillNo"))) {
|
if (StringUtils.isBlank(dFormJson.getString("OrderBillNo"))) {
|
||||||
result.setSrcBillNo(null);
|
result.setSrcBillNo(null);
|
||||||
@@ -330,9 +333,8 @@ public class PdaIOService {
|
|||||||
result.setStockOrgId((dFormJson.getString("StockOrgId")));
|
result.setStockOrgId((dFormJson.getString("StockOrgId")));
|
||||||
result.setOwnerIdHead_Id((dFormJson.getString("InStockOwnerId")));
|
result.setOwnerIdHead_Id((dFormJson.getString("InStockOwnerId")));
|
||||||
result.setMoNumber(dataList.get(11).toString());
|
result.setMoNumber(dataList.get(11).toString());
|
||||||
result.setMoId(prdMoBillData.getPId());
|
result.setMoId(prdMoBillData.getPId().substring(0, prdMoBillData.getPId().indexOf("$")));
|
||||||
result.setMoEntryId(prdMoBillData.getDId());
|
result.setMoEntryId(prdMoBillData.getDId().substring(0, prdMoBillData.getDId().indexOf("$")));
|
||||||
result.setSrcBillNo(dFormJson.getString("saleOrderEntryId"));
|
|
||||||
result.setMaterial_id(dataList.get(3).toString());
|
result.setMaterial_id(dataList.get(3).toString());
|
||||||
result.setPcsn(dataList.get(11).toString());
|
result.setPcsn(dataList.get(11).toString());
|
||||||
result.setUnit_id(dataList.get(7).toString());
|
result.setUnit_id(dataList.get(7).toString());
|
||||||
@@ -346,6 +348,12 @@ public class PdaIOService {
|
|||||||
result.setStockId(dFormJson.getString("stockId"));
|
result.setStockId(dFormJson.getString("stockId"));
|
||||||
result.setKeeperId((dFormJson.getString("StockOrgId")));
|
result.setKeeperId((dFormJson.getString("StockOrgId")));
|
||||||
result.setKeeperTypeId("BD_KeeperOrg");
|
result.setKeeperTypeId("BD_KeeperOrg");
|
||||||
|
String srcBillNo = dFormJson.getString("saleOrderEntryId");
|
||||||
|
if ("0".equals(srcBillNo)) {
|
||||||
|
//tofix 查询工序汇报单信息,取末道工序为源单号
|
||||||
|
} else {
|
||||||
|
result.setSrcBillNo(srcBillNo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException("查询合格证关联的生产订单信息异常!");
|
throw new BadRequestException("查询合格证关联的生产订单信息异常!");
|
||||||
|
|||||||
@@ -146,10 +146,8 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
// ex.printStackTrace();
|
|
||||||
log.error("ERP单据解析异常:" + ex.getMessage());
|
log.error("ERP单据解析异常:" + ex.getMessage());
|
||||||
// throw new BadRequestException(ex.getMessage());
|
throw new BadRequestException(ex.getMessage());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.nl.wms.system_manage.service.quartz.task;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.kingdee.bos.webapi.entity.*;
|
import com.kingdee.bos.webapi.entity.*;
|
||||||
@@ -84,49 +85,58 @@ public class SyncErpBillsScheduleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void manualSync(String formType,String code,String startTime,String endTime) {
|
public String manualSync(String formType, String code, String startTime, String endTime) {
|
||||||
if (StringUtils.isEmpty(formType)){
|
if (StringUtils.isEmpty(formType)) {
|
||||||
throw new BadRequestException("单据类型不能为空");
|
throw new BadRequestException("单据类型不能为空");
|
||||||
}
|
}
|
||||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, formType));
|
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, formType));
|
||||||
JSONArray mappingJson = syncFormMapping.getMapping_json();
|
JSONArray mappingJson = syncFormMapping.getMapping_json();
|
||||||
String mappingString = JSON.toJSONString(mappingJson);
|
String mappingString = JSON.toJSONString(mappingJson);
|
||||||
manualSyncData(mappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(),code,startTime,endTime);
|
return manualSyncData(mappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), code, startTime, endTime);
|
||||||
}
|
}
|
||||||
private void manualSyncData(String mappingJson, String formType, Boolean dtlSplit,String code,String start,String end) {
|
|
||||||
|
private String manualSyncData(String mappingJson, String formType, Boolean dtlSplit, String code, String start, String end) {
|
||||||
//formType:SAL_SaleOrder code:JDSCLLD20241102,start:2024-11-11 12:00:00 end:2024-11-11 12:00:00
|
//formType:SAL_SaleOrder code:JDSCLLD20241102,start:2024-11-11 12:00:00 end:2024-11-11 12:00:00
|
||||||
boolean islock = lock.tryLock();
|
boolean islock = lock.tryLock();
|
||||||
|
Integer count = 0;
|
||||||
|
String msg = "同步失败,失败原因:";
|
||||||
|
Map errorMsg = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
if (islock) {
|
if (islock) {
|
||||||
|
//单据同步总数
|
||||||
List<Object> result = new ArrayList<>();
|
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 timeEnd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
||||||
String sevenDaysAgo = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
String timeStart = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
||||||
String filterString = BillOrg_Mapping.get(formType) + " = '750572' AND FDocumentStatus = 'C' ";
|
if (StringUtils.isNotBlank(start) && StringUtils.isNotBlank(end)) {
|
||||||
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
timeStart = start;
|
||||||
filterString += " AND F_PMSY_BillStatus = 'A' AND F_PMSY_CreateDate >= '" + sevenDaysAgo + " 00:00:00' AND F_PMSY_CreateDate <= '" + today + " 23:59:59' ";
|
timeEnd = end;
|
||||||
} else if ("SAL_SaleOrder".equals(formType)) {
|
|
||||||
filterString += " AND FCloseStatus ='A' AND FCreateDate >= '" + sevenDaysAgo + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59' ";
|
|
||||||
} else {
|
|
||||||
filterString += " AND FCreateDate >= '" + sevenDaysAgo + " 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'";
|
//String filterString = "FUseOrgId='750572'";
|
||||||
|
String filterString;
|
||||||
|
if (StringUtils.isNotBlank(code)) {
|
||||||
|
filterString = "FBillNo = '" + code + "'";
|
||||||
|
} else {
|
||||||
|
filterString = BillOrg_Mapping.get(formType) + " = '750572' AND FDocumentStatus = 'C' ";
|
||||||
|
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||||
|
filterString += " AND F_PMSY_BillStatus = 'A' AND F_PMSY_CreateDate >= '" + timeStart + " 00:00:00' AND F_PMSY_CreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||||
|
} else if ("SAL_SaleOrder".equals(formType)) {
|
||||||
|
filterString += " AND FCloseStatus ='A' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||||
|
} else {
|
||||||
|
filterString += " AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||||
|
}
|
||||||
|
}
|
||||||
ErpQuery query = new ErpQuery();
|
ErpQuery query = new ErpQuery();
|
||||||
query.setFilterString(filterString);
|
query.setFilterString(filterString);
|
||||||
query.setFormId(formType);
|
query.setFormId(formType);
|
||||||
query.setFieldKeys("FID");
|
query.setFieldKeys("FID");
|
||||||
query.setLimit(0);
|
query.setLimit(0);
|
||||||
String jsonString = JSON.toJSONString(query);
|
String jsonString = JSON.toJSONString(query);
|
||||||
|
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||||
|
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||||
|
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||||
Set<String> ids = new HashSet<>();
|
Set<String> ids = new HashSet<>();
|
||||||
for (List<Object> list : lists) {
|
for (List<Object> list : lists) {
|
||||||
@@ -140,7 +150,6 @@ public class SyncErpBillsScheduleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
OperateParam param = new OperateParam();
|
OperateParam param = new OperateParam();
|
||||||
Map<String, String> error = new HashMap<>();
|
|
||||||
for (String id : ids) {
|
for (String id : ids) {
|
||||||
try {
|
try {
|
||||||
param.setId(id);
|
param.setId(id);
|
||||||
@@ -150,42 +159,60 @@ public class SyncErpBillsScheduleService {
|
|||||||
result.add(view.getResult().getResult());
|
result.add(view.getResult().getResult());
|
||||||
} else {
|
} else {
|
||||||
ArrayList<RepoError> errors = status.getErrors();
|
ArrayList<RepoError> errors = status.getErrors();
|
||||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
errorMsg.put(id, errorMsg);
|
||||||
error.put(id, errorMsg);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理ID [{}] 时出现异常: {}", id, e.getMessage());
|
errorMsg.put("id","处理ID异常"+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!CollectionUtils.isEmpty(error)) {
|
//物料同步
|
||||||
log.error("ERP单据同步失败:{}", error);
|
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
||||||
}
|
String materialMappingString = JSON.toJSONString(syncFormMapping.getMapping_json());
|
||||||
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
||||||
外部:
|
外部:
|
||||||
for (Object r : result) {
|
for (int i = 0; i < result.size(); i++) {
|
||||||
|
Object r = result.get(i);
|
||||||
try {
|
try {
|
||||||
jsonString = JSON.toJSONString(r);
|
|
||||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
||||||
|
//主单据
|
||||||
|
final String mainId=formDataList.stream().filter(rd -> StringUtils.isNotBlank(rd.getCode())).collect(Collectors.toList()).get(0).getId();
|
||||||
Set<String> materials = formDataList.stream().filter(rd -> StringUtils.isBlank(rd.getCode())).map(PmFormData::getMaterial_id).collect(Collectors.toSet());
|
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));
|
List<MdMeMaterialbase> materialList = iMdMeMaterialbaseService.list(new QueryWrapper<MdMeMaterialbase>().select("material_id").in("material_id", materials));
|
||||||
if (materialCount != materials.size()) {
|
Set<String> materialHas = materialList.stream().map(MdMeMaterialbase::getMaterial_id).collect(Collectors.toSet());
|
||||||
log.error("保存数据 [{}] 时出现异常: {}", JSON.toJSONString(formDataList), "物料信息不存在" + materials.toString());
|
for (String m : materials) {
|
||||||
}
|
if (!materialHas.contains(m)) {
|
||||||
for (PmFormData formData : formDataList) {
|
Boolean materialSync = queryMaterialInfo(materialMappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), m, cloudApi);
|
||||||
if (exitFormDataList.contains(formData.getId()+"$"+formData.getForm_type())) {
|
if (!materialSync) {
|
||||||
continue 外部;
|
continue 外部;
|
||||||
}
|
}
|
||||||
formData.setId(formData.getId()+"$"+formData.getForm_type());
|
}
|
||||||
formDataService.save(formData);
|
}
|
||||||
|
for (PmFormData f : formDataList) {
|
||||||
|
if (exitFormDataList.contains(f.getId() + "$" + f.getForm_type())) {
|
||||||
|
continue 外部;
|
||||||
|
}
|
||||||
|
//单据明细
|
||||||
|
if (StringUtils.isBlank(f.getCode())) {
|
||||||
|
f.setParent_id(mainId + "$" + formType);
|
||||||
|
}
|
||||||
|
f.setId(f.getId() + "$" + f.getForm_type());
|
||||||
|
formDataService.save(f);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("解析数据 [{}] 时ID重复: {}", JSON.toJSONString(r), e.getMessage());
|
errorMsg.put("result第"+i+1+"条解析异常:",e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!CollectionUtils.isEmpty(errorMsg)){
|
||||||
|
throw new BadRequestException("同步成功"+(result.size()-errorMsg.size())+"条,失败信息:"+errorMsg.toString());
|
||||||
|
}else {
|
||||||
|
return "同步成功,共计"+result.size()+"条";
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
throw new BadRequestException("当前同步操作正在执行,稍后再试");
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
throw new BadRequestException(ex.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
@@ -238,6 +265,9 @@ public class SyncErpBillsScheduleService {
|
|||||||
ids.add(fid);
|
ids.add(fid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//物料同步
|
||||||
|
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
||||||
|
String materialMappingString = JSON.toJSONString(syncFormMapping.getMapping_json());
|
||||||
OperateParam param = new OperateParam();
|
OperateParam param = new OperateParam();
|
||||||
Map<String, String> error = new HashMap<>();
|
Map<String, String> error = new HashMap<>();
|
||||||
for (String id : ids) {
|
for (String id : ids) {
|
||||||
@@ -259,6 +289,7 @@ public class SyncErpBillsScheduleService {
|
|||||||
if (!CollectionUtils.isEmpty(error)) {
|
if (!CollectionUtils.isEmpty(error)) {
|
||||||
log.error("ERP单据同步失败:{}", error);
|
log.error("ERP单据同步失败:{}", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
||||||
外部:
|
外部:
|
||||||
for (Object r : result) {
|
for (Object r : result) {
|
||||||
@@ -266,21 +297,32 @@ public class SyncErpBillsScheduleService {
|
|||||||
jsonString = JSON.toJSONString(r);
|
jsonString = JSON.toJSONString(r);
|
||||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
||||||
|
//主单据
|
||||||
|
final String mainId=formDataList.stream().filter(rd -> StringUtils.isNotBlank(rd.getCode())).collect(Collectors.toList()).get(0).getId();
|
||||||
Set<String> materials = formDataList.stream().filter(rd -> StringUtils.isBlank(rd.getCode())).map(PmFormData::getMaterial_id).collect(Collectors.toSet());
|
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));
|
List<MdMeMaterialbase> materialList = iMdMeMaterialbaseService.list(new QueryWrapper<MdMeMaterialbase>().select("material_id").in("material_id", materials));
|
||||||
if (materialCount != materials.size()) {
|
Set<String> materialHas = materialList.stream().map(MdMeMaterialbase::getMaterial_id).collect(Collectors.toSet());
|
||||||
log.error("保存数据 [{}] 时出现异常: {}", JSON.toJSONString(formDataList), "物料信息不存在" + materials.toString());
|
for (String m : materials) {
|
||||||
}
|
if (!materialHas.contains(m)) {
|
||||||
for (String id : formDataList.stream().map(PmFormData::getId).collect(Collectors.toList())) {
|
Boolean materialSync = queryMaterialInfo(materialMappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), m, cloudApi);
|
||||||
if (exitFormDataList.contains(id)) {
|
if (!materialSync) {
|
||||||
continue 外部;
|
continue 外部;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (PmFormData formData : formDataList) {
|
}
|
||||||
formDataService.save(formData);
|
for (PmFormData f : formDataList) {
|
||||||
|
if (exitFormDataList.contains(f.getId() + "$" + f.getForm_type())) {
|
||||||
|
continue 外部;
|
||||||
|
}
|
||||||
|
//单据明细
|
||||||
|
if (StringUtils.isBlank(f.getCode())) {
|
||||||
|
f.setParent_id(mainId + "$" + formType);
|
||||||
|
}
|
||||||
|
f.setId(f.getId() + "$" + f.getForm_type());
|
||||||
|
formDataService.save(f);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//log.error("解析数据 [{}] 时出现异常: {}", JSON.toJSONString(r), e.getMessage());
|
log.error("解析数据 [{}]数据失败: {}", JSON.toJSONString(r), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,6 +335,53 @@ public class SyncErpBillsScheduleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Boolean queryMaterialInfo(String mappingJson, String formType, Boolean dtlSplit, String id, K3CloudApi cloudApi) {
|
||||||
|
try {
|
||||||
|
{
|
||||||
|
ErpQuery query = new ErpQuery();
|
||||||
|
String filterString = "FUseOrgId='750572' AND FMATERIALID ='" + id + "'";
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("同步数据时出现异常: {}", ex.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void syncData2(String mappingJson, String formType, Boolean dtlSplit) {
|
public void syncData2(String mappingJson, String formType, Boolean dtlSplit) {
|
||||||
boolean islock = lock.tryLock();
|
boolean islock = lock.tryLock();
|
||||||
try {
|
try {
|
||||||
@@ -334,7 +423,7 @@ public class SyncErpBillsScheduleService {
|
|||||||
if (status.isIsSuccess()) {
|
if (status.isIsSuccess()) {
|
||||||
List<Object> result = new ArrayList<>();
|
List<Object> result = new ArrayList<>();
|
||||||
result.add(view.getResult().getResult());
|
result.add(view.getResult().getResult());
|
||||||
getData(mappingJson, formType, dtlSplit, result);
|
// getData(mappingJson, formType, dtlSplit, result);
|
||||||
} else {
|
} else {
|
||||||
ArrayList<RepoError> errors = status.getErrors();
|
ArrayList<RepoError> errors = status.getErrors();
|
||||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
||||||
@@ -442,13 +531,24 @@ public class SyncErpBillsScheduleService {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
if (formDataList != null) {
|
if (formDataList != null) {
|
||||||
List<PmFormData> formDataFilterList = formDataList.stream().filter(rs1 -> "BD_MATERIAL_1".equals(rs1.getForm_type())).collect(Collectors.toList());
|
PmFormData mainFormData = formDataList.stream().filter(rs1 -> "BD_MATERIAL".equals(rs1.getForm_type())).collect(Collectors.toList()).get(0);
|
||||||
for (PmFormData formData : formDataFilterList) {
|
JSONObject object = mainFormData.getForm_data();
|
||||||
formDataService.save(formData);
|
String m_code = object.getString("m_code");
|
||||||
log.info("数据同步成功!");
|
String m_name = object.getString("m_name");
|
||||||
|
String m_spec = object.getString("m_spec");
|
||||||
|
String m_unit = mainFormData.getUnit_id();
|
||||||
|
PmFormData formData = formDataList.stream().filter(rs1 -> "BD_MATERIAL_1".equals(rs1.getForm_type())).collect(Collectors.toList()).get(0);
|
||||||
|
MdMeMaterialbase materialBase = new MdMeMaterialbase();
|
||||||
|
materialBase.setMaterial_id(mainFormData.getId());
|
||||||
|
materialBase.setMaterial_code(m_code);
|
||||||
|
materialBase.setMaterial_code(m_code);
|
||||||
|
materialBase.setMaterial_name(m_name);
|
||||||
|
materialBase.setMaterial_spec(m_spec);
|
||||||
|
materialBase.setQty_unit_id(m_unit);
|
||||||
|
materialBase.setAssist_unit_id(formData.getVehicle_code());
|
||||||
|
materialBase.setPrint_no(formData.getPcsn());
|
||||||
|
iMdMeMaterialbaseService.save(materialBase);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("解析数据 [{}] 时出现异常: {}", JSON.toJSONString(r), e.getMessage());
|
log.error("解析数据 [{}] 时出现异常: {}", JSON.toJSONString(r), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,7 +261,7 @@
|
|||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-model="syncForm.datepick"
|
v-model="syncForm.datepick"
|
||||||
type="daterange"
|
type="daterange"
|
||||||
value-format="yyyy-MM-dd hh:mm:ss"
|
value-format="yyyy-MM-dd"
|
||||||
range-separator="至"
|
range-separator="至"
|
||||||
start-placeholder="开始日期"
|
start-placeholder="开始日期"
|
||||||
end-placeholder="结束日期"
|
end-placeholder="结束日期"
|
||||||
|
|||||||
Reference in New Issue
Block a user