| | |
| | | /* |
| | | * 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. |
| | | */ |
| | | * 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.task.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.text.DateFormat; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.DayOfWeek; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | 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.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.RoleSmallDto; |
| | | import me.zhengjie.modules.task.domain.Task; |
| | | import me.zhengjie.modules.task.domain.TaskDailyInterface; |
| | | import me.zhengjie.modules.task.domain.TaskDaliy; |
| | | import me.zhengjie.modules.task.domain.TaskUser; |
| | | import me.zhengjie.modules.task.repository.TaskDaliyRepository; |
| | | import me.zhengjie.modules.task.domain.*; |
| | | import me.zhengjie.modules.task.repository.TaskRepository; |
| | | import me.zhengjie.utils.*; |
| | | import me.zhengjie.modules.treatment.repository.UserLevelWageRepository; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | | import org.bson.types.ObjectId; |
| | | import org.springframework.cache.annotation.CacheConfig; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | | 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 lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.system.domain.SysConfigHoliday; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.UserService; |
| | | import me.zhengjie.modules.system.service.dto.UserDto; |
| | | import me.zhengjie.modules.task.repository.TaskUserRepository; |
| | | import me.zhengjie.modules.task.service.TaskUserService; |
| | | import me.zhengjie.modules.task.service.dto.TaskUserDto; |
| | | import me.zhengjie.modules.task.service.dto.TaskUserMongoDto; |
| | | import me.zhengjie.modules.task.service.dto.TaskUserQueryCriteria; |
| | | import me.zhengjie.modules.task.service.dto.TaskUserTotalDetailMongoDto; |
| | | import me.zhengjie.modules.task.service.dto.TaskUserTotalMongoDto; |
| | | import me.zhengjie.modules.task.service.mapstruct.TaskUserMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @author 赵士淞 |
| | | * @date 2022-12-28 |
| | | **/ |
| | | * @author 赵士淞 |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @date 2022-12-28 |
| | | **/ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | @CacheConfig(cacheNames = "taskUser") |
| | | public class TaskUserServiceImpl implements TaskUserService { |
| | | |
| | | private final TaskUserRepository taskUserRepository; |
| | | private final TaskUserMapper taskUserMapper; |
| | | private final ProjectRepository projectRepository; |
| | | private final TaskRepository taskRepository; |
| | | private final UserRepository userRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final RoleService roleService; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final TaskRepository taskRepository; |
| | | private final UserService userService; |
| | | private final MongoTemplate mongoTemplate; |
| | | private final UserLevelWageRepository userLevelWageRepository; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(TaskUserQueryCriteria criteria, Pageable pageable){ |
| | | // 获取登录用户角色等级 |
| | | 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 = taskDaliyRepository.findProjectIdByUserId(SecurityUtils.getCurrentUserId()); |
| | | // 根据用户ID查询负责的项目ID |
| | | List<Long> projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId()); |
| | | // 检索条件 |
| | | criteria.setProjectIdInList(Stream.of(taskUserProjectIdList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList())); |
| | | } |
| | | Page<TaskUser> page = taskUserRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | // 将实体类转换为DTO(重写) |
| | | Function<TaskUser, TaskUserDto> func = new Function<TaskUser, TaskUserDto>(){ |
| | | @Override |
| | | public TaskUserDto apply(TaskUser t) { |
| | | // 将实体类转换成DTO |
| | | TaskUserDto taskUserDto = taskUserMapper.toDto(t); |
| | | // 根据项目ID查询项目信息 |
| | | Project project = projectRepository.findById(taskUserDto.getProjectId()).orElseGet(Project::new); |
| | | ValidationUtil.isNull(project.getId(),"Project","id",taskUserDto.getProjectId()); |
| | | // 项目名称 |
| | | taskUserDto.setProjectName(project.getName()); |
| | | // 根据任务ID查询任务信息 |
| | | Task task = taskRepository.findById(taskUserDto.getTaskId()).orElseGet(Task::new); |
| | | ValidationUtil.isNull(task.getId(),"Task","id",taskUserDto.getTaskId()); |
| | | // 任务名称 |
| | | taskUserDto.setTaskName(task.getName()); |
| | | // 任务工作量单位 |
| | | taskUserDto.setTaskWorkloadUnit(task.getPlanWorkloadUnit()); |
| | | // 根据用户ID查询用户信息 |
| | | User user = userRepository.findById(taskUserDto.getUserId()).orElseGet(User::new); |
| | | ValidationUtil.isNull(user.getId(),"User","id",taskUserDto.getUserId()); |
| | | // 用户昵称 |
| | | taskUserDto.setUserNickName(user.getNickName()); |
| | | // 根据项目ID、任务ID、用户ID查询总消耗工时、总消耗工作量、最大任务进度 |
| | | TaskDailyInterface taskDailyInterface = taskDaliyRepository.findSumConsumedHoursAndSumConsumedWorkloadAndMaxTaskProgressByProjectIdAndTaskIdAndUserId(taskUserDto.getProjectId(), taskUserDto.getTaskId(), taskUserDto.getUserId()); |
| | | // 消耗工时 |
| | | taskUserDto.setConsumedHours(taskDailyInterface.getConsumedHours()); |
| | | // 消耗工作量 |
| | | taskUserDto.setConsumedWorkload(taskDailyInterface.getConsumedWorkload()); |
| | | // 任务进度 |
| | | taskUserDto.setTaskProgress(taskDailyInterface.getTaskProgress()); |
| | | // 返回处理好的DTO |
| | | return taskUserDto; |
| | | public TaskUserTotalMongoDto sumTotalByTask(String taskId) { |
| | | TaskUserTotalMongoDto result = new TaskUserTotalMongoDto(); |
| | | |
| | | TaskMongo taskMongo = mongoTemplate.findById(taskId, TaskMongo.class); |
| | | result.setPerformanceType(taskMongo.getPerformanceType()); |
| | | |
| | | Criteria criteria = Criteria.where("task").is(taskMongo); |
| | | |
| | | Aggregation customerAgg = Aggregation.newAggregation( |
| | | Aggregation.match(criteria), |
| | | Aggregation.project("taskStatus", "taskHours"), |
| | | Aggregation.group("taskStatus").count().as("taskStatusCnt").sum("taskHours").as("taskHours") |
| | | ); |
| | | |
| | | AggregationResults<TaskUserTotalDetailMongoDto> taskUserMongoList = mongoTemplate.aggregate(customerAgg, TaskUserMongo.class, TaskUserTotalDetailMongoDto.class); |
| | | result.setDetails(taskUserMongoList.getMappedResults()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskUserMongoDto> getAdventTasks() { |
| | | List<TaskUserMongo> taskUserMongos = mongoTemplate.find(new Query(new Criteria("userId").is(SecurityUtils.getCurrentUserId())), TaskUserMongo.class); |
| | | List<TaskUserMongoDto> taskUserMongoDtoList = new ArrayList<>(); |
| | | taskUserMongos.sort(((o1, o2) -> { |
| | | if(o1.getTaskEndDate() != null && o2.getTaskEndDate() != null){ |
| | | return o2.getTaskEndDate().compareTo(o1.getTaskEndDate()); |
| | | } |
| | | }; |
| | | return PageUtil.toPage(page.map(func)); |
| | | return 0; |
| | | } |
| | | )); |
| | | taskUserMongos.forEach(item -> { |
| | | if (item.getTaskEndDate() != null && item.getTaskStartDate() != null) { |
| | | //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 |
| | | Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); |
| | | TaskUserMongoDto dto = new TaskUserMongoDto(); |
| | | if (item.getPerformanceType() == null) { |
| | | TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); |
| | | item.setPerformanceType(byId.getPerformanceType()); |
| | | mongoTemplate.save(item); |
| | | getAdventTasks(); |
| | | } |
| | | if (item.getPerformanceType().equals("1")) { |
| | | //绩效任务 |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(item.getTaskHours() / coefficientByUserId); |
| | | item.setPerformanceHours(Double.valueOf(format)); |
| | | } else { |
| | | item.setPerformanceHours(item.getTaskHours()); |
| | | } |
| | | |
| | | dto.setId(item.getId()); |
| | | dto.setName(item.getName()); |
| | | dto.setProjectId(item.getTask().getProjectId()); |
| | | dto.setRemarks(item.getRemarks()); |
| | | dto.setTaskHours(item.getTaskHours()); |
| | | dto.setTaskStatus(item.getTaskStatus()); |
| | | dto.setTaskId(item.getTask().getId()); |
| | | dto.setUserId(SecurityUtils.getCurrentUserId()); |
| | | dto.setPerformanceHours(item.getPerformanceHours()); |
| | | dto.setTaskStartDate(item.getTaskStartDate()); |
| | | dto.setTaskEndDate(item.getTaskEndDate()); |
| | | //List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo.id").is(item.getId())), TaskDaliyMongo.class); |
| | | |
| | | |
| | | AtomicReference<Double> consumptionHours = new AtomicReference<>(0D); |
| | | |
| | | //获取已消耗的工时 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("taskUserMongo.id").is(item.getId())), TaskDaliyMongo.class); |
| | | daliyMongoList.forEach(daliy -> consumptionHours.updateAndGet(v -> v + daliy.getConsumedHours())); |
| | | if (daliyMongoList.size() == 0) { |
| | | dto.setMaxTaskProgress(0D); |
| | | if (dto.getTaskEndDate().after(Date.from(Instant.now()))) { |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } |
| | | } else { |
| | | daliyMongoList.sort(((o1, o2) -> (int) (o2.getTaskProgress() - o1.getTaskProgress()))); |
| | | if (daliyMongoList.get(0).getTaskProgress() != 100 && dto.getTaskEndDate().after(Date.from(Instant.now()))) { |
| | | dto.setMaxTaskProgress(daliyMongoList.get(0).getTaskProgress()); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | taskUserMongoDtoList.sort((Comparator.comparing(TaskUserMongoDto::getTaskEndDate))); |
| | | return taskUserMongoDtoList; |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskUserDto> queryAll(TaskUserQueryCriteria criteria){ |
| | | return taskUserMapper.toDto(taskUserRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | public List<TaskUserMongoDto> getOngoingTasks() { |
| | | Criteria criteriaMongo = new Criteria(); |
| | | criteriaMongo.and("taskStatus").is("task_status_in_hand"); |
| | | criteriaMongo.and("userId").is(SecurityUtils.getCurrentUserId()); |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(criteriaMongo), TaskUserMongo.class); |
| | | List<TaskUserMongoDto> taskUserMongoDtoList = new ArrayList<>(); |
| | | taskUserMongoList.forEach(item -> { |
| | | //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 |
| | | Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); |
| | | TaskUserMongoDto dto = new TaskUserMongoDto(); |
| | | if (item.getPerformanceType() == null) { |
| | | TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); |
| | | item.setPerformanceType(byId.getPerformanceType()); |
| | | mongoTemplate.save(item); |
| | | getOngoingTasks(); |
| | | } |
| | | if (item.getPerformanceType().equals("1")) { |
| | | //绩效任务 |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(item.getTaskHours() / coefficientByUserId); |
| | | item.setPerformanceHours(Double.valueOf(format)); |
| | | } else { |
| | | item.setPerformanceHours(item.getTaskHours()); |
| | | } |
| | | |
| | | dto.setId(item.getId()); |
| | | dto.setName(item.getName()); |
| | | dto.setProjectId(item.getTask().getProjectId()); |
| | | dto.setRemarks(item.getRemarks()); |
| | | dto.setTaskHours(item.getTaskHours()); |
| | | dto.setTaskStatus(item.getTaskStatus()); |
| | | dto.setTaskId(item.getTask().getId()); |
| | | dto.setUserId(SecurityUtils.getCurrentUserId()); |
| | | dto.setPerformanceHours(item.getPerformanceHours()); |
| | | dto.setTaskStartDate(item.getTaskStartDate()); |
| | | dto.setTaskEndDate(item.getTaskEndDate()); |
| | | //List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo.id").is(item.getId())), TaskDaliyMongo.class); |
| | | |
| | | |
| | | AtomicReference<Double> consumptionHours = new AtomicReference<>(0D); |
| | | |
| | | //获取已消耗的工时 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("taskUserMongo.id").is(item.getId())), TaskDaliyMongo.class); |
| | | daliyMongoList.forEach(daliy -> consumptionHours.updateAndGet(v -> v + daliy.getConsumedHours())); |
| | | if (daliyMongoList.size() == 0) { |
| | | dto.setMaxTaskProgress(0D); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } else { |
| | | daliyMongoList.sort(((o1, o2) -> (int) (o2.getTaskProgress() - o1.getTaskProgress()))); |
| | | dto.setMaxTaskProgress(daliyMongoList.get(0).getTaskProgress()); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } |
| | | }); |
| | | return taskUserMongoDtoList; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public TaskUserDto findById(Long id) { |
| | | TaskUser taskUser = taskUserRepository.findById(id).orElseGet(TaskUser::new); |
| | | ValidationUtil.isNull(taskUser.getId(),"TaskUser","id",id); |
| | | return taskUserMapper.toDto(taskUser); |
| | | public List<TaskUserMongoDto> getTaskNotStarted() { |
| | | Criteria criteriaMongo = new Criteria(); |
| | | criteriaMongo.and("taskStatus").is("task_status_not_started"); |
| | | criteriaMongo.and("userId").is(SecurityUtils.getCurrentUserId()); |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(criteriaMongo), TaskUserMongo.class); |
| | | List<TaskUserMongoDto> taskUserMongoDtoList = new ArrayList<>(); |
| | | |
| | | taskUserMongoList.forEach(item -> { |
| | | //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 |
| | | Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); |
| | | TaskUserMongoDto dto = new TaskUserMongoDto(); |
| | | if (item.getPerformanceType() == null) { |
| | | TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); |
| | | item.setPerformanceType(byId.getPerformanceType()); |
| | | mongoTemplate.save(item); |
| | | getTaskNotStarted(); |
| | | } |
| | | if (item.getPerformanceType().equals("1")) { |
| | | //绩效任务 |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(item.getTaskHours() / coefficientByUserId); |
| | | item.setPerformanceHours(Double.valueOf(format)); |
| | | } else { |
| | | item.setPerformanceHours(item.getTaskHours()); |
| | | } |
| | | |
| | | dto.setId(item.getId()); |
| | | dto.setName(item.getName()); |
| | | dto.setProjectId(item.getTask().getProjectId()); |
| | | dto.setRemarks(item.getRemarks()); |
| | | dto.setTaskHours(item.getTaskHours()); |
| | | dto.setTaskStatus(item.getTaskStatus()); |
| | | dto.setTaskId(item.getTask().getId()); |
| | | dto.setUserId(SecurityUtils.getCurrentUserId()); |
| | | dto.setPerformanceHours(item.getPerformanceHours()); |
| | | dto.setTaskStartDate(item.getTaskStartDate()); |
| | | dto.setTaskEndDate(item.getTaskEndDate()); |
| | | //List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo.id").is(item.getId())), TaskDaliyMongo.class); |
| | | |
| | | |
| | | AtomicReference<Double> consumptionHours = new AtomicReference<>(0D); |
| | | |
| | | //获取已消耗的工时 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("taskUserMongo.id").is(item.getId())), TaskDaliyMongo.class); |
| | | daliyMongoList.forEach(daliy -> consumptionHours.updateAndGet(v -> v + daliy.getConsumedHours())); |
| | | if (daliyMongoList.size() == 0) { |
| | | dto.setMaxTaskProgress(0D); |
| | | if (dto.getTaskEndDate().after(Date.from(Instant.now()))) { |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } |
| | | } else { |
| | | daliyMongoList.sort(((o1, o2) -> (int) (o2.getTaskProgress() - o1.getTaskProgress()))); |
| | | if (dto.getTaskEndDate().after(Date.from(Instant.now()))) { |
| | | dto.setMaxTaskProgress(daliyMongoList.get(0).getTaskProgress()); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } |
| | | } |
| | | }); |
| | | return taskUserMongoDtoList; |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskUserMongoDto> getAllTaskUser(Long userId,String taskUserMongoId) { |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId())), TaskUserMongo.class); |
| | | List<TaskUserMongoDto> taskUserMongoDtoList = new ArrayList<>(); |
| | | |
| | | taskUserMongoList.forEach(item -> { |
| | | //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 |
| | | Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); |
| | | TaskUserMongoDto dto = new TaskUserMongoDto(); |
| | | if (item.getPerformanceType() == null) { |
| | | TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); |
| | | item.setPerformanceType(byId.getPerformanceType()); |
| | | mongoTemplate.save(item); |
| | | getAllTaskUser(SecurityUtils.getCurrentUserId(),taskUserMongoId); |
| | | } |
| | | if (item.getPerformanceType().equals("1")) { |
| | | //绩效任务 |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(item.getTaskHours() / coefficientByUserId); |
| | | item.setPerformanceHours(Double.valueOf(format)); |
| | | } else { |
| | | item.setPerformanceHours(item.getTaskHours()); |
| | | } |
| | | |
| | | dto.setId(item.getId()); |
| | | dto.setName(item.getName()); |
| | | dto.setProjectId(item.getTask().getProjectId()); |
| | | dto.setRemarks(item.getRemarks()); |
| | | dto.setTaskHours(item.getTaskHours()); |
| | | dto.setTaskStatus(item.getTaskStatus()); |
| | | dto.setTaskId(item.getTask().getId()); |
| | | dto.setUserId(SecurityUtils.getCurrentUserId()); |
| | | dto.setPerformanceHours(item.getPerformanceHours()); |
| | | dto.setTaskStartDate(item.getTaskStartDate()); |
| | | dto.setTaskEndDate(item.getTaskEndDate()); |
| | | //List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo.id").is(item.getId())), TaskDaliyMongo.class); |
| | | |
| | | |
| | | AtomicReference<Double> consumptionHours = new AtomicReference<>(0D); |
| | | //获取已消耗的工时 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("taskUserMongo.id").is(item.getId()).and("userId").is(SecurityUtils.getCurrentUserId())), TaskDaliyMongo.class); |
| | | daliyMongoList.forEach(daliy -> consumptionHours.updateAndGet(v -> v + daliy.getConsumedHours())); |
| | | if (daliyMongoList.size() == 0) { |
| | | //如果没有日志,统一赋值为0 |
| | | //List<TaskDaliyMongo> alreadyDaily = mongoTemplate.find(Query.query(new Criteria("taskUserMongo._id").is(taskUserMongoId)), TaskDaliyMongo.class); |
| | | // System.out.println(alreadyDaily.get(alreadyDaily.size() - 1)); |
| | | dto.setMaxTaskProgress(0D); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } else { |
| | | //如果有日志 |
| | | //看看其他人写没写过日报 |
| | | List<TaskDaliyMongo> alreadyDaily = mongoTemplate.find(Query.query(new Criteria("taskUserMongo._id").is(taskUserMongoId).and("userId").ne(SecurityUtils.getCurrentUserId())), TaskDaliyMongo.class); |
| | | //将其他人填写的工时合并过来 |
| | | alreadyDaily.forEach(daily -> consumptionHours.updateAndGet(v -> v + daily.getConsumedHours())); |
| | | daliyMongoList.sort(((o1, o2) -> (int) (o2.getTaskProgress() - o1.getTaskProgress()))); |
| | | dto.setMaxTaskProgress(daliyMongoList.get(0).getTaskProgress()); |
| | | dto.setAlreadyConsumedHours(consumptionHours.get()); |
| | | taskUserMongoDtoList.add(dto); |
| | | } |
| | | |
| | | }); |
| | | return taskUserMongoDtoList; |
| | | } |
| | | |
| | | @Override |
| | | public void changeStatus(String[] ids) { |
| | | Arrays.stream(ids).forEach(item -> { |
| | | TaskUserMongo mongoTemplateById = mongoTemplate.findById(item, TaskUserMongo.class); |
| | | mongoTemplateById.setTaskStatus("task_status_completed"); |
| | | mongoTemplate.save(mongoTemplateById); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskUserDetail> getTaskUserDetail(String taskUserMongoId) { |
| | | List<TaskUserDetail> returnList = new ArrayList<>(); |
| | | List<String> colorList = new ArrayList<>(); |
| | | Collections.addAll(colorList,"#0bbd87","#67C23A","#909399","#E6A23C","#F56C6C"); |
| | | Criteria criteria = new Criteria(); |
| | | criteria.and("taskUserMongo._id").is(taskUserMongoId); |
| | | Query query = new Query(criteria); |
| | | // 获取到这个分配任务下所有的日报信息 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(query, TaskDaliyMongo.class); |
| | | // 按照人名进行分组 |
| | | Map<Long, List<TaskDaliyMongo>> collect = daliyMongoList.stream().collect(Collectors.groupingBy(TaskDaliyMongo::getUserId)); |
| | | Set<Map.Entry<Long, List<TaskDaliyMongo>>> entries = collect.entrySet(); |
| | | // 分别染色 |
| | | for (Map.Entry<Long, List<TaskDaliyMongo>> entry : entries) { |
| | | String color = colorList.get(new Random().nextInt(colorList.size())); |
| | | colorList.remove(color); |
| | | for (TaskDaliyMongo taskDaliyMongo : entry.getValue()) { |
| | | TaskUserDetail taskUserDetail = new TaskUserDetail(); |
| | | taskUserDetail.setTaskUserName(userRepository.findById(taskDaliyMongo.getUserId()).get().getNickName()); |
| | | taskUserDetail.setTitle(userRepository.findById(taskDaliyMongo.getUserId()).get().getNickName()+"提交了任务日报,消耗了"+taskDaliyMongo.getConsumedHours()+"个小时"); |
| | | taskUserDetail.setFillDate(new SimpleDateFormat("yyyy-MM-dd").format(taskDaliyMongo.getFillDate())); |
| | | taskUserDetail.setColor(color); |
| | | taskUserDetail.setAlreadyConsumeHours(entry.getValue().stream().collect(Collectors.summingDouble(TaskDaliyMongo::getConsumedHours))); |
| | | returnList.add(taskUserDetail); |
| | | } |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | @Override |
| | | @CacheEvict(cacheNames = "task", key = "'projectId:' + #p0") |
| | | public void addTaskUser(Long projectId, String taskId) { |
| | | //如果有用户认领了这个任务 |
| | | |
| | | //看看他在不在这个任务中 |
| | | TaskUserMongo byId = mongoTemplate.findById(taskId, TaskUserMongo.class); |
| | | |
| | | TaskMongo taskMongo = mongoTemplate.findById(byId.getTask().getId(), TaskMongo.class); |
| | | List<Long> containUserList = taskMongo.getContainUserList(); |
| | | if (!containUserList.contains(SecurityUtils.getCurrentUserId())) { |
| | | //如果获取的这个人不在这个任务中 |
| | | throw new BadRequestException("您不在当前的任务中,无法领取该任务"); |
| | | } |
| | | |
| | | if (byId != null) { |
| | | byId.setUserId(SecurityUtils.getCurrentUserId()); |
| | | mongoTemplate.save(byId); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> queryAll(TaskUserQueryCriteria criteria, Pageable pageable) { |
| | | |
| | | Criteria criteriaMongo = new Criteria(); |
| | | if (criteria.getTaskId() != null) { |
| | | TaskMongo taskMongo = mongoTemplate.findById(criteria.getTaskId(), TaskMongo.class); |
| | | criteriaMongo.and("task").is(taskMongo); |
| | | } else { |
| | | return PageUtil.toPage(Collections.emptyList(), 0); |
| | | } |
| | | if(criteria.getUserId() != null){ |
| | | criteriaMongo = criteriaMongo.and("userId").is(criteria.getUserId()); |
| | | } |
| | | if (criteria.getTaskStatus() != null && criteria.getTaskStatus().size() > 0) { |
| | | if (criteria.getTaskStatus().contains("task_status_unrecognized")){ |
| | | criteria.getTaskStatus().remove("task_status_unrecognized"); |
| | | // 如果要查询未承认的任务 |
| | | criteriaMongo.and("taskHours").is(0); |
| | | } |
| | | } |
| | | if (criteria.getTaskStatus() != null && criteria.getTaskStatus().size() > 0) { |
| | | criteriaMongo = criteriaMongo.and("taskStatus").in(criteria.getTaskStatus()); |
| | | } |
| | | Query query = new Query(criteriaMongo); |
| | | Long totalCount = mongoTemplate.count(query, TaskUserMongo.class); |
| | | if (totalCount == 0) { |
| | | return PageUtil.toPage(Collections.emptyList(), 0); |
| | | } |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(query.with(pageable), TaskUserMongo.class); |
| | | |
| | | List<TaskUserMongoDto> taskUserMongoDtoList = new ArrayList<TaskUserMongoDto>(); |
| | | for (TaskUserMongo taskUserMongo : taskUserMongoList) { |
| | | TaskUserMongoDto taskUserMongoDto = new TaskUserMongoDto(); |
| | | taskUserMongoDto.setId(taskUserMongo.getId()); |
| | | taskUserMongoDto.setName(taskUserMongo.getName()); |
| | | taskUserMongoDto.setOld_id(taskUserMongo.getTask().getOld_id()); |
| | | if (taskUserMongo.getTaskStatus().equals("task_status_completed")) { |
| | | taskUserMongoDto.setIs_ok(true); |
| | | } |
| | | if (taskUserMongo.getUserId() != null) { |
| | | taskUserMongoDto.setUserId(taskUserMongo.getUserId()); |
| | | UserDto userDto = userService.findById(taskUserMongo.getUserId()); |
| | | taskUserMongoDto.setUserNickName(userDto.getNickName()); |
| | | } |
| | | |
| | | taskUserMongoDto.setTaskId(taskUserMongo.getTask().getId()); |
| | | taskUserMongoDto.setPerformanceType(taskUserMongo.getPerformanceType()); |
| | | taskUserMongoDto.setPriority(taskUserMongo.getPriority()); |
| | | taskUserMongoDto.setTaskStatus(taskUserMongo.getTaskStatus()); |
| | | |
| | | taskUserMongoDto.setTaskStartDate(taskUserMongo.getTaskStartDate()); |
| | | taskUserMongoDto.setTaskEndDate(taskUserMongo.getTaskEndDate()); |
| | | taskUserMongoDto.setTaskHours(taskUserMongo.getTaskHours()); |
| | | |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("taskUserMongo.id").is(taskUserMongo.getId())), TaskDaliyMongo.class); |
| | | |
| | | daliyMongoList.sort(((o1, o2) -> o2.getFillDate().compareTo(o1.getFillDate()))); |
| | | |
| | | if (daliyMongoList.size() == 0) { |
| | | //没有日报 |
| | | taskUserMongoDto.setNewTaskProgress(0D); |
| | | } else { |
| | | //有日报 |
| | | taskUserMongoDto.setNewTaskProgress(daliyMongoList.get(0).getTaskProgress()); |
| | | } |
| | | |
| | | Double coefficientByUserId; |
| | | //这个人的绩效绩点 |
| | | if (taskUserMongo.getUserId() == null) { |
| | | //如果当前的任务没有指定任务负责人就设置整体的绩效绩点为1 |
| | | coefficientByUserId = 1D; |
| | | } else { |
| | | //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 |
| | | coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(taskUserMongo.getUserId()); |
| | | } |
| | | |
| | | if (taskUserMongo.getPerformanceType() == null) { |
| | | TaskMongo byId = mongoTemplate.findById(taskUserMongo.getTask().getId(), TaskMongo.class); |
| | | taskUserMongo.setPerformanceType(byId.getPerformanceType()); |
| | | mongoTemplate.save(taskUserMongo); |
| | | queryAll(criteria, pageable); |
| | | } |
| | | if (taskUserMongoDto.getPerformanceType().equals("1")) { |
| | | //绩效任务 |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(taskUserMongo.getTaskHours() / coefficientByUserId); |
| | | taskUserMongoDto.setPerformanceHours(Double.valueOf(format)); |
| | | } else { |
| | | taskUserMongoDto.setPerformanceHours(taskUserMongo.getTaskHours()); |
| | | } |
| | | |
| | | taskUserMongoDtoList.add(taskUserMongoDto); |
| | | } |
| | | return PageUtil.toPage(taskUserMongoDtoList, totalCount); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskUserMongoDto> queryAll(String taskId) { // TODO |
| | | //return taskUserMapper.toDto(taskUserRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | Criteria criteriaMongo = new Criteria(); |
| | | //是这个任务中的任务分配 |
| | | criteriaMongo.and("task").is(taskId); |
| | | criteriaMongo.and("userId").is(SecurityUtils.getCurrentUserId()); |
| | | Query query = new Query(criteriaMongo); |
| | | List<TaskUserMongo> taskUserMongos = mongoTemplate.find(query, TaskUserMongo.class); |
| | | List<TaskUserMongoDto> resultList = new ArrayList<>(); |
| | | Double coefficientByUserId; |
| | | |
| | | for (TaskUserMongo taskUserMongo : taskUserMongos) { |
| | | TaskUserMongoDto taskUserMongoDto = new TaskUserMongoDto(); |
| | | |
| | | Criteria criteriaTaskDaliy = new Criteria(); |
| | | criteriaTaskDaliy.and("taskUserMongo.id").is(taskUserMongo.getId()); |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(criteriaTaskDaliy), TaskDaliyMongo.class); |
| | | Double alreadyConsumedHours = 0D; |
| | | for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | alreadyConsumedHours += taskDaliyMongo.getConsumedHours(); |
| | | } |
| | | |
| | | taskUserMongoDto.setAlreadyConsumedHours(alreadyConsumedHours); |
| | | taskUserMongoDto.setId(taskUserMongo.getId()); |
| | | taskUserMongoDto.setName(taskUserMongo.getName()); |
| | | taskUserMongoDto.setOld_id(taskUserMongo.getTask().getOld_id()); |
| | | |
| | | if (taskUserMongo.getUserId() != null) { |
| | | taskUserMongoDto.setUserId(taskUserMongo.getUserId()); |
| | | UserDto userDto = userService.findById(taskUserMongo.getUserId()); |
| | | taskUserMongoDto.setUserNickName(userDto.getNickName()); |
| | | } |
| | | |
| | | taskUserMongoDto.setTaskId(taskUserMongo.getTask().getId()); |
| | | taskUserMongoDto.setPerformanceType(taskUserMongo.getPerformanceType()); |
| | | taskUserMongoDto.setPriority(taskUserMongo.getPriority()); |
| | | taskUserMongoDto.setTaskStatus(taskUserMongo.getTaskStatus()); |
| | | |
| | | taskUserMongoDto.setTaskStartDate(taskUserMongo.getTaskStartDate()); |
| | | taskUserMongoDto.setTaskEndDate(taskUserMongo.getTaskEndDate()); |
| | | taskUserMongoDto.setTaskHours(taskUserMongo.getTaskHours()); |
| | | //这个人的绩效绩点 |
| | | if (taskUserMongo.getUserId() == null) { |
| | | //如果当前的任务没有指定任务负责人就设置整体的绩效绩点为1 |
| | | coefficientByUserId = 1D; |
| | | } else { |
| | | //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 |
| | | coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(taskUserMongo.getUserId()); |
| | | } |
| | | |
| | | if (taskUserMongo.getPerformanceType() == null) { |
| | | TaskMongo byId = mongoTemplate.findById(taskUserMongo.getTask().getId(), TaskMongo.class); |
| | | taskUserMongoDto.setPerformanceType(byId.getPerformanceType()); |
| | | mongoTemplate.save(taskUserMongo); |
| | | queryAll(taskId); |
| | | } |
| | | if (taskUserMongo.getPerformanceType().equals("1")) { |
| | | //绩效任务 |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(taskUserMongo.getTaskHours() / coefficientByUserId); |
| | | taskUserMongoDto.setPerformanceHours(Double.valueOf(format)); |
| | | resultList.add(taskUserMongoDto); |
| | | } else { |
| | | taskUserMongoDto.setPerformanceHours(taskUserMongo.getTaskHours()); |
| | | resultList.add(taskUserMongoDto); |
| | | } |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | @Override |
| | | public Double calculateHour(TaskUserQueryCriteria criteria) { |
| | | ZoneId zoneId = ZoneId.systemDefault(); |
| | | LocalDateTime localEndDateTime = criteria.getTaskEndDate().toInstant().atZone(zoneId).toLocalDateTime(); |
| | | User user = userRepository.findById(criteria.getUserId()).orElseGet(User::new); |
| | | ValidationUtil.isNull(user.getId(), "User", "id", criteria.getUserId()); |
| | | |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findByHolidayDateBetween(criteria.getTaskStartDate(), criteria.getTaskEndDate()); |
| | | |
| | | Double totalHours = 0.0; |
| | | LocalDateTime toDayDateTime = criteria.getTaskStartDate().toInstant().atZone(zoneId).toLocalDateTime(); |
| | | while (toDayDateTime.isBefore(localEndDateTime)) { |
| | | |
| | | String dateType = ""; |
| | | for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayList) { |
| | | if (toDayDateTime.toLocalDate().isEqual(sysConfigHoliday.getHolidayDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate())) { |
| | | dateType = sysConfigHoliday.getDateType(); |
| | | break; |
| | | } |
| | | } |
| | | if ("".equals(dateType)) { |
| | | dateType = toDayDateTime.toLocalDate().getDayOfWeek() == DayOfWeek.SATURDAY || toDayDateTime.toLocalDate().getDayOfWeek() == DayOfWeek.SUNDAY ? Constant.DATE_TYPE_WEEKEND : Constant.DATE_TYPE_WEEKDAY; |
| | | } |
| | | if (Constant.DATE_TYPE_WEEKEND.equals(dateType) || Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(dateType)) { |
| | | toDayDateTime = toDayDateTime.plusDays(1).with(user.getSysRostering().getWorkStartTime()); |
| | | continue; |
| | | } |
| | | |
| | | if (toDayDateTime.toLocalTime().isBefore(user.getSysRostering().getWorkStartTime())) { |
| | | toDayDateTime = toDayDateTime.with(user.getSysRostering().getWorkStartTime()); |
| | | } |
| | | if (toDayDateTime.toLocalTime().isBefore(user.getSysRostering().getLunchStartTime())) { |
| | | if (toDayDateTime.toLocalDate().isEqual(localEndDateTime.toLocalDate())) { |
| | | if (toDayDateTime.toLocalTime().isBefore(localEndDateTime.toLocalTime())) { |
| | | if (localEndDateTime.toLocalTime().isBefore(user.getSysRostering().getLunchStartTime())) { |
| | | totalHours += toDayDateTime.toLocalTime().until(localEndDateTime.toLocalTime(), ChronoUnit.HOURS); |
| | | } else { |
| | | totalHours += toDayDateTime.toLocalTime().until(user.getSysRostering().getLunchStartTime(), ChronoUnit.HOURS); |
| | | } |
| | | } |
| | | } else { |
| | | totalHours += toDayDateTime.toLocalTime().until(user.getSysRostering().getLunchStartTime(), ChronoUnit.HOURS); |
| | | } |
| | | } |
| | | if (toDayDateTime.toLocalTime().isBefore(user.getSysRostering().getLunchEndTime())) { |
| | | toDayDateTime = toDayDateTime.with(user.getSysRostering().getLunchEndTime()); |
| | | } |
| | | if (toDayDateTime.toLocalTime().isBefore(user.getSysRostering().getWorkEndTime())) { |
| | | if (toDayDateTime.toLocalDate().isEqual(localEndDateTime.toLocalDate())) { |
| | | if (toDayDateTime.toLocalTime().isBefore(localEndDateTime.toLocalTime())) { |
| | | if (localEndDateTime.toLocalTime().isBefore(user.getSysRostering().getWorkEndTime())) { |
| | | totalHours += toDayDateTime.toLocalTime().until(localEndDateTime.toLocalTime(), ChronoUnit.HOURS); |
| | | } else { |
| | | totalHours += toDayDateTime.toLocalTime().until(user.getSysRostering().getWorkEndTime(), ChronoUnit.HOURS); |
| | | } |
| | | } |
| | | } else { |
| | | totalHours += toDayDateTime.toLocalTime().until(user.getSysRostering().getWorkEndTime(), ChronoUnit.HOURS); |
| | | } |
| | | } |
| | | toDayDateTime = toDayDateTime.plusDays(1).with(user.getSysRostering().getWorkStartTime()); |
| | | } |
| | | |
| | | return totalHours; |
| | | } |
| | | |
| | | @Override |
| | | public TaskUserMongo findById(String id) { // TODO |
| | | return mongoTemplate.findById(id, TaskUserMongo.class); |
| | | // TaskUser taskUser = taskUserRepository.findById(id).orElseGet(TaskUser::new); |
| | | // ValidationUtil.isNull(taskUser.getId(),"TaskUser","id",id); |
| | | // return taskUserMapper.toDto(taskUser); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public TaskUserDto create(TaskUser resources) { |
| | | return taskUserMapper.toDto(taskUserRepository.save(resources)); |
| | | public TaskUserMongo create(TaskUserMongo resources) throws Exception { |
| | | |
| | | // // 查询字典 |
| | | // DictDetail dictDetail = dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, resources.getTaskStatus()); |
| | | // //发送钉钉给审批人 |
| | | // List<String> sendList = new ArrayList<>(); |
| | | // //查询所属用户信息 |
| | | // User user = userRepository.findById(resources.getUserId()).orElseGet(User::new); |
| | | // sendList.add(user.getDingding()); |
| | | // opaiDingTalkService.sendNotice(sendList, "任务创建提醒", "### 任务创建提示 \n >" + |
| | | // " \n 任务名称:" + resources.getTask().getName() + |
| | | // " \n 当前任务状态: " + dictDetail.getLabel() + |
| | | // " \n 任务创建成功,请登录PMS系统查看。", "card"); |
| | | TaskMongo byId = mongoTemplate.findById(resources.getTask().getId(), TaskMongo.class); |
| | | if (byId != null) { |
| | | if (byId.getPerformanceType().equals("1")) { |
| | | resources.setPerformanceType("1"); |
| | | } else if (byId.getPerformanceType().equals("0")) { |
| | | resources.setPerformanceType("0"); |
| | | } |
| | | } |
| | | return mongoTemplate.save(resources); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(TaskUser resources) { |
| | | TaskUser taskUser = taskUserRepository.findById(resources.getId()).orElseGet(TaskUser::new); |
| | | ValidationUtil.isNull( taskUser.getId(),"TaskUser","id",resources.getId()); |
| | | taskUser.copy(resources); |
| | | taskUserRepository.save(taskUser); |
| | | @CacheEvict(cacheNames = "task", key = "'projectId:' + #p0.projectId") |
| | | public void update(TaskUserMongoDto resources) throws Exception { |
| | | |
| | | TaskUserMongo taskUserMongo = new TaskUserMongo(); |
| | | TaskMongo taskMongo = mongoTemplate.findById(resources.getTaskId(), TaskMongo.class); |
| | | taskUserMongo.setTask(taskMongo); |
| | | taskUserMongo.setId(resources.getId()); |
| | | taskUserMongo.setOld_id(resources.getOld_id()); |
| | | taskUserMongo.setName(resources.getName()); |
| | | taskUserMongo.setPerformanceType(resources.getPerformanceType()); |
| | | taskUserMongo.setUserId(resources.getUserId()); |
| | | taskUserMongo.setTaskStartDate(resources.getTaskStartDate()); |
| | | taskUserMongo.setTaskEndDate(resources.getTaskEndDate()); |
| | | taskUserMongo.setTaskHours(resources.getTaskHours()); |
| | | taskUserMongo.setTaskStatus(resources.getTaskStatus()); |
| | | |
| | | Double coefficientByUserId; |
| | | if (resources.isIs_ok()) { |
| | | taskUserMongo.setTaskStatus("task_status_completed"); |
| | | } else { |
| | | taskUserMongo.setTaskStatus("task_status_in_hand"); |
| | | } |
| | | |
| | | if (resources.getUserId() == null) { |
| | | //如果没有分配人员 |
| | | taskUserMongo.setPerformanceHours(taskUserMongo.getTaskHours()); |
| | | mongoTemplate.save(taskUserMongo); |
| | | } else { |
| | | //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 |
| | | coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(resources.getUserId()); |
| | | if (taskUserMongo.getPerformanceType().equals("1")) { |
| | | //绩效任务 |
| | | DecimalFormat decimalFormat = new DecimalFormat("#0"); |
| | | String format = decimalFormat.format(taskUserMongo.getTaskHours() / coefficientByUserId); |
| | | taskUserMongo.setPerformanceHours(Double.valueOf(format)); |
| | | } |
| | | } |
| | | |
| | | |
| | | mongoTemplate.save(taskUserMongo); |
| | | |
| | | // // 根据项目ID查询项目信息 |
| | | // Project project = projectRepository.findById(resources.getProjectId()).orElseGet(Project::new); |
| | | // // 查询字典 |
| | | // DictDetail dictDetail = dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, resources.getTaskStatus()); |
| | | // //查询任务名称 |
| | | // Task task = taskRepository.findById(resources.getTaskId()).orElseGet(Task::new); |
| | | // //发送钉钉给审批人 |
| | | // List<String> sendList = new ArrayList<>(); |
| | | // //查询所属用户信息 |
| | | // User user = userRepository.findById(resources.getUserId()).orElseGet(User::new); |
| | | // sendList.add(user.getDingding()); |
| | | // opaiDingTalkService.sendNotice(sendList, "任务变更提醒", "### 任务变更提示 \n >" + |
| | | // "项目名称:" + project.getName() + |
| | | // " \n 任务名称:" + task.getName() + |
| | | // " \n 当前任务状态: " + dictDetail.getLabel() + |
| | | // " \n 当前任务有新的变更,请登录PMS系统查看。", "card"); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteAll(Long[] ids) { |
| | | for (Long id : ids) { |
| | | // 根据ID查询 |
| | | TaskUser taskUser = taskUserRepository.findById(id).orElseGet(TaskUser::new); |
| | | ValidationUtil.isNull(taskUser.getId(),"TaskUser","id",id); |
| | | // 根据项目ID、任务ID查询项目日报列表 |
| | | List<TaskDaliy> taskDaliyList = taskDaliyRepository.findByProjectIdAndTaskId(taskUser.getProjectId(), taskUser.getTaskId()); |
| | | // 判断项目日报列表长度 |
| | | if (taskDaliyList.size() > 0) { |
| | | throw new BadRequestException("已填过项目日报的项目分配无法删除!"); |
| | | } |
| | | taskUserRepository.deleteById(id); |
| | | public void deleteAll(String[] ids) { // TODO |
| | | for (String id : ids) { |
| | | mongoTemplate.remove(Query.query(Criteria.where("id").is(new ObjectId(id))), TaskUserMongo.class); |
| | | } |
| | | // mongoTemplate.remove(Query.query(Criteria.where("id").in(ids)), getClass()); |
| | | |
| | | // for (Long id : ids) { |
| | | // // 根据ID查询 |
| | | // TaskUser taskUser = taskUserRepository.findById(id).orElseGet(TaskUser::new); |
| | | // ValidationUtil.isNull(taskUser.getId(),"TaskUser","id",id); |
| | | // // 根据项目ID、任务ID、用户ID查询项目日报列表 |
| | | // List<TaskDaliy> taskDaliyList = taskDaliyRepository.findByProjectIdAndTaskIdAndUserId(taskUser.getProjectId(), taskUser.getTaskId(), taskUser.getUserId()); |
| | | // // 判断项目日报列表长度 |
| | | // if (taskDaliyList.size() > 0) { |
| | | // throw new BadRequestException("已填过项目日报的项目分配无法删除!"); |
| | | // } |
| | | // taskUserRepository.deleteById(id); |
| | | // } |
| | | } |
| | | |
| | | @Override |
| | | public void download(List<TaskUserDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (TaskUserDto taskUser : all) { |
| | | String projectName = taskUser.getProjectId() != null ? projectRepository.findById(taskUser.getProjectId()).orElseGet(Project::new).getName() : ""; |
| | | String taskName = taskUser.getTaskId() != null ? taskRepository.findById(taskUser.getTaskId()).orElseGet(Task::new).getName() : ""; |
| | | String userNickName = taskUser.getUserId() != null ? userRepository.findById(taskUser.getUserId()).orElseGet(User::new).getNickName() : ""; |
| | | String taskStatus = taskUser.getTaskStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, taskUser.getTaskStatus()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("项目名称", projectName); |
| | | map.put("任务名称", taskName); |
| | | map.put("用户姓名", userNickName); |
| | | map.put("任务开始时间", taskUser.getTaskStartDate()); |
| | | map.put("任务结束时间", taskUser.getTaskEndDate()); |
| | | map.put("任务工时", taskUser.getTaskHours()); |
| | | map.put("任务工作量", taskUser.getTaskWorkload()); |
| | | map.put("任务状态", taskStatus); |
| | | map.put("备注", taskUser.getRemarks()); |
| | | map.put("创建者", taskUser.getCreateBy()); |
| | | map.put("创建时间", taskUser.getCreateTime()); |
| | | map.put("更新者", taskUser.getUpdateBy()); |
| | | map.put("更新时间", taskUser.getUpdateTime()); |
| | | list.add(map); |
| | | } |
| | | FileUtil.downloadExcel(list, response); |
| | | // List<Map<String, Object>> list = new ArrayList<>(); |
| | | // for (TaskUserDto taskUser : all) { |
| | | // String projectName = taskUser.getProjectId() != null ? projectRepository.findById(taskUser.getProjectId()).orElseGet(Project::new).getName() : ""; |
| | | // String taskName = taskUser.getTaskId() != null ? taskRepository.findById(taskUser.getTaskId()).orElseGet(Task::new).getName() : ""; |
| | | // String userNickName = taskUser.getUserId() != null ? userRepository.findById(taskUser.getUserId()).orElseGet(User::new).getNickName() : ""; |
| | | // String taskStatus = taskUser.getTaskStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, taskUser.getTaskStatus()).getLabel() : ""; |
| | | // Map<String,Object> map = new LinkedHashMap<>(); |
| | | // map.put("项目名称", projectName); |
| | | // map.put("任务名称", taskName); |
| | | // map.put("用户姓名", userNickName); |
| | | // map.put("任务开始时间", taskUser.getTaskStartDate()); |
| | | // map.put("任务结束时间", taskUser.getTaskEndDate()); |
| | | // map.put("任务工时", taskUser.getTaskHours()); |
| | | // map.put("任务工作量", taskUser.getTaskWorkload()); |
| | | // map.put("任务状态", taskStatus); |
| | | // map.put("备注", taskUser.getRemarks()); |
| | | // map.put("创建者", taskUser.getCreateBy()); |
| | | // map.put("创建时间", taskUser.getCreateTime()); |
| | | // map.put("更新者", taskUser.getUpdateBy()); |
| | | // map.put("更新时间", taskUser.getUpdateTime()); |
| | | // list.add(map); |
| | | // } |
| | | // FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | // @Override |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | // public void divide(TaskUserDto resources) throws Exception { |
| | | // // 循环多用户ID |
| | | // for (int i = 0; i < resources.getUserIds().size(); i ++) { |
| | | // // 任务分配实体类 |
| | | // TaskUser taskUser = new TaskUser(); |
| | | // taskUser.setProjectId(resources.getProjectId()); |
| | | // taskUser.setTaskId(resources.getTaskId()); |
| | | // taskUser.setUserId(resources.getUserIds().get(i)); |
| | | // taskUser.setTaskStartDate(resources.getTaskStartDate()); |
| | | // taskUser.setTaskEndDate(resources.getTaskEndDate()); |
| | | // taskUser.setTaskHours(resources.getTaskHours()); |
| | | // taskUser.setTaskWorkload(resources.getTaskWorkload()); |
| | | // taskUser.setTaskStatus(resources.getTaskStatus()); |
| | | // |
| | | // // 新增时连番固定是1 |
| | | // taskUser.setTaskInnerId(1L); |
| | | // // 有效FLG为True |
| | | // taskUser.setEnable(true); |
| | | // |
| | | // List<TaskUser> taskUserOldList = taskUserRepository.findByTaskIdAndUserId(resources.getTaskId(), resources.getUserIds().get(i)); |
| | | // // 判断项目日报列表长度 |
| | | // if (taskUserOldList.size() > 0) { |
| | | // throw new BadRequestException("用户已分配该任务,无法重复分配!"); |
| | | // } |
| | | // // 保存 |
| | | // taskUserRepository.save(taskUser); |
| | | // |
| | | // // 发送钉钉给审批人 |
| | | // List<String> sendList = new ArrayList<>(); |
| | | // // 查询所属用户信息 |
| | | // User user = userRepository.findById(resources.getUserIds().get(i)).orElseGet(User::new); |
| | | // sendList.add(user.getDingding()); |
| | | // // 查询字典 |
| | | // DictDetail dictDetail = dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, resources.getTaskStatus()); |
| | | // // 钉钉发送 |
| | | // opaiDingTalkService.sendNotice(sendList, "任务创建提醒", "### 任务创建提示 \n >" + |
| | | // " \n 任务名称:" + resources.getTaskName() + |
| | | // " \n 当前任务状态: " + dictDetail.getLabel() + |
| | | // " \n 任务创建成功,请登录PMS系统查看。", "card"); |
| | | // } |
| | | // } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void divide(TaskUserDto resources) { |
| | | // 循环多用户ID |
| | | for (int i = 0; i < resources.getUserIds().size(); i ++) { |
| | | // 任务分配实体类 |
| | | TaskUser taskUser = new TaskUser(); |
| | | taskUser.setProjectId(resources.getProjectId()); |
| | | taskUser.setTaskId(resources.getTaskId()); |
| | | taskUser.setUserId(resources.getUserIds().get(i)); |
| | | taskUser.setTaskStartDate(resources.getTaskStartDate()); |
| | | taskUser.setTaskEndDate(resources.getTaskEndDate()); |
| | | taskUser.setTaskHours(resources.getTaskHours()); |
| | | taskUser.setTaskWorkload(resources.getTaskWorkload()); |
| | | taskUser.setTaskStatus(resources.getTaskStatus()); |
| | | // 保存 |
| | | taskUserRepository.save(taskUser); |
| | | } |
| | | public List<Long> queryTaskUserIds(TaskUserQueryCriteria criteria) { |
| | | return Collections.emptyList(); // taskUserRepository.findUserIdByTaskId(criteria.getTaskId()); |
| | | } |
| | | } |