| | |
| | | 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 org.bson.types.ObjectId; |
| | | import org.springframework.cache.annotation.CacheConfig; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | |
| | | } else { |
| | | item.setPerformanceHours(item.getTaskHours()); |
| | | } |
| | | |
| | | mongoTemplate.save(item); |
| | | |
| | | dto.setId(item.getId()); |
| | | dto.setName(item.getName()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskDetail> getTaskDetail(String taskMongoId) { |
| | | TaskMongo byId = mongoTemplate.findById(taskMongoId, TaskMongo.class); |
| | | List<TaskDetail> resultList = new ArrayList<>(); |
| | | assert byId != null; |
| | | List<Long> containUserList = byId.getContainUserList(); |
| | | for (Long userId : containUserList) { |
| | | TaskDetail taskDetail = new TaskDetail(); |
| | | AtomicReference<Double> assignedWork = new AtomicReference<>(0D); |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(userId).and("task._id").is(taskMongoId).and("taskStatus").ne("task_status_completed")), TaskUserMongo.class); |
| | | taskDetail.setNickName(userRepository.findById(userId).get().getNickName()); |
| | | taskUserMongoList.forEach(item -> { |
| | | if(item.getPerformanceHours() != null) { |
| | | assignedWork.updateAndGet(v -> v + item.getPerformanceHours()); |
| | | } |
| | | }); |
| | | taskDetail.setAssignedWork(assignedWork.get()); |
| | | |
| | | resultList.add(taskDetail); |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | @Override |
| | | @CacheEvict(cacheNames = "task", key = "'projectId:' + #p0") |
| | | public void addTaskUser(Long projectId, String taskId) { |
| | | //如果有用户认领了这个任务 |
| | |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(taskUserMongo.getTaskHours() / coefficientByUserId); |
| | | taskUserMongoDto.setPerformanceHours(Double.valueOf(format)); |
| | | taskUserMongo.setPerformanceHours(Double.valueOf(format)); |
| | | } else { |
| | | taskUserMongoDto.setPerformanceHours(taskUserMongo.getTaskHours()); |
| | | } |
| | | |
| | | mongoTemplate.save(taskUserMongo); |
| | | |
| | | taskUserMongoDtoList.add(taskUserMongoDto); |
| | | } |
| | |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(taskUserMongo.getTaskHours() / coefficientByUserId); |
| | | taskUserMongoDto.setPerformanceHours(Double.valueOf(format)); |
| | | taskUserMongo.setPerformanceHours(Double.valueOf(format)); |
| | | mongoTemplate.save(taskUserMongo); |
| | | resultList.add(taskUserMongoDto); |
| | | } else { |
| | | taskUserMongoDto.setPerformanceHours(taskUserMongo.getTaskHours()); |