提交修改

This commit is contained in:
quyixiao 2021-01-27 12:00:32 +08:00
parent 1e344c6e86
commit fd46292a0c
7 changed files with 220 additions and 82 deletions

View File

@ -1,8 +1,12 @@
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 class BaseCommand {
public abstract class BaseCommand<T> {
public static final String add = "add";
public static final String update = "update";
@ -21,8 +25,50 @@ public class BaseCommand {
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);
}
}

View File

@ -7,8 +7,8 @@ import com.lz.modules.command.BaseCommand;
import com.lz.modules.command.ICommand;
import com.lz.modules.command.annotation.Description;
import com.lz.modules.command.annotation.Name;
import com.lz.modules.command.annotation.Option;
import com.lz.modules.command.annotation.Summary;
import com.lz.modules.sys.entity.SysUserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -27,21 +27,52 @@ import org.springframework.stereotype.Component;
" add 1 -nrm \"短信开发\" 30 \"中途遇到问题,可能会慢一点\"\n"
)
@Slf4j
public class AddCommand extends BaseCommand implements ICommand<Tuple> {
public class AddCommand extends BaseCommand<Tuple> implements ICommand<Tuple> {
@Override
public Tuple check() throws Exception {
return null;
}
private String option;
private Long id;
private String name;
private String rate;
private String mark;
@Override
public Tuple parse() throws Exception {
return null;
}
@Override
public R process(Tuple tuple) throws Exception {
return null;
}
@Option(index = 0, shortName = "o")
@Description("任务操作")
public void setOption(String option) {
this.option = option;
}
@Option(index = 1, shortName = "id")
@Description("任务 id")
public void setId(Long id) {
this.id = id;
}
@Option(index = 2, shortName = "n")
@Description("任务名称")
public void setName(String name) {
this.name = name;
}
@Option(index = 3, shortName = "r")
@Description("任务进度")
public void setRate(String rate) {
this.rate = rate;
}
@Option(index = 4, shortName = "m")
@Description("任务说明")
public void setMark(String mark) {
this.mark = mark;
}
}

View File

@ -24,41 +24,12 @@ import org.springframework.stereotype.Component;
+ " help\n"
+ " help task : 任务命令使用\n"
+ " help record : 绩效命令使用\n")
public class HelpCommand extends BaseCommand implements ICommand {
public class HelpCommand extends BaseCommand<Tuple> implements ICommand<Tuple> {
private String cmd;
@Argument(index = 0, argName = "task or record", required = false)
@Description("command name")
public void setCmd(String cmd) {
this.cmd = cmd;
}
public String getCmd() {
return cmd;
}
@Override
public void init(SysUserEntity user, String[] tokens) throws Exception {
this.user = user;
this.tokens = tokens;
}
@Override
public Tuple check() throws Exception {
return new Tuple(true);
}
@Override
public Object parse() throws Exception {
return null;
}
@Override
public R process(Object o) throws Exception {
public R process(Tuple o) throws Exception {
CLI cli;
if (tokens != null && tokens.length == 1) {
cli = CLIConfigurator.define(HelpCommand.class);
@ -75,4 +46,13 @@ public class HelpCommand extends BaseCommand implements ICommand {
cliDto.setSummary(cli.getSummary());
return R.ok(422).put("cliDto", cliDto);
}
@Argument(index = 0, argName = "task or record", required = false)
@Description("command name")
public void setCmd(String cmd) {
this.cmd = cmd;
}
}

View File

@ -1,5 +1,46 @@
package com.lz.modules.command.base1000;
public class ListCommand {
import com.lz.common.utils.Constant;
import com.lz.common.utils.R;
import com.lz.modules.app.dto.ResultDto;
import com.lz.modules.app.utils.t.Tuple;
import com.lz.modules.app.utils.t.TwoTuple;
import com.lz.modules.command.BaseCommand;
import com.lz.modules.command.ICommand;
import com.lz.modules.command.annotation.Description;
import com.lz.modules.command.annotation.Name;
import com.lz.modules.command.annotation.Summary;
import com.lz.modules.performance.service.ResultTaskService;
import com.lz.modules.third.service.TaskRespService;
import com.lz.modules.third.utils.TaskConvertUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("list")
@Name("list")
@Summary("列出所有的绩效和任务 ,任务以1.x开头 ")
@Description(Constant.EXAMPLE +
" list \n"
)
@Slf4j
public class ListCommand extends BaseCommand<Tuple> implements ICommand<Tuple> {
@Autowired
private ResultTaskService resultTaskService;
@Autowired
private TaskRespService taskRespService;
@Override
public R process(Tuple tuple) throws Exception {
List<ResultDto> list = resultTaskService.listResultTask(user);
taskRespService.deleteInsertLastResult(user, list, tokens[0]); //保存索引和 id对应关系
TwoTuple<List<String>, List<List<String>>> data = TaskConvertUtils.convert(list).getData();
return R.ok().put("header", data.getFirst()).put("data", data.getSecond());
}
}

View File

@ -69,42 +69,7 @@ public class TaskCommand extends BaseCommand implements ICommand<Tuple> {
return new Tuple(true);
}
public Tuple doParse (){
TaskDto taskDto = new TaskDto();
taskDto.setId(NumberUtil.objToLong(tokens[2]));
int i = 3;
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[1]);
return new Tuple(true, taskDto);
}
@Override
public R process(Tuple tuple) throws Exception {
@ -123,7 +88,7 @@ public class TaskCommand extends BaseCommand implements ICommand<Tuple> {
}
public R add() throws Exception {
Tuple tuple = doParse();
Tuple tuple = doTaskParse();
TwoTuple<Boolean, String> data = tuple.getData();
if (!data.getFirst()) {
return R.error(data.getSecond());
@ -155,7 +120,7 @@ public class TaskCommand extends BaseCommand implements ICommand<Tuple> {
}
public R update() {
Tuple tuple = doParse();
Tuple tuple = doTaskParse();
TwoTuple<Boolean, String> data = tuple.getData();
if (!data.getFirst()) {
return R.error(data.getSecond());

View File

@ -1,4 +1,78 @@
package com.lz.modules.command.base1000;
public class UpdateCommand {
import com.lz.common.utils.Constant;
import com.lz.common.utils.R;
import com.lz.modules.app.utils.t.Tuple;
import com.lz.modules.command.BaseCommand;
import com.lz.modules.command.ICommand;
import com.lz.modules.command.annotation.Description;
import com.lz.modules.command.annotation.Name;
import com.lz.modules.command.annotation.Option;
import com.lz.modules.command.annotation.Summary;
import org.springframework.stereotype.Component;
@Component("add")
@Name("add")
@Summary("绩效任务查看 添加 或 更新 ")
@Description(Constant.EXAMPLE +
" update 1 \"短信开发\"\n" +
" update 1.1 \"短信开发\" 30 \n" +
" update 1.2 \"短信开发\" 30 \"中途遇到问题,可能会慢一点\"\n" +
" update 1.3 -n \"短信开发\" -r 30 \n" +
" update 1.4 -n \"短信开发\" \n" +
" update 1.5 -nr \"短信开发\" 30 \n" +
" update 1.6 -r 30 -m \n" +
" update 1.7 -n \"短信开发\" -r 30 -m \"中途遇到问题,可能会慢一点\"\n" +
" update 1.8 -nrm \"短信开发\" 30 \"中途遇到问题,可能会慢一点\"\n"
)
public class UpdateCommand extends BaseCommand<Tuple> implements ICommand<Tuple> {
private String option;
private Long id;
private String name;
private String rate;
private String mark;
@Override
public R process(Tuple tuple) throws Exception {
return null;
}
@Option(index = 0, shortName = "o")
@Description("任务操作")
public void setOption(String option) {
this.option = option;
}
@Option(index = 1, shortName = "id")
@Description("任务 id")
public void setId(Long id) {
this.id = id;
}
@Option(index = 2, shortName = "n")
@Description("任务名称")
public void setName(String name) {
this.name = name;
}
@Option(index = 3, shortName = "r")
@Description("任务进度")
public void setRate(String rate) {
this.rate = rate;
}
@Option(index = 4, shortName = "m")
@Description("任务说明")
public void setMark(String mark) {
this.mark = mark;
}
}

View File

@ -9,4 +9,5 @@ public class TaskDto {
private String name;
private String rate ;
private String mark;
private String index;
}