ApiService.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.sckw.erp.service;
  2. import com.google.gson.Gson;
  3. import com.kingdee.bos.webapi.entity.IdentifyInfo;
  4. import com.kingdee.bos.webapi.entity.QueryParam;
  5. import com.kingdee.bos.webapi.sdk.K3CloudApi;
  6. import com.sckw.erp.entity.BdCustomer;
  7. import com.sckw.erp.entity.BdMaterial;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Value;
  10. import org.springframework.stereotype.Service;
  11. import javax.annotation.PostConstruct;
  12. import java.util.List;
  13. import java.util.Objects;
  14. /**
  15. * @author xucaiqin
  16. * @date 2025-05-20 09:54:00
  17. */
  18. @Service
  19. @Slf4j
  20. public class ApiService {
  21. protected K3CloudApi api;
  22. @Value("${kd.accid}")
  23. private String AcctID;
  24. @Value("${kd.username}")
  25. private String UserName;
  26. @Value("${kd.appid}")
  27. private String AppID;
  28. @Value("${kd.appsec}")
  29. private String AppSec;
  30. @Value("${kd.serviceUrl}")
  31. private String ServerUrl;
  32. @PostConstruct
  33. private void init() {
  34. if (Objects.isNull(this.api)) {
  35. IdentifyInfo widen = new IdentifyInfo();
  36. widen.setUserName(UserName);
  37. widen.setAppId(AppID);
  38. widen.setdCID(AcctID);
  39. widen.setAppSecret(AppSec);
  40. widen.setlCID(2052);
  41. widen.setServerUrl(ServerUrl);
  42. this.api = new K3CloudApi(widen, false);
  43. }
  44. }
  45. public List<Object> query(String name, Integer pageNo, Integer pageSize) {
  46. if (Objects.isNull(pageSize)) {
  47. pageSize = 20;
  48. }
  49. if (Objects.isNull(pageNo)) {
  50. pageNo = 0;
  51. }
  52. QueryParam<String> para = new QueryParam<>();
  53. para.setFormId("bd_customer");
  54. para.setFieldKeys("FNumber,FName");
  55. para.setFilterString("FName like '%" + name + "%'");
  56. para.setOrderString("");
  57. para.setTopRowCount(0);
  58. para.setStartRow(pageNo);
  59. para.setLimit(pageSize);
  60. List<Object> result;
  61. try {
  62. result = this.api.executeBillQuery(para, BdCustomer.class);
  63. } catch (Exception e) {
  64. throw new RuntimeException(e);
  65. }
  66. return result;
  67. }
  68. public List<Object> queryMaterial(String name, Integer pageNo, Integer pageSize) {
  69. if (Objects.isNull(pageSize)) {
  70. pageSize = 20;
  71. }
  72. if (Objects.isNull(pageNo)) {
  73. pageNo = 0;
  74. }
  75. QueryParam<String> para = new QueryParam<>();
  76. para.setFormId("BD_Material");
  77. para.setFieldKeys("FNumber,FName");
  78. para.setFilterString("FName like '%" + name + "%'");
  79. para.setOrderString("");
  80. para.setTopRowCount(0);
  81. para.setStartRow(pageNo);
  82. para.setLimit(pageSize);
  83. List<Object> lists;
  84. try {
  85. lists = api.executeBillQuery(para, BdMaterial.class);
  86. } catch (Exception e) {
  87. throw new RuntimeException(e);
  88. }
  89. return lists;
  90. }
  91. }