ActUtils.java
7.47 KB
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
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.modules.act.utils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.UserEntity;
import org.springframework.ui.Model;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.annotation.FieldName;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.Encodes;
import com.thinkgem.jeesite.common.utils.ObjectUtils;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.act.entity.Act;
import com.thinkgem.jeesite.modules.sys.entity.Role;
import com.thinkgem.jeesite.modules.sys.entity.User;
/**
* 流程工具
* @author ThinkGem
* @version 2013-11-03
*/
public class ActUtils {
// private static Logger logger = LoggerFactory.getLogger(ActUtils.class);
/**
* 定义流程定义KEY,必须以“PD_”开头
* 组成结构:string[]{"流程标识","业务主表表名"}
*/
public static final String[] PD_LEAVE = new String[]{"leave", "oa_leave"};
public static final String[] PD_TEST_AUDIT = new String[]{"test_audit", "oa_test_audit"};
//一般登记流程
public static final String[] PD_REG_AUDIT = new String[]{"reg_process", "reg_bus_slsq"};
//变更、转移登记的流程
public static final String[] PD_CREG_AUDIT = new String[]{"creg_process", "reg_bus_slsq"};
// /**
// * 流程定义Map(自动初始化)
// */
// private static Map<String, String> procDefMap = new HashMap<String, String>() {
// private static final long serialVersionUID = 1L;
// {
// for (Field field : ActUtils.class.getFields()){
// if(StringUtils.startsWith(field.getName(), "PD_")){
// try{
// String[] ss = (String[])field.get(null);
// put(ss[0], ss[1]);
// }catch (Exception e) {
// logger.debug("load pd error: {}", field.getName());
// }
// }
// }
// }
// };
//
// /**
// * 获取流程执行(办理)URL
// * @param procId
// * @return
// */
// public static String getProcExeUrl(String procId) {
// String url = procDefMap.get(StringUtils.split(procId, ":")[0]);
// if (StringUtils.isBlank(url)){
// return "404";
// }
// return url;
// }
@SuppressWarnings({ "unused" })
public static Map<String, Object> getMobileEntity(Object entity,String spiltType){
if(spiltType==null){
spiltType="@";
}
Map<String, Object> map = Maps.newHashMap();
List<String> field = Lists.newArrayList();
List<String> value = Lists.newArrayList();
List<String> chinesName =Lists.newArrayList();
try{
for (Method m : entity.getClass().getMethods()){
if (m.getAnnotation(JsonIgnore.class) == null && m.getAnnotation(JsonBackReference.class) == null && m.getName().startsWith("get")){
if (m.isAnnotationPresent(FieldName.class)) {
Annotation p = m.getAnnotation(FieldName.class);
FieldName fieldName=(FieldName) p;
chinesName.add(fieldName.value());
}else{
chinesName.add("");
}
if (m.getName().equals("getAct")){
Object act = m.invoke(entity, new Object[]{});
Method actMet = act.getClass().getMethod("getTaskId");
map.put("taskId", ObjectUtils.toString(m.invoke(act, new Object[]{}), ""));
}else{
field.add(StringUtils.uncapitalize(m.getName().substring(3)));
value.add(ObjectUtils.toString(m.invoke(entity, new Object[]{}), ""));
}
}
}
}catch (Exception e) {
e.printStackTrace();
}
map.put("beanTitles", StringUtils.join(field, spiltType));
map.put("beanInfos", StringUtils.join(value, spiltType));
map.put("chineseNames", StringUtils.join(chinesName, spiltType));
return map;
}
/**
* 获取流程表单URL
* @param formKey
* @param act 表单传递参数
* @return
*/
public static String getFormUrl(String formKey, Act act, HttpServletRequest request, Model model){
StringBuilder formUrl = new StringBuilder();
String formServerUrl = Global.getConfig("activiti.form.server.url");
if (StringUtils.isBlank(formServerUrl)){
formUrl.append(Global.getAdminPath());
}else{
formUrl.append(formServerUrl);
}
formUrl.append(formKey).append(formUrl.indexOf("?") == -1 ? "?" : "&");
formUrl.append("act.taskId=").append(act.getTaskId() != null ? act.getTaskId() : "");
formUrl.append("&act.taskName=").append(act.getTaskName() != null ? Encodes.urlEncode(act.getTaskName()) : "");
formUrl.append("&act.taskDefKey=").append(act.getTaskDefKey() != null ? act.getTaskDefKey() : "");
formUrl.append("&act.procInsId=").append(act.getProcInsId() != null ? act.getProcInsId() : "");
formUrl.append("&act.procDefId=").append(act.getProcDefId() != null ? act.getProcDefId() : "");
formUrl.append("&act.status=").append(act.getStatus() != null ? act.getStatus() : "");
formUrl.append("&id=").append(act.getBusinessId() != null ? act.getBusinessId() : "");
formUrl.append("&act.listsubmit=").append(act.getListsubmit() != null ? act.getListsubmit() : "");
//------------------------------------20180502 f 记忆查询
if(StringUtils.isNotBlank(request.getParameter("actywh"))){
model.addAttribute("actywh", request.getParameter("actywh"));
}
if(StringUtils.isNotBlank(request.getParameter("actsqr"))){
model.addAttribute("actsqr", request.getParameter("actsqr"));
}
if(StringUtils.isNotBlank(request.getParameter("actdjlx"))){
model.addAttribute("actdjlx", request.getParameter("actdjlx"));
}
if(StringUtils.isNotBlank(request.getParameter("acttitle"))){
model.addAttribute("acttitle", request.getParameter("acttitle"));
}
//----------------------------------------------
return formUrl.toString();
}
/**
* 转换流程节点类型为中文说明
* @param type 英文名称
* @return 翻译后的中文名称
*/
public static String parseToZhType(String type) {
Map<String, String> types = new HashMap<String, String>();
types.put("userTask", "用户任务");
types.put("serviceTask", "系统任务");
types.put("startEvent", "开始节点");
types.put("endEvent", "结束节点");
types.put("exclusiveGateway", "条件判断节点(系统自动根据条件处理)");
types.put("inclusiveGateway", "并行处理任务");
types.put("callActivity", "子流程");
return types.get(type) == null ? type : types.get(type);
}
public static UserEntity toActivitiUser(User user){
if (user == null){
return null;
}
UserEntity userEntity = new UserEntity();
userEntity.setId(user.getLoginName());
userEntity.setFirstName(user.getName());
userEntity.setLastName(StringUtils.EMPTY);
userEntity.setPassword(user.getPassword());
userEntity.setEmail(user.getEmail());
userEntity.setRevision(1);
return userEntity;
}
public static GroupEntity toActivitiGroup(Role role){
if (role == null){
return null;
}
GroupEntity groupEntity = new GroupEntity();
groupEntity.setId(role.getEnname());
groupEntity.setName(role.getName());
groupEntity.setType(role.getRoleType());
groupEntity.setRevision(1);
return groupEntity;
}
public static void main(String[] args) {
User user = new User();
System.out.println(getMobileEntity(user, "@"));
}
}