From 55199060d929f8fbcee0a13697796c98077bceda Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Tue, 26 Jan 2021 18:38:12 +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 --- .../java/com/lz/common/utils/TaskCommand.java | 9 ++- .../app/controller/ThirdTaskController.java | 7 +- .../modules/command/base1000/HelpCommand.java | 13 ++-- .../command/base1000/RecordCommand.java | 9 ++- .../modules/command/base1000/TaskCommand.java | 69 +++++++++++++------ .../lz/modules/third/dao/TaskRespMapper.java | 2 +- .../com/lz/modules/third/entity/TaskResp.java | 19 +++++ .../third/service/TaskRespService.java | 6 +- .../service/impl/TaskRespServiceImpl.java | 12 ++-- .../resources/mapper/third/TaskRespMapper.xml | 69 +++++++++++-------- 10 files changed, 145 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/lz/common/utils/TaskCommand.java b/src/main/java/com/lz/common/utils/TaskCommand.java index 46474fb9..92e05aca 100644 --- a/src/main/java/com/lz/common/utils/TaskCommand.java +++ b/src/main/java/com/lz/common/utils/TaskCommand.java @@ -5,18 +5,21 @@ import com.lz.common.cli.CliToken; import com.lz.common.cli.CliTokens; import com.lz.modules.app.utils.t.Tuple; import com.lz.modules.flow.model.TaskDto; +import lombok.extern.slf4j.Slf4j; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +@Slf4j public class TaskCommand { public static String[] parse(String command) { - command = command.replaceAll("\\\\u0000", ""); //替换掉前面的空格 + log.info("parse command : " + command); + return getTokens(command); } @@ -55,8 +58,8 @@ public class TaskCommand { //String command = "add task 1 -r \"哈哈\" \"说明\" " ; //String command = "add task 1 -r 30 " ; //String command = "add task 1 -mr \"说明\" 30 \"哈哈\"" ; - String command = "" ; - String[] tokens = getTokens(command); + String command = "\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000task list" ; + String[] tokens = parse(command); System.out.println(Arrays.toString(tokens)); } } diff --git a/src/main/java/com/lz/modules/app/controller/ThirdTaskController.java b/src/main/java/com/lz/modules/app/controller/ThirdTaskController.java index 6eea2347..66b10dd5 100644 --- a/src/main/java/com/lz/modules/app/controller/ThirdTaskController.java +++ b/src/main/java/com/lz/modules/app/controller/ThirdTaskController.java @@ -1,6 +1,7 @@ package com.lz.modules.app.controller; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.lz.common.constant.CacheConstants; import com.lz.common.utils.*; import com.lz.modules.app.dto.CommandDto; @@ -56,7 +57,11 @@ public class ThirdTaskController { if (user == null) { return R.error(499, "登陆己经过期"); } - log.info("commandDto:" + JSON.toJSONString(commandDto)); + String a = JSON.toJSONString(commandDto); + log.info("commandDto:" + a); + a = a.replaceAll("\\\\u0000", ""); //替换掉前面的空格 + log.info("替换空格之后的命令:" + a); + commandDto = JSONObject.parseObject(a,CommandDto.class); String[] tokens = TaskCommand.parse(commandDto.getCommand()); log.info("parse data :" + Arrays.toString(tokens)); Object object = SpringContextUtils.getBean(tokens[0]); 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 75967d21..17c69200 100644 --- a/src/main/java/com/lz/modules/command/base1000/HelpCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/HelpCommand.java @@ -19,16 +19,16 @@ import org.springframework.stereotype.Component; @Component("help") @Name("help") -@Summary("帮助") +@Summary("help") @Description(Constant.EXAMPLE + " help\n" - + " help task\n" - + " help record\n") + + " help task : 任务命令使用\n" + + " help record : 绩效命令使用\n") public class HelpCommand extends BaseCommand implements ICommand { private String cmd; - @Argument(index = 0, argName = "task", required = false) + @Argument(index = 0, argName = "task or record", required = false) @Description("command name") public void setCmd(String cmd) { this.cmd = cmd; @@ -41,7 +41,8 @@ public class HelpCommand extends BaseCommand implements ICommand { @Override public void init(SysUserEntity user, String[] tokens) throws Exception { - + this.user = user; + this.tokens = tokens; } @Override @@ -72,6 +73,6 @@ public class HelpCommand extends BaseCommand implements ICommand { cliDto.setName(cli.getName()); cliDto.setOptions(cli.getOptions()); cliDto.setSummary(cli.getSummary()); - return R.ok().put("cliDto", cliDto); + return R.ok(422).put("cliDto", cliDto); } } diff --git a/src/main/java/com/lz/modules/command/base1000/RecordCommand.java b/src/main/java/com/lz/modules/command/base1000/RecordCommand.java index f63beb68..a22d44e4 100644 --- a/src/main/java/com/lz/modules/command/base1000/RecordCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/RecordCommand.java @@ -27,6 +27,7 @@ import java.util.List; ) public class RecordCommand extends BaseCommand implements ICommand { + private String l; @Autowired private ResultDetailService resultDetailService; @@ -57,8 +58,14 @@ public class RecordCommand extends BaseCommand implements ICommand { @Override public R process(Tuple o) throws Exception { List listRecords = resultDetailService.listRecord(user); - taskRespService.deleteInsertLastResult(user, listRecords); //保存索引和 id对应关系 + 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()); } + + + + + + } 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 c764a349..9091e14b 100644 --- a/src/main/java/com/lz/modules/command/base1000/TaskCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/TaskCommand.java @@ -1,5 +1,6 @@ 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; @@ -15,6 +16,7 @@ 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; @@ -34,6 +36,7 @@ import java.util.List; " 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; @@ -57,17 +60,16 @@ public class TaskCommand extends BaseCommand implements ICommand { @Override public Tuple check() throws Exception { - if (tokens.length < 4) { - return new Tuple(false, "task add 参数不对,如 task add 1 \"今天任务\""); - } - if (!NumberUtil.isNumeric(tokens[2])) { - return new Tuple(false, "命令的第三个参数必需是数字"); - } + return new Tuple(true); } @Override public Tuple parse() throws Exception { + return new Tuple(true); + } + + public Tuple doParse (){ TaskDto taskDto = new TaskDto(); taskDto.setId(NumberUtil.objToLong(tokens[2])); int i = 3; @@ -101,7 +103,7 @@ public class TaskCommand extends BaseCommand implements ICommand { i++; } taskDto.setOption(tokens[1]); - return new Tuple(false, taskDto); + return new Tuple(true, taskDto); } @Override @@ -110,22 +112,34 @@ public class TaskCommand extends BaseCommand implements ICommand { if (!parse.getFirst()) { return R.error(parse.getSecond()); } - TwoTuple taskData = tuple.getData(); if (add.equals(tokens[1])) { - return add(taskData.getSecond()); + return add(); } else if (update.equals(tokens[1])) { - return update(taskData.getSecond()); + return update(); } else if (list.equals(tokens[1])) { return list(); } return R.error("未知问题"); } - public R add(TaskDto taskDto) throws Exception { - boolean flag = taskRespService.updateIndex(user, taskDto); + public R add() throws Exception { + Tuple tuple = doParse(); + 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; @@ -135,16 +149,29 @@ public class TaskCommand extends BaseCommand implements ICommand { public R list() throws Exception { List list = resultTaskService.listResultTask(user); - taskRespService.deleteInsertLastResult(user, list); //保存索引和 id对应关系 + 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(TaskDto taskDto) { - boolean flag = taskRespService.updateIndex(user, taskDto); + public R update() { + Tuple tuple = doParse(); + 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; @@ -154,34 +181,36 @@ public class TaskCommand extends BaseCommand implements ICommand { @Argument(index = 0, argName = "option") - @Option(shortName = "o", longName = "option") + @Option(shortName = "o") @Description("任务操作") public void setOption(String option) { this.option = option; } - @Option(shortName = "id", longName = "id") + @Option(shortName = "id") @Description("任务 id") public void setId(Long id) { this.id = id; } - @Option(shortName = "n", longName = "name") + @Option(shortName = "n") @Description("任务名称") public void setName(String name) { this.name = name; } - @Option(shortName = "r", longName = "rate") + @Option(shortName = "r") @Description("任务进度") public void setRate(String rate) { this.rate = rate; } - @Option(shortName = "m", longName = "mark") + @Option(shortName = "m") @Description("任务说明") public void setMark(String mark) { this.mark = mark; } + + } diff --git a/src/main/java/com/lz/modules/third/dao/TaskRespMapper.java b/src/main/java/com/lz/modules/third/dao/TaskRespMapper.java index 436164a2..9458d12e 100644 --- a/src/main/java/com/lz/modules/third/dao/TaskRespMapper.java +++ b/src/main/java/com/lz/modules/third/dao/TaskRespMapper.java @@ -35,7 +35,7 @@ public interface TaskRespMapper extends BaseMapper { void deleteTaskRespByUserId(@Param("userId") Long userId); - TaskResp selectTaskRespByUserIdIndex(@Param("userId") Long userId, @Param("index") Long index); + TaskResp selectTaskRespByUserIdIndex(@Param("userId") Long userId, @Param("index") Long index, @Param("command") String command); void batchInsertTaskRespList(@Param("taskRespList") List taskRespList); } \ No newline at end of file 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 d16ea326..0716ee2f 100644 --- a/src/main/java/com/lz/modules/third/entity/TaskResp.java +++ b/src/main/java/com/lz/modules/third/entity/TaskResp.java @@ -41,6 +41,9 @@ public class TaskResp implements java.io.Serializable { //返回值内容 @ApiModelProperty(value = "返回值内容", name = "content") private String content; + // + @ApiModelProperty(value = "", name = "command") + private String command; /** * * @return @@ -161,6 +164,21 @@ public class TaskResp implements java.io.Serializable { this.content = content; } + /** + * + * @return + */ + public String getCommand() { + return command; + } + /** + * + * @param command + */ + public void setCommand(String command) { + this.command = command; + } + @Override public String toString() { return "TaskResp{" + @@ -172,6 +190,7 @@ public class TaskResp implements java.io.Serializable { ",userId=" + userId + ",resultId=" + resultId + ",content=" + content + + ",command=" + command + "}"; } } \ No newline at end of file diff --git a/src/main/java/com/lz/modules/third/service/TaskRespService.java b/src/main/java/com/lz/modules/third/service/TaskRespService.java index 407a6dce..22d78fa5 100644 --- a/src/main/java/com/lz/modules/third/service/TaskRespService.java +++ b/src/main/java/com/lz/modules/third/service/TaskRespService.java @@ -35,9 +35,9 @@ public interface TaskRespService extends IService { int deleteTaskRespById(Long id); - void deleteInsertLastResult(SysUserEntity user ,List list); + void deleteInsertLastResult(SysUserEntity user ,List list,String command); - TaskResp selectTaskRespByUserIdIndex(Long userId, Long id); + TaskResp selectTaskRespByUserIdIndex(Long userId, Long id,String command); - boolean updateIndex(SysUserEntity userEntity, TaskDto taskDto); + boolean updateIndex(SysUserEntity userEntity, TaskDto taskDto,String command); } \ No newline at end of file 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 8e69d60b..9f067074 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 @@ -65,7 +65,7 @@ public class TaskRespServiceImpl extends ServiceImpl i } @Override - public void deleteInsertLastResult(SysUserEntity user,List list) { + public void deleteInsertLastResult(SysUserEntity user,List list,String command) { taskRespMapper.deleteTaskRespByUserId(user.getUserId()); List taskRespList =new ArrayList<>(); for(ResultDto resultDto : list){ @@ -74,6 +74,7 @@ public class TaskRespServiceImpl extends ServiceImpl i taskResp.setResultId(resultDto.getId()); taskResp.setUserId(user.getUserId()); taskResp.setContent(resultDto.getContent()); + taskResp.setCommand(command); taskRespList.add(taskResp); } if (CollectionUtils.isNotEmpty(taskRespList)) { @@ -82,12 +83,13 @@ public class TaskRespServiceImpl extends ServiceImpl i } @Override - public TaskResp selectTaskRespByUserIdIndex(Long userId, Long index ) { - return taskRespMapper.selectTaskRespByUserIdIndex(userId,index); + public TaskResp selectTaskRespByUserIdIndex(Long userId, Long index,String command ) { + return taskRespMapper.selectTaskRespByUserIdIndex(userId,index,command); } - public boolean updateIndex(SysUserEntity userEntity, TaskDto taskDto) { - TaskResp taskResp = taskRespService.selectTaskRespByUserIdIndex(userEntity.getUserId(), taskDto.getId()); + + public boolean updateIndex(SysUserEntity userEntity, TaskDto taskDto,String command) { + TaskResp taskResp = taskRespService.selectTaskRespByUserIdIndex(userEntity.getUserId(), taskDto.getId(),command); if (taskResp != null) { taskDto.setId(taskResp.getResultId()); return true; diff --git a/src/main/resources/mapper/third/TaskRespMapper.xml b/src/main/resources/mapper/third/TaskRespMapper.xml index b35ae983..601181cd 100644 --- a/src/main/resources/mapper/third/TaskRespMapper.xml +++ b/src/main/resources/mapper/third/TaskRespMapper.xml @@ -12,12 +12,13 @@ + - id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, index_id AS indexId, user_id AS userId, result_id AS resultId, content AS content + id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, index_id AS indexId, user_id AS userId, result_id AS resultId, content AS content, command AS command @@ -34,6 +35,7 @@ user_id, result_id, content, + command, is_delete, gmt_create, gmt_modified @@ -42,6 +44,7 @@ #{ userId}, #{ resultId}, #{ content}, + #{ command}, 0, now(), now() @@ -49,31 +52,6 @@ - - insert into lz_task_resp( - index_id, - user_id, - result_id, - content, - is_delete, - gmt_create, - gmt_modified - ) values - - ( - #{ item.indexId}, - #{ item.userId}, - #{ item.resultId}, - #{ item.content}, - 0, - now(), - now() - ) - - - - - update lz_task_resp @@ -83,7 +61,8 @@ index_id = #{indexId}, user_id = #{userId}, result_id = #{resultId}, - content = #{content} + content = #{content}, + command = #{command} ,gmt_modified = now() where id = #{id} @@ -99,22 +78,52 @@ index_id = #{indexId}, user_id = #{userId}, result_id = #{resultId}, - content = #{content} + content = #{content}, + command = #{command} ,gmt_modified = now() where id = #{id} - update lz_task_resp set is_delete = 1 where id=#{id} limit 1 + update lz_task_resp set is_delete = 1 where id=#{id} limit 1 + + + insert into lz_task_resp( + index_id, + user_id, + result_id, + content, + command, + is_delete, + gmt_create, + gmt_modified + ) values + + ( + #{ item.indexId}, + #{ item.userId}, + #{ item.resultId}, + #{ item.content}, + #{ item.command}, + 0, + now(), + now() + ) + + + + + + delete from lz_task_resp where user_id = #{userId}