提交修改
This commit is contained in:
parent
39b421b797
commit
55199060d9
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ import java.util.List;
|
||||
)
|
||||
public class RecordCommand extends BaseCommand implements ICommand<Tuple> {
|
||||
|
||||
private String l;
|
||||
|
||||
@Autowired
|
||||
private ResultDetailService resultDetailService;
|
||||
@ -57,8 +58,14 @@ public class RecordCommand extends BaseCommand implements ICommand<Tuple> {
|
||||
@Override
|
||||
public R process(Tuple o) throws Exception {
|
||||
List<ResultDto> listRecords = resultDetailService.listRecord(user);
|
||||
taskRespService.deleteInsertLastResult(user, listRecords); //保存索引和 id对应关系
|
||||
taskRespService.deleteInsertLastResult(user, listRecords,tokens[0]); //保存索引和 id对应关系
|
||||
TwoTuple<List<String>, List<List<String>>> recordData = TaskConvertUtils.convert(listRecords).getData();
|
||||
return R.ok().put("header", recordData.getFirst()).put("data", recordData.getSecond());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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<Tuple> {
|
||||
|
||||
private String option;
|
||||
@ -57,17 +60,16 @@ public class TaskCommand extends BaseCommand implements ICommand<Tuple> {
|
||||
|
||||
@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<Tuple> {
|
||||
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<Tuple> {
|
||||
if (!parse.getFirst()) {
|
||||
return R.error(parse.getSecond());
|
||||
}
|
||||
TwoTuple<Boolean, TaskDto> 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<Boolean, String> 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<Tuple> {
|
||||
|
||||
public R list() throws Exception {
|
||||
List<ResultDto> list = resultTaskService.listResultTask(user);
|
||||
taskRespService.deleteInsertLastResult(user, list); //保存索引和 id对应关系
|
||||
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());
|
||||
}
|
||||
|
||||
public R update(TaskDto taskDto) {
|
||||
boolean flag = taskRespService.updateIndex(user, taskDto);
|
||||
public R update() {
|
||||
Tuple tuple = doParse();
|
||||
TwoTuple<Boolean, String> 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<Tuple> {
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public interface TaskRespMapper extends BaseMapper<TaskResp> {
|
||||
|
||||
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<TaskResp> taskRespList);
|
||||
}
|
||||
@ -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 +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@ -35,9 +35,9 @@ public interface TaskRespService extends IService<TaskResp> {
|
||||
int deleteTaskRespById(Long id);
|
||||
|
||||
|
||||
void deleteInsertLastResult(SysUserEntity user ,List<ResultDto> list);
|
||||
void deleteInsertLastResult(SysUserEntity user ,List<ResultDto> 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);
|
||||
}
|
||||
@ -65,7 +65,7 @@ public class TaskRespServiceImpl extends ServiceImpl<TaskRespMapper, TaskResp> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteInsertLastResult(SysUserEntity user,List<ResultDto> list) {
|
||||
public void deleteInsertLastResult(SysUserEntity user,List<ResultDto> list,String command) {
|
||||
taskRespMapper.deleteTaskRespByUserId(user.getUserId());
|
||||
List<TaskResp> taskRespList =new ArrayList<>();
|
||||
for(ResultDto resultDto : list){
|
||||
@ -74,6 +74,7 @@ public class TaskRespServiceImpl extends ServiceImpl<TaskRespMapper, TaskResp> 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<TaskRespMapper, TaskResp> 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;
|
||||
|
||||
@ -12,12 +12,13 @@
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="result_id" property="resultId"/>
|
||||
<result column="content" property="content"/>
|
||||
<result column="command" property="command"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
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
|
||||
</sql>
|
||||
|
||||
|
||||
@ -34,6 +35,7 @@
|
||||
<if test="userId != null">user_id, </if>
|
||||
<if test="resultId != null">result_id, </if>
|
||||
<if test="content != null">content, </if>
|
||||
<if test="command != null">command, </if>
|
||||
is_delete,
|
||||
gmt_create,
|
||||
gmt_modified
|
||||
@ -42,6 +44,7 @@
|
||||
<if test="userId != null">#{ userId}, </if>
|
||||
<if test="resultId != null">#{ resultId}, </if>
|
||||
<if test="content != null">#{ content}, </if>
|
||||
<if test="command != null">#{ command}, </if>
|
||||
0,
|
||||
now(),
|
||||
now()
|
||||
@ -49,31 +52,6 @@
|
||||
</insert>
|
||||
|
||||
|
||||
<insert id="batchInsertTaskRespList">
|
||||
insert into lz_task_resp(
|
||||
index_id,
|
||||
user_id,
|
||||
result_id,
|
||||
content,
|
||||
is_delete,
|
||||
gmt_create,
|
||||
gmt_modified
|
||||
) values
|
||||
<foreach collection="taskRespList" item="item" separator=",">
|
||||
(
|
||||
#{ item.indexId},
|
||||
#{ item.userId},
|
||||
#{ item.resultId},
|
||||
#{ item.content},
|
||||
0,
|
||||
now(),
|
||||
now()
|
||||
)
|
||||
</foreach>
|
||||
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateTaskRespById" parameterType="TaskResp" >
|
||||
update
|
||||
lz_task_resp
|
||||
@ -83,7 +61,8 @@
|
||||
<if test="indexId != null">index_id = #{indexId},</if>
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
<if test="resultId != null">result_id = #{resultId},</if>
|
||||
<if test="content != null">content = #{content}</if>
|
||||
<if test="content != null">content = #{content},</if>
|
||||
<if test="command != null">command = #{command}</if>
|
||||
</trim>
|
||||
,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>
|
||||
|
||||
|
||||
<update id="deleteTaskRespById" parameterType="java.lang.Long">
|
||||
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
|
||||
</update>
|
||||
|
||||
|
||||
<insert id="batchInsertTaskRespList">
|
||||
insert into lz_task_resp(
|
||||
index_id,
|
||||
user_id,
|
||||
result_id,
|
||||
content,
|
||||
command,
|
||||
is_delete,
|
||||
gmt_create,
|
||||
gmt_modified
|
||||
) values
|
||||
<foreach collection="taskRespList" item="item" separator=",">
|
||||
(
|
||||
#{ item.indexId},
|
||||
#{ item.userId},
|
||||
#{ item.resultId},
|
||||
#{ item.content},
|
||||
#{ item.command},
|
||||
0,
|
||||
now(),
|
||||
now()
|
||||
)
|
||||
</foreach>
|
||||
|
||||
</insert>
|
||||
|
||||
|
||||
|
||||
<delete id="deleteTaskRespByUserId">
|
||||
delete from lz_task_resp where user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
<select id="selectTaskRespByUserIdIndex" resultType="com.lz.modules.third.entity.TaskResp">
|
||||
select * from lz_task_resp where index_id=#{index} and user_id = #{userId} and is_delete = 0 limit 1
|
||||
select * from lz_task_resp where index_id=#{index} and user_id = #{userId} and is_delete = 0 and command = #{command} limit 1
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user