From 1c3c7c3d23fab6723529781a4b525b178e5dff2d Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Wed, 27 Jan 2021 12:14:05 +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 | 2 +- .../modules/command/base1000/AddCommand.java | 35 +++- .../modules/command/base1000/HelpCommand.java | 1 - .../command/base1000/RecordCommand.java | 74 ------- .../modules/command/base1000/TaskCommand.java | 180 ------------------ .../command/base1000/UpdateCommand.java | 39 +++- .../com/lz/modules/third/entity/TaskResp.java | 6 +- .../service/impl/TaskRespServiceImpl.java | 13 +- 8 files changed, 80 insertions(+), 270 deletions(-) delete mode 100644 src/main/java/com/lz/modules/command/base1000/RecordCommand.java delete mode 100644 src/main/java/com/lz/modules/command/base1000/TaskCommand.java diff --git a/src/main/java/com/lz/modules/command/BaseCommand.java b/src/main/java/com/lz/modules/command/BaseCommand.java index 6cd33d65..980e0a14 100644 --- a/src/main/java/com/lz/modules/command/BaseCommand.java +++ b/src/main/java/com/lz/modules/command/BaseCommand.java @@ -34,7 +34,7 @@ public abstract class BaseCommand { return (T) new Tuple(true); } - public Tuple doTaskParse (){ + public Tuple doTaskParse() { TaskDto taskDto = new TaskDto(); taskDto.setId(NumberUtil.objToLong(tokens[1])); int i = 2; 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 038d2af8..075fd6ab 100644 --- a/src/main/java/com/lz/modules/command/base1000/AddCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/AddCommand.java @@ -1,15 +1,22 @@ package com.lz.modules.command.base1000; +import com.alibaba.fastjson.JSON; import com.lz.common.utils.Constant; +import com.lz.common.utils.NumberUtil; import com.lz.common.utils.R; 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.Option; import com.lz.modules.command.annotation.Summary; +import com.lz.modules.flow.model.TaskDto; +import com.lz.modules.performance.service.ResultTaskService; +import com.lz.modules.third.service.TaskRespService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component("add") @@ -35,14 +42,36 @@ public class AddCommand extends BaseCommand implements ICommand { private String rate; private String mark; + @Autowired + private TaskRespService taskRespService; + + @Autowired + private ResultTaskService resultTaskService; + @Override public R process(Tuple tuple) throws Exception { - - return null; + tuple = doTaskParse(); + TwoTuple data = tuple.getData(); + if (!data.getFirst()) { + return R.error(data.getSecond()); + } + if (tokens.length < 3) { + return R.error("add 参数不对,如 task add 1 \"今天任务\""); + } + TaskDto taskDto = (TaskDto) tuple.getData().getSecond(); + boolean flag = taskRespService.updateIndex(user, taskDto, "list"); + if (!flag) { + return R.error("请先输入 list record"); + } + log.info(" 添加数据 :" + JSON.toJSONString(taskDto)); + R r = resultTaskService.addOrUpdateTask(user, taskDto); + if (NumberUtil.objToIntDefault(r.get("code"), 500) != 200) { //如果返回值不是200 + return r; + } + return R.ok(250, "添加任务成功"); } - @Option(index = 0, shortName = "o") @Description("任务操作") public void setOption(String option) { 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 392c9e8a..9a58468a 100644 --- a/src/main/java/com/lz/modules/command/base1000/HelpCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/HelpCommand.java @@ -14,7 +14,6 @@ import com.lz.modules.command.annotation.Name; import com.lz.modules.command.annotation.Summary; import com.lz.modules.command.utils.CLI; import com.lz.modules.command.utils.CLIConfigurator; -import com.lz.modules.sys.entity.SysUserEntity; import org.springframework.stereotype.Component; @Component("help") diff --git a/src/main/java/com/lz/modules/command/base1000/RecordCommand.java b/src/main/java/com/lz/modules/command/base1000/RecordCommand.java deleted file mode 100644 index 7f7574fd..00000000 --- a/src/main/java/com/lz/modules/command/base1000/RecordCommand.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.lz.modules.command.base1000; - -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.Option; -import com.lz.modules.command.annotation.Summary; -import com.lz.modules.sys.entity.SysUserEntity; -import com.lz.modules.sys.service.app.ResultDetailService; -import com.lz.modules.third.service.TaskRespService; -import com.lz.modules.third.utils.TaskConvertUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component("record") -@Name("record") -@Summary("查看绩效列表") -@Description(value = Constant.EXAMPLE + - " record list \n" -) -public class RecordCommand extends BaseCommand implements ICommand { - - private String l; - - @Autowired - private ResultDetailService resultDetailService; - - @Autowired - private TaskRespService taskRespService; - - @Override - public void init(SysUserEntity user, String[] tokens) throws Exception { - this.user = user; - this.tokens = tokens; - } - - @Override - public Tuple check() throws Exception { - if (!list.equals(tokens[1])) { - return new Tuple(false, "record命令的第一个参数目前只能是 list"); - } - return new Tuple(true); - } - - @Override - public Tuple parse() throws Exception { - - return new Tuple(true); - } - - @Override - public R process(Tuple o) throws Exception { - List listRecords = resultDetailService.listRecord(user); - taskRespService.deleteInsertLastResult(user, listRecords,tokens[0]); //保存索引和 id对应关系 - TwoTuple, List>> recordData = TaskConvertUtils.convert(listRecords).getData(); - return R.ok().put("header", recordData.getFirst()).put("data", recordData.getSecond()); - } - - - @Option(shortName = "list") - @Description("绩效列表") - public void setL(String l) { - this.l = l; - } - -} diff --git a/src/main/java/com/lz/modules/command/base1000/TaskCommand.java b/src/main/java/com/lz/modules/command/base1000/TaskCommand.java deleted file mode 100644 index d0a52df3..00000000 --- a/src/main/java/com/lz/modules/command/base1000/TaskCommand.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.lz.modules.command.base1000; - -import com.alibaba.fastjson.JSON; -import com.lz.common.utils.*; -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.*; -import com.lz.modules.command.utils.CLI; -import com.lz.modules.command.utils.CLIConfigurator; -import com.lz.modules.flow.model.TaskDto; -import com.lz.modules.performance.service.ResultTaskService; -import com.lz.modules.sys.entity.SysUserEntity; -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 javax.sound.midi.Soundbank; -import java.util.List; - -@Component("task") -@Name("task") -@Summary("绩效任务查看 添加 或 更新 ") -@Description(Constant.EXAMPLE + - " task add 1 \"短信开发\"\n" + - " task add 1 \"短信开发\" 30 \n" + - " task add 1 \"短信开发\" 30 \"中途遇到问题,可能会慢一点\"\n" + - " task add 1 -n \"短信开发\" -r 30 \n" + - " task add 1 -n \"短信开发\" \n" + - " task add 1 -nr \"短信开发\" 30 \n" + - " task update 1 -r 30 -m \n" + - " task add 1 -n \"短信开发\" -r 30 -m \"中途遇到问题,可能会慢一点\"\n" + - " task add 1 -nrm \"短信开发\" 30 \"中途遇到问题,可能会慢一点\"\n" -) -@Slf4j -public class TaskCommand extends BaseCommand implements ICommand { - - private String option; - private Long id; - private String name; - private String rate; - private String mark; - - @Autowired - private ResultTaskService resultTaskService; - - @Autowired - private TaskRespService taskRespService; - - - @Override - public void init(SysUserEntity user, String[] tokens) { - this.user = user; - this.tokens = tokens; - } - - @Override - public Tuple check() throws Exception { - - return new Tuple(true); - } - - @Override - public Tuple parse() throws Exception { - return new Tuple(true); - } - - - - @Override - public R process(Tuple tuple) throws Exception { - TwoTuple parse = tuple.getData(); - if (!parse.getFirst()) { - return R.error(parse.getSecond()); - } - if (add.equals(tokens[1])) { - return add(); - } else if (update.equals(tokens[1])) { - return update(); - } else if (list.equals(tokens[1])) { - return list(); - } - return R.error("未知问题"); - } - - public R add() throws Exception { - Tuple tuple = doTaskParse(); - TwoTuple data = tuple.getData(); - if (!data.getFirst()) { - return R.error(data.getSecond()); - } - if (tokens.length < 4) { - return R.error("task add 参数不对,如 task add 1 \"今天任务\""); - } - if (!NumberUtil.isNumeric(tokens[2])) { - return R.error("命令的第三个参数必需是数字"); - } - TaskDto taskDto = (TaskDto) tuple.getData().getSecond(); - boolean flag = taskRespService.updateIndex(user, taskDto,"record"); - if (!flag) { - return R.error("请先输入 list record"); - } - log.info(" 添加数据 :" + JSON.toJSONString(taskDto)); - R r = resultTaskService.addOrUpdateTask(user, taskDto); - if (NumberUtil.objToIntDefault(r.get("code"), 500) != 200) { //如果返回值不是200 - return r; - } - return R.ok(250, "添加任务成功"); - } - - public R list() 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()); - } - - public R update() { - Tuple tuple = doTaskParse(); - TwoTuple data = tuple.getData(); - if (!data.getFirst()) { - return R.error(data.getSecond()); - } - if (tokens.length < 4) { - return R.error("task add 参数不对,如 task add 1 \"今天任务\""); - } - if (!NumberUtil.isNumeric(tokens[2])) { - return R.error("命令的第三个参数必需是数字"); - } - TaskDto taskDto = (TaskDto) tuple.getData().getSecond(); - boolean flag = taskRespService.updateIndex(user, taskDto,"task"); - if (!flag) { - return R.error("请先输入 list task"); - } - log.info(" 更新数据 :" + JSON.toJSONString(taskDto)); - R r = resultTaskService.addOrUpdateTask(user, taskDto); - if (NumberUtil.objToIntDefault(r.get("code"), 500) != 200) { //如果返回值不是200 - return r; - } - return R.ok(250, "更新任务成功"); - } - - - @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/UpdateCommand.java b/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java index 93dd9fdd..6f1d3314 100644 --- a/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java @@ -1,14 +1,22 @@ package com.lz.modules.command.base1000; +import com.alibaba.fastjson.JSON; import com.lz.common.utils.Constant; +import com.lz.common.utils.NumberUtil; import com.lz.common.utils.R; 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.Option; import com.lz.modules.command.annotation.Summary; +import com.lz.modules.flow.model.TaskDto; +import com.lz.modules.performance.service.ResultTaskService; +import com.lz.modules.third.service.TaskRespService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component("add") @@ -25,6 +33,7 @@ import org.springframework.stereotype.Component; " update 1.7 -n \"短信开发\" -r 30 -m \"中途遇到问题,可能会慢一点\"\n" + " update 1.8 -nrm \"短信开发\" 30 \"中途遇到问题,可能会慢一点\"\n" ) +@Slf4j public class UpdateCommand extends BaseCommand implements ICommand { @@ -34,14 +43,35 @@ public class UpdateCommand extends BaseCommand implements ICommand private String rate; private String mark; + @Autowired + private TaskRespService taskRespService; + + @Autowired + private ResultTaskService resultTaskService; + @Override public R process(Tuple tuple) throws Exception { - - return null; + tuple = doTaskParse(); + TwoTuple data = tuple.getData(); + if (!data.getFirst()) { + return R.error(data.getSecond()); + } + if (tokens.length < 3) { + return R.error("update 参数不对,如 update 1.1 \"今天任务\""); + } + TaskDto taskDto = (TaskDto) tuple.getData().getSecond(); + boolean flag = taskRespService.updateIndex(user, taskDto, "list"); + if (!flag) { + return R.error("请先输入list 或 选择正确的索引 ,如1 or 1.x"); + } + log.info(" 更新请求数据 :" + JSON.toJSONString(taskDto)); + R r = resultTaskService.addOrUpdateTask(user, taskDto); + if (NumberUtil.objToIntDefault(r.get("code"), 500) != 200) { //如果返回值不是200 + return r; + } + return R.ok(250, "更新任务成功"); } - - @Option(index = 0, shortName = "o") @Description("任务操作") public void setOption(String option) { @@ -74,5 +104,4 @@ public class UpdateCommand extends BaseCommand implements ICommand } - } diff --git a/src/main/java/com/lz/modules/third/entity/TaskResp.java b/src/main/java/com/lz/modules/third/entity/TaskResp.java index ef93ca4b..400e2f27 100644 --- a/src/main/java/com/lz/modules/third/entity/TaskResp.java +++ b/src/main/java/com/lz/modules/third/entity/TaskResp.java @@ -31,7 +31,7 @@ public class TaskResp implements java.io.Serializable { private Date gmtModified; //索引 @ApiModelProperty(value = "索引 ", name = "indexId") - private Long indexId; + private String indexId; //用户 id @ApiModelProperty(value = "用户 id", name = "userId") private Long userId; @@ -111,14 +111,14 @@ public class TaskResp implements java.io.Serializable { * 索引 * @return */ - public Long getIndexId() { + public String getIndexId() { return indexId; } /** * 索引 * @param indexId */ - public void setIndexId(Long indexId) { + public void setIndexId(String indexId) { this.indexId = indexId; } diff --git a/src/main/java/com/lz/modules/third/service/impl/TaskRespServiceImpl.java b/src/main/java/com/lz/modules/third/service/impl/TaskRespServiceImpl.java index 2b54bd48..c6959445 100644 --- a/src/main/java/com/lz/modules/third/service/impl/TaskRespServiceImpl.java +++ b/src/main/java/com/lz/modules/third/service/impl/TaskRespServiceImpl.java @@ -2,6 +2,7 @@ package com.lz.modules.third.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.lz.modules.app.dto.ResultDto; +import com.lz.modules.command.BaseCommand; import com.lz.modules.flow.model.TaskDto; import com.lz.modules.sys.entity.SysUserEntity; import com.lz.modules.third.dao.TaskRespMapper; @@ -70,8 +71,9 @@ public class TaskRespServiceImpl extends ServiceImpl i List taskRespList =new ArrayList<>(); for(ResultDto resultDto : list){ TaskResp taskResp = new TaskResp(); - /*taskResp.setIndexId(resultDto.getIndex()); - taskResp.setResultId(resultDto.getId());*/ + taskResp.setIndexId(resultDto.getIndex()); + taskResp.setDetailId(resultDto.getDetailId()); + taskResp.setTaskId(resultDto.getTaskId()); taskResp.setUserId(user.getUserId()); taskResp.setContent(resultDto.getContent()); taskResp.setCommand(command); @@ -91,9 +93,14 @@ public class TaskRespServiceImpl extends ServiceImpl i public boolean updateIndex(SysUserEntity userEntity, TaskDto taskDto,String command) { TaskResp taskResp = taskRespService.selectTaskRespByUserIdIndex(userEntity.getUserId(), taskDto.getId(),command); if (taskResp != null) { - taskDto.setId(taskResp.getDetailId()); + if(BaseCommand.add.equals(taskDto.getOption())){ + taskDto.setId(taskResp.getDetailId()); + }else{ + taskDto.setId(taskResp.getTaskId()); + } return true; } + return false; }