From 023d3afdee962f5f655fb5cde10dc44a0775ab46 Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Wed, 27 Jan 2021 14:24:17 +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/StringUtil.java | 41 +- .../com/lz/modules/app/dto/ResultDto.java | 9 + .../com/lz/modules/command/BaseCommand.java | 1 + .../command/base1000/UpdateCommand.java | 14 +- .../performance/dao/ResultTaskMapper.java | 2 + .../service/impl/ResultTaskServiceImpl.java | 575 +++++++++--------- .../sys/service/app/ResultDetailService.java | 2 +- .../app/impl/ResultDetailServiceImpl.java | 11 +- .../lz/modules/third/dao/TaskRespMapper.java | 2 +- .../third/service/TaskRespService.java | 2 +- .../service/impl/TaskRespServiceImpl.java | 4 +- .../modules/third/utils/TaskConvertUtils.java | 12 +- .../mapper/app/ResultDetailMapper.xml | 6 +- .../mapper/performance/ResultTaskMapper.xml | 7 +- 14 files changed, 375 insertions(+), 313 deletions(-) diff --git a/src/main/java/com/lz/common/utils/StringUtil.java b/src/main/java/com/lz/common/utils/StringUtil.java index 584e63c4..444b5b48 100644 --- a/src/main/java/com/lz/common/utils/StringUtil.java +++ b/src/main/java/com/lz/common/utils/StringUtil.java @@ -3,8 +3,11 @@ package com.lz.common.utils; import org.apache.commons.lang.StringUtils; import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.URLDecoder; import java.net.URLEncoder; +import java.text.DecimalFormat; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -653,11 +656,6 @@ public class StringUtil extends StringUtils { return value; } - public static void main(String[] args) { - - System.out.println(realNameTo2("xxxxx")); - } - /** * fmai 根据基数产生随机5位数 * @@ -726,4 +724,37 @@ public class StringUtil extends StringUtils { } return longList; } + + public static String formateRate(BigDecimal processRate,int multiply) { + if(processRate == null){ + return "0 %"; + } + processRate = processRate.multiply(new BigDecimal(multiply)); + System.out.println(processRate); + DecimalFormat df = new DecimalFormat("0"); + df.setRoundingMode(RoundingMode.HALF_UP); + return df.format(processRate)+" %"; + + } + + + public static String formateRate(String rate,int multiply) { + if(StringUtil.isEmpty(rate)) { + return "0 %"; + } + BigDecimal processRate = NumberUtil.objToBigDecimalDefault(rate, BigDecimal.ZERO).multiply(new BigDecimal(multiply)); + System.out.println(processRate); + DecimalFormat df = new DecimalFormat("0"); + df.setRoundingMode(RoundingMode.HALF_UP); + return df.format(processRate) + " %"; + + } + + public static void main(String[] args) { + System.out.println(formateRate(new BigDecimal(0.32),100)); + } + + + + } diff --git a/src/main/java/com/lz/modules/app/dto/ResultDto.java b/src/main/java/com/lz/modules/app/dto/ResultDto.java index f85f0c62..bfc2c60b 100644 --- a/src/main/java/com/lz/modules/app/dto/ResultDto.java +++ b/src/main/java/com/lz/modules/app/dto/ResultDto.java @@ -31,4 +31,13 @@ public class ResultDto { + + public ResultDto(@TaskHeader(value = "index", order = 0) String index, @TaskHeader(value = "进度", order = 1) String rate, Long detailId, @TaskHeader(value = "内容", order = 3) String content) { + this.index = index; + this.rate = rate; + this.detailId = detailId; + this.taskId = taskId; + this.content = content; + } + } diff --git a/src/main/java/com/lz/modules/command/BaseCommand.java b/src/main/java/com/lz/modules/command/BaseCommand.java index 980e0a14..b689aa9a 100644 --- a/src/main/java/com/lz/modules/command/BaseCommand.java +++ b/src/main/java/com/lz/modules/command/BaseCommand.java @@ -68,6 +68,7 @@ public abstract class BaseCommand { i++; } taskDto.setOption(tokens[0]); + taskDto.setIndex(tokens[1]); return new Tuple(true, taskDto); } 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 6f1d3314..ea6e914f 100644 --- a/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java +++ b/src/main/java/com/lz/modules/command/base1000/UpdateCommand.java @@ -19,8 +19,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -@Component("add") -@Name("add") +@Component("update") +@Name("update") @Summary("绩效任务查看 添加 或 更新 ") @Description(Constant.EXAMPLE + " update 1 \"短信开发\"\n" + @@ -46,9 +46,17 @@ public class UpdateCommand extends BaseCommand implements ICommand @Autowired private TaskRespService taskRespService; + @Autowired private ResultTaskService resultTaskService; + public Tuple check() throws Exception { + if(!tokens[1].contains(".")){ + return new Tuple(true,"目前绩效不支持更新,只有任务才支持更新"); + } + return new Tuple(true); + } + @Override public R process(Tuple tuple) throws Exception { tuple = doTaskParse(); @@ -62,7 +70,7 @@ public class UpdateCommand extends BaseCommand implements ICommand TaskDto taskDto = (TaskDto) tuple.getData().getSecond(); boolean flag = taskRespService.updateIndex(user, taskDto, "list"); if (!flag) { - return R.error("请先输入list 或 选择正确的索引 ,如1 or 1.x"); + return R.error("请先输入list或选择正确的索引,如1 or 1.x,或你输入的x.x不存在"); } log.info(" 更新请求数据 :" + JSON.toJSONString(taskDto)); R r = resultTaskService.addOrUpdateTask(user, taskDto); diff --git a/src/main/java/com/lz/modules/performance/dao/ResultTaskMapper.java b/src/main/java/com/lz/modules/performance/dao/ResultTaskMapper.java index 6ecc383b..31cd26f6 100644 --- a/src/main/java/com/lz/modules/performance/dao/ResultTaskMapper.java +++ b/src/main/java/com/lz/modules/performance/dao/ResultTaskMapper.java @@ -44,4 +44,6 @@ public interface ResultTaskMapper extends BaseMapper { int deleteResultTasksByDetailId(Long detailId); List listResultTask(@Param("detailIds") List detailIds); + + List listResultTaskByDetailId(@Param("detailIds") List detailIds); } \ No newline at end of file diff --git a/src/main/java/com/lz/modules/performance/service/impl/ResultTaskServiceImpl.java b/src/main/java/com/lz/modules/performance/service/impl/ResultTaskServiceImpl.java index aaf12da4..dd61e035 100644 --- a/src/main/java/com/lz/modules/performance/service/impl/ResultTaskServiceImpl.java +++ b/src/main/java/com/lz/modules/performance/service/impl/ResultTaskServiceImpl.java @@ -25,27 +25,21 @@ import com.lz.modules.sys.entity.app.ResultDetail; import com.lz.modules.sys.service.app.ResultDetailService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; +import java.util.*; /** -*

-* 任务表 服务类 -*

-* -* @author quyixiao -* @since 2020-12-08 -*/ + *

+ * 任务表 服务类 + *

+ * + * @author quyixiao + * @since 2020-12-08 + */ @Slf4j @Service @@ -53,223 +47,218 @@ public class ResultTaskServiceImpl extends ServiceImpl resultTasks = resultTaskMapper.selectResultTaskDtosByDetailId(detailId); - @Override - public ResultTaskDetailRes taskDetail(Long detailId) { - ResultTaskDetailRes res = new ResultTaskDetailRes(); - StaffEntity staffEntity = null; - ResultDetail resultDetail = resultDetailService.selectResultDetailById(detailId); - if(resultDetail != null){ - res.setProcessRate(resultDetail.getProcessRate()); - res.setTarget(resultDetail.getTarget()); - Long staffId = resultDetail.getStaffId(); - staffEntity = staffService.selectStaffById(staffId); - } - List resultTasks = resultTaskMapper.selectResultTaskDtosByDetailId(detailId); - - //获取最近更新记录 - if(CollectionUtils.isNotEmpty(resultTasks)){ - StaffEntity finalStaffEntity = staffEntity; - resultTasks.forEach(resultTaskDto -> { + //获取最近更新记录 + if (CollectionUtils.isNotEmpty(resultTasks)) { + StaffEntity finalStaffEntity = staffEntity; + resultTasks.forEach(resultTaskDto -> { TaskProcessRecordDto taskProcessRecordDto = taskProcessRecordMapper.selectTaskProcessRecordLastByTaskId(resultTaskDto.getId()); - if(taskProcessRecordDto != null){ - //resultTaskDto.setLabel(taskProcessRecordDto.getLabel()); - if(taskProcessRecordDto.getUseType()==0){ - ProcessRecordEnum byType = ProcessRecordEnum.findByType(taskProcessRecordDto.getType()); - Optional.ofNullable(byType).ifPresent(processRecordEnum -> resultTaskDto.setTypeDesc(byType.getDesc())); - if(finalStaffEntity !=null){ - resultTaskDto.setAvatar(finalStaffEntity.getAvatar()); - resultTaskDto.setStaffName(finalStaffEntity.getName()); - } - } - if(taskProcessRecordDto.getUseType()==1){ - resultTaskDto.setTypeDesc(taskProcessRecordDto.getLabel()); - StaffEntity staffEntity1 = staffService.selectStaffById(taskProcessRecordDto.getStaffId()); - if(staffEntity1 !=null){ - resultTaskDto.setAvatar(staffEntity1.getAvatar()); - resultTaskDto.setStaffName(staffEntity1.getName()); + if (taskProcessRecordDto != null) { + //resultTaskDto.setLabel(taskProcessRecordDto.getLabel()); + if (taskProcessRecordDto.getUseType() == 0) { + ProcessRecordEnum byType = ProcessRecordEnum.findByType(taskProcessRecordDto.getType()); + Optional.ofNullable(byType).ifPresent(processRecordEnum -> resultTaskDto.setTypeDesc(byType.getDesc())); + if (finalStaffEntity != null) { + resultTaskDto.setAvatar(finalStaffEntity.getAvatar()); + resultTaskDto.setStaffName(finalStaffEntity.getName()); + } + } + if (taskProcessRecordDto.getUseType() == 1) { + resultTaskDto.setTypeDesc(taskProcessRecordDto.getLabel()); + StaffEntity staffEntity1 = staffService.selectStaffById(taskProcessRecordDto.getStaffId()); + if (staffEntity1 != null) { + resultTaskDto.setAvatar(staffEntity1.getAvatar()); + resultTaskDto.setStaffName(staffEntity1.getName()); - } + } - } + } } }); - } - res.setResultTasks(resultTasks); - return res; - } + } + res.setResultTasks(resultTasks); + return res; + } - @Override - public R saveOrUpdateResultTask(ResultUpdateTaskReq req, Long userId) { - Long tasklId = req.getTaskId(); - Long detailId = req.getDetailId(); - if(tasklId == null && detailId == null){ - log.error("任务保存或更新失败:tasklId, detailId都为空"); - return R.error(); - } - ResultTask resultTask; - if(tasklId == null){ - log.info("绩效任务新增操作。。。"); - ResultDetail resultDetail = resultDetailService.selectResultDetailById(req.getDetailId()); - if(!userId.equals(resultDetail.getStaffId())){ - log.info("非本人任务不能添加"); - return R.error("非本人任务不能添加"); - } - resultTask = new ResultTask(); - BeanUtils.copyProperties(req,resultTask); - resultTask.setDetailId(detailId); - resultTaskMapper.insertResultTask(resultTask); - //将插入的id传递过去 - req.setTaskId(resultTask.getId()); - changeTaskProcess(null, req,null); - } - else { + @Override + public R saveOrUpdateResultTask(ResultUpdateTaskReq req, Long userId) { + Long tasklId = req.getTaskId(); + Long detailId = req.getDetailId(); + if (tasklId == null && detailId == null) { + log.error("任务保存或更新失败:tasklId, detailId都为空"); + return R.error(); + } + ResultTask resultTask; + if (tasklId == null) { + log.info("绩效任务新增操作。。。"); + ResultDetail resultDetail = resultDetailService.selectResultDetailById(req.getDetailId()); + if (!userId.equals(resultDetail.getStaffId())) { + log.info("非本人任务不能添加"); + return R.error("非本人任务不能添加"); + } + resultTask = new ResultTask(); + BeanUtils.copyProperties(req, resultTask); + resultTask.setDetailId(detailId); + resultTaskMapper.insertResultTask(resultTask); + //将插入的id传递过去 + req.setTaskId(resultTask.getId()); + changeTaskProcess(null, req, null); + } else { - log.info("绩效任务修改操作。。。"); - resultTask = resultTaskMapper.selectResultTaskById(tasklId); - ResultDetail resultDetail = resultDetailService.selectResultDetailById(resultTask.getDetailId()); - if(!userId.equals(resultDetail.getStaffId())){ - log.info("非本人任务不能修改"); - return R.error("非本人任务不能修改"); - } - TaskProcessRecordDto taskProcessRecordDto = taskProcessRecordMapper.selectTaskProcessRecordLastByTaskId(tasklId); - int i = changeTaskProcess(resultTask, req,taskProcessRecordDto); - if(i<1){ - log.info("任务暂无变化,不做修改"); - } - resultTask.setOrderBy(req.getOrderBy()); - if(StringUtil.isNotBlank(req.getName())){ - resultTask.setName(req.getName()); - } - if(req.getProcessRate()!=null){ - resultTask.setProcessRate(req.getProcessRate()); - } - resultTaskMapper.updateCoverResultTaskById(resultTask); + log.info("绩效任务修改操作。。。"); + resultTask = resultTaskMapper.selectResultTaskById(tasklId); + ResultDetail resultDetail = resultDetailService.selectResultDetailById(resultTask.getDetailId()); + if (!userId.equals(resultDetail.getStaffId())) { + log.info("非本人任务不能修改"); + return R.error("非本人任务不能修改"); + } + TaskProcessRecordDto taskProcessRecordDto = taskProcessRecordMapper.selectTaskProcessRecordLastByTaskId(tasklId); + int i = changeTaskProcess(resultTask, req, taskProcessRecordDto); + if (i < 1) { + log.info("任务暂无变化,不做修改"); + } + resultTask.setOrderBy(req.getOrderBy()); + if (StringUtil.isNotBlank(req.getName())) { + resultTask.setName(req.getName()); + } + if (req.getProcessRate() != null) { + resultTask.setProcessRate(req.getProcessRate()); + } + resultTaskMapper.updateCoverResultTaskById(resultTask); - } - //修改总进度 - if(detailId == null){ - detailId = resultTask.getDetailId(); - } - ResultDetail resultDetail = resultDetailService.selectResultDetailById(detailId); - resultDetail.setProcessRate(BigDecimal.valueOf(caclateResultDetailProcess(detailId))); - resultDetailService.updateResultDetailById(resultDetail); - return R.ok(); + } + //修改总进度 + if (detailId == null) { + detailId = resultTask.getDetailId(); + } + ResultDetail resultDetail = resultDetailService.selectResultDetailById(detailId); + resultDetail.setProcessRate(BigDecimal.valueOf(caclateResultDetailProcess(detailId))); + resultDetailService.updateResultDetailById(resultDetail); + return R.ok(); - } + } - //计算总进度 - private Double caclateResultDetailProcess(Long detailId){ - List resultTaskDtos = resultTaskMapper.selectResultTaskDtosByDetailId(detailId); - if(CollectionUtils.isEmpty(resultTaskDtos)){ - log.info("未找到该绩效详情下得任务信息"); - return 0d; - } - int size = resultTaskDtos.size(); - Double rate = 0d; - for(ResultTaskDto dto:resultTaskDtos){ - if(dto.getProcessRate()!=null){ - rate = BigDecimalUtil.add(rate,dto.getProcessRate()); - } - } - double result = BigDecimalUtil.div(rate, size, 4); - return result; + //计算总进度 + private Double caclateResultDetailProcess(Long detailId) { + List resultTaskDtos = resultTaskMapper.selectResultTaskDtosByDetailId(detailId); + if (CollectionUtils.isEmpty(resultTaskDtos)) { + log.info("未找到该绩效详情下得任务信息"); + return 0d; + } + int size = resultTaskDtos.size(); + Double rate = 0d; + for (ResultTaskDto dto : resultTaskDtos) { + if (dto.getProcessRate() != null) { + rate = BigDecimalUtil.add(rate, dto.getProcessRate()); + } + } + double result = BigDecimalUtil.div(rate, size, 4); + return result; - } + } - //记录变更记录 - private int changeTaskProcess(ResultTask beforeResultTask,ResultUpdateTaskReq req,TaskProcessRecordDto beforeTaskProcessRecord){ - TaskProcessRecord taskProcessRecord = new TaskProcessRecord(); - BeanUtils.copyProperties(req,taskProcessRecord); - //新增操作 - if(beforeResultTask == null){ - taskProcessRecord.setType(ProcessRecordEnum.ADD.getType()); - taskProcessRecord.setLabel("新增key Results名称:" + req.getName() + ";进度:" + BigDecimalUtil.mul(req.getProcessRate(),BigDecimal.valueOf(100)).setScale(2) + "%"); - return taskProcessRecordService.insertTaskProcessRecord(taskProcessRecord).intValue(); - } - //判断修改了名称或进度 - int i = 0; - String lebel = "key Results名称:" + beforeResultTask.getName(); - if(StringUtil.isNotBlank(req.getName()) && !req.getName().equals(beforeResultTask.getName())) { - i|= (0x00000001<<0); - lebel = lebel + " 改为 " + req.getName() + "\n"; - } - if(req.getProcessRate()!=null && BigDecimalUtil.compareTo(beforeResultTask.getProcessRate(),req.getProcessRate())!=0){ - i|= (0x00000001<<1); - lebel = lebel + "将进度:" +BigDecimalUtil.mul(beforeResultTask.getProcessRate(),BigDecimal.valueOf(100)).setScale(2)+ "%" + " 更新为 " + BigDecimalUtil.mul(req.getProcessRate(),BigDecimal.valueOf(100)).setScale(2)+ "%"; - } + //记录变更记录 + private int changeTaskProcess(ResultTask beforeResultTask, ResultUpdateTaskReq req, TaskProcessRecordDto beforeTaskProcessRecord) { + TaskProcessRecord taskProcessRecord = new TaskProcessRecord(); + BeanUtils.copyProperties(req, taskProcessRecord); + //新增操作 + if (beforeResultTask == null) { + taskProcessRecord.setType(ProcessRecordEnum.ADD.getType()); + taskProcessRecord.setLabel("新增key Results名称:" + req.getName() + ";进度:" + BigDecimalUtil.mul(req.getProcessRate(), BigDecimal.valueOf(100)).setScale(2) + "%"); + return taskProcessRecordService.insertTaskProcessRecord(taskProcessRecord).intValue(); + } + //判断修改了名称或进度 + int i = 0; + String lebel = "key Results名称:" + beforeResultTask.getName(); + if (StringUtil.isNotBlank(req.getName()) && !req.getName().equals(beforeResultTask.getName())) { + i |= (0x00000001 << 0); + lebel = lebel + " 改为 " + req.getName() + "\n"; + } + if (req.getProcessRate() != null && BigDecimalUtil.compareTo(beforeResultTask.getProcessRate(), req.getProcessRate()) != 0) { + i |= (0x00000001 << 1); + lebel = lebel + "将进度:" + BigDecimalUtil.mul(beforeResultTask.getProcessRate(), BigDecimal.valueOf(100)).setScale(2) + "%" + " 更新为 " + BigDecimalUtil.mul(req.getProcessRate(), BigDecimal.valueOf(100)).setScale(2) + "%"; + } - String remark = StringUtil.EMPTY; + String remark = StringUtil.EMPTY; - if(req.getRemark() != null){ - if(beforeTaskProcessRecord != null){ - remark = beforeTaskProcessRecord.getRemark(); - } - if(beforeTaskProcessRecord == null ||(!req.getRemark().equals(beforeTaskProcessRecord.getRemark()))){ - i|= (0x00000001<<2); - lebel = lebel + "将进度说明更新为: " + req.getRemark(); - } - } + if (req.getRemark() != null) { + if (beforeTaskProcessRecord != null) { + remark = beforeTaskProcessRecord.getRemark(); + } + if (beforeTaskProcessRecord == null || (!req.getRemark().equals(beforeTaskProcessRecord.getRemark()))) { + i |= (0x00000001 << 2); + lebel = lebel + "将进度说明更新为: " + req.getRemark(); + } + } - if(i==0){ - return -1; - } + if (i == 0) { + return -1; + } - taskProcessRecord.setTaskId(beforeResultTask.getId()); - taskProcessRecord.setDetailId(beforeResultTask.getDetailId()); - taskProcessRecord.setType(i); - taskProcessRecord.setLabel(lebel); - return taskProcessRecordService.insertTaskProcessRecord(taskProcessRecord).intValue(); + taskProcessRecord.setTaskId(beforeResultTask.getId()); + taskProcessRecord.setDetailId(beforeResultTask.getDetailId()); + taskProcessRecord.setType(i); + taskProcessRecord.setLabel(lebel); + return taskProcessRecordService.insertTaskProcessRecord(taskProcessRecord).intValue(); /*if(!beforeResultTask.getName().equals(req.getName())){ if(BigDecimalUtil.compareTo(beforeResultTask.getProcessRate(),req.getProcessRate())!=0){ taskProcessRecord.setType(ProcessRecordEnum.ALL.getType()); @@ -289,103 +278,131 @@ public class ResultTaskServiceImpl extends ServiceImpl selectResultTasksByDetailId(Long detailId) { + return resultTaskMapper.selectResultTasksByDetailId(detailId); + } - @Override - public List selectResultTasksByDetailId(Long detailId){ - return resultTaskMapper.selectResultTasksByDetailId(detailId); - } + @Override + public int deleteResultTasksByDetailId(Long detailId) { + List tasks = resultTaskMapper.selectResultTasksByDetailId(detailId); + for (ResultTask task : tasks + ) { + taskProcessRecordService.deleteTaskProcessRecordsByTaskId(task.getId()); + } + return resultTaskMapper.deleteResultTasksByDetailId(detailId); + } - @Override - public int deleteResultTasksByDetailId(Long detailId) { - List tasks = resultTaskMapper.selectResultTasksByDetailId(detailId); - for (ResultTask task : tasks - ) { - taskProcessRecordService.deleteTaskProcessRecordsByTaskId(task.getId()); - } - return resultTaskMapper.deleteResultTasksByDetailId(detailId); - } + @Override + public R deleteTask(Long taskId, Long userId) { + ResultTask resultTask = resultTaskMapper.selectResultTaskById(taskId); + ResultDetail resultDetail = resultDetailService.selectResultDetailById(resultTask.getDetailId()); + if (!userId.equals(resultDetail.getStaffId())) { + log.info("非本人任务不能删除"); + return R.error("非本人任务不能删除"); + } + resultTaskMapper.deleteResultTaskById(taskId); + TaskProcessRecord taskProcessRecord = new TaskProcessRecord(); + taskProcessRecord.setTaskId(taskId); + taskProcessRecord.setType(ProcessRecordEnum.DELETE.getType()); + taskProcessRecord.setLabel("将" + resultTask.getName() + "任务删除"); + taskProcessRecordService.insertTaskProcessRecord(taskProcessRecord); + //修改总进度 + resultDetail.setProcessRate(BigDecimal.valueOf(caclateResultDetailProcess(resultTask.getDetailId()))); + resultDetailService.updateResultDetailById(resultDetail); + return R.ok(); + } - @Override - public R deleteTask(Long taskId,Long userId) { - ResultTask resultTask = resultTaskMapper.selectResultTaskById(taskId); - ResultDetail resultDetail = resultDetailService.selectResultDetailById(resultTask.getDetailId()); - if(!userId.equals(resultDetail.getStaffId())){ - log.info("非本人任务不能删除"); - return R.error("非本人任务不能删除"); - } - resultTaskMapper.deleteResultTaskById(taskId); - TaskProcessRecord taskProcessRecord = new TaskProcessRecord(); - taskProcessRecord.setTaskId(taskId); - taskProcessRecord.setType(ProcessRecordEnum.DELETE.getType()); - taskProcessRecord.setLabel("将" +resultTask.getName() + "任务删除"); - taskProcessRecordService.insertTaskProcessRecord(taskProcessRecord); - //修改总进度 - resultDetail.setProcessRate(BigDecimal.valueOf(caclateResultDetailProcess(resultTask.getDetailId()))); - resultDetailService.updateResultDetailById(resultDetail); - return R.ok(); - } - - @Override - public List selectResultTaskDtosByDetailId(Long detailId){ - return resultTaskMapper.selectResultTaskDtosByDetailId(detailId); - } + @Override + public List selectResultTaskDtosByDetailId(Long detailId) { + return resultTaskMapper.selectResultTaskDtosByDetailId(detailId); + } @Override public List listResultTask(SysUserEntity user) { - List resultDtos = resultDetailMapper.listRecord(user.getUserId()); - if(CollectionUtils.isEmpty(resultDtos)){ - return Collections.EMPTY_LIST; - } - List detailIds = new ArrayList<>();//resultDtos.stream().map(resultDto -> resultDto.getId() + "").collect(Collectors.toList()); - - List dtos = resultTaskMapper.listResultTask(detailIds); - for(ResultDto resultDto:dtos){ - String rate = resultDto.getRate(); - BigDecimal bigDecimal = new BigDecimal(rate).setScale(4); - resultDto.setRate((bigDecimal.doubleValue() * 100) + "%"); - } - return dtos; + List list = new ArrayList<>(); + List resultDtos = resultDetailMapper.listRecord(user.getUserId()); + if (CollectionUtils.isEmpty(resultDtos)) { + return list; + } + List detailIds = new ArrayList<>(); + for (ResultDto resultDto : resultDtos) { + detailIds.add(resultDto.getDetailId()); + } + List dtos = resultTaskMapper.listResultTaskByDetailId(detailIds); + Map> map = new HashMap<>(); + for (ResultTask task : dtos) { + List resultTasks = map.get(task.getDetailId()); + if (resultTasks == null) { + resultTasks = new ArrayList<>(); + } + resultTasks.add(task); + map.put(task.getDetailId(), resultTasks); + } + for (int i = 0; i < resultDtos.size(); i++) { + ResultDto resultDto = resultDtos.get(i); + Integer index1 = i + 1; + resultDto.setIndex(index1 + ""); + resultDto.setRate(StringUtil.formateRate(resultDto.getRate(), 100)); + list.add(resultDto); + List resultTasks = map.get(resultDto.getDetailId()); + if (CollectionUtils.isNotEmpty(resultTasks)) { + int j = 1; + for (ResultTask resultTask : resultTasks) { + ResultDto r = new ResultDto(); + r.setIndex(index1 + "." + j); + r.setDetailId(resultDto.getDetailId()); + r.setContent(resultTask.getName()); + r.setTaskId(resultTask.getId()); + r.setRate(StringUtil.formateRate(resultTask.getProcessRate(), 100)); + j++; + list.add(r); + } + } + } + return list; } - @Override - public R addOrUpdateTask(SysUserEntity user, TaskDto second) { - ResultUpdateTaskReq resultUpdateTaskReq = new ResultUpdateTaskReq(); - resultUpdateTaskReq.setRemark(second.getMark()); - if("update".equals(second.getOption())){ - resultUpdateTaskReq.setTaskId(second.getId()); - }else if("add".equals(second.getOption())){ - resultUpdateTaskReq.setDetailId(second.getId()); - if(StringUtil.isBlank(second.getRate())){ - resultUpdateTaskReq.setProcessRate(BigDecimal.ZERO); - } - } - resultUpdateTaskReq.setName(second.getName()); - ResultTask resultTask = resultTaskMapper.selectResultTaskById(second.getId()); - if(resultTask!=null){ - resultUpdateTaskReq.setDetailId(resultTask.getDetailId()); - } - String rate = second.getRate(); - BigDecimal rateRes; - if(StringUtil.isNotBlank(rate)){ - rate = rate.trim(); - boolean contains = rate.contains("%"); - if(contains){ - rate = rate.replaceAll("%", ""); - } - if(contains || new BigDecimal(rate).compareTo(BigDecimal.ONE)>-1){ - rateRes = new BigDecimal(rate).multiply(BigDecimal.valueOf(0.01)); - }else { - rateRes = new BigDecimal(rate); - } - resultUpdateTaskReq.setProcessRate(rateRes); + @Override + public R addOrUpdateTask(SysUserEntity user, TaskDto second) { + ResultUpdateTaskReq resultUpdateTaskReq = new ResultUpdateTaskReq(); + resultUpdateTaskReq.setRemark(second.getMark()); + if ("update".equals(second.getOption())) { + resultUpdateTaskReq.setTaskId(second.getId()); + } else if ("add".equals(second.getOption())) { + resultUpdateTaskReq.setDetailId(second.getId()); + if (StringUtil.isBlank(second.getRate())) { + resultUpdateTaskReq.setProcessRate(BigDecimal.ZERO); + } + } + resultUpdateTaskReq.setName(second.getName()); + ResultTask resultTask = resultTaskMapper.selectResultTaskById(second.getId()); + if (resultTask != null) { + resultUpdateTaskReq.setDetailId(resultTask.getDetailId()); + } + String rate = second.getRate(); + BigDecimal rateRes; + if (StringUtil.isNotBlank(rate)) { + rate = rate.trim(); + boolean contains = rate.contains("%"); + if (contains) { + rate = rate.replaceAll("%", ""); + } + if (contains || new BigDecimal(rate).compareTo(BigDecimal.ONE) > -1) { + rateRes = new BigDecimal(rate).multiply(BigDecimal.valueOf(0.01)); + } else { + rateRes = new BigDecimal(rate); + } - } - return this.saveOrUpdateResultTask(resultUpdateTaskReq,user.getUserId()); - } + resultUpdateTaskReq.setProcessRate(rateRes); + + } + return this.saveOrUpdateResultTask(resultUpdateTaskReq, user.getUserId()); + } } diff --git a/src/main/java/com/lz/modules/sys/service/app/ResultDetailService.java b/src/main/java/com/lz/modules/sys/service/app/ResultDetailService.java index 91b0244e..000f9cc3 100644 --- a/src/main/java/com/lz/modules/sys/service/app/ResultDetailService.java +++ b/src/main/java/com/lz/modules/sys/service/app/ResultDetailService.java @@ -80,5 +80,5 @@ public interface ResultDetailService extends IService { List selectNotNoticeResultDetailByRecordId(Long recordId); - List listRecord(SysUserEntity user); + } \ No newline at end of file diff --git a/src/main/java/com/lz/modules/sys/service/app/impl/ResultDetailServiceImpl.java b/src/main/java/com/lz/modules/sys/service/app/impl/ResultDetailServiceImpl.java index 24e50093..fbfee0ca 100644 --- a/src/main/java/com/lz/modules/sys/service/app/impl/ResultDetailServiceImpl.java +++ b/src/main/java/com/lz/modules/sys/service/app/impl/ResultDetailServiceImpl.java @@ -359,14 +359,5 @@ public class ResultDetailServiceImpl extends ServiceImpl listRecord(SysUserEntity user) { - List resultDtos = resultDetailMapper.listRecord(user.getUserId()); - for(ResultDto resultDto:resultDtos){ - String rate = resultDto.getRate(); - BigDecimal bigDecimal = new BigDecimal(rate).setScale(4); - resultDto.setRate((bigDecimal.doubleValue() * 100) + "%"); - } - return resultDetailMapper.listRecord(user.getUserId()); - } + } 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 926bd3e8..9098017c 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, @Param("command") String command); - TaskResp selectTaskRespByUserIdIndex(@Param("userId") Long userId, @Param("index") Long index, @Param("command") String command); + TaskResp selectTaskRespByUserIdIndex(@Param("userId") Long userId, @Param("index") String 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/service/TaskRespService.java b/src/main/java/com/lz/modules/third/service/TaskRespService.java index 22d78fa5..69dd4bf9 100644 --- a/src/main/java/com/lz/modules/third/service/TaskRespService.java +++ b/src/main/java/com/lz/modules/third/service/TaskRespService.java @@ -37,7 +37,7 @@ public interface TaskRespService extends IService { void deleteInsertLastResult(SysUserEntity user ,List list,String command); - TaskResp selectTaskRespByUserIdIndex(Long userId, Long id,String command); + TaskResp selectTaskRespByUserIdIndex(Long userId, String id,String command); 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 c6959445..417822e8 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 @@ -85,13 +85,13 @@ public class TaskRespServiceImpl extends ServiceImpl i } @Override - public TaskResp selectTaskRespByUserIdIndex(Long userId, Long index,String command ) { + public TaskResp selectTaskRespByUserIdIndex(Long userId, String index,String command ) { return taskRespMapper.selectTaskRespByUserIdIndex(userId,index,command); } public boolean updateIndex(SysUserEntity userEntity, TaskDto taskDto,String command) { - TaskResp taskResp = taskRespService.selectTaskRespByUserIdIndex(userEntity.getUserId(), taskDto.getId(),command); + TaskResp taskResp = taskRespService.selectTaskRespByUserIdIndex(userEntity.getUserId(), taskDto.getIndex(),command); if (taskResp != null) { if(BaseCommand.add.equals(taskDto.getOption())){ taskDto.setId(taskResp.getDetailId()); diff --git a/src/main/java/com/lz/modules/third/utils/TaskConvertUtils.java b/src/main/java/com/lz/modules/third/utils/TaskConvertUtils.java index 9d0f4117..949f7564 100644 --- a/src/main/java/com/lz/modules/third/utils/TaskConvertUtils.java +++ b/src/main/java/com/lz/modules/third/utils/TaskConvertUtils.java @@ -118,12 +118,12 @@ public class TaskConvertUtils { } 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 resultDtos = Arrays.asList(); + ResultDto resultDto1 = new ResultDto("1.0", "30 %",1l, "哈哈0"); + ResultDto resultDto2 = new ResultDto("1.1", "30 %", 1l,2l,"哈哈1"); + ResultDto resultDto3 = new ResultDto("1.2", "30 %", 1l,"哈哈2"); + ResultDto resultDto4 = new ResultDto("1.3", "30 %",1l, "哈哈3"); + ResultDto[] array = new ResultDto[]{resultDto1, resultDto2, resultDto3, resultDto4}; + List resultDtos = Arrays.asList(array); TwoTuple, List>> data = convert(resultDtos).getData(); System.out.println(JSON.toJSONString(data.getFirst())); System.out.println(JSON.toJSONString(data.getSecond())); diff --git a/src/main/resources/mapper/app/ResultDetailMapper.xml b/src/main/resources/mapper/app/ResultDetailMapper.xml index e2aaac72..31e5fb01 100644 --- a/src/main/resources/mapper/app/ResultDetailMapper.xml +++ b/src/main/resources/mapper/app/ResultDetailMapper.xml @@ -217,12 +217,10 @@ diff --git a/src/main/resources/mapper/performance/ResultTaskMapper.xml b/src/main/resources/mapper/performance/ResultTaskMapper.xml index aba525da..3a12797c 100644 --- a/src/main/resources/mapper/performance/ResultTaskMapper.xml +++ b/src/main/resources/mapper/performance/ResultTaskMapper.xml @@ -101,7 +101,6 @@ +