package tqq9.lc123.cloud.app.plugin.form.pm; import com.alibaba.fastjson.JSONObject; 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.entity.datamodel.ListSelectedRow; import kd.bos.entity.datamodel.ListSelectedRowCollection; import kd.bos.entity.operate.result.OperationResult; import kd.bos.form.control.events.BeforeItemClickEvent; import kd.bos.form.events.AfterDoOperationEventArgs; import kd.bos.list.BillList; import kd.bos.list.plugin.AbstractListPlugin; 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.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.math.BigDecimal; import java.math.RoundingMode; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; /** * 采购订单关闭推送返利系统 */ public class PurOrderCloseBillPlugin extends AbstractListPlugin implements Plugin { private final static Log logger = LogFactory.getLog(PurOrderCloseBillPlugin.class); private static String Cancel_URL; private static String RETURN_URL; private static String FLXT_TOKEN; static { DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name", 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", new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Undeduct_Url")}); RETURN_URL = url1 != null ? url1.getString("name") : null; DynamicObject token = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name", new QFilter[]{new QFilter("number", QCP.equals, "FLXT_TOKEN")}); FLXT_TOKEN = token != null ? token.getString("name") : null; } @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 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); } } } } @Override public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) { super.afterDoOperation(afterDoOperationEventArgs); String operateKey = afterDoOperationEventArgs.getOperateKey(); OperationResult operationResult = afterDoOperationEventArgs.getOperationResult(); 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(); // 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 String billno = pm_purorderbill.getString("billno");//单据编号 BigDecimal oneHundred = new BigDecimal(100); HashMap tokenMap = new HashMap(); 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 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+",请求返利系统失败"); } } //现返关闭 if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) { 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 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{ //货返关闭 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 String billno = pm_purorderbill.getString("billno");//单据编号 BigDecimal oneHundred = new BigDecimal(100); HashMap tokenMap = new HashMap(); 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);//税额 JSONObject queryMap = new JSONObject(); 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 { String bodyString = HttpRequestUtils.postJson(RETURN_URL, queryMap.toString(), tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Boolean data = map.getBoolean("data"); if (data == null || !data) { lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, false, queryMap.toString(), bodyString); this.getView().showErrorNotification("采购订单:" + billno + ",释放返利金额失败"); } else { lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, true, queryMap.toString(), bodyString); } } catch (IOException ex) { lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, false, queryMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } } //现返关闭 if (tqq9_hsxfsyje.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_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(new BigDecimal(13)), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额 JSONObject queryMap = new JSONObject(); 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 { String bodyString = HttpRequestUtils.postJson(RETURN_URL, queryMap.toString(), tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Boolean data = map.getBoolean("data"); if (data == null || !data) { lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, false, queryMap.toString(), bodyString); this.getView().showErrorNotification("采购订单:" + billno + ",释放返利金额失败"); } else { lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, true, queryMap.toString(), bodyString); } } catch (IOException ex) { lcLogService.savelog("FL-释放返利金额", RETURN_URL, false, false, queryMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } } } } } } }