From fd46292a0ca5f4d1ace7760ac89c801bbc92f062 Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Wed, 27 Jan 2021 12:00:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lz/modules/command/BaseCommand.java | 48 +++++++++++- .../modules/command/base1000/AddCommand.java | 51 ++++++++++--- .../modules/command/base1000/HelpCommand.java | 42 +++------- .../modules/command/base1000/ListCommand.java | 43 ++++++++++- .../modules/command/base1000/TaskCommand.java | 41 +--------- .../command/base1000/UpdateCommand.java | 76 ++++++++++++++++++- .../com/lz/modules/flow/model/TaskDto.java | 1 + 7 files changed, 220 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/lz/modules/command/BaseCommand.java b/src/main/java/com/lz/modules/command/BaseCommand.java index 20d5ff4e..6cd33d65 100644 --- a/src/main/java/com/lz/modules/command/BaseCommand.java +++ b/src/main/java/com/lz/modules/command/BaseCommand.java @@ -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 { 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); + } } diff --git a/src/main/java/com/lz/modules/command/base1000/AddCommand.java b/src/main/java/com/lz/modules/command/base1000/AddCommand.java index a7759889..038d2af8 100644 --- a/src/main/java/com/lz/modules/command/base1000/AddCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/AddCommand.java @@ -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 { +public class AddCommand extends BaseCommand implements ICommand { - @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; + } + + } diff --git a/src/main/java/com/lz/modules/command/base1000/HelpCommand.java b/src/main/java/com/lz/modules/command/base1000/HelpCommand.java index 17c69200..392c9e8a 100644 --- a/src/main/java/com/lz/modules/command/base1000/HelpCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/HelpCommand.java @@ -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 implements ICommand { 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; + } + + } diff --git a/src/main/java/com/lz/modules/command/base1000/ListCommand.java b/src/main/java/com/lz/modules/command/base1000/ListCommand.java index d050e4cd..7861a498 100644 --- a/src/main/java/com/lz/modules/command/base1000/ListCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/ListCommand.java @@ -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 implements ICommand { + + @Autowired + private ResultTaskService resultTaskService; + + @Autowired + private TaskRespService taskRespService; + + @Override + public R process(Tuple tuple) throws Exception { + List list = resultTaskService.listResultTask(user); + taskRespService.deleteInsertLastResult(user, list, tokens[0]); //保存索引和 id对应关系 + TwoTuple, List>> data = TaskConvertUtils.convert(list).getData(); + return R.ok().put("header", data.getFirst()).put("data", data.getSecond()); + } + } diff --git a/src/main/java/com/lz/modules/command/base1000/TaskCommand.java b/src/main/java/com/lz/modules/command/base1000/TaskCommand.java index 2d6b6f1b..d0a52df3 100644 --- a/src/main/java/com/lz/modules/command/base1000/TaskCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/TaskCommand.java @@ -69,42 +69,7 @@ public class TaskCommand extends BaseCommand implements ICommand { 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 { } public R add() throws Exception { - Tuple tuple = doParse(); + Tuple tuple = doTaskParse(); TwoTuple data = tuple.getData(); if (!data.getFirst()) { return R.error(data.getSecond()); @@ -155,7 +120,7 @@ public class TaskCommand extends BaseCommand implements ICommand { } public R update() { - Tuple tuple = doParse(); + Tuple tuple = doTaskParse(); TwoTuple data = tuple.getData(); if (!data.getFirst()) { return R.error(data.getSecond()); diff --git a/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java b/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java index 7fd46207..93dd9fdd 100644 --- a/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java @@ -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 implements ICommand { + + + 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; + } + + + } diff --git a/src/main/java/com/lz/modules/flow/model/TaskDto.java b/src/main/java/com/lz/modules/flow/model/TaskDto.java index 2e432cfc..f3dbce0d 100644 --- a/src/main/java/com/lz/modules/flow/model/TaskDto.java +++ b/src/main/java/com/lz/modules/flow/model/TaskDto.java @@ -9,4 +9,5 @@ public class TaskDto { private String name; private String rate ; private String mark; + private String index; }