package tqq9.lc123.cloud.app.plugin.operate.sys; 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.BusinessDataServiceHelper; import kd.sdk.plugin.Plugin; import kd.bos.dataentity.utils.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import tqq9.lc123.cloud.app.eip.iscb.LCLogService; import tqq9.lc123.cloud.app.eip.iscb.impl.LCLogServiceImpl; import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.HashMap; import static cfca.svs.api.ClientEnvironment.connectTimeout; import static kd.imc.rim.common.utils.HttpUtil.socketTimeout; /** * 单据操作插件 * 物料撤销 调用流程撤回 接口 */ public class MaterialUnsubmitOp extends AbstractOperationServicePlugIn implements Plugin { // private static final Log logger = LogFactory.getLog(MaterialUnsubmitOp.class); // final static String KEY_OPKEY = "unsubmit"; // private static String WL_UnSubmit_URL; // // static { // DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name", // new QFilter[]{new QFilter("number", QCP.equals, "WL_UnSubmit_URL")}); // WL_UnSubmit_URL = url != null ? url.getString("name") : null; // } @Override public void afterExecuteOperationTransaction(AfterOperationArgs e) { super.afterExecuteOperationTransaction(e); // LCLogService lcLogService = new LCLogServiceImpl(); // String operationKey = e.getOperationKey(); // if (StringUtils.equals(operationKey, KEY_OPKEY)) { // //获取选中的物料单据数据 // DynamicObject[] dataEntities = e.getDataEntities(); // for (DynamicObject material : dataEntities) { // String id = String.valueOf(material.getLong("id")); // // 创建HttpClient实例 // try (CloseableHttpClient httpClient = HttpClients.createDefault()) { // // 创建PUT请求 // HttpPut httpPut = new HttpPut(WL_UnSubmit_URL); // // 设置请求体 // StringEntity entity1 = new StringEntity("0", ContentType.APPLICATION_JSON); // StringEntity entity2 = new StringEntity(id, ContentType.APPLICATION_JSON); // httpPut.setEntity(entity1); // httpPut.setEntity(entity2); // // 执行请求并处理响应 // try (CloseableHttpResponse response = httpClient.execute(httpPut)) { // int statusCode = response.getStatusLine().getStatusCode(); // HttpEntity responseEntity = response.getEntity(); // // if (responseEntity == null) { // throw new IOException("Empty response entity"); // } // // String responseBody = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8); // logger.debug("Response status: {}, Body: {}", statusCode, responseBody); // // if (statusCode < 200 || statusCode >= 300) { // throw new IOException("HTTP request failed with status code: " + statusCode + "\n" + "HTTP request failed responseBody: " + responseBody); // } // } // // } catch (IOException ex) { // lcLogService.savelog("FW_流程实例:流程撤回", WL_UnSubmit_URL, false, false, id.toString(), "接口调用报错,errormessage:" + ex.getMessage()); // throw new RuntimeException(ex + "FW_流程实例:流程撤回失败" ); // } // } // // } } }