284 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			284 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			Java
		
	
	
	
package tqq9.lc123.cloud.app.plugin.operate.sys;
 | 
						|
 | 
						|
import com.alibaba.fastjson.JSONObject;
 | 
						|
import com.fasterxml.jackson.databind.ObjectMapper;
 | 
						|
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.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.sdk.plugin.Plugin;
 | 
						|
import tqq9.lc123.cloud.app.plugin.operate.pm.PurOrderBillRebatePlugin;
 | 
						|
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
 | 
						|
 | 
						|
import java.io.IOException;
 | 
						|
import java.math.BigDecimal;
 | 
						|
import java.util.ArrayList;
 | 
						|
import java.util.Date;
 | 
						|
import java.util.HashMap;
 | 
						|
import java.util.List;
 | 
						|
 | 
						|
/**
 | 
						|
 * 返利规则操作插件
 | 
						|
 */
 | 
						|
public class RebateRuleOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
 | 
						|
    private final static Log logger = LogFactory.getLog(PurOrderBillRebatePlugin.class);
 | 
						|
//    private final static HashMap<String, String> tokenMap = new HashMap<String, String>() {{
 | 
						|
//        put("Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3");
 | 
						|
//    }};
 | 
						|
 | 
						|
 | 
						|
    private static String Push_URL;
 | 
						|
    private static String FLXT_TOKEN;
 | 
						|
 | 
						|
 | 
						|
    static {
 | 
						|
        DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
 | 
						|
                new QFilter[]{new QFilter("number", QCP.equals, "FLXT_CreatRule_Url")});
 | 
						|
        Push_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("name");
 | 
						|
        e.getFieldKeys().add("tqq9_rulestype");
 | 
						|
        e.getFieldKeys().add("tqq9_startdate");
 | 
						|
        e.getFieldKeys().add("tqq9_enddate");
 | 
						|
        e.getFieldKeys().add("tqq9_supplier");
 | 
						|
        e.getFieldKeys().add("tqq9_estimatepro");
 | 
						|
        e.getFieldKeys().add("tqq9_targetamount");
 | 
						|
        e.getFieldKeys().add("tqq9_rebatebrand");
 | 
						|
        e.getFieldKeys().add("tqq9_rebategoods");
 | 
						|
        e.getFieldKeys().add("tqq9_rebatesub");
 | 
						|
        e.getFieldKeys().add("tqq9_guangzhoulici");
 | 
						|
        e.getFieldKeys().add("tqq9_shanghailici");
 | 
						|
        e.getFieldKeys().add("tqq9_beijinglichi");
 | 
						|
        e.getFieldKeys().add("tqq9_gzlcbl");
 | 
						|
        e.getFieldKeys().add("tqq9_shlcbl");
 | 
						|
        e.getFieldKeys().add("tqq9_bjlcbl");
 | 
						|
        e.getFieldKeys().add("tqq9_excl_start_base");
 | 
						|
        e.getFieldKeys().add("tqq9_excl_end_base");
 | 
						|
        e.getFieldKeys().add("tqq9_proportion");
 | 
						|
        e.getFieldKeys().add("tqq9_istax");
 | 
						|
        e.getFieldKeys().add("tqq9_rebatesettlespe");
 | 
						|
        e.getFieldKeys().add("tqq9_cal_amt");
 | 
						|
        e.getFieldKeys().add("tqq9_calc_procurement");
 | 
						|
        e.getFieldKeys().add("tqq9_excludnum");
 | 
						|
        e.getFieldKeys().add("tqq9_startexcludate");
 | 
						|
        e.getFieldKeys().add("tqq9_endexcludate");
 | 
						|
        e.getFieldKeys().add("tqq9_exclunopur");
 | 
						|
        e.getFieldKeys().add("tqq9_exclupur");
 | 
						|
        e.getFieldKeys().add("tqq9_purchaseorder");
 | 
						|
        e.getFieldKeys().add("tqq9_rebateamount");
 | 
						|
    }
 | 
						|
 | 
						|
    @Override
 | 
						|
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
 | 
						|
        super.afterExecuteOperationTransaction(e);
 | 
						|
        for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
//                    HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
            HashMap<String, String> tokenMap = new HashMap<String, String>();
 | 
						|
            tokenMap.put("Authorization", FLXT_TOKEN);
 | 
						|
            JSONObject bodyMap = new JSONObject();
 | 
						|
            String name = dataEntity.getString("name");//规则名称
 | 
						|
            String tqq9_rulestype = dataEntity.getString("tqq9_rulestype");//规则类型
 | 
						|
            Integer type = Integer.valueOf(tqq9_rulestype);//规则类型
 | 
						|
            Date tqq9_startdate = dataEntity.getDate("tqq9_startdate");//返利计算开始时间
 | 
						|
            Date tqq9_enddate = dataEntity.getDate("tqq9_enddate");//返利计算结束时间
 | 
						|
            long startTime = tqq9_startdate.getTime();
 | 
						|
            String startTimeString = String.valueOf(startTime);
 | 
						|
            long endTime = tqq9_enddate.getTime();
 | 
						|
            String tqq9_enddateString = String.valueOf(endTime);
 | 
						|
            DynamicObjectCollection tqq9_supplier = dataEntity.getDynamicObjectCollection("tqq9_supplier");//返利供应商
 | 
						|
            StringBuilder supplierIds = new StringBuilder();
 | 
						|
            for (DynamicObject dynamicObject : tqq9_supplier) {
 | 
						|
                supplierIds.append(",").append(dynamicObject.getDynamicObject("fbasedataid").getString("id"));
 | 
						|
            }
 | 
						|
            BigDecimal tqq9_estimatepro = dataEntity.getBigDecimal("tqq9_estimatepro");//预测比例
 | 
						|
            BigDecimal tqq9_targetamount = dataEntity.getBigDecimal("tqq9_targetamount");//预测总金额
 | 
						|
            DynamicObjectCollection tqq9_rebatebrand = dataEntity.getDynamicObjectCollection("tqq9_rebatebrand");//返利品牌
 | 
						|
            StringBuilder rebatebrandIds = new StringBuilder();
 | 
						|
            for (DynamicObject dynamicObject : tqq9_rebatebrand) {
 | 
						|
                rebatebrandIds.append(",").append(dynamicObject.getDynamicObject("fbasedataid").getString("id"));
 | 
						|
            }
 | 
						|
            DynamicObjectCollection tqq9_rebategoods = dataEntity.getDynamicObjectCollection("tqq9_rebategoods");//返利商品
 | 
						|
            StringBuilder rebategoodsIds = new StringBuilder();
 | 
						|
            if (tqq9_rebategoods.size() > 0) {
 | 
						|
                for (DynamicObject dynamicObject : tqq9_rebategoods) {
 | 
						|
                    rebategoodsIds.append(",").append(dynamicObject.getDynamicObject("fbasedataid").getString("number"));
 | 
						|
                }
 | 
						|
            }
 | 
						|
            String tqq9_rebatesub = dataEntity.getString("tqq9_rebatesub");//分配类型
 | 
						|
            Integer distributeType = Integer.valueOf(tqq9_rebatesub);//分配类型
 | 
						|
            List<List<String>> List = new ArrayList<>();
 | 
						|
            ObjectMapper mapper = new ObjectMapper();
 | 
						|
            if (StringUtils.equals("0", tqq9_rebatesub)) {
 | 
						|
                if (dataEntity.getBoolean("tqq9_guangzhoulici")) {
 | 
						|
                    List<String> gzList = new ArrayList<>();
 | 
						|
                    gzList.add("GZ_LC");
 | 
						|
                    List.add(gzList);
 | 
						|
                }
 | 
						|
                if (dataEntity.getBoolean("tqq9_shanghailici")) {
 | 
						|
                    List<String> shList = new ArrayList<>();
 | 
						|
                    shList.add("SH_LC");
 | 
						|
                    List.add(shList);
 | 
						|
                }
 | 
						|
                if (dataEntity.getBoolean("tqq9_beijinglichi")) {
 | 
						|
                    List<String> bjList = new ArrayList<>();
 | 
						|
                    bjList.add("BJ_LC");
 | 
						|
                    List.add(bjList);
 | 
						|
                }
 | 
						|
            } else {
 | 
						|
                BigDecimal tqq9_gzlcbl = dataEntity.getBigDecimal("tqq9_gzlcbl");
 | 
						|
                BigDecimal tqq9_shlcbl = dataEntity.getBigDecimal("tqq9_shlcbl");
 | 
						|
                BigDecimal tqq9_bjlcbl = dataEntity.getBigDecimal("tqq9_bjlcbl");
 | 
						|
                if (tqq9_gzlcbl.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
                    List<String> gzList = new ArrayList<>();
 | 
						|
                    gzList.add("GZ_LC");
 | 
						|
                    gzList.add(tqq9_gzlcbl.toString());
 | 
						|
                    List.add(gzList);
 | 
						|
                }
 | 
						|
                if (tqq9_shlcbl.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
                    List<String> shList = new ArrayList<>();
 | 
						|
                    shList.add("SH_LC");
 | 
						|
                    shList.add(tqq9_shlcbl.toString());
 | 
						|
                    List.add(shList);
 | 
						|
                }
 | 
						|
                if (tqq9_bjlcbl.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
                    List<String> bjList = new ArrayList<>();
 | 
						|
                    bjList.add("GZ_LC");
 | 
						|
                    bjList.add(tqq9_bjlcbl.toString());
 | 
						|
                    List.add(bjList);
 | 
						|
                }
 | 
						|
            }
 | 
						|
            String distributeCity = List.toString();
 | 
						|
            List<List<String>> calculationProportionList = new ArrayList<>();
 | 
						|
            BigDecimal tqq9_excl_start_base = dataEntity.getBigDecimal("tqq9_excl_start_base");
 | 
						|
            BigDecimal tqq9_excl_end_base = dataEntity.getBigDecimal("tqq9_excl_end_base");
 | 
						|
            BigDecimal tqq9_proportion = dataEntity.getBigDecimal("tqq9_proportion");
 | 
						|
            if (tqq9_excl_start_base.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
                List<String> startList = new ArrayList<>();
 | 
						|
                startList.add(tqq9_excl_start_base.toString());
 | 
						|
                calculationProportionList.add(startList);
 | 
						|
            }
 | 
						|
            if (tqq9_proportion.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
                List<String> proportionList = new ArrayList<>();
 | 
						|
                proportionList.add(tqq9_proportion.toString());
 | 
						|
                calculationProportionList.add(proportionList);
 | 
						|
            }
 | 
						|
            if (tqq9_excl_end_base.compareTo(BigDecimal.ZERO) > 0) {
 | 
						|
                List<String> endList = new ArrayList<>();
 | 
						|
                endList.add(tqq9_excl_end_base.toString());
 | 
						|
                calculationProportionList.add(endList);
 | 
						|
            }
 | 
						|
            String calculationProportion = calculationProportionList.toString();
 | 
						|
            Integer isTax = 1;
 | 
						|
            Boolean tqq9_istax = dataEntity.getBoolean("tqq9_istax");//是否含税
 | 
						|
            if (tqq9_istax) {
 | 
						|
                isTax = 0;//是否含税
 | 
						|
            }
 | 
						|
 | 
						|
            String tqq9_rebatesettlespe = dataEntity.getString("tqq9_rebatesettlespe");//返利结算特例
 | 
						|
            Integer isSpecial = Integer.valueOf(tqq9_rebatesettlespe);//返利结算特例
 | 
						|
 | 
						|
            bodyMap.put("ruleName", name);
 | 
						|
            bodyMap.put("type", type);
 | 
						|
            bodyMap.put("startTime", startTimeString);
 | 
						|
            bodyMap.put("endTime", tqq9_enddateString);
 | 
						|
            bodyMap.put("supplierIds", (supplierIds.length() == 0) ? null : supplierIds.substring(1));
 | 
						|
            bodyMap.put("predictedProportion", tqq9_estimatepro);
 | 
						|
            bodyMap.put("predictedAggregateMoney", tqq9_targetamount);
 | 
						|
            bodyMap.put("brandIds", (rebatebrandIds.length() == 0) ? null : rebatebrandIds.substring(1));
 | 
						|
            bodyMap.put("productIds", (rebategoodsIds.length() == 0) ? null : rebategoodsIds.substring(1));
 | 
						|
            bodyMap.put("distributeType", distributeType);
 | 
						|
            bodyMap.put("distributeCity", distributeCity);
 | 
						|
            bodyMap.put("isTax", isTax);
 | 
						|
            bodyMap.put("isSpecial", isSpecial);
 | 
						|
 | 
						|
            if (StringUtils.equals("0", tqq9_rulestype)) {
 | 
						|
                String tqq9_cal_amt = dataEntity.getString("tqq9_cal_amt");//计算金额指标
 | 
						|
                Integer calculationMoneyType = Integer.valueOf(tqq9_cal_amt);//计算金额指标
 | 
						|
 | 
						|
                String tqq9_calc_procurement = dataEntity.getString("tqq9_calc_procurement");//计算采购指标
 | 
						|
                Integer calculationPurchaseType = Integer.valueOf(tqq9_calc_procurement);//计算采购指标
 | 
						|
 | 
						|
                String tqq9_excludnum = dataEntity.getString("tqq9_excludnum");//排除后基数
 | 
						|
                Integer isInclude = Integer.valueOf(tqq9_excludnum);//计算采购指标
 | 
						|
                Date tqq9_startexcludate = dataEntity.getDate("tqq9_startexcludate");//排除返利计算开始时间
 | 
						|
                String noStartTime = null;
 | 
						|
                String noEndTime = null;
 | 
						|
                if (tqq9_startexcludate != null) {
 | 
						|
                    noStartTime = String.valueOf(tqq9_startexcludate.getTime());
 | 
						|
                }
 | 
						|
                Date tqq9_endexcludate = dataEntity.getDate("tqq9_endexcludate");//排除返利计算结束时间
 | 
						|
                if (tqq9_endexcludate != null) {
 | 
						|
                    noEndTime = String.valueOf(tqq9_endexcludate.getTime());
 | 
						|
                }
 | 
						|
                Integer noStatus = 0;
 | 
						|
                if (tqq9_startexcludate != null && tqq9_endexcludate != null) {
 | 
						|
                    noStatus = 1;
 | 
						|
                }
 | 
						|
                DynamicObjectCollection tqq9_exclunopur = dataEntity.getDynamicObjectCollection("tqq9_exclunopur");//排除时间不排除订单
 | 
						|
                StringBuilder exclunopurIds = new StringBuilder();
 | 
						|
                if (tqq9_exclunopur.size() > 0) {
 | 
						|
                    for (DynamicObject dynamicObject : tqq9_exclunopur) {
 | 
						|
                        exclunopurIds.append(",").append(dynamicObject.getDynamicObject("fbasedataid").getString("billno"));
 | 
						|
                    }
 | 
						|
                }
 | 
						|
 | 
						|
                DynamicObjectCollection tqq9_exclupur = dataEntity.getDynamicObjectCollection( "tqq9_exclupur");//排除采购订单
 | 
						|
                StringBuilder exclupurIds = new StringBuilder();
 | 
						|
                if (tqq9_exclupur.size() > 0) {
 | 
						|
                    for (DynamicObject dynamicObject : tqq9_exclunopur) {
 | 
						|
                        exclupurIds.append(",").append(dynamicObject.getDynamicObject("fbasedataid").getString("billno"));
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                bodyMap.put("noOrderIds", (exclupurIds.length() == 0) ? null : exclupurIds.substring(1));
 | 
						|
                bodyMap.put("calculationMoneyType", calculationMoneyType);
 | 
						|
                bodyMap.put("calculationPurchaseType", calculationPurchaseType);
 | 
						|
                bodyMap.put("calculationProportion", calculationProportion);
 | 
						|
                bodyMap.put("isInclude", isInclude);
 | 
						|
                bodyMap.put("noStartTime", noStartTime);
 | 
						|
                bodyMap.put("noEndTime", noEndTime);
 | 
						|
                bodyMap.put("noTimeOrderIds", (exclunopurIds.length() == 0) ? null : exclunopurIds.substring(1));
 | 
						|
                bodyMap.put("noStatus", noStatus);
 | 
						|
            } else {
 | 
						|
                DynamicObjectCollection tqq9_purchaseorder = dataEntity.getDynamicObjectCollection("tqq9_purchaseorder");//特殊订单
 | 
						|
                StringBuilder purchaseorderIds = new StringBuilder();
 | 
						|
                if (tqq9_purchaseorder.size() > 0) {
 | 
						|
                    for (DynamicObject dynamicObject : tqq9_purchaseorder) {
 | 
						|
                        purchaseorderIds.append(",").append(dynamicObject.getDynamicObject("fbasedataid").getString("billno"));
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                BigDecimal tqq9_rebateamount = dataEntity.getBigDecimal("tqq9_rebateamount");//返利金额
 | 
						|
                bodyMap.put("orderIds", (purchaseorderIds.length() == 0) ? null : purchaseorderIds.substring(1));
 | 
						|
                bodyMap.put("returnMoney", tqq9_rebateamount);
 | 
						|
            }
 | 
						|
 | 
						|
 | 
						|
            Gson gson = new Gson();
 | 
						|
            try {
 | 
						|
                String bodyString = HttpRequestUtils.postJson(Push_URL, bodyMap.toString(), tokenMap);
 | 
						|
                JSONObject map = gson.fromJson(bodyString, JSONObject.class);
 | 
						|
                Integer data = map.getInteger("data");
 | 
						|
                if (data == null) {
 | 
						|
                    this.getOperationResult().setMessage("返利规则:" + name + ",审核时创建返利规则失败");
 | 
						|
                }
 | 
						|
            } catch (IOException ex) {
 | 
						|
                throw new RuntimeException(ex);
 | 
						|
            }
 | 
						|
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |