groupedit

Posted armyja

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了groupedit相关的知识,希望对你有一定的参考价值。

/**
* @author 王家辉
* @date 2019-12-26
*/
var plugin = new FormPlugin({
    TYPE: "type",
    CUSTOMER: "bdcustomer",
    PRODUCT: "product_name",
    GROUP: "group",
    STATE: "sr_state",
    KEY_FILTERGRID: "filtergridap",
    beforeBindData: function (e) {
        var group = this.getControl(this.GROUP);
        var qFilter = new QFilter("id", "is null", null);
        group.setQFilter(qFilter);
    },
    propertyChanged: function (e) {
        var key = e.getProperty().getName();

        if (TYPE == key || CUSTOMER == key || PRODUCT == key || STATE == key || GROUP == key) {
            this.onPropertyChanged();
        }
    },

    onPropertyChanged: function (e) {
        var types = this.getModel().getValue(this.TYPE);
        var customers = this.getModel().getValue(this.CUSTOMER);
        var products = this.getModel().getValue(this.PRODUCT);
        var states = this.getModel().getValue(this.STATE);

        var typesParams = 0;
        var customersParams = 0;
        var productsParams = 0;
        var statesParams = 0;

        if (types != null) {
            typesParams = types.getLong("id");
        }
        if (customers != null) {
            customersParams = customers.getLong("country.id");
        }
        if (products != null) {
            productsParams = products.getLong("id");
        }
        if (states != null) {
            statesParams = states.getLong("id");
        }

        // 取出群组中拥有的职责
        var rangeOfState = this.getStatesResult(statesParams);
        // 根据问题单类型、客户、产品筛选出对应的职责
        var userRangeResult = this.getUserRangeResult(typesParams, customersParams, productsParams)
        // 职责取交集
        if (rangeOfState != null && rangeOfState.length > 0) {
            userRangeResult = this.retain(rangeResult, userRangeResult);
        }


        var groupBD = this.getControl(this.GROUP)
        groupBD.setQFilter([new QFilter("range", "in", userRangeResult)])

        // 取职责对应的群组和群组里所有工程师
        // 设置群组的过滤条件
        // DynamicObject[]
        var groups = BusinessDataServiceHelper.load("hwsup_bd_group", "entryentity.engineer", [new QFilter("range", "in", userRangeResult)])

        // 设置责任人的过滤条件
        var allEngineers = [];
        for (var i = 0; i < groups.length; i++) {
            var group = groups[i]
            var lines = group.get("entryentity")

            for (var j = 0; j < lines.size(); j++) {
                allEngineers.push(lines.get(i).get("engineer").getPkValue())
            }
        }
        var ownerBD = this.getControl("owner")
        ownerBD.setQFilter("id", "in", allEngineers)

        // 随机群组和责任人
        // TODO 群组优先级,优先取CCR,让CCR处理
        var allGroups = [];
        for (var i = 0; i < groups.length; i++) {
            allGroups.push(groups.get(i).getPkValue())
        }

        var groupIndex = parseInt(Math.random() * allGroups.length);
        this.getModel().setValue(this.GROUP, allGroups[i])

        var linesInRandomGroup = groups.get(groupIndex).get("entryentity")
        var lineIndex = parseInt(Math.random() * linesInRandomGroup.size());
        this.getModel().setValue("owner", linesInRandomGroup.get(lineIndex).get("engineer").getPkValue())


    },

    retain: function (arr1, arr2) {
        return arr1.filter(function (v) {
            return arr2.indexOf(v) != -1
        })
    },

    getRangesOfState: function (statesParams) {
        if (statesParams == 0) {
            var state = BusinessDataServiceHelper.loadSingle(Constants.HWSUP_BD_SR_STATUS, "", [new QFilter("number", "=", "progressing_l1")]);
            statesParams = state.getPkValue()
        }
        var ranges = BusinessDataServiceHelper.load("hwsup_bd_range", "name,entryentity.srstatus", [new QFilter("entryentity.srstatus", "=", statesParams)]);
        var result = []
        for (var i = 0; i < ranges.length; i++) {
            result.push(ranges[i].getPkValue())
        }

        return result
    },

    getUserRangeResult: function (typesParams, customersParams, productsParams) {
        var groups = BusinessDataServiceHelper.load("hwsup_bd_group", "name,entryentity_group.userrange,range", [new QFilter("entryentity_group.type", "=", typesParams), new QFilter("entryentity_group.country", "=", customersParams), new QFilter("entryentity_group.product", "=", productsParams)]);

        var result = []
        for (var i = 0; i < groups.length; i++) {
            var range = groups[i].get("range")
            result.push(range.getPkValue())
        }

        return result
    }
});

以上是关于groupedit的主要内容,如果未能解决你的问题,请参考以下文章

emc存储划分空间

微信小程序代码片段

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板