码迷,mamicode.com
首页 > 其他好文 > 详细

groupedit

时间:2019-12-26 13:24:49      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:ogr   err   retain   help   his   筛选   count   mod   geo   

/**
* @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

标签:ogr   err   retain   help   his   筛选   count   mod   geo   

原文地址:https://www.cnblogs.com/armyja/p/12101352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!