2025-10-13 10:00:56 +00:00
|
|
|
|
package tqq9.lc123.cloud.app.plugin.operate.sys;
|
|
|
|
|
|
|
|
|
|
|
|
import kd.bos.bill.AbstractBillPlugIn;
|
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
|
|
import kd.bos.entity.datamodel.IDataModel;
|
|
|
|
|
|
import kd.bos.form.events.AfterDoOperationEventArgs;
|
2025-10-17 02:04:03 +00:00
|
|
|
|
import kd.bos.logging.Log;
|
|
|
|
|
|
import kd.bos.logging.LogFactory;
|
2025-10-13 10:00:56 +00:00
|
|
|
|
import kd.bos.orm.query.QCP;
|
|
|
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
|
|
|
import kd.bos.servicehelper.AttachmentServiceHelper;
|
|
|
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
2025-10-20 09:27:06 +00:00
|
|
|
|
import kd.bos.util.StringUtils;
|
2025-10-13 10:00:56 +00:00
|
|
|
|
import kd.sdk.plugin.Plugin;
|
|
|
|
|
|
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 动态表单插件
|
|
|
|
|
|
*/
|
|
|
|
|
|
public class wmsZczPostApi extends AbstractBillPlugIn implements Plugin {
|
2025-10-17 02:04:03 +00:00
|
|
|
|
private final static Log logger = LogFactory.getLog(ScsPostApi.class);
|
|
|
|
|
|
|
2025-10-13 10:00:56 +00:00
|
|
|
|
DynamicObject BJURL = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
|
|
|
|
|
new QFilter[]{new QFilter("number", QCP.equals, "BJ_POSTURL")});
|
|
|
|
|
|
String BJ_URL = (String) BJURL.getString("name");
|
|
|
|
|
|
DynamicObject GZURL = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
|
|
|
|
|
new QFilter[]{new QFilter("number", QCP.equals, "GZ_POSTURL")});
|
|
|
|
|
|
String GZ_URL = GZURL.getString("name");
|
|
|
|
|
|
DynamicObject WMSURL = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
|
|
|
|
|
new QFilter[]{new QFilter("number", QCP.equals, "Ttx_MainURL")});
|
|
|
|
|
|
String WMS_URL = WMSURL.getString("name");
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void afterDoOperation(AfterDoOperationEventArgs e) {
|
|
|
|
|
|
super.afterDoOperation(e);
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
String operateKey = e.getOperateKey();
|
|
|
|
|
|
IDataModel model = this.getModel();
|
|
|
|
|
|
|
|
|
|
|
|
DynamicObject dataEntity = model.getDataEntity();
|
|
|
|
|
|
String number = dataEntity.getString("number");
|
|
|
|
|
|
|
2025-10-20 09:27:06 +00:00
|
|
|
|
if ("audit".equals(operateKey)) {
|
2025-10-13 10:00:56 +00:00
|
|
|
|
DynamicObject file = BusinessDataServiceHelper.loadSingle("tqq9_registration", "id,tqq9_attachmentpanelbj,tqq9_supplier.number,tqq9_supplier.tqq9_prolicense,tqq9_entry,tqq9_entry.tqq9_e_supplier",
|
|
|
|
|
|
new QFilter[]{new QFilter("number", QFilter.equals, number)});
|
|
|
|
|
|
DynamicObjectCollection tqq9_entry = file.getDynamicObjectCollection("tqq9_entry");
|
|
|
|
|
|
|
|
|
|
|
|
//获取厂商分录的信息
|
|
|
|
|
|
Map<String, Object> manufactoryList = new HashMap<>();
|
|
|
|
|
|
List<Map<String, String>> manufactoryArray = new ArrayList<>();
|
|
|
|
|
|
for (DynamicObject entry : tqq9_entry) {
|
|
|
|
|
|
DynamicObject tqq9_e_supplier = entry.getDynamicObject("tqq9_e_supplier");
|
|
|
|
|
|
if (tqq9_e_supplier != null) {
|
|
|
|
|
|
HashMap<String, String> map = new HashMap<>();
|
|
|
|
|
|
String number2 = tqq9_e_supplier.getString("number");
|
2025-10-20 09:27:06 +00:00
|
|
|
|
DynamicObject file2 = BusinessDataServiceHelper.loadSingle("tqq9_proxyandfactory", "id,number,name,tqq9_prolicense,tqq9_type",
|
2025-10-13 10:00:56 +00:00
|
|
|
|
new QFilter[]{new QFilter("number", QFilter.equals, number2)});
|
|
|
|
|
|
String MFCode = file2.getString("number");
|
|
|
|
|
|
String name = file2.getString("name");
|
|
|
|
|
|
String ProLicenceCode = file2.getString("tqq9_prolicense");
|
2025-10-20 09:27:06 +00:00
|
|
|
|
String tqq9_type = file2.getString("tqq9_type");//厂商类型
|
|
|
|
|
|
if (StringUtils.isNotEmpty(tqq9_type) && tqq9_type.contains("B")) {
|
|
|
|
|
|
map.put("isAgent", "Y");//代理商
|
|
|
|
|
|
} else {
|
|
|
|
|
|
map.put("isAgent", "N");
|
|
|
|
|
|
}
|
2025-10-13 10:00:56 +00:00
|
|
|
|
map.put("manufactoryCode", MFCode);
|
|
|
|
|
|
map.put("manufactoryName", name);
|
|
|
|
|
|
map.put("proLicenceCode", ProLicenceCode);
|
|
|
|
|
|
manufactoryArray.add(map);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
manufactoryList.put("manufactory", manufactoryArray);
|
|
|
|
|
|
//获取url路径信息
|
|
|
|
|
|
List<Map<String, String>> urlPathsArray = new ArrayList<>();
|
|
|
|
|
|
List<Map<String, Object>> wms_atts = AttachmentServiceHelper.getAttachments("tqq9_registration", file.getPkValue().toString(), "tqq9_attachmentpanelsh");
|
|
|
|
|
|
for (Map<String, Object> att : wms_atts) {
|
|
|
|
|
|
HashMap<String, String> map = new HashMap<>();
|
|
|
|
|
|
String url = (String) att.get("url");
|
|
|
|
|
|
map.put("urlPath", url);
|
|
|
|
|
|
urlPathsArray.add(map);
|
|
|
|
|
|
}
|
|
|
|
|
|
Map<String, Object> urlPathList = new HashMap<>();
|
|
|
|
|
|
urlPathList.put("urlPaths", urlPathsArray);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始封装body
|
|
|
|
|
|
//<actionType>add|update, 必填</actionType>
|
|
|
|
|
|
// <regNo>注册证号, string (250) , 必填</regNo>
|
|
|
|
|
|
// <imported>是否进口,必填,Y/N (默认为N) </imported >
|
|
|
|
|
|
//<productDate>有效期始, string (10) , YYYY-MM-DD</productDate>
|
|
|
|
|
|
// <expireDate>有效期至, string (10) , YYYY-MM-DD , 必填</expireDate>
|
|
|
|
|
|
// <threeLevelClass >三级分类, string(50)</threeLevelClass >
|
|
|
|
|
|
// <status>是否有效, Y/N (默认为Y) </ status>
|
2025-10-14 09:40:15 +00:00
|
|
|
|
String yxqs = "";
|
|
|
|
|
|
Date tqq9_startdate = dataEntity.getDate("tqq9_startdate");
|
2025-10-20 09:27:06 +00:00
|
|
|
|
if (tqq9_startdate != null) {
|
|
|
|
|
|
yxqs = sdf.format(tqq9_startdate);//有效期至
|
2025-10-14 09:40:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
String yxqz = "";
|
2025-10-20 09:27:06 +00:00
|
|
|
|
Date tqq9_enddate = dataEntity.getDate("tqq9_enddate");//有效期至
|
2025-10-14 09:40:15 +00:00
|
|
|
|
if (tqq9_enddate != null) {
|
2025-10-20 09:27:06 +00:00
|
|
|
|
yxqz = sdf.format(tqq9_enddate);//有效期至
|
2025-10-14 09:40:15 +00:00
|
|
|
|
}
|
2025-10-13 10:00:56 +00:00
|
|
|
|
String modifytime = sdf.format(dataEntity.getDate("modifytime"));//修改时间
|
|
|
|
|
|
String IsImportation = dataEntity.getString("tqq9_type").equals("A") ? "Y" : "N";//是否进口
|
|
|
|
|
|
Map<String, Object> request = new HashMap<>();
|
|
|
|
|
|
request.put("actionType", "update");
|
|
|
|
|
|
request.put("regNo", number);
|
|
|
|
|
|
request.put("imported", IsImportation);
|
2025-10-14 09:40:15 +00:00
|
|
|
|
request.put("productDate", yxqs);
|
|
|
|
|
|
request.put("expireDate", yxqz);
|
2025-10-21 10:04:17 +00:00
|
|
|
|
DynamicObject tqq9_typethree = dataEntity.getDynamicObject("tqq9_typethree");//三类产品分类
|
|
|
|
|
|
if (null != tqq9_typethree) {
|
|
|
|
|
|
request.put("threeLevelClass", tqq9_typethree.getString("name"));
|
|
|
|
|
|
}
|
|
|
|
|
|
Map<String, Object> extendProps = new HashMap<>();
|
|
|
|
|
|
extendProps.put("key1", dataEntity.getString("tqq9_remark"));//备注
|
|
|
|
|
|
request.put("extendProps", extendProps);
|
2025-10-13 10:00:56 +00:00
|
|
|
|
//request.put("threeLevelClass", "【三类】口腔科器械(17)");
|
|
|
|
|
|
request.put("status", "Y");
|
|
|
|
|
|
request.put("updateTime", modifytime);
|
|
|
|
|
|
request.put("urlPathList", urlPathList);
|
|
|
|
|
|
request.put("manufactoryList", manufactoryList);
|
|
|
|
|
|
// 最终的外层Map
|
|
|
|
|
|
Map<String, Object> finalMap = new HashMap<>();
|
|
|
|
|
|
finalMap.put("request", request);
|
|
|
|
|
|
StringBuilder xmlBuilder = new StringBuilder();
|
|
|
|
|
|
xmlBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
|
|
|
|
|
buildXml(xmlBuilder, finalMap, 0);
|
2025-10-20 09:27:06 +00:00
|
|
|
|
System.out.println("xmlBuilder:" + xmlBuilder);
|
2025-10-13 10:00:56 +00:00
|
|
|
|
|
|
|
|
|
|
HashMap<String, String> headMap = new HashMap<>();
|
|
|
|
|
|
try {
|
2025-10-20 09:27:06 +00:00
|
|
|
|
String s = HttpRequestUtils.postXml(WMS_URL + "?method=registrationcertificate.create&v=2.0&format=xml&customerId=123", xmlBuilder.toString(), headMap);
|
|
|
|
|
|
logger.info("wms注册证接口回传日志:" + s);
|
2025-10-13 10:00:56 +00:00
|
|
|
|
System.out.println(s);
|
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
|
throw new RuntimeException(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void buildXml(StringBuilder xmlBuilder, Map<String, Object> map, int indent) {
|
|
|
|
|
|
String indentStr = createIndent(indent);
|
|
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
|
|
|
String key = entry.getKey();
|
|
|
|
|
|
Object value = entry.getValue();
|
|
|
|
|
|
|
|
|
|
|
|
if (value instanceof Map) {
|
|
|
|
|
|
// 处理嵌套Map
|
|
|
|
|
|
xmlBuilder.append(indentStr).append("<").append(key).append(">\n");
|
|
|
|
|
|
buildXml(xmlBuilder, (Map<String, Object>) value, indent + 1);
|
|
|
|
|
|
xmlBuilder.append(indentStr).append("</").append(key).append(">\n");
|
|
|
|
|
|
} else if (value instanceof List) {
|
|
|
|
|
|
// 处理List
|
|
|
|
|
|
List<?> list = (List<?>) value;
|
|
|
|
|
|
for (Object item : list) {
|
|
|
|
|
|
if (item instanceof Map) {
|
|
|
|
|
|
xmlBuilder.append(indentStr).append("<").append(key).append(">\n");
|
|
|
|
|
|
buildXml(xmlBuilder, (Map<String, Object>) item, indent + 1);
|
|
|
|
|
|
xmlBuilder.append(indentStr).append("</").append(key).append(">\n");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
xmlBuilder.append(indentStr).append("<").append(key).append(">")
|
|
|
|
|
|
.append(escapeXml(item.toString()))
|
|
|
|
|
|
.append("</").append(key).append(">\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 处理普通值
|
|
|
|
|
|
if (value == null) {
|
|
|
|
|
|
xmlBuilder.append(indentStr).append("<").append(key).append("/>\n");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
xmlBuilder.append(indentStr).append("<").append(key).append(">")
|
|
|
|
|
|
.append(escapeXml(value.toString()))
|
|
|
|
|
|
.append("</").append(key).append(">\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* XML特殊字符转义
|
|
|
|
|
|
*/
|
|
|
|
|
|
private static String escapeXml(String text) {
|
|
|
|
|
|
if (text == null) return "";
|
|
|
|
|
|
return text.replace("&", "&")
|
|
|
|
|
|
.replace("<", "<")
|
|
|
|
|
|
.replace(">", ">")
|
|
|
|
|
|
.replace("\"", """)
|
|
|
|
|
|
.replace("'", "'");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 自定义缩进方法
|
|
|
|
|
|
private static String createIndent(int indent) {
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
for (int i = 0; i < indent; i++) {
|
|
|
|
|
|
sb.append(" "); // 4个空格
|
|
|
|
|
|
}
|
|
|
|
|
|
return sb.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|