项目来源 SPRJ202509171552_SCAJ

前端请求方法

  • 先是进行的检查checkTemplate是否有新版本,并且提示信息

  • 然后弹窗确认是否复制流程(copyUrl通过按钮copyDoc传入)

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
<%--复制--%>
<kmss:auth requestURL="/fssc/invoice/fssc_invoice_payable/fsscInvoicePayable.do?method=add&invoiceId=${param.fdId}&fdId=${param.fdId}" requestMethod="GET">
<ui:button text="${lfn:message('fssc-invoice:fsscInvoicePayable.copy') }" order="5" onclick="copyDoc('${LUI_ContextPath}/fssc/invoice/fssc_invoice_payable/fsscInvoicePayable.do?method=add&invoiceId=${param.fdId}&i.docTemplate=${fsscInvoicePayableForm.docTemplateId}&fdReviewIdSource=copy');">
</ui:button>
</kmss:auth>
<script>
function copyDoc(copyUrl) {
seajs.use(['lui/dialog'], function(dialog) {
// 检查模板表单是否有更新
$.ajax({
url : '<c:url value="/fssc/invoice/fssc_invoice_payable/fsscInvoicePayable.do" />?method=checkTemplate&invoiceId=${param.fdId}&docTemplateId=${fsscInvoicePayableForm.docTemplateId}',
// 这里的请求如果是异步,在打开新窗口时会被浏览器阻止,所以设置为同步,缺点:在点击“复制流程”时,会有一点点卡顿
async : false,
dataType : 'json',
success : function(json) {
if (json == false) {
Com_OpenWindow(copyUrl, '_blank');
} else {
dialog.confirm('<bean:message bundle="fssc-invoice" key="fsscInvoicePayable.copy.comfirm"/>', function(isOk) {
if (isOk) {
Com_OpenWindow(copyUrl, '_blank');
}
});
}
}
});
return;
});
}
</script>

创建表单的时候设置信息

  • 拿到传递的参数invoiceId去查询实体
  • 先将实体转换赋值到表单中copyForm
  • 其次清空部分参数和赋值部分参数
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
@Override
public ActionForm createNewForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
super.createNewForm(mapping, form, request, response);
((IFsscInvoicePayableService) getServiceImp(request)).initFormSetting((IExtendForm) form, new RequestContext(request));
/*add by 增加复制流程功能 start*/
FsscInvoicePayableForm newForm = (FsscInvoicePayableForm) form;
String invoiceId = request.getParameter("invoiceId");
// 复制流程时,尽可能复制原文档的数据
if (StringUtil.isNotNull(invoiceId)) {
FsscInvoicePayable fsscInvoicePayable = (FsscInvoicePayable) getServiceImp(request).findByPrimaryKey(invoiceId);
String authReaderIds = newForm.getAuthReaderIds();
String authReaderNames = newForm.getAuthReaderNames();
String authAttCopyIds = newForm.getAuthAttCopyIds();
String authAttCopyNames = newForm.getAuthAttCopyNames();
String authAttNoCopy = newForm.getAuthAttNocopy();
String authAttDownloadIds = newForm.getAuthAttDownloadIds();
String authAttDownloadNames = newForm.getAuthAttDownloadNames();
String authAttNodownload = newForm.getAuthAttNodownload();
String authAttPrintIds = newForm.getAuthAttPrintIds();
String authAttPrintNames = newForm.getAuthAttPrintNames();
String authAttNoprint = newForm.getAuthAttNoprint();
String extendFilePath = newForm.getExtendDataFormInfo().getExtendFilePath();

Map<String, Object> newDataMap = new HashMap();
boolean isUpdate = Boolean.valueOf(this.checkTemplateUpdate(mapping, form, request, response, newDataMap));
FsscInvoicePayableForm copyForm = null;
if (fsscInvoicePayable != null) {
if (!UserUtil.checkAuthentication(ModelUtil.getModelUrl(fsscInvoicePayable), "GET")) {
throw new KmssRuntimeException(new KmssMessage("fssc-invoice:fsscInvoicePayable.auth.copy.error"));
}

RequestContext requestContext = new RequestContext(request);
requestContext.setParameter("extendDataClone", "true");
copyForm = (FsscInvoicePayableForm)this.getServiceImp(request).cloneModelToForm(newForm, fsscInvoicePayable, requestContext);
}
newForm.setDocNumber((String)null);
newForm.setDocCreateTime(DateUtil.convertDateToString(new Date(), "datetime", request.getLocale()));
newForm.setDocCreatorId(UserUtil.getUser().getFdId());
newForm.setDocCreatorName(UserUtil.getUserName(request));
newForm.setDocStatus("10");
newForm.setDocPublishTime((String)null);
Map<String, Object> oldDataMap = copyForm.getExtendDataFormInfo().getFormData();
DictLoadService sysFormDictLoadService = (DictLoadService)SpringBeanUtil.getBean("sysFormDictLoadService");
SysDictExtendModel dictExtendModel = sysFormDictLoadService.loadDictByFileName(extendFilePath);
request.setAttribute(newForm.getModelClass().getName() + "#" + newForm.getFdId(), dictExtendModel);
Map<String, SysDictCommonProperty> propertyMap = dictExtendModel.getPropertyMap();
if (isUpdate) {
for(String key : oldDataMap.keySet()) {
if (newDataMap.containsKey(key)) {
if (this.isNotCopy(propertyMap, key)) {
this.putDefaultValue(newDataMap, key);
} else {
Object value = oldDataMap.get(key);
if (!this.isNull(value)) {
if (key.indexOf("_index") > -1) {
String[] keyArr = key.split("_index");
value = oldDataMap.get(keyArr[0]);
if (value == null) {
continue;
}

if (propertyMap.containsKey(keyArr[0]) && propertyMap.get(keyArr[0]) instanceof SysDictExtendSubTableProperty) {
List<?> _values = (List)value;
new HashMap();
HashMap<String, Object> var75 = (HashMap)newDataMap.get(key);

for(int i = 0; i < _values.size(); ++i) {
if (_values.get(i) instanceof HashMap) {
HashMap<String, Object> _map = (HashMap)_values.get(i);

for(String _key : var75.keySet()) {
if (!_map.containsKey(_key)) {
_map.put(_key, var75.get(_key));
}
}
}
}

value = _values;
}
}

this.putDefaultValue(newDataMap, key);
newDataMap.put(key, value);
}
}
}
}
} else {
for(String key : oldDataMap.keySet()) {
if (this.isNotCopy(propertyMap, key)) {
this.putDefaultValue(newDataMap, key);
if (!newDataMap.containsKey(key)) {
newDataMap.put(key, (Object)null);
}
} else if (!key.endsWith("_index_")) {
this.setSubTableValue(propertyMap, oldDataMap, newDataMap, key);
Object value = oldDataMap.get(key);
if (!this.isNull(value)) {
if (propertyMap.containsKey(key) && propertyMap.get(key) instanceof SysDictExtendSubTableProperty) {
List<?> _values = (List)value;
HashMap<String, Object> _newMap = new HashMap();
if (newDataMap.containsKey(key + "_index_")) {
_newMap = (HashMap)newDataMap.get(key + "_index_");
}

for(int i = 0; i < _values.size(); ++i) {
if (_values.get(i) instanceof HashMap) {
HashMap<String, Object> _map = (HashMap)_values.get(i);

for(String _key : _newMap.keySet()) {
if (!_map.containsKey(_key)) {
_map.put(_key, _newMap.get(_key));
}
}
}
}

value = _values;
}

this.putDefaultValue(newDataMap, key);
newDataMap.put(key, value);
}
}
}
}
newForm.getExtendDataFormInfo().setExtendFilePath(extendFilePath);
Map<String, Object> formData = newForm.getExtendDataFormInfo().getFormData();
formData.putAll(newDataMap);

for(String key : formData.keySet()) {
if (propertyMap.containsKey(key) && propertyMap.get(key) instanceof SysDictExtendSubTableProperty) {
List<?> list = (List)formData.get(key);

for(int i = 0; i < list.size(); ++i) {
if (list.get(i) instanceof Map) {
((Map)list.get(i)).put("fdId", IDGenerator.generateID(System.currentTimeMillis() + (long)i));
}
}
}
}

this.removeEnumValue(formData, propertyMap, oldDataMap);
newForm.setAuthReaderIds(authReaderIds);
newForm.setAuthReaderNames(authReaderNames);
newForm.setAuthAttCopyIds(authAttCopyIds);
newForm.setAuthAttCopyNames(authAttCopyNames);
newForm.setAuthAttNocopy(authAttNoCopy);
newForm.setAuthAttDownloadIds(authAttDownloadIds);
newForm.setAuthAttDownloadNames(authAttDownloadNames);
newForm.setAuthAttNodownload(authAttNodownload);
newForm.setAuthAttPrintIds(authAttPrintIds);
newForm.setAuthAttPrintNames(authAttPrintNames);
newForm.setAuthAttNoprint(authAttNoprint);
}
/*add by 增加复制流程功能end*/
return newForm;
}

处理详细信息和封装的工具方法

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*add by 新增复制流程 start */
private void setSubTableMap(Map<String, Object> oldDataMap, Map<String, Object> newDataMap, String key, SysDictExtendProperty extpro, String key_index) {
if (oldDataMap.containsKey(key) && oldDataMap.get(key) instanceof ArrayList && oldDataMap.containsKey(key_index) && oldDataMap.get(key_index) instanceof Map) {
ArrayList subtableMapList = (ArrayList)oldDataMap.get(key);
Map newSubtableMap = (Map)newDataMap.get(key_index);
Map oldSubtableMap_index = (Map)oldDataMap.get(key_index);

for(Object subTableObj : subtableMapList) {
if (subTableObj instanceof Map) {
Map oldSubTableMap = (Map)subTableObj;
this.putDefaultValue(newSubtableMap, extpro.getName());
oldSubtableMap_index.put(extpro.getName(), newSubtableMap.get(extpro.getName()));
oldSubTableMap.put(extpro.getName(), newSubtableMap.get(extpro.getName()));
}
}
}

}

private void setSubTableValue(Map<String, SysDictCommonProperty> propertyMap, Map<String, Object> oldDataMap, Map<String, Object> newDataMap, String key) {
if (propertyMap.containsKey(key) && propertyMap.get(key) instanceof SysDictExtendSubTableProperty) {
SysDictExtendSubTableProperty property = (SysDictExtendSubTableProperty)propertyMap.get(key);
if (property.getElementDictExtendModel() == null) {
return;
}

SysDictExtendModel model = property.getElementDictExtendModel();
if (model.getPropertyList() == null) {
return;
}

for(SysDictCommonProperty compro : model.getPropertyList()) {
if (compro instanceof SysDictExtendElementProperty || compro instanceof SysDictExtendSimpleProperty) {
SysDictExtendProperty extpro = (SysDictExtendProperty)compro;
String key_index = key + "_index_";
if ("datetime".equals(extpro.getBusinessType()) && StringUtil.isNotNull(extpro.getDefaultValue())) {
this.setSubTableMap(oldDataMap, newDataMap, key, extpro, key_index);
} else if ("new_address".equals(extpro.getBusinessType()) && StringUtil.isNotNull(extpro.getDefaultValue())) {
this.setSubTableMap(oldDataMap, newDataMap, key, extpro, key_index);
} else if ("address".equals(extpro.getBusinessType()) && StringUtil.isNotNull(extpro.getDefaultValue())) {
this.setSubTableMap(oldDataMap, newDataMap, key, extpro, key_index);
} else if (oldDataMap.containsKey(key) && oldDataMap.get(key) instanceof ArrayList && oldDataMap.containsKey(key_index) && oldDataMap.get(key_index) instanceof Map) {
ArrayList subtableMapList = (ArrayList)oldDataMap.get(key);
Map newSubtableMap = (Map)newDataMap.get(key_index);

for(Object subTableObj : subtableMapList) {
if (subTableObj instanceof Map) {
this.putDefaultValue(newSubtableMap, extpro.getName());
}
}
}
}
}
}

}

private void removeEnumValue(Map<String, Object> formData, Map<String, SysDictCommonProperty> propertyMap, Map<String, Object> oldDataMap) {
for(Object key : new ArrayList(formData.keySet())) {
if (propertyMap.containsKey(key) && propertyMap.get(key) instanceof SysDictExtendSubTableProperty) {
SysDictExtendSubTableProperty property = (SysDictExtendSubTableProperty)propertyMap.get(key);
if (property.getElementDictExtendModel() != null) {
SysDictExtendModel model = property.getElementDictExtendModel();
if (model.getPropertyList() != null) {
Map<String, SysDictCommonProperty> subPropertyMap = model.getPropertyMap();

for(Object o : (ArrayList)formData.get(key)) {
HashMap<String, Object> hashMap = (HashMap)o;
Iterator<String> iterator = hashMap.keySet().iterator();

while(iterator.hasNext()) {
String subKey = (String)iterator.next();
if (subPropertyMap.containsKey(subKey) && (subPropertyMap.get(subKey) instanceof SysDictExtendElementProperty || subPropertyMap.get(subKey) instanceof SysDictExtendSimpleProperty)) {
SysDictExtendProperty subProperty = (SysDictExtendProperty)subPropertyMap.get(subKey);
if (StringUtil.isNotNull(subProperty.getEnumValues())) {
String[] enumValues = subProperty.getEnumValues().split(";");
String oldVal = hashMap.get(subKey).toString();
oldVal = StringUtil.XMLUnEscape(oldVal);
String[] olds = oldVal.split(";");
List<String> list = new ArrayList();

for(String enumValue : enumValues) {
String[] values = enumValue.split("\\|");
if (values.length == 2) {
list.add(values[1]);
}
}

boolean isHave = true;

for(String old : olds) {
if (!list.contains(old)) {
isHave = false;
break;
}
}

if (!isHave) {
iterator.remove();
}
}
}
}
}
}
}
} else if (propertyMap.containsKey(key) && (propertyMap.get(key) instanceof SysDictExtendElementProperty || propertyMap.get(key) instanceof SysDictExtendSimpleProperty)) {
SysDictExtendProperty property = (SysDictExtendProperty)propertyMap.get(key);
if (StringUtil.isNotNull(property.getEnumValues())) {
String[] enumValues = property.getEnumValues().split(";");
boolean isHave = true;
List<String> list = new ArrayList();

for(String enumValue : enumValues) {
String[] values = enumValue.split("\\|");
if (values.length == 2) {
list.add(values[1]);
}
}

String oldVal = formData.get(key).toString();
oldVal = StringUtil.XMLUnEscape(oldVal);
String[] split = oldVal.split(";");

for(String old : split) {
if (!list.contains(old)) {
isHave = false;
break;
}
}

if (!isHave) {
formData.remove(key);
}
}
}
}

}

private boolean isNull(Object obj) {
if (obj == null) {
return true;
} else if (obj instanceof String) {
return StringUtil.isNull((String)obj);
} else if (obj instanceof Collection) {
return ((Collection)obj).size() == 0;
} else if (obj instanceof Map) {
return ((Map)obj).size() == 0;
} else {
return true;
}
}

private void putDefaultValue(Map<String, Object> newDataMap, String key) {
if (newDataMap.get(key) != null) {
newDataMap.put(key + "_NoCopy", newDataMap.get(key));
}

}

private boolean isNotCopy(Map<String, SysDictCommonProperty> propertyMap, String key) {
if (propertyMap.containsKey(key) && (propertyMap.get(key) instanceof SysDictExtendElementProperty || propertyMap.get(key) instanceof SysDictExtendSimpleProperty)) {
SysDictExtendProperty property = (SysDictExtendProperty)propertyMap.get(key);
if ("datetime".equals(property.getBusinessType()) && StringUtil.isNotNull(property.getDefaultValue())) {
return true;
}

if ("new_address".equals(property.getBusinessType()) && StringUtil.isNotNull(property.getDefaultValue())) {
return true;
}

if ("address".equals(property.getBusinessType()) && StringUtil.isNotNull(property.getDefaultValue())) {
return true;
}
}

return false;
}

private String checkTemplateUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, Map<String, Object> newDataMap) throws Exception {
((IFsscInvoicePayableService) getServiceImp(request)).initFormSetting((IExtendForm)form, new RequestContext(request));
FsscInvoicePayableForm newForm = (FsscInvoicePayableForm)form;
String invoiceId = request.getParameter("invoiceId");
FsscInvoicePayableForm copyForm = null;
FsscInvoicePayable fsscInvoicePayable = (FsscInvoicePayable)this.getServiceImp(request).findByPrimaryKey(invoiceId);
if (fsscInvoicePayable != null) {
copyForm = (FsscInvoicePayableForm)this.getServiceImp(request).convertModelToForm(new FsscInvoicePayableForm(), fsscInvoicePayable, new RequestContext());
}

if (newDataMap != null) {
newDataMap.putAll(newForm.getExtendDataFormInfo().getFormData());
}

return this.isUpdate(newForm, copyForm);
}

private String isUpdate(FsscInvoicePayableForm newForm, FsscInvoicePayableForm copyForm) {
String isUpdate = "false";
String newFilePath = newForm.getExtendDataFormInfo().getExtendFilePath();
String copyFilePath = copyForm.getExtendDataFormInfo().getExtendFilePath();
if (StringUtil.isNotNull(newFilePath)) {
if (!newFilePath.equals(copyFilePath)) {
isUpdate = "true";
}
} else if (StringUtil.isNotNull(copyFilePath)) {
isUpdate = "true";
}

return isUpdate;
}

public void checkTemplate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
response.getWriter().print(this.checkTemplateUpdate(mapping, form, request, response, (Map)null));
response.getWriter().flush();
response.getWriter().close();
}
/*add by 新增复制流程 end */