| | |
| | | package me.zhengjie.modules.task.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.text.DecimalFormat; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | |
| | | import me.zhengjie.modules.task.domain.Task; |
| | | import me.zhengjie.modules.task.domain.TaskUser; |
| | | import me.zhengjie.modules.task.repository.TaskRepository; |
| | | import me.zhengjie.modules.treatment.repository.UserLevelWageRepository; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | | import org.bson.types.ObjectId; |
| | | import org.springframework.data.domain.Pageable; |
| | |
| | | private final TaskRepository taskRepository; |
| | | private final UserService userService; |
| | | private final MongoTemplate mongoTemplate; |
| | | private final UserLevelWageRepository userLevelWageRepository; |
| | | |
| | | @Override |
| | | public TaskUserTotalMongoDto sumTotalByTask(String taskId) { |
| | |
| | | |
| | | AggregationResults<TaskUserTotalDetailMongoDto> taskUserMongoList = mongoTemplate.aggregate(customerAgg, TaskUserMongo.class, TaskUserTotalDetailMongoDto.class); |
| | | result.setDetails(taskUserMongoList.getMappedResults()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | |
| | | TaskMongo taskMongo = mongoTemplate.findById(byId.getTask().getId(), TaskMongo.class); |
| | | List<Long> containUserList = taskMongo.getContainUserList(); |
| | | if(!containUserList.contains(SecurityUtils.getCurrentUserId())){ |
| | | if (!containUserList.contains(SecurityUtils.getCurrentUserId())) { |
| | | //如果获取的这个人不在这个任务中 |
| | | throw new BadRequestException("您不在当前的任务中,无法领取该任务"); |
| | | } |
| | | |
| | | if(byId != null){ |
| | | if (byId != null) { |
| | | byId.setUserId(SecurityUtils.getCurrentUserId()); |
| | | mongoTemplate.save(byId); |
| | | } |
| | |
| | | } else { |
| | | return PageUtil.toPage(Collections.emptyList(), 0); |
| | | } |
| | | if (criteria.getName() != null) { |
| | | criteriaMongo = criteriaMongo.and("name").regex(Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE)); |
| | | } |
| | | if (criteria.getUserId() != null) { |
| | | criteriaMongo = criteriaMongo.and("userId").in(criteria.getUserId()); |
| | | if (criteria.getUserId() != null){ |
| | | criteriaMongo = criteriaMongo.and("userId").is(criteria.getUserId()); |
| | | } |
| | | if (criteria.getTaskStatus() != null && criteria.getTaskStatus().size() > 0) { |
| | | criteriaMongo = criteriaMongo.and("taskStatus").in(criteria.getTaskStatus()); |
| | |
| | | taskUserMongoDto.setId(taskUserMongo.getId()); |
| | | taskUserMongoDto.setName(taskUserMongo.getName()); |
| | | taskUserMongoDto.setOld_id(taskUserMongo.getTask().getOld_id()); |
| | | taskUserMongoDto.setTaskClassification(taskUserMongo.getTaskClassification()); |
| | | |
| | | if (taskUserMongo.getUserId() != null) { |
| | | taskUserMongoDto.setUserId(taskUserMongo.getUserId()); |
| | | UserDto userDto = userService.findById(taskUserMongo.getUserId()); |
| | |
| | | taskUserMongoDto.setTaskStartDate(taskUserMongo.getTaskStartDate()); |
| | | taskUserMongoDto.setTaskEndDate(taskUserMongo.getTaskEndDate()); |
| | | taskUserMongoDto.setTaskHours(taskUserMongo.getTaskHours()); |
| | | |
| | | |
| | | taskUserMongoDto.setTaskDaliyList(taskUserMongo.getTaskDaliyList()); |
| | | 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); |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public TaskUserMongo create(TaskUserMongo resources) throws Exception { |
| | | |
| | | // // 查询字典 |
| | | // DictDetail dictDetail = dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, resources.getTaskStatus()); |
| | | // //发送钉钉给审批人 |
| | |
| | | // " \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); |
| | | } |
| | | |
| | |
| | | // taskUserRepository.save(taskUserNew); |
| | | // } |
| | | |
| | | if(resources.getUserId() == null){ |
| | | if (resources.getUserId() == null) { |
| | | TaskUserMongo byId = mongoTemplate.findById(resources.getId(), TaskUserMongo.class); |
| | | if(byId != null){ |
| | | if (byId != null) { |
| | | byId.setUserId(null); |
| | | mongoTemplate.save(byId); |
| | | } |