| | |
| | | package me.zhengjie.modules.task.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.text.DateFormat; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.DayOfWeek; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Cacheable(key = "'allTaskUser:'+#p0") |
| | | public List<TaskUserMongoDto> getAllTaskUser(Long userId) { |
| | | public List<TaskUserMongoDto> getAllTaskUser(Long userId,String taskUserMongoId) { |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId())), TaskUserMongo.class); |
| | | List<TaskUserMongoDto> taskUserMongoDtoList = new ArrayList<>(); |
| | | |
| | |
| | | TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); |
| | | item.setPerformanceType(byId.getPerformanceType()); |
| | | mongoTemplate.save(item); |
| | | getAllTaskUser(SecurityUtils.getCurrentUserId()); |
| | | getAllTaskUser(SecurityUtils.getCurrentUserId(),taskUserMongoId); |
| | | } |
| | | if (item.getPerformanceType().equals("1")) { |
| | | //绩效任务 |
| | |
| | | daliyMongoList.forEach(daliy -> consumptionHours.updateAndGet(v -> v + daliy.getConsumedHours())); |
| | | if (daliyMongoList.size() == 0) { |
| | | //如果没有日志,统一赋值为0 |
| | | //List<TaskDaliyMongo> alreadyDaily = mongoTemplate.find(Query.query(new Criteria("taskUserMongo._id").is(taskUserMongoId)), TaskDaliyMongo.class); |
| | | // System.out.println(alreadyDaily.get(alreadyDaily.size() - 1)); |
| | | dto.setMaxTaskProgress(0D); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } else { |
| | | //如果有日志 |
| | | //看看其他人写没写过日报 |
| | | List<TaskDaliyMongo> alreadyDaily = mongoTemplate.find(Query.query(new Criteria("taskUserMongo._id").is(taskUserMongoId).and("userId").ne(SecurityUtils.getCurrentUserId())), TaskDaliyMongo.class); |
| | | //将其他人填写的工时合并过来 |
| | | alreadyDaily.forEach(daily -> consumptionHours.updateAndGet(v -> v + daily.getConsumedHours())); |
| | | daliyMongoList.sort(((o1, o2) -> (int) (o2.getTaskProgress() - o1.getTaskProgress()))); |
| | | dto.setMaxTaskProgress(daliyMongoList.get(0).getTaskProgress()); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskUserDetail> getTaskUserDetail(String taskUserMongoId) { |
| | | List<TaskUserDetail> returnList = new ArrayList<>(); |
| | | List<String> colorList = new ArrayList<>(); |
| | | Collections.addAll(colorList,"#0bbd87","#67C23A","#909399","#E6A23C","#F56C6C"); |
| | | Criteria criteria = new Criteria(); |
| | | criteria.and("taskUserMongo._id").is(taskUserMongoId); |
| | | Query query = new Query(criteria); |
| | | // 获取到这个分配任务下所有的日报信息 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(query, TaskDaliyMongo.class); |
| | | // 按照人名进行分组 |
| | | Map<Long, List<TaskDaliyMongo>> collect = daliyMongoList.stream().collect(Collectors.groupingBy(TaskDaliyMongo::getUserId)); |
| | | Set<Map.Entry<Long, List<TaskDaliyMongo>>> entries = collect.entrySet(); |
| | | // 分别染色 |
| | | for (Map.Entry<Long, List<TaskDaliyMongo>> entry : entries) { |
| | | String color = colorList.get(new Random().nextInt(colorList.size())); |
| | | colorList.remove(color); |
| | | for (TaskDaliyMongo taskDaliyMongo : entry.getValue()) { |
| | | TaskUserDetail taskUserDetail = new TaskUserDetail(); |
| | | taskUserDetail.setTitle(userRepository.findById(taskDaliyMongo.getUserId()).get().getNickName()+"提交了任务日报,消耗了"+taskDaliyMongo.getConsumedHours()+"个小时"); |
| | | taskUserDetail.setFillDate(new SimpleDateFormat("yyyy-MM-dd").format(taskDaliyMongo.getFillDate())); |
| | | taskUserDetail.setColor(color); |
| | | returnList.add(taskUserDetail); |
| | | } |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | @Override |
| | | @CacheEvict(cacheNames = "task", key = "'projectId:' + #p0") |
| | | public void addTaskUser(Long projectId, String taskId) { |
| | | //如果有用户认领了这个任务 |