| | |
| | | /* |
| | | * Copyright 2019-2020 Zheng Jie |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package me.zhengjie.modules.project.service.impl; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.contract.repository.ContractProjectRepository; |
| | | import me.zhengjie.modules.cost.repository.CostRepository; |
| | | import me.zhengjie.modules.project.domain.*; |
| | | import me.zhengjie.modules.project.repository.*; |
| | | import me.zhengjie.modules.project.service.ProjectCostService; |
| | | 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.project.service.dto.ProjectTypeQueryCriteria; |
| | | import me.zhengjie.modules.project.service.mapstruct.ProjectMapper; |
| | | 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.SysExchangeRateService; |
| | | import me.zhengjie.modules.system.service.SysGoalSettingService; |
| | | import me.zhengjie.modules.system.service.dto.*; |
| | | 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.TaskUserTotalDetailMongoDto; |
| | | import me.zhengjie.modules.task.service.mapstruct.TaskMapper; |
| | | import me.zhengjie.utils.*; |
| | | import me.zhengjie.utils.enums.DataScopeEnum; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | | import org.springframework.data.mongodb.core.aggregation.AggregationResults; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.Map.Entry; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | |
| | | /** |
| | | * @author HuaZhe |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @date 2022-12-15 |
| | | **/ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class ProjectServiceImpl implements ProjectService { // TODO redis化 |
| | | |
| | | private final ProjectRepository projectRepository; |
| | | private final ProjectMapper projectMapper; |
| | | private final ProjectTypeRepository projectTypeRepository; |
| | | private final UserRepository userRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final ProjectTaskRepository projectTaskRepository; |
| | | private final RoleService roleService; |
| | | private final TaskUserRepository taskUserRepository; |
| | | private final ProjectCostRepository projectCostRepository; |
| | | private final ProjectCostOtherRepository projectCostOtherRepository; |
| | | private final TaskRepository taskRepository; |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final ProjectCostService projectCostService; |
| | | private final ProjectProgressRepository projectProgressRepository; |
| | | private final ProjectPerformanceRepository projectPerformanceRepository; |
| | | private final ProjectPerformanceDetailRepository projectPerformanceDetailRepository; |
| | | private final CostRepository costRepository; |
| | | private final ContractProjectRepository contractProjectRepository; |
| | | private final SysGoalSettingService sysGoalSettingService; |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | private final TaskMapper taskMapper; |
| | | private final SysExchangeRateService sysExchangeRateService; |
| | | private final MongoTemplate mongoTemplate; |
| | | |
| | | @Override |
| | | public Map<String, Object> queryAll(ProjectQueryCriteria criteria, Pageable pageable) { |
| | | |
| | | if (criteria.getLiableUserId() == null) { |
| | | // 获取当前用户ID |
| | | Long userId = SecurityUtils.getCurrentUserId(); |
| | | // 查询用户角色 |
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId); |
| | | if (roleSet.stream().anyMatch(role -> DataScopeEnum.find(role.getDataScope()) == DataScopeEnum.THIS_LEVEL)) { |
| | | // 根据用户ID查询负责的项目ID |
| | | List<Long> projectIdList = projectRepository.findIdByLiableUserId(userId); |
| | | // 根据用户ID查询参与的项目ID |
| | | List<Long> taskUserProjectIdList = projectCostRepository.findProjectIdByUserId(userId); |
| | | // 检索条件 |
| | | List<Long> totalProjectIdList = Stream.of(taskUserProjectIdList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList()); |
| | | if (totalProjectIdList.size() == 0) { |
| | | return PageUtil.toPage(Collections.emptyList(), 0); |
| | | } |
| | | criteria.setLiableUserId("-" + userId + "-"); |
| | | } |
| | | } |
| | | |
| | | Page<Project> page = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); |
| | | // 将实体类转换为DTO(重写) |
| | | Function<Project, ProjectDto> func = new Function<Project, ProjectDto>() { |
| | | @Override |
| | | public ProjectDto apply(Project project) { |
| | | // 将实体类转换成DTO |
| | | ProjectDto projectDto = projectMapper.toDto(project); |
| | | // 根据项目类型ID查询项目类型信息 |
| | | ProjectType projectType = projectTypeRepository.findById(projectDto.getProjectTypeId()).orElseGet(ProjectType::new); |
| | | ValidationUtil.isNull(project.getId(), "ProjectType", "id", projectDto.getProjectTypeId()); |
| | | // 项目类型名称 |
| | | projectDto.setProjectTypeName(projectType.getName()); |
| | | // 判断是否有负责人 |
| | | if (projectDto.getLiableUserId() != null) { |
| | | // 负责人名称 |
| | | String liableUserName = null; |
| | | // 负责人ID列表 |
| | | List<Long> liableUserIdList = new ArrayList<>(); |
| | | // 负责人ID |
| | | String handleLiableUserId = projectDto.getLiableUserId().replace("-", ""); |
| | | // 负责人ID列表 |
| | | String[] handleLiableUserIdList = handleLiableUserId.split(","); |
| | | // 循环负责人ID列表 |
| | | for (String liableUserId : handleLiableUserIdList) { |
| | | // 负责人ID列表 |
| | | liableUserIdList.add(Long.valueOf(liableUserId)); |
| | | // 根据负责人ID查询用户信息 |
| | | User user = userRepository.findById(Long.valueOf(liableUserId)).orElseGet(User::new); |
| | | ValidationUtil.isNull(project.getId(), "User", "id", projectDto.getLiableUserId()); |
| | | // 判断负责人名称 |
| | | liableUserName = liableUserName == null ? user.getNickName() : liableUserName + "," + user.getNickName(); |
| | | } |
| | | // 负责人ID列表 |
| | | projectDto.setLiableUserIdList(liableUserIdList); |
| | | // 负责人名称 |
| | | projectDto.setLiableUserName(liableUserName); |
| | | } |
| | | |
| | | ProjectTaskSummary projectTaskSummary = projectTaskRepository.findSummaryByProjectId(project.getId()); |
| | | projectDto.setTaskStartDate(projectTaskSummary.getTaskStartDate()); |
| | | projectDto.setTaskEndDate(projectTaskSummary.getTaskEndDate()); |
| | | projectDto.setTotalTaskTime(projectTaskSummary.getTotalTaskTime()); |
| | | |
| | | ProjectCostSummary projectCostSummary = projectCostRepository.findSummaryByProjectId(project.getId()); |
| | | projectDto.setTotalLaborCost(projectCostSummary.getTotalLaborCost()); |
| | | |
| | | // 其他项目成本 |
| | | List<ProjectCostOther> projectCostOtherList = projectCostOtherRepository.findByProjectId(project.getId()); |
| | | projectDto.setTotalOtherCost(projectCostOtherList.stream().map(ProjectCostOther::getProjectCost).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | |
| | | // 查询项目的任务数据 |
| | | TaskInterface taskInterface = taskRepository.collectByProjectId(project.getId()); |
| | | projectDto.setActualTaskTime(taskInterface.getPlanHours()); |
| | | |
| | | // 根据日期和项目ID取得日报信息 |
| | | List<TaskDailyInterface> taskDailyInterfaceList = taskDaliyRepository.collectByProjectIdGroupByUserIdAndFillDate(project.getId()); |
| | | Map<Long, List<TaskDailyInterface>> collectMap = taskDailyInterfaceList.stream().collect(Collectors.groupingBy(TaskDailyInterface::getUserId)); |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 实际消耗成本 |
| | | BigDecimal actualCost = BigDecimal.valueOf(0.0); |
| | | for (Entry<Long, List<TaskDailyInterface>> entry : collectMap.entrySet()) { |
| | | List<TaskDailyInterface> taskDaliyListSub = entry.getValue(); |
| | | // 最小日期 |
| | | TaskDailyInterface taskDaliyFirst = taskDaliyListSub.stream().min(Comparator.comparing(taskDaliy -> taskDaliy.getFillDate())).get(); |
| | | // 最大日期 |
| | | TaskDailyInterface taskDaliyLast = taskDaliyListSub.stream().max(Comparator.comparing(taskDaliy -> taskDaliy.getFillDate())).get(); |
| | | Map<String, Double> costHourMap = new HashMap<String, Double>(); |
| | | taskDaliyListSub.forEach(taskDaliy -> { |
| | | costHourMap.put(sdf.format(taskDaliy.getFillDate()), taskDaliy.getConsumedHours()); |
| | | }); |
| | | // 根据员工成本单金算出当前工作的成本 |
| | | actualCost = actualCost.add(projectCostService.calcUserCostByDate(entry.getKey(), new Timestamp(taskDaliyFirst.getFillDate().getTime()), new Timestamp(taskDaliyLast.getFillDate().getTime()), costHourMap)); |
| | | } |
| | | // 实际消耗成本 |
| | | projectDto.setActualLaborCost(actualCost); |
| | | // 项目二次处理 |
| | | projectDto = customHandle(projectDto); |
| | | // 返回处理好的Dto |
| | | return projectDto; |
| | | } |
| | | }; |
| | | return PageUtil.toPage(page.map(func)); |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectDto> queryAll2(ProjectQueryCriteria criteria) { |
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | } |
| | | |
| | | private ProjectDto customHandle(ProjectDto projectDto) { |
| | | // 任务合计(已分配) |
| | | Double divideTaskTime = 0D; |
| | | // 任务合计(已完成) |
| | | Double completedTaskTime = 0D; |
| | | // 根据项目ID查询任务列表 |
| | | Criteria criteria = new Criteria(); |
| | | criteria.and("projectId").is(projectDto.getId()); |
| | | Query query = new Query(criteria); |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class); |
| | | Criteria criteriaAggr = Criteria.where("task").in(taskMongoList); |
| | | |
| | | Aggregation customerAgg = Aggregation.newAggregation( |
| | | Aggregation.match(criteriaAggr), |
| | | Aggregation.project("taskStatus", "taskHours"), |
| | | Aggregation.group("taskStatus").count().as("taskStatusCnt").sum("taskHours").as("taskHours") |
| | | ); |
| | | |
| | | AggregationResults<TaskUserTotalDetailMongoDto> taskUserMongoList = mongoTemplate.aggregate(customerAgg, TaskUserMongo.class, TaskUserTotalDetailMongoDto.class); |
| | | for (TaskUserTotalDetailMongoDto taskUserTotalDetailMongoDto : taskUserMongoList.getMappedResults()) { |
| | | if (Constant.TASK_STATUS_COMPLETED.equals(taskUserTotalDetailMongoDto.get_id())) { |
| | | completedTaskTime += taskUserTotalDetailMongoDto.getTaskHours(); |
| | | } |
| | | divideTaskTime += taskUserTotalDetailMongoDto.getTaskHours(); |
| | | } |
| | | // 任务合计(已分配) |
| | | projectDto.setDivideTaskTime(DoubleUtil.maximumDigitLimit(divideTaskTime, 2)); |
| | | // 任务合计(已完成) |
| | | projectDto.setCompletedTaskTime(DoubleUtil.maximumDigitLimit(completedTaskTime, 2)); |
| | | // 任务合计(未完成) |
| | | projectDto.setIncompleteTaskTime(DoubleUtil.maximumDigitLimit(divideTaskTime - completedTaskTime, 2)); |
| | | return projectDto; |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectDto> queryAll(ProjectQueryCriteria criteria) { |
| | | if (criteria.getLiableUserId() == null) { |
| | | // 获取当前用户ID |
| | | Long userId = SecurityUtils.getCurrentUserId(); |
| | | // 查询用户角色 |
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId); |
| | | if (roleSet.stream().anyMatch(role -> DataScopeEnum.find(role.getDataScope()) == DataScopeEnum.THIS_LEVEL)) { |
| | | criteria.setLiableUserId("-" + userId + "-"); |
| | | } |
| | | } |
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectDto> queryRelevant(ProjectQueryCriteria criteria) { |
| | | // 获取登录用户角色等级 |
| | | List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()); |
| | | // 登录用户最大角色等级 |
| | | int min = Collections.min(levels); |
| | | List<Long> projectIdList = new ArrayList<>(); |
| | | // 判断角色等级 |
| | | if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) { |
| | | // 根据用户ID查询参与的项目ID |
| | | //List<Long> taskUserProjectIdList = taskDaliyRepository.findProjectIdByUserId(SecurityUtils.getCurrentUserId()); |
| | | //如果当前用户属于一个任务,那么他也可以看见当前这个任务的项目 |
| | | Query query = Query.query(Criteria.where("containUserList").is(SecurityUtils.getCurrentUserId())); |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class); |
| | | |
| | | ArrayList<Long> projectList = new ArrayList<>(); |
| | | for (TaskMongo taskMongo : taskMongoList) { |
| | | projectList.add(taskMongo.getProjectId()); |
| | | } |
| | | // 根据用户ID查询负责的项目ID |
| | | projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId()); |
| | | // 检索条件 |
| | | List<Long> totalProjectIdList = Stream.of(projectList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList()); |
| | | if (totalProjectIdList.size() == 0) { |
| | | return Collections.emptyList(); |
| | | } |
| | | criteria.setIdInList(totalProjectIdList); |
| | | } |
| | | // 项目列表 |
| | | List<ProjectDto> projectDtoList = projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | // 循环项目列表 |
| | | for (int i = 0; i < projectDtoList.size(); i++) { |
| | | // 项目 |
| | | ProjectDto projectDto = projectDtoList.get(i); |
| | | |
| | | if (projectDto.getLiableUserId() != null && !"".equals(projectDto.getLiableUserId())) { |
| | | // 负责人ID列表 |
| | | List<Long> liableUserIdList = new ArrayList<>(); |
| | | // 负责人ID |
| | | String handleLiableUserId = projectDto.getLiableUserId().replace("-", ""); |
| | | // 负责人ID列表 |
| | | String[] handleLiableUserIdList = handleLiableUserId.split(","); |
| | | // 循环负责人ID列表 |
| | | for (String liableUserId : handleLiableUserIdList) { |
| | | // 负责人ID列表 |
| | | liableUserIdList.add(Long.valueOf(liableUserId)); |
| | | } |
| | | // 负责人ID列表 |
| | | projectDto.setLiableUserIdList(liableUserIdList); |
| | | } |
| | | } |
| | | |
| | | if (!(min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY)){ |
| | | for (ProjectDto projectDto : projectDtoList) { |
| | | projectDto.setFlag(true); |
| | | } |
| | | return projectDtoList; |
| | | } |
| | | |
| | | for (ProjectDto projectDto : projectDtoList) { |
| | | for (Long project : projectIdList) { |
| | | //当前用户所负责的项目ID |
| | | //如果当前用户负责的项目ID在这个集合中,就给那个项目打一个标识 |
| | | if (projectDto.getId().equals(project)) { |
| | | projectDto.setFlag(true); |
| | | break; |
| | | } else { |
| | | projectDto.setFlag(false); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return projectDtoList; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public ProjectDto findById(Long id) { |
| | | Project project = projectRepository.findById(id).orElseGet(Project::new); |
| | | ValidationUtil.isNull(project.getId(), "Project", "id", id); |
| | | return projectMapper.toDto(project); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ProjectDto create(Project resources) { |
| | | return projectMapper.toDto(projectRepository.save(resources)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(Project resources) { |
| | | Project project = projectRepository.findById(resources.getId()).orElseGet(Project::new); |
| | | ValidationUtil.isNull(project.getId(), "Project", "id", resources.getId()); |
| | | project.copy(resources); |
| | | projectRepository.save(project); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteAll(Long[] ids) { |
| | | for (Long id : ids) { |
| | | // 根据项目ID查询任务日报 |
| | | List<TaskDaliy> taskDaliyList = taskDaliyRepository.findByProjectId(id); |
| | | // 判断任务日报数量 |
| | | if (taskDaliyList.size() == 0) { |
| | | projectRepository.deleteById(id); |
| | | projectTaskRepository.deleteByProjectId(id); |
| | | projectCostRepository.deleteByProjectId(id); |
| | | projectProgressRepository.deleteByProjectId(id); |
| | | projectPerformanceRepository.deleteByProjectId(id); |
| | | projectPerformanceDetailRepository.deleteByProjectId(id); |
| | | costRepository.deleteByProjectId(id); |
| | | taskRepository.deleteByProjectId(id); |
| | | taskUserRepository.deleteByProjectId(id); |
| | | taskDaliyRepository.deleteByProjectId(id); |
| | | contractProjectRepository.deleteByProjectId(id); |
| | | } else { |
| | | throw new BadRequestException("存在任务日报的项目无法删除!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateProjectAdmit(Long[] ids) { |
| | | // 获取当前用户ID |
| | | Long userId = SecurityUtils.getCurrentUserId(); |
| | | // 查询用户角色 |
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId); |
| | | Long min = roleSet.stream().mapToLong(RoleSmallDto::getLevel).min().getAsLong(); |
| | | for (Long id : ids) { |
| | | // 查询项目 |
| | | Project project = projectRepository.findByIdUpdate(id); |
| | | if (min == Constant.ROLE_LEVEL_SUPER) { |
| | | project.setApproveStatus(Constant.APPROVE_STATUS_ACKNOWLEDGED); |
| | | } else if (min == Constant.ROLE_LEVEL_GENERAL) { |
| | | project.setApproveStatus(Constant.APPROVE_STATUS_MASTER_ACKNOWLEDGED); |
| | | } else if (min == Constant.ROLE_LEVEL_MANAGER) { |
| | | project.setApproveStatus(Constant.APPROVE_STATUS_LEADER_ACKNOWLEDGED); |
| | | } |
| | | // 更新项目 |
| | | update(project); |
| | | |
| | | // 已承认的项目,生成任务 |
| | | if (Constant.APPROVE_STATUS_ACKNOWLEDGED.equals(project.getProjectStatus())) { |
| | | // 查询项目任务 |
| | | List<ProjectTask> projectTaskList = projectTaskRepository.findByProjectId(id); |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(Query.query(new Criteria("projectId").is(id)), TaskMongo.class); |
| | | if (taskMongoList.size() == 0) { |
| | | // 从项目任务拷贝到任务中 |
| | | for (int i = 0; i < projectTaskList.size(); i++) { |
| | | TaskMongo taskMongo = new TaskMongo(); |
| | | taskMongo.setProjectId(projectTaskList.get(i).getProjectId()); |
| | | taskMongo.setName(projectTaskList.get(i).getName()); |
| | | // // TODO |
| | | // taskMongo.setTagList(Arrays.asList(projectTaskList.get(i).getTaskClassification())); |
| | | if (projectTaskList.get(i).getDescription() != null) { |
| | | taskMongo.setDescription(projectTaskList.get(i).getDescription()); |
| | | } |
| | | taskMongo.setPlanHours(projectTaskList.get(i).getPlanHours()); |
| | | if (projectTaskList.get(i).getPlanWorkload() != null) { |
| | | taskMongo.setPlanWorkload(projectTaskList.get(i).getPlanWorkload()); |
| | | } |
| | | if (projectTaskList.get(i).getPlanWorkloadUnit() != null) { |
| | | taskMongo.setPlanWorkloadUnit(projectTaskList.get(i).getPlanWorkloadUnit()); |
| | | } |
| | | if (projectTaskList.get(i).getRemarks() != null) { |
| | | taskMongo.setDescription(projectTaskList.get(i).getRemarks()); |
| | | } |
| | | // task.setPriority(Constant.PRIORITY_LOW); |
| | | // 绩效区分 |
| | | taskMongo.setPerformanceType(projectTaskList.get(i).getPerformanceType()); |
| | | // 未开始 |
| | | taskMongo.setTaskStatus(Constant.TASK_STATUS_NOT_STARTED); |
| | | taskMongo.setPlanStartTime(projectTaskList.get(i).getPlanStartTime()); |
| | | taskMongo.setPlanEndTime(projectTaskList.get(i).getPlanEndTime()); |
| | | mongoTemplate.insert(taskMongo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateProjectDisavow(Long[] ids) { |
| | | for (Long id : ids) { |
| | | // 查询项目 |
| | | Project project = projectRepository.findByIdUpdate(id); |
| | | project.setApproveStatus(Constant.APPROVE_STATUS_UNRECOGNIZED); |
| | | // 更新项目 |
| | | update(project); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void download(List<ProjectDto> all, HttpServletResponse response) throws IOException { // TODO |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (ProjectDto project : all) { |
| | | String projectTypeName = project.getProjectTypeId() != null ? projectTypeRepository.findById(project.getProjectTypeId()).orElseGet(ProjectType::new).getName() : ""; |
| | | String projectDistinguish = project.getProjectDistinguish() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PROJECT_DISTINGUISH, project.getProjectDistinguish()).getLabel() : ""; |
| | | String projectStatus = project.getProjectStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PROJECT_STATUS, project.getProjectStatus()).getLabel() : ""; |
| | | String approveStatus = project.getApproveStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.APPROVE_STATUS, project.getApproveStatus()).getLabel() : ""; |
| | | String unitCurrency = project.getUnitCurrency() != null ? dictDetailRepository.findByDictNameAndValue(Constant.STANDARD_UNIT_CURRENCY, project.getUnitCurrency()).getLabel() : ""; |
| | | // 负责人名称 |
| | | String liableUserName = null; |
| | | |
| | | if (project.getLiableUserId() != null && !"".equals(project.getLiableUserId())) { |
| | | // 处理后负责人ID |
| | | String handleLiableUserId = project.getLiableUserId().replace("-", ""); |
| | | // 处理后负责人ID列表 |
| | | String[] handleLiableUserIdList = handleLiableUserId.split(","); |
| | | // 循环处理后负责人ID列表 |
| | | for (String liableUserId : handleLiableUserIdList) { |
| | | // 根据负责人ID查询用户信息 |
| | | User user = userRepository.findById(Long.valueOf(liableUserId)).orElseGet(User::new); |
| | | // 判断负责人名称 |
| | | liableUserName = liableUserName == null ? user.getNickName() : liableUserName + "," + user.getNickName(); |
| | | } |
| | | } |
| | | |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("名称", project.getName()); |
| | | map.put("项目类型", projectTypeName); |
| | | map.put("项目区分:", projectDistinguish); |
| | | map.put("需求说明", project.getRequirement()); |
| | | map.put("单价币种", unitCurrency); |
| | | // TODO |
| | | // map.put("单价金额", project.getUnitPrice()); |
| | | // map.put("报价金额", project.getTotalPrice()); |
| | | map.put("责任人", liableUserName); |
| | | map.put("计划开始日期", project.getPlanStartDate()); |
| | | map.put("计划结束日期", project.getPlanEndDate()); |
| | | map.put("项目状态", projectStatus); |
| | | map.put("批准状态", approveStatus); |
| | | map.put("备注", project.getRemarks()); |
| | | map.put("创建者", project.getCreateBy()); |
| | | map.put("创建时间", project.getCreateTime()); |
| | | map.put("更新者", project.getUpdateBy()); |
| | | map.put("更新时间", project.getUpdateTime()); |
| | | list.add(map); |
| | | } |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectDto> queryPartakeAll(ProjectQueryCriteria criteria) { |
| | | // 根据用户ID查询项目ID |
| | | List<Long> partakeProjectIds = taskUserRepository.findProjectIdByUserId(criteria.getTaskUserId()); |
| | | // 判断长度 |
| | | if (partakeProjectIds.size() == 0) { |
| | | return new ArrayList<>(); |
| | | } |
| | | // 项目检索条件 |
| | | criteria.setIdInList(partakeProjectIds); |
| | | criteria.setProjectStatusNotEqual(Constant.PROJECT_STATUS_COMPLETED); |
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> querySubgroupTurnover(ProjectQueryCriteria criteria) { |
| | | // 判断入参完整性 |
| | | if (criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) { |
| | | return null; |
| | | } |
| | | // 根据字典名称查询 |
| | | List<DictDetail> dictDetailList = dictDetailRepository.findByDictName(Constant.PROJECT_DISTINGUISH); |
| | | // 查询汇率列表 |
| | | List<SysExchangeRateDto> sysExchangeRateDtoList = sysExchangeRateService.queryAll(new SysExchangeRateQueryCriteria()); |
| | | // 根据目标年份查询分组营业额 |
| | | List<ProjectSummary> projectSummaryList = projectRepository.findSubgroupTurnoverByTargetYear(criteria.getTargetYear()); |
| | | // 根据目标年份查询分组目标金额 |
| | | SysGoalSettingQueryCriteria sysGoalSettingQueryCriteria = new SysGoalSettingQueryCriteria(); |
| | | sysGoalSettingQueryCriteria.setTargetYear(criteria.getTargetYear()); |
| | | List<SysGoalSettingDto> sysGoalSettingDtoList = sysGoalSettingService.queryAll(sysGoalSettingQueryCriteria); |
| | | // 返回列表 |
| | | List<Map<String, Object>> returnList = new ArrayList<>(); |
| | | // 循环项目区分 |
| | | for (int i = 0; i < dictDetailList.size(); i++) { |
| | | // 返回集合 |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | // 当前项目区分 |
| | | DictDetail dictDetail = dictDetailList.get(i); |
| | | // 返回集合 |
| | | returnMap.put("projectDistinguish", dictDetail.getLabel()); |
| | | // 营业额 |
| | | BigDecimal contractPrice = new BigDecimal(0); |
| | | // 循环分组营业额 |
| | | for (int j = 0; j < projectSummaryList.size(); j++) { |
| | | // 当前项目区分 |
| | | ProjectSummary projectSummary = projectSummaryList.get(j); |
| | | // 判断与项目区分是否一致 |
| | | if (dictDetail.getValue().equals(projectSummary.getProjectDistinguish())) { |
| | | // 当前汇率列表 |
| | | List<SysExchangeRateDto> currentSysExchangeRateDtoList = sysExchangeRateDtoList.stream().filter(item -> item.getUnitCurrency().equals(projectSummary.getUnitCurrency())).collect(Collectors.toList()); |
| | | // 判断当前汇率列表长度 |
| | | if (currentSysExchangeRateDtoList.size() == 1) { |
| | | // 营业额 |
| | | contractPrice = contractPrice.add(projectSummary.getContractPrice().multiply(currentSysExchangeRateDtoList.get(0).getExchangeRate())); |
| | | } |
| | | } |
| | | // 判断循环是否结束 |
| | | if (j == projectSummaryList.size() - 1) { |
| | | // 返回集合 |
| | | returnMap.put("contractPrice", contractPrice); |
| | | } |
| | | } |
| | | // 循环分组目标金额 |
| | | for (int j = 0; j < sysGoalSettingDtoList.size(); j++) { |
| | | // 判断与项目区分是否一致 |
| | | if (dictDetail.getValue().equals(sysGoalSettingDtoList.get(j).getProjectDistinguish())) { |
| | | // 返回集合 |
| | | returnMap.put("targetAmount", sysGoalSettingDtoList.get(j).getTargetAmount()); |
| | | break; |
| | | } |
| | | // 判断循环是否结束 |
| | | if (j == sysGoalSettingDtoList.size() - 1) { |
| | | // 返回集合 |
| | | returnMap.put("targetAmount", new BigDecimal(0)); |
| | | } |
| | | } |
| | | // 返回列表 |
| | | returnList.add(returnMap); |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> querySubgroupWorkingHours(ProjectQueryCriteria criteria) { |
| | | // 根据字典名称查询 |
| | | List<DictDetail> dictDetailList = dictDetailRepository.findByDictName(Constant.PROJECT_DISTINGUISH); |
| | | // 查询项目列表 |
| | | List<Project> projectList = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)); |
| | | List<Long> projectIdList = projectList.stream().map(Project::getId).collect(Collectors.toList()); |
| | | // 查询任务列表 |
| | | List<TaskInterface> taskInterfaceList = taskRepository.findSubgroupWorkingHoursByProjectId(projectIdList); |
| | | // 返回列表 |
| | | List<Map<String, Object>> returnList = new ArrayList<>(); |
| | | // 循环项目区分 |
| | | for (int i = 0; i < dictDetailList.size(); i++) { |
| | | // 已分配工时 |
| | | Double divideHours = 0D; |
| | | // 未完成工时 |
| | | Double incompleteHours = 0D; |
| | | // 返回集合 |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | // 当前项目区分 |
| | | DictDetail dictDetail = dictDetailList.get(i); |
| | | // 返回集合 |
| | | returnMap.put("projectDistinguish", dictDetail.getLabel()); |
| | | // 当前任务列表 |
| | | List<TaskInterface> currentTaskInterfaceList = taskInterfaceList.stream().filter(item -> item.getProjectDistinguish().equals(dictDetail.getValue())).collect(Collectors.toList()); |
| | | // 循环当前任务列表 |
| | | for (int j = 0; j < currentTaskInterfaceList.size(); j++) { |
| | | // 当前任务 |
| | | TaskInterface currentTaskInterface = currentTaskInterfaceList.get(j); |
| | | Task task = taskRepository.findById(currentTaskInterface.getTaskId()).orElseGet(Task::new); |
| | | // 当前任务二次处理 |
| | | TaskDto taskDto = taskMapper.toDto(task); |
| | | taskDto = taskService.customHandleMini(taskDto); |
| | | // 已分配工时 |
| | | divideHours += taskDto.getDivideHours(); |
| | | // 未完成工时 |
| | | incompleteHours += (taskDto.getDivideHours() - taskDto.getCompletedHours()); |
| | | } |
| | | // 返回集合 |
| | | returnMap.put("divideHours", DoubleUtil.maximumDigitLimit(divideHours, 2)); |
| | | returnMap.put("incompleteHours", DoubleUtil.maximumDigitLimit(incompleteHours, 2)); |
| | | // 返回列表 |
| | | returnList.add(returnMap); |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> queryProjectWorkingHours(ProjectQueryCriteria criteria) { |
| | | // 判断入参完整性 |
| | | if (criteria.getId() == null) { |
| | | return null; |
| | | } |
| | | // 根据项目ID查询项目 |
| | | ProjectDto projectDto = projectMapper.toDto(projectRepository.findById(criteria.getId()).orElseGet(Project::new)); |
| | | // 项目二次处理 |
| | | projectDto = customHandle(projectDto); |
| | | // 返回集合 |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | returnMap.put("divideHours", projectDto.getDivideTaskTime()); |
| | | returnMap.put("incompleteHours", projectDto.getIncompleteTaskTime()); |
| | | return returnMap; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> queryTypeContractPrice(ProjectQueryCriteria criteria) { |
| | | // 判断入参完整性 |
| | | if (criteria.getProjectDistinguish() == null || "".equals(criteria.getProjectDistinguish()) || criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) { |
| | | return null; |
| | | } |
| | | // 查询汇率列表 |
| | | List<SysExchangeRateDto> sysExchangeRateDtoList = sysExchangeRateService.queryAll(new SysExchangeRateQueryCriteria()); |
| | | // 根据项目区分、目标年份查询类型营业额 |
| | | List<ProjectSummary> projectSummaryList = projectRepository.findTypeContractPriceByProjectDistinguishAndTargetYear(criteria.getProjectDistinguish(), criteria.getTargetYear()); |
| | | // 项目类型列表 |
| | | List<String> projectTypeNameList = projectSummaryList.stream().map(ProjectSummary::getProjectTypeName).distinct().collect(Collectors.toList()); |
| | | // 返回列表 |
| | | List<Map<String, Object>> returnList = new ArrayList<>(); |
| | | // 循环项目类型列表 |
| | | for (int i = 0; i < projectTypeNameList.size(); i++) { |
| | | // 项目类型 |
| | | String projectTypeName = projectTypeNameList.get(i); |
| | | // 返回集合 |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | returnMap.put("name", projectTypeName); |
| | | // 当前项目类型营业额列表 |
| | | List<ProjectSummary> currentProjectSummaryList = projectSummaryList.stream().filter(item -> item.getProjectTypeName().equals(projectTypeName)).collect(Collectors.toList()); |
| | | // 营业额 |
| | | BigDecimal contractPrice = new BigDecimal(0); |
| | | // 循环当前项目类型营业额列表 |
| | | for (int j = 0; j < currentProjectSummaryList.size(); j++) { |
| | | // 当前项目类型营业额 |
| | | ProjectSummary currentProjectSummary = currentProjectSummaryList.get(j); |
| | | // 当前汇率列表 |
| | | List<SysExchangeRateDto> currentSysExchangeRateDtoList = sysExchangeRateDtoList.stream().filter(item -> item.getUnitCurrency().equals(currentProjectSummary.getUnitCurrency())).collect(Collectors.toList()); |
| | | // 判断当前汇率列表长度 |
| | | if (currentSysExchangeRateDtoList.size() == 1) { |
| | | // 营业额 |
| | | contractPrice = contractPrice.add(currentProjectSummary.getContractPrice().multiply(currentSysExchangeRateDtoList.get(0).getExchangeRate())); |
| | | } |
| | | } |
| | | returnMap.put("value", contractPrice); |
| | | // 返回列表 |
| | | returnList.add(returnMap); |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> queryTypeWorkingHours(ProjectQueryCriteria criteria) { |
| | | // 判断入参完整性 |
| | | if (criteria.getProjectDistinguish() == null || "".equals(criteria.getProjectDistinguish()) || criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) { |
| | | return null; |
| | | } |
| | | // 根据项目区分、目标年份查询项目 |
| | | List<Project> projectList = projectRepository.findProjectByProjectDistinguishAndTargetYear(criteria.getProjectDistinguish(), criteria.getTargetYear()); |
| | | // 查询项目类型列表 |
| | | ProjectTypeQueryCriteria projectTypeQueryCriteria = new ProjectTypeQueryCriteria(); |
| | | List<ProjectType> projectTypeList = projectTypeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, projectTypeQueryCriteria, criteriaBuilder)); |
| | | // 返回列表 |
| | | List<Map<String, Object>> returnList = new ArrayList<>(); |
| | | // 循环项目类型列表 |
| | | for (int i = 0; i < projectTypeList.size(); i++) { |
| | | // 项目类型 |
| | | ProjectType projectType = projectTypeList.get(i); |
| | | // 处理后项目列表 |
| | | List<Project> handleProjectList = projectList.stream().filter(item -> item.getProjectTypeId() == projectType.getId()).collect(Collectors.toList()); |
| | | // 判断处理后项目列表长度 |
| | | if (handleProjectList.size() != 0) { |
| | | // 处理后项目ID列表 |
| | | List<Long> handleProjectIdList = handleProjectList.stream().map(Project::getId).collect(Collectors.toList()); |
| | | // 根据项目ID查询总工时 |
| | | Double sumWorkingHours = taskRepository.sumWorkingHoursByProjectId(handleProjectIdList); |
| | | // 返回集合 |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | returnMap.put("name", projectType.getName()); |
| | | returnMap.put("value", sumWorkingHours); |
| | | // 返回列表 |
| | | returnList.add(returnMap); |
| | | } |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectDto> querySubgroupTopHours(ProjectQueryCriteria criteria) { |
| | | // 判断入参完整性 |
| | | if (criteria.getProjectDistinguish() == null || "".equals(criteria.getProjectDistinguish())) { |
| | | return null; |
| | | } |
| | | // 查询项目列表 |
| | | List<ProjectDto> projectDtoList = projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | // 循环项目列表 |
| | | for (int i = 0; i < projectDtoList.size(); i++) { |
| | | // 当前项目 |
| | | ProjectDto projectDto = projectDtoList.get(i); |
| | | // 项目二次处理 |
| | | projectDto = customHandle(projectDto); |
| | | } |
| | | // 按照任务合计(未完成)进行降序排列 |
| | | projectDtoList = projectDtoList.stream().sorted(Comparator.comparing(ProjectDto::getIncompleteTaskTime).reversed()).collect(Collectors.toList()); |
| | | return projectDtoList; |
| | | } |
| | | |
| | | @Override |
| | | //@Cacheable(cacheNames = "project",key = "{#p0}") |
| | | public List<ProjectDto> queryRelevantOfDaily(Long userId) { |
| | | List<TaskUserMongo> taskUserMongos = mongoTemplate.find(Query.query(new Criteria("userId").is(userId) |
| | | .and("taskStatus").in(Constant.TASK_STATUS_NOT_STARTED, Constant.TASK_STATUS_IN_HAND, Constant.TASK_STATUS_TEST, Constant.TASK_STATUS_UNRECOGNIZED)), TaskUserMongo.class); |
| | | List<Long> projectIds = taskUserMongos.stream().map(taskUserMongo -> taskUserMongo.getTask().getProjectId()).distinct().collect(Collectors.toList()); |
| | | List<Project> projectList = projectRepository.findByProjectStatusInAndIdIn(Arrays.asList(Constant.PROJECT_STATUS_NOT_STARTED, Constant.PROJECT_STATUS_UNDER_WAY), projectIds); |
| | | return projectList.stream().map(project -> { |
| | | ProjectDto projectDto = new ProjectDto(); |
| | | projectDto.setId(project.getId()); |
| | | projectDto.setName(project.getName()); |
| | | return projectDto; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | /*
|
| | | * Copyright 2019-2020 Zheng Jie
|
| | | *
|
| | | * Licensed under the Apache License, Version 2.0 (the "License");
|
| | | * you may not use this file except in compliance with the License.
|
| | | * You may obtain a copy of the License at
|
| | | *
|
| | | * http://www.apache.org/licenses/LICENSE-2.0
|
| | | *
|
| | | * Unless required by applicable law or agreed to in writing, software
|
| | | * distributed under the License is distributed on an "AS IS" BASIS,
|
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| | | * See the License for the specific language governing permissions and
|
| | | * limitations under the License.
|
| | | */
|
| | | package me.zhengjie.modules.project.service.impl;
|
| | |
|
| | | import lombok.RequiredArgsConstructor;
|
| | | import me.zhengjie.exception.BadRequestException;
|
| | | import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository;
|
| | | import me.zhengjie.modules.constant.Constant;
|
| | | import me.zhengjie.modules.contract.repository.ContractProjectRepository;
|
| | | import me.zhengjie.modules.cost.repository.CostRepository;
|
| | | import me.zhengjie.modules.project.domain.*;
|
| | | import me.zhengjie.modules.project.repository.*;
|
| | | import me.zhengjie.modules.project.service.ProjectCostService;
|
| | | 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.project.service.dto.ProjectTypeQueryCriteria;
|
| | | import me.zhengjie.modules.project.service.mapstruct.ProjectMapper;
|
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
|
| | | 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.SysExchangeRateService;
|
| | | import me.zhengjie.modules.system.service.SysGoalSettingService;
|
| | | import me.zhengjie.modules.system.service.dto.*;
|
| | | 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.TaskUserTotalDetailMongoDto;
|
| | | import me.zhengjie.modules.task.service.mapstruct.TaskMapper;
|
| | | import me.zhengjie.utils.*;
|
| | | import me.zhengjie.utils.enums.DataScopeEnum;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | 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.data.mongodb.core.aggregation.Aggregation;
|
| | | import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
| | | import org.springframework.data.mongodb.core.query.Criteria;
|
| | | import org.springframework.data.mongodb.core.query.Query;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.*;
|
| | | import java.util.function.Function;
|
| | | import java.util.stream.Collectors;
|
| | | import java.util.stream.Stream;
|
| | |
|
| | |
|
| | | /**
|
| | | * @author HuaZhe
|
| | | * @website https://eladmin.vip
|
| | | * @description 服务实现
|
| | | * @date 2022-12-15
|
| | | **/
|
| | | @Service
|
| | | @RequiredArgsConstructor
|
| | | public class ProjectServiceImpl implements ProjectService { // TODO redis化
|
| | |
|
| | | private final ProjectRepository projectRepository;
|
| | | private final ProjectMapper projectMapper;
|
| | | private final ProjectTypeRepository projectTypeRepository;
|
| | | private final UserRepository userRepository;
|
| | | private final DictDetailRepository dictDetailRepository;
|
| | | private final RoleService roleService;
|
| | | private final TaskUserRepository taskUserRepository;
|
| | | private final ProjectCostRepository projectCostRepository;
|
| | | private final ProjectCostOtherRepository projectCostOtherRepository;
|
| | | private final TaskRepository taskRepository;
|
| | | private final TaskDaliyRepository taskDaliyRepository;
|
| | | private final ProjectCostService projectCostService;
|
| | | private final ProjectProgressRepository projectProgressRepository;
|
| | | private final ProjectPerformanceRepository projectPerformanceRepository;
|
| | | private final ProjectPerformanceDetailRepository projectPerformanceDetailRepository;
|
| | | private final CostRepository costRepository;
|
| | | private final ContractProjectRepository contractProjectRepository;
|
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
|
| | | private final SysGoalSettingService sysGoalSettingService;
|
| | | private final WeComServiceImpl weComService;
|
| | |
|
| | | @Autowired
|
| | | private TaskService taskService;
|
| | | private final TaskMapper taskMapper;
|
| | | private final SysExchangeRateService sysExchangeRateService;
|
| | | private final MongoTemplate mongoTemplate;
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> queryAll(ProjectQueryCriteria criteria, Pageable pageable) {
|
| | |
|
| | | if (criteria.getLiableUserId() == null) {
|
| | | // 获取当前用户ID
|
| | | Long userId = SecurityUtils.getCurrentUserId();
|
| | | // 查询用户角色
|
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId);
|
| | | if (roleSet.stream().anyMatch(role -> DataScopeEnum.find(role.getDataScope()) == DataScopeEnum.THIS_LEVEL)) {
|
| | | // 根据用户ID查询负责的项目ID
|
| | | List<Long> projectIdList = projectRepository.findIdByLiableUserId(userId);
|
| | | // 根据用户ID查询参与的项目ID
|
| | | List<Long> taskUserProjectIdList = projectCostRepository.findProjectIdByUserId(userId);
|
| | | // 检索条件
|
| | | List<Long> totalProjectIdList = Stream.of(taskUserProjectIdList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
| | | if (totalProjectIdList.size() == 0) {
|
| | | return PageUtil.toPage(Collections.emptyList(), 0);
|
| | | }
|
| | | criteria.setLiableUserId("-" + userId + "-");
|
| | | }
|
| | | }
|
| | |
|
| | | Page<Project> page = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
| | | // 将实体类转换为DTO(重写)
|
| | | Function<Project, ProjectDto> func = new Function<Project, ProjectDto>() {
|
| | | @Override
|
| | | public ProjectDto apply(Project project) {
|
| | | // 将实体类转换成DTO
|
| | | ProjectDto projectDto = projectMapper.toDto(project);
|
| | | // 根据项目类型ID查询项目类型信息
|
| | | ProjectType projectType = projectTypeRepository.findById(projectDto.getProjectTypeId()).orElseGet(ProjectType::new);
|
| | | ValidationUtil.isNull(project.getId(), "ProjectType", "id", projectDto.getProjectTypeId());
|
| | | // 项目类型名称
|
| | | projectDto.setProjectTypeName(projectType.getName());
|
| | | // 判断是否有负责人
|
| | | if (projectDto.getLiableUserId() != null) {
|
| | | // 负责人名称
|
| | | String liableUserName = null;
|
| | | // 负责人ID列表
|
| | | List<Long> liableUserIdList = new ArrayList<>();
|
| | | // 负责人ID
|
| | | String handleLiableUserId = projectDto.getLiableUserId().replace("-", "");
|
| | | // 负责人ID列表
|
| | | String[] handleLiableUserIdList = handleLiableUserId.split(",");
|
| | | // 循环负责人ID列表
|
| | | for (String liableUserId : handleLiableUserIdList) {
|
| | | // 负责人ID列表
|
| | | liableUserIdList.add(Long.valueOf(liableUserId));
|
| | | // 根据负责人ID查询用户信息
|
| | | User user = userRepository.findById(Long.valueOf(liableUserId)).orElseGet(User::new);
|
| | | ValidationUtil.isNull(project.getId(), "User", "id", projectDto.getLiableUserId());
|
| | | // 判断负责人名称
|
| | | liableUserName = liableUserName == null ? user.getNickName() : liableUserName + "," + user.getNickName();
|
| | | }
|
| | | // 负责人ID列表
|
| | | projectDto.setLiableUserIdList(liableUserIdList);
|
| | | // 负责人名称
|
| | | projectDto.setLiableUserName(liableUserName);
|
| | | }
|
| | |
|
| | | ProjectCostSummary projectCostSummary = projectCostRepository.findSummaryByProjectId(project.getId());
|
| | | projectDto.setTotalLaborCost(projectCostSummary.getTotalLaborCost());
|
| | |
|
| | | // 其他项目成本
|
| | | List<ProjectCostOther> projectCostOtherList = projectCostOtherRepository.findByProjectId(project.getId());
|
| | | projectDto.setTotalOtherCost(projectCostOtherList.stream().map(ProjectCostOther::getProjectCost).reduce(BigDecimal.ZERO, BigDecimal::add));
|
| | |
|
| | | // 根据日期和项目ID取得日报信息
|
| | | Query query = new Query(Criteria.where("projectId").is(project.getId()));
|
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
|
| | |
|
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(Criteria.where("task").in(taskMongoList)), TaskUserMongo.class);
|
| | | Aggregation customerAgg = Aggregation.newAggregation(
|
| | | Aggregation.match(Criteria.where("taskUserMongo").in(taskUserMongoList)),
|
| | | Aggregation.project("userId", "consumedHours"),
|
| | | Aggregation.group("userId").sum("consumedHours").as("consumedHours")
|
| | | );
|
| | |
|
| | | AggregationResults<Map> aggregate = mongoTemplate.aggregate(customerAgg, TaskDaliyMongo.class, Map.class);
|
| | | BigDecimal actualCost =aggregate.getMappedResults().stream().filter(data -> data.get("_id") != null).map(data -> {
|
| | | BigDecimal moneyTotalCost = projectCostService.calcUserCostByHours(Long.parseLong(String.valueOf(data.get("_id"))), Double.valueOf(String.valueOf(data.get("consumedHours"))));
|
| | | return moneyTotalCost;
|
| | | }).reduce(BigDecimal.ZERO, BigDecimal::add);
|
| | |
|
| | | // 实际消耗成本
|
| | | projectDto.setActualLaborCost(actualCost);
|
| | | // 项目二次处理
|
| | | projectDto = customHandle(projectDto);
|
| | |
|
| | | // 项目出差总天数
|
| | | projectDto.setTotalTravelDuration(attendanceBusinessTravelRepository.countProjectTravelDuration(project.getId()));
|
| | |
|
| | | // 返回处理好的Dto
|
| | | return projectDto;
|
| | | }
|
| | | };
|
| | | return PageUtil.toPage(page.map(func));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ProjectDto> queryAll2(ProjectQueryCriteria criteria) {
|
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
| | | }
|
| | |
|
| | | private ProjectDto customHandle(ProjectDto projectDto) {
|
| | | // 任务合计(计划)
|
| | | Double planTaskTime = 0D;
|
| | | // 任务合计(实际)
|
| | | Double actualTaskTime = 0D;
|
| | | // 任务合计(已完成实际)
|
| | | Double completedActualTaskTime = 0D;
|
| | | // 任务合计(已分配)
|
| | | Double divideTaskTime = 0D;
|
| | | // 任务合计(已完成)
|
| | | Double completedTaskTime = 0D;
|
| | | // 根据项目ID查询任务列表
|
| | | Criteria criteria = new Criteria();
|
| | | criteria.and("projectId").is(projectDto.getId());
|
| | | Query query = new Query(criteria);
|
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
|
| | | Criteria criteriaAggr = Criteria.where("task").in(taskMongoList);
|
| | |
|
| | | Aggregation customerAgg = Aggregation.newAggregation(
|
| | | Aggregation.match(criteriaAggr),
|
| | | Aggregation.project("taskStatus", "taskHours", "costHours"),
|
| | | Aggregation.group("taskStatus").count().as("taskStatusCnt").sum("taskHours").as("taskHours").sum("costHours").as("costHours")
|
| | | );
|
| | |
|
| | | AggregationResults<TaskUserTotalDetailMongoDto> taskUserMongoList = mongoTemplate.aggregate(customerAgg, TaskUserMongo.class, TaskUserTotalDetailMongoDto.class);
|
| | | for (TaskUserTotalDetailMongoDto taskUserTotalDetailMongoDto : taskUserMongoList.getMappedResults()) {
|
| | | if (Constant.TASK_STATUS_COMPLETED.equals(taskUserTotalDetailMongoDto.get_id())) {
|
| | | completedTaskTime += taskUserTotalDetailMongoDto.getTaskHours();
|
| | | completedActualTaskTime += taskUserTotalDetailMongoDto.getCostHours();
|
| | | }
|
| | | actualTaskTime += taskUserTotalDetailMongoDto.getCostHours();
|
| | | planTaskTime += taskUserTotalDetailMongoDto.getTaskHours();
|
| | | divideTaskTime += taskUserTotalDetailMongoDto.getTaskHours();
|
| | | }
|
| | | // 任务合计(计划)
|
| | | projectDto.setTotalTaskTime(planTaskTime);
|
| | | // 任务合计(实际)
|
| | | projectDto.setActualTaskTime(actualTaskTime);
|
| | | // 任务合计(已完成实际)
|
| | | projectDto.setCompletedActualTaskTime(completedActualTaskTime);
|
| | | // 任务合计(已分配)
|
| | | projectDto.setDivideTaskTime(DoubleUtil.maximumDigitLimit(divideTaskTime, 2));
|
| | | // 任务合计(已完成)
|
| | | projectDto.setCompletedTaskTime(DoubleUtil.maximumDigitLimit(completedTaskTime, 2));
|
| | | // 任务合计(未完成)
|
| | | projectDto.setIncompleteTaskTime(DoubleUtil.maximumDigitLimit(divideTaskTime - completedTaskTime, 2));
|
| | | return projectDto;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ProjectDto> queryAll(ProjectQueryCriteria criteria) {
|
| | | if (criteria.getLiableUserId() == null) {
|
| | | // 获取当前用户ID
|
| | | Long userId = SecurityUtils.getCurrentUserId();
|
| | | // 查询用户角色
|
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId);
|
| | | if (roleSet.stream().anyMatch(role -> DataScopeEnum.find(role.getDataScope()) == DataScopeEnum.THIS_LEVEL)) {
|
| | | criteria.setLiableUserId("-" + userId + "-");
|
| | | }
|
| | | }
|
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ProjectDto> queryRelevant(ProjectQueryCriteria criteria) {
|
| | | // 获取登录用户角色等级
|
| | | List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
|
| | | // 登录用户最大角色等级
|
| | | int min = Collections.min(levels);
|
| | | List<Long> projectIdList = new ArrayList<>();
|
| | | // 判断角色等级
|
| | | if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) {
|
| | | // 根据用户ID查询参与的项目ID
|
| | | //List<Long> taskUserProjectIdList = taskDaliyRepository.findProjectIdByUserId(SecurityUtils.getCurrentUserId());
|
| | | //如果当前用户属于一个任务,那么他也可以看见当前这个任务的项目
|
| | | Query query = Query.query(Criteria.where("containUserList").is(SecurityUtils.getCurrentUserId()));
|
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
|
| | |
|
| | | ArrayList<Long> projectList = new ArrayList<>();
|
| | | for (TaskMongo taskMongo : taskMongoList) {
|
| | | projectList.add(taskMongo.getProjectId());
|
| | | }
|
| | | // 根据用户ID查询负责的项目ID
|
| | | projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId());
|
| | | // 检索条件
|
| | | List<Long> totalProjectIdList = Stream.of(projectList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
| | | if (totalProjectIdList.size() == 0) {
|
| | | return Collections.emptyList();
|
| | | }
|
| | | criteria.setIdInList(totalProjectIdList);
|
| | | }
|
| | | // 项目列表
|
| | | List<ProjectDto> projectDtoList = projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
| | | // 循环项目列表
|
| | | for (int i = 0; i < projectDtoList.size(); i++) {
|
| | | // 项目
|
| | | ProjectDto projectDto = projectDtoList.get(i);
|
| | |
|
| | | if (projectDto.getLiableUserId() != null && !"".equals(projectDto.getLiableUserId())) {
|
| | | // 负责人ID列表
|
| | | List<Long> liableUserIdList = new ArrayList<>();
|
| | | // 负责人ID
|
| | | String handleLiableUserId = projectDto.getLiableUserId().replace("-", "");
|
| | | // 负责人ID列表
|
| | | String[] handleLiableUserIdList = handleLiableUserId.split(",");
|
| | | // 循环负责人ID列表
|
| | | for (String liableUserId : handleLiableUserIdList) {
|
| | | // 负责人ID列表
|
| | | liableUserIdList.add(Long.valueOf(liableUserId));
|
| | | }
|
| | | // 负责人ID列表
|
| | | projectDto.setLiableUserIdList(liableUserIdList);
|
| | | }
|
| | | }
|
| | |
|
| | | if (!(min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY)){
|
| | | for (ProjectDto projectDto : projectDtoList) {
|
| | | projectDto.setFlag(true);
|
| | | }
|
| | | return projectDtoList;
|
| | | }
|
| | |
|
| | | for (ProjectDto projectDto : projectDtoList) {
|
| | | for (Long project : projectIdList) {
|
| | | //当前用户所负责的项目ID
|
| | | //如果当前用户负责的项目ID在这个集合中,就给那个项目打一个标识
|
| | | if (projectDto.getId().equals(project)) {
|
| | | projectDto.setFlag(true);
|
| | | break;
|
| | | } else {
|
| | | projectDto.setFlag(false);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return projectDtoList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public ProjectDto findById(Long id) {
|
| | | Project project = projectRepository.findById(id).orElseGet(Project::new);
|
| | | ValidationUtil.isNull(project.getId(), "Project", "id", id);
|
| | | return projectMapper.toDto(project);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public ProjectDto create(Project resources) {
|
| | | return projectMapper.toDto(projectRepository.save(resources));
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void update(Project resources) {
|
| | | Project project = projectRepository.findById(resources.getId()).orElseGet(Project::new);
|
| | | ValidationUtil.isNull(project.getId(), "Project", "id", resources.getId());
|
| | | project.copy(resources);
|
| | | projectRepository.save(project);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void deleteAll(Long[] ids) {
|
| | | for (Long id : ids) {
|
| | | // 根据项目ID查询任务日报
|
| | | List<TaskDaliy> taskDaliyList = taskDaliyRepository.findByProjectId(id);
|
| | | // 判断任务日报数量
|
| | | if (taskDaliyList.size() == 0) {
|
| | | projectRepository.deleteById(id);
|
| | | projectCostRepository.deleteByProjectId(id);
|
| | | projectProgressRepository.deleteByProjectId(id);
|
| | | projectPerformanceRepository.deleteByProjectId(id);
|
| | | projectPerformanceDetailRepository.deleteByProjectId(id);
|
| | | costRepository.deleteByProjectId(id);
|
| | | taskRepository.deleteByProjectId(id);
|
| | | taskUserRepository.deleteByProjectId(id);
|
| | | taskDaliyRepository.deleteByProjectId(id);
|
| | | contractProjectRepository.deleteByProjectId(id);
|
| | | } else {
|
| | | throw new BadRequestException("存在任务日报的项目无法删除!");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void updateProjectAdmit(Long[] ids) {
|
| | | // 获取当前用户ID
|
| | | Long userId = SecurityUtils.getCurrentUserId();
|
| | | // 查询用户角色
|
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId);
|
| | | Long min = roleSet.stream().mapToLong(RoleSmallDto::getLevel).min().getAsLong();
|
| | | for (Long id : ids) {
|
| | | // 查询项目
|
| | | Project project = projectRepository.findByIdUpdate(id);
|
| | | if (min == Constant.ROLE_LEVEL_SUPER) {
|
| | | project.setApproveStatus(Constant.APPROVE_STATUS_ACKNOWLEDGED);
|
| | | } else if (min == Constant.ROLE_LEVEL_GENERAL) {
|
| | | project.setApproveStatus(Constant.APPROVE_STATUS_MASTER_ACKNOWLEDGED);
|
| | | } else if (min == Constant.ROLE_LEVEL_MANAGER) {
|
| | | project.setApproveStatus(Constant.APPROVE_STATUS_LEADER_ACKNOWLEDGED);
|
| | | }
|
| | | // 更新项目
|
| | | update(project);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void updateProjectDisavow(Long[] ids) {
|
| | | for (Long id : ids) {
|
| | | // 查询项目
|
| | | Project project = projectRepository.findByIdUpdate(id);
|
| | | project.setApproveStatus(Constant.APPROVE_STATUS_UNRECOGNIZED);
|
| | | // 更新项目
|
| | | update(project);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void download(List<ProjectDto> all, HttpServletResponse response) throws IOException { // TODO
|
| | | List<Map<String, Object>> list = new ArrayList<>();
|
| | | for (ProjectDto project : all) {
|
| | | String projectTypeName = project.getProjectTypeId() != null ? projectTypeRepository.findById(project.getProjectTypeId()).orElseGet(ProjectType::new).getName() : "";
|
| | | String projectDistinguish = project.getProjectDistinguish() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PROJECT_DISTINGUISH, project.getProjectDistinguish()).getLabel() : "";
|
| | | String projectStatus = project.getProjectStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PROJECT_STATUS, project.getProjectStatus()).getLabel() : "";
|
| | | String approveStatus = project.getApproveStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.APPROVE_STATUS, project.getApproveStatus()).getLabel() : "";
|
| | | String unitCurrency = project.getUnitCurrency() != null ? dictDetailRepository.findByDictNameAndValue(Constant.STANDARD_UNIT_CURRENCY, project.getUnitCurrency()).getLabel() : "";
|
| | | // 负责人名称
|
| | | String liableUserName = null;
|
| | |
|
| | | if (project.getLiableUserId() != null && !"".equals(project.getLiableUserId())) {
|
| | | // 处理后负责人ID
|
| | | String handleLiableUserId = project.getLiableUserId().replace("-", "");
|
| | | // 处理后负责人ID列表
|
| | | String[] handleLiableUserIdList = handleLiableUserId.split(",");
|
| | | // 循环处理后负责人ID列表
|
| | | for (String liableUserId : handleLiableUserIdList) {
|
| | | // 根据负责人ID查询用户信息
|
| | | User user = userRepository.findById(Long.valueOf(liableUserId)).orElseGet(User::new);
|
| | | // 判断负责人名称
|
| | | liableUserName = liableUserName == null ? user.getNickName() : liableUserName + "," + user.getNickName();
|
| | | }
|
| | | }
|
| | |
|
| | | Map<String, Object> map = new LinkedHashMap<>();
|
| | | map.put("名称", project.getName());
|
| | | map.put("项目类型", projectTypeName);
|
| | | map.put("项目区分:", projectDistinguish);
|
| | | map.put("需求说明", project.getRequirement());
|
| | | map.put("单价币种", unitCurrency);
|
| | | // TODO
|
| | | // map.put("单价金额", project.getUnitPrice());
|
| | | // map.put("报价金额", project.getTotalPrice());
|
| | | map.put("责任人", liableUserName);
|
| | | map.put("计划开始日期", project.getPlanStartDate());
|
| | | map.put("计划结束日期", project.getPlanEndDate());
|
| | | map.put("项目状态", projectStatus);
|
| | | map.put("批准状态", approveStatus);
|
| | | map.put("备注", project.getRemarks());
|
| | | map.put("创建者", project.getCreateBy());
|
| | | map.put("创建时间", project.getCreateTime());
|
| | | map.put("更新者", project.getUpdateBy());
|
| | | map.put("更新时间", project.getUpdateTime());
|
| | | list.add(map);
|
| | | }
|
| | | FileUtil.downloadExcel(list, response);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ProjectDto> queryPartakeAll(ProjectQueryCriteria criteria) {
|
| | | // 根据用户ID查询项目ID
|
| | | List<Long> partakeProjectIds = taskUserRepository.findProjectIdByUserId(criteria.getTaskUserId());
|
| | | // 判断长度
|
| | | if (partakeProjectIds.size() == 0) {
|
| | | return new ArrayList<>();
|
| | | }
|
| | | // 项目检索条件
|
| | | criteria.setIdInList(partakeProjectIds);
|
| | | criteria.setProjectStatusNotEqual(Constant.PROJECT_STATUS_COMPLETED);
|
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> queryProjectCost(ProjectQueryCriteria criteria) throws ParseException {
|
| | | // 判断入参完整性
|
| | | if (criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | |
|
| | | Sort sort = Sort.by(Sort.Order.desc("createTime"));
|
| | | ProjectQueryCriteria criteria1 = new ProjectQueryCriteria();
|
| | | // criteria1.setProjectDistinguish("project_distinguish_product"); // TODO
|
| | | criteria1.setProjectStatusNotEqual(Constant.PROJECT_STATUS_COMPLETED);
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
| | | List<Project> projectList = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria1, criteriaBuilder), sort);
|
| | |
|
| | | for (Project project : projectList) {
|
| | | Query query = new Query(
|
| | | Criteria.where("projectId").is(project.getId())
|
| | | .and("planStartTime").gte(sdf.parse(criteria.getTargetYear() + "-01-01"))
|
| | | );
|
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
|
| | |
|
| | | Map<String, Object> result = new HashMap<>();
|
| | | result.put("projectName", project.getName());
|
| | |
|
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(new Query(Criteria.where("task").in(taskMongoList)), TaskUserMongo.class);
|
| | | result.put("taskHours", taskUserMongoList.stream().mapToDouble(TaskUserMongo::getTaskHours).sum());
|
| | | result.put("consumedHours", taskUserMongoList.stream().mapToDouble(TaskUserMongo::getCostHours).sum());
|
| | |
|
| | | if (!result.get("consumedHours").equals(0.0D)) {
|
| | | resultList.add(result);
|
| | | }
|
| | | }
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> querySubgroupTurnover(ProjectQueryCriteria criteria) {
|
| | | // 判断入参完整性
|
| | | if (criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) {
|
| | | return null;
|
| | | }
|
| | | // 根据字典名称查询
|
| | | List<DictDetail> dictDetailList = dictDetailRepository.findByDictName(Constant.PROJECT_DISTINGUISH);
|
| | | // 查询汇率列表
|
| | | List<SysExchangeRateDto> sysExchangeRateDtoList = sysExchangeRateService.queryAll(new SysExchangeRateQueryCriteria());
|
| | | // 根据目标年份查询分组营业额
|
| | | List<ProjectSummary> projectSummaryList = projectRepository.findSubgroupTurnoverByTargetYear(criteria.getTargetYear());
|
| | | // 根据目标年份查询分组目标金额
|
| | | SysGoalSettingQueryCriteria sysGoalSettingQueryCriteria = new SysGoalSettingQueryCriteria();
|
| | | sysGoalSettingQueryCriteria.setTargetYear(criteria.getTargetYear());
|
| | | List<SysGoalSettingDto> sysGoalSettingDtoList = sysGoalSettingService.queryAll(sysGoalSettingQueryCriteria);
|
| | | // 返回列表
|
| | | List<Map<String, Object>> returnList = new ArrayList<>();
|
| | | // 循环项目区分
|
| | | for (int i = 0; i < dictDetailList.size(); i++) {
|
| | | // 返回集合
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | // 当前项目区分
|
| | | DictDetail dictDetail = dictDetailList.get(i);
|
| | | // 返回集合
|
| | | returnMap.put("projectDistinguish", dictDetail.getLabel());
|
| | | // 营业额
|
| | | BigDecimal contractPrice = new BigDecimal(0);
|
| | | // 循环分组营业额
|
| | | for (int j = 0; j < projectSummaryList.size(); j++) {
|
| | | // 当前项目区分
|
| | | ProjectSummary projectSummary = projectSummaryList.get(j);
|
| | | // 判断与项目区分是否一致
|
| | | if (dictDetail.getValue().equals(projectSummary.getProjectDistinguish())) {
|
| | | // 当前汇率列表
|
| | | List<SysExchangeRateDto> currentSysExchangeRateDtoList = sysExchangeRateDtoList.stream().filter(item -> item.getUnitCurrency().equals(projectSummary.getUnitCurrency())).collect(Collectors.toList());
|
| | | // 判断当前汇率列表长度
|
| | | if (currentSysExchangeRateDtoList.size() == 1) {
|
| | | // 营业额
|
| | | contractPrice = contractPrice.add(projectSummary.getContractPrice().multiply(currentSysExchangeRateDtoList.get(0).getExchangeRate()));
|
| | | }
|
| | | }
|
| | | // 判断循环是否结束
|
| | | if (j == projectSummaryList.size() - 1) {
|
| | | // 返回集合
|
| | | returnMap.put("contractPrice", contractPrice);
|
| | | }
|
| | | }
|
| | | // 循环分组目标金额
|
| | | for (int j = 0; j < sysGoalSettingDtoList.size(); j++) {
|
| | | // 判断与项目区分是否一致
|
| | | if (dictDetail.getValue().equals(sysGoalSettingDtoList.get(j).getProjectDistinguish())) {
|
| | | // 返回集合
|
| | | returnMap.put("targetAmount", sysGoalSettingDtoList.get(j).getTargetAmount());
|
| | | break;
|
| | | }
|
| | | // 判断循环是否结束
|
| | | if (j == sysGoalSettingDtoList.size() - 1) {
|
| | | // 返回集合
|
| | | returnMap.put("targetAmount", new BigDecimal(0));
|
| | | }
|
| | | }
|
| | | // 返回列表
|
| | | returnList.add(returnMap);
|
| | | }
|
| | | return returnList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> querySubgroupWorkingHours(ProjectQueryCriteria criteria) {
|
| | | // 根据字典名称查询
|
| | | List<DictDetail> dictDetailList = dictDetailRepository.findByDictName(Constant.PROJECT_DISTINGUISH);
|
| | | // 查询项目列表
|
| | | List<Project> projectList = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
|
| | | List<Long> projectIdList = projectList.stream().map(Project::getId).collect(Collectors.toList());
|
| | | // 查询任务列表
|
| | | List<TaskInterface> taskInterfaceList = taskRepository.findSubgroupWorkingHoursByProjectId(projectIdList);
|
| | | // 返回列表
|
| | | List<Map<String, Object>> returnList = new ArrayList<>();
|
| | | // 循环项目区分
|
| | | for (int i = 0; i < dictDetailList.size(); i++) {
|
| | | // 已分配工时
|
| | | Double divideHours = 0D;
|
| | | // 未完成工时
|
| | | Double incompleteHours = 0D;
|
| | | // 返回集合
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | // 当前项目区分
|
| | | DictDetail dictDetail = dictDetailList.get(i);
|
| | | // 返回集合
|
| | | returnMap.put("projectDistinguish", dictDetail.getLabel());
|
| | | // 当前任务列表
|
| | | List<TaskInterface> currentTaskInterfaceList = taskInterfaceList.stream().filter(item -> item.getProjectDistinguish().equals(dictDetail.getValue())).collect(Collectors.toList());
|
| | | // 循环当前任务列表
|
| | | for (int j = 0; j < currentTaskInterfaceList.size(); j++) {
|
| | | // 当前任务
|
| | | TaskInterface currentTaskInterface = currentTaskInterfaceList.get(j);
|
| | | Task task = taskRepository.findById(currentTaskInterface.getTaskId()).orElseGet(Task::new);
|
| | | // 当前任务二次处理
|
| | | TaskDto taskDto = taskMapper.toDto(task);
|
| | | taskDto = taskService.customHandleMini(taskDto);
|
| | | // 已分配工时
|
| | | divideHours += taskDto.getDivideHours();
|
| | | // 未完成工时
|
| | | incompleteHours += (taskDto.getDivideHours() - taskDto.getCompletedHours());
|
| | | }
|
| | | // 返回集合
|
| | | returnMap.put("divideHours", DoubleUtil.maximumDigitLimit(divideHours, 2));
|
| | | returnMap.put("incompleteHours", DoubleUtil.maximumDigitLimit(incompleteHours, 2));
|
| | | // 返回列表
|
| | | returnList.add(returnMap);
|
| | | }
|
| | | return returnList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> queryProjectWorkingHours(ProjectQueryCriteria criteria) {
|
| | | // 判断入参完整性
|
| | | if (criteria.getId() == null) {
|
| | | return null;
|
| | | }
|
| | | // 根据项目ID查询项目
|
| | | ProjectDto projectDto = projectMapper.toDto(projectRepository.findById(criteria.getId()).orElseGet(Project::new));
|
| | | // 项目二次处理
|
| | | projectDto = customHandle(projectDto);
|
| | | // 返回集合
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | returnMap.put("divideHours", projectDto.getDivideTaskTime());
|
| | | returnMap.put("incompleteHours", projectDto.getIncompleteTaskTime());
|
| | | return returnMap;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> queryTypeContractPrice(ProjectQueryCriteria criteria) {
|
| | | // 判断入参完整性
|
| | | if (criteria.getProjectDistinguish() == null || "".equals(criteria.getProjectDistinguish()) || criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) {
|
| | | return null;
|
| | | }
|
| | | // 查询汇率列表
|
| | | List<SysExchangeRateDto> sysExchangeRateDtoList = sysExchangeRateService.queryAll(new SysExchangeRateQueryCriteria());
|
| | | // 根据项目区分、目标年份查询类型营业额
|
| | | List<ProjectSummary> projectSummaryList = projectRepository.findTypeContractPriceByProjectDistinguishAndTargetYear(criteria.getProjectDistinguish(), criteria.getTargetYear());
|
| | | // 项目类型列表
|
| | | List<String> projectTypeNameList = projectSummaryList.stream().map(ProjectSummary::getProjectTypeName).distinct().collect(Collectors.toList());
|
| | | // 返回列表
|
| | | List<Map<String, Object>> returnList = new ArrayList<>();
|
| | | // 循环项目类型列表
|
| | | for (int i = 0; i < projectTypeNameList.size(); i++) {
|
| | | // 项目类型
|
| | | String projectTypeName = projectTypeNameList.get(i);
|
| | | // 返回集合
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | returnMap.put("name", projectTypeName);
|
| | | // 当前项目类型营业额列表
|
| | | List<ProjectSummary> currentProjectSummaryList = projectSummaryList.stream().filter(item -> item.getProjectTypeName().equals(projectTypeName)).collect(Collectors.toList());
|
| | | // 营业额
|
| | | BigDecimal contractPrice = new BigDecimal(0);
|
| | | // 循环当前项目类型营业额列表
|
| | | for (int j = 0; j < currentProjectSummaryList.size(); j++) {
|
| | | // 当前项目类型营业额
|
| | | ProjectSummary currentProjectSummary = currentProjectSummaryList.get(j);
|
| | | // 当前汇率列表
|
| | | List<SysExchangeRateDto> currentSysExchangeRateDtoList = sysExchangeRateDtoList.stream().filter(item -> item.getUnitCurrency().equals(currentProjectSummary.getUnitCurrency())).collect(Collectors.toList());
|
| | | // 判断当前汇率列表长度
|
| | | if (currentSysExchangeRateDtoList.size() == 1) {
|
| | | // 营业额
|
| | | contractPrice = contractPrice.add(currentProjectSummary.getContractPrice().multiply(currentSysExchangeRateDtoList.get(0).getExchangeRate()));
|
| | | }
|
| | | }
|
| | | returnMap.put("value", contractPrice);
|
| | | // 返回列表
|
| | | returnList.add(returnMap);
|
| | | }
|
| | | return returnList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> queryTypeWorkingHours(ProjectQueryCriteria criteria) {
|
| | | // 判断入参完整性
|
| | | if (criteria.getProjectDistinguish() == null || "".equals(criteria.getProjectDistinguish()) || criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) {
|
| | | return null;
|
| | | }
|
| | | // 根据项目区分、目标年份查询项目
|
| | | List<Project> projectList = projectRepository.findProjectByProjectDistinguishAndTargetYear(criteria.getProjectDistinguish(), criteria.getTargetYear());
|
| | | // 查询项目类型列表
|
| | | ProjectTypeQueryCriteria projectTypeQueryCriteria = new ProjectTypeQueryCriteria();
|
| | | List<ProjectType> projectTypeList = projectTypeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, projectTypeQueryCriteria, criteriaBuilder));
|
| | | // 返回列表
|
| | | List<Map<String, Object>> returnList = new ArrayList<>();
|
| | | // 循环项目类型列表
|
| | | for (int i = 0; i < projectTypeList.size(); i++) {
|
| | | // 项目类型
|
| | | ProjectType projectType = projectTypeList.get(i);
|
| | | // 处理后项目列表
|
| | | List<Project> handleProjectList = projectList.stream().filter(item -> item.getProjectTypeId() == projectType.getId()).collect(Collectors.toList());
|
| | | // 判断处理后项目列表长度
|
| | | if (handleProjectList.size() != 0) {
|
| | | // 处理后项目ID列表
|
| | | List<Long> handleProjectIdList = handleProjectList.stream().map(Project::getId).collect(Collectors.toList());
|
| | | // 根据项目ID查询总工时
|
| | | Double sumWorkingHours = taskRepository.sumWorkingHoursByProjectId(handleProjectIdList);
|
| | | // 返回集合
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | returnMap.put("name", projectType.getName());
|
| | | returnMap.put("value", sumWorkingHours);
|
| | | // 返回列表
|
| | | returnList.add(returnMap);
|
| | | }
|
| | | }
|
| | | return returnList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ProjectDto> querySubgroupTopHours(ProjectQueryCriteria criteria) {
|
| | | // 判断入参完整性
|
| | | if (criteria.getProjectDistinguish() == null || "".equals(criteria.getProjectDistinguish())) {
|
| | | return null;
|
| | | }
|
| | | // 查询项目列表
|
| | | List<ProjectDto> projectDtoList = projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
| | | // 循环项目列表
|
| | | for (int i = 0; i < projectDtoList.size(); i++) {
|
| | | // 当前项目
|
| | | ProjectDto projectDto = projectDtoList.get(i);
|
| | | // 项目二次处理
|
| | | projectDto = customHandle(projectDto);
|
| | | }
|
| | | // 按照任务合计(未完成)进行降序排列
|
| | | projectDtoList = projectDtoList.stream().sorted(Comparator.comparing(ProjectDto::getIncompleteTaskTime).reversed()).collect(Collectors.toList());
|
| | | return projectDtoList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | //@Cacheable(cacheNames = "project",key = "{#p0}")
|
| | | public List<ProjectDto> queryRelevantOfDaily(Long userId) {
|
| | | List<TaskUserMongo> taskUserMongos = mongoTemplate.find(Query.query(new Criteria("userId").is(userId)
|
| | | .and("taskStatus").in(Constant.TASK_STATUS_NOT_STARTED, Constant.TASK_STATUS_IN_HAND, Constant.TASK_STATUS_TEST, Constant.TASK_STATUS_UNRECOGNIZED)), TaskUserMongo.class);
|
| | | List<Long> projectIds = taskUserMongos.stream().map(taskUserMongo -> taskUserMongo.getTask().getProjectId()).distinct().collect(Collectors.toList());
|
| | | List<Project> projectList = projectRepository.findByProjectStatusInAndIdIn(Arrays.asList(Constant.PROJECT_STATUS_NOT_STARTED, Constant.PROJECT_STATUS_UNDER_WAY), projectIds);
|
| | | return projectList.stream().map(project -> {
|
| | | ProjectDto projectDto = new ProjectDto();
|
| | | projectDto.setId(project.getId());
|
| | | projectDto.setName(project.getName());
|
| | | return projectDto;
|
| | | }).collect(Collectors.toList());
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void generateReport(ProjectQueryCriteria criteria) {
|
| | | List<Long> projectIds;
|
| | | if (criteria.getIdInList().size() > 0) {
|
| | | // 指定项目
|
| | | projectIds = criteria.getIdInList();
|
| | | } else {
|
| | | // 暂定科技全部未结束、未停滞项目
|
| | | criteria.setProjectDistinguish(Constant.PROJECT_DISTINGUISH_PRODUCT);
|
| | | criteria.setProjectStatusIn(Arrays.asList(Constant.PROJECT_STATUS_NOT_STARTED, Constant.PROJECT_STATUS_UNDER_WAY));
|
| | | projectIds = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)).stream().map(p -> p.getId()).collect(Collectors.toList());
|
| | | }
|
| | | weComService.toWeComSheetPushProjectReport(projectIds);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void downloadProgress(ProjectQueryCriteria criteria, HttpServletResponse response) throws IOException {
|
| | | List<Map<String, Object>> list = new ArrayList<>();
|
| | | List<User> userList = userRepository.findAll();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | List<Project> projectList = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
|
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(Query.query(Criteria.where("projectId").in(criteria.getIdInList())), TaskMongo.class);
|
| | | List<TaskUserMongo> taskUserList = mongoTemplate.find(Query.query(Criteria.where("task").in(taskMongoList)), TaskUserMongo.class);
|
| | | Integer sortId = 1;
|
| | | for (TaskUserMongo taskUserMongo : taskUserList) {
|
| | | Project project = projectList.stream().filter(p -> p.getId().equals(taskUserMongo.getTask().getProjectId())).findFirst().get();
|
| | | // 任务负责人
|
| | | List<Long> userIdList = taskUserMongo.getTask().getUserIdList();
|
| | | String taskLiableUser = userList.stream().filter(user -> userIdList.contains(user.getId())).map(user -> user.getNickName()).collect(Collectors.joining(","));
|
| | | // 作成者
|
| | | String creator = userList.stream().filter(user -> user.getId().equals(taskUserMongo.getUserId())).findFirst().get().getNickName();
|
| | | // 项目负责人
|
| | | String projectUserId = "";
|
| | | if (project.getLiableUserId() != null) {
|
| | | projectUserId = project.getLiableUserId().replace("-", "");
|
| | | }
|
| | | List<Long> idList = Arrays.asList(projectUserId.split(",")).stream().map(i -> Long.parseLong(i)).collect(Collectors.toList());
|
| | | String projectLiableUser = userList.stream().filter(user -> idList.contains(user.getId())).map(user -> user.getNickName()).collect(Collectors.joining(","));
|
| | |
|
| | | Map<String, Object> map = new LinkedHashMap<>();
|
| | | map.put("序号", sortId++);
|
| | | map.put("任务详情-项目", project.getName());
|
| | | map.put("项目负责人", projectLiableUser);
|
| | | map.put("任务分类", String.join(",", taskUserMongo.getTask().getTagList()));
|
| | | map.put("任务详情-名称", taskUserMongo.getTask().getName());
|
| | | map.put("项目单位", "/");
|
| | | map.put("任务负责人", taskLiableUser);
|
| | | map.put("任务详情-描述", taskUserMongo.getTask().getDescription());
|
| | | map.put("任务分配-名称", taskUserMongo.getName());
|
| | | map.put("作成者", creator);
|
| | | if (taskUserMongo.getTask().getPlanStartTime() != null) {
|
| | | map.put("计划开始时间", sdf.format(taskUserMongo.getTask().getPlanStartTime()));
|
| | | } else {
|
| | | map.put("计划开始时间", "");
|
| | | }
|
| | | if (taskUserMongo.getTask().getPlanEndTime() != null) {
|
| | | map.put("计划完成时间", sdf.format(taskUserMongo.getTask().getPlanEndTime()));
|
| | | } else {
|
| | | map.put("计划完成时间", "");
|
| | | }
|
| | | map.put("预计工时", taskUserMongo.getTask().getPlanHours());
|
| | | map.put("实际开始时间", sdf.format(taskUserMongo.getTaskStartDate()));
|
| | | map.put("实际完成时间", sdf.format(taskUserMongo.getTaskEndDate()));
|
| | | map.put("实际工时", taskUserMongo.getTaskHours());
|
| | | map.put("进度", taskUserMongo.getNewTaskProgress());
|
| | | map.put("预警", "");
|
| | | map.put("备注", taskUserMongo.getRemarks());
|
| | | list.add(map);
|
| | | }
|
| | | FileUtil.downloadExcel(list, response);
|
| | | }
|
| | | } |