| | |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.system.domain.DictDetail; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.task.domain.*; |
| | | import me.zhengjie.modules.task.repository.TaskRepository; |
| | | import me.zhengjie.modules.task.service.dto.TaskDaliyMongoDto; |
| | | import me.zhengjie.utils.*; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | |
| | | |
| | | @Override |
| | | public List<TaskDaliyDto> queryAll(TaskDaliyQueryCriteria criteria) { |
| | | return taskDaliyMapper.toDto(taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | Criteria criteriaMongo = new Criteria(); |
| | | criteriaMongo.and("userId").is(SecurityUtils.getCurrentUserId()); |
| | | |
| | | if (criteria.getTaskId() != null || criteria.getProjectId() != null || criteria.getName() != null) { |
| | | Criteria criteriaTaskUserMongo = new Criteria(); |
| | | if (criteria.getTaskMongoId() != null) { |
| | | criteriaTaskUserMongo.and("task").is(criteria.getTaskMongoId()); |
| | | } else if (criteria.getProjectId() != null) { |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(Query.query(Criteria.where("projectId").is(criteria.getProjectId())), TaskMongo.class); |
| | | criteriaTaskUserMongo.and("task").in(taskMongoList); |
| | | } |
| | | if (criteria.getName() != null) { |
| | | Pattern pattern = Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE); |
| | | criteriaTaskUserMongo.and("name").is(pattern); |
| | | } |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(criteriaTaskUserMongo), TaskUserMongo.class); |
| | | criteriaMongo.and("taskUserMongo").in(taskUserMongoList); |
| | | } |
| | | if (criteria.getFillDates() != null) { |
| | | DateTime startTime = new DateTime(criteria.getFillDates().get(0)); |
| | | DateTime endTime = new DateTime(criteria.getFillDates().get(1)); |
| | | criteriaMongo.andOperator(Criteria.where("fillDate").gte(startTime), Criteria.where("fillDate").lte(endTime)); |
| | | } |
| | | |
| | | Query query = Query.query(criteriaMongo); |
| | | long count = mongoTemplate.count(query, TaskDaliyMongo.class); |
| | | // 如果用户的日报为空 |
| | | if (count == 0) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | //如果这个用户的日报不为空 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(query, TaskDaliyMongo.class); |
| | | List<TaskDaliyDto> resultList = new ArrayList<>(); |
| | | daliyMongoList.sort((o1, o2) -> o2.getFillDate().compareTo(o1.getFillDate())); |
| | | for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | TaskDaliyDto dto = new TaskDaliyDto(); |
| | | dto.setId(Long.valueOf(taskDaliyMongo.getId())); |
| | | dto.setFillDate(taskDaliyMongo.getFillDate()); |
| | | dto.setProjectId(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId()); |
| | | dto.setTaskName(taskDaliyMongo.getTaskUserMongo().getTask().getName()); |
| | | dto.setTaskId(Long.valueOf(taskDaliyMongo.getTaskUserMongo().getTask().getId())); |
| | | dto.setConsumedHours(taskDaliyMongo.getConsumedHours()); |
| | | dto.setTaskProgress(taskDaliyMongo.getTaskProgress()); |
| | | dto.setSettlementStatus(taskDaliyMongo.getSettlementStatus()); |
| | | dto.setRemarks(taskDaliyMongo.getRemarks()); |
| | | dto.setTaskUserMongo(taskDaliyMongo.getTaskUserMongo()); |
| | | resultList.add(dto); |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public void download(List<TaskDaliyDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | Map<Long, String> projectNameMap = new HashMap<>(); |
| | | Map<Long, String> taskNameMap = new HashMap<>(); |
| | | Map<Long, String> userNickNameMap = new HashMap<>(); |
| | | Map<String, String> settlementStatusMap = dictDetailRepository.findByDictName(Constant.SETTLEMENT_STATUS).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel)); |
| | | |
| | | for (TaskDaliyDto taskDaliy : all) { |
| | | String projectName = taskDaliy.getProjectId() != null ? projectRepository.findById(taskDaliy.getProjectId()).orElseGet(Project::new).getName() : ""; |
| | | String taskName = taskDaliy.getTaskId() != null ? taskRepository.findById(taskDaliy.getTaskId()).orElseGet(Task::new).getName() : ""; |
| | | String userNickName = taskDaliy.getUserId() != null ? userRepository.findById(taskDaliy.getUserId()).orElseGet(User::new).getNickName() : ""; |
| | | String settlementStatus = taskDaliy.getSettlementStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.SETTLEMENT_STATUS, taskDaliy.getSettlementStatus()).getLabel() : ""; |
| | | if (ObjectUtils.isNotEmpty(taskDaliy.getProjectId()) && !projectNameMap.containsKey(taskDaliy.getProjectId())) { |
| | | Project project = projectRepository.findById(taskDaliy.getProjectId()).orElseGet(Project::new); |
| | | if (project.getId() != null) { |
| | | projectNameMap.put(project.getId(), project.getName()); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(taskDaliy.getTaskId()) && !taskNameMap.containsKey(taskDaliy.getTaskId())) { |
| | | Task task = taskRepository.findById(taskDaliy.getTaskId()).orElseGet(Task::new); |
| | | if (task.getId() != null) { |
| | | taskNameMap.put(task.getId(), task.getName()); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(taskDaliy.getUserId()) && !userNickNameMap.containsKey(taskDaliy.getUserId())) { |
| | | User user = userRepository.findById(taskDaliy.getUserId()).orElseGet(User::new); |
| | | if (user.getId() != null) { |
| | | userNickNameMap.put(user.getId(), user.getNickName()); |
| | | } |
| | | } |
| | | |
| | | // 录入数据 |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("填写日期", taskDaliy.getFillDate()); |
| | | map.put("项目名称", projectName); |
| | | map.put("任务名称", taskName); |
| | | map.put("员工姓名", userNickName); |
| | | map.put("项目名称", Optional.ofNullable(projectNameMap.get(taskDaliy.getProjectId())).orElse(null)); |
| | | map.put("任务名称", Optional.ofNullable(taskNameMap.get(taskDaliy.getTaskId())).orElse(null)); |
| | | map.put("员工姓名", Optional.ofNullable(userNickNameMap.get(taskDaliy.getUserId())).orElse(null)); |
| | | map.put("消耗工时", taskDaliy.getConsumedHours()); |
| | | map.put("消耗工作量", taskDaliy.getConsumedWorkload()); |
| | | map.put("任务进度", taskDaliy.getTaskProgress()); |
| | | map.put("结算状态", settlementStatus); |
| | | map.put("结算状态", Optional.ofNullable(settlementStatusMap.get(taskDaliy.getSettlementStatus())).orElse(taskDaliy.getSettlementStatus())); |
| | | map.put("备注", taskDaliy.getRemarks()); |
| | | map.put("创建者", taskDaliy.getCreateBy()); |
| | | map.put("创建时间", taskDaliy.getCreateTime()); |