1.返利系统插件开发(未测试)

2.HttpRequestUtils工具类get方法调整
This commit is contained in:
龚豆豆 2025-10-13 15:47:05 +08:00
parent 30d334f87e
commit 388587b5e1
7 changed files with 384 additions and 88 deletions

View File

@ -17,15 +17,11 @@ import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.user.UserServiceHelper;
import kd.sdk.plugin.Plugin;
import org.springframework.http.ResponseEntity;
import tqq9.lc123.cloud.app.api.utils.Constants;
import tqq9.lc123.cloud.app.api.utils.HttpClient;
import tqq9.lc123.cloud.app.plugin.utils.EntryFieldRefresher;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.ConnectException;
import java.util.*;
/**
@ -79,7 +75,7 @@ public class PurApplyBillPlugin extends AbstractBillPlugIn implements Plugin {
entryFieldRefresher.updateDynamicObjectByOrg(SH_ORGNUMBER, "supplier", tqq9_sup_sh, model);
String tqq9_mulcombofield1 = tqq9_sup_sh.getString("tqq9_mulcombofield1");
model.setValue("tqq9_suparea_sh", tqq9_mulcombofield1);
HashMap<String, String> queryMap = new HashMap<>();
HashMap<String, Object> queryMap = new HashMap<>();
queryMap.put("supplierId", tqq9_sup_sh.getString("number"));
queryMap.put("companyId", org.getString("number"));
Gson gson = new Gson();
@ -160,7 +156,7 @@ public class PurApplyBillPlugin extends AbstractBillPlugIn implements Plugin {
entryFieldRefresher.updateDynamicObjectByOrg(BJ_ORGNUMBER, "supplier", tqq9_sup_bj, model);
String tqq9_mulcombofield1 = tqq9_sup_bj.getString("tqq9_mulcombofield1");
model.setValue("tqq9_suparea_bj", tqq9_mulcombofield1);
HashMap<String, String> queryMap = new HashMap<>();
HashMap<String, Object> queryMap = new HashMap<>();
queryMap.put("supplierId", tqq9_sup_bj.getString("number"));
queryMap.put("companyId", org.getString("number"));
Gson gson = new Gson();
@ -243,7 +239,7 @@ public class PurApplyBillPlugin extends AbstractBillPlugIn implements Plugin {
entryFieldRefresher.updateDynamicObjectByOrg(GZ_ORGNUMBER, "supplier", tqq9_sup_gz, model);
String tqq9_mulcombofield1 = tqq9_sup_gz.getString("tqq9_mulcombofield1");
model.setValue("tqq9_suparea_gz", tqq9_mulcombofield1);
HashMap<String, String> queryMap = new HashMap<>();
HashMap<String, Object> queryMap = new HashMap<>();
queryMap.put("supplierId", tqq9_sup_gz.getString("number"));
queryMap.put("companyId", org.getString("number"));
Gson gson = new Gson();

View File

@ -15,15 +15,11 @@ import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import org.springframework.http.ResponseEntity;
import tqq9.lc123.cloud.app.api.utils.Constants;
import tqq9.lc123.cloud.app.api.utils.HttpClient;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -336,7 +332,7 @@ public class PuroderBillShareRefundPlugin extends AbstractBillPlugIn {
ChangeData changeData = e.getChangeSet()[0];
DynamicObject newValue = (DynamicObject) changeData.getNewValue();//供应商
DynamicObject org = (DynamicObject)model.getValue("org");//组织
HashMap<String,String> queryMap =new HashMap<>();
HashMap<String,Object> queryMap =new HashMap<>();
queryMap.put("supplierId",newValue.getString("number"));
queryMap.put("companyId",org.getString("number"));
Gson gson = new Gson();

View File

@ -1,33 +1,28 @@
package tqq9.lc123.cloud.app.plugin.operate.ap;
import kd.bos.algo.DataSet;
import kd.bos.dataentity.OperateOption;
import com.google.gson.Gson;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.operate.OperateOptionConst;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.ORM;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;
import tqq9.lc123.cloud.app.plugin.operate.cas.PurOrderReversePayBillPlugin;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.sql.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.DriverManager;
import java.sql.*;
import java.util.HashMap;
/**
* 付款单操作插件
@ -38,6 +33,8 @@ public class PayBillOperationPlugin extends AbstractOperationServicePlugIn imple
private static String URL;
private static String USERNAME;
private static String PASSWORD;
private static String Use_URL;
static {
DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
@ -49,8 +46,16 @@ public class PayBillOperationPlugin extends AbstractOperationServicePlugIn imple
DynamicObject passWord = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "EqmDatabase_password")});
PASSWORD = passWord != null ? passWord.getString("name") : null;
url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_BillCreate_Url")});
Use_URL = url != null ? url.getString("name") : null;
}
private final static HashMap<String, String> tokenMap = new HashMap<String, String>() {{
put("Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3");
}};
@Override
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
@ -86,7 +91,7 @@ public class PayBillOperationPlugin extends AbstractOperationServicePlugIn imple
if (e_payableamt.compareTo(BigDecimal.ZERO) < 0) {
String banktxn = dataEntity1.getString("tqq9_banktxn");//银行流水号
String billno = dataEntity1.getString("billno");//银行流水号
if(StringUtils.isBlank(banktxn)){
if (StringUtils.isBlank(banktxn)) {
this.addErrorMessage(dataEntity, "单据号:" + billno + ",银行流水为空,无法审核");
break;
}
@ -101,7 +106,7 @@ public class PayBillOperationPlugin extends AbstractOperationServicePlugIn imple
rs = stmt.executeQuery(sql);
if (!rs.next()) {
this.addErrorMessage(dataEntity, "单据号:" + billno + ",银行流水:" + banktxn + ",在E企明系统中不存在,无法审核");
this.addErrorMessage(dataEntity, "单据号:" + billno + ",银行流水:" + banktxn + ",在E企明系统中不存在,无法审核");
}
break;
} catch (SQLException | ClassNotFoundException e) {
@ -130,4 +135,65 @@ public class PayBillOperationPlugin extends AbstractOperationServicePlugIn imple
}
}
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
for (DynamicObject dataEntity : e.getDataEntities()) {
String billno = dataEntity.getString("billno");
BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
BigDecimal tqq9_payamount = dataEntity.getBigDecimal("tqq9_payamount");//折扣后返利后价税合计
String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) {
DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("id", tqq9_hfid);
bodyMap.put("lockMoney", tqq9_hshfsyje);
bodyMap.put("lockTaxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(Use_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
} else {
dataEntity.set("tqq9_isrebatecalculate", true);
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
//现返审核
} else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) {
DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("id", tqq9_xfid);
bodyMap.put("lockMoney", tqq9_hsxfsyje);
bodyMap.put("lockTaxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(Use_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
} else {
dataEntity.set("tqq9_isrebatecalculate", true);
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
}

View File

@ -13,10 +13,8 @@ import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.ORM;
import kd.sdk.plugin.Plugin;
import tqq9.lc123.cloud.app.plugin.operate.im.PurOrderPushReceiptNoticePlugin;
import java.math.BigDecimal;
import java.util.Map;
/**
* 付款申请单转换规则插件
@ -45,9 +43,11 @@ public class PurApplySyncSupplierDeductPlugin extends AbstractConvertPlugIn impl
DataSet dataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("cas"), sql);
DataSet copy = dataSet.copy();
DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy);
BigDecimal qty = dynamicObjects.get(0).getBigDecimal("qty");
dataEntity.set("tqq9_gyskdkzje",qty);
if(dynamicObjects.size()>0){
BigDecimal qty = dynamicObjects.get(0).getBigDecimal("qty");
dataEntity.set("tqq9_gyskdkzje",qty);
}
}
}

View File

@ -2,6 +2,7 @@ package tqq9.lc123.cloud.app.plugin.operate.pm;
import com.google.gson.Gson;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
@ -10,15 +11,17 @@ import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
/**
* 操作插件
* 采购订单操作插件
*/
public class PurOrderBillRebatePlugin extends AbstractOperationServicePlugIn implements Plugin {
@ -29,106 +32,277 @@ public class PurOrderBillRebatePlugin extends AbstractOperationServicePlugIn imp
put("Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3");
}};
private static String URL;
private static String Create_URL;
private static String Cancel_URL;
private static String Use_URL;
static {
DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Balance_Url")});
URL = url != null ? url.getString("name") : null;
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_BillCreate_Url")});
Create_URL = url != null ? url.getString("name") : null;
url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Billcancel_Url")});
Cancel_URL = url != null ? url.getString("name") : null;
url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Deduct_Url")});
Use_URL = url != null ? url.getString("name") : null;
}
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
String operationKey = e.getOperationKey();
if (StringUtils.equals("save",operationKey)) {
if (StringUtils.equals("save", operationKey)) {
for (DynamicObject dataEntity : e.getDataEntities()) {
String billno = dataEntity.getString("billno");
DynamicObject supplier = dataEntity.getDynamicObject("supplier");//供应商
DynamicObject org = dataEntity.getDynamicObject("org");//组织
BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
if(tqq9_hshfsyje.compareTo(BigDecimal.ZERO)>0){
String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
//货返锁定
if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_hfid == null) {
DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String,Object> bodyMap =new HashMap<>();
bodyMap.put("supplierId",supplier.getString("number"));
bodyMap.put("companyId",org.getString("number"));
bodyMap.put("type",0);
bodyMap.put("money",tqq9_hshfsyje);
bodyMap.put("taxAmount",taxamount);
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("supplierId", supplier.getString("number"));
bodyMap.put("companyId", org.getString("number"));
bodyMap.put("type", 0);
bodyMap.put("money", tqq9_hshfsyje);
bodyMap.put("taxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
String data = map.get("data").toString();
if (data != null) {
dataEntity.set("tqq9_hfid", data);
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
} else {
this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}else if(tqq9_hsxfsyje.compareTo(BigDecimal.ZERO)>0){
//现返锁定
} else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_xfid == null) {
DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String,Object> bodyMap =new HashMap<>();
bodyMap.put("supplierId",supplier.getString("number"));
bodyMap.put("companyId",org.getString("number"));
bodyMap.put("type",1);
bodyMap.put("money",tqq9_hsxfsyje);
bodyMap.put("taxAmount",taxamount);
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("supplierId", supplier.getString("number"));
bodyMap.put("companyId", org.getString("number"));
bodyMap.put("type", 1);
bodyMap.put("money", tqq9_hsxfsyje);
bodyMap.put("taxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
String data = map.get("data").toString();
if (data != null) {
dataEntity.set("tqq9_xfid", data);
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
} else {
this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
//货返修改
} else if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_hfid != null) {
List<IDataEntityProperty> iDataEntityProperties = dataEntity.getDataEntityState().GetDirtyProperties();
if (iDataEntityProperties.contains("tqq9_hshfsysl")) {
DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String, Object> queryMap = new HashMap<>();
queryMap.put("id", tqq9_xfid);
queryMap.put("money", tqq9_hshfsyje);
queryMap.put("taxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.doGet(Create_URL, queryMap, tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("supplierId", supplier.getString("number"));
bodyMap.put("companyId", org.getString("number"));
bodyMap.put("type", 0);
bodyMap.put("money", tqq9_hshfsyje);
bodyMap.put("taxAmount", taxamount);
try {
String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
String data = map.get("data").toString();
if (data != null) {
dataEntity.set("tqq9_hfid", data);
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
} else {
this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
//现返修改
} else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_xfid != null) {
DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String, Object> queryMap = new HashMap<>();
queryMap.put("id", tqq9_xfid);
queryMap.put("money", tqq9_hsxfsyje);
queryMap.put("taxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.doGet(Create_URL, queryMap, tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("supplierId", supplier.getString("number"));
bodyMap.put("companyId", org.getString("number"));
bodyMap.put("type", 1);
bodyMap.put("money", tqq9_hsxfsyje);
bodyMap.put("taxAmount", taxamount);
try {
String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
String data = map.get("data").toString();
if (data != null) {
dataEntity.set("tqq9_xfid", data);
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
} else {
this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}else if(StringUtils.equals("delete",operationKey)){
} else if (StringUtils.equals("delete", operationKey)) {
//货返删除
for (DynamicObject dataEntity : e.getDataEntities()) {
DynamicObject supplier = dataEntity.getDynamicObject("supplier");//供应商
DynamicObject org = dataEntity.getDynamicObject("org");//组织
String billno = dataEntity.getString("billno");
BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
if(tqq9_hshfsyje.compareTo(BigDecimal.ZERO)>0){
String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) {
DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String,Object> bodyMap =new HashMap<>();
bodyMap.put("supplierId",supplier.getString("number"));
bodyMap.put("companyId",org.getString("number"));
bodyMap.put("type",0);
bodyMap.put("money",tqq9_hshfsyje);
bodyMap.put("taxAmount",taxamount);
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("id", tqq9_hfid);
bodyMap.put("money", tqq9_hshfsyje);
bodyMap.put("taxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
String bodyString = HttpRequestUtils.postJson(Cancel_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}else if(tqq9_hsxfsyje.compareTo(BigDecimal.ZERO)>0){
//现返删除
} else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) {
DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String,Object> bodyMap =new HashMap<>();
bodyMap.put("supplierId",supplier.getString("number"));
bodyMap.put("companyId",org.getString("number"));
bodyMap.put("type",1);
bodyMap.put("money",tqq9_hsxfsyje);
bodyMap.put("taxAmount",taxamount);
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("id", tqq9_xfid);
bodyMap.put("money", tqq9_hsxfsyje);
bodyMap.put("taxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
String bodyString = HttpRequestUtils.postJson(Cancel_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
} else if (StringUtils.equals("audit", operationKey)) {
//货返审核
for (DynamicObject dataEntity : e.getDataEntities()) {
String billno = dataEntity.getString("billno");
BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
BigDecimal tqq9_payamount = dataEntity.getBigDecimal("tqq9_payamount");//折扣后返利后价税合计
String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) {
DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("id", tqq9_hfid);
bodyMap.put("lockMoney", tqq9_hshfsyje);
bodyMap.put("lockTaxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(Use_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
} else {
dataEntity.set("tqq9_isrebatecalculate", true);
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
//现返审核
} else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) {
DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
HashMap<String, Object> bodyMap = new HashMap<>();
bodyMap.put("id", tqq9_xfid);
bodyMap.put("lockMoney", tqq9_hsxfsyje);
bodyMap.put("lockTaxAmount", taxamount);
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(Use_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
} else {
dataEntity.set("tqq9_isrebatecalculate", true);
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
}
}

View File

@ -0,0 +1,66 @@
package tqq9.lc123.cloud.app.plugin.operate.sys;
import com.google.gson.Gson;
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 tqq9.lc123.cloud.app.plugin.operate.pm.PurOrderBillRebatePlugin;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
/**
* 返利规则操作插件
*/
public class RebateRuleOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
private final static Log logger = LogFactory.getLog(PurOrderBillRebatePlugin.class);
private final static HashMap<String, String> tokenMap = new HashMap<String, String>() {{
put("Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3");
}};
private static String Push_URL;
static {
DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_CreatRule_Url")});
Push_URL = url != null ? url.getString("name") : null;
}
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
for (DynamicObject dataEntity : e.getDataEntities()) {
String ruleName = dataEntity.getString("name");//规则名称
String tqq9_rulestype = dataEntity.getString("tqq9_rulestype");//规则类型
Integer type = Integer.valueOf(tqq9_rulestype);//规则类型
Date startTime = dataEntity.getDate("startTime");//返利计算开始时间
Date endTime = dataEntity.getDate("endTime");//返利计算结束时间
HashMap<String, Object> bodyMap = new HashMap<>();
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.postJson(Push_URL, bodyMap.toString(), tokenMap);
HashMap map = gson.fromJson(bodyString, HashMap.class);
Boolean data = (Boolean) map.get("data");
if (!data) {
this.getOperationResult().setMessage("返利规则:" + ruleName + ",审核时创建返利规则失败");
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}

View File

@ -1,20 +1,24 @@
package tqq9.lc123.cloud.app.plugin.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.JSONObject;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
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.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
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 org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -29,12 +33,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.alibaba.fastjson.JSONObject;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public class HttpRequestUtils {
@ -65,7 +63,7 @@ public class HttpRequestUtils {
* @return 响应字符串
* @throws IOException 请求异常时抛出
*/
public static String doGet(String url, Map<String, String> params,
public static String doGet(String url, Map<String, Object> params,
Map<String, String> headers) throws IOException {
return doGet(url, params, headers, DEFAULT_CONNECT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
}
@ -80,7 +78,7 @@ public class HttpRequestUtils {
* @return 响应字符串
* @throws IOException 请求异常时抛出
*/
public static String doGet(String url, Map<String, String> params,
public static String doGet(String url, Map<String, Object> params,
Map<String, String> headers,
int connectTimeout, int socketTimeout) throws IOException {
// 创建HttpClient实例
@ -90,8 +88,8 @@ public class HttpRequestUtils {
// 添加请求参数
if (params != null && !params.isEmpty()) {
for (Map.Entry<String, String> entry : params.entrySet()) {
builder.addParameter(entry.getKey(), entry.getValue());
for (Map.Entry<String, Object> entry : params.entrySet()) {
builder.addParameter(entry.getKey(), entry.getValue().toString());
}
}