#实践案例#苍穹树形列表的分类与过滤的实践原创
金蝶云社区-城主
城主
1人赞赏了该文章 1,100次浏览 未经作者许可,禁止转载编辑于2023年02月07日 16:39:52

一、业务背景


苍穹原生的树形列表没有自带分类及按照分类过滤的功能,在我们客户的实际使用场景中,却很多地方会用到下面这种树形列表的分类及根据分类对象进行过滤。例如客户下面的诊断列表模板(树形列表)要实现按个人,科室,院区来分类过滤。我们只能在继承标准列表模板的基础上,通过插件开发的方式实现我们客户的需求。


二、解决方案


继承标准树形列表,然后扩展,通过列表插件完成分类及过滤的功能,然后在业务单据列表中使用。


三、关键步骤


1、创建继承标准树列表的列表表单模板,用来给具体业务单据的列表使用


image.png


2、在创建的模板(标准树列表_诊断模板)中添加个人、科室、院区页签,科室和院区页签下添加相应基础资料供用户选择,如下图。


image.png

注意:此处三个页签的标识设置为--个人(kdy_tab_1)--科室(kdy_tab_2)–全院(kdy_tab_3)是为了插件中方便做通用功能。


3、使用的业务单据列表(诊断模板(树))中设置列表表单模板为标准树列表_ 诊断模板的标识,如下图


image.png


4、业务单据列表(诊断模板(树))在大纲中找到基础资料模板列表,在其帮助文本中填写json格式值,如下图


image.png


image.png

上图红色圈出的内容中填写的是:{"1":"kdy_userid","2":"kdy_deptid","3":"kdy_branchid"},1、2、3是key,

kdy_userid、kdy_deptid、kdy_branchid分别是三个key对应的值,并且是诊断模板(树)表单三个字段(适用人员、使用科室、使用院区)的标识。

注意:这里帮助文本的内容设置是为了插件中使用。


5、列表插件关键代码


public class BaseTplDiagListPlugin extends AbstractTreeListPlugin implements TabSelectListener {

    //页签 - 控件标识
    private static final String KDY_TAB = "kdy_tabap";

    //页签控件 - 个人
    private static final String KDY_TAB_PERSONAL = "kdy_tab_1";

    //页签控件 - 科室
    private static final String KDY_TAB_DEPT = "kdy_tab_2";

    //页签控件 - 全院
    private static final String KDY_TAB_HOSPITAL = "kdy_tab_3";

    //基础资料 - 院区选择标识
    private static final String KDY_HOSPITAL_AREA = "kdy_hospital_area";

    //基础资料 - 科室选择标识
    private static final String KDY_DEPT = "kdy_dept";

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);

        // 页签添加监听事件
        Tab tab = this.getView().getControl(KDY_TAB);
        tab.addTabSelectListener(this);
    }


    @Override
    public void tabSelected(TabSelectEvent tabSelectEvent) {
        switch (tabSelectEvent.getTabKey()) {
            //个人
            case KDY_TAB_PERSONAL:
                getView().invokeOperation("refresh");
                break;
            //科室
            case KDY_TAB_DEPT:
                getView().invokeOperation("refresh");
                break;
            //全院
            case KDY_TAB_HOSPITAL:
                getView().invokeOperation("refresh");
                break;
            default:
                break;
        }
    }

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        super.propertyChanged(e);

        String propertyName = e.getProperty().getName();

        //科室变更
        if (KDY_DEPT.equalsIgnoreCase(propertyName)) {
            getView().invokeOperation("refresh");
        }

        //院区变更
        if (KDY_HOSPITAL_AREA.equalsIgnoreCase(propertyName)) {
            getView().invokeOperation("refresh");
        }


    }

    @Override
    public void setFilter(SetFilterEvent e) {
        super.setFilter(e);

        //获取当前页签对应的数字
        String tabSelect = getTabSelected();

        if ("0".equals(tabSelect)) {
            this.getView().showTipNotification("列表模板未页签标识未包含数字1、2、3中的其中一个,请检查设置");
            return;
        }

        //获取过滤字段方法
        String selectFiled = currencyFilterMethod(tabSelect);

        if (selectFiled == null || "null".equals(selectFiled) || "".equals(selectFiled)) {
            return;
        }

        //当前用户id
        String userId = String.valueOf(RequestContext.get().getCurrUserId());

        switch (tabSelect) {
            //个人
            case "1":
                QFilter filter1 = new QFilter(selectFiled, QCP.equals, userId);
                e.addCustomQFilter(filter1);
                break;
            //科室
            case "2":
                QFilter filter2;
                if (this.getView().getModel().getValue(KDY_DEPT) == null) {
                    break;
                }
                DynamicObject dept = (DynamicObject) this.getView().getModel().getValue(KDY_DEPT);
                filter2 = new QFilter(selectFiled, QCP.equals, dept.getString("id"));
                e.addCustomQFilter(filter2);
                break;
            //全院
            case "3":
                QFilter filter3;
                if (this.getView().getModel().getValue(KDY_HOSPITAL_AREA) == null) {
                    break;
                }
                DynamicObject hospitalArea = (DynamicObject) this.getView().getModel().getValue(KDY_HOSPITAL_AREA);
                filter3 = new QFilter(selectFiled, QCP.equals, hospitalArea.getString("id"));
                e.addCustomQFilter(filter3);
                break;
            default:
                break;
        }
    }

    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);

        //当前用户科室
        long orgid = RequestContext.get().getOrgId();
        //当前用户所在院区
        Long campusId = RoleUserUtils.getCampusByOrgId(orgid, RoleUserUtils.getFunctionViewId("临床"));

        //设置科室
        this.getView().getModel().setValue(KDY_DEPT, orgid);
        //设置院区
        this.getView().getModel().setValue(KDY_HOSPITAL_AREA, campusId);

        //获取科室和院区
        Object dept = this.getView().getModel().getValue(KDY_DEPT);
        Object hospitalarea = this.getView().getModel().getValue(KDY_HOSPITAL_AREA);

        //空值处理防止报错
        if (dept == null) {
            this.getView().getModel().setValue(KDY_DEPT, null);
        }
        if (hospitalarea == null) {
            this.getView().getModel().setValue(KDY_HOSPITAL_AREA, null);
        }
    }

    @Override
    public void refreshNode(RefreshNodeEvent e) {
        super.refreshNode(e);

        filterTreeNode();
    }

    /**
     * 过滤树节点
     */
    private void filterTreeNode() {
        // 根节点是否显示
        this.getTreeModel().setRootVisable(true);
        if (this.getTreeModel().getGroupProp() != null) {

            //获取当前页签对应的数字
            String tabSelect = getTabSelected();

            if ("0".equals(tabSelect)) {
                this.getView().showTipNotification("列表模板未页签标识未包含数字1、2、3中的其中一个,请检查设置");
                return;
            }

            //获取过滤字段方法
            String selectFiled = currencyFilterMethod(tabSelect);

            if (selectFiled == null || "null".equals(selectFiled) || "".equals(selectFiled)) {
                return;
            }

            //当前用户id
            String userId = String.valueOf(RequestContext.get().getCurrUserId());

            switch (tabSelect) {
                //个人
                case "1":
                    QFilter filter1 = new QFilter(selectFiled, QCP.equals, userId);
                    this.getTreeModel().getTreeFilter().add(filter1);
                    break;
                //科室
                case "2":
                    QFilter filter2;
                    if (this.getView().getModel().getValue(KDY_DEPT) == null) {
                        break;
                    }
                    DynamicObject dept = (DynamicObject) this.getView().getModel().getValue(KDY_DEPT);
                    filter2 = new QFilter(selectFiled, QCP.equals, dept.getString("id"));
                    this.getTreeModel().getTreeFilter().add(filter2);
                    break;
                //全院
                case "3":
                    QFilter filter3;
                    if (this.getView().getModel().getValue(KDY_HOSPITAL_AREA) == null) {
                        break;
                    }
                    DynamicObject hospitalArea = (DynamicObject) this.getView().getModel().getValue(KDY_HOSPITAL_AREA);
                    filter3 = new QFilter(selectFiled, QCP.equals, hospitalArea.getString("id"));
                    this.getTreeModel().getTreeFilter().add(filter3);
                    break;
                default:
                    break;
            }
        }
    }


    /**
     * 通用获取过滤字段方法
     *
     * @param tabSelect 页签选择
     */
    private String currencyFilterMethod(String tabSelect) {

        //获取列表控件,并做空值判断
        BillList billList = this.getControl("billlistap");
        if (billList == null) {
            this.getView().showTipNotification("未获取到列表控件");
            return null;
        }

        Tips tips = billList.getCtlTips();
        if (tips == null) {
            this.getView().showTipNotification("未设置帮助文本内容");
            return null;
        }

        if (tips.getContent() == null) {
            this.getView().showTipNotification("未设置帮助文本内容");
            return null;
        }

        if (tips.getContent().getLocaleValue() == null) {
            this.getView().showTipNotification("未设置帮助文本内容");
            return null;
        }

        //获取列表控件的帮助文本,将json格式的字段映射转换为map再获取对应页签的字段
        String helpContent = tips.getContent().getLocaleValue();
        Map map;
        try {
            map = JSONObject.parseObject(helpContent, Map.class);
        } catch (Exception x) {
            this.getView().showTipNotification("帮助文本设置了错误的json格式,格式参照:{\"1\":\"kdy_userid\",\"2\":\"kdy_deptid\",\"3\":\"kdy_branchid\"}");
            return null;
        }
        //判断map中是否存有对应字段
        if (map.get(tabSelect) == null) {
            this.getView().showTipNotification("帮助文本未设置对的字段对应标识,请设置1,2,3及分别对应的字段,格式参照:" +
                    "{\"1\":\"kdy_userid\",\"2\":\"kdy_deptid\",\"3\":\"kdy_branchid\"}");
            return null;
        }
        //获取过滤字段
        String selectFiled = map.get(tabSelect).toString();

        return selectFiled;
    }

    /**
     * 通用获取当前页签对应的数字的方法
     *
     * @return
     */
    private String getTabSelected() {
        //获取当前页签所选的控件
        Tab tab = this.getView().getControl(KDY_TAB);
        String tabKey = tab.getCurrentTab();

        //页签选择
        String tabSelect = "0";
        if (tabKey.contains("1")) {
            tabSelect = "1";
        } else if (tabKey.contains("2")) {
            tabSelect = "2";
        } else if (tabKey.contains("3")) {
            tabSelect = "3";
        }
        return tabSelect;
    }

}

四、效果展示


效果一:个人过滤

image.png


效果二:科室过滤

image.png


效果三:院区过滤

image.png


赞 1