diff --git a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/config/KingdeeConfig.java b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/config/KingdeeConfig.java index 7eade75..cef1f8f 100644 --- a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/config/KingdeeConfig.java +++ b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/config/KingdeeConfig.java @@ -3,6 +3,7 @@ package com.hw.jindie.config; import com.alibaba.fastjson2.JSONObject; import com.hw.common.core.utils.DateUtils; import com.kingdee.bos.webapi.sdk.K3CloudApi; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -17,6 +18,18 @@ public class KingdeeConfig { return new K3CloudApi(); } + /** + * erp部门ID + * */ + @Value("${erp.deptId}") + public Long erpDeptId; + + /** + * erp物料开头前缀 + */ + @Value("${erp.materialCodePrefix}") + public String materialCodePrefix; + /** * 实体主键 */ 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 853215d..5249e2d 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("/syncDeptInfoFromErp") + @Log(title = "ERP部门信息", businessType = BusinessType.INSERT) +// @InnerAuth + public AjaxResult syncDeptInfoFromErp() { + try { + return AjaxResult.success(kingdeeErpSyncService.syncDeptInfoFromErp(0)); + } catch (Exception e) { + logger.error("同步部门信息错误:" + e.getMessage()); + return AjaxResult.error(); + } + } + /** * 从erp中同步单位数据到MES */ @@ -65,9 +80,9 @@ public class KingdeeErpSyncController { /** * 从ERP中同步物料信息到MES */ - @Log(title = "ERP物料信息", businessType = BusinessType.INSERT) +// @Log(title = "ERP物料信息", businessType = BusinessType.INSERT) @PostMapping(("/syncMaterialInfoFromErp")) - @InnerAuth +// @InnerAuth public AjaxResult syncMaterialInfoFromErp(@RequestBody ErpSyncInfoVo erpSyncInfoVo) { try { return AjaxResult.success(kingdeeErpSyncService.syncMaterialInfoFromErp(0, erpSyncInfoVo)); diff --git a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/mapper/MesBaseMaterialInfoMapper.java b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/mapper/MesBaseMaterialInfoMapper.java index dbc0df7..323345c 100644 --- a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/mapper/MesBaseMaterialInfoMapper.java +++ b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/mapper/MesBaseMaterialInfoMapper.java @@ -95,5 +95,11 @@ public interface MesBaseMaterialInfoMapper */ public int batchMesBaseMaterialInfo(List mesBaseMaterialInfos); - + /** + * 查询物料信息 + * + * @param materialCode 物料编码 + * @return 物料信息 + */ + public MesBaseMaterialInfo selectMesBaseMaterialInfoByMaterialCode(String materialCode); } 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 5d161e8..ae3c6bd 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 syncDeptInfoFromErp(int startRow) throws Exception; + /** * @throws Exception * @Description:从金蝶ERP同步单位信息 diff --git a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/impl/KingdeeErpService.java b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/impl/KingdeeErpService.java index ad3ed86..a07bbf0 100644 --- a/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/impl/KingdeeErpService.java +++ b/hw-modules/hw-jindie/src/main/java/com/hw/jindie/service/impl/KingdeeErpService.java @@ -200,7 +200,12 @@ public class KingdeeErpService { String FDate = (String) objectParams.get("FDate");//日期 Double FRealQty = (Double) objectParams.get("FRealQty");//实收数量 String FStockId = (String) objectParams.get("FStockId");//仓库 - String F_TOND_Base = "JY(NT)-SA-XS-2020-0039";//京源项目 + String F_TOND_Base = (String) objectParams.get("FTondBase");//京源项目 + String supplierCode = (String) objectParams.get("FSupplierCode");//供应商编码 + supplierCode = StringUtils.isEmpty(supplierCode)?"VEN04520":supplierCode; + + +// String F_TOND_Base = "JY(NT)-SA-XS-2020-0039";//京源项目 try { //业务对象标识 String formId = KingdeeConfig.STK_InStock; @@ -254,7 +259,7 @@ public class KingdeeErpService { F_TOND_BaseObject.put("FNUMBER", F_TOND_Base); model.put("F_TOND_Base", F_TOND_BaseObject); //京源项目(必填项) JSONObject FSupplierId = new JSONObject(); - FSupplierId.put("FNumber", "VEN04969"); + FSupplierId.put("FNumber", supplierCode); model.put("FSupplierId", FSupplierId); //供应商(必填项) data.put("Model", model); String saveParams = data.toJSONString(); @@ -405,6 +410,7 @@ public class KingdeeErpService { Double FQty = (Double) objectParams.get("FQty");//实发数量 Double FPrice = (Double) objectParams.get("FPrice");//成本价 String FStockId = (String) objectParams.get("FStockId");//仓库 + String FTONDCombo = (String) objectParams.get("FTONDCombo");//领料类型(必填项) try { //业务对象标识 String formId = KingdeeConfig.STK_MisDelivery; @@ -448,7 +454,7 @@ public class KingdeeErpService { JSONObject FDeptIdObject = new JSONObject(); FDeptIdObject.put("FNumber", "BM000001"); model.put("FDeptId", FDeptIdObject); //部门 - model.put("F_TOND_Combo", "一般领料"); //领料类型(必填项) + model.put("F_TOND_Combo", FTONDCombo); //领料类型(必填项) data.put("Model", model); String saveParams = data.toJSONString(); String resultJson = client.save(formId, saveParams); 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 fecd3c8..22fba6b 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 @@ -6,6 +6,7 @@ import com.hw.common.core.constant.MesConstants; import com.hw.common.core.utils.DateUtils; import com.hw.common.core.utils.StringUtils; import com.hw.jindie.api.domain.vo.ErpSyncInfoVo; +import com.hw.jindie.config.KingdeeConfig; import com.hw.jindie.domain.*; import com.hw.jindie.mapper.*; import com.hw.jindie.service.IKingdeeErpSyncService; @@ -39,9 +40,131 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { private MesPurchaseOrderMapper mesPurchaseOrderMapper; @Autowired private MesBaseUnitInfoMapper mesBaseUnitInfoMapper; + @Autowired + private KingdeeConfig kingdeeConfig; private static final int limit = 100; + /** + * @throws Exception + * @Description:从金蝶ERP同步部门信息 + */ + @Override + public int syncDeptInfoFromErp(int startRow) throws Exception { +// String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate()) ? +// mesBaseSupplierInfoMapper.selectMaxErpModifyDate() : erpSyncInfoVo.getMaxErpModifyDate(); +// String maxErpModifyDate = erpSyncInfoVo.getMaxErpModifyDate(); + return syncDeptInfoFromErp1(startRow); + } + + + /** + * @throws Exception + * @Description:从金蝶ERP同步单位信息,递归使用 + */ + public int syncDeptInfoFromErp1(int startRow) throws Exception { + System.out.println("startRow=" + startRow); + K3CloudApi api = new K3CloudApi(); + JSONObject queryJson = new JSONObject(); + String formId = "BD_Department"; + String fieldKeys = "FDeptId,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(queryJson.toString()); + + String result = api.billQuery(queryJson.toString()); + if (StringUtils.isEmpty(result)) { + return 1; + } + System.out.println("部门单据查询接口: " + result); + 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); +// MesBaseUnitInfo baseUnitInfo = new MesBaseUnitInfo(); +// //主键 +// Long FUnitId = resultObject.getLong("FUnitId"); +// //编号 +// String FNumber = resultObject.getString("FNumber"); +// //描述 +// String FName = resultObject.getString("FName"); +// //创建时间 +// String FCreateDate = resultObject.getString("FCreateDate"); +// //更新时间 +// String FModifyDate = resultObject.getString("FModifyDate"); +// +// baseUnitInfo.setUnitCode(FNumber); +// baseUnitInfo.setErpId(FUnitId); +// baseUnitInfo.setUnitName(FName); +// baseUnitInfo.setUnitStatus("1"); +// baseUnitInfo.setUpdateTime(currentDate); +// if (StringUtils.isNotEmpty(FCreateDate)) { +// baseUnitInfo.setCreateTime(conversionERPTime(FCreateDate)); +// } +// if (StringUtils.isNotEmpty(FModifyDate)) { +// baseUnitInfo.setErpModifyDate(conversionERPTime(FModifyDate)); +// } +// +// MesBaseUnitInfo existedUnitInfo = mesBaseUnitInfoMapper.selectMesBaseUnitInfoByErpId(FUnitId); +// +// if (existedUnitInfo != null) { +// baseUnitInfo.setUnitId(existedUnitInfo.getUnitId()); +// toUpdateSupplierInfoList.add(baseUnitInfo); +// } else { +// toInsertSupplierInfoList.add(baseUnitInfo); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + + +// if (!toInsertSupplierInfoList.isEmpty()) { +// for (MesBaseUnitInfo mesBaseUnitInfo : toInsertSupplierInfoList) { +// mesBaseUnitInfoMapper.insertMesBaseUnitInfo(mesBaseUnitInfo); +// } +// } +// +// if (!toUpdateSupplierInfoList.isEmpty()) { +// for (MesBaseUnitInfo toUpdatedUnitInfo : toUpdateSupplierInfoList) { +// mesBaseUnitInfoMapper.updateMesBaseUnitInfo(toUpdatedUnitInfo); +// } +// } + + System.out.println("size:" + resultArray.size()); +// System.out.println(resultArray); + //如果返回的数组的数量等于分页数量,则继续获取下一页数据 + if (resultArray.size() == limit) { + //通过递归同步所有供应商,测试先不用 + int i = syncDeptInfoFromErp1(startRow + resultArray.size()); + return 1; + } else { + //为空时的总行数 + return startRow + resultArray.size(); + } + } + + + /** * @throws Exception * @Description:从金蝶ERP同步单位信息 @@ -165,7 +288,6 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { } - /** * @throws Exception * @Description:从金蝶ERP同步供应商信息 @@ -323,6 +445,7 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { public int syncMaterialInfoFromErp(int startRow, String maxErpModifyDate) throws Exception { K3CloudApi api = new K3CloudApi(); String FDocumentStatus = "C"; + String materialCodePrefix = kingdeeConfig.materialCodePrefix; JSONObject queryJson = new JSONObject(); String formId = "BD_Material"; @@ -341,11 +464,18 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { queryJson.put("Limit", limit); queryJson.put("SubSystemId", ""); + if (StringUtils.isEmpty(materialCodePrefix)) { + return 0; + } + //条件查询 + StringBuilder filterStringBuilder = new StringBuilder(); + filterStringBuilder.append("FNumber like '%").append(materialCodePrefix).append("%'"); if (StringUtils.isNotEmpty(maxErpModifyDate)) { - String filterString = "FModifyDate >'" + maxErpModifyDate + "'"; - queryJson.put("FilterString", filterString); + filterStringBuilder.append(" and FModifyDate >'").append(maxErpModifyDate).append("'"); } + queryJson.put("FilterString", filterStringBuilder.toString()); + System.out.println(queryJson.toString()); String result = api.billQuery(queryJson.toString()); @@ -417,6 +547,9 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { } MesBaseMaterialInfo existedMesBaseMaterialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByErpId(erpId); + +// MesBaseMaterialInfo existedMesBaseMaterialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByMaterialCode(materialCode); + if (existedMesBaseMaterialInfo != null) { mesBaseMaterialInfo.setMaterialId(existedMesBaseMaterialInfo.getMaterialId()); toUpdateMaterialInfoList.add(mesBaseMaterialInfo); @@ -456,8 +589,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { */ @Override public int syncSaleOrderFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception { - String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate())? - mesSaleOrderMapper.selectMaxErpModifyDate():erpSyncInfoVo.getMaxErpModifyDate(); + String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate()) ? + mesSaleOrderMapper.selectMaxErpModifyDate() : erpSyncInfoVo.getMaxErpModifyDate(); return syncSaleOrderFromErp(startRow, maxErpModifyDate); } @@ -486,6 +619,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { // // String filterString = "FNumber='98010102'"; // String filterString = ""; + + String orderString = ""; int topRowCount = 0; // int startRow = 0; @@ -501,11 +636,23 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { System.out.println(queryJson.toString()); //条件查询 + Long deptId = kingdeeConfig.erpDeptId; + if (deptId == null) { + return 0; + } + + StringBuilder filterStringBuilder = new StringBuilder(); + filterStringBuilder.append("FSaleDeptId = ").append(deptId); + + filterStringBuilder.append(" and FDocumentStatus='C'"); + System.out.println("maxErpModifyDate=" + maxErpModifyDate); if (StringUtils.isNotEmpty(maxErpModifyDate)) { - String filterString = "FModifyDate >'" + maxErpModifyDate + "'"; - queryJson.put("FilterString", filterString); + filterStringBuilder.append(" and FModifyDate >'").append(maxErpModifyDate).append("'"); + } + + queryJson.put("FilterString", filterStringBuilder.toString()); System.out.println(queryJson.toString()); String result = api.billQuery(queryJson.toString()); @@ -558,6 +705,10 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { Long stockOrgId = resultObject.getLong("FStockOrgId"); //单据状态 String documentStatus = resultObject.getString("FDocumentStatus"); + + if(!documentStatus.equals("C")){ + System.out.println(documentStatus); + } String tondBase = resultObject.getString("F.TOND.Base"); String FCreateDate = resultObject.getString("FCreateDate"); @@ -638,8 +789,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { */ @Override public int syncProjectInfoFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception { - String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate())? - mesProjectInfoMapper.selectMaxErpModifyDate(): erpSyncInfoVo.getMaxErpModifyDate(); + String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate()) ? + mesProjectInfoMapper.selectMaxErpModifyDate() : erpSyncInfoVo.getMaxErpModifyDate(); return syncProjectInfoFromErp(startRow, maxErpModifyDate); } @@ -672,7 +823,7 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { //条件查询 System.out.println("maxErpModifyDate=" + maxErpModifyDate); if (StringUtils.isNotEmpty(maxErpModifyDate)) { - String filterString = "FModifyDate >'" + maxErpModifyDate + "'"; + String filterString = "FModifyDate >'" + maxErpModifyDate + "' and FDocumentStatus ='C'"; queryJson.put("FilterString", filterString); } System.out.println(queryJson.toString()); @@ -693,6 +844,11 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { String FNumber = resultObject.getString("FNumber"); String FName = resultObject.getString("FName"); String FDocumentStatus = resultObject.getString("FDocumentStatus"); + + if(!FDocumentStatus.equals("C")){ + System.out.println(FDocumentStatus); + } + String FForbidStatus = resultObject.getString("FForbidStatus"); String FAuditDate = resultObject.getString("FAuditDate"); String FModifyDate = resultObject.getString("FModifyDate"); @@ -757,8 +913,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { */ @Override public int syncPurchaseOrderFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception { - String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate())? - mesPurchaseOrderMapper.selectMaxErpModifyDate():erpSyncInfoVo.getMaxErpModifyDate(); + String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate()) ? + mesPurchaseOrderMapper.selectMaxErpModifyDate() : erpSyncInfoVo.getMaxErpModifyDate(); return syncPurchaseOrderFromErp(startRow, maxErpModifyDate); } @@ -767,13 +923,13 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { * @Descrption:从金蝶ERP同步采购订单 */ public int syncPurchaseOrderFromErp(int startRow, String maxErpModifyDate) throws Exception { - maxErpModifyDate = "2022-03-23 11:30:57"; +// maxErpModifyDate = "2022-03-23 11:30:57"; K3CloudApi api = new K3CloudApi(); // String FDocumentStatus = "C"; JSONObject queryJson = new JSONObject(); String formId = "PUR_PurchaseOrder"; - String fieldKeys = "FID,FBillNo,FApproveDate,FDocumentStatus,FPOOrderEntry_FEntryID,FMaterialId,FMaterialId.FNumber,FMaterialId.FName," + - "FQty,FDeliveryDate,FCreateDate,FModifyDate,FUnitId,FStockUnitID,FPriceUnitID,FAuxPropId,FAUXPROPID.FF100001,FSrcBillNo,FPurchaseOrgId,F_TOND_Base,FSupplierId"; + String fieldKeys = "FID,FBillNo,FApproveDate,FDocumentStatus,FPOOrderEntry_FEntryID,FRequireDeptId,FMaterialId,FMaterialId.FNumber,FMaterialId.FName," + + "FQty,FDeliveryDate,FCreateDate,FModifyDate,FUnitId,FStockUnitID,FPriceUnitID,FAuxPropId,FAUXPROPID.FF100001,FSrcBillNo,FPurchaseOrgId,FPurchaseDeptId,F_TOND_Base,FSupplierId"; // String filterString = ""; String orderString = ""; int topRowCount = 0; @@ -787,20 +943,32 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { queryJson.put("StartRow", startRow); queryJson.put("Limit", limit); queryJson.put("SubSystemId", ""); - System.out.println(queryJson.toString()); +// System.out.println(queryJson.toString()); //条件查询 - System.out.println("maxErpModifyDate=" + maxErpModifyDate); + Long deptId = kingdeeConfig.erpDeptId; + if (deptId == null) { + return 0; + } + +// System.out.println("maxErpModifyDate=" + maxErpModifyDate); + StringBuilder filterStringBuilder = new StringBuilder(); + filterStringBuilder.append("FPurchaseDeptId = ").append(deptId); + + filterStringBuilder.append(" and FDocumentStatus = 'C'"); + +// System.out.println("maxErpModifyDate=" + maxErpModifyDate); if (StringUtils.isNotEmpty(maxErpModifyDate)) { - String filterString = "FModifyDate >'" + maxErpModifyDate + "'"; - queryJson.put("FilterString", filterString); + filterStringBuilder.append(" FModifyDate >'").append(maxErpModifyDate).append("'"); + } - System.out.println(queryJson.toString()); + queryJson.put("FilterString", filterStringBuilder.toString()); +// 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); +// System.out.println(resultArray.size()); +// System.out.println("采购订单单据查询接口: " + result); List toInsertPurchaseOrderList = new ArrayList<>(); List toUpdatePurchaseOrderList = new ArrayList<>(); @@ -817,6 +985,9 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { String approveDate = resultObject.getString("FApproveDate"); //单据状态 String documentStatus = resultObject.getString("FDocumentStatus"); + if(!documentStatus.equals("C")){ + System.out.println(documentStatus); + } //订单明细id Long fentryId = resultObject.getLong("FPOOrderEntry.FEntryID"); //erp物料ID @@ -871,9 +1042,7 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService { mesPurchaseOrder.setTondBase(tondBase); mesPurchaseOrder.setSupplierId(supplierId); mesPurchaseOrder.setUpdateTime(currentDate); - - //todo:需要确认ERP中的采购订单信息有没有完成和代采购的状态等信息 -// mesPurchaseOrder.setOrderStatus(待采购); + mesPurchaseOrder.setOrderStatus(MesConstants.MES_PURCHASE_ORDER_STATUS_TOPURCHASE); if (approveDate != null) { mesPurchaseOrder.setApproveDate(conversionERPTime(approveDate)); diff --git a/hw-modules/hw-jindie/src/main/resources/mapper/jindie/MesBaseMaterialInfoMapper.xml b/hw-modules/hw-jindie/src/main/resources/mapper/jindie/MesBaseMaterialInfoMapper.xml index a9dff2b..ab80969 100644 --- a/hw-modules/hw-jindie/src/main/resources/mapper/jindie/MesBaseMaterialInfoMapper.xml +++ b/hw-modules/hw-jindie/src/main/resources/mapper/jindie/MesBaseMaterialInfoMapper.xml @@ -258,4 +258,9 @@ + + + diff --git a/hw-modules/hw-jindie/src/main/resources/mapper/jindie/MesPurchaseOrderMapper.xml b/hw-modules/hw-jindie/src/main/resources/mapper/jindie/MesPurchaseOrderMapper.xml index ba31dd9..11c5b2f 100644 --- a/hw-modules/hw-jindie/src/main/resources/mapper/jindie/MesPurchaseOrderMapper.xml +++ b/hw-modules/hw-jindie/src/main/resources/mapper/jindie/MesPurchaseOrderMapper.xml @@ -216,7 +216,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" INSERT INTO mes_purchase_order (erp_id, fentry_id, po_no, document_status, material_id, material_code, material_name, order_amount, complete_amount, approve_date, erp_modify_date, plan_delivery_date, order_status, unit_id, stock_unit_id, price_unit_id, aux_prop_id, specification_parameter, src_bill_no, purchase_org_id, tond_base, supplier_id, create_time,update_time) VALUES - (#{item.erpId}, #{item.fentryId}, #{item.poNo},#{item.documentStatus}, #{item.materialId}, #{item.materialCode}, #{item.materialName}, #{item.orderAmount}, #{item.completeAmount}, #{item.approveDate}, #{item.erpModifyDate}, #{item.planDeliveryDate}, #{item.orderStatus}, #{item.unitId}, #{item.stockUnitId}, #{item.priceUnitId}, #{item.auxPropId}, #{specificationParameter},#{item.srcBillNo}, #{item.purchaseOrgId}, #{item.tondBase}, #{item.supplierId}, #{item.createTime},#{item.updateTime}) + (#{item.erpId}, #{item.fentryId}, #{item.poNo},#{item.documentStatus}, #{item.materialId}, #{item.materialCode}, #{item.materialName}, #{item.orderAmount}, #{item.completeAmount}, #{item.approveDate}, #{item.erpModifyDate}, #{item.planDeliveryDate}, #{item.orderStatus}, #{item.unitId}, #{item.stockUnitId}, #{item.priceUnitId}, #{item.auxPropId}, #{item.specificationParameter},#{item.srcBillNo}, #{item.purchaseOrgId}, #{item.tondBase}, #{item.supplierId}, #{item.createTime},#{item.updateTime}) diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawOutstock.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawOutstock.java index 0ecb16d..a076786 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawOutstock.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawOutstock.java @@ -229,6 +229,9 @@ public class WmsRawOutstock extends BaseEntity { /** 计量单位编号 */ private String unitCode; + private String taskTypeStr; + + public String getUnitCode() { return unitCode; } @@ -581,6 +584,14 @@ public class WmsRawOutstock extends BaseEntity { this.saleOrderId = saleOrderId; } + public String getTaskTypeStr() { + return taskTypeStr; + } + + public void setTaskTypeStr(String taskTypeStr) { + this.taskTypeStr = taskTypeStr; + } + @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java index 9a1eca9..2e57348 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java @@ -2,9 +2,11 @@ package com.hw.wms.service.impl; import com.alibaba.fastjson2.JSONObject; import com.hw.common.core.constant.SecurityConstants; +import com.hw.common.core.constant.WmsConstants; import com.hw.common.core.domain.R; import com.hw.common.core.exception.ServiceException; import com.hw.common.core.utils.DateUtils; +import com.hw.common.core.utils.StringUtils; import com.hw.common.core.web.domain.AjaxResult; import com.hw.jindie.api.RemoteJindieService; import com.hw.mes.api.RemoteMesService; @@ -88,7 +90,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi if (purchaseOrderData != null) { mesPurchaseOrder = purchaseOrderData.getData(); } - String supplierCode = mesPurchaseOrder == null ? "": mesPurchaseOrder.getSupplierCode(); + String supplierCode = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getSupplierCode(); String projectNo = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getProjectNo(); @@ -110,7 +112,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi data.put("FRealQty", FRealQty); data.put("FStockId", FStockId); data.put("FSupplierCode", supplierCode); - data.put("FTondBase",projectNo); + data.put("FTondBase", projectNo); String params = data.toJSONString(); R paramsResult = remoteJindieService.savePurchaseStorage(params, SecurityConstants.INNER); String paramsResultData = paramsResult.getMsg(); @@ -133,18 +135,30 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi @Override @Transactional public int synchronizeRawMaterialDeliveryInformationToERP() { - WmsRawOutstock rawOutstock = new WmsRawOutstock(); int result = 0; - List outStockList = wmsRawOutstockMapper.selectWmsRawOutstockERPNotSynchronized(rawOutstock); - Map> materialIdMap = outStockList.stream().collect(Collectors.groupingBy(WmsRawOutstock::getMaterialId)); - for (Long materialId : materialIdMap.keySet()) { - syncOutstockInformation(materialIdMap, materialId, result); +// WmsRawOutstock otherRawOutstock = new WmsRawOutstock(); +// otherRawOutstock.setTaskTypeStr(WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_PRODUCTION_PICKING + "," + WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_PRODUCTION_INSTALL +// + "," + WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_OTHER); +// List otherRawOutstockList = wmsRawOutstockMapper.selectWmsRawOutstockERPNotSynchronized(otherRawOutstock); +// Map> otherMaterialIdMap = otherRawOutstockList.stream().collect(Collectors.groupingBy(WmsRawOutstock::getMaterialId)); +// for (Long materialId : otherMaterialIdMap.keySet()) { +// result += syncOutstockInformation(otherMaterialIdMap, materialId, ""); +// } + + WmsRawOutstock returnRawOutstock = new WmsRawOutstock(); + returnRawOutstock.setTaskType(WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_RETURN_OUTSTOCK); + List returnOutstockList = wmsRawOutstockMapper.selectWmsRawOutstockERPNotSynchronized(returnRawOutstock); + Map> returnMaterialIdMap = returnOutstockList.stream().collect(Collectors.groupingBy(WmsRawOutstock::getMaterialId)); + for (Long materialId : returnMaterialIdMap.keySet()) { + result += syncOutstockInformation(returnMaterialIdMap, materialId, WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_RETURN_OUTSTOCK); } + return result; } @Transactional(propagation = Propagation.REQUIRES_NEW) - public void syncOutstockInformation(Map> materialIdMap, Long materialId, int result) { + public int syncOutstockInformation(Map> materialIdMap, Long materialId, String taskType) { + int result = 0; List wmsRawOutstockList = materialIdMap.get(materialId); JSONObject data = new JSONObject(); double FRealQty = wmsRawOutstockList.stream().mapToDouble(item -> item.getRealOutstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); @@ -160,15 +174,21 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi wmsRawOutstockMapper.updateWmsRawOutstock(wmsRawOutstock); } + if (StringUtils.isNotEmpty(taskType) && taskType.equals(WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_RETURN_OUTSTOCK)) { + data.put("FTONDCombo", "售后服务"); + } else { + data.put("FTONDCombo", "一般领料"); + } // model.put("F_TOND_Combo", "一般领料"); //领料类型(必填项) data.put("FDate", DateUtils.getTime()); data.put("FMaterialId", outstock.getMaterialCode()); - data.put("FAuxPropId", outstock.getSpecificationParameter()); + data.put("FAuxPropId", outstock.getSpecificationParameter() == null ? "" : outstock.getSpecificationParameter()); data.put("FUnitID", outstock.getUnitCode()); data.put("FQty", FRealQty); data.put("FPrice", outstock.getPrice()); data.put("FStockId", FStockId); + String params = data.toJSONString(); R paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER); String paramsResultData = paramsResult.getMsg(); @@ -181,6 +201,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString()); throw new RuntimeException("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString()); } + return result; } /** @@ -222,7 +243,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi data.put("FDate", DateUtils.getTime()); data.put("FMaterialId", instock.getMaterialCode()); - data.put("FAuxPropId", instock.getSpecificationParameter()); + data.put("FAuxPropId", instock.getSpecificationParameter() == null ? "B" : instock.getSpecificationParameter()); data.put("FUnitID", instock.getUnitCode()); data.put("FQty", FRealQty); data.put("FPrice", instock.getPrice()); @@ -279,11 +300,12 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi } data.put("FDate", DateUtils.getTime()); data.put("FMaterialId", outstock.getMaterialCode()); - data.put("FAuxPropId", outstock.getSpecificationParameter()); + data.put("FAuxPropId", outstock.getSpecificationParameter() == null ? "无" : outstock.getSpecificationParameter()); data.put("FUnitID", outstock.getUnitCode()); data.put("FQty", FRealQty); data.put("FPrice", outstock.getPrice()); data.put("FStockId", FStockId); + data.put("FTONDCombo", "一般领料"); String params = data.toJSONString(); R paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER); String paramsResultData = paramsResult.getMsg(); diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductInstockMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductInstockMapper.xml index a999604..524e1b1 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductInstockMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductInstockMapper.xml @@ -248,6 +248,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and wpi.execute_status = '2' and (wpi.erp_status is null or wpi.erp_status != '1') and wpi.instock_type = '1' + and mbmi.material_classfication = '1' and wpi.apply_date between #{beginTime} and #{endTime} diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductOutstockMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductOutstockMapper.xml index fc32a10..2c115a4 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductOutstockMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductOutstockMapper.xml @@ -320,6 +320,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and wpo.outstock_qty > 0 and wpo.apply_qty >= wpo.outstock_qty and wpo.outstock_qty > if(wpo.erp_amount is null, 0, wpo.erp_amount) + and mbmi.material_classfication = '1' and wpi.apply_date between #{beginTime} and #{endTime} diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawOutstockMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawOutstockMapper.xml index fa9340c..1dc8714 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawOutstockMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawOutstockMapper.xml @@ -375,11 +375,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id left join mes_product_plan mpp on mpp.plan_code = wro.plan_code left join mes_sale_order mso on mso.sale_order_id = mpp.sale_order_id - where wro.real_outstock_amount > 0 - and wro.outstock_amount >= wro.real_outstock_amount - and wro.real_outstock_amount > if(wro.erp_amount is null, 0, wro.erp_amount) - and wro.task_type in (1, 3, 5,9) - and mbmi.material_classfication = '1' + + + wro.real_outstock_amount > 0 + and wro.outstock_amount >= wro.real_outstock_amount + and wro.real_outstock_amount > if(wro.erp_amount is null, 0, wro.erp_amount) + and mbmi.material_classfication = '1' + and wro.task_type in (${taskTypeStr}) + and wro.task_type = #{taskType} + +