1
2
3
4
5 package gboat2.base.core.model;
6
7 import gboat2.base.core.annotation.Operation;
8
9 import java.lang.reflect.Method;
10
11 import org.apache.commons.lang3.StringUtils;
12
13
14
15
16
17
18
19
20
21
22
23
24 public class Opera {
25
26
27
28
29 private String name;
30
31
32
33
34 private String code = "";
35
36
37
38
39 private String action;
40
41
42
43
44 private String invokeAction;
45
46
47
48
49 private String invokeMethod;
50
51
52
53
54 private String desc;
55
56
57
58
59
60
61
62
63 public Opera(Operation operation, Method method, Class<?> action) {
64 this.action = action.getName();
65 this.name = operation.name();
66 this.code = operation.code();
67 this.desc = operation.desc();
68
69 if (StringUtils.isNotEmpty(operation.invokeAction()) && StringUtils.isNotEmpty(operation.invokeMethod())) {
70 invokeAction = operation.invokeAction();
71 invokeMethod = operation.invokeMethod();
72 } else {
73 invokeAction = action.getName();
74 invokeMethod = method.getName();
75 }
76 }
77
78
79
80
81
82
83
84
85 public Opera(Operation operation, Class<?> action) {
86 this.name = operation.name();
87 this.action = action.getName();
88 this.code = operation.code();
89 this.desc = operation.desc();
90
91 if (StringUtils.isNotEmpty(operation.invokeAction()) && StringUtils.isNotEmpty(operation.invokeMethod())) {
92 invokeAction = operation.invokeAction();
93 invokeMethod = operation.invokeMethod();
94 } else {
95 invokeAction = action.getName();
96 invokeMethod = StringUtils.isEmpty(operation.invokeMethod()) ? operation.code() : operation.invokeMethod();
97 }
98
99
100 if ("add".equals(operation.code())) {
101 invokeMethod = "edit";
102 }
103 }
104
105
106
107
108
109
110
111
112
113
114
115 public Opera(String name, String code, String action, String invokeAction, String invokeMethod, String desc) {
116 this.name = name;
117 this.code = code;
118 this.action = action;
119 this.invokeAction = invokeAction;
120 this.invokeMethod = invokeMethod;
121 this.desc = desc;
122 }
123
124 public String getName() {
125 return name;
126 }
127
128 public String getAction() {
129 return action;
130 }
131
132 public String getDesc() {
133 return desc;
134 }
135
136 public String getCode() {
137 return code;
138 }
139
140 public String getInvokeAction() {
141 return invokeAction;
142 }
143
144 public String getInvokeMethod() {
145 return invokeMethod;
146 }
147
148 public String toString() {
149 StringBuilder _string = new StringBuilder();
150 _string.append(super.toString());
151 _string.append("{name : ");
152 _string.append(name).append(",code : ").append(code).append("}");
153 return _string.toString();
154 }
155
156 public boolean equals(Object target) {
157 Opera o = (Opera) target;
158 return o.getAction().equals(action) && o.getInvokeMethod().equals(invokeMethod);
159 }
160 }