| | |
| | | */ |
| | | package me.zhengjie.modules.task.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | | import java.time.Instant; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import lombok.RequiredArgsConstructor;
|
| | | import me.zhengjie.modules.constant.Constant;
|
| | | import me.zhengjie.modules.project.domain.Project;
|
| | | import me.zhengjie.modules.project.repository.ProjectRepository;
|
| | | import me.zhengjie.modules.project.service.ProjectService;
|
| | | import me.zhengjie.modules.project.service.dto.ProjectDto;
|
| | | import me.zhengjie.modules.project.service.dto.ProjectQueryCriteria;
|
| | | 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.system.repository.UserRepository;
|
| | | import me.zhengjie.modules.system.service.RoleService;
|
| | | import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
|
| | | import me.zhengjie.modules.system.service.dto.RoleSmallDto;
|
| | | import me.zhengjie.modules.task.domain.*;
|
| | | import me.zhengjie.modules.task.repository.TaskDaliyRepository;
|
| | | import me.zhengjie.modules.task.repository.TaskRepository;
|
| | | import me.zhengjie.modules.task.repository.TaskUserRepository;
|
| | | import me.zhengjie.modules.task.service.TaskService;
|
| | | import me.zhengjie.modules.task.service.dto.TaskDto;
|
| | | import me.zhengjie.modules.task.service.dto.TaskMongoDto;
|
| | | import me.zhengjie.modules.task.service.dto.TaskQueryCriteria;
|
| | | import me.zhengjie.modules.task.service.dto.TaskUserMongoDto; |
| | | import me.zhengjie.modules.task.service.mapstruct.TaskMapper;
|
| | | import me.zhengjie.modules.treatment.repository.UserLevelWageRepository; |
| | | import org.bson.types.ObjectId; |
| | | import me.zhengjie.utils.*;
|
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.annotation.CacheConfig; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.project.service.ProjectService; |
| | | import me.zhengjie.modules.project.service.dto.ProjectDto; |
| | | import me.zhengjie.modules.project.service.dto.ProjectQueryCriteria; |
| | | import me.zhengjie.modules.system.domain.DictDetail; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.service.RoleService; |
| | | import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria; |
| | | import me.zhengjie.modules.system.service.dto.RoleSmallDto; |
| | | import me.zhengjie.modules.task.domain.Task; |
| | | import me.zhengjie.modules.task.domain.TaskAggrMongo; |
| | | import me.zhengjie.modules.task.domain.TaskDaliy; |
| | | import me.zhengjie.modules.task.domain.TaskDaliyMongo; |
| | | import me.zhengjie.modules.task.domain.TaskMongo; |
| | | import me.zhengjie.modules.task.domain.TaskUser; |
| | | import me.zhengjie.modules.task.domain.TaskUserMongo; |
| | | import me.zhengjie.modules.task.repository.TaskDaliyRepository; |
| | | import me.zhengjie.modules.task.repository.TaskRepository; |
| | | import me.zhengjie.modules.task.repository.TaskUserRepository; |
| | | import me.zhengjie.modules.task.service.TaskService; |
| | | import me.zhengjie.modules.task.service.dto.TaskDto; |
| | | import me.zhengjie.modules.task.service.dto.TaskMongoDto; |
| | | import me.zhengjie.modules.task.service.dto.TaskQueryCriteria; |
| | | import me.zhengjie.modules.task.service.mapstruct.TaskMapper; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.math.MathContext;
|
| | | import java.math.RoundingMode;
|
| | | import java.util.*;
|
| | | import java.util.concurrent.atomic.AtomicReference;
|
| | | import java.util.regex.Pattern;
|
| | | import java.util.stream.Collectors;
|
| | | import java.util.stream.Stream;
|
| | | |
| | | /** |
| | | * @author 赵士淞 |
| | |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final TaskUserRepository taskUserRepository; |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final UserRepository userRepository;
|
| | | private final RoleService roleService; |
| | | private final UserLevelWageRepository userLevelWageRepository; |
| | | @Autowired |
| | |
| | | taskUserMongoDtoList.add(dto); |
| | | } else { |
| | | //如果有日志 |
| | | daliyMongoList.sort(((o1, o2) -> (int) (o2.getTaskProgress() - o1.getTaskProgress()))); |
| | | daliyMongoList.sort(((o1, o2) -> (int) (100 * (o2.getTaskProgress() - o1.getTaskProgress()))));
|
| | | dto.setMaxTaskProgress(daliyMongoList.get(0).getTaskProgress()); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskMongo> queryAll(TaskQueryCriteria criteria) { |
| | | public List<TaskMongoDto> queryAll(TaskQueryCriteria criteria) {
|
| | | |
| | | // 获取登录用户角色等级 |
| | | List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()); |
| | | // 登录用户最大角色等级 |
| | | int min = Collections.min(levels); |
| | | // 判断角色等级 |
| | | if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) { |
| | | // // 根据用户ID查询参与的项目ID |
| | | // List<Long> taskUserProjectIdList = taskUserRepository.findProjectIdByUserId(SecurityUtils.getCurrentUserId()); |
| | | // 根据用户ID查询负责的项目ID |
| | | List<Long> projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId()); |
| | | // 检索条件 |
| | | List<Long> totalProjectIdList = Stream.of(projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList()); |
| | | if (totalProjectIdList.size() == 0) { |
| | | return Collections.emptyList(); |
| | | } |
| | | criteria.setProjectIdInList(totalProjectIdList); |
| | | } |
| | | // // 获取登录用户角色等级
|
| | | // List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
|
| | | // // 登录用户最大角色等级
|
| | | // int min = Collections.min(levels);
|
| | | // // 判断角色等级
|
| | | // if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) {
|
| | | //// // 根据用户ID查询参与的项目ID
|
| | | //// List<Long> taskUserProjectIdList = taskUserRepository.findProjectIdByUserId(SecurityUtils.getCurrentUserId());
|
| | | // // 根据用户ID查询负责的项目ID
|
| | | // List<Long> projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId());
|
| | | // // 检索条件
|
| | | // List<Long> totalProjectIdList = Stream.of(projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
| | | // if (totalProjectIdList.size() == 0) {
|
| | | // return Collections.emptyList();
|
| | | // }
|
| | | // criteria.setProjectIdInList(totalProjectIdList);
|
| | | // }
|
| | | //
|
| | | // Criteria criteriaMongo = new Criteria();
|
| | | // if (criteria.getProjectId() != null) {
|
| | | // criteriaMongo = criteriaMongo.and("projectId").is(criteria.getProjectId());
|
| | | // } else if (criteria.getProjectIdInList() != null) {
|
| | | // criteriaMongo = criteriaMongo.and("projectId").in(criteria.getProjectIdInList().toArray());
|
| | | // }
|
| | | // if (criteria.getName() != null) {
|
| | | //// criteriaMongo = criteriaMongo.and("parent").exists(false);
|
| | | //// } else {
|
| | | // criteriaMongo = criteriaMongo.and("name").regex(Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE));
|
| | | // }
|
| | | // Query query = new Query(criteriaMongo);
|
| | | // Long totalCount = mongoTemplate.count(query, TaskMongo.class);
|
| | | // if (totalCount == 0) {
|
| | | // return Collections.emptyList();
|
| | | // }
|
| | | // List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
|
| | | // return taskMongoList;
|
| | | |
| | | Criteria criteriaMongo = new Criteria(); |
| | | if (criteria.getProjectId() != null) { |
| | | criteriaMongo = criteriaMongo.and("projectId").is(criteria.getProjectId()); |
| | | } else if (criteria.getProjectIdInList() != null) { |
| | | criteriaMongo = criteriaMongo.and("projectId").in(criteria.getProjectIdInList().toArray()); |
| | | } |
| | | if (criteria.getName() != null) { |
| | | // criteriaMongo = criteriaMongo.and("parent").exists(false); |
| | | // } else { |
| | | if (criteria.getName() == null) {
|
| | | criteriaMongo = criteriaMongo.and("parent").exists(false);
|
| | | } else {
|
| | | criteriaMongo = criteriaMongo.and("name").regex(Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE)); |
| | | } |
| | | Query query = new Query(criteriaMongo); |
| | | Long totalCount = mongoTemplate.count(query, TaskMongo.class); |
| | | if (totalCount == 0) { |
| | | return Collections.emptyList(); |
| | | if (criteria.getTaskStatuses() != null && criteria.getTaskStatuses().size() > 0) {
|
| | | criteriaMongo = criteriaMongo.and("taskStatus").in(criteria.getTaskStatuses());
|
| | | } |
| | | if (criteria.getUserIds() != null && criteria.getUserIds().size() > 0) {
|
| | | criteriaMongo = criteriaMongo.and("userIdList").in(criteria.getUserIds());
|
| | | }
|
| | | if (criteria.getTagList() != null && criteria.getTagList().size() > 0) {
|
| | | criteriaMongo = criteriaMongo.and("tagList").in(criteria.getTagList());
|
| | | }
|
| | | if(criteria.getPerformanceType() != null) {
|
| | | criteriaMongo = criteriaMongo.and("performanceType").is(criteria.getPerformanceType());
|
| | | }
|
| | | Query query = new Query(criteriaMongo);
|
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class); |
| | | return taskMongoList; |
| | |
|
| | | List<TaskMongoDto> taskMongoDtoList = createTreeWithoutChildren(null, taskMongoList);
|
| | | return taskMongoDtoList;
|
| | | } |
| | | |
| | | public List<TaskMongoDto> findByCompanyId(Long companyId) { |
| | |
| | | |
| | | // @Cacheable(cacheNames = "ChildrenTask", key = "'userId:' +#p0 + 'projectId:' + #p1.projectId") |
| | | public List<TaskMongoDto> queryChildrenTaskAnyParent(Long userId,TaskQueryCriteria criteria) { |
| | | |
| | | |
| | | List<TaskMongo> taskMongosName = new ArrayList<>(); |
| | | boolean flag = false; |
| | | if (criteria.getName() != null) { |
| | | Criteria criteriaTask = new Criteria(); |
| | | Pattern pattern = Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE); |
| | | criteriaTask.and("name").is(pattern); |
| | | criteriaTask.and("pid").is(null); |
| | | taskMongosName = mongoTemplate.find(Query.query(criteriaTask), TaskMongo.class); |
| | | flag = true; |
| | | } |
| | | // 获取登录用户角色等级 |
| | | List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()); |
| | | // 登录用户最大角色等级 |
| | | int min = Collections.min(levels); |
| | | |
| | | List<TaskMongo> taskMongoList = null;
|
| | | Criteria criteriaTask = new Criteria();
|
| | | criteriaTask.and("pid").is(null);
|
| | | criteriaTask.and("taskStatus").nin(Constant.TASK_STATUS_COMPLETED);
|
| | | if (criteria.getName() != null) {
|
| | | Pattern pattern = Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE);
|
| | | criteriaTask.and("name").is(pattern);
|
| | | }
|
| | |
|
| | | if (criteria.getProjectId() != null) {
|
| | | criteriaTask.and("projectId").is(criteria.getProjectId());
|
| | | if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) { |
| | | //看看当前这个用户是不是这个项目的项目负责人,如果是项目负责人的话显示全部的任务 |
| | | List<Long> idByLiableUserId = projectRepository.findIdByLiableUserId(userId); |
| | | for (Long aLong : idByLiableUserId) { |
| | | if (criteria.getProjectId().equals(aLong)) { |
| | | Criteria criteriaAll = new Criteria(); |
| | | criteriaAll = criteriaAll.and("projectId").is(criteria.getProjectId()).and("pid").is(null); |
| | | Query query = new Query(criteriaAll); |
| | | List<TaskMongo> taskMongos = new ArrayList<>(); |
| | | if (flag) { |
| | | taskMongos = taskMongosName; |
| | | } else { |
| | | taskMongos = mongoTemplate.find(query, TaskMongo.class); |
| | | List<Long> projectIds = projectRepository.findIdByLiableUserId(userId);
|
| | | if (!projectIds.contains(criteria.getProjectId())) {
|
| | | criteriaTask.and("containUserList").is(userId);
|
| | | }
|
| | | }
|
| | | } |
| | | |
| | | List<TaskMongoDto> taskMongoDtoList = new ArrayList<TaskMongoDto>(); |
| | | for (TaskMongo taskMongo : taskMongos) { |
| | | TaskMongoDto taskMongoDto = new TaskMongoDto(); |
| | | |
| | | taskMongoDto.setId(taskMongo.getId()); |
| | | taskMongoDto.setName(taskMongo.getName()); |
| | | taskMongoDto.setProjectId(taskMongo.getProjectId()); |
| | | taskMongoDto.setPlanStartTime(taskMongo.getPlanStartTime()); |
| | | taskMongoDto.setPlanEndTime(taskMongo.getPlanEndTime()); |
| | | |
| | | Query childrenQuery = new Query(Criteria.where("parent").is(taskMongo)); |
| | | long children = mongoTemplate.count(childrenQuery, TaskMongo.class); |
| | | taskMongoDto.setLeaf(children == 0); |
| | | |
| | | //如果时项目负责人有最高权限 |
| | | taskMongoDto.setFlag(true); |
| | | |
| | | taskMongoDtoList.add(taskMongoDto); |
| | | } |
| | | return taskMongoDtoList; |
| | | } |
| | | } |
| | | Criteria criteriaMongo = new Criteria(); |
| | | criteriaMongo = criteriaMongo.and("containUserList").is(userId); |
| | | if (criteria.getProjectId() != null) { |
| | | criteriaMongo = criteriaMongo.and("projectId").is(criteria.getProjectId()).and("pid").is(null); |
| | | } |
| | | if (criteria.getName() != null) { |
| | | criteriaMongo = criteriaMongo.and("name").regex(Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE)).and("pid").is(null); |
| | | } |
| | | Query query = new Query(criteriaMongo); |
| | | Query query = new Query(criteriaTask);
|
| | | Long totalCount = mongoTemplate.count(query, TaskMongo.class); |
| | | if (totalCount == 0) { |
| | | return Collections.emptyList(); |
| | | } |
| | | //获取包含成员 |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class); |
| | | |
| | | List<TaskMongoDto> taskMongoDtoList = new ArrayList<TaskMongoDto>(); |
| | | taskMongoList = mongoTemplate.find(query, TaskMongo.class);
|
| | | // 结果集
|
| | | List<TaskMongoDto> taskMongoDtoList = new ArrayList<>();
|
| | | for (TaskMongo taskMongo : taskMongoList) { |
| | | |
| | | TaskMongoDto taskMongoDto = new TaskMongoDto(); |
| | |
| | | taskMongoDtoList.add(taskMongoDto); |
| | | } |
| | | return taskMongoDtoList; |
| | | } else { |
| | | List<TaskMongoDto> taskMongoDtoList = new ArrayList<>(); |
| | | |
| | | if (criteria.getName() != null) { |
| | | Criteria criteriaTask = new Criteria(); |
| | | Pattern pattern = Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE); |
| | | criteriaTask.and("name").is(pattern); |
| | | criteriaTask.and("pid").is(null); |
| | | taskMongosName = mongoTemplate.find(Query.query(criteriaTask), TaskMongo.class); |
| | | flag = true; |
| | | } |
| | | |
| | | List<TaskMongo> all; |
| | | if (flag) { |
| | | all = taskMongosName; |
| | | } else { |
| | | all = mongoTemplate.find(Query.query(new Criteria("projectId").is(criteria.getProjectId()).and("pid").is(null)), TaskMongo.class); |
| | | } |
| | | //获取所有的任务 |
| | | for (TaskMongo taskMongo : all) { |
| | | |
| | | TaskMongoDto taskMongoDto = new TaskMongoDto(); |
| | | |
| | | taskMongoDto.setId(taskMongo.getId()); |
| | | taskMongoDto.setName(taskMongo.getName()); |
| | | taskMongoDto.setProjectId(taskMongo.getProjectId()); |
| | | taskMongoDto.setPlanStartTime(taskMongo.getPlanStartTime()); |
| | | taskMongoDto.setPlanEndTime(taskMongo.getPlanEndTime()); |
| | | |
| | | Query childrenQuery = new Query(Criteria.where("parent").is(taskMongo)); |
| | | long children = mongoTemplate.count(childrenQuery, TaskMongo.class); |
| | | taskMongoDto.setLeaf(children == 0); |
| | | taskMongoDto.setFlag(true); |
| | | taskMongoDtoList.add(taskMongoDto); |
| | | } |
| | | int num = taskMongoDtoList.size(); |
| | | return taskMongoDtoList; |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void download(List<TaskDto> all, HttpServletResponse response) throws IOException { |
| | | public void download(List<TaskMongoDto> all, HttpServletResponse response) throws IOException {
|
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (TaskDto task : all) { |
| | | for (TaskMongoDto task : all) {
|
| | | String projectName = task.getProjectId() != null ? projectRepository.findById(task.getProjectId()).orElseGet(Project::new).getName() : ""; |
| | | String pidName = task.getPid() != null ? taskRepository.findById(task.getPid()).orElseGet(Task::new).getName() : ""; |
| | | String priority = task.getPriority() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PRIORITY, task.getPriority()).getLabel() : ""; |
| | | String taskClassification = task.getTaskClassification() != null ? dictDetailRepository.findByDictNameAndValue(Constant.TASK_CLASSIFICATION, task.getTaskClassification()).getLabel() : ""; |
| | | String planWorkloadUnit = task.getPlanWorkloadUnit() != null ? dictDetailRepository.findByDictNameAndValue(Constant.STANDARD_WORKLOAD_UNIT, task.getPlanWorkloadUnit()).getLabel() : ""; |
| | | String taskStatus = task.getTaskStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, task.getTaskStatus()).getLabel() : ""; |
| | | List<String> userNameList = new ArrayList<>();
|
| | | userRepository.findAllById(task.getUserIdList()).forEach(user -> userNameList.add(user.getNickName()));
|
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("项目名称", projectName); |
| | | map.put("父任务名称", pidName); |
| | | map.put("项目", projectName);
|
| | | map.put("名称", task.getName()); |
| | | map.put("优先度", priority); |
| | | map.put("任务分类", taskClassification); |
| | | map.put("描述", task.getDescription()); |
| | | map.put("计划工时", task.getPlanHours());
|
| | | map.put("计划开始时间", task.getPlanStartTime()); |
| | | map.put("计划结束时间", task.getPlanEndTime()); |
| | | map.put("计划工时", task.getPlanHours()); |
| | | map.put("计划工作量", task.getPlanWorkload()); |
| | | map.put("计划工作量单位", planWorkloadUnit); |
| | | map.put("任务状态", taskStatus); |
| | | map.put("备注", task.getRemarks()); |
| | | map.put("创建者", task.getCreateBy()); |
| | | map.put("创建时间", task.getCreateTime()); |
| | | map.put("更新者", task.getUpdateBy()); |
| | | map.put("更新时间", task.getUpdateTime()); |
| | |
|
| | | map.put("消耗工时", task.getConsumedHours());
|
| | |
|
| | | map.put("绩效类型", task.getPerformanceType().equals("1") ? "绩效" : "非绩效");
|
| | | map.put("任务分类", String.join(",", task.getTagList()));
|
| | | map.put("任务负责人", String.join(",", userNameList));
|
| | | list.add(map); |
| | | } |
| | | FileUtil.downloadExcel(list, response); |