KingDeeHelper.java
7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.diligrp.tax.proxy.helper;
import com.diligrp.tax.central.domain.BaseMapping;
import com.diligrp.tax.central.exception.TaxAgentServiceException;
import com.diligrp.tax.central.type.TaxSystemType;
import com.diligrp.tax.central.utils.JsonUtils;
import com.diligrp.tax.proxy.message.KingDeeQuery;
import com.diligrp.tax.proxy.message.KingDeeSubmit;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.gson.Gson;
import com.kingdee.bos.webapi.entity.IdentifyInfo;
import com.kingdee.bos.webapi.entity.OperateParam;
import com.kingdee.bos.webapi.entity.RepoError;
import com.kingdee.bos.webapi.entity.RepoRet;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import lombok.extern.slf4j.Slf4j;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* @Author: zhangmeiyang
* @CreateTime: 2025-10-29 09:42
* @Version: todo
*/
@Slf4j
public class KingDeeHelper {
private static final Gson GSON = new Gson();
/**
* 获取 King Dee API
*
* @param identifyInfo 识别信息
* @return {@link K3CloudApi }
*/
public static K3CloudApi getKingDeeApi(IdentifyInfo identifyInfo) {
return new K3CloudApi(identifyInfo, false);
}
/**
* 获取 repo ret
*
* @param res 分辨率
* @return {@link RepoRet }<{@link ? }>
*/
private static RepoRet<?> getRepoRet(String res) {
RepoRet<?> repoRet = GSON.fromJson(res, RepoRet.class);
if (!repoRet.getResult().getResponseStatus().isIsSuccess()) {
List<String> list = repoRet.getResult().getResponseStatus().getErrors().stream().map(RepoError::getMessage).toList();
throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, String.join(";", list));
}
return repoRet;
}
/**
* 创建非审计机构
*
* @param model 型
* @param api 应用程序接口
* @param formId 表单 ID
* @return {@link RepoRet }<{@link ? }>
*/
public static RepoRet<?> nonAuditSend(Map<String, Object> model, K3CloudApi api, String formId) {
var message = new KingDeeSubmit();
message.setModel(model);
message.setIsAutoSubmitAndAudit(false);
message.setIsAutoAdjustField(true);
var body = JsonUtils.toJsonString(message);
try {
String res = api.save(formId, body);
log.info("金蝶无需审核接口完成,formId={},res={}", formId, res);
return getRepoRet(res);
} catch (Exception e) {
log.error("金蝶无需审核接口调用异常", e);
throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, e);
}
}
/**
* 审计发送
*
* @param mapping 映射
* @param identifyInfo 识别信息
* @param formId 表单 ID
* @return {@link RepoRet }<{@link ? }>
*/
public static RepoRet<?> auditSend(BaseMapping mapping, IdentifyInfo identifyInfo, String formId) {
var message = new KingDeeSubmit();
message.setModel(JsonUtils.convertValue(mapping, new TypeReference<>() {}));
message.setIsAutoSubmitAndAudit(true);
message.setIsAutoAdjustField(true);
var body = JsonUtils.toJsonString(message);
try {
log.info("kingdee auditSend: {}", body);
String res;
K3CloudApi api = getKingDeeApi(identifyInfo);
res = api.save(formId, body);
log.info("金蝶审核接口完成,formId={},res={}", formId, res);
return getRepoRet(res);
} catch (Exception e) {
log.error("金蝶审核接口调用异常", e);
throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, e);
}
}
/**
* 审计发送
*
* @param model 型
* @param api 应用程序接口
* @param formId 表单 ID
* @return {@link RepoRet }<{@link ? }>
*/
public static RepoRet<?> auditSend(Map<String, Object> model, K3CloudApi api, String formId) {
var message = new KingDeeSubmit();
message.setModel(model);
message.setIsAutoSubmitAndAudit(true);
message.setIsAutoAdjustField(true);
var body = JsonUtils.toJsonString(message);
try {
log.info("kingdee auditSend: {}", body);
String res;
res = api.save(formId, body);
log.info("金蝶审核接口完成,formId={},res={}", formId, res);
return getRepoRet(res);
} catch (Exception e) {
log.error("金蝶审核接口调用异常", e);
throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, e);
}
}
/**
* 创建 un audit 参数
*
* @param ids 身份证
* @param api 应用程序接口
* @param formId 表单 ID
* @return {@link RepoRet }<{@link ? }>
*/
public static RepoRet<?> unAuditSend(String ids, K3CloudApi api, String formId) {
var operateParam = new OperateParam();
operateParam.setIds(ids);
try {
RepoRet<?> repoRet = api.unAudit(formId, operateParam);
if (!repoRet.getResult().getResponseStatus().isIsSuccess()) {
List<String> list = repoRet.getResult().getResponseStatus().getErrors().stream().map(RepoError::getMessage).toList();
throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, String.join(";", list));
}
return repoRet;
} catch (Exception e) {
log.error("金蝶反审核接口调用异常", e);
throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, e);
}
}
public static <T extends BaseMapping> List<Object> querySend(T t, String formId, K3CloudApi kingDeeApi) {
var filterString = t.getVerifyInformation();
var fieldKeys = t.getReturnKeys();
return querySend(formId, filterString, fieldKeys, kingDeeApi);
}
/**
* 创建查询参数
*
* @param formId 表单 ID
* @param filterString 过滤器字符串
* @param fieldKeys 字段键
* @param api 应用程序接口
* @return {@link List }<{@link List }<{@link Object }>>
*/
private static List<Object> querySend(String formId, String filterString, String fieldKeys, K3CloudApi api) {
var query = new KingDeeQuery();
query.setFormId(formId);
query.setFilterString(filterString);
query.setFieldKeys(fieldKeys);
try {
List<List<Object>> lists = api.executeBillQuery(JsonUtils.toJsonString(query));
log.info("金蝶查证接口返回,formId={},json={}", formId, lists);
if (lists.isEmpty()) {
return Collections.emptyList();
}
return lists.getFirst();
} catch (Exception e) {
log.error("金蝶查证接口调用异常", e);
throw new TaxAgentServiceException(TaxSystemType.REMOTE_SERVICE_CALLS_ARE_EXCEPTIONAL, e);
}
}
}