Merge branch 'version_20210112_indicator' of http://gitlab.ldxinyong.com/enterpriseManagement/lz_management into version_20210112_indicator
This commit is contained in:
commit
66bc01223c
@ -8,4 +8,7 @@ import java.lang.annotation.*;
|
||||
public @interface TaskHeader {
|
||||
|
||||
String value ( ) default "";
|
||||
|
||||
|
||||
int order() default 0;
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.lz.common.utils;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.lz.common.cli.CliToken;
|
||||
import com.lz.common.cli.CliTokens;
|
||||
import com.lz.modules.app.utils.t.Tuple;
|
||||
@ -24,10 +25,10 @@ public class TaskCommand {
|
||||
|
||||
public static Tuple parse(String command) {
|
||||
String[] tokens = getTokens(command);
|
||||
if (commandCommands.contains(tokens[0])) {
|
||||
if (!commandCommands.contains(tokens[0])) {
|
||||
return new Tuple(488, "命令的第一个参数必需是 add or update or list");
|
||||
}
|
||||
if (optTargets.contains(tokens[1])) {
|
||||
if (!optTargets.contains(tokens[1])) {
|
||||
return new Tuple(488, "命令的第二个参数必需是 task or record");
|
||||
}
|
||||
if (task.equals(tokens[1])) { //表示对 task 增删改查
|
||||
@ -64,11 +65,6 @@ public class TaskCommand {
|
||||
|
||||
|
||||
public static Tuple doParseTaskDto(int flag ,String [] tokens){
|
||||
//task add 1 -nrm "内容" 30 "哈哈"
|
||||
//task add 1 "内容" 30 "哈哈"
|
||||
//task add 1 "内容" 30
|
||||
//task add 1 "内容"
|
||||
//task add 1 -n "内容"
|
||||
if (tokens.length < 4) {
|
||||
return new Tuple(488, "task add 参数不对,如 task add 1 \"今天任务\"");
|
||||
}
|
||||
@ -101,12 +97,14 @@ public class TaskCommand {
|
||||
taskDto.setRate(NumberUtil.objToIntDefault(know, 0));
|
||||
} else if (c == 'm') {
|
||||
taskDto.setMark(know);
|
||||
}else{
|
||||
return new Tuple(488, "-后面的参数不对,只能是 n 或 r 或 m");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (StringUtil.isBlank(taskDto.getName())) {
|
||||
taskDto.setName(notKnow);
|
||||
} else if (taskDto.getRate() != null) {
|
||||
} else if (taskDto.getRate() == null) {
|
||||
if (!NumberUtil.isNumeric(notKnow)) {
|
||||
return new Tuple(488, "进度必需是一个正整数");
|
||||
}
|
||||
@ -125,6 +123,7 @@ public class TaskCommand {
|
||||
return new Tuple(flag,taskDto);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test11() {
|
||||
String ln = " abcdef b csssss dddddd -c \"b ccc ' bb a , bb x b\" a ";
|
||||
@ -135,8 +134,21 @@ public class TaskCommand {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* //task add 1 -nrm "内容" 30 "哈哈"
|
||||
* //task add 1 "内容" 30 "哈哈"
|
||||
* //task add 1 "内容" 30
|
||||
* //task add 1 "内容"
|
||||
* //task add 1 -n "内容"
|
||||
*/
|
||||
@Test
|
||||
public void test2() {
|
||||
|
||||
//String command = "add task 1 \"哈哈\" 30 \"说明\" " ;
|
||||
//String command = "add task 1 -r \"哈哈\" \"说明\" " ;
|
||||
//String command = "add task 1 -r 30 " ;
|
||||
//String command = "add task 1 -mr \"说明\" 30 \"哈哈\"" ;
|
||||
String command = "add task 1 -m\"说明\" -r 30 \"哈哈\"" ;
|
||||
Tuple tuple = TaskCommand.parse(command);
|
||||
System.out.println(JSON.toJSONString(tuple));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.lz.modules.app.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.lz.common.cli.LineStatus;
|
||||
import com.lz.common.constant.CacheConstants;
|
||||
import com.lz.common.utils.Md5Utils;
|
||||
import com.lz.common.utils.R;
|
||||
@ -18,6 +19,9 @@ import com.lz.modules.performance.service.ResultTaskService;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.service.SysUserService;
|
||||
import com.lz.modules.sys.service.app.ResultDetailService;
|
||||
import com.lz.modules.third.entity.TaskResp;
|
||||
import com.lz.modules.third.service.TaskRespService;
|
||||
import com.lz.modules.third.utils.TaskConvertUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -49,8 +53,11 @@ public class ThirdTaskController {
|
||||
@Autowired
|
||||
private ResultDetailService resultDetailService;
|
||||
|
||||
@Autowired
|
||||
private TaskRespService taskRespService;
|
||||
|
||||
@RequestMapping("/handler")
|
||||
public R handler(@RequestBody CommandDto commandDto) {
|
||||
public R handler(@RequestBody CommandDto commandDto) throws Exception{
|
||||
SysUserEntity user = checkLogin(commandDto.getToken());
|
||||
if (user == null) {
|
||||
return R.error(499, "登陆己经过期");
|
||||
@ -63,16 +70,30 @@ public class ThirdTaskController {
|
||||
return R.error(twoTuple.getSecond());
|
||||
}
|
||||
TwoTuple<Integer, TaskDto> taskInfo = tuple.getData();
|
||||
boolean flag = true;
|
||||
switch (parseData.getFirst()) {
|
||||
case 1: //list task
|
||||
List<ResultDto> list = resultTaskService.listResultTask(user);
|
||||
break;
|
||||
taskRespService.deleteInsertLastResult(user,list); //保存索引和 id对应关系
|
||||
TwoTuple<List<String>,List<List<String>>> data = TaskConvertUtils.convert(list).getData();
|
||||
return R.ok().put("header", data.getFirst()).put("data", data.getSecond());
|
||||
case 2: //add task
|
||||
flag = updateIndex(user, taskInfo.getSecond());
|
||||
if(!flag){
|
||||
return R.error("请先输入 list record");
|
||||
}
|
||||
return resultTaskService.addOrUpdateTask(user, taskInfo.getSecond());
|
||||
case 3: //update task
|
||||
flag = updateIndex(user, taskInfo.getSecond());
|
||||
if(!flag){
|
||||
return R.error("请先输入 list task");
|
||||
}
|
||||
return resultTaskService.addOrUpdateTask(user, taskInfo.getSecond());
|
||||
case 4: //list record
|
||||
return resultDetailService.listRecord(user);
|
||||
List<ResultDto> listRecords = resultDetailService.listRecord(user);
|
||||
taskRespService.deleteInsertLastResult(user,listRecords); //保存索引和 id对应关系
|
||||
TwoTuple<List<String>,List<List<String>>> recordData = TaskConvertUtils.convert(listRecords).getData();
|
||||
return R.ok().put("header", recordData.getFirst()).put("data", recordData.getSecond());
|
||||
case 5: //TODO add record
|
||||
break;
|
||||
case 6: //TODO update record
|
||||
@ -81,12 +102,19 @@ public class ThirdTaskController {
|
||||
break;
|
||||
}
|
||||
List<List<String>> data = new ArrayList<>();
|
||||
List<String> header = new ArrayList<>(Arrays.asList(new String[]{"用户名", "密码", "哈哈", "双", "你是"}));
|
||||
List<String> header = new ArrayList<>(Arrays.asList(new String[]{"未知问题"}));
|
||||
return R.ok().put("header", header).put("data", data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean updateIndex(SysUserEntity userEntity ,TaskDto taskDto){
|
||||
TaskResp taskResp = taskRespService.selectTaskRespByUserIdIndex(userEntity.getUserId(),taskDto.getId());
|
||||
if(taskResp !=null){
|
||||
taskDto.setId(taskResp.getResultId());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public SysUserEntity checkLogin(String token) {
|
||||
Object object = redisCacheUtil.getObject(token);
|
||||
if (object != null) {
|
||||
|
||||
@ -1,38 +1,45 @@
|
||||
package com.lz.modules.app.dto;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.lz.common.annotation.TaskHeader;
|
||||
import com.lz.modules.app.utils.t.Tuple;
|
||||
import com.lz.modules.app.utils.t.TwoTuple;
|
||||
import lombok.Data;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ResultDto {
|
||||
@TaskHeader("index")
|
||||
private int index;
|
||||
@TaskHeader("id")
|
||||
@TaskHeader(value = "index", order = 0)
|
||||
private Integer index;
|
||||
@TaskHeader(value = "id", order = 1)
|
||||
private Long id;
|
||||
@TaskHeader("内容")
|
||||
@TaskHeader(value = "内容", order = 2)
|
||||
private String content;
|
||||
@TaskHeader("进度") //返回值如30%, 如果没有可以不填写
|
||||
@TaskHeader(value = "进度", order = 3) //返回值如30%, 如果没有可以不填写
|
||||
private String rate;
|
||||
|
||||
public ResultDto() {
|
||||
}
|
||||
|
||||
public ResultDto(@TaskHeader("索引") int index, @TaskHeader("Id") Long id, @TaskHeader("内容") String content) {
|
||||
public ResultDto(@TaskHeader("索引") Integer index, @TaskHeader("Id") Long id, @TaskHeader("内容") String content) {
|
||||
this.index = index;
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ResultDto resultDto1 = new ResultDto(0,10l,"哈哈0");
|
||||
ResultDto resultDto2 = new ResultDto(1,11l,"哈哈1");
|
||||
ResultDto resultDto3 = new ResultDto(2,12l,"哈哈2");
|
||||
ResultDto resultDto4 = new ResultDto(3,13l,"哈哈3");
|
||||
ResultDto [] array = new ResultDto[]{resultDto1,resultDto2,resultDto3,resultDto4};
|
||||
List<ResultDto> resultDtos = Arrays.asList(array);
|
||||
|
||||
public ResultDto(@TaskHeader("index") Integer index, @TaskHeader("id") Long id, @TaskHeader("内容") String content, @TaskHeader("进度") String rate) {
|
||||
this.index = index;
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.lz.modules.sys.service.app;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lz.common.utils.BigDecimalUtil;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.app.dto.ResultDto;
|
||||
import com.lz.modules.app.resp.ResultDetailResp;
|
||||
import com.lz.modules.app.resp.Step;
|
||||
import com.lz.modules.flow.model.Auth;
|
||||
@ -79,5 +80,5 @@ public interface ResultDetailService extends IService<ResultDetail> {
|
||||
|
||||
List<ResultDetail> selectNotNoticeResultDetailByRecordId(Long recordId);
|
||||
|
||||
R listRecord(SysUserEntity user);
|
||||
List<ResultDto> listRecord(SysUserEntity user);
|
||||
}
|
||||
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lz.common.utils.BigDecimalUtil;
|
||||
import com.lz.common.utils.Constant;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.app.dto.ResultDto;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.resp.ResultDetailResp;
|
||||
import com.lz.modules.app.resp.Step;
|
||||
@ -358,7 +359,7 @@ public class ResultDetailServiceImpl extends ServiceImpl<ResultDetailMapper, Res
|
||||
}
|
||||
|
||||
@Override
|
||||
public R listRecord(SysUserEntity user) {
|
||||
public List<ResultDto> listRecord(SysUserEntity user) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,4 +30,7 @@ public interface TaskRespMapper extends BaseMapper<TaskResp> {
|
||||
int deleteTaskRespById(@Param("id") Long id);
|
||||
|
||||
|
||||
void deleteTaskRespByUserId(@Param("userId") Long userId);
|
||||
|
||||
TaskResp selectTaskRespByUserIdIndex(@Param("userId") Long userId, @Param("index") Long index);
|
||||
}
|
||||
@ -1,8 +1,12 @@
|
||||
package com.lz.modules.third.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lz.modules.app.dto.ResultDto;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.third.entity.TaskResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户执行命令的最后一个值表 服务类
|
||||
@ -30,4 +34,7 @@ public interface TaskRespService extends IService<TaskResp> {
|
||||
int deleteTaskRespById(Long id);
|
||||
|
||||
|
||||
void deleteInsertLastResult(SysUserEntity user ,List<ResultDto> list);
|
||||
|
||||
TaskResp selectTaskRespByUserIdIndex(Long userId, Long id);
|
||||
}
|
||||
@ -1,12 +1,16 @@
|
||||
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.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.third.dao.TaskRespMapper;
|
||||
import com.lz.modules.third.entity.TaskResp;
|
||||
import com.lz.modules.third.service.TaskRespService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户执行命令的最后一个值表 服务类
|
||||
@ -58,6 +62,24 @@ public class TaskRespServiceImpl extends ServiceImpl<TaskRespMapper, TaskResp> i
|
||||
return taskRespMapper.deleteTaskRespById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteInsertLastResult(SysUserEntity user,List<ResultDto> list) {
|
||||
taskRespMapper.deleteTaskRespByUserId(user.getUserId());
|
||||
for(ResultDto resultDto : list){
|
||||
TaskResp taskResp = new TaskResp();
|
||||
taskResp.setIndex(resultDto.getIndex());
|
||||
taskResp.setResultId(resultDto.getId());
|
||||
taskResp.setUserId(user.getUserId());
|
||||
taskResp.setContent(resultDto.getContent());
|
||||
taskRespMapper.insertTaskResp(taskResp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskResp selectTaskRespByUserIdIndex(Long userId, Long index ) {
|
||||
return taskRespMapper.selectTaskRespByUserIdIndex(userId,index);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
130
src/main/java/com/lz/modules/third/utils/TaskConvertUtils.java
Normal file
130
src/main/java/com/lz/modules/third/utils/TaskConvertUtils.java
Normal file
@ -0,0 +1,130 @@
|
||||
package com.lz.modules.third.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.lz.common.annotation.TaskHeader;
|
||||
import com.lz.modules.app.dto.ResultDto;
|
||||
import com.lz.modules.app.utils.t.Tuple;
|
||||
import com.lz.modules.app.utils.t.TwoTuple;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class TaskConvertUtils {
|
||||
|
||||
public static Tuple convert(List<ResultDto> resultDtos) throws Exception {
|
||||
Field[] fields = sortFields(ResultDto.class.getDeclaredFields());
|
||||
List<String> header = new ArrayList<>();
|
||||
for (Field field : fields) {
|
||||
TaskHeader taskHeader = field.getAnnotation(TaskHeader.class);
|
||||
header.add(taskHeader.value());
|
||||
}
|
||||
Method[] methodLengths = sortMethods(ResultDto.class.getMethods());
|
||||
boolean[] indexs = new boolean[methodLengths.length];
|
||||
List<List<String>> data = new ArrayList<>();
|
||||
for (ResultDto resultDto : resultDtos) {
|
||||
Method[] methods = methodLengths;
|
||||
List<String> methodValueList = new ArrayList<>();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
String methodName = methods[i].getName();
|
||||
if (!methodName.equals("getId")) {
|
||||
Object object = methods[i].invoke(resultDto, null);
|
||||
if (object != null && object != "") {
|
||||
indexs[i] = true;
|
||||
methodValueList.add(object + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
data.add(methodValueList);
|
||||
}
|
||||
for (int i = 0; i < indexs.length; i++) {
|
||||
if (!indexs[i]) {
|
||||
header.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
return new Tuple(header, data);
|
||||
}
|
||||
|
||||
|
||||
public static Field[] sortFields(Field[] fields) {
|
||||
// 用来存放所有的属性域
|
||||
List<Field> fieldList = new ArrayList<>();
|
||||
// 过滤带有注解的Field
|
||||
for (Field f : fields) {
|
||||
if (f.getAnnotation(TaskHeader.class) != null) {
|
||||
fieldList.add(f);
|
||||
}
|
||||
}
|
||||
// 这个比较排序的语法依赖于java 1.8
|
||||
fieldList.sort(Comparator.comparingInt(
|
||||
f -> f.getAnnotation(TaskHeader.class).order()
|
||||
));
|
||||
return fieldList.toArray(new Field[fieldList.size()]);
|
||||
}
|
||||
|
||||
public static String captureName(String name) {
|
||||
char[] cs = name.toCharArray();
|
||||
cs[0] += 32;
|
||||
return String.valueOf(cs);
|
||||
}
|
||||
|
||||
|
||||
public static Method[] sortMethods(Method[] methods) {
|
||||
// 用来存放所有的属性域
|
||||
List<Method> methodList = new ArrayList<>();
|
||||
// 过滤带有注解的Field
|
||||
for (Method m : methods) {
|
||||
String mname = m.getName();
|
||||
if ((mname.startsWith("get") || mname.startsWith("Get")) && !"getClass".equals(m.getName())) {
|
||||
Class clas = m.getDeclaringClass();
|
||||
String a = mname.substring(3);
|
||||
a = captureName(a);
|
||||
try {
|
||||
Field field = clas.getDeclaredField(a);
|
||||
if (field.getAnnotation(TaskHeader.class) != null) {
|
||||
methodList.add(m);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 这个比较排序的语法依赖于java 1.8
|
||||
methodList.sort(Comparator.comparingInt(
|
||||
m -> {
|
||||
String mname = m.getName();
|
||||
Class clas = m.getDeclaringClass();
|
||||
String a = mname.substring(3);
|
||||
a = captureName(a);
|
||||
try {
|
||||
Field field = clas.getDeclaredField(a);
|
||||
int sort = field.getAnnotation(TaskHeader.class).order();
|
||||
return sort;
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 9999;
|
||||
}
|
||||
));
|
||||
return methodList.toArray(new Method[methodList.size()]);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ResultDto resultDto1 = new ResultDto(0, 10l, "哈哈0");
|
||||
ResultDto resultDto2 = new ResultDto(1, 11l, "哈哈1");
|
||||
ResultDto resultDto3 = new ResultDto(2, 12l, "哈哈2");
|
||||
ResultDto resultDto4 = new ResultDto(3, 13l, "哈哈3", "30%");
|
||||
ResultDto[] array = new ResultDto[]{resultDto1, resultDto2, resultDto3, resultDto4};
|
||||
List<ResultDto> resultDtos = Arrays.asList(array);
|
||||
TwoTuple<List<String>, List<List<String>>> data = convert(resultDtos).getData();
|
||||
System.out.println(JSON.toJSONString(data.getFirst()));
|
||||
System.out.println(JSON.toJSONString(data.getSecond()));
|
||||
|
||||
}
|
||||
}
|
||||
@ -20,9 +20,6 @@
|
||||
id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, index AS index, user_id AS userId, result_id AS resultId, content AS content
|
||||
</sql>
|
||||
|
||||
|
||||
|
||||
|
||||
<select id="selectTaskRespById" resultType="TaskResp" >
|
||||
select * from lz_task_resp where id=#{id} and is_delete = 0 limit 1
|
||||
</select>
|
||||
@ -84,5 +81,15 @@
|
||||
update lz_task_resp set is_delete = 1 where id=#{id} limit 1
|
||||
</update>
|
||||
|
||||
<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=#{index} and user_id = #{userId} and is_delete = 0 limit 1
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user