2025-10-18 09:51:13 +00:00
|
|
|
|
package tqq9.lc123.cloud.app.plugin.form.pm;
|
|
|
|
|
|
|
2025-11-25 04:41:34 +00:00
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
import com.google.gson.Gson;
|
2025-10-18 09:51:13 +00:00
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
2025-11-25 04:41:34 +00:00
|
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
2025-10-18 09:51:13 +00:00
|
|
|
|
import kd.bos.dataentity.utils.StringUtils;
|
2025-11-25 04:41:34 +00:00
|
|
|
|
import kd.bos.entity.datamodel.ListSelectedRow;
|
|
|
|
|
|
import kd.bos.entity.datamodel.ListSelectedRowCollection;
|
2025-11-24 03:46:18 +00:00
|
|
|
|
import kd.bos.entity.operate.result.OperationResult;
|
2025-11-25 04:41:34 +00:00
|
|
|
|
import kd.bos.form.control.events.BeforeItemClickEvent;
|
2025-11-24 03:46:18 +00:00
|
|
|
|
import kd.bos.form.events.AfterDoOperationEventArgs;
|
2025-11-25 04:41:34 +00:00
|
|
|
|
import kd.bos.list.BillList;
|
|
|
|
|
|
import kd.bos.list.plugin.AbstractListPlugin;
|
2025-10-18 09:51:13 +00:00
|
|
|
|
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;
|
2025-11-25 04:41:34 +00:00
|
|
|
|
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;
|
2025-10-18 09:51:13 +00:00
|
|
|
|
|
2025-11-25 04:41:34 +00:00
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
2025-10-18 09:51:13 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-24 03:46:18 +00:00
|
|
|
|
* 采购订单关闭推送返利系统
|
2025-10-18 09:51:13 +00:00
|
|
|
|
*/
|
2025-11-25 04:41:34 +00:00
|
|
|
|
public class PurOrderCloseBillPlugin extends AbstractListPlugin implements Plugin {
|
2025-10-18 09:51:13 +00:00
|
|
|
|
private final static Log logger = LogFactory.getLog(PurOrderCloseBillPlugin.class);
|
2025-11-25 04:41:34 +00:00
|
|
|
|
private static String Cancel_URL;
|
|
|
|
|
|
private static String RETURN_URL;
|
2025-10-18 09:51:13 +00:00
|
|
|
|
private static String FLXT_TOKEN;
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
|
DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
2025-11-25 04:41:34 +00:00
|
|
|
|
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Billcancel_Url")});
|
|
|
|
|
|
Cancel_URL = url != null ? url.getString("name") : null;
|
|
|
|
|
|
DynamicObject url1 = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
2025-10-18 09:51:13 +00:00
|
|
|
|
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Undeduct_Url")});
|
2025-11-25 04:41:34 +00:00
|
|
|
|
RETURN_URL = url1 != null ? url1.getString("name") : null;
|
2025-10-18 09:51:13 +00:00
|
|
|
|
DynamicObject token = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
|
|
|
|
|
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_TOKEN")});
|
|
|
|
|
|
FLXT_TOKEN = token != null ? token.getString("name") : null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-25 04:41:34 +00:00
|
|
|
|
@Override
|
|
|
|
|
|
public void beforeItemClick(BeforeItemClickEvent evt) {
|
|
|
|
|
|
super.beforeItemClick(evt);
|
|
|
|
|
|
String itemKey = evt.getItemKey();
|
|
|
|
|
|
if ("tblbizclose".equals(itemKey)) {
|
|
|
|
|
|
BillList billList = this.getControl("billlistap");
|
|
|
|
|
|
ListSelectedRowCollection selectedRows = billList.getSelectedRows();
|
|
|
|
|
|
List<String> billnoList = selectedRows.stream().map(ListSelectedRow::getBillNo).distinct().collect(Collectors.toList());
|
|
|
|
|
|
if (billnoList.size() > 1) {
|
|
|
|
|
|
this.getView().showMessage("请选择一张单据");
|
|
|
|
|
|
evt.setCancel(true);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
DynamicObject dataEntity = BusinessDataServiceHelper.loadSingle("pm_purorderbill", "id,billno,closestatus",
|
|
|
|
|
|
new QFilter[]{new QFilter("billno", QCP.in, billnoList)});
|
|
|
|
|
|
if (null != dataEntity) {
|
|
|
|
|
|
String closestatus = dataEntity.getString("closestatus");
|
|
|
|
|
|
if (StringUtils.equals("B", closestatus)) {
|
|
|
|
|
|
this.getView().showMessage("该单据已关闭");
|
|
|
|
|
|
evt.setCancel(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-18 09:51:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-11-24 03:46:18 +00:00
|
|
|
|
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
|
|
|
|
|
|
super.afterDoOperation(afterDoOperationEventArgs);
|
|
|
|
|
|
String operateKey = afterDoOperationEventArgs.getOperateKey();
|
|
|
|
|
|
OperationResult operationResult = afterDoOperationEventArgs.getOperationResult();
|
2025-11-25 04:41:34 +00:00
|
|
|
|
if (StringUtils.equals("bizclose", operateKey) && operationResult.isSuccess()) {
|
|
|
|
|
|
BillList billList = this.getView().getControl("billlistap");
|
|
|
|
|
|
ListSelectedRowCollection selectedRows = billList.getSelectedRows();
|
|
|
|
|
|
//因为只有一张关闭,这里直接调用返利接口
|
|
|
|
|
|
for (int i = 0; i < selectedRows.size(); i++) {
|
|
|
|
|
|
ListSelectedRow selectedRow = selectedRows.get(i);
|
|
|
|
|
|
String billNo = selectedRow.getBillNo();
|
|
|
|
|
|
DynamicObject pm_purorderbill = BusinessDataServiceHelper.loadSingle("pm_purorderbill", new QFilter[]{new QFilter("billno", QCP.equals, billNo)});
|
|
|
|
|
|
DynamicObjectCollection billentry = pm_purorderbill.getDynamicObjectCollection("billentry");
|
|
|
|
|
|
for (DynamicObject dynamicObject : billentry) {
|
|
|
|
|
|
BigDecimal invqty = dynamicObject.getBigDecimal("invqty");
|
|
|
|
|
|
if (invqty.compareTo(BigDecimal.ZERO)>0) {
|
|
|
|
|
|
this.getView().showMessage("部分关单不退回已使用返利");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
boolean tqq9_isrebatecalculate = pm_purorderbill.getBoolean("tqq9_isrebatecalculate");
|
|
|
|
|
|
LCLogService lcLogService = new LCLogServiceImpl();
|
2025-10-18 09:51:13 +00:00
|
|
|
|
|
2025-11-25 04:41:34 +00:00
|
|
|
|
// todo 在此添加业务逻辑
|
|
|
|
|
|
if(!tqq9_isrebatecalculate){
|
|
|
|
|
|
BigDecimal tqq9_hshfsyje = pm_purorderbill.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
|
|
|
|
|
|
BigDecimal tqq9_hsxfsyje = pm_purorderbill.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
|
|
|
|
|
|
String tqq9_hfid = pm_purorderbill.getString("tqq9_hfid");//货返id
|
|
|
|
|
|
String tqq9_xfid = pm_purorderbill.getString("tqq9_xfid");//现返id
|
2025-11-25 09:52:48 +00:00
|
|
|
|
String billno = pm_purorderbill.getString("billno");//单据编号
|
2025-11-25 04:41:34 +00:00
|
|
|
|
BigDecimal oneHundred = new BigDecimal(100);
|
|
|
|
|
|
HashMap<String, String> tokenMap = new HashMap<String, String>();
|
|
|
|
|
|
tokenMap.put("Authorization", FLXT_TOKEN);
|
|
|
|
|
|
//货返关闭
|
|
|
|
|
|
if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
|
BigDecimal notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(new BigDecimal(13)), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
BigDecimal taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额
|
|
|
|
|
|
HashMap<String, Object> queryMap = new HashMap<>();
|
|
|
|
|
|
queryMap.put("id", tqq9_hfid);
|
|
|
|
|
|
queryMap.put("money", tqq9_hshfsyje);
|
|
|
|
|
|
queryMap.put("taxAmount", taxamount);
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
try {
|
|
|
|
|
|
String bodyString = HttpRequestUtils.doGet(Cancel_URL, queryMap, tokenMap);
|
|
|
|
|
|
JSONObject map = gson.fromJson(bodyString, JSONObject.class);
|
|
|
|
|
|
Boolean data = map.getBoolean("data");
|
|
|
|
|
|
if (data == null || !data) {
|
|
|
|
|
|
lcLogService.savelog("FL-解锁返利金额", Cancel_URL, false, false, queryMap.toString(), bodyString);
|
|
|
|
|
|
this.getView().showErrorNotification("采购订单:" + billno + ",撤销占用金额失败");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
lcLogService.savelog("FL-解锁返利金额", Cancel_URL, false, true, queryMap.toString(), bodyString);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
|
lcLogService.savelog("FL-解锁返利金额", Cancel_URL, false, false, queryMap.toString(), "接口调用报错,errormessage:" + ex.getMessage());
|
|
|
|
|
|
throw new RuntimeException(ex+",请求返利系统失败");
|
|
|
|
|
|
}
|
2025-11-25 09:52:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
//现返关闭
|
|
|
|
|
|
if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) {
|
2025-11-25 04:41:34 +00:00
|
|
|
|
BigDecimal notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(new BigDecimal(13)), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
BigDecimal taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额
|
|
|
|
|
|
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(Cancel_URL, queryMap, tokenMap);
|
|
|
|
|
|
JSONObject map = gson.fromJson(bodyString, JSONObject.class);
|
|
|
|
|
|
Boolean data = map.getBoolean("data");
|
|
|
|
|
|
if (data == null || !data) {
|
|
|
|
|
|
lcLogService.savelog("FL-解锁返利金额", Cancel_URL, false, false, queryMap.toString(), bodyString);
|
|
|
|
|
|
this.getView().showErrorNotification("采购订单:" + billno + ",撤销占用金额失败");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
lcLogService.savelog("FL-解锁返利金额", Cancel_URL, false, true, queryMap.toString(), bodyString);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
|
lcLogService.savelog("FL-解锁返利金额", Cancel_URL, false, false, queryMap.toString(), "接口调用报错,errormessage:" + ex.getMessage());
|
|
|
|
|
|
throw new RuntimeException(ex+",请求返利系统失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
2025-11-25 09:52:48 +00:00
|
|
|
|
//货返关闭
|
2025-11-25 04:41:34 +00:00
|
|
|
|
BigDecimal tqq9_hshfsyje = pm_purorderbill.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
|
|
|
|
|
|
BigDecimal tqq9_hsxfsyje = pm_purorderbill.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
|
|
|
|
|
|
String tqq9_hfid = pm_purorderbill.getString("tqq9_hfid");//货返id
|
|
|
|
|
|
String tqq9_xfid = pm_purorderbill.getString("tqq9_xfid");//现返id
|
2025-11-25 09:52:48 +00:00
|
|
|
|
String billno = pm_purorderbill.getString("billno");//单据编号
|
2025-11-25 04:41:34 +00:00
|
|
|
|
BigDecimal oneHundred = new BigDecimal(100);
|
|
|
|
|
|
HashMap<String, String> tokenMap = new HashMap<String, String>();
|
|
|
|
|
|
tokenMap.put("Authorization", FLXT_TOKEN);
|
|
|
|
|
|
//货返关闭
|
|
|
|
|
|
if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
|
DynamicObject supplier = pm_purorderbill.getDynamicObject("supplier");//供应商
|
|
|
|
|
|
DynamicObject org = pm_purorderbill.getDynamicObject("org");//组织
|
|
|
|
|
|
String number = org.getString("number");
|
|
|
|
|
|
DynamicObject org_fl = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
|
|
|
|
|
new QFilter[]{new QFilter("number", QCP.equals, number)});
|
|
|
|
|
|
String orgid_fl = org_fl != null ? org_fl.getString("name") : null;
|
|
|
|
|
|
BigDecimal notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(new BigDecimal(13)), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
BigDecimal taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额
|
2025-11-25 09:52:48 +00:00
|
|
|
|
JSONObject queryMap = new JSONObject();
|
2025-11-25 04:41:34 +00:00
|
|
|
|
queryMap.put("id", tqq9_hfid);
|
|
|
|
|
|
queryMap.put("money", tqq9_hshfsyje);
|
|
|
|
|
|
queryMap.put("taxAmount", taxamount);
|
|
|
|
|
|
queryMap.put("supplierId", supplier.getString("tqq9_ztsupplierid"));
|
|
|
|
|
|
queryMap.put("companyId", orgid_fl);
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
try {
|
2025-11-25 09:52:48 +00:00
|
|
|
|
String bodyString = HttpRequestUtils.postJson(RETURN_URL, queryMap.toString(), tokenMap);
|
2025-11-25 04:41:34 +00:00
|
|
|
|
JSONObject map = gson.fromJson(bodyString, JSONObject.class);
|
|
|
|
|
|
Boolean data = map.getBoolean("data");
|
|
|
|
|
|
if (data == null || !data) {
|
2025-11-25 09:52:48 +00:00
|
|
|
|
lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, false, queryMap.toString(), bodyString);
|
2025-11-25 04:41:34 +00:00
|
|
|
|
this.getView().showErrorNotification("采购订单:" + billno + ",释放返利金额失败");
|
|
|
|
|
|
} else {
|
2025-11-25 09:52:48 +00:00
|
|
|
|
lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, true, queryMap.toString(), bodyString);
|
2025-11-25 04:41:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
} catch (IOException ex) {
|
2025-11-25 09:52:48 +00:00
|
|
|
|
lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, false, queryMap.toString(), "接口调用报错,errormessage:" + ex.getMessage());
|
2025-11-25 04:41:34 +00:00
|
|
|
|
throw new RuntimeException(ex+",请求返利系统失败");
|
|
|
|
|
|
}
|
2025-11-25 09:52:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
//现返关闭
|
|
|
|
|
|
if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) {
|
2025-11-25 04:41:34 +00:00
|
|
|
|
DynamicObject supplier = pm_purorderbill.getDynamicObject("supplier");//供应商
|
|
|
|
|
|
DynamicObject org = pm_purorderbill.getDynamicObject("org");//组织
|
|
|
|
|
|
String number = org.getString("number");
|
|
|
|
|
|
DynamicObject org_fl = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
|
|
|
|
|
new QFilter[]{new QFilter("number", QCP.equals, number)});
|
|
|
|
|
|
String orgid_fl = org_fl != null ? org_fl.getString("name") : null;
|
|
|
|
|
|
BigDecimal notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(new BigDecimal(13)), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
BigDecimal taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额
|
2025-11-25 09:52:48 +00:00
|
|
|
|
JSONObject queryMap = new JSONObject();
|
2025-11-25 04:41:34 +00:00
|
|
|
|
queryMap.put("id", tqq9_xfid);
|
|
|
|
|
|
queryMap.put("money", tqq9_hsxfsyje);
|
|
|
|
|
|
queryMap.put("taxAmount", taxamount);
|
|
|
|
|
|
queryMap.put("supplierId", supplier.getString("tqq9_ztsupplierid"));
|
|
|
|
|
|
queryMap.put("companyId", orgid_fl);
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
try {
|
2025-11-25 09:52:48 +00:00
|
|
|
|
String bodyString = HttpRequestUtils.postJson(RETURN_URL, queryMap.toString(), tokenMap);
|
2025-11-25 04:41:34 +00:00
|
|
|
|
JSONObject map = gson.fromJson(bodyString, JSONObject.class);
|
|
|
|
|
|
Boolean data = map.getBoolean("data");
|
|
|
|
|
|
if (data == null || !data) {
|
2025-11-25 09:52:48 +00:00
|
|
|
|
lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, false, queryMap.toString(), bodyString);
|
2025-11-25 04:41:34 +00:00
|
|
|
|
this.getView().showErrorNotification("采购订单:" + billno + ",释放返利金额失败");
|
|
|
|
|
|
} else {
|
2025-11-25 09:52:48 +00:00
|
|
|
|
lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, true, queryMap.toString(), bodyString);
|
2025-11-25 04:41:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
} catch (IOException ex) {
|
2025-11-25 09:52:48 +00:00
|
|
|
|
lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, false, queryMap.toString(), "接口调用报错,errormessage:" + ex.getMessage());
|
2025-11-25 04:41:34 +00:00
|
|
|
|
throw new RuntimeException(ex+",请求返利系统失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-18 09:51:13 +00:00
|
|
|
|
|
2025-11-25 04:41:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-24 03:46:18 +00:00
|
|
|
|
}
|
2025-10-18 09:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|