lc/lc123/cloud/app/plugin/operate/sys/WmsZczSyncOpPlugin.java

159 lines
8.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tqq9.lc123.cloud.app.plugin.operate.sys;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.util.StringUtils;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
//wms注册证同步
public class WmsZczSyncOpPlugin extends AbstractOperationServicePlugIn {
private final static Log logger = LogFactory.getLog(WmsZczSyncOpPlugin.class);
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 onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
e.getFieldKeys().add("number");
e.getFieldKeys().add("tqq9_startdate");
e.getFieldKeys().add("tqq9_enddate");
e.getFieldKeys().add("modifytime");
e.getFieldKeys().add("tqq9_type");
e.getFieldKeys().add("tqq9_typethree");
e.getFieldKeys().add("tqq9_remark");
e.getFieldKeys().add("tqq9_entry.tqq9_e_supplier");
}
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
DynamicObject[] dataEntities1 = e.getDataEntities();
if (null != dataEntities1 && dataEntities1.length > 0) {
for (DynamicObject dataEntity : dataEntities1) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String number = dataEntity.getString("number");
//厂商分录
DynamicObjectCollection tqq9_entry = dataEntity.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,tqq9_type",
new QFilter[]{new QFilter("number", QFilter.equals, number2)});
String MFCode = file2.getString("number");
String name = file2.getString("name");
String ProLicenceCode = file2.getString("tqq9_prolicense");
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");
}
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", dataEntity.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 >三级分类, string50</threeLevelClass >
// <status>是否有效, Y/N (默认为Y) </ status>
String yxqs = "";
Date tqq9_startdate = dataEntity.getDate("tqq9_startdate");
if (tqq9_startdate != null) {
yxqs = sdf.format(tqq9_startdate);//有效期至
}
String yxqz = "";
Date tqq9_enddate = dataEntity.getDate("tqq9_enddate");//有效期至
if (tqq9_enddate != null) {
yxqz = sdf.format(tqq9_enddate);//有效期至
}
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);
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);
//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);
logger.info("wms注册证同步request" + request);
StringBuilder xmlBuilder = new StringBuilder();
xmlBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
HttpRequestUtils.buildXml(xmlBuilder, finalMap, 0);
logger.info("wms注册证同步xml" + 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);
logger.info("wms注册证接口结果" + s);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
}