|
|
|
@ -2,16 +2,12 @@ package com.hw.jindie.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
import com.hw.common.core.utils.DateUtils;
|
|
|
|
|
import com.hw.common.core.utils.StringUtils;
|
|
|
|
|
import com.hw.jindie.domain.*;
|
|
|
|
|
import com.hw.jindie.mapper.*;
|
|
|
|
|
import com.hw.jindie.service.IKingdeeErpSyncService;
|
|
|
|
|
import com.kingdee.bos.webapi.entity.RepoRet;
|
|
|
|
|
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
|
|
|
import io.swagger.models.auth.In;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
@ -40,23 +36,33 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesPurchaseOrderMapper mesPurchaseOrderMapper;
|
|
|
|
|
|
|
|
|
|
private static final int limit = 100;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Description:从金蝶ERP同步供应商信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int syncSupplierInfoFromErp(int startRow) throws Exception {
|
|
|
|
|
String maxErpModifyDate = mesBaseSupplierInfoMapper.selectMaxErpModifyDate();
|
|
|
|
|
return syncSupplierInfoFromErp(startRow, maxErpModifyDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Description:从金蝶ERP同步供应商信息,递归使用
|
|
|
|
|
*/
|
|
|
|
|
public int syncSupplierInfoFromErp(int startRow, String maxErpModifyDate) throws Exception {
|
|
|
|
|
System.out.println("startRow=" + startRow + ",,,maxErpModifyDate=" + maxErpModifyDate);
|
|
|
|
|
K3CloudApi api = new K3CloudApi();
|
|
|
|
|
// "FormId": "BD_Supplier",
|
|
|
|
|
// "FieldKeys": "FNumber ,FName,FCreateDate,FModifyDate,FAuditDate",
|
|
|
|
|
// "FilterString": "FDocumentStatus='C' AND FCreateDate>'2022-01-01' ",
|
|
|
|
|
JSONObject queryJson = new JSONObject();
|
|
|
|
|
String formId = "BD_Supplier";
|
|
|
|
|
String fieldKeys = "FSupplierId,FNumber,FName,FCreateDate,FModifyDate,FAuditDate,FCreatorId,FModifierId";
|
|
|
|
|
String orderString = "";
|
|
|
|
|
int topRowCount = 0;
|
|
|
|
|
// int startRow = 0;
|
|
|
|
|
int limit = 2;
|
|
|
|
|
// int limit = 2;
|
|
|
|
|
queryJson.put("FormId", formId);
|
|
|
|
|
queryJson.put("FieldKeys", fieldKeys);
|
|
|
|
|
queryJson.put("OrderString", orderString);
|
|
|
|
@ -64,7 +70,15 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
queryJson.put("StartRow", startRow);
|
|
|
|
|
queryJson.put("Limit", limit);
|
|
|
|
|
queryJson.put("SubSystemId", "");
|
|
|
|
|
|
|
|
|
|
//条件查询
|
|
|
|
|
System.out.println("maxErpModifyDate=" + maxErpModifyDate);
|
|
|
|
|
if (StringUtils.isNotEmpty(maxErpModifyDate)) {
|
|
|
|
|
String filterString = "FModifyDate >'" + maxErpModifyDate + "'";
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
|
}
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
// if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(endTime)) {
|
|
|
|
|
// String filterString = "FCreateDate >'" + beginTime + "' AND '" + endTime + "' >FCreateDate";
|
|
|
|
|
// queryJson.put("FilterString", filterString);
|
|
|
|
@ -76,66 +90,83 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String result = api.billQuery(queryJson.toString());
|
|
|
|
|
if (StringUtils.isEmpty(result)) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONArray resultArray = JSONArray.parseArray(result);
|
|
|
|
|
// System.out.println(resultArray.size());
|
|
|
|
|
// System.out.println("供应商查询接口: " + result);
|
|
|
|
|
if (resultArray == null) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<MesBaseSupplierInfo> toInsertSupplierInfoList = new ArrayList<>();
|
|
|
|
|
List<MesBaseSupplierInfo> toUpdateSupplierInfoList = new ArrayList<>();
|
|
|
|
|
Date currentDate = new Date();
|
|
|
|
|
for (int i = 0; i < resultArray.size(); i++) {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject resultObject = (JSONObject) resultArray.get(i);
|
|
|
|
|
MesBaseSupplierInfo mesBaseSupplierInfo = new MesBaseSupplierInfo();
|
|
|
|
|
//供应商编号
|
|
|
|
|
String FNumber = (String) resultObject.get("FNumber");
|
|
|
|
|
String FNumber = resultObject.getString("FNumber");
|
|
|
|
|
//供应商名称
|
|
|
|
|
String FName = (String) resultObject.get("FName");
|
|
|
|
|
String FName = resultObject.getString("FName");
|
|
|
|
|
//erp主键id
|
|
|
|
|
Integer erpId = resultObject.get("FSupplierId") == null ? 0 : (Integer) resultObject.get("FSupplierId");
|
|
|
|
|
Long erpId = resultObject.getLong("FSupplierId");
|
|
|
|
|
//创建时间
|
|
|
|
|
String FCreateDate = (String) resultObject.get("FCreateDate");
|
|
|
|
|
String FCreateDate = resultObject.getString("FCreateDate");
|
|
|
|
|
//更新时间
|
|
|
|
|
String FModifyDate = (String) resultObject.get("FModifyDate");
|
|
|
|
|
String FModifyDate = resultObject.getString("FModifyDate");
|
|
|
|
|
//审核日期
|
|
|
|
|
String FAuditDate = (String) resultObject.get("FAuditDate");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mesBaseSupplierInfo.setErpId(Long.valueOf(erpId));
|
|
|
|
|
|
|
|
|
|
List<MesBaseSupplierInfo> mesBaseSupplierInfos = mesBaseSupplierInfoMapper.selectMesBaseSupplierInfoList(mesBaseSupplierInfo);
|
|
|
|
|
String FAuditDate = resultObject.getString("FAuditDate");
|
|
|
|
|
|
|
|
|
|
mesBaseSupplierInfo.setErpId(erpId);
|
|
|
|
|
mesBaseSupplierInfo.setSupplierCode(FNumber);
|
|
|
|
|
mesBaseSupplierInfo.setSupplierName(FName);
|
|
|
|
|
|
|
|
|
|
//供应商状态
|
|
|
|
|
mesBaseSupplierInfo.setSupplierStatus("1");
|
|
|
|
|
// mesBaseSupplierInfo.setCreateBy(FCreatorId);
|
|
|
|
|
// mesBaseSupplierInfo.setUpdateBy(FModifierId);
|
|
|
|
|
mesBaseSupplierInfo.setUpdateTime(currentDate);
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(FCreateDate)) {
|
|
|
|
|
mesBaseSupplierInfo.setCreateTime(conversionERPTime(FCreateDate));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(FModifyDate)) {
|
|
|
|
|
mesBaseSupplierInfo.setUpdateTime(conversionERPTime(FModifyDate));
|
|
|
|
|
mesBaseSupplierInfo.setErpModifyDate(conversionERPTime(FModifyDate));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(FAuditDate)) {
|
|
|
|
|
mesBaseSupplierInfo.setAuditDate(conversionERPTime(FAuditDate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// System.out.println(mesBaseSupplierInfo);
|
|
|
|
|
//通过erp主键判断,表中是否有重复的数据,如果有则更新,没有则插入
|
|
|
|
|
if (mesBaseSupplierInfos.size() == 0) {
|
|
|
|
|
mesBaseSupplierInfoMapper.insertMesBaseSupplierInfo(mesBaseSupplierInfo);
|
|
|
|
|
MesBaseSupplierInfo existedMesBaseSupplierInfo = mesBaseSupplierInfoMapper.selectMesBaseSupplierInfoByErpId(erpId);
|
|
|
|
|
|
|
|
|
|
if (existedMesBaseSupplierInfo != null) {
|
|
|
|
|
mesBaseSupplierInfo.setSupplierId(existedMesBaseSupplierInfo.getSupplierId());
|
|
|
|
|
toUpdateSupplierInfoList.add(mesBaseSupplierInfo);
|
|
|
|
|
} else {
|
|
|
|
|
//todo 主键
|
|
|
|
|
mesBaseSupplierInfo.setSupplierId(mesBaseSupplierInfos.get(0).getSupplierId());
|
|
|
|
|
mesBaseSupplierInfoMapper.updateMesBaseSupplierInfo(mesBaseSupplierInfo);
|
|
|
|
|
toInsertSupplierInfoList.add(mesBaseSupplierInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!toInsertSupplierInfoList.isEmpty()) {
|
|
|
|
|
mesBaseSupplierInfoMapper.batchMesBaseSupplierInfo(toInsertSupplierInfoList);
|
|
|
|
|
}
|
|
|
|
|
if (!toUpdateSupplierInfoList.isEmpty()) {
|
|
|
|
|
for (MesBaseSupplierInfo toUpdatedSupplierInfo : toUpdateSupplierInfoList) {
|
|
|
|
|
mesBaseSupplierInfoMapper.updateMesBaseSupplierInfo(toUpdatedSupplierInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("size:"+resultArray.size());
|
|
|
|
|
//如果返回的数组的数量等于分页数量,则继续获取下一页数据
|
|
|
|
|
if (resultArray.size() == limit) {
|
|
|
|
|
// System.out.println(startRow);
|
|
|
|
|
//通过递归同步所有供应商,测试先不用
|
|
|
|
|
int i = syncSupplierInfoFromErp(startRow + resultArray.size());
|
|
|
|
|
int i = syncSupplierInfoFromErp(startRow + resultArray.size(), maxErpModifyDate);
|
|
|
|
|
// return i;
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
@ -151,6 +182,15 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int syncMaterialInfoFromErp(int startRow) throws Exception {
|
|
|
|
|
String maxErpModifyDate = mesBaseMaterialInfoMapper.selectMaxErpModifyDate();
|
|
|
|
|
return syncMaterialInfoFromErp(startRow, maxErpModifyDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Description:从金蝶ERP同步物料信息,递归使用
|
|
|
|
|
*/
|
|
|
|
|
public int syncMaterialInfoFromErp(int startRow, String maxErpModifyDate) throws Exception {
|
|
|
|
|
K3CloudApi api = new K3CloudApi();
|
|
|
|
|
String FDocumentStatus = "C";
|
|
|
|
|
|
|
|
|
@ -162,7 +202,7 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
String orderString = "";
|
|
|
|
|
int topRowCount = 0;
|
|
|
|
|
// int startRow = 0;
|
|
|
|
|
int limit = 20;
|
|
|
|
|
// int limit = 20;
|
|
|
|
|
queryJson.put("FormId", formId);
|
|
|
|
|
queryJson.put("FieldKeys", fieldKeys);
|
|
|
|
|
queryJson.put("OrderString", orderString);
|
|
|
|
@ -170,8 +210,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
queryJson.put("StartRow", startRow);
|
|
|
|
|
queryJson.put("Limit", limit);
|
|
|
|
|
queryJson.put("SubSystemId", "");
|
|
|
|
|
|
|
|
|
|
//条件查询
|
|
|
|
|
String maxErpModifyDate = mesBaseMaterialInfoMapper.getMaxErpModifyDate();
|
|
|
|
|
if (StringUtils.isNotEmpty(maxErpModifyDate)) {
|
|
|
|
|
String filterString = "FModifyDate >'" + maxErpModifyDate + "'";
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
@ -179,50 +219,60 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
String result = api.billQuery(queryJson.toString());
|
|
|
|
|
if (StringUtils.isEmpty(result)) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONArray resultArray = JSONArray.parseArray(result);
|
|
|
|
|
if (resultArray == null) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
System.out.println("物料单据查询接口: " + result);
|
|
|
|
|
|
|
|
|
|
List<MesBaseMaterialInfo> toInsertMaterialInfoList = new ArrayList<>();
|
|
|
|
|
List<MesBaseMaterialInfo> toUpdateMaterialInfoList = new ArrayList<>();
|
|
|
|
|
Date currentDate = new Date();
|
|
|
|
|
for (int i = 0; i < resultArray.size(); i++) {
|
|
|
|
|
JSONObject resultObject = (JSONObject) resultArray.get(i);
|
|
|
|
|
MesBaseMaterialInfo mesBaseMaterialInfo = new MesBaseMaterialInfo();
|
|
|
|
|
//erp主键
|
|
|
|
|
Integer erpId = (Integer) resultObject.get("FMaterialId");
|
|
|
|
|
Long erpId = resultObject.getLong("FMaterialId");
|
|
|
|
|
//物料编码
|
|
|
|
|
String materialCode = (String) resultObject.get("FNumber");
|
|
|
|
|
String materialCode = resultObject.getString("FNumber");
|
|
|
|
|
//物料名称
|
|
|
|
|
String materialName = (String) resultObject.get("FName");
|
|
|
|
|
String materialName = resultObject.getString("FName");
|
|
|
|
|
//计量单位ID
|
|
|
|
|
Integer materaialUnitId = resultObject.get("FBaseUnitId") == null ? null : (Integer) resultObject.get("FBaseUnitId");
|
|
|
|
|
Long materialUnitId = resultObject.getLong("FBaseUnitId");
|
|
|
|
|
//物料规格
|
|
|
|
|
String materialSpec = resultObject.get("FSpecification") == null ? null : (String) resultObject.get("FSpecification");
|
|
|
|
|
String materialSpec = resultObject.getString("FSpecification");
|
|
|
|
|
//净重
|
|
|
|
|
BigDecimal netWeight = resultObject.get("FNETWEIGHT") == null ? null : (BigDecimal) resultObject.get("FNETWEIGHT");
|
|
|
|
|
BigDecimal netWeight = resultObject.getBigDecimal("FNETWEIGHT");
|
|
|
|
|
//毛重
|
|
|
|
|
BigDecimal grossWeight = resultObject.get("FGROSSWEIGHT") == null ? null : (BigDecimal) resultObject.get("FGROSSWEIGHT");
|
|
|
|
|
BigDecimal grossWeight = resultObject.getBigDecimal("FGROSSWEIGHT");
|
|
|
|
|
//创建时间
|
|
|
|
|
String createDateStr = resultObject.get("FCreateDate") == null ? null : (String) resultObject.get("FCreateDate");
|
|
|
|
|
String createDateStr = resultObject.getString("FCreateDate");
|
|
|
|
|
//erp最后更新日期
|
|
|
|
|
String modifyDateStr = resultObject.get("FModifyDate") == null ? null : (String) resultObject.get("FModifyDate");
|
|
|
|
|
String modifyDateStr = resultObject.getString("FModifyDate");
|
|
|
|
|
//审核日期
|
|
|
|
|
String approveDateStr = resultObject.get("FApproveDate") == null ? null : (String) resultObject.get("FApproveDate");
|
|
|
|
|
String approveDateStr = resultObject.getString("FApproveDate");
|
|
|
|
|
//创建组织
|
|
|
|
|
Integer createOrgId = resultObject.get("FCreateOrgId") == null ? null : (Integer) resultObject.get("FCreateOrgId");
|
|
|
|
|
Long createOrgId = resultObject.getLong("FCreateOrgId");
|
|
|
|
|
//使用组织
|
|
|
|
|
Integer useOrgId = resultObject.get("FUseOrgId") == null ? null : (Integer) resultObject.get("FUseOrgId");
|
|
|
|
|
Long useOrgId = resultObject.getLong("FUseOrgId");
|
|
|
|
|
//采购计量单价
|
|
|
|
|
Integer purchasePriceUnitId = resultObject.get("FPurchasePriceUnitId") == null ? null : (Integer) resultObject.get("FPurchasePriceUnit");
|
|
|
|
|
Long purchasePriceUnitId = resultObject.getLong("FPurchasePriceUnitId");
|
|
|
|
|
|
|
|
|
|
mesBaseMaterialInfo.setErpId(erpId);
|
|
|
|
|
mesBaseMaterialInfo.setMaterialCode(materialCode);
|
|
|
|
|
mesBaseMaterialInfo.setMaterialName(materialName);
|
|
|
|
|
mesBaseMaterialInfo.setMaterialUnitId(Long.valueOf(materaialUnitId));
|
|
|
|
|
mesBaseMaterialInfo.setMaterialUnitId(materialUnitId);
|
|
|
|
|
mesBaseMaterialInfo.setMaterialSpec(materialSpec);
|
|
|
|
|
mesBaseMaterialInfo.setNetWeight(netWeight);
|
|
|
|
|
mesBaseMaterialInfo.setGrossWeight(grossWeight);
|
|
|
|
|
mesBaseMaterialInfo.setCreateOrgId(Long.valueOf(createOrgId));
|
|
|
|
|
mesBaseMaterialInfo.setUseOrgId(Long.valueOf(useOrgId));
|
|
|
|
|
mesBaseMaterialInfo.setPurchasePriceUnitId(Long.valueOf(purchasePriceUnitId));
|
|
|
|
|
mesBaseMaterialInfo.setCreateOrgId(createOrgId);
|
|
|
|
|
mesBaseMaterialInfo.setUseOrgId(useOrgId);
|
|
|
|
|
mesBaseMaterialInfo.setUpdateTime(currentDate);
|
|
|
|
|
mesBaseMaterialInfo.setPurchasePriceUnitId(purchasePriceUnitId);
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(createDateStr)) {
|
|
|
|
|
mesBaseMaterialInfo.setCreateTime(conversionERPTime(createDateStr));
|
|
|
|
@ -236,16 +286,13 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
mesBaseMaterialInfo.setApproveDate(conversionERPTime(approveDateStr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MesBaseMaterialInfo existedMesBaseMaterialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByErpId(Long.valueOf(erpId));
|
|
|
|
|
|
|
|
|
|
MesBaseMaterialInfo existedMesBaseMaterialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByErpId(erpId);
|
|
|
|
|
if (existedMesBaseMaterialInfo != null) {
|
|
|
|
|
mesBaseMaterialInfo.setMaterialId(existedMesBaseMaterialInfo.getMaterialId());
|
|
|
|
|
toUpdateMaterialInfoList.add(mesBaseMaterialInfo);
|
|
|
|
|
} else {
|
|
|
|
|
toInsertMaterialInfoList.add(mesBaseMaterialInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!toInsertMaterialInfoList.isEmpty()) {
|
|
|
|
@ -257,11 +304,12 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("size:"+resultArray.size());
|
|
|
|
|
/**分页递归获取所有物料信息*/
|
|
|
|
|
if (resultArray.size() == limit) {
|
|
|
|
|
// System.out.println(startRow);
|
|
|
|
|
//通过递归同步所有物料信息,测试先不用
|
|
|
|
|
int i = syncMaterialInfoFromErp(startRow + resultArray.size());
|
|
|
|
|
int i = syncMaterialInfoFromErp(startRow + resultArray.size(), maxErpModifyDate);
|
|
|
|
|
// return i;
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
@ -271,14 +319,23 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Descrption:从金蝶ERP同步销售订单
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int syncSaleOrderFromErp(int startRow) throws Exception {
|
|
|
|
|
String maxErpModifyDate = mesSaleOrderMapper.selectMaxErpModifyDate();
|
|
|
|
|
return syncSaleOrderFromErp(startRow, maxErpModifyDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Descrption:从金蝶ERP同步销售订单
|
|
|
|
|
*/
|
|
|
|
|
public int syncSaleOrderFromErp(int startRow,String maxErpModifyDate) throws Exception {
|
|
|
|
|
K3CloudApi api = new K3CloudApi();
|
|
|
|
|
String FDocumentStatus = "C";
|
|
|
|
|
// String FDocumentStatus = "C";
|
|
|
|
|
// String json = "{\n" +
|
|
|
|
|
// " \"FormId\": \"SAL_SaleOrder\",\n" +
|
|
|
|
|
// " \"FieldKeys\": \"FID,FBillNo,FApproveDate,FSaleOrderEntry_FEntryID,FMaterialId.FNumber,FMaterialName,FQty ,FMinPlanDeliveryDate,\",\n" +
|
|
|
|
@ -292,18 +349,18 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
|
|
|
|
|
JSONObject queryJson = new JSONObject();
|
|
|
|
|
String formId = "SAL_SaleOrder";
|
|
|
|
|
String fieldKeys = "FID,FBillNo,FApproveDate,FSaleOrderEntry_FEntryID,FMaterialId.FNumber,FMaterialName," +
|
|
|
|
|
"FQty,FModifyDate,FMinPlanDeliveryDate,FAuxPropId,FStockId,FOwnerId,FSaleDeptId,FPrice,FStockOrgId";
|
|
|
|
|
String fieldKeys = "FID,FBillNo,FApproveDate,FSaleOrderEntry_FEntryID,FMaterialId,FMaterialId.FNumber,FMaterialName,FDocumentStatus," +
|
|
|
|
|
"FQty,FCreateDate,FModifyDate,FMinPlanDeliveryDate,FAuxPropId,FStockId,FOwnerId,FSaleDeptId,FPrice,FStockOrgId,F_TOND_Base";
|
|
|
|
|
//
|
|
|
|
|
String filterString = "FNumber='98010102'";
|
|
|
|
|
filterString = "";
|
|
|
|
|
// String filterString = "FNumber='98010102'";
|
|
|
|
|
// String filterString = "";
|
|
|
|
|
String orderString = "";
|
|
|
|
|
int topRowCount = 0;
|
|
|
|
|
// int startRow = 0;
|
|
|
|
|
int limit = 10;
|
|
|
|
|
// int limit = 10;
|
|
|
|
|
queryJson.put("FormId", formId);
|
|
|
|
|
queryJson.put("FieldKeys", fieldKeys);
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
|
// queryJson.put("FilterString", filterString);
|
|
|
|
|
queryJson.put("OrderString", orderString);
|
|
|
|
|
queryJson.put("TopRowCount", topRowCount);
|
|
|
|
|
queryJson.put("StartRow", startRow);
|
|
|
|
@ -311,109 +368,123 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
queryJson.put("SubSystemId", "");
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
//条件查询
|
|
|
|
|
System.out.println("maxErpModifyDate=" + maxErpModifyDate);
|
|
|
|
|
if (StringUtils.isNotEmpty(maxErpModifyDate)) {
|
|
|
|
|
String filterString = "FModifyDate >'" + maxErpModifyDate + "'";
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
|
}
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
String result = api.billQuery(queryJson.toString());
|
|
|
|
|
JSONArray resultArray = JSONArray.parseArray(result);
|
|
|
|
|
System.out.println(resultArray.size());
|
|
|
|
|
System.out.println("销售订单单据查询接口: " + result);
|
|
|
|
|
|
|
|
|
|
List<MesSaleOrder> mesSaleOrderListInsert = new ArrayList<>();
|
|
|
|
|
List<MesSaleOrder> mesSaleOrderListUpdate = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < resultArray.size(); i++){
|
|
|
|
|
try{
|
|
|
|
|
List<MesSaleOrder> toInsertSaleOrderList = new ArrayList<>();
|
|
|
|
|
List<MesSaleOrder> toUpdateSaleOrderList = new ArrayList<>();
|
|
|
|
|
Date currentDate = new Date();
|
|
|
|
|
for (int i = 0; i < resultArray.size(); i++) {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject resultObject = (JSONObject) resultArray.get(i);
|
|
|
|
|
MesSaleOrder mesSaleOrder = new MesSaleOrder();
|
|
|
|
|
//erp主键
|
|
|
|
|
Integer erpId = (Integer) resultObject.get("FID");
|
|
|
|
|
Long erpId = resultObject.getLong("FID");
|
|
|
|
|
//销售订单编号id
|
|
|
|
|
String saleOrderCode = (String) resultObject.get("FBillNo");
|
|
|
|
|
String saleOrderCode = resultObject.getString("FBillNo");
|
|
|
|
|
//审核日期
|
|
|
|
|
String approveDate = resultObject.get("FApproveDate") == null ? null : (String) resultObject.get("FApproveDate");
|
|
|
|
|
String approveDate = resultObject.getString("FApproveDate");
|
|
|
|
|
//订单明细id
|
|
|
|
|
Integer fentyrId = resultObject.get("FSaleOrderEntry_FEntryID")==null?0:(Integer) resultObject.get("FSaleOrderEntry_FEntryID");
|
|
|
|
|
Long fentyrId = resultObject.getLong("FSaleOrderEntry.FEntryID");
|
|
|
|
|
//ERP物料id
|
|
|
|
|
Long fmaterialId = resultObject.getLong("FMaterialId");
|
|
|
|
|
//物料编码
|
|
|
|
|
String materialCode = resultObject.get("FMaterialId.FNumber")==null?null:(String) resultObject.get("FMaterialId.FNumber");
|
|
|
|
|
String materialCode = resultObject.getString("FMaterialId.FNumber");
|
|
|
|
|
//物料名称
|
|
|
|
|
String materialName = resultObject.get("FMaterialName")==null?null:(String) resultObject.get("FMaterialName");
|
|
|
|
|
String materialName = resultObject.getString("FMaterialName");
|
|
|
|
|
//订单数量
|
|
|
|
|
BigDecimal orderAmount = resultObject.get("FQty")==null?new BigDecimal(0):(BigDecimal) resultObject.get("FQty");
|
|
|
|
|
BigDecimal orderAmount = resultObject.getBigDecimal("FQty");
|
|
|
|
|
//erp最后修改日期
|
|
|
|
|
String erpModifyDate = resultObject.get("FModifyDate")==null?null:(String) resultObject.get("FModifyDate");
|
|
|
|
|
String erpModifyDate = resultObject.getString("FModifyDate");
|
|
|
|
|
//计划交货日期
|
|
|
|
|
String planDeliveryDate = resultObject.get("FMinPlanDeliveryDate")==null?null:(String) resultObject.get("FMinPlanDeliveryDate");
|
|
|
|
|
String planDeliveryDate = resultObject.getString("FMinPlanDeliveryDate");
|
|
|
|
|
//辅助属性
|
|
|
|
|
Integer auxPropId = resultObject.get("FAuxPropId")==null?0:(Integer) resultObject.get("FAuxPropId");
|
|
|
|
|
Long auxPropId = resultObject.getLong("FAuxPropId");
|
|
|
|
|
//仓库
|
|
|
|
|
Integer stockId = resultObject.get("FStockId")==null?0:(Integer) resultObject.get("FStockId");
|
|
|
|
|
Long stockId = resultObject.getLong("FStockId");
|
|
|
|
|
//货主
|
|
|
|
|
Integer ownerId = resultObject.get("FOwnerId")==null?0:(Integer) resultObject.get("FOwnerId");
|
|
|
|
|
Long ownerId = resultObject.getLong("FOwnerId");
|
|
|
|
|
//销售部门
|
|
|
|
|
Integer saleDeptId = resultObject.get("FSaleDeptId")==null?0:(Integer) resultObject.get("FSaleDeptId");
|
|
|
|
|
Long saleDeptId = resultObject.getLong("FSaleDeptId");
|
|
|
|
|
//单价
|
|
|
|
|
BigDecimal price = resultObject.get("FPrice")==null?new BigDecimal(0):(BigDecimal) resultObject.get("FPrice");
|
|
|
|
|
BigDecimal price = resultObject.getBigDecimal("FPrice");
|
|
|
|
|
//库存组织
|
|
|
|
|
Integer stockOrgId = resultObject.get("FStockOrgId")==null?0:(Integer) resultObject.get("FStockOrgId");
|
|
|
|
|
Long stockOrgId = resultObject.getLong("FStockOrgId");
|
|
|
|
|
//单据状态
|
|
|
|
|
String documentStatus = resultObject.getString("FDocumentStatus");
|
|
|
|
|
String tondBase = resultObject.getString("F.TOND.Base");
|
|
|
|
|
String FCreateDate = resultObject.getString("FCreateDate");
|
|
|
|
|
|
|
|
|
|
mesSaleOrder.setErpId(Long.valueOf(erpId));
|
|
|
|
|
mesSaleOrder.setErpId(erpId);
|
|
|
|
|
mesSaleOrder.setSaleorderCode(saleOrderCode);
|
|
|
|
|
mesSaleOrder.setFentryId(Long.valueOf(fentyrId));
|
|
|
|
|
//物料id
|
|
|
|
|
if (materialCode!=null){
|
|
|
|
|
if(mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByCode(materialCode)!=null){
|
|
|
|
|
mesSaleOrder.setMaterialId (mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByCode(materialCode).getMaterialId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mesSaleOrder.setFentryId(fentyrId);
|
|
|
|
|
mesSaleOrder.setDocumentStatus(documentStatus);
|
|
|
|
|
//erp物料id
|
|
|
|
|
mesSaleOrder.setMaterialId(fmaterialId);
|
|
|
|
|
mesSaleOrder.setMaterialCode(materialCode);
|
|
|
|
|
mesSaleOrder.setMaterialName(materialName);
|
|
|
|
|
mesSaleOrder.setOrderAmount(orderAmount);
|
|
|
|
|
mesSaleOrder.setAuxPropId(Long.valueOf(auxPropId));
|
|
|
|
|
mesSaleOrder.setStockId(Long.valueOf(stockId));
|
|
|
|
|
mesSaleOrder.setOwnerId(Long.valueOf(ownerId));
|
|
|
|
|
mesSaleOrder.setSaleDeptId(Long.valueOf(saleDeptId));
|
|
|
|
|
mesSaleOrder.setAuxPropId(auxPropId);
|
|
|
|
|
mesSaleOrder.setStockId(stockId);
|
|
|
|
|
mesSaleOrder.setOwnerId(ownerId);
|
|
|
|
|
mesSaleOrder.setSaleDeptId(saleDeptId);
|
|
|
|
|
mesSaleOrder.setPrice(price);
|
|
|
|
|
mesSaleOrder.setStockOrgId(Long.valueOf(stockOrgId));
|
|
|
|
|
if (planDeliveryDate!=null){
|
|
|
|
|
mesSaleOrder.setStockOrgId(stockOrgId);
|
|
|
|
|
mesSaleOrder.setTondBase(tondBase);
|
|
|
|
|
mesSaleOrder.setUpdateTime(currentDate);
|
|
|
|
|
if (StringUtils.isNotEmpty(FCreateDate)) {
|
|
|
|
|
mesSaleOrder.setCreateTime(conversionERPTime(FCreateDate));
|
|
|
|
|
}
|
|
|
|
|
if (planDeliveryDate != null) {
|
|
|
|
|
mesSaleOrder.setPlanDeliveryDate(conversionERPTime(planDeliveryDate));
|
|
|
|
|
}
|
|
|
|
|
if (erpModifyDate!=null){
|
|
|
|
|
if (erpModifyDate != null) {
|
|
|
|
|
mesSaleOrder.setErpModifyDate(conversionERPTime(erpModifyDate));
|
|
|
|
|
}
|
|
|
|
|
if (approveDate!=null){
|
|
|
|
|
if (approveDate != null) {
|
|
|
|
|
mesSaleOrder.setApproveDate(conversionERPTime(approveDate));
|
|
|
|
|
}
|
|
|
|
|
MesSaleOrder mesSaleOrder1 = mesSaleOrderMapper.selectMesSaleOrderByErpId(Long.valueOf(erpId));
|
|
|
|
|
if (mesSaleOrder1!=null){
|
|
|
|
|
mesSaleOrder.setSaleOrderId(mesSaleOrder1.getSaleOrderId());
|
|
|
|
|
mesSaleOrderMapper.insertMesSaleOrder(mesSaleOrder);
|
|
|
|
|
// mesSaleOrderListUpdate.add(mesSaleOrder);
|
|
|
|
|
|
|
|
|
|
MesSaleOrder existedMesSaleOrder = mesSaleOrderMapper.selectMesSaleOrderByUI(erpId, fentyrId);
|
|
|
|
|
if (existedMesSaleOrder != null) {
|
|
|
|
|
mesSaleOrder.setSaleOrderId(existedMesSaleOrder.getSaleOrderId());
|
|
|
|
|
toUpdateSaleOrderList.add(mesSaleOrder);
|
|
|
|
|
} else {
|
|
|
|
|
toInsertSaleOrderList.add(mesSaleOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// mesSaleOrderListInsert.add(mesSaleOrder);
|
|
|
|
|
mesSaleOrderMapper.updateMesSaleOrder(mesSaleOrder);
|
|
|
|
|
}
|
|
|
|
|
// if (mesSaleOrderListInsert!=null){
|
|
|
|
|
// for (MesSaleOrder mesSaleOrders : mesSaleOrderListInsert){
|
|
|
|
|
// mesSaleOrderMapper.insertMesSaleOrder(mesSaleOrders);
|
|
|
|
|
// System.out.println(mesSaleOrders);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if (mesSaleOrderListUpdate != null) {
|
|
|
|
|
// for (MesSaleOrder mesSaleOrders : mesSaleOrderListUpdate){
|
|
|
|
|
// mesSaleOrderMapper.updateMesSaleOrder(mesSaleOrders);
|
|
|
|
|
// System.out.println(mesSaleOrders);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!toInsertSaleOrderList.isEmpty()) {
|
|
|
|
|
mesSaleOrderMapper.batchMesBaseSaleOrder(toInsertSaleOrderList);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
if (!toUpdateSaleOrderList.isEmpty()) {
|
|
|
|
|
for (MesSaleOrder toUpdatedSaleOrder : toUpdateSaleOrderList) {
|
|
|
|
|
mesSaleOrderMapper.updateMesSaleOrder(toUpdatedSaleOrder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("size:"+resultArray.size());
|
|
|
|
|
|
|
|
|
|
/**分页递归获取所有物料信息*/
|
|
|
|
|
if (resultArray.size() == limit) {
|
|
|
|
|
// System.out.println(startRow);
|
|
|
|
|
//通过递归同步所有物料信息,测试先不用
|
|
|
|
|
int i = syncSaleOrderFromErp(startRow + resultArray.size());
|
|
|
|
|
int i = syncSaleOrderFromErp(startRow + resultArray.size(),maxErpModifyDate);
|
|
|
|
|
// return i;
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
@ -423,27 +494,35 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Descrption:从金蝶ERP同步项目信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int syncProjectInfoFromErp(int startRow) throws Exception {
|
|
|
|
|
K3CloudApi api = new K3CloudApi();
|
|
|
|
|
String FDocumentStatus = "C";
|
|
|
|
|
String maxErpModifyDate = mesProjectInfoMapper.selectMaxErpModifyDate();
|
|
|
|
|
return syncProjectInfoFromErp(startRow,maxErpModifyDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Descrption:从金蝶ERP同步项目信息
|
|
|
|
|
*/
|
|
|
|
|
public int syncProjectInfoFromErp(int startRow,String maxErpModifyDate) throws Exception {
|
|
|
|
|
K3CloudApi api = new K3CloudApi();
|
|
|
|
|
// String FDocumentStatus = "C";
|
|
|
|
|
|
|
|
|
|
JSONObject queryJson = new JSONObject();
|
|
|
|
|
String formId = "TOND_ProjectFile";
|
|
|
|
|
String fieldKeys = "FID,FNumber,FName,FPlanDate,FDocumentStatus,FForbidStatus,FCreateDate,FModifyDate,FAuditDate";
|
|
|
|
|
String filterString = "";
|
|
|
|
|
// String filterString = "";
|
|
|
|
|
String orderString = "";
|
|
|
|
|
int topRowCount = 0;
|
|
|
|
|
// int startRow = 0;
|
|
|
|
|
int limit = 20;
|
|
|
|
|
// int limit = 20;
|
|
|
|
|
queryJson.put("FormId", formId);
|
|
|
|
|
queryJson.put("FieldKeys", fieldKeys);
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
|
// queryJson.put("FilterString", filterString);
|
|
|
|
|
queryJson.put("OrderString", orderString);
|
|
|
|
|
queryJson.put("TopRowCount", topRowCount);
|
|
|
|
|
queryJson.put("StartRow", startRow);
|
|
|
|
@ -451,33 +530,42 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
queryJson.put("SubSystemId", "");
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
//条件查询
|
|
|
|
|
System.out.println("maxErpModifyDate=" + maxErpModifyDate);
|
|
|
|
|
if (StringUtils.isNotEmpty(maxErpModifyDate)) {
|
|
|
|
|
String filterString = "FModifyDate >'" + maxErpModifyDate + "'";
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
|
}
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
String result = api.billQuery(queryJson.toString());
|
|
|
|
|
JSONArray resultArray = JSONArray.parseArray(result);
|
|
|
|
|
System.out.println(resultArray.size());
|
|
|
|
|
System.out.println("项目信息单据查询接口: " + result);
|
|
|
|
|
|
|
|
|
|
List<MesProjectInfo> toInsertProjectInfoList = new ArrayList<>();
|
|
|
|
|
List<MesProjectInfo> toUpdateProjectInfoList = new ArrayList<>();
|
|
|
|
|
Date currentDate = new Date();
|
|
|
|
|
for (int i = 0; i < resultArray.size(); i++) {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject resultObject = (JSONObject) resultArray.get(i);
|
|
|
|
|
MesProjectInfo mesProjectInfo = new MesProjectInfo();
|
|
|
|
|
List<MesProjectInfo> projectInfoListUpdate = new ArrayList<MesProjectInfo>();
|
|
|
|
|
List<MesProjectInfo> projectInfoListInsert = new ArrayList<MesProjectInfo>();
|
|
|
|
|
|
|
|
|
|
Integer FID = resultObject.get("FID") == null ? 0 : (Integer) resultObject.get("FID");
|
|
|
|
|
String FNumber = resultObject.get("FNumber") == null ? null : (String) resultObject.get("FNumber");
|
|
|
|
|
String FName = resultObject.get("FName") == null ? null : (String) resultObject.get("FName");
|
|
|
|
|
// String FDocumentStatus = resultObject.get("FDocumentStatus")==null? null:(String)resultObject.get("FDocumentStatus");
|
|
|
|
|
String FForbidStatus = resultObject.get("FForbidStatus") == null ? null : (String) resultObject.get("FForbidStatus");
|
|
|
|
|
String FAuditDate = resultObject.get("FAuditDate") == null ? null : (String) resultObject.get("FAuditDate");
|
|
|
|
|
String FModifyDate = resultObject.get("FModifyDate") == null ? null : (String) resultObject.get("FModifyDate");
|
|
|
|
|
String FCreateDate = resultObject.get("FCreateDate") == null ? null : (String) resultObject.get("FCreateDate");
|
|
|
|
|
|
|
|
|
|
mesProjectInfo.setErpId(Long.valueOf(FID));
|
|
|
|
|
Long erpId = resultObject.getLong("FID");
|
|
|
|
|
String FNumber = resultObject.getString("FNumber");
|
|
|
|
|
String FName = resultObject.getString("FName");
|
|
|
|
|
String FDocumentStatus = resultObject.getString("FDocumentStatus");
|
|
|
|
|
String FForbidStatus = resultObject.getString("FForbidStatus");
|
|
|
|
|
String FAuditDate = resultObject.getString("FAuditDate");
|
|
|
|
|
String FModifyDate = resultObject.getString("FModifyDate");
|
|
|
|
|
String FCreateDate = resultObject.getString("FCreateDate");
|
|
|
|
|
|
|
|
|
|
mesProjectInfo.setErpId(erpId);
|
|
|
|
|
mesProjectInfo.setProjectNo(FNumber);
|
|
|
|
|
mesProjectInfo.setProjectName(FName);
|
|
|
|
|
mesProjectInfo.setDocumentStatus(FDocumentStatus);
|
|
|
|
|
mesProjectInfo.setForbidStatus(FForbidStatus);
|
|
|
|
|
mesProjectInfo.setIsFlag("1");
|
|
|
|
|
mesProjectInfo.setUpdateTime(currentDate);
|
|
|
|
|
if (StringUtils.isNotEmpty(FAuditDate)) {
|
|
|
|
|
mesProjectInfo.setAuditDate(conversionERPTime(FAuditDate));
|
|
|
|
|
}
|
|
|
|
@ -488,38 +576,34 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
mesProjectInfo.setCreateTime(conversionERPTime(FCreateDate));
|
|
|
|
|
}
|
|
|
|
|
// System.out.println(mesProjectInfo);
|
|
|
|
|
MesProjectInfo mesProjectInfo1 = mesProjectInfoMapper.selectMesProjectInfoByErpId(mesProjectInfo.getErpId());
|
|
|
|
|
MesProjectInfo existedProjectInfo = mesProjectInfoMapper.selectMesProjectInfoByErpId(erpId);
|
|
|
|
|
|
|
|
|
|
if (mesProjectInfo1 != null)
|
|
|
|
|
{
|
|
|
|
|
mesProjectInfo.setProjectId(mesProjectInfo1.getProjectId());
|
|
|
|
|
projectInfoListUpdate.add(mesProjectInfo);
|
|
|
|
|
if (existedProjectInfo != null) {
|
|
|
|
|
mesProjectInfo.setProjectId(existedProjectInfo.getProjectId());
|
|
|
|
|
toUpdateProjectInfoList.add(mesProjectInfo);
|
|
|
|
|
} else {
|
|
|
|
|
toInsertProjectInfoList.add(mesProjectInfo);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
projectInfoListInsert.add(mesProjectInfo);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (!projectInfoListUpdate.isEmpty()){
|
|
|
|
|
for (MesProjectInfo projectInfo : projectInfoListUpdate){
|
|
|
|
|
mesProjectInfoMapper.updateMesProjectInfo(projectInfo);
|
|
|
|
|
System.out.println(projectInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!toInsertProjectInfoList.isEmpty()) {
|
|
|
|
|
mesProjectInfoMapper.batchMesBaseProjectInfo(toInsertProjectInfoList);
|
|
|
|
|
}
|
|
|
|
|
if (!projectInfoListInsert.isEmpty()){
|
|
|
|
|
for (MesProjectInfo projectInfo : projectInfoListInsert){
|
|
|
|
|
mesProjectInfoMapper.insertMesProjectInfo(projectInfo);
|
|
|
|
|
System.out.println(projectInfo);
|
|
|
|
|
if (!toUpdateProjectInfoList.isEmpty()) {
|
|
|
|
|
for (MesProjectInfo toUpdatedProjectInfo : toUpdateProjectInfoList) {
|
|
|
|
|
mesProjectInfoMapper.updateMesProjectInfo(toUpdatedProjectInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("size:"+resultArray.size());
|
|
|
|
|
/**分页递归获取所有物料信息*/
|
|
|
|
|
if (resultArray.size() == limit) {
|
|
|
|
|
// System.out.println(startRow);
|
|
|
|
|
//通过递归同步所有物料信息,测试先不用
|
|
|
|
|
int i = syncProjectInfoFromErp(startRow + resultArray.size());
|
|
|
|
|
int i = syncProjectInfoFromErp(startRow + resultArray.size(),maxErpModifyDate);
|
|
|
|
|
// return i;
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
@ -532,23 +616,31 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Descrption:从金蝶ERP同步采购订单
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int syncPurchaseOrderFromErp(int startRow) throws Exception {
|
|
|
|
|
K3CloudApi api = new K3CloudApi();
|
|
|
|
|
String FDocumentStatus = "C";
|
|
|
|
|
|
|
|
|
|
String maxErpModifyDate = mesPurchaseOrderMapper.selectMaxErpModifyDate();
|
|
|
|
|
return syncPurchaseOrderFromErp(startRow,maxErpModifyDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @Descrption:从金蝶ERP同步采购订单
|
|
|
|
|
*/
|
|
|
|
|
public int syncPurchaseOrderFromErp(int startRow,String maxErpModifyDate) throws Exception {
|
|
|
|
|
K3CloudApi api = new K3CloudApi();
|
|
|
|
|
// String FDocumentStatus = "C";
|
|
|
|
|
JSONObject queryJson = new JSONObject();
|
|
|
|
|
String formId = "PUR_PurchaseOrder";
|
|
|
|
|
String fieldKeys = "FID,FBillNo,FApproveDate,FDocumentStatus,FPOOrderEntry_FEntryID,FMaterialId.FNumber,FMaterialId.FName," +
|
|
|
|
|
"FQty,FDeliveryDate,FUnitId,FStockUnitID,FPriceUnitID,FAuxPropId,FSrcBillNo,FPurchaseOrgId,F_TOND_Base,FSupplierId";
|
|
|
|
|
String filterString = "";
|
|
|
|
|
String fieldKeys = "FID,FBillNo,FApproveDate,FDocumentStatus,FPOOrderEntry_FEntryID,FMaterialId,FMaterialId.FNumber,FMaterialId.FName," +
|
|
|
|
|
"FQty,FDeliveryDate,FCreateDate,FModifyDate,FUnitId,FStockUnitID,FPriceUnitID,FAuxPropId,FSrcBillNo,FPurchaseOrgId,F_TOND_Base,FSupplierId";
|
|
|
|
|
// String filterString = "";
|
|
|
|
|
String orderString = "";
|
|
|
|
|
int topRowCount = 0;
|
|
|
|
|
// int startRow = 0;
|
|
|
|
|
int limit = 20;
|
|
|
|
|
// int limit = 20;
|
|
|
|
|
queryJson.put("FormId", formId);
|
|
|
|
|
queryJson.put("FieldKeys", fieldKeys);
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
|
// queryJson.put("FilterString", filterString);
|
|
|
|
|
queryJson.put("OrderString", orderString);
|
|
|
|
|
queryJson.put("TopRowCount", topRowCount);
|
|
|
|
|
queryJson.put("StartRow", startRow);
|
|
|
|
@ -556,92 +648,130 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
queryJson.put("SubSystemId", "");
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
//条件查询
|
|
|
|
|
System.out.println("maxErpModifyDate=" + maxErpModifyDate);
|
|
|
|
|
if (StringUtils.isNotEmpty(maxErpModifyDate)) {
|
|
|
|
|
String filterString = "FModifyDate >'" + maxErpModifyDate + "'";
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
|
}
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
String result = api.billQuery(queryJson.toString());
|
|
|
|
|
JSONArray resultArray = JSONArray.parseArray(result);
|
|
|
|
|
System.out.println(resultArray.size());
|
|
|
|
|
System.out.println("采购订单单据查询接口: " + result);
|
|
|
|
|
List<MesPurchaseOrder> mesPurchaseOrderListUpdate = new ArrayList<MesPurchaseOrder>();
|
|
|
|
|
List<MesPurchaseOrder> mesPurchaseOrderListInsert = new ArrayList<>();
|
|
|
|
|
for (int i = 0 ;i < resultArray.size();i++){
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
List<MesPurchaseOrder> toInsertPurchaseOrderList = new ArrayList<>();
|
|
|
|
|
List<MesPurchaseOrder> toUpdatePurchaseOrderList = new ArrayList<>();
|
|
|
|
|
Date currentDate = new Date();
|
|
|
|
|
for (int i = 0; i < resultArray.size(); i++) {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject resultObject = (JSONObject) resultArray.get(i);
|
|
|
|
|
MesPurchaseOrder mesPurchaseOrder = new MesPurchaseOrder();
|
|
|
|
|
//erpid
|
|
|
|
|
Integer erpId = resultObject.get("FID")==null?null :(Integer) resultObject.get("FID");
|
|
|
|
|
Long erpId = resultObject.getLong("FID");
|
|
|
|
|
//采购订单编号
|
|
|
|
|
String poNo = resultObject.get("FBillNo")==null?null :(String) resultObject.get("FBillNo");
|
|
|
|
|
String poNo = resultObject.getString("FBillNo");
|
|
|
|
|
//审核日期
|
|
|
|
|
String approveDate = resultObject.get("FApproveDate")==null?null :(String) resultObject.get("FApproveDate");
|
|
|
|
|
String approveDate = resultObject.getString("FApproveDate");
|
|
|
|
|
//单据状态
|
|
|
|
|
String documentStatus = resultObject.get("FDocumentStatus")==null?null :(String) resultObject.get("FDocumentStatus");
|
|
|
|
|
String documentStatus = resultObject.getString("FDocumentStatus");
|
|
|
|
|
//订单明细id
|
|
|
|
|
Integer fentryId = resultObject.get("FPOOrderEntry.FEntryID")==null?null:(Integer) resultObject.get("FPOOrderEntry.FEntryID");
|
|
|
|
|
Long fentryId = resultObject.getLong("FPOOrderEntry.FEntryID");
|
|
|
|
|
//erp物料ID
|
|
|
|
|
Long fmaterialId = resultObject.getLong("FMaterialId");
|
|
|
|
|
//物料编码
|
|
|
|
|
String materialCode = resultObject.get("FMaterialId.FNumber")==null?null:(String) resultObject.get("FMaterialId.FNumber");
|
|
|
|
|
String materialCode = resultObject.getString("FMaterialId.FNumber");
|
|
|
|
|
//物料名称
|
|
|
|
|
String materialName = resultObject.get("FMaterialId.FName")==null?null:(String) resultObject.get("FMaterialId.FName");
|
|
|
|
|
String materialName = resultObject.getString("FMaterialId.FName");
|
|
|
|
|
//订单计划数量
|
|
|
|
|
BigDecimal orderAmount = resultObject.get("FQty")==null?new BigDecimal(0):(BigDecimal) resultObject.get("FQty");
|
|
|
|
|
BigDecimal orderAmount = resultObject.getBigDecimal("FQty");
|
|
|
|
|
//计划交货日期
|
|
|
|
|
String planDeliveryDate = resultObject.get("FDeliveryDate")==null?null:(String) resultObject.get("FDeliveryDate");
|
|
|
|
|
String planDeliveryDate = resultObject.getString("FDeliveryDate");
|
|
|
|
|
//采购单位
|
|
|
|
|
Integer unitId = resultObject.get("FUnitId")==null?null:(Integer) resultObject.get("FUnitId");
|
|
|
|
|
Long unitId = resultObject.getLong("FUnitId");
|
|
|
|
|
//库存单位
|
|
|
|
|
Integer stockUnitId = resultObject.get("FStockUnitID")==null?null:(Integer) resultObject.get("FStockUnitID");
|
|
|
|
|
Long stockUnitId = resultObject.getLong("FStockUnitID");
|
|
|
|
|
//计价单位
|
|
|
|
|
Integer priceUnitId = resultObject.get("FPriceUnitID")==null?null:(Integer) resultObject.get("FPriceUnitID");
|
|
|
|
|
Long priceUnitId = resultObject.getLong("FPriceUnitID");
|
|
|
|
|
//辅助属性
|
|
|
|
|
Integer auxPropId = resultObject.get("FAuxPropId") == null?null:(Integer) resultObject.get("FAuxPropId");
|
|
|
|
|
Long auxPropId = resultObject.getLong("FAuxPropId");
|
|
|
|
|
//源单编号
|
|
|
|
|
String srcBillNo = resultObject.get("FSrcBillNo") == null?null:(String) resultObject.get("FSrcBillNo");
|
|
|
|
|
String srcBillNo = resultObject.getString("FSrcBillNo");
|
|
|
|
|
//采购组织
|
|
|
|
|
Integer purchaseOrgId = resultObject.get("FPurchaseOrgId") ==null?null:(Integer) resultObject.get("FPurchaseOrgId");
|
|
|
|
|
Long purchaseOrgId = resultObject.getLong("FPurchaseOrgId");
|
|
|
|
|
//京源项目
|
|
|
|
|
String tondBase = resultObject.get("F_TOND_Base")==null?null:(String) resultObject.get("F_TOND_Base");
|
|
|
|
|
String tondBase = resultObject.getString("F.TOND.Base");
|
|
|
|
|
//供应商id
|
|
|
|
|
Integer supplierId = resultObject.get("FSupplierId")==null?null:(Integer) resultObject.get("FSupplierId");
|
|
|
|
|
Long supplierId = resultObject.getLong("FSupplierId");
|
|
|
|
|
|
|
|
|
|
//创建时间
|
|
|
|
|
String FCreateDate = resultObject.getString("FCreateDate");
|
|
|
|
|
//更新时间
|
|
|
|
|
String FModifyDate = resultObject.getString("FModifyDate");
|
|
|
|
|
|
|
|
|
|
mesPurchaseOrder.setErpId(Long.valueOf(erpId));
|
|
|
|
|
mesPurchaseOrder.setErpId(erpId);
|
|
|
|
|
mesPurchaseOrder.setPoNo(poNo);
|
|
|
|
|
mesPurchaseOrder.setDocumentStatus(documentStatus);
|
|
|
|
|
mesPurchaseOrder.setFentryId(Long.valueOf(fentryId));
|
|
|
|
|
mesPurchaseOrder.setFentryId(fentryId);
|
|
|
|
|
mesPurchaseOrder.setMaterialId(fmaterialId);
|
|
|
|
|
mesPurchaseOrder.setMaterialCode(materialCode);
|
|
|
|
|
mesPurchaseOrder.setMaterialCode(materialName);
|
|
|
|
|
mesPurchaseOrder.setMaterialName(materialName);
|
|
|
|
|
mesPurchaseOrder.setOrderAmount(orderAmount);
|
|
|
|
|
mesPurchaseOrder.setUnitId(unitId.toString());
|
|
|
|
|
mesPurchaseOrder.setStockUnitId(Long.valueOf(stockUnitId));
|
|
|
|
|
mesPurchaseOrder.setPriceUnitId(Long.valueOf(priceUnitId));
|
|
|
|
|
mesPurchaseOrder.setAuxPropId(Long.valueOf(auxPropId));
|
|
|
|
|
mesPurchaseOrder.setUnitId(unitId);
|
|
|
|
|
mesPurchaseOrder.setStockUnitId(stockUnitId);
|
|
|
|
|
mesPurchaseOrder.setPriceUnitId(priceUnitId);
|
|
|
|
|
mesPurchaseOrder.setAuxPropId(auxPropId);
|
|
|
|
|
mesPurchaseOrder.setSrcBillNo(srcBillNo);
|
|
|
|
|
mesPurchaseOrder.setPurchaseOrgId(Long.valueOf(purchaseOrgId));
|
|
|
|
|
mesPurchaseOrder.setPurchaseOrgId(purchaseOrgId);
|
|
|
|
|
mesPurchaseOrder.setTondBase(tondBase);
|
|
|
|
|
mesPurchaseOrder.setSupplierId(Long.valueOf(supplierId));
|
|
|
|
|
if (approveDate!=null){
|
|
|
|
|
mesPurchaseOrder.setSupplierId(supplierId);
|
|
|
|
|
mesPurchaseOrder.setUpdateTime(currentDate);
|
|
|
|
|
if (approveDate != null) {
|
|
|
|
|
mesPurchaseOrder.setApproveDate(conversionERPTime(approveDate));
|
|
|
|
|
}
|
|
|
|
|
if (planDeliveryDate!=null){
|
|
|
|
|
if (planDeliveryDate != null) {
|
|
|
|
|
mesPurchaseOrder.setPlanDeliveryDate(conversionERPTime(planDeliveryDate));
|
|
|
|
|
}
|
|
|
|
|
MesPurchaseOrder mesPurchaseOrder1 = mesPurchaseOrderMapper.selectMesPurchaseOrderByErpId(Long.valueOf(erpId));
|
|
|
|
|
if (mesPurchaseOrder1!=null){
|
|
|
|
|
mesPurchaseOrder.setPurchaseOrgId(mesPurchaseOrder1.getPurchaseOrgId());
|
|
|
|
|
mesPurchaseOrderMapper.updateMesPurchaseOrder(mesPurchaseOrder);
|
|
|
|
|
if (StringUtils.isNotEmpty(FCreateDate)) {
|
|
|
|
|
mesPurchaseOrder.setCreateTime(conversionERPTime(FCreateDate));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
mesPurchaseOrderMapper.insertMesPurchaseOrder(mesPurchaseOrder);
|
|
|
|
|
if (StringUtils.isNotEmpty(FModifyDate)) {
|
|
|
|
|
mesPurchaseOrder.setErpModifyDate(conversionERPTime(FModifyDate));
|
|
|
|
|
}
|
|
|
|
|
// if (StringUtils.isNotEmpty(FAuditDate)) {
|
|
|
|
|
// mesPurchaseOrder.setAuditDate(conversionERPTime(FAuditDate));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
MesPurchaseOrder existedPurchaseOrder = mesPurchaseOrderMapper.selectMesPurchaseOrderByUI(erpId, fentryId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
if (existedPurchaseOrder != null) {
|
|
|
|
|
mesPurchaseOrder.setPurchaseOrderId(existedPurchaseOrder.getPurchaseOrderId());
|
|
|
|
|
toUpdatePurchaseOrderList.add(mesPurchaseOrder);
|
|
|
|
|
} else {
|
|
|
|
|
toInsertPurchaseOrderList.add(mesPurchaseOrder);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!toInsertPurchaseOrderList.isEmpty()) {
|
|
|
|
|
mesPurchaseOrderMapper.batchMesBasePurchaseOrder(toInsertPurchaseOrderList);
|
|
|
|
|
}
|
|
|
|
|
if (!toUpdatePurchaseOrderList.isEmpty()) {
|
|
|
|
|
for (MesPurchaseOrder toUpdatePurchaseOrder : toUpdatePurchaseOrderList) {
|
|
|
|
|
mesPurchaseOrderMapper.updateMesPurchaseOrder(toUpdatePurchaseOrder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("size:"+resultArray.size());
|
|
|
|
|
/**分页递归获取所有物料信息*/
|
|
|
|
|
if (resultArray.size() == limit) {
|
|
|
|
|
// System.out.println(startRow);
|
|
|
|
|
//通过递归同步所有物料信息,测试先不用
|
|
|
|
|
int i = syncPurchaseOrderFromErp(startRow + resultArray.size());
|
|
|
|
|
int i = syncPurchaseOrderFromErp(startRow + resultArray.size(),maxErpModifyDate);
|
|
|
|
|
// return i;
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
@ -651,8 +781,10 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
KingdeeErpSyncServiceImpl k = new KingdeeErpSyncServiceImpl();
|
|
|
|
|
k.syncProjectInfoFromErp(0,"");
|
|
|
|
|
// int i = syncSupplierInfoFromErp(0);
|
|
|
|
|
// syncMaterialInfoFromErp();
|
|
|
|
|
// syncMaterialInfoFromErpTest(0);
|
|
|
|
|
// syncSaleOrderFromErp();
|
|
|
|
|
// syncPurchaseOrderFromErp();
|
|
|
|
|
// syncProjectInfoFromErp();
|
|
|
|
@ -664,4 +796,51 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
|
|
|
|
|
Date date = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", ERPTime);
|
|
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int syncMaterialInfoFromErpTest(int startRow) throws Exception {
|
|
|
|
|
K3CloudApi api = new K3CloudApi();
|
|
|
|
|
String FDocumentStatus = "C";
|
|
|
|
|
|
|
|
|
|
JSONObject queryJson = new JSONObject();
|
|
|
|
|
String formId = "BD_Material";
|
|
|
|
|
String fieldKeys = "FMaterialId,FNumber,FName,FDocumentStatus,FForbidStatus,FMaterialGroup.FNUMBER,FBaseUnitId,FSpecification,FNETWEIGHT,FGROSSWEIGHT," +
|
|
|
|
|
"FCreateDate,FModifyDate,FApproveDate,FCreateOrgId,FUseOrgId,FPurchasePriceUnitId";
|
|
|
|
|
// String filterString = "FNumber='98010102'";
|
|
|
|
|
String orderString = "";
|
|
|
|
|
int topRowCount = 0;
|
|
|
|
|
// int startRow = 0;
|
|
|
|
|
// int limit = 20;
|
|
|
|
|
queryJson.put("FormId", formId);
|
|
|
|
|
queryJson.put("FieldKeys", fieldKeys);
|
|
|
|
|
queryJson.put("OrderString", orderString);
|
|
|
|
|
queryJson.put("TopRowCount", topRowCount);
|
|
|
|
|
queryJson.put("StartRow", startRow);
|
|
|
|
|
queryJson.put("Limit", limit);
|
|
|
|
|
queryJson.put("SubSystemId", "");
|
|
|
|
|
|
|
|
|
|
//条件查询
|
|
|
|
|
String filterString = "FNumber ='01010001'";
|
|
|
|
|
queryJson.put("FilterString", filterString);
|
|
|
|
|
|
|
|
|
|
System.out.println(queryJson.toString());
|
|
|
|
|
|
|
|
|
|
String result = api.billQuery(queryJson.toString());
|
|
|
|
|
if (StringUtils.isEmpty(result)) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONArray resultArray = JSONArray.parseArray(result);
|
|
|
|
|
if (resultArray == null) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
System.out.println("物料单据查询接口: " + result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|