ERP:完善同步物料信息接口、同步供应商信息接口、同步销售订单信息接口、同步采购订单信息接口、同步项目信息接口
master
xins 6 months ago
parent 550fb33713
commit bbc5be0c4c

@ -5,9 +5,8 @@ import com.hw.common.core.constant.ServiceNameConstants;
import com.hw.common.core.domain.R;
import com.hw.jindie.api.factory.RemoteJindieFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @ClassName : RemoteJindieService
@ -19,10 +18,23 @@ import org.springframework.web.bind.annotation.RequestParam;
public interface RemoteJindieService {
/** 同步供应商*/
@GetMapping("/jindie/ErpSupplierInfo")
R<Integer> ErpSupplierInfo(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/jindie/syncSupplierInfoFromErp")
R<Integer> syncSupplierInfoFromErp(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** 同步物料*/
@GetMapping("/jindie/syncMaterialInfo")
R<Integer> ErpMesMaterialInfo(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/jindie/syncMaterialInfoFromErp")
R<Integer> syncMaterialInfoFromErp(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** 同步项目信息*/
@PostMapping("/jindie/syncProjectInfoFromErp")
R<Integer> syncProjectInfoFromErp(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** 同步销售订单*/
@PostMapping("/jindie/syncSaleOrderFromErp")
R<Integer> syncSaleOrderFromErp(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** 同步采购订单*/
@PostMapping("/jindie/syncPurchaseOrderFromErp")
R<Integer> syncPurchaseOrderFromErp(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

@ -14,13 +14,28 @@ public class RemoteJindieFallbackFactory implements FallbackFactory<RemoteJindie
public RemoteJindieService create(Throwable throwable) {
return new RemoteJindieService() {
@Override
public R<Integer> ErpSupplierInfo(String source) {
return null;
public R<Integer> syncSupplierInfoFromErp(String source) {
return R.fail("同步供应商信息失败:" + throwable.getMessage());
}
@Override
public R<Integer> ErpMesMaterialInfo(String source) {
return null;
public R<Integer> syncMaterialInfoFromErp(String source) {
return R.fail("同步物料信息失败:" + throwable.getMessage());
}
@Override
public R<Integer> syncProjectInfoFromErp(String source) {
return R.fail("同步项目信息失败:" + throwable.getMessage());
}
@Override
public R<Integer> syncSaleOrderFromErp(String source) {
return R.fail("同步销售订单信息失败:" + throwable.getMessage());
}
@Override
public R<Integer> syncPurchaseOrderFromErp(String source) {
return R.fail("同步采购订单信息失败:" + throwable.getMessage());
}
};
}

@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.InnerAuth;
import com.hw.jindie.service.IKingdeeErpSyncService;
import com.hw.jindie.service.impl.KingdeeErpService;
import org.springframework.beans.factory.annotation.Autowired;
@ -27,10 +28,12 @@ public class KingdeeErpSyncController {
private KingdeeErpService kingdeeErpService;
/**
* erp
* erpMES
* */
@GetMapping("/ErpSupplierInfo")
public AjaxResult ErpSupplierInfo(){
@PostMapping("/syncSupplierInfoFromErp")
@Log(title = "ERP供应商信息", businessType = BusinessType.INSERT)
@InnerAuth
public AjaxResult syncSupplierInfoFromErp(){
try {
return AjaxResult.success(kingdeeErpSyncService.syncSupplierInfoFromErp(0));
} catch (Exception e){
@ -40,12 +43,13 @@ public class KingdeeErpSyncController {
}
/**
*
* ERPMES
*/
// @RequiresPermissions("wms:mobile:addrawinstock")
@Log(title = "物料信息", businessType = BusinessType.INSERT)
@GetMapping(("/syncMaterialInfo"))
public AjaxResult syncMaterialInfo() {
@Log(title = "ERP物料信息", businessType = BusinessType.INSERT)
@PostMapping(("/syncMaterialInfoFromErp"))
@InnerAuth
public AjaxResult syncMaterialInfoFromErp() {
try {
return AjaxResult.success(kingdeeErpSyncService.syncMaterialInfoFromErp(0));
} catch (Exception e) {
@ -55,6 +59,61 @@ public class KingdeeErpSyncController {
}
/**
* ERPMES
* */
@PostMapping("/syncProjectInfoFromErp")
@Log(title = "ERP项目信息", businessType = BusinessType.INSERT)
@InnerAuth
public AjaxResult syncProjectInfoFromErp(){
try {
return AjaxResult.success(kingdeeErpSyncService.syncProjectInfoFromErp(0));
}
catch (Exception e) {
return AjaxResult.error();
}
}
/**
* ERPERP
* */
@PostMapping("/syncSaleOrderFromErp")
@Log(title = "ERP销售订单", businessType = BusinessType.INSERT)
@InnerAuth
public AjaxResult syncSaleOrderFromErp(){
try {
return AjaxResult.success(kingdeeErpSyncService.syncSaleOrderFromErp(0));
}
catch (Exception e) {
e.printStackTrace();
return AjaxResult.error();
}
}
/**
* ERPMES
* */
@PostMapping("/syncPurchaseOrderFromErp")
@Log(title = "ERP采购订单", businessType = BusinessType.INSERT)
@InnerAuth
public AjaxResult syncPurchaseOrderFromErp(){
try {
return AjaxResult.success(kingdeeErpSyncService.syncPurchaseOrderFromErp(0));
}
catch (Exception e) {
return AjaxResult.error();
}
}
/**
* ->->
*
@ -193,41 +252,6 @@ public class KingdeeErpSyncController {
}
}
/**
* ERP
* */
@GetMapping("/ERPProject")
public AjaxResult getERPProject(){
try {
return AjaxResult.success(kingdeeErpSyncService.syncProjectInfoFromErp(0));
}
catch (Exception e) {
return AjaxResult.error();
}
}
/**
* ERP
* */
@GetMapping("/ERPMesSaleOrder")
public AjaxResult getERPMesSaleOrder(){
try {
return AjaxResult.success(kingdeeErpSyncService.syncSaleOrderFromErp(0));
}
catch (Exception e) {
return AjaxResult.error();
}
}
/**
* ERP
* */
@GetMapping("/ERPPurchase")
public AjaxResult getERPPurchase(){
try {
return AjaxResult.success(kingdeeErpSyncService.syncPurchaseOrderFromErp(0));
}
catch (Exception e) {
return AjaxResult.error();
}
}
}

@ -42,6 +42,8 @@ public class MesBaseSupplierInfo extends BaseEntity
@Excel(name = "审核日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date auditDate;
private Date erpModifyDate;
public void setSupplierId(Long supplierId)
{
this.supplierId = supplierId;
@ -97,6 +99,14 @@ public class MesBaseSupplierInfo extends BaseEntity
return auditDate;
}
public Date getErpModifyDate() {
return erpModifyDate;
}
public void setErpModifyDate(Date erpModifyDate) {
this.erpModifyDate = erpModifyDate;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

@ -131,7 +131,7 @@ public class MesPurchaseOrder extends BaseEntity {
@Excel(name = "是否标识1-是0-否")
private String isFlag;
//采购单位id
private String unitId;
private Long unitId;
//库存单位
private Long stockUnitId;
//计价单位
@ -148,11 +148,11 @@ public class MesPurchaseOrder extends BaseEntity {
private Long supplierId;
public String getUnitId() {
public Long getUnitId() {
return unitId;
}
public void setUnitId(String unitId) {
public void setUnitId(Long unitId) {
this.unitId = unitId;
}

@ -173,6 +173,8 @@ public class MesSaleOrder extends BaseEntity {
//库存组织
private Long stockOrgId;
private String tondBase;
public Long getStockId() {
return stockId;
@ -406,6 +408,14 @@ public class MesSaleOrder extends BaseEntity {
return isFlag;
}
public String getTondBase() {
return tondBase;
}
public void setTondBase(String tondBase) {
this.tondBase = tondBase;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

@ -77,7 +77,7 @@ public interface MesBaseMaterialInfoMapper
* ERP
* @return String
*/
public String getMaxErpModifyDate();
public String selectMaxErpModifyDate();
/**
*
@ -95,10 +95,5 @@ public interface MesBaseMaterialInfoMapper
*/
public int batchMesBaseMaterialInfo(List<MesBaseMaterialInfo> mesBaseMaterialInfos);
/**
*
* */
public MesBaseMaterialInfo selectMesBaseMaterialInfoByCode(String materialCode);
}

@ -59,4 +59,30 @@ public interface MesBaseSupplierInfoMapper
* @return
*/
public int deleteMesBaseSupplierInfoBySupplierIds(Long[] supplierIds);
/**
* ERP
* @return String
*/
public String selectMaxErpModifyDate();
/**
*
*
* @param erpId ERP
* @return
*/
public MesBaseSupplierInfo selectMesBaseSupplierInfoByErpId(Long erpId);
/**
*
*
* @param mesBaseSupplierInfos
* @return
*/
public int batchMesBaseSupplierInfo(List<MesBaseSupplierInfo> mesBaseSupplierInfos);
}

@ -1,5 +1,6 @@
package com.hw.jindie.mapper;
import com.hw.jindie.domain.MesBaseSupplierInfo;
import com.hw.jindie.domain.MesProjectInfo;
import java.util.List;
@ -64,4 +65,21 @@ public interface MesProjectInfoMapper
* erpid
* */
public MesProjectInfo selectMesProjectInfoByErpId(Long erpId);
/**
* ERP
* @return String
*/
public String selectMaxErpModifyDate();
/**
*
*
* @param mesProjectInfos
* @return
*/
public int batchMesBaseProjectInfo(List<MesProjectInfo> mesProjectInfos);
}

@ -1,6 +1,7 @@
package com.hw.jindie.mapper;
import com.hw.jindie.domain.MesPurchaseOrder;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -10,8 +11,7 @@ import java.util.List;
* @author Yinq
* @date 2024-02-19
*/
public interface MesPurchaseOrderMapper
{
public interface MesPurchaseOrderMapper {
/**
*
*
@ -59,8 +59,31 @@ public interface MesPurchaseOrderMapper
* @return
*/
public int deleteMesPurchaseOrderByPurchaseOrderIds(Long[] purchaseOrderIds);
/**
* ERP
*
* @return String
*/
public String selectMaxErpModifyDate();
/**
*
*
* @param erpId ERP
* @param fentryId ERP
* @return
*/
public MesPurchaseOrder selectMesPurchaseOrderByUI(@Param("erpId") Long erpId,
@Param("fentryId") Long fentryId);
/**
* erpid
* */
public MesPurchaseOrder selectMesPurchaseOrderByErpId(Long erpId);
*
*
* @param mesPurchaseOrders
* @return
*/
public int batchMesBasePurchaseOrder(List<MesPurchaseOrder> mesPurchaseOrders);
}

@ -1,6 +1,7 @@
package com.hw.jindie.mapper;
import com.hw.jindie.domain.MesSaleOrder;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -10,8 +11,7 @@ import java.util.List;
* @author Yinq
* @date 2024-02-19
*/
public interface MesSaleOrderMapper
{
public interface MesSaleOrderMapper {
/**
*
*
@ -60,8 +60,29 @@ public interface MesSaleOrderMapper
*/
public int deleteMesSaleOrderBySaleOrderIds(Long[] saleOrderIds);
/**
* ERP
*
* @return String
*/
public String selectMaxErpModifyDate();
/**
*
*
* @param erpId ERP
* @param fentryId ERP
* @return
*/
public MesSaleOrder selectMesSaleOrderByUI(@Param("erpId") Long erpId,
@Param("fentryId") Long fentryId);
/**
* erpid
* */
public MesSaleOrder selectMesSaleOrderByErpId(Long erpId);
*
*
* @param mesSaleOrders
* @return
*/
public int batchMesBaseSaleOrder(List<MesSaleOrder> mesSaleOrders);
}

@ -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
* @DescrptionERP
*/
@Override
public int syncSaleOrderFromErp(int startRow) throws Exception {
String maxErpModifyDate = mesSaleOrderMapper.selectMaxErpModifyDate();
return syncSaleOrderFromErp(startRow, maxErpModifyDate);
}
/**
* @throws Exception
* @DescrptionERP
*/
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,66 +368,83 @@ 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<>();
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));
mesSaleOrder.setStockOrgId(stockOrgId);
mesSaleOrder.setTondBase(tondBase);
mesSaleOrder.setUpdateTime(currentDate);
if (StringUtils.isNotEmpty(FCreateDate)) {
mesSaleOrder.setCreateTime(conversionERPTime(FCreateDate));
}
if (planDeliveryDate != null) {
mesSaleOrder.setPlanDeliveryDate(conversionERPTime(planDeliveryDate));
}
@ -380,40 +454,37 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
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
* @DescrptionERP
*/
@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
* @DescrptionERP
*/
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
* @DescrptionERP
*/
@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
* @DescrptionERP
*/
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<>();
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));
mesPurchaseOrder.setSupplierId(supplierId);
mesPurchaseOrder.setUpdateTime(currentDate);
if (approveDate != null) {
mesPurchaseOrder.setApproveDate(conversionERPTime(approveDate));
}
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);
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;
}
}

@ -243,7 +243,6 @@
<select id="selectMaxErpModifyDate" resultType="String">
<include refid="selectMesBaseMaterialInfoVo"/>
SELECT max(erp_modify_date) FROM mes_base_material_info order by erp_id
</select>
@ -253,15 +252,10 @@
</select>
<insert id="batchMesBaseMaterialInfo">
INSERT INTO mes_base_material_info (erp_id, material_code, old_material_code, material_name, material_categories, material_subclass, material_type_id, batch_flag, material_unit_id, material_unit, material_matkl, material_spec, net_weight, gross_weight, factory_id, create_org_id, use_org_id, prodline_id, active_flag, deleted_flag, remark, purchase_price_unit_id, create_by, create_time, approve_date, erp_modify_date) VALUES
INSERT INTO mes_base_material_info (erp_id, material_code, old_material_code, material_name, material_categories, material_subclass, material_type_id, batch_flag, material_unit_id, material_unit, material_matkl, material_spec, net_weight, gross_weight, factory_id, create_org_id, use_org_id, prodline_id, active_flag, deleted_flag, remark, purchase_price_unit_id, create_by, create_time, approve_date, erp_modify_date,update_time) VALUES
<foreach item="item" index="index" collection="list" separator=",">
( #{item.erpId}, #{item.materialCode}, #{item.oldMaterialCode}, #{item.materialName}, #{item.materialCategories}, #{item.materialSubclass}, #{item.materialTypeId}, #{item.batchFlag}, #{item.materialUnifId}, #{item.materialUnit}, #{item.materialMatkl}, #{item.materialSpec}, #{item.netWeight}, #{item.grossWeight}, #{item.factoryId}, #{item.createOrgId}, #{item.useOrgId}, #{item.prodlineId}, #{item.activeFlag}, #{item.deletedFlag}, #{item.remark}, #{item.purchasePriceUnitId}, #{item.createBy}, #{item.createTime}, #{item.approveDate}, #{item.erpModifyDate})
( #{item.erpId}, #{item.materialCode}, #{item.oldMaterialCode}, #{item.materialName}, #{item.materialCategories}, #{item.materialSubclass}, #{item.materialTypeId}, #{item.batchFlag}, #{item.materialUnitId}, #{item.materialUnit}, #{item.materialMatkl}, #{item.materialSpec}, #{item.netWeight}, #{item.grossWeight}, #{item.factoryId}, #{item.createOrgId}, #{item.useOrgId}, #{item.prodlineId}, #{item.activeFlag}, #{item.deletedFlag}, #{item.remark}, #{item.purchasePriceUnitId}, #{item.createBy}, #{item.createTime}, #{item.approveDate}, #{item.erpModifyDate}, #{item.updateTime})
</foreach>
</insert>
<select id="selectMesBaseMaterialInfoByCode" parameterType="String" resultMap="MesBaseMaterialInfoResult">
<include refid="selectMesBaseMaterialInfoVo"/>
where material_code = #{materialCode}
</select>
</mapper>

@ -16,10 +16,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="auditDate" column="audit_date" />
<result property="erpModifyDate" column="erp_modify_date" />
</resultMap>
<sql id="selectMesBaseSupplierInfoVo">
select supplier_id, supplier_code, supplier_name, erp_id, supplier_status, remark, create_by, create_time, update_by, update_time, audit_date from mes_base_supplier_info
select supplier_id, supplier_code, supplier_name, erp_id, supplier_status, remark, create_by, create_time, update_by, update_time, audit_date,erp_modify_date from mes_base_supplier_info
</sql>
<select id="selectMesBaseSupplierInfoList" parameterType="MesBaseSupplierInfo" resultMap="MesBaseSupplierInfoResult">
@ -51,6 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="auditDate != null">audit_date,</if>
<if test="erpModifyDate != null">erp_modify_date,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="supplierCode != null">#{supplierCode},</if>
@ -63,6 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="auditDate != null">#{auditDate},</if>
<if test="erpModifyDate != null">#{erpModifyDate},</if>
</trim>
</insert>
@ -79,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="auditDate != null">audit_date = #{auditDate},</if>
<if test="erpModifyDate != null">erp_modify_date = #{erpModifyDate},</if>
</trim>
where supplier_id = #{supplierId}
</update>
@ -93,4 +97,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{supplierId}
</foreach>
</delete>
<select id="selectMaxErpModifyDate" resultType="String">
SELECT max(erp_modify_date) FROM mes_base_supplier_info order by erp_id
</select>
<select id="selectMesBaseSupplierInfoByErpId" parameterType="Long"
resultMap="MesBaseSupplierInfoResult">
select supplier_id from mes_base_supplier_info where erp_id = #{erpId} limit 1
</select>
<insert id="batchMesBaseSupplierInfo">
INSERT INTO mes_base_supplier_info (supplier_code, supplier_name, erp_id, supplier_status, remark, create_by, create_time, update_by, update_time, audit_date, erp_modify_date) VALUES
<foreach item="item" index="index" collection="list" separator=",">
(#{item.supplierCode}, #{item.supplierName},#{item.erpId}, #{item.supplierStatus}, #{item.remark}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.auditDate}, #{item.erpModifyDate})
</foreach>
</insert>
</mapper>

@ -131,6 +131,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectMesProjectInfoByErpId" parameterType="Long" resultMap="MesProjectInfoResult">
<include refid="selectMesProjectInfoVo"/>
where erp_id = #{erpId}
where erp_id = #{erpId} limit 1
</select>
<select id="selectMaxErpModifyDate" resultType="String">
SELECT max(erp_modify_date) FROM mes_project_info order by erp_id
</select>
<insert id="batchMesBaseProjectInfo">
INSERT INTO mes_project_info (erp_id, project_no, project_name, document_status, forbid_status, audit_date, erp_modify_date, order_status, complete_date, create_time,update_time) VALUES
<foreach item="item" index="index" collection="list" separator=",">
(#{item.erpId}, #{item.projectNo}, #{item.projectName},#{item.documentStatus}, #{item.forbidStatus}, #{item.auditDate}, #{item.erpModifyDate}, #{item.orderStatus}, #{item.completeDate}, #{item.createTime}, #{item.updateTime})
</foreach>
</insert>
</mapper>

@ -198,8 +198,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{purchaseOrderId}
</foreach>
</delete>
<select id="selectMesPurchaseOrderByErpId" parameterType="Long" resultMap="MesPurchaseOrderResult">
<select id="selectMaxErpModifyDate" resultType="String">
SELECT max(erp_modify_date) FROM mes_purchase_order order by erp_id,fentry_id
</select>
<select id="selectMesPurchaseOrderByUI" resultMap="MesPurchaseOrderResult">
<include refid="selectMesPurchaseOrderVo"/>
where erp_id = #{erpId}
where erp_id = #{erpId} and fentry_id = #{fentryId} limit 1
</select>
<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, src_bill_no, purchase_org_id, tond_base, supplier_id, create_time,update_time) VALUES
<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}, #{item.srcBillNo}, #{item.purchaseOrgId}, #{item.tondBase}, #{item.supplierId}, #{item.createTime},#{item.updateTime})
</foreach>
</insert>
</mapper>

@ -39,6 +39,7 @@
<result property="ownerId" column="owner_id"/>
<result property="price" column="price"/>
<result property="stockOrgId" column="stock_org_id"/>
<result property="tondBae" column="tond_base"/>
</resultMap>
<sql id="selectMesSaleOrderVo">
@ -253,4 +254,24 @@
<include refid="selectMesSaleOrderVo"/>
where erp_id = #{erpId}
</select>
<select id="selectMaxErpModifyDate" resultType="String">
SELECT max(erp_modify_date) FROM mes_sale_order order by erp_id,fentry_id
</select>
<select id="selectMesSaleOrderByUI" resultMap="MesSaleOrderResult">
<include refid="selectMesSaleOrderVo"/>
where erp_id = #{erpId} and fentry_id = #{fentryId} limit 1
</select>
<insert id="batchMesBaseSaleOrder">
INSERT INTO mes_sale_order (erp_id, fentry_id, saleorder_code, saleorder_linenumber, document_statsu, material_id, material_code, material_name, matkl, order_amount, complete_amount, release_qty, approve_date, erp_modify_date, plan_delivery_date, stock_id, owner_id, aux_prop_id, sale_dept_id, price, stock_org_id, tond_base, create_time,update_time) VALUES
<foreach item="item" index="index" collection="list" separator=",">
(#{item.erpId}, #{item.fentryId}, #{item.saleorderCode}, #{item.saleorderLinenumber}, #{item.documentStatus}, #{item.materialId}, #{item.materialCode}, #{item.materialName}, #{item.matkl}, #{item.orderAmount}, #{item.completeAmount}, #{item.releaseQty}, #{item.approveDate}, #{item.erpModifyDate}, #{item.planDeliveryDate}, #{item.stockId}, #{item.ownerId}, #{item.auxPropId}, #{item.saleDeptId}, #{item.price}, #{item.stockOrgId}, #{item.tondBase}, #{item.createTime}, #{item.updateTime})
</foreach>
</insert>
</mapper>

@ -67,15 +67,28 @@ public class RyTask
System.out.println("++创建保养工单++getDmsMaintInstance");
remoteDmsService.getDmsBillsMaintInstance(SecurityConstants.INNER,planMaintCode);
}
public void ERPSynMesSupplierInfo(String beginTime, String endTime){
public void syncSupplierInfoFromErp(){
System.out.println("++同步ERP中物料供应商++ErpSupplierInfo");
remoteJindieService.ErpSupplierInfo(SecurityConstants.INNER);
remoteJindieService.syncSupplierInfoFromErp(SecurityConstants.INNER);
}
public void ERPSynMesMaterialInfo(String beginTime, String endTime){
//todo 查询createtime>上次执行时间和updatetime>上次执行时间的,要区分是第一次查询还是后续查询
public void syncMaterialInfoFromErp(){
System.out.println("++同步ERP中物料信息++ErpMesMaterialInfo");
remoteJindieService.ErpMesMaterialInfo(SecurityConstants.INNER);
remoteJindieService.syncMaterialInfoFromErp(SecurityConstants.INNER);
}
public void syncProjectInfoFromErp(){
System.out.println("++同步ERP中项目信息++ErpProjectInfo");
remoteJindieService.syncProjectInfoFromErp(SecurityConstants.INNER);
}
public void syncSaleOrderFromErp(){
System.out.println("++同步ERP中销售订单信息++ErpSaleOrder");
remoteJindieService.syncSaleOrderFromErp(SecurityConstants.INNER);
}
public void syncPurchaseOrderFromErp(){
System.out.println("++同步ERP中采购订单信息++ErpPurchaseOrder");
remoteJindieService.syncPurchaseOrderFromErp(SecurityConstants.INNER);
}
}

Loading…
Cancel
Save