ERP:
成品出库和成品入库完善
master
xs 2 weeks ago
parent d02fda5211
commit be79405985

@ -3,6 +3,7 @@ package com.hw.jindie.config;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.hw.common.core.utils.DateUtils; import com.hw.common.core.utils.DateUtils;
import com.kingdee.bos.webapi.sdk.K3CloudApi; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -17,6 +18,18 @@ public class KingdeeConfig {
return new K3CloudApi(); return new K3CloudApi();
} }
/**
* erpID
* */
@Value("${erp.deptId}")
public Long erpDeptId;
/**
* erp
*/
@Value("${erp.materialCodePrefix}")
public String materialCodePrefix;
/** /**
* *
*/ */

@ -32,6 +32,21 @@ public class KingdeeErpSyncController {
@Autowired @Autowired
private KingdeeErpService kingdeeErpService; private KingdeeErpService kingdeeErpService;
/**
* erpMES
*/
@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();
}
}
/** /**
* erpMES * erpMES
*/ */
@ -65,9 +80,9 @@ public class KingdeeErpSyncController {
/** /**
* ERPMES * ERPMES
*/ */
@Log(title = "ERP物料信息", businessType = BusinessType.INSERT) // @Log(title = "ERP物料信息", businessType = BusinessType.INSERT)
@PostMapping(("/syncMaterialInfoFromErp")) @PostMapping(("/syncMaterialInfoFromErp"))
@InnerAuth // @InnerAuth
public AjaxResult syncMaterialInfoFromErp(@RequestBody ErpSyncInfoVo erpSyncInfoVo) { public AjaxResult syncMaterialInfoFromErp(@RequestBody ErpSyncInfoVo erpSyncInfoVo) {
try { try {
return AjaxResult.success(kingdeeErpSyncService.syncMaterialInfoFromErp(0, erpSyncInfoVo)); return AjaxResult.success(kingdeeErpSyncService.syncMaterialInfoFromErp(0, erpSyncInfoVo));

@ -95,5 +95,11 @@ public interface MesBaseMaterialInfoMapper
*/ */
public int batchMesBaseMaterialInfo(List<MesBaseMaterialInfo> mesBaseMaterialInfos); public int batchMesBaseMaterialInfo(List<MesBaseMaterialInfo> mesBaseMaterialInfos);
/**
*
*
* @param materialCode
* @return
*/
public MesBaseMaterialInfo selectMesBaseMaterialInfoByMaterialCode(String materialCode);
} }

@ -4,6 +4,12 @@ import com.hw.jindie.api.domain.vo.ErpSyncInfoVo;
public interface IKingdeeErpSyncService { public interface IKingdeeErpSyncService {
/**
* @throws Exception
* @Description:ERP
*/
public int syncDeptInfoFromErp(int startRow) throws Exception;
/** /**
* @throws Exception * @throws Exception
* @Description:ERP * @Description:ERP

@ -200,7 +200,12 @@ public class KingdeeErpService {
String FDate = (String) objectParams.get("FDate");//日期 String FDate = (String) objectParams.get("FDate");//日期
Double FRealQty = (Double) objectParams.get("FRealQty");//实收数量 Double FRealQty = (Double) objectParams.get("FRealQty");//实收数量
String FStockId = (String) objectParams.get("FStockId");//仓库 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 { try {
//业务对象标识 //业务对象标识
String formId = KingdeeConfig.STK_InStock; String formId = KingdeeConfig.STK_InStock;
@ -254,7 +259,7 @@ public class KingdeeErpService {
F_TOND_BaseObject.put("FNUMBER", F_TOND_Base); F_TOND_BaseObject.put("FNUMBER", F_TOND_Base);
model.put("F_TOND_Base", F_TOND_BaseObject); //京源项目(必填项) model.put("F_TOND_Base", F_TOND_BaseObject); //京源项目(必填项)
JSONObject FSupplierId = new JSONObject(); JSONObject FSupplierId = new JSONObject();
FSupplierId.put("FNumber", "VEN04969"); FSupplierId.put("FNumber", supplierCode);
model.put("FSupplierId", FSupplierId); //供应商(必填项) model.put("FSupplierId", FSupplierId); //供应商(必填项)
data.put("Model", model); data.put("Model", model);
String saveParams = data.toJSONString(); String saveParams = data.toJSONString();
@ -405,6 +410,7 @@ public class KingdeeErpService {
Double FQty = (Double) objectParams.get("FQty");//实发数量 Double FQty = (Double) objectParams.get("FQty");//实发数量
Double FPrice = (Double) objectParams.get("FPrice");//成本价 Double FPrice = (Double) objectParams.get("FPrice");//成本价
String FStockId = (String) objectParams.get("FStockId");//仓库 String FStockId = (String) objectParams.get("FStockId");//仓库
String FTONDCombo = (String) objectParams.get("FTONDCombo");//领料类型(必填项)
try { try {
//业务对象标识 //业务对象标识
String formId = KingdeeConfig.STK_MisDelivery; String formId = KingdeeConfig.STK_MisDelivery;
@ -448,7 +454,7 @@ public class KingdeeErpService {
JSONObject FDeptIdObject = new JSONObject(); JSONObject FDeptIdObject = new JSONObject();
FDeptIdObject.put("FNumber", "BM000001"); FDeptIdObject.put("FNumber", "BM000001");
model.put("FDeptId", FDeptIdObject); //部门 model.put("FDeptId", FDeptIdObject); //部门
model.put("F_TOND_Combo", "一般领料"); //领料类型(必填项) model.put("F_TOND_Combo", FTONDCombo); //领料类型(必填项)
data.put("Model", model); data.put("Model", model);
String saveParams = data.toJSONString(); String saveParams = data.toJSONString();
String resultJson = client.save(formId, saveParams); String resultJson = client.save(formId, saveParams);

@ -6,6 +6,7 @@ import com.hw.common.core.constant.MesConstants;
import com.hw.common.core.utils.DateUtils; import com.hw.common.core.utils.DateUtils;
import com.hw.common.core.utils.StringUtils; import com.hw.common.core.utils.StringUtils;
import com.hw.jindie.api.domain.vo.ErpSyncInfoVo; import com.hw.jindie.api.domain.vo.ErpSyncInfoVo;
import com.hw.jindie.config.KingdeeConfig;
import com.hw.jindie.domain.*; import com.hw.jindie.domain.*;
import com.hw.jindie.mapper.*; import com.hw.jindie.mapper.*;
import com.hw.jindie.service.IKingdeeErpSyncService; import com.hw.jindie.service.IKingdeeErpSyncService;
@ -39,9 +40,131 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
private MesPurchaseOrderMapper mesPurchaseOrderMapper; private MesPurchaseOrderMapper mesPurchaseOrderMapper;
@Autowired @Autowired
private MesBaseUnitInfoMapper mesBaseUnitInfoMapper; private MesBaseUnitInfoMapper mesBaseUnitInfoMapper;
@Autowired
private KingdeeConfig kingdeeConfig;
private static final int limit = 100; 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<MesBaseUnitInfo> toInsertSupplierInfoList = new ArrayList<>();
List<MesBaseUnitInfo> 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 * @throws Exception
* @Description:ERP * @Description:ERP
@ -165,7 +288,6 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
} }
/** /**
* @throws Exception * @throws Exception
* @Description:ERP * @Description:ERP
@ -323,6 +445,7 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
public int syncMaterialInfoFromErp(int startRow, String maxErpModifyDate) throws Exception { public int syncMaterialInfoFromErp(int startRow, String maxErpModifyDate) throws Exception {
K3CloudApi api = new K3CloudApi(); K3CloudApi api = new K3CloudApi();
String FDocumentStatus = "C"; String FDocumentStatus = "C";
String materialCodePrefix = kingdeeConfig.materialCodePrefix;
JSONObject queryJson = new JSONObject(); JSONObject queryJson = new JSONObject();
String formId = "BD_Material"; String formId = "BD_Material";
@ -341,11 +464,18 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
queryJson.put("Limit", limit); queryJson.put("Limit", limit);
queryJson.put("SubSystemId", ""); queryJson.put("SubSystemId", "");
if (StringUtils.isEmpty(materialCodePrefix)) {
return 0;
}
//条件查询 //条件查询
StringBuilder filterStringBuilder = new StringBuilder();
filterStringBuilder.append("FNumber like '%").append(materialCodePrefix).append("%'");
if (StringUtils.isNotEmpty(maxErpModifyDate)) { if (StringUtils.isNotEmpty(maxErpModifyDate)) {
String filterString = "FModifyDate >'" + maxErpModifyDate + "'"; filterStringBuilder.append(" and FModifyDate >'").append(maxErpModifyDate).append("'");
queryJson.put("FilterString", filterString);
} }
queryJson.put("FilterString", filterStringBuilder.toString());
System.out.println(queryJson.toString()); System.out.println(queryJson.toString());
String result = api.billQuery(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.selectMesBaseMaterialInfoByErpId(erpId);
// MesBaseMaterialInfo existedMesBaseMaterialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByMaterialCode(materialCode);
if (existedMesBaseMaterialInfo != null) { if (existedMesBaseMaterialInfo != null) {
mesBaseMaterialInfo.setMaterialId(existedMesBaseMaterialInfo.getMaterialId()); mesBaseMaterialInfo.setMaterialId(existedMesBaseMaterialInfo.getMaterialId());
toUpdateMaterialInfoList.add(mesBaseMaterialInfo); toUpdateMaterialInfoList.add(mesBaseMaterialInfo);
@ -456,8 +589,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
*/ */
@Override @Override
public int syncSaleOrderFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception { public int syncSaleOrderFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception {
String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate())? String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate()) ?
mesSaleOrderMapper.selectMaxErpModifyDate():erpSyncInfoVo.getMaxErpModifyDate(); mesSaleOrderMapper.selectMaxErpModifyDate() : erpSyncInfoVo.getMaxErpModifyDate();
return syncSaleOrderFromErp(startRow, maxErpModifyDate); return syncSaleOrderFromErp(startRow, maxErpModifyDate);
} }
@ -486,6 +619,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
// //
// String filterString = "FNumber='98010102'"; // String filterString = "FNumber='98010102'";
// String filterString = ""; // String filterString = "";
String orderString = ""; String orderString = "";
int topRowCount = 0; int topRowCount = 0;
// int startRow = 0; // int startRow = 0;
@ -501,11 +636,23 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
System.out.println(queryJson.toString()); 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); System.out.println("maxErpModifyDate=" + maxErpModifyDate);
if (StringUtils.isNotEmpty(maxErpModifyDate)) { if (StringUtils.isNotEmpty(maxErpModifyDate)) {
String filterString = "FModifyDate >'" + maxErpModifyDate + "'"; filterStringBuilder.append(" and FModifyDate >'").append(maxErpModifyDate).append("'");
queryJson.put("FilterString", filterString);
} }
queryJson.put("FilterString", filterStringBuilder.toString());
System.out.println(queryJson.toString()); System.out.println(queryJson.toString());
String result = api.billQuery(queryJson.toString()); String result = api.billQuery(queryJson.toString());
@ -558,6 +705,10 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
Long stockOrgId = resultObject.getLong("FStockOrgId"); Long stockOrgId = resultObject.getLong("FStockOrgId");
//单据状态 //单据状态
String documentStatus = resultObject.getString("FDocumentStatus"); String documentStatus = resultObject.getString("FDocumentStatus");
if(!documentStatus.equals("C")){
System.out.println(documentStatus);
}
String tondBase = resultObject.getString("F.TOND.Base"); String tondBase = resultObject.getString("F.TOND.Base");
String FCreateDate = resultObject.getString("FCreateDate"); String FCreateDate = resultObject.getString("FCreateDate");
@ -638,8 +789,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
*/ */
@Override @Override
public int syncProjectInfoFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception { public int syncProjectInfoFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception {
String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate())? String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate()) ?
mesProjectInfoMapper.selectMaxErpModifyDate(): erpSyncInfoVo.getMaxErpModifyDate(); mesProjectInfoMapper.selectMaxErpModifyDate() : erpSyncInfoVo.getMaxErpModifyDate();
return syncProjectInfoFromErp(startRow, maxErpModifyDate); return syncProjectInfoFromErp(startRow, maxErpModifyDate);
} }
@ -672,7 +823,7 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
//条件查询 //条件查询
System.out.println("maxErpModifyDate=" + maxErpModifyDate); System.out.println("maxErpModifyDate=" + maxErpModifyDate);
if (StringUtils.isNotEmpty(maxErpModifyDate)) { if (StringUtils.isNotEmpty(maxErpModifyDate)) {
String filterString = "FModifyDate >'" + maxErpModifyDate + "'"; String filterString = "FModifyDate >'" + maxErpModifyDate + "' and FDocumentStatus ='C'";
queryJson.put("FilterString", filterString); queryJson.put("FilterString", filterString);
} }
System.out.println(queryJson.toString()); System.out.println(queryJson.toString());
@ -693,6 +844,11 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
String FNumber = resultObject.getString("FNumber"); String FNumber = resultObject.getString("FNumber");
String FName = resultObject.getString("FName"); String FName = resultObject.getString("FName");
String FDocumentStatus = resultObject.getString("FDocumentStatus"); String FDocumentStatus = resultObject.getString("FDocumentStatus");
if(!FDocumentStatus.equals("C")){
System.out.println(FDocumentStatus);
}
String FForbidStatus = resultObject.getString("FForbidStatus"); String FForbidStatus = resultObject.getString("FForbidStatus");
String FAuditDate = resultObject.getString("FAuditDate"); String FAuditDate = resultObject.getString("FAuditDate");
String FModifyDate = resultObject.getString("FModifyDate"); String FModifyDate = resultObject.getString("FModifyDate");
@ -757,8 +913,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
*/ */
@Override @Override
public int syncPurchaseOrderFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception { public int syncPurchaseOrderFromErp(int startRow, ErpSyncInfoVo erpSyncInfoVo) throws Exception {
String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate())? String maxErpModifyDate = StringUtils.isEmpty(erpSyncInfoVo.getMaxErpModifyDate()) ?
mesPurchaseOrderMapper.selectMaxErpModifyDate():erpSyncInfoVo.getMaxErpModifyDate(); mesPurchaseOrderMapper.selectMaxErpModifyDate() : erpSyncInfoVo.getMaxErpModifyDate();
return syncPurchaseOrderFromErp(startRow, maxErpModifyDate); return syncPurchaseOrderFromErp(startRow, maxErpModifyDate);
} }
@ -767,13 +923,13 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
* @DescrptionERP * @DescrptionERP
*/ */
public int syncPurchaseOrderFromErp(int startRow, String maxErpModifyDate) throws Exception { 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(); K3CloudApi api = new K3CloudApi();
// String FDocumentStatus = "C"; // String FDocumentStatus = "C";
JSONObject queryJson = new JSONObject(); JSONObject queryJson = new JSONObject();
String formId = "PUR_PurchaseOrder"; String formId = "PUR_PurchaseOrder";
String fieldKeys = "FID,FBillNo,FApproveDate,FDocumentStatus,FPOOrderEntry_FEntryID,FMaterialId,FMaterialId.FNumber,FMaterialId.FName," + 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,F_TOND_Base,FSupplierId"; "FQty,FDeliveryDate,FCreateDate,FModifyDate,FUnitId,FStockUnitID,FPriceUnitID,FAuxPropId,FAUXPROPID.FF100001,FSrcBillNo,FPurchaseOrgId,FPurchaseDeptId,F_TOND_Base,FSupplierId";
// String filterString = ""; // String filterString = "";
String orderString = ""; String orderString = "";
int topRowCount = 0; int topRowCount = 0;
@ -787,20 +943,32 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
queryJson.put("StartRow", startRow); queryJson.put("StartRow", startRow);
queryJson.put("Limit", limit); queryJson.put("Limit", limit);
queryJson.put("SubSystemId", ""); 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)) { if (StringUtils.isNotEmpty(maxErpModifyDate)) {
String filterString = "FModifyDate >'" + maxErpModifyDate + "'"; filterStringBuilder.append(" FModifyDate >'").append(maxErpModifyDate).append("'");
queryJson.put("FilterString", filterString);
} }
System.out.println(queryJson.toString()); queryJson.put("FilterString", filterStringBuilder.toString());
// System.out.println(queryJson.toString());
String result = api.billQuery(queryJson.toString()); String result = api.billQuery(queryJson.toString());
JSONArray resultArray = JSONArray.parseArray(result); JSONArray resultArray = JSONArray.parseArray(result);
System.out.println(resultArray.size()); // System.out.println(resultArray.size());
System.out.println("采购订单单据查询接口: " + result); // System.out.println("采购订单单据查询接口: " + result);
List<MesPurchaseOrder> toInsertPurchaseOrderList = new ArrayList<>(); List<MesPurchaseOrder> toInsertPurchaseOrderList = new ArrayList<>();
List<MesPurchaseOrder> toUpdatePurchaseOrderList = new ArrayList<>(); List<MesPurchaseOrder> toUpdatePurchaseOrderList = new ArrayList<>();
@ -817,6 +985,9 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
String approveDate = resultObject.getString("FApproveDate"); String approveDate = resultObject.getString("FApproveDate");
//单据状态 //单据状态
String documentStatus = resultObject.getString("FDocumentStatus"); String documentStatus = resultObject.getString("FDocumentStatus");
if(!documentStatus.equals("C")){
System.out.println(documentStatus);
}
//订单明细id //订单明细id
Long fentryId = resultObject.getLong("FPOOrderEntry.FEntryID"); Long fentryId = resultObject.getLong("FPOOrderEntry.FEntryID");
//erp物料ID //erp物料ID
@ -871,9 +1042,7 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
mesPurchaseOrder.setTondBase(tondBase); mesPurchaseOrder.setTondBase(tondBase);
mesPurchaseOrder.setSupplierId(supplierId); mesPurchaseOrder.setSupplierId(supplierId);
mesPurchaseOrder.setUpdateTime(currentDate); mesPurchaseOrder.setUpdateTime(currentDate);
mesPurchaseOrder.setOrderStatus(MesConstants.MES_PURCHASE_ORDER_STATUS_TOPURCHASE);
//todo:需要确认ERP中的采购订单信息有没有完成和代采购的状态等信息
// mesPurchaseOrder.setOrderStatus(待采购);
if (approveDate != null) { if (approveDate != null) {
mesPurchaseOrder.setApproveDate(conversionERPTime(approveDate)); mesPurchaseOrder.setApproveDate(conversionERPTime(approveDate));

@ -258,4 +258,9 @@
</foreach> </foreach>
</insert> </insert>
<select id="selectMesBaseMaterialInfoByMaterialCode" parameterType="String" resultMap="MesBaseMaterialInfoResult">
select material_id from mes_base_material_info where material_code = #{materialCode} limit 1
</select>
</mapper> </mapper>

@ -216,7 +216,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="batchMesBasePurchaseOrder"> <insert id="batchMesBasePurchaseOrder">
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 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
<foreach item="item" index="index" collection="list" separator=","> <foreach item="item" index="index" collection="list" separator=",">
(#{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})
</foreach> </foreach>
</insert> </insert>
</mapper> </mapper>

@ -229,6 +229,9 @@ public class WmsRawOutstock extends BaseEntity {
/** 计量单位编号 */ /** 计量单位编号 */
private String unitCode; private String unitCode;
private String taskTypeStr;
public String getUnitCode() { public String getUnitCode() {
return unitCode; return unitCode;
} }
@ -581,6 +584,14 @@ public class WmsRawOutstock extends BaseEntity {
this.saleOrderId = saleOrderId; this.saleOrderId = saleOrderId;
} }
public String getTaskTypeStr() {
return taskTypeStr;
}
public void setTaskTypeStr(String taskTypeStr) {
this.taskTypeStr = taskTypeStr;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

@ -2,9 +2,11 @@ package com.hw.wms.service.impl;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.hw.common.core.constant.SecurityConstants; 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.domain.R;
import com.hw.common.core.exception.ServiceException; import com.hw.common.core.exception.ServiceException;
import com.hw.common.core.utils.DateUtils; 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.common.core.web.domain.AjaxResult;
import com.hw.jindie.api.RemoteJindieService; import com.hw.jindie.api.RemoteJindieService;
import com.hw.mes.api.RemoteMesService; import com.hw.mes.api.RemoteMesService;
@ -88,7 +90,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
if (purchaseOrderData != null) { if (purchaseOrderData != null) {
mesPurchaseOrder = purchaseOrderData.getData(); mesPurchaseOrder = purchaseOrderData.getData();
} }
String supplierCode = mesPurchaseOrder == null ? "": mesPurchaseOrder.getSupplierCode(); String supplierCode = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getSupplierCode();
String projectNo = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getProjectNo(); String projectNo = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getProjectNo();
@ -110,7 +112,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
data.put("FRealQty", FRealQty); data.put("FRealQty", FRealQty);
data.put("FStockId", FStockId); data.put("FStockId", FStockId);
data.put("FSupplierCode", supplierCode); data.put("FSupplierCode", supplierCode);
data.put("FTondBase",projectNo); data.put("FTondBase", projectNo);
String params = data.toJSONString(); String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.savePurchaseStorage(params, SecurityConstants.INNER); R<AjaxResult> paramsResult = remoteJindieService.savePurchaseStorage(params, SecurityConstants.INNER);
String paramsResultData = paramsResult.getMsg(); String paramsResultData = paramsResult.getMsg();
@ -133,18 +135,30 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
@Override @Override
@Transactional @Transactional
public int synchronizeRawMaterialDeliveryInformationToERP() { public int synchronizeRawMaterialDeliveryInformationToERP() {
WmsRawOutstock rawOutstock = new WmsRawOutstock();
int result = 0; int result = 0;
List<WmsRawOutstock> outStockList = wmsRawOutstockMapper.selectWmsRawOutstockERPNotSynchronized(rawOutstock); // WmsRawOutstock otherRawOutstock = new WmsRawOutstock();
Map<Long, List<WmsRawOutstock>> materialIdMap = outStockList.stream().collect(Collectors.groupingBy(WmsRawOutstock::getMaterialId)); // otherRawOutstock.setTaskTypeStr(WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_PRODUCTION_PICKING + "," + WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_PRODUCTION_INSTALL
for (Long materialId : materialIdMap.keySet()) { // + "," + WmsConstants.WMS_RAW_OUTSTOCK_TASK_TYPE_OTHER);
syncOutstockInformation(materialIdMap, materialId, result); // List<WmsRawOutstock> otherRawOutstockList = wmsRawOutstockMapper.selectWmsRawOutstockERPNotSynchronized(otherRawOutstock);
// Map<Long, List<WmsRawOutstock>> 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<WmsRawOutstock> returnOutstockList = wmsRawOutstockMapper.selectWmsRawOutstockERPNotSynchronized(returnRawOutstock);
Map<Long, List<WmsRawOutstock>> 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; return result;
} }
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public void syncOutstockInformation(Map<Long, List<WmsRawOutstock>> materialIdMap, Long materialId, int result) { public int syncOutstockInformation(Map<Long, List<WmsRawOutstock>> materialIdMap, Long materialId, String taskType) {
int result = 0;
List<WmsRawOutstock> wmsRawOutstockList = materialIdMap.get(materialId); List<WmsRawOutstock> wmsRawOutstockList = materialIdMap.get(materialId);
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
double FRealQty = wmsRawOutstockList.stream().mapToDouble(item -> item.getRealOutstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); 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); 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", "一般领料"); //领料类型(必填项) // model.put("F_TOND_Combo", "一般领料"); //领料类型(必填项)
data.put("FDate", DateUtils.getTime()); data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", outstock.getMaterialCode()); 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("FUnitID", outstock.getUnitCode());
data.put("FQty", FRealQty); data.put("FQty", FRealQty);
data.put("FPrice", outstock.getPrice()); data.put("FPrice", outstock.getPrice());
data.put("FStockId", FStockId); data.put("FStockId", FStockId);
String params = data.toJSONString(); String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER); R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER);
String paramsResultData = paramsResult.getMsg(); String paramsResultData = paramsResult.getMsg();
@ -181,6 +201,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString()); log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString());
throw new RuntimeException("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("FDate", DateUtils.getTime());
data.put("FMaterialId", instock.getMaterialCode()); 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("FUnitID", instock.getUnitCode());
data.put("FQty", FRealQty); data.put("FQty", FRealQty);
data.put("FPrice", instock.getPrice()); data.put("FPrice", instock.getPrice());
@ -279,11 +300,12 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
} }
data.put("FDate", DateUtils.getTime()); data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", outstock.getMaterialCode()); 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("FUnitID", outstock.getUnitCode());
data.put("FQty", FRealQty); data.put("FQty", FRealQty);
data.put("FPrice", outstock.getPrice()); data.put("FPrice", outstock.getPrice());
data.put("FStockId", FStockId); data.put("FStockId", FStockId);
data.put("FTONDCombo", "一般领料");
String params = data.toJSONString(); String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER); R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER);
String paramsResultData = paramsResult.getMsg(); String paramsResultData = paramsResult.getMsg();

@ -248,6 +248,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and wpi.execute_status = '2' and wpi.execute_status = '2'
and (wpi.erp_status is null or wpi.erp_status != '1') and (wpi.erp_status is null or wpi.erp_status != '1')
and wpi.instock_type = '1' and wpi.instock_type = '1'
and mbmi.material_classfication = '1'
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''"> <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and wpi.apply_date between #{beginTime} and #{endTime} and wpi.apply_date between #{beginTime} and #{endTime}
</if> </if>

@ -320,6 +320,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and wpo.outstock_qty > 0 and wpo.outstock_qty > 0
and wpo.apply_qty >= wpo.outstock_qty and wpo.apply_qty >= wpo.outstock_qty
and wpo.outstock_qty > if(wpo.erp_amount is null, 0, wpo.erp_amount) and wpo.outstock_qty > if(wpo.erp_amount is null, 0, wpo.erp_amount)
and mbmi.material_classfication = '1'
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''"> <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and wpi.apply_date between #{beginTime} and #{endTime} and wpi.apply_date between #{beginTime} and #{endTime}
</if> </if>

@ -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_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_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 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 <where>
and wro.real_outstock_amount > if(wro.erp_amount is null, 0, wro.erp_amount) wro.real_outstock_amount > 0
and wro.task_type in (1, 3, 5,9) and wro.outstock_amount >= wro.real_outstock_amount
and mbmi.material_classfication = '1' and wro.real_outstock_amount > if(wro.erp_amount is null, 0, wro.erp_amount)
and mbmi.material_classfication = '1'
<if test="taskTypeStr != null and taskTypeStr != ''"> and wro.task_type in (${taskTypeStr})</if>
<if test="taskType != null and taskType != ''"> and wro.task_type = #{taskType}</if>
</where>
</select> </select>
</mapper> </mapper>

Loading…
Cancel
Save