指令数据采集(三)--Instruction 指令对象的创建

Instruction指令的实现

  1 public class Instruction implements Cloneable {
  2     private static final String COMMAND_SPLITE="\\?";
  3     private static final String COMMAND_EMPTY=" ";
  4     //父指令ID
  5     private String parentInstId;
  6     //指令和指令关联的ID
  7     private String relaId;
  8     //指令ID
  9     private String instId;
 10     //指令
 11     private String instNo;
 12     private String instName;
 13     private int instType;
 14     //关联的接口ID
 15     private String relaIntfOjbId;
 16     //指令输入
 17     private List<Param> paramsInput;
 18     //指令输出 每次发送指令的时候 需要这边设置 paramKey 用来表示需要解释的结果
 19     private List<Param> paramsOutput;
 20     //上一条指令的输出 被分配到当前的指令当中的值
 21     private List<Param> paramOutputParent;
 22     private List<List<Param>> listsOutputResult;
 23     private List<InstructionRelaParam> instructionRelaParamList;
 24     //关联的指令
 25     private List<Instruction> children;
 26     //指令所在的位置
 27     private Integer seq;
 28 
 29     //当前的指令是否执行 指令默认执行
 30     private boolean isRun = true;
 31     private String woId;
 32     public List<Instruction> getChildren() {
 33         return children;
 34     }
 35 
 36     public void setChildren(List<Instruction> children) {
 37         this.children = children;
 38     }
 39 
 40     public String getInstId() {
 41         return instId;
 42     }
 43 
 44     public void setInstId(String instId) {
 45         this.instId = instId;
 46     }
 47 
 48     public String getInstNo() {
 49         return instNo;
 50     }
 51 
 52     public void setInstNo(String instNo) {
 53         this.instNo = instNo;
 54     }
 55 
 56     public List<Param> getParamsInput() {
 57         return paramsInput;
 58     }
 59 
 60     public void setParamsInput(List<Param> paramsInput) {
 61         this.paramsInput = paramsInput;
 62     }
 63 
 64     public List<Param> getParamsOutput() {
 65         return paramsOutput;
 66     }
 67 
 68     public void setParamsOutput(List<Param> paramsOutput) {
 69         this.paramsOutput = paramsOutput;
 70     }
 71 
 72     public Integer getSeq() {
 73         return seq;
 74     }
 75 
 76     public void setSeq(Integer seq) {
 77         this.seq = seq;
 78     }
 79 
 80 
 81     public List<InstructionRelaParam> getInstructionRelaParamList() {
 82         return instructionRelaParamList;
 83     }
 84 
 85     public void setInstructionRelaParamList(List<InstructionRelaParam> instructionRelaParamList) {
 86         this.instructionRelaParamList = instructionRelaParamList;
 87     }
 88 
 89     public String getInstName() {
 90         return instName;
 91     }
 92 
 93     public void setInstName(String instName) {
 94         this.instName = instName;
 95     }
 96 
 97     public int getInstType() {
 98         return instType;
 99     }
100 
101     public void setInstType(int instType) {
102         this.instType = instType;
103     }
104 
105     public boolean isRun() {
106         return isRun;
107     }
108 
109     public void setIsRun(boolean isRun) {
110         this.isRun = isRun;
111     }
112 
113     public String getRelaId() {
114         return relaId;
115     }
116 
117     public void setRelaId(String relaId) {
118         this.relaId = relaId;
119     }
120 
121     public String getWoId() {
122         return woId;
123     }
124 
125     public void setWoId(String woId) {
126         this.woId = woId;
127     }
128 
129     /**
130      * 该接口用于获得参数的数组 解析数据
131      * @return
132      */
133     public String[] getOutputParamKeys() {
134         String [] parmkesString = null;
135         if (this.paramsOutput != null && !this.paramsOutput.isEmpty()) {
136             parmkesString = new String[this.paramsOutput.size()];
137             for (int i = 0; i < this.paramsOutput.size(); i++) {
138                 if (this.paramsOutput.get(i) != null) {
139                     ParamKey paramKey = this.paramsOutput.get(i).getParamKey();
140                     parmkesString[i] = paramKey.getKeyDesc();
141                 }
142             }
143         }else {
144             //没有分割 长度是1 一条也是一个数据
145             parmkesString = new String[1];
146         }
147         return parmkesString;
148     }
149 
150     /**
151      * 获得输入的指令 同时解析 ? 进行替换
152      * @return
153      */
154     public String getInputInstruction() {
155         if (this.paramsInput != null && !this.paramsInput.isEmpty()) {
156             //首先拆分命令
157             String[] stringArray = this.getInstNo().split(this.COMMAND_SPLITE);
158             StringBuffer stringBuffer = new StringBuffer();
159             //拼接命令第一个值
160             stringBuffer.append(stringArray[0]);
161 //            stringBuffer.append(this.COMMAND_EMPTY);
162             //这边不应该是直接拼接上一个命令的入参
163             for (int start = 0; start < this.paramsInput.size(); start++) {
164                 Param param = this.paramsInput.get(start);
165                 ParamValue paramValue = param.getParamValue();
166                 stringBuffer.append(paramValue.getValue());
167                 //增加第二个
168                 if (start + 1 < stringArray.length) {
169                     stringBuffer.append(stringArray[start + 1]);
170 //                    stringBuffer.append(this.COMMAND_EMPTY);
171                 }
172             }
173             return stringBuffer.toString();
174         } else {
175             return this.instNo;
176         }
177     }
178 
179     @Override
180     public Instruction clone() throws CloneNotSupportedException {
181         Instruction instruction = (Instruction)(super.clone());
182         //
183         if(this.paramsInput!=null) {
184             List<Param> paramInput = this.paramsInput;
185             List<Param> paramListInputColone = new ArrayList<Param>();
186             for (Param param : paramInput) {
187                 paramListInputColone.add(param.clone());
188             }
189             instruction.setParamsInput(paramListInputColone);
190         }
191         //
192         if(StringUtils.isNotBlank(this.getInstId())) {
193             instruction.setInstId(new String(this.getInstId()));
194         }else {
195             instruction.setInstId("");
196         }
197         if(StringUtils.isNotBlank(this.getInstNo())) {
198             instruction.setInstNo(new String(this.getInstNo()));
199         }else {
200             instruction.setInstNo("");
201         }
202         if(StringUtils.isNotBlank(this.getInstName())) {
203             instruction.setInstName(new String(this.getInstName()));
204         }else {
205             instruction.setInstName("");
206         }
207         instruction.setInstType(this.getInstType());
208         if(StringUtils.isNotBlank(this.getRelaIntfOjbId())) {
209             instruction.setRelaIntfOjbId(new String(this.getRelaIntfOjbId()));
210         }else {
211             instruction.setRelaIntfOjbId("");
212         }
213 
214         if(StringUtils.isNotBlank(this.getParentInstId())) {
215             instruction.setParentInstId(new String(this.getParentInstId()));
216         }else {
217             instruction.setParentInstId("");
218         }
219 
220         if(StringUtils.isNotBlank(this.getRelaId())){
221             instruction.setRelaId(new String(this.getRelaId()));
222         }else {
223             instruction.setRelaId("");
224         }
225         //
226         if(this.paramsOutput!=null) {
227             List<Param> paramOuput = this.paramsOutput;
228             List<Param> paramListOutputColone = new ArrayList<Param>();
229             for (Param param : paramOuput) {
230                 paramListOutputColone.add(param.clone());
231             }
232             instruction.setParamsOutput(paramListOutputColone);
233         }
234         //
235         if(this.instructionRelaParamList!=null) {
236             List<InstructionRelaParam> instructionRelaParamList = this.instructionRelaParamList;
237             List<InstructionRelaParam> instructionRelaParamListColone = new ArrayList<InstructionRelaParam>();
238             for (InstructionRelaParam instructionRelaParam : instructionRelaParamList) {
239                 instructionRelaParamListColone.add(instructionRelaParam.clone());
240             }
241             instruction.setInstructionRelaParamList(instructionRelaParamListColone);
242         }
243         //
244         if(this.children!=null) {
245             List<Instruction> relaInstructions = this.children;
246             List<Instruction> relaInstructionsColone = new ArrayList<Instruction>();
247             for (Instruction instruction1 : relaInstructions) {
248                 relaInstructionsColone.add(instruction1.clone());
249             }
250             instruction.setChildren(relaInstructionsColone);
251         }
252         //
253         if(this.seq!=null) {
254             instruction.setSeq(new Integer(this.seq));
255         }else {
256             instruction.setSeq(new Integer(-1));
257         }
258         // 是否执行
259         instruction.setIsRun(this.isRun);
260         //被分配的条件
261         if(this.paramOutputParent!=null&&!this.paramOutputParent.isEmpty()){
262             List<Param> paramList = new ArrayList<Param>();
263             for(Param param:this.getParamOutputParent()){
264                 paramList.add(param.clone());
265             }
266             instruction.setParamOutputParent(paramList);
267         }
268         return instruction;
269     }
270 
271     public List<Param> getParamOutputParent() {
272         return paramOutputParent;
273     }
274 
275     public void setParamOutputParent(List<Param> paramOutputParent) {
276         this.paramOutputParent = paramOutputParent;
277     }
278 
279     public String getRelaIntfOjbId() {
280         return relaIntfOjbId;
281     }
282 
283     public void setRelaIntfOjbId(String relaIntfOjbId) {
284         this.relaIntfOjbId = relaIntfOjbId;
285     }
286 
287     public String getParentInstId() {
288         return parentInstId;
289     }
290 
291     public void setParentInstId(String parentInstId) {
292         this.parentInstId = parentInstId;
293     }
294 
295     public List<List<Param>> getListsOutputResult() {
296         return listsOutputResult;
297     }
298 
299     public void setListsOutputResult(List<List<Param>> listsOutputResult) {
300         this.listsOutputResult = listsOutputResult;
301     }
302 
303     @Override
304     public String toString() {
305         return "Instruction{" +
306                 "parentInstId='" + parentInstId + '\'' +
307                 ", instId='" + instId + '\'' +
308                 ", instNo='" + instNo + '\'' +
309                 ", instName='" + instName + '\'' +
310                 ", instType=" + instType +
311                 ", relaIntfOjbId='" + relaIntfOjbId + '\'' +
312                 ", paramsInput=" + paramsInput +
313                 ", paramsOutput=" + paramsOutput +
314                 ", listsOutputResult=" + listsOutputResult +
315                 ", instructionRelaParamList=" + instructionRelaParamList +
316                 ", children=" + children +
317                 ", seq=" + seq +
318                 '}';
319     }
320 }
View Code

Instruction指令比较重要的属性有

1.父指令ID(private String parentInstId)

2.指令的出入参数(private List<Param> paramsInput)

3.指令的出参(private List<Param> paramsOutput),被分配到当前指令的结果,也就是父指令的执行,经过复制创建的子指令,同于前一个篇幅说明的Param对象

4.分配的不同的入参(private List<Param> paramOutputParent)

5.当前指令的执行结果设置(private List<List<Param>> listsOutputResult),当前的执行结果也会封装成一个Param进行处理

6.子指令 (private List<Instruction> children) 用来存储子指令

7.是否执行,通过条件判断 默认执行(private boolean isRun = true)

8.获得指令,用于真正执行指令的时候进行调用处理的

 1 public String getInputInstruction() {
 2         if (this.paramsInput != null && !this.paramsInput.isEmpty()) {
 3             //首先拆分命令
 4             String[] stringArray = this.getInstNo().split(this.COMMAND_SPLITE);
 5             StringBuffer stringBuffer = new StringBuffer();
 6             //拼接命令第一个值
 7             stringBuffer.append(stringArray[0]);
 8 //            stringBuffer.append(this.COMMAND_EMPTY);
 9             //这边不应该是直接拼接上一个命令的入参
10             for (int start = 0; start < this.paramsInput.size(); start++) {
11                 Param param = this.paramsInput.get(start);
12                 ParamValue paramValue = param.getParamValue();
13                 stringBuffer.append(paramValue.getValue());
14                 //增加第二个
15                 if (start + 1 < stringArray.length) {
16                     stringBuffer.append(stringArray[start + 1]);
17 //                    stringBuffer.append(this.COMMAND_EMPTY);
18                 }
19             }
20             return stringBuffer.toString();
21         } else {
22             return this.instNo;
23         }
24     }
View Code

数据库当中对于指令的入参使用的是?来进行表示的,在动态执行的时候,把需要的入参数据替换?进行处理

posted @ 2017-08-25 16:45  BinarySheep  阅读(478)  评论(0编辑  收藏  举报