75 lines
2.3 KiB
Java
75 lines
2.3 KiB
Java
package com.lz.modules.command;
|
|
|
|
import com.lz.common.utils.NumberUtil;
|
|
import com.lz.common.utils.StringUtil;
|
|
import com.lz.modules.app.utils.t.Tuple;
|
|
import com.lz.modules.flow.model.TaskDto;
|
|
import com.lz.modules.sys.entity.SysUserEntity;
|
|
|
|
public abstract class BaseCommand<T> {
|
|
|
|
public static final String add = "add";
|
|
public static final String update = "update";
|
|
public static final String list = "list";
|
|
public static final String task = "task";
|
|
public static final String record = "record";
|
|
public static final String help = "help";
|
|
|
|
|
|
protected String[] tokens;
|
|
|
|
protected SysUserEntity user;
|
|
|
|
public void init(SysUserEntity user, String[] tokens) throws Exception {
|
|
this.user = user;
|
|
this.tokens = tokens;
|
|
}
|
|
|
|
public T check() throws Exception {
|
|
|
|
return (T) new Tuple(true);
|
|
}
|
|
|
|
public T parse() throws Exception {
|
|
return (T) new Tuple(true);
|
|
}
|
|
|
|
public Tuple doTaskParse (){
|
|
TaskDto taskDto = new TaskDto();
|
|
taskDto.setId(NumberUtil.objToLong(tokens[1]));
|
|
int i = 2;
|
|
while (i < tokens.length) {
|
|
String notKnow = tokens[i];
|
|
if (notKnow.startsWith("-")) {
|
|
notKnow = notKnow.substring(1);
|
|
char chars[] = notKnow.toCharArray();
|
|
for (char c : chars) {
|
|
i++;
|
|
String know = tokens[i];
|
|
if (c == 'n') {
|
|
taskDto.setName(know);
|
|
} else if (c == 'r') {
|
|
taskDto.setRate(know);
|
|
} else if (c == 'm') {
|
|
taskDto.setMark(know);
|
|
} else {
|
|
return new Tuple(false, "-后面的参数不对,只能是 n 或 r 或 m");
|
|
}
|
|
}
|
|
} else {
|
|
if (StringUtil.isBlank(taskDto.getName())) {
|
|
taskDto.setName(notKnow);
|
|
} else if (taskDto.getRate() == null) {
|
|
taskDto.setRate(notKnow);
|
|
} else if (StringUtil.isEmpty(taskDto.getMark())) {
|
|
taskDto.setMark(notKnow);
|
|
}
|
|
}
|
|
i++;
|
|
}
|
|
taskDto.setOption(tokens[0]);
|
|
return new Tuple(true, taskDto);
|
|
}
|
|
|
|
}
|