change - 采购申请单ERP接口、通用提交、审核ERP接口

master
yinq 7 months ago
parent 05467aed61
commit af2cb826b9

@ -0,0 +1,107 @@
package com.hw.jindie.config;
import com.alibaba.fastjson2.JSONObject;
import com.hw.common.core.utils.DateUtils;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* bean
*/
@Configuration
public class KingdeeConfig {
@Bean
public K3CloudApi K3CloudApi() {
return new K3CloudApi();
}
/**
*
*/
public static Long FID = 0L;
/**
*
*/
public static String FApplicationDate = DateUtils.getTime();
/**
*
*/
public static String FRequestType = "Material";
/**
* formId
*/
public static String PUR_Requisition = "PUR_Requisition";
/**
*
*/
public static JSONObject F_TOND_Base = new JSONObject();
/**
* ||||
*/
public static JSONObject FApplicationOrgId = new JSONObject();
/**
* -
*/
public static JSONObject FBillTypeIDPurchase = new JSONObject();
/**
*
*/
public static JSONObject FCurrencyId = new JSONObject();
/**
*
*/
public static JSONObject FExchangeTypeId = new JSONObject();
/**
*
*/
public static JSONObject getF_TOND_Base() {
F_TOND_Base.put("FNumber", "001");
return F_TOND_Base;
}
/**
* ||||
*/
public static JSONObject getFApplicationOrgId() {
FApplicationOrgId.put("FNumber", "100");
return FApplicationOrgId;
}
/**
* -
*/
public static JSONObject getFBillTypeIDPurchase() {
FBillTypeIDPurchase.put("FNUMBER", "CGSQD01_SYS");
return FBillTypeIDPurchase;
}
/**
*
*/
public static JSONObject getFCurrencyId() {
FCurrencyId.put("FNumber", "PRE001");
return FCurrencyId;
}
/**
*
*/
public static JSONObject getFExchangeTypeId() {
FExchangeTypeId.put("FNumber", "HLTX01_SYS");
return FExchangeTypeId;
}
}

@ -1,11 +1,12 @@
package com.hw.jindie.controller;
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.jindie.service.IKingdeeErpSyncService;
import com.hw.jindie.service.impl.KingdeeErpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
@ -18,9 +19,13 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/jindie")
public class KingdeeErpSyncController {
@Autowired
private IKingdeeErpSyncService kingdeeErpSyncService;
@Autowired
private KingdeeErpService kingdeeErpService;
/**
*
*/
@ -28,12 +33,88 @@ public class KingdeeErpSyncController {
@Log(title = "物料信息", businessType = BusinessType.INSERT)
@GetMapping(("/syncMaterialInfo"))
public AjaxResult syncMaterialInfo() {
try{
try {
return AjaxResult.success(kingdeeErpSyncService.syncMaterialInfoFromErp());
}catch(Exception e){
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error();
}
}
/**
* ->->
*
* @param params {"FMaterialId": "040200050162","FMaterialDesc": "UPVC直管","FReqQty": 20}
* @return {"msg": "{"IsSuccess": true,"Errors": [],"SuccessEntitys": [{"Id": "154898","Number": "CGSQ010785","DIndex": 0}]}", "code": 200}
*/
@PostMapping(("/singleSavePurchaseRequisition"))
public AjaxResult singleSavePurchaseRequisition(@RequestBody String params) {
try {
return AjaxResult.success(kingdeeErpService.singleSavePurchaseRequisition(params));
} catch (Exception e) {
return AjaxResult.error(e.toString());
}
}
/**
* ERP
*
* @param params
* @return
*/
@PostMapping(("/genericCommitInterface"))
public AjaxResult genericCommitInterface(@RequestBody JSONObject params) {
try {
return AjaxResult.success(kingdeeErpService.genericCommitInterface(params));
} catch (Exception e) {
return AjaxResult.error(e.toString());
}
}
/**
* ERP
*
* @param params
* @return
*/
@PostMapping(("/genericAuditInterface"))
public AjaxResult genericAuditInterface(@RequestBody JSONObject params) {
try {
return AjaxResult.success(kingdeeErpService.genericAuditInterface(params));
} catch (Exception e) {
return AjaxResult.error(e.toString());
}
}
/**
* ERP
*
* @param params
* @return
*/
@PostMapping(("/genericViewInterface"))
public String genericViewInterface(@RequestBody JSONObject params) {
try {
return kingdeeErpService.genericViewInterface(params);
} catch (Exception e) {
return e.toString();
}
}
/**
*
*
* @param params
* @return
*/
@PostMapping(("/testAssemblyEntity"))
public String testAssemblyEntity(@RequestBody String params) {
try {
return kingdeeErpService.testAssemblyEntity(params);
} catch (Exception e) {
return e.toString();
}
}
}

@ -0,0 +1,232 @@
package com.hw.jindie.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.hw.jindie.config.KingdeeConfig;
import com.kingdee.bos.webapi.entity.RepoRet;
import com.kingdee.bos.webapi.entity.RepoStatus;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
/**
* @Description: ERP
* @Author : Yinq
* @Date :2024-04-08 14:38
*/
@Service
public class KingdeeErpService {
private static final Logger logger = LoggerFactory.getLogger(KingdeeErpService.class);
private final K3CloudApi client;
public KingdeeErpService(K3CloudApi client) {
this.client = client;
}
/**
* ->->
*
* @param params
* @return
*/
public String singleSavePurchaseRequisition(String params) {
Gson gsonParams = new Gson();
JSONObject objectParams = gsonParams.fromJson(params, JSONObject.class);
JSONObject model = new JSONObject();
JSONObject FEntity = new JSONObject();
String FMaterialId = (String) objectParams.get("FMaterialId");//物料编码
// String FMaterialDesc = (String) objectParams.get("FMaterialDesc");//物料说明
Double FReqQty = (Double) objectParams.get("FReqQty");//采购数量
try {
//业务对象标识
String formId = KingdeeConfig.PUR_Requisition;
//调用接口
FEntity.put("FRequireOrgId", KingdeeConfig.getFApplicationOrgId()); //需求组织(必填项)
JSONObject FMaterialIdObject = new JSONObject();
FMaterialIdObject.put("FNumber", FMaterialId);
FEntity.put("FMaterialId", FMaterialIdObject); //物料编码(必填项)
FEntity.put("FPurchaseOrgId", KingdeeConfig.getFApplicationOrgId()); //采购组织(必填项)
JSONObject FUnitId = new JSONObject();
FUnitId.put("FNumber", "m");
FEntity.put("FUnitId", FUnitId); //申请单位(必填项)
FEntity.put("FPriceUnitId", FUnitId); //计价单位(必填项)
FEntity.put("FREQSTOCKUNITID", FUnitId); //库存单位(必填项)
FEntity.put("FReqQty", FReqQty); //申请数量
// FEntity.put("FMaterialDesc", FMaterialDesc); //物料说明
// FEntity.put("FReceiveOrgId", KingdeeConfig.getFApplicationOrgId()); //收料组织
// FEntity.put("FApproveQty", FReqQty); //批准数量
// FEntity.put("FEvaluatePrice", 0.0); //单价
// FEntity.put("FTAXPRICE", 0.0); //含税单价
// FEntity.put("FTAXRATE", 0.0); //税率%
// FEntity.put("FPriceUnitQty", FReqQty); //计价数量
// FEntity.put("FREQSTOCKQTY", FReqQty); //库存单位数量
// FEntity.put("FLeadTime", 0); //提前期
// FEntity.put("FSrcBillTypeId", ""); //源单类型
// FEntity.put("FSrcBillNo", ""); //源单编号
// FEntity.put("FBaseReqQty", FReqQty); //申请数量
// FEntity.put("FSalUnitID", FUnitId); //销售单位
// FEntity.put("FSalQty", FReqQty); //销售数量
// FEntity.put("FSalBaseQty", FReqQty); //销售基本数量
// FEntity.put("FIsVmiBusiness", false); //VMI业务
// FEntity.put("FDEMANDBILLENTRYSEQ", 0); // 需求单据行号
// FEntity.put("FDEMANDBILLENTRYID", 0); // 需求单据分录内码
ArrayList<JSONObject> entityList = new ArrayList<>();
entityList.add(FEntity);
model.put("FEntity", entityList);
String saveParams = this.saveGenericAssemblyEntity(model);
String resultJson = client.save(formId, saveParams);
// String resultJson = "{\"Result\":{\"ResponseStatus\":{\"IsSuccess\":true,\"Errors\":[],\"SuccessEntitys\":[{\"Id\":154903,\"Number\":\"CGSQ010788\",\"DIndex\":0}],\"SuccessMessages\":[],\"MsgCode\":0},\"Id\":154903,\"Number\":\"CGSQ010788\",\"NeedReturnData\":[{}]}}";
//用于记录结果
Gson gson = new Gson();
//对返回结果进行解析和校验
RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
logger.info("singleSavePurchaseRequisition接口调用成功|请求参数:" + saveParams + "|返回结果:" + resultJson);
RepoStatus responseStatus = repoRet.getResult().getResponseStatus();
if (responseStatus.isIsSuccess()) {
JSONObject json = new JSONObject();
json.put("formId", KingdeeConfig.PUR_Requisition);
json.put("Ids", repoRet.getResult().getId());
//采购申请单提交
// String commitResult = this.genericCommitInterface(json);
//采购申请单审核
// String auditResult = this.genericAuditInterface(json);
}
return gson.toJson(responseStatus);
} catch (Exception e) {
logger.error("singleSavePurchaseRequisition|params" + params + "|Exception" + e);
return e.getMessage();
}
}
/**
*
*
* @param model
* @return
*/
public String saveGenericAssemblyEntity(JSONObject model) {
// 组装数据json
JSONObject result = new JSONObject();
result.put("NeedUpDateFields", new ArrayList<>());
result.put("NeedReturnFields", new ArrayList<>());
result.put("IsDeleteEntry", "true");
result.put("SubSystemId", "");
result.put("IsVerifyBaseDataField", "false");
result.put("IsEntryBatchFill", "true");
result.put("ValidateFlag", "true");
result.put("NumberSearch", "true");
result.put("IsAutoAdjustField", "false");
result.put("InterationFlags", "");
result.put("IgnoreInterationFlag", "");
result.put("IsControlPrecision", "false");
result.put("ValidateRepeatJson", "false");
model.put("FID", KingdeeConfig.FID);
model.put("FBillTypeID", KingdeeConfig.getFBillTypeIDPurchase()); //单据类型(必填项)
model.put("FApplicationDate", KingdeeConfig.FApplicationDate); //申请日期(必填项)
model.put("FRequestType", KingdeeConfig.FRequestType); //申请类型(必填项)
model.put("FApplicationOrgId", KingdeeConfig.getFApplicationOrgId()); //申请组织(必填项)
model.put("F_TOND_Base", KingdeeConfig.getF_TOND_Base()); //京源项目(必填项)
// model.put("FCurrencyId", KingdeeConfig.getFCurrencyId());
// model.put("FExchangeTypeId", KingdeeConfig.getFExchangeTypeId());
// model.put("FISPRICEEXCLUDETAX", true); //价外税
// model.put("FIsConvert", false); //是否是单据转换
// model.put("FACCTYPE", "Q"); //验收方式
// JSONObject FMobBillHead = new JSONObject();
// FMobBillHead.put("FIsMobBill", false);
// FMobBillHead.put("FMobIsPending", false);
// model.put("FMobBillHead", FMobBillHead); //移动单据
result.put("Model", model);
try {
return result.toJSONString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* ERP
*
* @param params
* @return
*/
public String genericCommitInterface(JSONObject params) throws Exception {
JSONObject requestParams = new JSONObject();
//业务对象标识
String formId = params.getString("formId");
requestParams.put("Ids", params.get("Ids"));//单据内码集合
// requestParams.put("Numbers", params.get("Numbers"));//单据编码集合
// requestParams.put("CreateOrgId", 0);
// requestParams.put("IgnoreInterationFlag", "");
// requestParams.put("InterationFlags", "");
// requestParams.put("IsVerifyProcInst", "true");
// requestParams.put("NetworkCtrl", "true");
// requestParams.put("UseBatControlTimes", "false");
// requestParams.put("UseOrgId", 0);
//调用接口
String s = requestParams.toJSONString();
System.out.println(s);
String submit = client.submit(formId, requestParams.toJSONString());
logger.error("genericCommitInterface|formId" + formId + "|请求参数:" + requestParams.toJSONString() + "|返回结果:" + submit);
return submit;
}
/**
* ERP
*
* @param params
* @return
*/
public String genericAuditInterface(JSONObject params) throws Exception {
JSONObject requestParams = new JSONObject();
//业务对象标识
String formId = params.getString("formId");
requestParams.put("Ids", params.get("Ids"));//单据内码集合
//调用接口
String audit = client.audit(formId, requestParams.toJSONString());
logger.error("genericAuditInterface|formId" + formId + "|请求参数:" + requestParams.toJSONString() + "|返回结果:" + audit);
return audit;
}
/**
* ERP
*
* @param params
* @return
*/
public String genericViewInterface(JSONObject params) throws Exception {
JSONObject requestParams = new JSONObject();
//业务对象标识
String formId = params.getString("formId");
requestParams.put("Id", params.get("Id"));//单据内码集合
//调用接口
String audit = client.view(formId, requestParams.toJSONString());
System.out.println(("genericAuditInterface|formId" + formId + "|请求参数:" + requestParams.toJSONString() + "|返回结果:" + audit));
return audit;
}
/**
*
*
* @param params
* @return
*/
public String testAssemblyEntity(String params) {
JSONObject model = new JSONObject();
String result = this.saveGenericAssemblyEntity(model);
System.out.println(result);
return result;
}
}
Loading…
Cancel
Save