diff --git a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/controller/KingdeeErpSyncController.java b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/controller/KingdeeErpSyncController.java index 999ea49..a11c012 100644 --- a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/controller/KingdeeErpSyncController.java +++ b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/controller/KingdeeErpSyncController.java @@ -32,6 +32,21 @@ public class KingdeeErpSyncController { @Autowired private KingdeeErpService kingdeeErpService; + /** + * 从erp中同步单位数据到MES + */ + @PostMapping("/syncUnitInfoFromErp") + @Log(title = "ERP单位信息", businessType = BusinessType.INSERT) +// @InnerAuth + public AjaxResult syncUnitInfoFromErp(@RequestBody ErpSyncInfoVo erpSyncInfoVo) { + try { + return AjaxResult.success(kingdeeErpSyncService.syncUnitInfoFromErp(0, erpSyncInfoVo)); + } catch (Exception e) { + logger.error("同步单位信息错误:" + e.getMessage()); + return AjaxResult.error(); + } + } + /** * 从erp中同步供应商数据到MES */ diff --git a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/IKingdeeErpSyncService.java b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/IKingdeeErpSyncService.java index 1cac101..5d161e8 100644 --- a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/IKingdeeErpSyncService.java +++ b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/IKingdeeErpSyncService.java @@ -4,6 +4,12 @@ import com.hw.jindie.api.domain.vo.ErpSyncInfoVo; public interface IKingdeeErpSyncService { + /** + * @throws Exception + * @Description:从金蝶ERP同步单位信息 + */ + public int syncUnitInfoFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception; + public int syncSupplierInfoFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception; public int syncMaterialInfoFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception; public int syncProjectInfoFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception; diff --git a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/impl/KingdeeErpSyncServiceImpl.java b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/impl/KingdeeErpSyncServiceImpl.java index c2e7f22..b2d41e7 100644 --- a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/impl/KingdeeErpSyncServiceImpl.java +++ b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/impl/KingdeeErpSyncServiceImpl.java @@ -39,6 +39,151 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { private static final int limit = 100; + /** + * @throws Exception + * @Description:从金蝶ERP同步单位信息 + */ + @Override + public int syncUnitInfoFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception { +// String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate()) ? +// mesBaseSupplierInfoMapper.selectMaxErpModifyDate() : erpSyncInfoVo.getMaxErpModifyDate(); + String maxErpModifyDate = erpSyncInfoVo.getMaxErpModifyDate(); + return syncUnitInfoFromErp(startRow, maxErpModifyDate); + } + + + /** + * @throws Exception + * @Description:从金蝶ERP同步单位信息,递归使用 + */ + public int syncUnitInfoFromErp(int startRow, String maxErpModifyDate) throws Exception { + System.out.println("startRow=" + startRow + ",,,maxErpModifyDate=" + maxErpModifyDate); + K3CloudApi api = new K3CloudApi(); + JSONObject queryJson = new JSONObject(); + String formId = "BD_Unit"; + String fieldKeys = "FUnitId,FNumber,FName,FCreateDate,FModifyDate"; + String orderString = ""; + int topRowCount = 0; +// int startRow = 0; +// int limit = 2; + 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", ""); + + //条件查询 + 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); +// } +// System.out.println(queryJson.toString()); + +// "FieldKeys": "FNumber,FName,FBaseUnitId,FSpecification,FNETWEIGHT,FGROSSWEIGHT,FCreateDate,FModifyDate,FApproveDate", +// "FilterString": "FDocumentStatus='C' AND FCreateDate>'2022-01-01' and FMaterialGroup.FNUMBER IN ('28')", + + + String result = api.billQuery(queryJson.toString()); + if (StringUtils.isEmpty(result)) { + return 1; + } + + JSONArray resultArray = JSONArray.parseArray(result); + if (resultArray == null) { + return 1; + } + +// List toInsertSupplierInfoList = new ArrayList<>(); +// List 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 = resultObject.getString("FNumber"); +// //供应商名称 +// String FName = resultObject.getString("FName"); +// //erp主键id +// Long erpId = resultObject.getLong("FSupplierId"); +// //创建时间 +// String FCreateDate = resultObject.getString("FCreateDate"); +// //更新时间 +// String FModifyDate = resultObject.getString("FModifyDate"); +// //审核日期 +// String FAuditDate = resultObject.getString("FAuditDate"); +// +// mesBaseSupplierInfo.setErpId(erpId); +// mesBaseSupplierInfo.setSupplierCode(FNumber); +// mesBaseSupplierInfo.setSupplierName(FName); +// +// //供应商状态 +// mesBaseSupplierInfo.setSupplierStatus("1"); +// mesBaseSupplierInfo.setUpdateTime(currentDate); +// +// if (StringUtils.isNotEmpty(FCreateDate)) { +// mesBaseSupplierInfo.setCreateTime(conversionERPTime(FCreateDate)); +// } +// if (StringUtils.isNotEmpty(FModifyDate)) { +// mesBaseSupplierInfo.setErpModifyDate(conversionERPTime(FModifyDate)); +// } +// if (StringUtils.isNotEmpty(FAuditDate)) { +// mesBaseSupplierInfo.setAuditDate(conversionERPTime(FAuditDate)); +// } +// +// MesBaseSupplierInfo existedMesBaseSupplierInfo = mesBaseSupplierInfoMapper.selectMesBaseSupplierInfoByErpId(erpId); +// +// if (existedMesBaseSupplierInfo != null) { +// mesBaseSupplierInfo.setSupplierId(existedMesBaseSupplierInfo.getSupplierId()); +// toUpdateSupplierInfoList.add(mesBaseSupplierInfo); +// } else { +// 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()); + System.out.println(resultArray); + //如果返回的数组的数量等于分页数量,则继续获取下一页数据 +// if (resultArray.size() == limit) { +//// System.out.println(startRow); +// //通过递归同步所有供应商,测试先不用 +// int i = syncSupplierInfoFromErp(startRow + resultArray.size(), maxErpModifyDate); +//// return i; +// return 1; +// } else { +// //为空时的总行数 +// return startRow + resultArray.size(); +// } + + + return 0; + } + + + /** * @throws Exception * @Description:从金蝶ERP同步供应商信息