@@ -24,6 +24,7 @@ public class FormFieldPermissionStrategy extends BaseStrategy {
2424
2525 /**
2626 * 表单字段权限
27+ * 若为空时,代表字段全部可写
2728 */
2829 private List <FormFieldPermission > fieldPermissions ;
2930
@@ -44,10 +45,12 @@ public FormFieldPermissionStrategy(List<FormFieldPermission> fieldPermissions) {
4445 @ Override
4546 public void verifyNode (FlowForm form ) {
4647 Map <String , DataType > fieldTypes = form .loadAllFieldTypeMaps ();
47- for (FormFieldPermission permission : fieldPermissions ) {
48- String key = permission .getFormCode () + "." + permission .getFieldCode ();
49- if (!fieldTypes .containsKey (key )) {
50- throw FlowValidationException .fieldNotFound (key );
48+ if (fieldPermissions !=null ) {
49+ for (FormFieldPermission permission : fieldPermissions ) {
50+ String key = permission .getFormCode () + "." + permission .getFieldCode ();
51+ if (!fieldTypes .containsKey (key )) {
52+ throw FlowValidationException .fieldNotFound (key );
53+ }
5154 }
5255 }
5356 }
@@ -57,39 +60,41 @@ public void verifySession(FlowSession session) {
5760 FlowForm flowForm = session .getFormData ().getFlowForm ();
5861 Map <String , Object > currentData = session .getCurrentRecord ().getFormData ();
5962 Map <String , Object > latestData = session .getFormData ().toMapData ();
60- for (FormFieldPermission permission : fieldPermissions ) {
61- // 子表
62- if (flowForm .isSubForm (permission .getFormCode ())) {
63- if (permission .getType () == PermissionType .READ ) {
64- List <Map <String , Object >> currentSubFormData = (List <Map <String , Object >>) currentData .get (permission .getFormCode ());
65- List <Map <String , Object >> latestSubFormData = (List <Map <String , Object >>) latestData .get (permission .getFormCode ());
66- if (currentSubFormData == null || latestSubFormData == null ) {
67- throw FlowValidationException .nodeRequired ("form" );
68- }
63+ if (fieldPermissions !=null ) {
64+ for (FormFieldPermission permission : fieldPermissions ) {
65+ // 子表
66+ if (flowForm .isSubForm (permission .getFormCode ())) {
67+ if (permission .getType () == PermissionType .READ ) {
68+ List <Map <String , Object >> currentSubFormData = (List <Map <String , Object >>) currentData .get (permission .getFormCode ());
69+ List <Map <String , Object >> latestSubFormData = (List <Map <String , Object >>) latestData .get (permission .getFormCode ());
70+ if (currentSubFormData == null || latestSubFormData == null ) {
71+ throw FlowValidationException .nodeRequired ("form" );
72+ }
6973
70- if (currentSubFormData .size () != latestSubFormData .size ()) {
71- throw FlowValidationException .nodeRequired ("form" );
72- }
74+ if (currentSubFormData .size () != latestSubFormData .size ()) {
75+ throw FlowValidationException .nodeRequired ("form" );
76+ }
7377
74- for (int i = 0 ; i < currentSubFormData .size (); i ++) {
75- Map <String , Object > currentSubFormItem = currentSubFormData .get (i );
76- Map <String , Object > latestSubFormItem = latestSubFormData .get (i );
77- Object currentValue = currentSubFormItem .get (permission .getFieldCode ());
78- Object latestValue = latestSubFormItem .get (permission .getFieldCode ());
78+ for (int i = 0 ; i < currentSubFormData .size (); i ++) {
79+ Map <String , Object > currentSubFormItem = currentSubFormData .get (i );
80+ Map <String , Object > latestSubFormItem = latestSubFormData .get (i );
81+ Object currentValue = currentSubFormItem .get (permission .getFieldCode ());
82+ Object latestValue = latestSubFormItem .get (permission .getFieldCode ());
83+ if (!currentValue .equals (latestValue )) {
84+ throw FlowValidationException .fieldReadOnly (permission .getFieldCode ());
85+ }
86+ }
87+ }
88+ } else {
89+ // 在只读权限下不允许修改数据
90+ if (permission .getType () == PermissionType .READ ) {
91+ Object currentValue = currentData .get (permission .getFieldCode ());
92+ Object latestValue = latestData .get (permission .getFieldCode ());
7993 if (!currentValue .equals (latestValue )) {
8094 throw FlowValidationException .fieldReadOnly (permission .getFieldCode ());
8195 }
8296 }
8397 }
84- } else {
85- // 在只读权限下不允许修改数据
86- if (permission .getType () == PermissionType .READ ) {
87- Object currentValue = currentData .get (permission .getFieldCode ());
88- Object latestValue = latestData .get (permission .getFieldCode ());
89- if (!currentValue .equals (latestValue )) {
90- throw FlowValidationException .fieldReadOnly (permission .getFieldCode ());
91- }
92- }
9398 }
9499 }
95100 }
0 commit comments