rev:优化
This commit is contained in:
@@ -10,6 +10,7 @@ import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.nl.common.domain.exception.BadRequestException;
|
||||||
import org.nl.common.utils.BaseCode;
|
import org.nl.common.utils.BaseCode;
|
||||||
import org.nl.common.utils.IdUtil;
|
import org.nl.common.utils.IdUtil;
|
||||||
import org.nl.common.utils.MapOf;
|
import org.nl.common.utils.MapOf;
|
||||||
@@ -81,9 +82,117 @@ public class SyncErpBillsScheduleService {
|
|||||||
} finally {
|
} finally {
|
||||||
LuceneAppender.traceIdTL.remove();
|
LuceneAppender.traceIdTL.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void manualSync(String formType,String code,String startTime,String endTime) {
|
||||||
|
if (StringUtils.isEmpty(formType)){
|
||||||
|
throw new BadRequestException("单据类型不能为空");
|
||||||
|
}
|
||||||
|
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, formType));
|
||||||
|
JSONArray mappingJson = syncFormMapping.getMapping_json();
|
||||||
|
String mappingString = JSON.toJSONString(mappingJson);
|
||||||
|
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) {
|
||||||
|
//formType:SAL_SaleOrder code:JDSCLLD20241102,start:2024-11-11 12:00:00 end:2024-11-11 12:00:00
|
||||||
|
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());
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
||||||
|
String sevenDaysAgo = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
||||||
|
String filterString = BillOrg_Mapping.get(formType) + " = '750572' AND FDocumentStatus = 'C' ";
|
||||||
|
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||||
|
filterString += " AND F_PMSY_BillStatus = 'A' AND F_PMSY_CreateDate >= '" + sevenDaysAgo + " 00:00:00' AND F_PMSY_CreateDate <= '" + today + " 23:59:59' ";
|
||||||
|
} 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'";
|
||||||
|
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 syncData(String mappingJson, String formType, Boolean dtlSplit) {
|
public void syncData(String mappingJson, String formType, Boolean dtlSplit) {
|
||||||
boolean islock = lock.tryLock();
|
boolean islock = lock.tryLock();
|
||||||
|
|||||||
Reference in New Issue
Block a user