JdTest.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. package com.malk.heshu;
  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.heshu.config.KDWebApiConf;
  18. import com.malk.heshu.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 saveCust() throws Exception {
  50. JSONObject params=new JSONObject();
  51. params.put("fid","7eeb3600-3450-46e9-b4e7-47ab4e0ad18e");
  52. params.put("key","textField_mnhav84y");
  53. try {
  54. Map formData= (Map) ydClient.queryData(YDParam.builder().formInstId(params.getString("fid")).build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
  55. if(formData==null){
  56. return ;
  57. }
  58. CustomerInfo customerInfo = BeanUtil.toBean(formData, CustomerInfo.class);
  59. List<Map> list=UtilMap.getList(formData,"tableField_mma72l0q");
  60. List<CustomerInfo.CustBank> bkList=new ArrayList<>();
  61. for(Map map:list){
  62. CustomerInfo.CustBank fBankInfo = BeanUtil.toBean(map, CustomerInfo.CustBank.class);
  63. bkList.add(fBankInfo);
  64. }
  65. customerInfo.setFT_BD_CUSTBANK(bkList);
  66. List<Map> list2=UtilMap.getList(formData,"tableField_mma72kx1");
  67. List<ContactInfo> lxrList=new ArrayList<>();
  68. for(Map map:list2){
  69. ContactInfo contactInfo=new ContactInfo();
  70. contactInfo.setFName(UtilMap.getString(map,"textField_mma72kx2"));
  71. contactInfo.setFMobile(UtilMap.getString(map,"textField_mma72kx3"));
  72. contactInfo.setFCompanyType("BD_Customer");
  73. contactInfo.setFBizLocation(UtilMap.getString(map,"textField_mogukmdi"));
  74. contactInfo.setFBizAddress(UtilMap.getString(map,"textField_mogukmdi"));
  75. lxrList.add(contactInfo);
  76. }
  77. customerInfo.setFSALDEPTID(new FNumber(UtilMap.getString(formData,"textField_mogukmdd")));// 业务部门
  78. String custTypeValue=UtilMap.getString(formData,"radioField_mma72kxi");
  79. String custType;
  80. if(custTypeValue.equals("贸易商")){
  81. custType="02";
  82. }else if(custTypeValue.equals("工厂")){
  83. custType="01";
  84. }else {
  85. custType="05";
  86. }
  87. customerInfo.setFGroup(new FNumber(custType));
  88. String operator=UtilMap.getString(formData,"radioField_mma72l0t");// 操作类型 客商准入 客商更新
  89. if(operator.equals("客商更新")){
  90. String fId=UtilMap.getString(formData,"textField_moi1ejl1");
  91. if(!PublicUtil.isNull(fId)){
  92. // 反审核
  93. unAudit("BD_Customer",fId);
  94. customerInfo.setFCUSTID(Integer.parseInt(fId));
  95. }
  96. }
  97. McR mcr=saveToAudit("BD_Customer",customerInfo,params.getString("fid"),params.getString("key"),"selectField_mogukmd8","textareaField_mogukmda","textField_moi1ejl1",lxrList);
  98. System.out.println(JSONObject.toJSONString(mcr));
  99. }catch (Exception e){
  100. }
  101. }
  102. @Test
  103. public void saveSupplier() throws Exception {
  104. Map formData= (Map) ydClient.queryData(YDParam.builder().formInstId("a4fba63b-586c-43ee-9d34-daaeee2b19f1").build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
  105. System.out.println(formData);
  106. SupplierEntity supplierEntity = BeanUtil.toBean(formData, SupplierEntity.class);
  107. SupplierEntity.FBaseInfo fBaseInfo = BeanUtil.toBean(formData, SupplierEntity.FBaseInfo.class);
  108. List<Map> list=UtilMap.getList(formData,"tableField_mma72l0q");
  109. List<SupplierEntity.FBankInfo> bkList=new ArrayList<>();
  110. for(Map map:list){
  111. SupplierEntity.FBankInfo fBankInfo = BeanUtil.toBean(map, SupplierEntity.FBankInfo.class);
  112. bkList.add(fBankInfo);
  113. }
  114. supplierEntity.setFBaseInfo(fBaseInfo);
  115. supplierEntity.setFBankInfo(bkList);
  116. List<Map> list2=UtilMap.getList(formData,"tableField_mma72kx1");
  117. List<SupplierEntity.FSupplierContact> lxrList=new ArrayList<>();
  118. for(Map map:list2){
  119. SupplierEntity.FSupplierContact lxrInfo = BeanUtil.toBean(map, SupplierEntity.FSupplierContact.class);
  120. lxrList.add(lxrInfo);
  121. }
  122. supplierEntity.setFSupplierContact(lxrList);
  123. System.out.println(supplierEntity);
  124. // System.out.println(saveToAudit("BD_Supplier",supplierEntity));
  125. }
  126. private McR saveToAudit(String formid, Object object,String fid,String codeKey,String statusKey,String msgKey,String idKey,List<ContactInfo> lxrList) throws Exception {
  127. JSONObject resultObj = new JSONObject();
  128. K3CloudApi client = new K3CloudApi(initIden());
  129. String result=client.save(formid,JSONObject.toJSONString(UtilMap.map("Model",object)));
  130. resultObj.put("save",result);
  131. Gson gson = new Gson();
  132. RepoRet sRet = gson.fromJson(result, RepoRet.class);
  133. JSONObject reObj = JSONObject.parseObject(result,JSONObject.class);
  134. if (sRet.isSuccessfully()) {
  135. if(!PublicUtil.isNull(codeKey)){
  136. // 回写信息
  137. Map updateMap=UtilMap.map(codeKey,reObj.getJSONObject("Result").getString("Number"));
  138. updateMap.put(statusKey,"成功");
  139. updateMap.put(idKey,reObj.getJSONObject("Result").getString("Id"));// ID 内码
  140. ydClient.operateData(YDParam.builder().formInstId(fid).updateFormDataJson(
  141. JSONObject.toJSONString(updateMap)
  142. ).build(), YDConf.FORM_OPERATION.update);
  143. }
  144. if(lxrList!=null){
  145. for (ContactInfo contactInfo : lxrList) {
  146. contactInfo.setFCompany(new FNumber(reObj.getJSONObject("Result").getString("Number")));
  147. String data=new Gson().toJson(contactInfo);
  148. String id=saveToAudit("BD_CommonContact",new Gson().fromJson(data,Object.class));
  149. }
  150. }
  151. JsonObject jsonData = new JsonObject();
  152. jsonData.addProperty("Ids", sRet.getResult().getId());
  153. String result2=client.submit(formid, jsonData.toString());
  154. resultObj.put("submit",result2);
  155. RepoRet sRet2 = gson.fromJson(result, RepoRet.class);
  156. if (sRet2.isSuccessfully()) {
  157. JsonObject jsonData3 = new JsonObject();
  158. jsonData3.addProperty("Ids", sRet2.getResult().getId());
  159. String result3 = client.audit(formid, jsonData3.toString());
  160. resultObj.put("audit",result3);
  161. RepoRet repoRet3 = gson.fromJson(result3, RepoRet.class);
  162. if (repoRet3.getResult().getResponseStatus().isIsSuccess()) {
  163. log.info("审批通过,新增完成");
  164. return McR.success(resultObj);
  165. // Map map=UtilMap.map("PkIds, TOrgIds",sRet.getResult().getId(),"1,105818,105822,127834,127835,127838,127843,127846,127847,127848,127850,127862,1370321,1325841,1327202,1646858");
  166. // String result4=client.allocate("formid",JSONObject.toJSONString(map));
  167. // resultObj.put("allocate",result4);
  168. // RepoRet repoRet4 = gson.fromJson(result4, RepoRet.class);
  169. // if (repoRet4.getResult().getResponseStatus().isIsSuccess()) {
  170. // log.info("分配完成");
  171. // return McR.success(resultObj);
  172. // }
  173. }
  174. }
  175. }else {
  176. log.info("保存失败:{}",result);
  177. Map updateMap=UtilMap.map(statusKey,"失败");
  178. updateMap.put(msgKey,result);
  179. ydClient.operateData(YDParam.builder().formInstId(fid).updateFormDataJson(
  180. JSONObject.toJSONString(updateMap)
  181. ).build(), YDConf.FORM_OPERATION.update);
  182. }
  183. return McR.error("203",JSONObject.toJSONString(resultObj));
  184. }
  185. private void unAudit(String formid,String fNumber) throws Exception {
  186. K3CloudApi client = new K3CloudApi(initIden());
  187. Gson gson = new Gson();
  188. JsonObject jsonData = new JsonObject();
  189. jsonData.addProperty("Ids", fNumber);
  190. String result=client.unAudit(formid, jsonData.toString());
  191. RepoRet sRet2 = gson.fromJson(result, RepoRet.class);
  192. if (!sRet2.isSuccessfully()) {
  193. log.info("反审核失败:{}",result);
  194. }
  195. }
  196. @Test
  197. public void queryOrder(){
  198. K3CloudApi client = new K3CloudApi(initIden());
  199. try {
  200. int startRow = 0;
  201. int limit = 2000;
  202. BillQuery billQuery = new BillQuery();
  203. billQuery.setFormId("AR_RECEIVEBILL");
  204. 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");
  205. // 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");
  206. List<Map> filterString = new ArrayList<>();
  207. //审核日期为昨天至今天
  208. filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","265",4,"","","0"));//审核日期在今天之前N天以后
  209. // filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","420","2025-10-20 00:00:00","","","0"));//审核日期年=XX
  210. // filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FNumber","67","35","","","0"));//物料编码等于XX
  211. billQuery.setFilterString(filterString);
  212. billQuery.setLimit(limit);
  213. billQuery.setStartRow(startRow);
  214. String result=client.billQuery(JSONObject.toJSONString(billQuery));
  215. System.out.println(result);
  216. // JSONArray jsonArray = JSONArray.parseArray(result);
  217. // for(int i=0;i<jsonArray.size();i++){
  218. // JSONObject jsonObject = jsonArray.getJSONObject(i);
  219. // System.out.println(jsonObject);
  220. // Receivebill rb= BeanUtil.toBean(jsonObject, Receivebill.class);
  221. // if(!PublicUtil.isNull(rb.getAssociationFormField_lypey1wr())){
  222. // List<Map> data=(List<Map>) ydClient.queryData(YDParam.builder().formUuid("FORM-8E4AA59DFB354F2D922826F47F70B31AZ8ES")
  223. // .searchCondition(JSONObject.toJSONString(Arrays.asList(YDConf.searchCondition_TextFiled("textField_lx05suvl",rb.getAssociationFormField_lypey1wr(),"eq"))))
  224. // .build(), YDConf.FORM_QUERY.retrieve_list).getData();
  225. // if(data.size()>0){
  226. // System.out.println(data.get(0).get("formInstanceId"));
  227. // List<Map> kh=ydConf.associationForm("FORM-8E4AA59DFB354F2D922826F47F70B31AZ8ES", String.valueOf(data.get(0).get("formInstanceId")),rb.getAssociationFormField_lypey1wr(),"",false);
  228. // rb.setAssociationFormField_lypey1wr(JSONObject.toJSONString(kh));
  229. // }else{
  230. // rb.setAssociationFormField_lypey1wr("[]");
  231. // }
  232. // }
  233. // Map prodata=new HashMap();
  234. // if(!PublicUtil.isNull(rb.getAssociationFormField_lsvmld22())){
  235. // List<Map> data=(List<Map>) ydClient.queryData(YDParam.builder().formUuid("FORM-2E06211370FA43D3AEAAC0CF7636365491YX")
  236. // .searchCondition(JSONObject.toJSONString(Arrays.asList(YDConf.searchCondition_TextFiled("textField_m0c4utr2",rb.getAssociationFormField_lsvmld22(),"eq"))))
  237. // .build(), YDConf.FORM_QUERY.retrieve_list).getData();
  238. // if(data.size()>0){
  239. // System.out.println(data.get(0).get("formInstanceId"));
  240. // Map formData= UtilMap.getMap(data.get(0),"formData");
  241. // List<Map> kh=ydConf.associationForm("FORM-2E06211370FA43D3AEAAC0CF7636365491YX", String.valueOf(data.get(0).get("formInstanceId")),UtilMap.getString(formData,"textField_m50ci9rk"),"",false);
  242. // rb.setAssociationFormField_lsvmld22(JSONObject.toJSONString(kh));
  243. // prodata.put("textField_lwgba84b",formData.get("textField_m0namazl"));
  244. // prodata.put("textField_lxvrmu61",formData.get("textField_m0namazj"));
  245. // prodata.put("textField_lypey1wx",formData.get("textField_m0c4utr2"));
  246. // prodata.put("textField_m1aft8ye",formData.get("textField_m6yurmat"));
  247. // prodata.put("numberField_lxu21h6c",formData.get("numberField_mdcwz9mr"));
  248. // prodata.put("numberField_lxu29mvg",formData.get("numberField_mdcwz9mv"));
  249. // prodata.put("numberField_lxu336sn",formData.get("numberField_m0gb97py"));
  250. // }else{
  251. // rb.setAssociationFormField_lsvmld22("[]");
  252. // }
  253. // }
  254. // prodata.putAll(JSONObject.parseObject(JSONObject.toJSONString(rb.toYiDa())));
  255. // ydClient.operateData(YDParam.builder().formUuid("FORM-9BDAFB39320246EFACC176C9E33E51DC4N40")
  256. // .formDataJson(JSONObject.toJSONString(prodata)).build(), YDConf.FORM_OPERATION.start);
  257. // }
  258. }catch (Exception e){
  259. e.printStackTrace();
  260. }
  261. }
  262. @Test
  263. public void update(){
  264. // unAudit("BD_Customer","");
  265. }
  266. @Test
  267. public void queryOrder2(){
  268. ContactInfo contactInfo=new ContactInfo();
  269. contactInfo.setFName("张三");
  270. contactInfo.setFMobile("17700001111");
  271. contactInfo.setFCompanyType("BD_Customer");
  272. contactInfo.setFCompany(new FNumber("CUST5127"));
  273. contactInfo.setFBizLocation("测试地址");
  274. contactInfo.setFBizAddress("测试地址");
  275. try {
  276. String data=new Gson().toJson(contactInfo);
  277. System.out.println(data);
  278. JSONObject jsonObject=JSONObject.parseObject(data);
  279. System.out.println(jsonObject);
  280. String id=saveToAudit("BD_CommonContact",new Gson().fromJson(data,Object.class));
  281. } catch (Exception e) {
  282. throw new RuntimeException(e);
  283. }
  284. }
  285. private String saveToAudit(String formid, Object object) throws Exception {
  286. K3CloudApi client = new K3CloudApi(initIden());
  287. String result=client.save(formid,JSONObject.toJSONString(UtilMap.map("Model",object)));
  288. System.out.println(result);
  289. Gson gson = new Gson();
  290. RepoRet sRet = gson.fromJson(result, RepoRet.class);
  291. JSONObject reObj = JSONObject.parseObject(result,JSONObject.class);
  292. if (sRet.isSuccessfully()) {
  293. return reObj.getJSONObject("Result").getString("Id");
  294. }else {
  295. return "";
  296. }
  297. }
  298. }