552 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			552 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			Java
		
	
	
	
package tqq9.lc123.cloud.app.plugin.operate.pm;
 | 
						|
 | 
						|
import com.alibaba.fastjson.JSONObject;
 | 
						|
import com.google.gson.Gson;
 | 
						|
import kd.bos.dataentity.entity.DynamicObject;
 | 
						|
import kd.bos.dataentity.utils.StringUtils;
 | 
						|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 | 
						|
import kd.bos.entity.plugin.PreparePropertysEventArgs;
 | 
						|
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.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.math.RoundingMode;
 | 
						|
import java.util.HashMap;
 | 
						|
 | 
						|
/**
 | 
						|
 * 采购订单操作插件
 | 
						|
 */
 | 
						|
public class PurOrderBillRebatePlugin extends AbstractOperationServicePlugIn implements Plugin {
 | 
						|
 | 
						|
    private final static Log logger = LogFactory.getLog(PurOrderBillRebatePlugin.class);
 | 
						|
    private final static String ENTRYENTITY = "billentry";
 | 
						|
 | 
						|
//    private final static HashMap<String, String> tokenMap = new HashMap<String, String>() {{
 | 
						|
//        put("Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3");
 | 
						|
//    }};
 | 
						|
 | 
						|
    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 afterExecuteOperationTransaction(AfterOperationArgs e) {
 | 
						|
        super.afterExecuteOperationTransaction(e);
 | 
						|
        String operationKey = e.getOperationKey();
 | 
						|
        HashMap<String, String> tokenMap = new HashMap<String, String>();
 | 
						|
        tokenMap.put("Authorization", FLXT_TOKEN);
 | 
						|
        BigDecimal oneHundred = new BigDecimal(100);
 | 
						|
        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");//组织
 | 
						|
                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);//税额
 | 
						|
//                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    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());
 | 
						|
                        } else {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        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);//税额
 | 
						|
//                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    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());
 | 
						|
                        } else {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        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<String, Object> 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) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        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);//税额
 | 
						|
//                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                        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());
 | 
						|
                            } else {
 | 
						|
                                this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
                            }
 | 
						|
                        } catch (IOException ex) {
 | 
						|
                            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<String, Object> 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) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                    if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
//                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                         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());
 | 
						|
                            } else {
 | 
						|
                                this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
                            }
 | 
						|
                        } catch (IOException ex) {
 | 
						|
                            throw new RuntimeException(ex);
 | 
						|
                        }
 | 
						|
                        dataEntity.set("tqq9_hsxfsyje_old", tqq9_hsxfsyje);//含税现返使用金额(旧)
 | 
						|
                        SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
//        else if (StringUtils.equals("submit", 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").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);//含税现返使用金额(旧)
 | 
						|
//                //货返锁定
 | 
						|
//                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_hshfsyjesubtract(notaxamount);//税额
 | 
						|
//                    //                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
//                    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());
 | 
						|
//                        } else {
 | 
						|
//                            this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
//                        }
 | 
						|
//                    } catch (IOException ex) {
 | 
						|
//                        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);//税额
 | 
						|
////                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
//                    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());
 | 
						|
//                        } else {
 | 
						|
//                            this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
//                        }
 | 
						|
//                    } catch (IOException ex) {
 | 
						|
//                        throw new RuntimeException(ex);
 | 
						|
//                    }
 | 
						|
//                    dataEntity.set("tqq9_hsxfsyje_old", tqq9_hsxfsyje);//含税现返使用金额(旧)
 | 
						|
//                    SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
//                }
 | 
						|
//            }
 | 
						|
//
 | 
						|
//        } else if (StringUtils.equals("unsubmit", operationKey)) {
 | 
						|
//            //货返删除
 | 
						|
//            for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
//                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 (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<String, Object> bodyMap = new HashMap<>();
 | 
						|
//                    JSONObject bodyMap = new JSONObject();
 | 
						|
//                    bodyMap.put("id", hfid);
 | 
						|
//                    bodyMap.put("money", tqq9_hshfsyje);
 | 
						|
//                    bodyMap.put("taxAmount", taxamount);
 | 
						|
//                    Gson gson = new Gson();
 | 
						|
//                    try {
 | 
						|
//                        String bodyString = HttpRequestUtils.postJson(Cancel_URL, bodyMap.toString(), tokenMap);
 | 
						|
//        JSONObject map = gson.fromJson(bodyString, JSONObject.class);
 | 
						|
//                        Boolean data =  map.getBoolean("data");
 | 
						|
//                        if (data==null||!data)) {
 | 
						|
//                            this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
//                        }
 | 
						|
//                    } catch (IOException ex) {
 | 
						|
//                        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<String, Object> bodyMap = new HashMap<>();
 | 
						|
//                    JSONObject bodyMap = new JSONObject();
 | 
						|
//                    bodyMap.put("id", xfid);
 | 
						|
//                    bodyMap.put("money", tqq9_hsxfsyje);
 | 
						|
//                    bodyMap.put("taxAmount", taxamount);
 | 
						|
//                    Gson gson = new Gson();
 | 
						|
//                    try {
 | 
						|
//                        String bodyString = HttpRequestUtils.postJson(Cancel_URL, bodyMap.toString(), tokenMap);
 | 
						|
//        JSONObject map = gson.fromJson(bodyString, JSONObject.class);
 | 
						|
//                        Boolean data =  map.getBoolean("data");
 | 
						|
//                        if (data==null||!data)) {
 | 
						|
//                            this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
//                        }
 | 
						|
//                    } catch (IOException ex) {
 | 
						|
//                        throw new RuntimeException(ex);
 | 
						|
//                    }
 | 
						|
//                }
 | 
						|
//            }
 | 
						|
//        }
 | 
						|
        if (StringUtils.equals("delete", operationKey)) {
 | 
						|
            //货返删除
 | 
						|
            for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
                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) {
 | 
						|
                    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<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    HashMap<String, Object> 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) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        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<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    HashMap<String, Object> 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) {
 | 
						|
                            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").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<String, Object> bodyMap = new HashMap<>();
 | 
						|
//                    JSONObject bodyMap = new JSONObject();
 | 
						|
                    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) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
 | 
						|
                        } else {
 | 
						|
                            dataEntity.set("tqq9_isrebatecalculate", true);
 | 
						|
                            SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        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<String, Object> 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) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
 | 
						|
                        } else {
 | 
						|
                            dataEntity.set("tqq9_isrebatecalculate", true);
 | 
						|
                            SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |