# 重复节综合运用

# 需求场景

  • 系统附件:根据业务表单内容,计算所需相关附件,用户无法对附件做添加删除操作。
  • 用户附件:用户可追加补充附件,可以对附件做添加或删除操作。
  • 动态删除:根据重复节A条目,自动计算出重复节B中的特定条目;A重复节删除条目时,B重复节需要删除相关联条目。


# 开发要点

# 简单实现

  • 如业务需求中,每个业务选项只产生一个或多个相同数量附件,则可以使用单个重复节简单完成
  • 使用group属性中的 MinOccur $INDEX 进行控制
  • 使用group前端属性中的 MinOccur 控制最小行数
  • 使用 $INDEX 与 业务类型(fieldBizType) 进行对首行初值进行动态变更
  • 并且设置首行readonly属性值



# 复杂实现

  • 如业务需求中,每个业务选项会产生不同数量的附件时
  • 表单中设置两组重复节,groupSysAttachment与groupUserAttachment
  • groupSysAttachment设置readOnly属性为true只读,只允许messenger操作
  • groupUserAttachment为用户可操作重复节
  • 根据“办理事项”的onFieldChange事件,计算所需附件
@Override
public InfoPlusResponse onFieldChanging(InfoPlusEvent e) {
    InfoPlusExampleRepeat form = e.toBean(InfoPlusExampleRepeat.class);
    switch (e.getField()) {
        case "fieldBizType":
            if(form.getBizType()!=null && StringUtils.isNotEmpty(form.getBizType().getCodeId())) {
                List<InfoPlusExampleRepeatSysAttachment> attachmentList=new ArrayList<>();
                switch (form.getBizType().getCodeId()) {
                    case "10": {
                        InfoPlusExampleRepeatSysAttachment att = new InfoPlusExampleRepeatSysAttachment();
                        att.setSysAttachmentName("因公出国附件1");
                        att.setSysAttachmentRequired(new CodeItemImpl("1"));
                        attachmentList.add(att);

                        InfoPlusExampleRepeatSysAttachment att1 = new InfoPlusExampleRepeatSysAttachment();
                        att1.setSysAttachmentName("因公出国附件2");
                        att1.setSysAttachmentRequired(new CodeItemImpl("1"));
                        attachmentList.add(att1);
                    }
                    break;
                    case "20": {
                        InfoPlusExampleRepeatSysAttachment att = new InfoPlusExampleRepeatSysAttachment();
                            att.setSysAttachmentName("因私出国附件1");
                            att.setSysAttachmentRequired(new CodeItemImpl("1"));
                            attachmentList.add(att);
                            InfoPlusExampleRepeatSysAttachment att1 = new InfoPlusExampleRepeatSysAttachment();
                            att1.setSysAttachmentName("因私出国附件2");
                            att1.setSysAttachmentRequired(new CodeItemImpl("1"));
                            attachmentList.add(att1);
                            InfoPlusExampleRepeatSysAttachment att2 = new InfoPlusExampleRepeatSysAttachment();
                            att2.setSysAttachmentName("因私出国附件3");
                            att2.setSysAttachmentRequired(new CodeItemImpl("1"));
                            attachmentList.add(att2);
                        }
                        break;
                    case "30": {
                            InfoPlusExampleRepeatSysAttachment att = new InfoPlusExampleRepeatSysAttachment();
                            att.setSysAttachmentName("在职证明附件");
                            attachmentList.add(att);
                        }
                        break;
                    case "40": {
                            InfoPlusExampleRepeatSysAttachment att = new InfoPlusExampleRepeatSysAttachment();
                            att.setSysAttachmentName("收入证明附件");
                            attachmentList.add(att);
                        }
                        break;
                    }
                    form.setSysAttachment(attachmentList);
                }
            break;
        }
        return new InfoPlusResponse(e, form);
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
download 案例地址

# 动态删除

根据重复节A条目,自动计算出重复节B中的特定条目;A重复节删除条目时,B重复节需要删除相关联条目。

例:重复节A为成员列表;重复节B为成员所需上传的特定附件(只读属性,用户不可操作,由后端计算生成)。

  • 因重复节没有删除条目的filedChange事件,所以需要使用其他方法实现
  • 在重复节A的上一层级(与重复节同级或上级),建立一个memberCount字段(类型:int,控件样式:hidden)设置fieldChange事件
  • memberCount字段value属性设置为count($fieldRepeatMemberName),此处为重复节A中任意字段,只用于动态存储重复节A条目数量
@Override
public InfoPlusResponse onFieldChanging(InfoPlusEvent e) {
    InfoPlusExampleRepeat form = e.toBean(InfoPlusExampleRepeat.class);
    switch (e.getField()) {
        case "fieldMemberCount":
            //此处无法获取当前删除操作的重复节A的条目,需要遍历重复节B中已经生成的条目进行比对计算
            //具体实现方法
            calculateMemberAttachments(form)
            break;
        }
    return new InfoPlusResponse(e, form);
}

private void calculateMemberAttachments(InfoPlusExampleRepeat form) {
    //已存在的附件 需保留

    //附件列表
    List<MemberAttachment> attachments = form.getMemberAttachments();
    if (attachments == null) {
        attachments = new ArrayList<>();
        form.setMemberAttachments(attachments);
    }
        
    Map<String, MemberAttachment> map = new HashMap<>();
    attachments.forEach(a -> map.put(a.getMemberAttachmentName(), a));
    attachments.clear();

    //成员列表
    List<Member> members = form.getMembers();
    if (members != null) {
        for (Member member : members) {
            if (StringUtils.isNotEmpty(member.getMemberName())) {
                String attachmentName = String.format("%s的材料证明",member.getMemberName());
                MemberAttachment memberAttachment = map.get(attachmentName);
                if (memberAttachment == null) {
                    memberAttachment = new MemberAttachment();
                    memberAttachment.setMemberAttachmentName(attachmentName);
                    memberAttachment.setMemberAttachmentRequired(YesNo.);
                    memberAttachment.setMemberAttachmentRequiredMark("*");
                }
                attachments.add(memberAttachment);
        
                String attachmentName2 = String.format("%s的条款同意书",member.getMemberName());
                MemberAttachment memberAttachment2 = map.get(attachmentName2);
                if (memberAttachment2 == null) {
                    memberAttachment2 = new MemberAttachment();
                    memberAttachment2.setMemberAttachmentName(attachmentName2);
                    memberAttachment2.setMemberAttachmentRequired(YesNo.);
                    memberAttachment2.setMemberAttachmentRequiredMark("*");
                }
                attachments.add(memberAttachment2);
            }
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55