JdTest.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.malk.zhiwei;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.google.gson.Gson;
  6. import com.google.gson.JsonObject;
  7. import com.kingdee.bos.webapi.entity.IdentifyInfo;
  8. import com.kingdee.bos.webapi.entity.RepoRet;
  9. import com.kingdee.bos.webapi.sdk.K3CloudApi;
  10. import com.malk.server.aliwork.YDConf;
  11. import com.malk.server.aliwork.YDParam;
  12. import com.malk.server.aliwork.YDSearch;
  13. import com.malk.server.common.McR;
  14. import com.malk.service.aliwork.YDClient;
  15. import com.malk.utils.PublicUtil;
  16. import com.malk.utils.UtilMap;
  17. import com.malk.zhiwei.config.KDWebApiConf;
  18. import com.malk.zhiwei.entity.*;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.junit.Test;
  21. import org.junit.runner.RunWith;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.boot.test.context.SpringBootTest;
  24. import org.springframework.test.context.junit4.SpringRunner;
  25. import java.util.*;
  26. @Slf4j
  27. @SpringBootTest
  28. @RunWith(SpringRunner.class)
  29. public class JdTest {
  30. @Autowired
  31. private KDWebApiConf kdWebApiConf;
  32. @Autowired
  33. private YDClient ydClient;
  34. @Autowired
  35. private YDConf ydConf;
  36. private IdentifyInfo initIden(){
  37. //注意 1:此处不再使用参数形式传入用户名及密码等敏感信息,改为在登录配置文件中设置。
  38. //注意 2:必须先配置第三方系统登录授权信息后,再进行业务操作,详情参考各语言版本SDK介绍中的登录配置文件说明。
  39. //读取配置,初始化SDK
  40. IdentifyInfo iden = new IdentifyInfo();
  41. iden.setUserName(kdWebApiConf.getXKDApiUserName());
  42. iden.setAppId(kdWebApiConf.getXKDApiAppID());
  43. iden.setdCID(kdWebApiConf.getXKDApiAcctID());
  44. iden.setAppSecret(kdWebApiConf.getXKDApiAppSec());
  45. iden.setServerUrl(kdWebApiConf.getXKDApiServerUrl());
  46. return iden;
  47. }
  48. @Test
  49. public void test(){
  50. K3CloudApi client = new K3CloudApi(initIden());
  51. String value="{\"CreateOrgId\":0,\"Number\":\"\",\"Id\":\"\",\"IsSortBySeq\":\"false\"}";
  52. try {
  53. // String result=client.view("BAS_PreBaseDataOne",value);
  54. PreBaseDataOne preBaseDataOne = new PreBaseDataOne();
  55. preBaseDataOne.setCreateOrgId(value);
  56. String result=client.submit("BAS_PreBaseDataOne", JSONObject.toJSONString(preBaseDataOne));
  57. System.out.println(result);
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. }
  61. }
  62. @Test
  63. public void saveProject(){
  64. K3CloudApi client = new K3CloudApi(initIden());
  65. try {
  66. FBillHead fBillHead = new FBillHead("测试项目","TEST-2026-03-18-001","AI");
  67. String result=client.save("BD_Customer",JSONObject.toJSONString(UtilMap.map("Model",fBillHead)));
  68. System.out.println(result); // 保存数据到金蝶
  69. // JsonObject jsonData = new JsonObject();
  70. // jsonData.addProperty("Numbers", "TEST-2026-03-18-001");
  71. // String result=client.audit("BAS_PreBaseDataOne", jsonData.toString());
  72. System.out.println(result);
  73. }catch (Exception e){
  74. e.printStackTrace();
  75. }
  76. }
  77. @Test
  78. public void saveCust() throws Exception {
  79. FNumber zd = new FNumber("其他");//终端
  80. FNumber syb = new FNumber("MPP");//事业部
  81. FNumber hy = new FNumber("001");//行业
  82. FNumber sktj = new FNumber("008");//收款条件
  83. FNumber xsbm = new FNumber("BM000027");//销售部门
  84. FNumber xsy = new FNumber("0016_GW000014_1");//销售员
  85. CustomerModel customerModel = new CustomerModel("测试客户3",sktj,hy,syb,zd,"李英","1234",xsbm,xsy);
  86. System.out.println(saveToAudit("BD_Customer", customerModel));
  87. }
  88. private McR saveToAudit(String formid, Object object) throws Exception {
  89. JSONObject resultObj = new JSONObject();
  90. K3CloudApi client = new K3CloudApi(initIden());
  91. String result=client.save(formid,JSONObject.toJSONString(UtilMap.map("Model",object)));
  92. resultObj.put("save",result);
  93. Gson gson = new Gson();
  94. RepoRet sRet = gson.fromJson(result, RepoRet.class);
  95. if (sRet.isSuccessfully()) {
  96. JsonObject jsonData = new JsonObject();
  97. jsonData.addProperty("Ids", sRet.getResult().getId());
  98. String result2=client.submit(formid, jsonData.toString());
  99. resultObj.put("save",result2);
  100. RepoRet sRet2 = gson.fromJson(result, RepoRet.class);
  101. if (sRet2.isSuccessfully()) {
  102. JsonObject jsonData3 = new JsonObject();
  103. jsonData3.addProperty("Ids", sRet2.getResult().getId());
  104. String result3 = client.audit(formid, jsonData3.toString());
  105. RepoRet repoRet3 = gson.fromJson(result3, RepoRet.class);
  106. if (repoRet3.getResult().getResponseStatus().isIsSuccess()) {
  107. log.info("审批通过,新增完成");
  108. return McR.success(resultObj);
  109. }
  110. }
  111. }
  112. return McR.error("203",JSONObject.toJSONString(resultObj));
  113. }
  114. @Test
  115. public void queryOrder(){
  116. K3CloudApi client = new K3CloudApi(initIden());
  117. try {
  118. int startRow = 0;
  119. int limit = 2000;
  120. BillQuery billQuery = new BillQuery();
  121. billQuery.setFormId("AR_RECEIVEBILL");
  122. billQuery.setFieldKeys("FPAYUNIT.FName,FREALRECAMOUNTFOR,FDATE,FSETTLETYPEID,FSETTLETYPEID.FName,F_ABC_Base1,FRECACCOUNTNAME,FACCOUNTID.FNumber,FACCOUNTID.FName,FSALEERID.FName,F_ABC_Base,F_ABC_BaseProperty,FBPBILLNUMBER,FBPBILLPARAMOUNT,FBPBILLTYPE,FEXPIRY");
  123. // billQuery.setFieldKeys("FBillNo,FBillTypeID.FName,FPAYUNITTYPE,FDate,FPAYUNIT.FName,FCURRENCYID.FName,FRECEIVEAMOUNTFOR_H,FREALRECAMOUNTFOR,FSALEERID.FName,FSETTLETYPEID,FSETTLETYPEID.FName,FPURPOSEID.FName,FACCOUNTID.FNumber,FACCOUNTID.FName,FRECTOTALAMOUNTFOR,FREALRECAMOUNTFOR_D,FCOMMENT");
  124. List<Map> filterString = new ArrayList<>();
  125. //审核日期为昨天至今天
  126. filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","265",1,"","","0"));//审核日期在今天之前N天以后
  127. // filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","420","2025-10-20 00:00:00","","","0"));//审核日期年=XX
  128. // filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FNumber","67","35","","","0"));//物料编码等于XX
  129. billQuery.setFilterString(filterString);
  130. billQuery.setLimit(limit);
  131. billQuery.setStartRow(startRow);
  132. String result=client.billQuery(JSONObject.toJSONString(billQuery));
  133. JSONArray jsonArray = JSONArray.parseArray(result);
  134. for(int i=0;i<jsonArray.size();i++){
  135. JSONObject jsonObject = jsonArray.getJSONObject(i);
  136. System.out.println(jsonObject);
  137. Receivebill rb= BeanUtil.toBean(jsonObject, Receivebill.class);
  138. if(!PublicUtil.isNull(rb.getAssociationFormField_lypey1wr())){
  139. List<Map> data=(List<Map>) ydClient.queryData(YDParam.builder().formUuid("FORM-8E4AA59DFB354F2D922826F47F70B31AZ8ES")
  140. .searchCondition(JSONObject.toJSONString(Arrays.asList(YDConf.searchCondition_TextFiled("textField_lx05suvl",rb.getAssociationFormField_lypey1wr(),"eq"))))
  141. .build(), YDConf.FORM_QUERY.retrieve_list).getData();
  142. if(data.size()>0){
  143. System.out.println(data.get(0).get("formInstanceId"));
  144. List<Map> kh=ydConf.associationForm("FORM-8E4AA59DFB354F2D922826F47F70B31AZ8ES", String.valueOf(data.get(0).get("formInstanceId")),rb.getAssociationFormField_lypey1wr(),"",false);
  145. rb.setAssociationFormField_lypey1wr(JSONObject.toJSONString(kh));
  146. }else{
  147. rb.setAssociationFormField_lypey1wr("[]");
  148. }
  149. }
  150. Map prodata=new HashMap();
  151. if(!PublicUtil.isNull(rb.getAssociationFormField_lsvmld22())){
  152. List<Map> data=(List<Map>) ydClient.queryData(YDParam.builder().formUuid("FORM-2E06211370FA43D3AEAAC0CF7636365491YX")
  153. .searchCondition(JSONObject.toJSONString(Arrays.asList(YDConf.searchCondition_TextFiled("textField_m0c4utr2",rb.getAssociationFormField_lsvmld22(),"eq"))))
  154. .build(), YDConf.FORM_QUERY.retrieve_list).getData();
  155. if(data.size()>0){
  156. System.out.println(data.get(0).get("formInstanceId"));
  157. Map formData= UtilMap.getMap(data.get(0),"formData");
  158. List<Map> kh=ydConf.associationForm("FORM-2E06211370FA43D3AEAAC0CF7636365491YX", String.valueOf(data.get(0).get("formInstanceId")),UtilMap.getString(formData,"textField_m50ci9rk"),"",false);
  159. rb.setAssociationFormField_lsvmld22(JSONObject.toJSONString(kh));
  160. prodata.put("textField_lwgba84b",formData.get("textField_m0namazl"));
  161. prodata.put("textField_lxvrmu61",formData.get("textField_m0namazj"));
  162. prodata.put("textField_lypey1wx",formData.get("textField_m0c4utr2"));
  163. prodata.put("textField_m1aft8ye",formData.get("textField_m6yurmat"));
  164. prodata.put("numberField_lxu21h6c",formData.get("numberField_mdcwz9mr"));
  165. prodata.put("numberField_lxu29mvg",formData.get("numberField_mdcwz9mv"));
  166. prodata.put("numberField_lxu336sn",formData.get("numberField_m0gb97py"));
  167. }else{
  168. rb.setAssociationFormField_lsvmld22("[]");
  169. }
  170. }
  171. prodata.putAll(JSONObject.parseObject(JSONObject.toJSONString(rb.toYiDa())));
  172. ydClient.operateData(YDParam.builder().formUuid("FORM-9BDAFB39320246EFACC176C9E33E51DC4N40")
  173. .formDataJson(JSONObject.toJSONString(prodata)).build(), YDConf.FORM_OPERATION.start);
  174. }
  175. }catch (Exception e){
  176. e.printStackTrace();
  177. }
  178. }
  179. @Test
  180. public void queryOrder2(){
  181. }
  182. }