JdTest.java 17 KB

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