308 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			308 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			Java
		
	
	
	
package tqq9.lc123.cloud.app.plugin.operate.pm;
 | 
						|
 | 
						|
import com.google.gson.Gson;
 | 
						|
import kd.bos.dataentity.entity.DynamicObject;
 | 
						|
import kd.bos.dataentity.metadata.IDataEntityProperty;
 | 
						|
import kd.bos.dataentity.utils.StringUtils;
 | 
						|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 | 
						|
import kd.bos.entity.plugin.args.AfterOperationArgs;
 | 
						|
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.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 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;
 | 
						|
 | 
						|
    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;
 | 
						|
    }
 | 
						|
 | 
						|
    @Override
 | 
						|
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
 | 
						|
        super.afterExecuteOperationTransaction(e);
 | 
						|
        String operationKey = e.getOperationKey();
 | 
						|
        if (StringUtils.equals("save", operationKey)) {
 | 
						|
            for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
                String billno = dataEntity.getString("billno");
 | 
						|
                DynamicObject supplier = dataEntity.getDynamicObject("supplier");//供应商
 | 
						|
                DynamicObject org = dataEntity.getDynamicObject("org");//组织
 | 
						|
                BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
 | 
						|
                BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
 | 
						|
                String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
 | 
						|
                String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
 | 
						|
                //货返锁定
 | 
						|
                if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_hfid == null) {
 | 
						|
                    DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
 | 
						|
                    BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
 | 
						|
                    BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    bodyMap.put("supplierId", supplier.getString("number"));
 | 
						|
                    bodyMap.put("companyId", org.getString("number"));
 | 
						|
                    bodyMap.put("type", 0);
 | 
						|
                    bodyMap.put("money", tqq9_hshfsyje);
 | 
						|
                    bodyMap.put("taxAmount", taxamount);
 | 
						|
                    Gson gson = new Gson();
 | 
						|
                    try {
 | 
						|
                        String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap);
 | 
						|
                        HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                        String data = map.get("data").toString();
 | 
						|
                        if (data != null) {
 | 
						|
                            dataEntity.set("tqq9_hfid", data);
 | 
						|
                            SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                        } else {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                    //现返锁定
 | 
						|
                } else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_xfid == null) {
 | 
						|
                    DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
 | 
						|
                    BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
 | 
						|
                    BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    bodyMap.put("supplierId", supplier.getString("number"));
 | 
						|
                    bodyMap.put("companyId", org.getString("number"));
 | 
						|
                    bodyMap.put("type", 1);
 | 
						|
                    bodyMap.put("money", tqq9_hsxfsyje);
 | 
						|
                    bodyMap.put("taxAmount", taxamount);
 | 
						|
                    Gson gson = new Gson();
 | 
						|
                    try {
 | 
						|
                        String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap);
 | 
						|
                        HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                        String data = map.get("data").toString();
 | 
						|
                        if (data != null) {
 | 
						|
                            dataEntity.set("tqq9_xfid", data);
 | 
						|
                            SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                        } else {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                    //货返修改
 | 
						|
                } else if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_hfid != null) {
 | 
						|
                    List<IDataEntityProperty> iDataEntityProperties = dataEntity.getDataEntityState().GetDirtyProperties();
 | 
						|
                    if (iDataEntityProperties.contains("tqq9_hshfsysl")) {
 | 
						|
                        DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
 | 
						|
                        BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
 | 
						|
                        BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                        HashMap<String, Object> queryMap = new HashMap<>();
 | 
						|
                        queryMap.put("id", tqq9_xfid);
 | 
						|
                        queryMap.put("money", tqq9_hshfsyje);
 | 
						|
                        queryMap.put("taxAmount", taxamount);
 | 
						|
                        Gson gson = new Gson();
 | 
						|
                        try {
 | 
						|
                            String bodyString = HttpRequestUtils.doGet(Create_URL, queryMap, tokenMap);
 | 
						|
                            HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                            Boolean data = (Boolean) map.get("data");
 | 
						|
                            if (!data) {
 | 
						|
                                this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
                            }
 | 
						|
                        } catch (IOException ex) {
 | 
						|
                            throw new RuntimeException(ex);
 | 
						|
                        }
 | 
						|
                        HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                        bodyMap.put("supplierId", supplier.getString("number"));
 | 
						|
                        bodyMap.put("companyId", org.getString("number"));
 | 
						|
                        bodyMap.put("type", 0);
 | 
						|
                        bodyMap.put("money", tqq9_hshfsyje);
 | 
						|
                        bodyMap.put("taxAmount", taxamount);
 | 
						|
                        try {
 | 
						|
                            String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap);
 | 
						|
                            HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                            String data = map.get("data").toString();
 | 
						|
                            if (data != null) {
 | 
						|
                                dataEntity.set("tqq9_hfid", data);
 | 
						|
                                SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                            } else {
 | 
						|
                                this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
                            }
 | 
						|
                        } catch (IOException ex) {
 | 
						|
                            throw new RuntimeException(ex);
 | 
						|
                        }
 | 
						|
 | 
						|
                    }
 | 
						|
 | 
						|
                    //现返修改
 | 
						|
                } else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_xfid != null) {
 | 
						|
                    DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
 | 
						|
                    BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
 | 
						|
                    BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                    HashMap<String, Object> queryMap = new HashMap<>();
 | 
						|
                    queryMap.put("id", tqq9_xfid);
 | 
						|
                    queryMap.put("money", tqq9_hsxfsyje);
 | 
						|
                    queryMap.put("taxAmount", taxamount);
 | 
						|
                    Gson gson = new Gson();
 | 
						|
                    try {
 | 
						|
                        String bodyString = HttpRequestUtils.doGet(Create_URL, queryMap, tokenMap);
 | 
						|
                        HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                        Boolean data = (Boolean) map.get("data");
 | 
						|
                        if (!data) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    bodyMap.put("supplierId", supplier.getString("number"));
 | 
						|
                    bodyMap.put("companyId", org.getString("number"));
 | 
						|
                    bodyMap.put("type", 1);
 | 
						|
                    bodyMap.put("money", tqq9_hsxfsyje);
 | 
						|
                    bodyMap.put("taxAmount", taxamount);
 | 
						|
                    try {
 | 
						|
                        String bodyString = HttpRequestUtils.postJson(Create_URL, bodyMap.toString(), tokenMap);
 | 
						|
                        HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                        String data = map.get("data").toString();
 | 
						|
                        if (data != null) {
 | 
						|
                            dataEntity.set("tqq9_xfid", data);
 | 
						|
                            SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                        } else {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",保存时占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        } else if (StringUtils.equals("delete", operationKey)) {
 | 
						|
            //货返删除
 | 
						|
            for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
                String billno = dataEntity.getString("billno");
 | 
						|
                BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
 | 
						|
                BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
 | 
						|
                String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
 | 
						|
                String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
 | 
						|
                if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
                    DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
 | 
						|
                    BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
 | 
						|
                    BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    bodyMap.put("id", tqq9_hfid);
 | 
						|
                    bodyMap.put("money", tqq9_hshfsyje);
 | 
						|
                    bodyMap.put("taxAmount", taxamount);
 | 
						|
                    Gson gson = new Gson();
 | 
						|
                    try {
 | 
						|
                        String bodyString = HttpRequestUtils.postJson(Cancel_URL, bodyMap.toString(), tokenMap);
 | 
						|
                        HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                        Boolean data = (Boolean) map.get("data");
 | 
						|
                        if (!data) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                    //现返删除
 | 
						|
                } else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
                    DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
 | 
						|
                    BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
 | 
						|
                    BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    bodyMap.put("id", tqq9_xfid);
 | 
						|
                    bodyMap.put("money", tqq9_hsxfsyje);
 | 
						|
                    bodyMap.put("taxAmount", taxamount);
 | 
						|
                    Gson gson = new Gson();
 | 
						|
                    try {
 | 
						|
                        String bodyString = HttpRequestUtils.postJson(Cancel_URL, bodyMap.toString(), tokenMap);
 | 
						|
                        HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                        Boolean data = (Boolean) map.get("data");
 | 
						|
                        if (!data) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",删除时撤销占用金额失败");
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        } else if (StringUtils.equals("audit", operationKey)) {
 | 
						|
            //货返审核
 | 
						|
            for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
                String billno = dataEntity.getString("billno");
 | 
						|
                BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
 | 
						|
                BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
 | 
						|
                BigDecimal tqq9_payamount = dataEntity.getBigDecimal("tqq9_payamount");//折扣后返利后价税合计
 | 
						|
                String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
 | 
						|
                String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
 | 
						|
                if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) {
 | 
						|
                    DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
 | 
						|
                    BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
 | 
						|
                    BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    bodyMap.put("id", tqq9_hfid);
 | 
						|
                    bodyMap.put("lockMoney", tqq9_hshfsyje);
 | 
						|
                    bodyMap.put("lockTaxAmount", taxamount);
 | 
						|
                    Gson gson = new Gson();
 | 
						|
                    try {
 | 
						|
                        String bodyString = HttpRequestUtils.postJson(Use_URL, bodyMap.toString(), tokenMap);
 | 
						|
                        HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                        Boolean data = (Boolean) map.get("data");
 | 
						|
                        if (!data) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
 | 
						|
                        } else {
 | 
						|
                            dataEntity.set("tqq9_isrebatecalculate", true);
 | 
						|
                            SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                    //现返审核
 | 
						|
                } else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) {
 | 
						|
                    DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
 | 
						|
                    BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
 | 
						|
                    BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                    bodyMap.put("id", tqq9_xfid);
 | 
						|
                    bodyMap.put("lockMoney", tqq9_hsxfsyje);
 | 
						|
                    bodyMap.put("lockTaxAmount", taxamount);
 | 
						|
                    Gson gson = new Gson();
 | 
						|
                    try {
 | 
						|
                        String bodyString = HttpRequestUtils.postJson(Use_URL, bodyMap.toString(), tokenMap);
 | 
						|
                        HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                        Boolean data = (Boolean) map.get("data");
 | 
						|
                        if (!data) {
 | 
						|
                            this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
 | 
						|
                        } else {
 | 
						|
                            dataEntity.set("tqq9_isrebatecalculate", true);
 | 
						|
                            SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                        }
 | 
						|
                    } catch (IOException ex) {
 | 
						|
                        throw new RuntimeException(ex);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |