package tqq9.lc123.cloud.app.plugin.operate.pm; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import kd.bos.dataentity.OperateOption; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.utils.StringUtils; import kd.bos.entity.operate.result.OperationResult; import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.PreparePropertysEventArgs; import kd.bos.entity.plugin.args.AfterOperationArgs; import kd.bos.entity.plugin.args.BeforeOperationArgs; 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.bos.servicehelper.operation.OperationServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.sdk.plugin.Plugin; import tqq9.lc123.cloud.app.api.utils.Constants; 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.ArrayList; import java.util.HashMap; import java.util.List; /** * 采购订单操作插件 */ public class PurOrderBillRebatePlugin extends AbstractOperationServicePlugIn implements Plugin { private final static Log logger = LogFactory.getLog(PurOrderBillRebatePlugin.class); private final static String ENTRYENTITY = "billentry"; private static String Create_URL; private static String Cancel_URL; private static String Use_URL; private static String FLXT_TOKEN; static { DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name", 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; 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 onPreparePropertys(PreparePropertysEventArgs e) { super.onPreparePropertys(e); e.getFieldKeys().add("billno"); e.getFieldKeys().add("supplier"); e.getFieldKeys().add("tqq9_hshfsyje"); e.getFieldKeys().add("tqq9_hsxfsyje"); e.getFieldKeys().add("tqq9_hshfsyje_old"); e.getFieldKeys().add("tqq9_hsxfsyje_old"); e.getFieldKeys().add("tqq9_hshfsysl"); e.getFieldKeys().add("tqq9_hsxfsysl"); e.getFieldKeys().add("tqq9_hfid"); e.getFieldKeys().add("tqq9_xfid"); e.getFieldKeys().add("tqq9_payamount"); } @Override public void beforeExecuteOperationTransaction(BeforeOperationArgs e) { super.beforeExecuteOperationTransaction(e); String operationKey = e.getOperationKey(); if (StringUtils.equals("submit", operationKey)) { OperateOption option = this.getOption(); DynamicObject[] dataEntities1 = e.getDataEntities(); for (int i = 0; i < dataEntities1.length; i++) { DynamicObject object = dataEntities1[i]; DynamicObject object1 = BusinessDataServiceHelper.loadSingle(object.getPkValue(), "pm_purorderbill"); OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SAVE, "pm_purorderbill",new DynamicObject[]{object1} , operateOption); } } } @Override public void afterExecuteOperationTransaction(AfterOperationArgs e) { super.afterExecuteOperationTransaction(e); String operationKey = e.getOperationKey(); HashMap tokenMap = new HashMap(); tokenMap.put("Authorization", FLXT_TOKEN); BigDecimal oneHundred = new BigDecimal(100); LCLogService lcLogService = new LCLogServiceImpl(); DynamicObject[] dataEntities1 = e.getDataEntities(); String entitytype = ""; if (dataEntities1 != null && dataEntities1.length > 0) { entitytype = dataEntities1[0].getDynamicObjectType().getName(); } if (StringUtils.equals("save", operationKey)) { for (DynamicObject dataEntity : e.getDataEntities()) { String billno = dataEntity.getString("billno"); if (!StringUtils.equals("pm_purorderbill", entitytype)) { billno = dataEntity.getString("changebillno"); } DynamicObject supplier = dataEntity.getDynamicObject("supplier");//供应商 DynamicObject org = dataEntity.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 tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje").setScale(2, RoundingMode.HALF_UP);//含税货返使用金额 BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje").setScale(2, RoundingMode.HALF_UP);//含税现返使用金额 BigDecimal tqq9_hshfsyje_old = dataEntity.getBigDecimal("tqq9_hshfsyje_old").setScale(2, RoundingMode.HALF_UP);//含税货返使用金额(旧) BigDecimal tqq9_hsxfsyje_old = dataEntity.getBigDecimal("tqq9_hsxfsyje_old").setScale(2, RoundingMode.HALF_UP);//含税现返使用金额(旧) String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id Integer hfid = null; Integer xfid = null; if (StringUtils.isNotBlank(tqq9_hfid)) { hfid = Integer.valueOf(tqq9_hfid); } if (StringUtils.isNotBlank(tqq9_xfid)) { xfid = Integer.valueOf(tqq9_xfid); } //货返锁定 if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && !tqq9_hshfsyje.equals(tqq9_hshfsyje_old) && tqq9_hshfsyje_old.compareTo(BigDecimal.ZERO) == 0) { DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率 BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额 JSONObject bodyMap = new JSONObject(); bodyMap.put("supplierId", supplier.getString("tqq9_ztsupplierid")); bodyMap.put("companyId", orgid_fl); bodyMap.put("type", 0); bodyMap.put("money", tqq9_hshfsyje); bodyMap.put("taxAmount", taxamount); Gson gson = new Gson(); try { String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Object data = map.getInteger("data"); if (data != null) { dataEntity.set("tqq9_hfid", data.toString()); lcLogService.savelog("FL-锁定返利金额", Create_URL, true, true, bodyMap.toString(), bodyString); } else { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), bodyString); this.getOperationResult().setMessage("采购订单:" + billno + ",占用金额失败"); } } catch (IOException ex) { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } dataEntity.set("tqq9_hshfsyje_old", tqq9_hshfsyje);//含税货返使用金额(旧) SaveServiceHelper.save(new DynamicObject[]{dataEntity}); } //现返锁定 if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && !tqq9_hsxfsyje.equals(tqq9_hsxfsyje_old) && tqq9_hsxfsyje_old.compareTo(BigDecimal.ZERO) == 0) { DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率 BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额 JSONObject bodyMap = new JSONObject(); bodyMap.put("supplierId", supplier.getString("tqq9_ztsupplierid")); bodyMap.put("companyId", orgid_fl); bodyMap.put("type", 1); bodyMap.put("money", tqq9_hsxfsyje); bodyMap.put("taxAmount", taxamount); Gson gson = new Gson(); try { String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Object data = map.getInteger("data"); if (data != null) { dataEntity.set("tqq9_xfid", data.toString()); lcLogService.savelog("FL-锁定返利金额", Create_URL, true, true, bodyMap.toString(), bodyString); } else { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), bodyString); this.getOperationResult().setMessage("采购订单:" + billno + ",占用金额失败"); } } catch (IOException ex) { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } dataEntity.set("tqq9_hsxfsyje_old", tqq9_hsxfsyje);//含税现返使用金额(旧) SaveServiceHelper.save(new DynamicObject[]{dataEntity}); } //货返修改 if (!tqq9_hshfsyje.equals(tqq9_hshfsyje_old) && tqq9_hshfsyje_old.compareTo(BigDecimal.ZERO) > 0) { DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率 BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hshfsyje_old.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hshfsyje_old.subtract(notaxamount);//税额 HashMap queryMap = new HashMap<>(); queryMap.put("id", hfid); queryMap.put("money", tqq9_hshfsyje_old); 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.getOperationResult().setMessage("采购订单:" + 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_hshfsyje.compareTo(BigDecimal.ZERO) > 0) { notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额 JSONObject bodyMap = new JSONObject(); bodyMap.put("supplierId", supplier.getString("tqq9_ztsupplierid")); bodyMap.put("companyId", orgid_fl); bodyMap.put("type", 0); bodyMap.put("money", tqq9_hshfsyje); bodyMap.put("taxAmount", taxamount); try { String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Object data = map.getInteger("data"); if (data != null) { dataEntity.set("tqq9_hfid", data.toString()); lcLogService.savelog("FL-锁定返利金额", Create_URL, true, true, bodyMap.toString(), bodyString); } else { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), bodyString); this.getOperationResult().setMessage("采购订单:" + billno + ",占用金额失败"); } } catch (IOException ex) { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } dataEntity.set("tqq9_hshfsyje_old", tqq9_hshfsyje);//含税货返使用金额(旧) SaveServiceHelper.save(new DynamicObject[]{dataEntity}); } } //现返修改 if (!tqq9_hsxfsyje.equals(tqq9_hsxfsyje_old) && tqq9_hsxfsyje_old.compareTo(BigDecimal.ZERO) > 0) { DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率 BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hsxfsyje_old.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hsxfsyje_old.subtract(notaxamount);//税额 HashMap queryMap = new HashMap<>(); queryMap.put("id", xfid); queryMap.put("money", tqq9_hsxfsyje_old); 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.getOperationResult().setMessage("采购订单:" + 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) { notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额 JSONObject bodyMap = new JSONObject(); bodyMap.put("supplierId", supplier.getString("tqq9_ztsupplierid")); bodyMap.put("companyId", orgid_fl); bodyMap.put("type", 1); bodyMap.put("money", tqq9_hsxfsyje); bodyMap.put("taxAmount", taxamount); try { String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Object data = map.getInteger("data"); if (data != null) { dataEntity.set("tqq9_xfid", data.toString()); lcLogService.savelog("FL-锁定返利金额", Create_URL, true, true, bodyMap.toString(), bodyString); } else { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), bodyString); this.getOperationResult().setMessage("采购订单:" + billno + ",占用金额失败"); } } catch (IOException ex) { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } dataEntity.set("tqq9_hsxfsyje_old", tqq9_hsxfsyje);//含税现返使用金额(旧) SaveServiceHelper.save(new DynamicObject[]{dataEntity}); } } } } if (StringUtils.equals("delete", operationKey)) { //货返删除 if (StringUtils.equals("pm_purorderbill", entitytype)) { for (DynamicObject dataEntity : e.getDataEntities()) { String billno = dataEntity.getString("billno"); if (!StringUtils.equals("pm_purorderbill", entitytype)) { billno = dataEntity.getString("changebillno"); } BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje").setScale(2, RoundingMode.HALF_UP);//含税货返使用金额 BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje").setScale(2, RoundingMode.HALF_UP);//含税现返使用金额 String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id Integer hfid = null; Integer xfid = null; if (StringUtils.isNotBlank(tqq9_hfid)) { hfid = Integer.valueOf(tqq9_hfid); } if (StringUtils.isNotBlank(tqq9_xfid)) { xfid = Integer.valueOf(tqq9_xfid); } if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) { DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率 BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额 HashMap queryMap = new HashMap<>(); queryMap.put("id", 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.getOperationResult().setMessage("采购订单:" + 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) { DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率 BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额 // HashMap bodyMap = new HashMap<>(); HashMap queryMap = new HashMap<>(); queryMap.put("id", 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.getOperationResult().setMessage("采购订单:" + 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 { for (DynamicObject dataEntity : e.getDataEntities()) { DynamicObject org = dataEntity.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; DynamicObject supplier = dataEntity.getDynamicObject("supplier");//供应商 String billno = dataEntity.getString("billno"); BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje").setScale(2, RoundingMode.HALF_UP);//含税货返使用金额 BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje").setScale(2, RoundingMode.HALF_UP);//含税现返使用金额 String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id Integer hfid = null; Integer xfid = null; if (StringUtils.isNotBlank(tqq9_hfid)) { hfid = Integer.valueOf(tqq9_hfid); } if (StringUtils.isNotBlank(tqq9_xfid)) { xfid = Integer.valueOf(tqq9_xfid); } //货返删除 if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) { String billno1 = dataEntity.getString("billno"); DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率 BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额 HashMap queryMap = new HashMap<>(); queryMap.put("id", 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.getOperationResult().setMessage("采购订单:" + 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+",请求返利系统失败"); } DynamicObject pm_purorderbill = BusinessDataServiceHelper.loadSingle("pm_purorderbill", new QFilter[]{new QFilter("billno", QCP.equals, billno1)}); tqq9_hshfsyje = pm_purorderbill.getBigDecimal("tqq9_hshfsyje").setScale(2, RoundingMode.HALF_UP);//含税货返使用金额 tqq9_hshfsysl = pm_purorderbill.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率 taxrate = tqq9_hshfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额 if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) { notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额 JSONObject bodyMap = new JSONObject(); bodyMap.put("supplierId", supplier.getString("tqq9_ztsupplierid")); bodyMap.put("companyId", orgid_fl); bodyMap.put("type", 0); bodyMap.put("money", tqq9_hshfsyje); bodyMap.put("taxAmount", taxamount); try { String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Object data = map.getInteger("data"); if (data != null) { pm_purorderbill.set("tqq9_hfid", data.toString()); lcLogService.savelog("FL-锁定返利金额", Create_URL, true, true, bodyMap.toString(), bodyString); } else { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), bodyString); this.getOperationResult().setMessage("采购订单:" + billno + ",占用原返利金额失败"); } } catch (IOException ex) { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } pm_purorderbill.set("tqq9_hshfsyje_old", tqq9_hshfsyje);//含税货返使用金额(旧) SaveServiceHelper.save(new DynamicObject[]{pm_purorderbill}); } } //现返删除 if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) { String billno1 = dataEntity.getString("billno"); DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率 BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额 HashMap queryMap = new HashMap<>(); queryMap.put("id", 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.getOperationResult().setMessage("采购订单:" + 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+",请求返利系统失败"); } DynamicObject pm_purorderbill = BusinessDataServiceHelper.loadSingle("pm_purorderbill", new QFilter[]{new QFilter("billno", QCP.equals, billno1)}); tqq9_hsxfsyje = pm_purorderbill.getBigDecimal("tqq9_hsxfsyje").setScale(2, RoundingMode.HALF_UP);//含税现返使用金额 tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率 taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate").setScale(2, RoundingMode.HALF_UP); notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额 if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) { notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额 JSONObject bodyMap = new JSONObject(); bodyMap.put("supplierId", supplier.getString("tqq9_ztsupplierid")); bodyMap.put("companyId", orgid_fl); bodyMap.put("type", 0); bodyMap.put("money", tqq9_hsxfsyje); bodyMap.put("taxAmount", taxamount); try { String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Object data = map.getInteger("data"); if (data != null) { pm_purorderbill.set("tqq9_xfid", data.toString()); lcLogService.savelog("FL-锁定返利金额", Create_URL, true, true, bodyMap.toString(), bodyString); } else { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), bodyString); this.getOperationResult().setMessage("采购订单:" + billno + ",占用原返利金额失败"); } } catch (IOException ex) { lcLogService.savelog("FL-锁定返利金额", Create_URL, true, false, bodyMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } pm_purorderbill.set("tqq9_hsxfsyje_old", tqq9_hsxfsyje);//含税货返使用金额(旧) SaveServiceHelper.save(new DynamicObject[]{pm_purorderbill}); } } } } } else if (StringUtils.equals("audit", operationKey) && StringUtils.equals("pm_purorderbill", entitytype)) { //货返审核 for (DynamicObject dataEntity : e.getDataEntities()) { String billno = dataEntity.getString("billno"); if (!StringUtils.equals("pm_purorderbill", entitytype)) { billno = dataEntity.getString("changebillno"); } BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje").setScale(2, RoundingMode.HALF_UP);//含税货返使用金额 BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje").setScale(2, RoundingMode.HALF_UP);//含税现返使用金额 BigDecimal tqq9_payamount = dataEntity.getBigDecimal("tqq9_payamount").setScale(2, RoundingMode.HALF_UP);//折扣后返利后价税合计 String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id Integer hfid = null; Integer xfid = null; if (StringUtils.isNotBlank(tqq9_hfid)) { hfid = Integer.valueOf(tqq9_hfid); } if (StringUtils.isNotBlank(tqq9_xfid)) { xfid = Integer.valueOf(tqq9_xfid); } 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").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额 HashMap bodyMap = new HashMap<>(); bodyMap.put("id", hfid); bodyMap.put("lockMoney", tqq9_hshfsyje); bodyMap.put("lockTaxAmount", taxamount); Gson gson = new Gson(); try { String bodyString = HttpRequestUtils.doGet(Use_URL, bodyMap, tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Boolean data = map.getBoolean("data"); if (data == null || !data) { lcLogService.savelog("FL-使用返利金额", Use_URL, false, false, bodyMap.toString(), bodyString); this.getOperationResult().setMessage("采购订单:" + billno + ",扣除订单金额失败"); } else { dataEntity.set("tqq9_isrebatecalculate", true); lcLogService.savelog("FL-使用返利金额", Use_URL, false, true, bodyMap.toString(), bodyString); SaveServiceHelper.save(new DynamicObject[]{dataEntity}); } } catch (IOException ex) { lcLogService.savelog("FL-使用返利金额", Use_URL, false, false, bodyMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } } //现返审核 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").setScale(2, RoundingMode.HALF_UP); BigDecimal notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(taxrate), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP); BigDecimal taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额 HashMap bodyMap = new HashMap<>(); // JSONObject bodyMap = new JSONObject(); bodyMap.put("id", xfid); bodyMap.put("lockMoney", tqq9_hsxfsyje); bodyMap.put("lockTaxAmount", taxamount); Gson gson = new Gson(); try { String bodyString = HttpRequestUtils.doGet(Use_URL, bodyMap, tokenMap); JSONObject map = gson.fromJson(bodyString, JSONObject.class); Boolean data = map.getBoolean("data"); if (data == null || !data) { lcLogService.savelog("FL-使用返利金额", Use_URL, false, false, bodyMap.toString(), bodyString); this.getOperationResult().setMessage("采购订单:" + billno + ",扣除订单金额失败"); } else { dataEntity.set("tqq9_isrebatecalculate", true); lcLogService.savelog("FL-使用返利金额", Use_URL, false, true, bodyMap.toString(), bodyString); SaveServiceHelper.save(new DynamicObject[]{dataEntity}); } } catch (IOException ex) { lcLogService.savelog("FL-使用返利金额", Use_URL, false, false, bodyMap.toString(), "接口调用报错,errormessage:" + ex.getMessage()); throw new RuntimeException(ex+",请求返利系统失败"); } } } } } }