191 lines
		
	
	
		
			9.1 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			191 lines
		
	
	
		
			9.1 KiB
		
	
	
	
		
			Java
		
	
	
	
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;
 | 
						||
import kd.bos.orm.query.QCP;
 | 
						||
import kd.bos.orm.query.QFilter;
 | 
						||
import kd.bos.servicehelper.AttachmentServiceHelper;
 | 
						||
import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
						||
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 {
 | 
						||
    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");
 | 
						||
 | 
						||
        if ("audit" .equals(operateKey)) {
 | 
						||
            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");
 | 
						||
                    DynamicObject file2 = BusinessDataServiceHelper.loadSingle("tqq9_proxyandfactory", "id,number,name,tqq9_prolicense",
 | 
						||
                            new QFilter[]{new QFilter("number", QFilter.equals, number2)});
 | 
						||
                    String MFCode = file2.getString("number");
 | 
						||
                    String name = file2.getString("name");
 | 
						||
                    String ProLicenceCode = file2.getString("tqq9_prolicense");
 | 
						||
                    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>
 | 
						||
            String yxqs = "";
 | 
						||
            Date tqq9_startdate = dataEntity.getDate("tqq9_startdate");
 | 
						||
            if (tqq9_startdate !=null){
 | 
						||
                yxqs = sdf.format(dataEntity.getDate("tqq9_startdate"));//有效期至
 | 
						||
            }
 | 
						||
            String yxqz = "";
 | 
						||
            String tqq9_enddate = sdf.format(dataEntity.getDate("tqq9_enddate"));//有效期至
 | 
						||
            if (tqq9_enddate != null) {
 | 
						||
                yxqs = sdf.format(dataEntity.getDate("tqq9_enddate"));//有效期至
 | 
						||
            }
 | 
						||
            String cRemark = dataEntity.getString("tqq9_remark");//备注
 | 
						||
            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);
 | 
						||
            request.put("productDate", yxqs);
 | 
						||
            request.put("expireDate", yxqz);
 | 
						||
            //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);
 | 
						||
            System.out.println("xmlBuilder:"+xmlBuilder);
 | 
						||
 | 
						||
            HashMap<String, String> headMap = new HashMap<>();
 | 
						||
            try {
 | 
						||
                String s = HttpRequestUtils.postXml(WMS_URL+ "?method=registrationcertificate.create&v=2.0&format=xml&customerId=123", xmlBuilder.toString(), headMap);
 | 
						||
                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();
 | 
						||
    }
 | 
						||
 | 
						||
} |