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

103 lines
5.1 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 com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
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.eip.iscb.impl.LCLogServiceImpl;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//北广生产商同步
public class BGScsOpPlugin extends AbstractOperationServicePlugIn {
private final static Log logger = LogFactory.getLog(BGScsOpPlugin.class);
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
DynamicObject[] dataEntities1 = e.getDataEntities();
if (null != dataEntities1 && dataEntities1.length > 0) {
for (DynamicObject dataEntity : dataEntities1) {
DynamicObject BJURL = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "BJ_POSTURL")});
String BJ_URL = 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");
HashMap<String, Object> body = new HashMap<>();
List<String> fj = new ArrayList<>();
//获取单据信息,并查询单据中的附件字段
dataEntity = BusinessDataServiceHelper.loadSingle(dataEntity.getLong("id"), "tqq9_proxyandfactory");
String number = dataEntity.getString("number");
//获取单据中附件面板信息
List<Map<String, Object>> atts = AttachmentServiceHelper.getAttachments("tqq9_proxyandfactory", dataEntity.getPkValue(), "tqq9_attachmentpanelap");
for (Map<String, Object> att : atts) {
String url = (String) att.get("url");
fj.add(url);
}
String[] collectArray = fj.toArray(new String[0]);
String fname = dataEntity.getString("name");
body.put("MFCode", number);
body.put("MFName", fname);
body.put("lstImageUrls", collectArray);
String jsonBody = JSON.toJSONString(body);
HashMap<String, String> headMap = new HashMap<>();
logger.info("北广生产商同步body" + jsonBody);
try {
String result = HttpRequestUtils.postJson(BJ_URL + "/api/BA/Manufacturer", jsonBody, headMap);
if (StringUtils.isNotEmpty(result)) {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(result);
if (null != rootNode) {
String code = String.valueOf(rootNode.get("code"));
LCLogServiceImpl lcLogService = new LCLogServiceImpl();
lcLogService.savelog("北京生产商同步", BJ_URL+ "/api/BA/Manufacturer", true, code.equals("0"), jsonBody, result);
lcLogService.isSuccess("tqq9_proxyandfactory", number, "number", "tqq9_pushw", code.equals("0"));
}
logger.info("北京生产商同步结果:" + result);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
//广州
try {
String result = HttpRequestUtils.postJson(GZ_URL + "/api/BA/Manufacturer", jsonBody, headMap);
if (StringUtils.isNotEmpty(result)) {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(result);
if (null != rootNode) {
String code = String.valueOf(rootNode.get("code"));
LCLogServiceImpl lcLogService = new LCLogServiceImpl();
lcLogService.savelog("广州生产商同步", GZ_URL+ "/api/BA/Manufacturer", true, code.equals("0"), jsonBody, result);
lcLogService.isSuccess("tqq9_proxyandfactory", number, "number", "tqq9_pushw", code.equals("0"));
}
logger.info("广州生产商同步结果:" + result);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
}