| | |
| | | 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()); |
| | |
| | | colorList.remove(color); |
| | | for (TaskDaliyMongo taskDaliyMongo : entry.getValue()) { |
| | | TaskUserDetail taskUserDetail = new TaskUserDetail(); |
| | | if(taskDaliyMongo.getRemarks() != null) { |
| | | taskUserDetail.setFlag(true); |
| | | taskUserDetail.setRemarks(taskDaliyMongo.getRemarks()); |
| | | } |
| | | taskUserDetail.setTaskUserName(userRepository.findById(taskDaliyMongo.getUserId()).get().getNickName()); |
| | | taskUserDetail.setTitle(userRepository.findById(taskDaliyMongo.getUserId()).get().getNickName()+"提交了任务日报,消耗了"+taskDaliyMongo.getConsumedHours()+"个小时"); |
| | | taskUserDetail.setFillDate(new SimpleDateFormat("yyyy-MM-dd").format(taskDaliyMongo.getFillDate())); |
| | |
| | | } |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | @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 |
| | |
| | | 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()); |
| | |
| | | @Override |
| | | public void deleteAll(String[] ids) { // TODO |
| | | for (String id : ids) { |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("taskUserMongo._id").is(id)), TaskDaliyMongo.class); |
| | | if(daliyMongoList.size() > 0) { |
| | | throw new BadRequestException("当前分配任务已经有用户填写了日报!"); |
| | | } |
| | | mongoTemplate.remove(Query.query(Criteria.where("id").is(new ObjectId(id))), TaskUserMongo.class); |
| | | } |
| | | // mongoTemplate.remove(Query.query(Criteria.where("id").in(ids)), getClass()); |