churf
2023-08-10 6125e850667ea723fbd888f592e0a81da2a89dd2
no message
8 files modified
505 ■■■■■ changed files
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/domain/TaskDaliyMongo.java 17 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/repository/TaskDaliyRepository.java 6 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskDaliyServiceImpl.java 227 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskServiceImpl.java 181 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskUserServiceImpl.java 56 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/repository/CmnLevelRankRepository.java 6 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/repository/UserLevelWageRepository.java 6 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectServiceImpl.java
@@ -244,11 +244,7 @@
    @Override
    public List<ProjectDto> queryAll2(ProjectQueryCriteria criteria) {
        List<ProjectDto> projectDtoList = projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
        Long userId = SecurityUtils.getCurrentUserId();
        List<Long> projectIdList = projectRepository.findIdByLiableUserId(userId);
        return projectDtoList;
        return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
    }
    private ProjectDto customHandle(ProjectDto projectDto) {
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/domain/TaskDaliyMongo.java
@@ -19,6 +19,7 @@
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import io.swagger.annotations.ApiModelProperty;
@@ -34,18 +35,18 @@
@Document("task_daliy")
public class TaskDaliyMongo implements Serializable {
//    @Id
//    @ApiModelProperty(value = "ID")
//    private String id;
//
    @Id
    private String id;
//    @ApiModelProperty(value = "项目ID")
//    private Long projectId;
//
//    @ApiModelProperty(value = "任务ID")
//    private String taskId;
//
//    @ApiModelProperty(value = "员工ID")
//    private Long userId;
    @DBRef
    private TaskUserMongo taskUserMongo;
    @ApiModelProperty(value = "员工ID")
    private Long userId;
    @ApiModelProperty(value = "填写日期")
    private Date fillDate;
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/repository/TaskDaliyRepository.java
@@ -235,5 +235,9 @@
    @Query(value = "select DISTINCT user_id from task_daliy where task_id = ?1",nativeQuery = true)
    List<Long> findByTaskId(Long TaskId);
    List<Long> findByTaskId(Long taskId);
    @Query(value = "select * from task_daliy where task_id = ?1",nativeQuery = true)
    List<TaskDaliy> findTaskDaliyByTaskId(Long taskId);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskDaliyServiceImpl.java
@@ -1,18 +1,18 @@
/*
*  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;
@@ -30,8 +30,12 @@
import javax.servlet.http.HttpServletResponse;
import me.zhengjie.modules.task.domain.*;
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.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -48,10 +52,6 @@
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.repository.TaskRepository;
import me.zhengjie.modules.task.repository.TaskUserRepository;
@@ -67,11 +67,11 @@
import me.zhengjie.utils.ValidationUtil;
/**
* @website https://eladmin.vip
* @description 服务实现
* @author 赵士淞
* @date 2022-12-30
**/
 * @author 赵士淞
 * @website https://eladmin.vip
 * @description 服务实现
 * @date 2022-12-30
 **/
@Service
@RequiredArgsConstructor
public class TaskDaliyServiceImpl implements TaskDaliyService {
@@ -85,69 +85,32 @@
    private final DictDetailRepository dictDetailRepository;
    private final TaskUserRepository taskUserRepository;
    private final RoleService roleService;
    private final MongoTemplate mongoTemplate;
    @Override
    public Map<String,Object> queryAll(TaskDaliyQueryCriteria 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 = taskUserRepository.findProjectIdByUserId(SecurityUtils.getCurrentUserId());
            // 根据用户ID查询负责的项目ID
            List<Long> projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId());
            // 检索条件
            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.setProjectIdInList(totalProjectIdList);
        }
        Page<TaskDaliy> page = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
        // 将实体类转换为DTO(重写)
        Function<TaskDaliy, TaskDaliyDto> func = new Function<TaskDaliy, TaskDaliyDto>(){
            @Override
            public TaskDaliyDto apply(TaskDaliy t) {
                // 将实体类转换成DTO
                TaskDaliyDto taskDaliyDto = taskDaliyMapper.toDto(t);
                // 根据项目ID查询项目信息
                Project project = projectRepository.findById(taskDaliyDto.getProjectId()).orElseGet(Project::new);
                ValidationUtil.isNull(project.getId(),"Project","id",taskDaliyDto.getProjectId());
                // 项目名称
                taskDaliyDto.setProjectName(project.getName());
                // 根据任务ID查询任务信息
                Task task = taskRepository.findById(taskDaliyDto.getTaskId()).orElseGet(Task::new);
                ValidationUtil.isNull(task.getId(),"Task","id",taskDaliyDto.getTaskId());
                // 任务名称
                taskDaliyDto.setTaskName(task.getName());
                // 任务工作量单位
                taskDaliyDto.setTaskWorkloadUnit(task.getPlanWorkloadUnit());
                // 根据用户ID查询用户信息
                User user = userRepository.findById(taskDaliyDto.getUserId()).orElseGet(User::new);
                ValidationUtil.isNull(user.getId(),"User","id",taskDaliyDto.getUserId());
                // 用户昵称
                taskDaliyDto.setUserNickName(user.getNickName());
                // 返回处理好的DTO
                return taskDaliyDto;
            }
        };
        return PageUtil.toPage(page.map(func));
    public Map<String, Object> queryAll(TaskDaliyQueryCriteria criteria, Pageable pageable) {
        Query query = Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()));
        mongoTemplate.count(query,TaskUserMongo.class);
        List<TaskUserMongo> taskUserList = mongoTemplate.find(query, TaskUserMongo.class);
        return null;
    }
    @Override
    public Map<String,Object> queryAllWithTaskUser(TaskDaliyQueryCriteria criteria, Pageable pageable){
        Page<TaskDaliy> page = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
    public Map<String, Object> queryAllWithTaskUser(TaskDaliyQueryCriteria criteria, Pageable pageable) {
        Page<TaskDaliy> page = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        // 将实体类转换为DTO(重写)
        Function<TaskDaliy, TaskDaliyDto> func = new Function<TaskDaliy, TaskDaliyDto>(){
        Function<TaskDaliy, TaskDaliyDto> func = new Function<TaskDaliy, TaskDaliyDto>() {
            @Override
            public TaskDaliyDto apply(TaskDaliy t) {
                // 将实体类转换成DTO
                TaskDaliyDto taskDaliyDto = taskDaliyMapper.toDto(t);
                // 根据任务ID查询任务信息
                Task task = taskRepository.findById(taskDaliyDto.getTaskId()).orElseGet(Task::new);
                ValidationUtil.isNull(task.getId(),"Task","id",taskDaliyDto.getTaskId());
                ValidationUtil.isNull(task.getId(), "Task", "id", taskDaliyDto.getTaskId());
                // 任务名称
                taskDaliyDto.setTaskName(task.getName());
                // 根据任务ID,任务连番和用户ID查询任务分配
@@ -162,22 +125,22 @@
    }
    @Override
    public List<TaskDaliyDto> queryAll(TaskDaliyQueryCriteria criteria){
        return taskDaliyMapper.toDto(taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
    public List<TaskDaliyDto> queryAll(TaskDaliyQueryCriteria criteria) {
        return taskDaliyMapper.toDto(taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
    }
    @Override
    @Transactional
    public TaskDaliyDto findById(Long id) {
        TaskDaliy taskDaliy = taskDaliyRepository.findById(id).orElseGet(TaskDaliy::new);
        ValidationUtil.isNull(taskDaliy.getId(),"TaskDaliy","id",id);
        ValidationUtil.isNull(taskDaliy.getId(), "TaskDaliy", "id", id);
        return taskDaliyMapper.toDto(taskDaliy);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public TaskDaliyDto create(TaskDaliy resources) {
        // 获取任务分配信息
        // 获取任务分配信息
        TaskUser taskUser = taskUserRepository.findByTaskIdAndUserIdAndEnable(resources.getTaskId(), resources.getUserId(), true);
        // 设置任务连番
        resources.setTaskInnerId(taskUser.getTaskInnerId());
@@ -187,8 +150,8 @@
        checkAddOrUpdate(resources);
        if (Constant.TASK_STATUS_NOT_STARTED.equals(taskUser.getTaskStatus())) {
            taskUser.setTaskStatus(Constant.TASK_STATUS_IN_HAND);
            taskUserRepository.save(taskUser);
            taskUser.setTaskStatus(Constant.TASK_STATUS_IN_HAND);
            taskUserRepository.save(taskUser);
        }
        return taskDaliyMapper.toDto(taskDaliyRepository.save(resources));
    }
@@ -197,9 +160,9 @@
    @Transactional(rollbackFor = Exception.class)
    public void update(TaskDaliy resources) {
        TaskDaliy taskDaliy = taskDaliyRepository.findById(resources.getId()).orElseGet(TaskDaliy::new);
        ValidationUtil.isNull( taskDaliy.getId(),"TaskDaliy","id",resources.getId());
        ValidationUtil.isNull(taskDaliy.getId(), "TaskDaliy", "id", resources.getId());
        // 获取任务分配信息
        // 获取任务分配信息
        TaskUser taskUser = taskUserRepository.findByTaskIdAndUserIdAndEnable(resources.getTaskId(), resources.getUserId(), true);
        // 新增修改删除验证
@@ -211,14 +174,15 @@
        taskDaliy.copy(resources);
        if (Constant.TASK_STATUS_NOT_STARTED.equals(taskUser.getTaskStatus())) {
            taskUser.setTaskStatus(Constant.TASK_STATUS_IN_HAND);
            taskUserRepository.save(taskUser);
            taskUser.setTaskStatus(Constant.TASK_STATUS_IN_HAND);
            taskUserRepository.save(taskUser);
        }
        taskDaliyRepository.save(taskDaliy);
    }
    /**
     * 新增修改验证
     *
     * @param resources
     */
    private void checkAddOrUpdate(TaskDaliy resources) {
@@ -229,7 +193,7 @@
        criteria.setUserId(resources.getUserId());
//        criteria.setFillDate(resources.getFillDate());// TODO
        // 根据项目ID、任务ID、用户ID、填报日期查询
        List<TaskDaliy> taskDaliyList = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
        List<TaskDaliy> taskDaliyList = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
        // 判断是否已有日报
        if (taskDaliyList.size() > 1 || (taskDaliyList.size() == 1 && taskDaliyList.get(0).getId() != resources.getId())) {
            throw new BadRequestException("每个任务每天只能填写一次日报!");
@@ -241,7 +205,7 @@
        // 根据项目ID、任务ID、用户ID查询填报日期前最近的任务日报信息
        TaskDaliy previousTaskDaliy = taskDaliyRepository.findPreviousByProjectIdAndTaskIdAndAndUserId(resources.getProjectId(), resources.getTaskId(), resources.getUserId(), resources.getFillDate());
        if (previousTaskDaliy != null) {
            TaskUser previousTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(previousTaskDaliy.getTaskId(), previousTaskDaliy.getTaskInnerId(), previousTaskDaliy.getUserId());
            TaskUser previousTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(previousTaskDaliy.getTaskId(), previousTaskDaliy.getTaskInnerId(), previousTaskDaliy.getUserId());
            if (previousTaskUser != null && resources.getTaskProgress() * currentTaskUser.getTaskHours() < previousTaskDaliy.getTaskProgress() * previousTaskUser.getTaskHours()) {
                throw new BadRequestException("任务进度必须比前一次多且比后一次少!");
            }
@@ -250,12 +214,12 @@
        // 根据项目ID、任务ID、用户ID查询填报日期后最近的任务日报信息
        TaskDaliy nextTaskDaliy = taskDaliyRepository.findNextByProjectIdAndTaskIdAndAndUserId(resources.getProjectId(), resources.getTaskId(), resources.getUserId(), resources.getFillDate());
        if (nextTaskDaliy != null) {
            // 后日任务分配
            TaskUser nextTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(nextTaskDaliy.getTaskId(), nextTaskDaliy.getTaskInnerId(), nextTaskDaliy.getUserId());
            // 判断任务进度是否比前一次多,比后一次少
            if (nextTaskUser != null && resources.getTaskProgress() * currentTaskUser.getTaskHours() > nextTaskDaliy.getTaskProgress() * nextTaskUser.getTaskHours()) {
                throw new BadRequestException("任务进度必须比前一次多且比后一次少!");
            }
            // 后日任务分配
            TaskUser nextTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(nextTaskDaliy.getTaskId(), nextTaskDaliy.getTaskInnerId(), nextTaskDaliy.getUserId());
            // 判断任务进度是否比前一次多,比后一次少
            if (nextTaskUser != null && resources.getTaskProgress() * currentTaskUser.getTaskHours() > nextTaskDaliy.getTaskProgress() * nextTaskUser.getTaskHours()) {
                throw new BadRequestException("任务进度必须比前一次多且比后一次少!");
            }
        }
    }
@@ -263,7 +227,7 @@
    public void deleteAll(Long[] ids) {
        for (Long id : ids) {
            TaskDaliy taskDaliy = taskDaliyRepository.findById(id).orElseGet(TaskDaliy::new);
            ValidationUtil.isNull( taskDaliy.getId(),"TaskDaliy","id",id);
            ValidationUtil.isNull(taskDaliy.getId(), "TaskDaliy", "id", id);
            // 新增修改删除验证
            checkAddOrUpdateOrDelete(taskDaliy);
            // 修改删除验证
@@ -274,6 +238,7 @@
    /**
     * 修改删除验证
     *
     * @param resources
     */
    private void checkUpdateOrDelete(TaskDaliy resources) {
@@ -285,6 +250,7 @@
    /**
     * 新增修改删除验证
     *
     * @param resources
     */
    private void checkAddOrUpdateOrDelete(TaskDaliy resources) {
@@ -309,7 +275,7 @@
            String taskName = taskDaliy.getTaskId() != null ? taskRepository.findById(taskDaliy.getTaskId()).orElseGet(Task::new).getName() : "";
            String userNickName = taskDaliy.getUserId() != null ? userRepository.findById(taskDaliy.getUserId()).orElseGet(User::new).getNickName() : "";
            String settlementStatus = taskDaliy.getSettlementStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.SETTLEMENT_STATUS, taskDaliy.getSettlementStatus()).getLabel() : "";
            Map<String,Object> map = new LinkedHashMap<>();
            Map<String, Object> map = new LinkedHashMap<>();
            map.put("填写日期", taskDaliy.getFillDate());
            map.put("项目名称", projectName);
            map.put("任务名称", taskName);
@@ -329,21 +295,21 @@
    }
    @Override
    public Double queryOtherWage(TaskDaliyQueryCriteria criteria){
    public Double queryOtherWage(TaskDaliyQueryCriteria criteria) {
        // 已完成工时
        Double completedWork = 0D;
        // 国际时间转中国时间
        String targetYearMonth = DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth());
        // 任务日报检索类
        criteria.setFillDateLike(targetYearMonth.substring(0,7));
        criteria.setFillDateLike(targetYearMonth.substring(0, 7));
        // 获取本月任务日报列表
        List<TaskDaliy> taskDaliyMonthList = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
        List<TaskDaliy> taskDaliyMonthList = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
        // 判断是否有本月任务日报
        if (taskDaliyMonthList.size() != 0) {
            // 获取本月任务日报中所有任务ID
            List<Long> taskIds = taskDaliyMonthList.stream().map(item -> item.getTaskId()).distinct().collect(Collectors.toList());
            // 获取对应的任务
            Map<Long, Task> taskMap = taskRepository.findAllById(taskIds).stream().collect(Collectors.toMap(Task::getId,Function.identity()));
            Map<Long, Task> taskMap = taskRepository.findAllById(taskIds).stream().collect(Collectors.toMap(Task::getId, Function.identity()));
            // 获取本月任务分配列表
            List<TaskUser> taskUserMonthList = taskUserRepository.findByUserIdAndTaskIdIn(criteria.getUserId(), taskIds);
            // 日历类
@@ -351,40 +317,40 @@
            // 获取本月最大天数
            int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            // 循环本月最大天数
            for (int i = 1; i <= lastDay; i ++) {
            for (int i = 1; i <= lastDay; i++) {
                // 设置天数
                cal.set(Calendar.DAY_OF_MONTH, i);
                // 获取本日任务日报列表
                List<TaskDaliy> taskDaliyDayList = taskDaliyMonthList.stream().filter(item -> item.getFillDate().getTime() == cal.getTime().getTime()).collect(Collectors.toList());
                // 循环本日任务日报列表
                for (int j = 0; j < taskDaliyDayList.size(); j ++) {
                for (int j = 0; j < taskDaliyDayList.size(); j++) {
                    // 本日任务日报
                    TaskDaliy taskDaliyDay = taskDaliyDayList.get(j);
                    // 本日任务分配列表
                    Optional<TaskUser> OptionalTaskUser = taskUserMonthList.stream().filter(item -> item.getTaskId().equals(taskDaliyDay.getTaskId()) && item.getTaskInnerId().equals(taskDaliyDay.getTaskInnerId())).findFirst();
                    if (!OptionalTaskUser.isPresent()) {
                        throw new BadRequestException("未找到任务分配记录!");
                        throw new BadRequestException("未找到任务分配记录!");
                    }
                    TaskUser taskUserDay = OptionalTaskUser.get();
                    Task task = taskMap.get(taskUserDay.getTaskId());
                    if (Constant.PERFORMANCE_TYPE_RATE.equals(task.getPerformanceType())) {
                        // 根据项目ID、任务ID、用户ID查询填报日期前最近的任务日报信息
                        // 根据项目ID、任务ID、用户ID查询填报日期前最近的任务日报信息
                        TaskDaliy taskDaliyHistory = taskDaliyRepository.findPreviousByProjectIdAndTaskIdAndAndUserId(taskDaliyDay.getProjectId(), taskDaliyDay.getTaskId(), taskDaliyDay.getUserId(), taskDaliyDay.getFillDate());
                        // 判断最近的任务日报是否为空
                        if (taskDaliyHistory != null) {
                            TaskUser previousTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(taskDaliyHistory.getTaskId(), taskDaliyHistory.getTaskInnerId(), taskDaliyHistory.getUserId());
                            TaskUser previousTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(taskDaliyHistory.getTaskId(), taskDaliyHistory.getTaskInnerId(), taskDaliyHistory.getUserId());
                            if (previousTaskUser == null) {
                                throw new BadRequestException("任务日报进度计算存在异常!");
                            }
                            // 判断进度是否正常
                            if (taskDaliyDay.getConsumedWorkload() < taskDaliyHistory.getConsumedWorkload()) {
                                throw new BadRequestException("任务日报进度计算存在异常!");
                                throw new BadRequestException("任务日报进度计算存在异常!");
                            }
                            // 本日任务日报进度
                            completedWork += task.getPieceRate() * (taskDaliyDay.getConsumedWorkload() - taskDaliyHistory.getConsumedWorkload());
                        } else {
                            // 已完成工时
                            completedWork += task.getPieceRate() * taskDaliyDay.getConsumedWorkload();
                            // 已完成工时
                            completedWork += task.getPieceRate() * taskDaliyDay.getConsumedWorkload();
                        }
                    }
@@ -400,21 +366,21 @@
    }
    @Override
    public Double queryCompletedWork(TaskDaliyQueryCriteria criteria, Boolean readOnly){
    public Double queryCompletedWork(TaskDaliyQueryCriteria criteria, Boolean readOnly) {
        // 已完成工时
        Double completedWork = 0D;
        // 国际时间转中国时间
        String targetYearMonth = DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth());
        // 任务日报检索类
        criteria.setFillDateLike(targetYearMonth.substring(0,7));
        criteria.setFillDateLike(targetYearMonth.substring(0, 7));
        // 获取本月任务日报列表
        List<TaskDaliy> taskDaliyMonthList = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
        List<TaskDaliy> taskDaliyMonthList = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
        // 判断是否有本月任务日报
        if (taskDaliyMonthList.size() != 0) {
            // 获取本月任务日报中所有任务ID
            List<Long> taskIds = taskDaliyMonthList.stream().map(item -> item.getTaskId()).distinct().collect(Collectors.toList());
            // 获取对应的任务
            Map<Long, Task> taskMap = taskRepository.findAllById(taskIds).stream().collect(Collectors.toMap(Task::getId,Function.identity()));
            Map<Long, Task> taskMap = taskRepository.findAllById(taskIds).stream().collect(Collectors.toMap(Task::getId, Function.identity()));
            // 获取本月任务分配列表
            List<TaskUser> taskUserMonthList = taskUserRepository.findByUserIdAndTaskIdIn(criteria.getUserId(), taskIds);
            // 日历类
@@ -422,43 +388,43 @@
            // 获取本月最大天数
            int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            // 循环本月最大天数
            for (int i = 1; i <= lastDay; i ++) {
            for (int i = 1; i <= lastDay; i++) {
                // 设置天数
                cal.set(Calendar.DAY_OF_MONTH, i);
                // 获取本日任务日报列表
                List<TaskDaliy> taskDaliyDayList = taskDaliyMonthList.stream().filter(item -> item.getFillDate().getTime() == cal.getTime().getTime()).collect(Collectors.toList());
                // 循环本日任务日报列表
                for (int j = 0; j < taskDaliyDayList.size(); j ++) {
                for (int j = 0; j < taskDaliyDayList.size(); j++) {
                    // 本日任务日报
                    TaskDaliy taskDaliyDay = taskDaliyDayList.get(j);
                    // 本日任务分配列表
                    Optional<TaskUser> OptionalTaskUser = taskUserMonthList.stream().filter(item -> item.getTaskId().equals(taskDaliyDay.getTaskId()) && item.getTaskInnerId().equals(taskDaliyDay.getTaskInnerId())).findFirst();
                    if (!OptionalTaskUser.isPresent()) {
                        throw new BadRequestException("未找到任务分配记录!");
                        throw new BadRequestException("未找到任务分配记录!");
                    }
                    TaskUser taskUserDay = OptionalTaskUser.get();
                    Task task = taskMap.get(taskUserDay.getTaskId());
                    if (Constant.PERFORMANCE_TYPE_ON.equals(task.getPerformanceType())) {
                        // 根据项目ID、任务ID、用户ID查询填报日期前最近的任务日报信息
                        // 根据项目ID、任务ID、用户ID查询填报日期前最近的任务日报信息
                        TaskDaliy taskDaliyHistory = taskDaliyRepository.findPreviousByProjectIdAndTaskIdAndAndUserId(taskDaliyDay.getProjectId(), taskDaliyDay.getTaskId(), taskDaliyDay.getUserId(), taskDaliyDay.getFillDate());
                        // 判断最近的任务日报是否为空
                        if (taskDaliyHistory != null) {
                            TaskUser previousTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(taskDaliyHistory.getTaskId(), taskDaliyHistory.getTaskInnerId(), taskDaliyHistory.getUserId());
                            TaskUser previousTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(taskDaliyHistory.getTaskId(), taskDaliyHistory.getTaskInnerId(), taskDaliyHistory.getUserId());
                            if (previousTaskUser == null) {
                                throw new BadRequestException("任务日报进度计算存在异常!");
                            }
                            // 判断进度是否正常
                            if (taskDaliyDay.getTaskProgress() * taskUserDay.getTaskHours() < taskDaliyHistory.getTaskProgress() * previousTaskUser.getTaskHours()) {
                                throw new BadRequestException("任务日报进度计算存在异常!");
                                throw new BadRequestException("任务日报进度计算存在异常!");
                            }
                            // 本日任务日报进度
                            completedWork += (taskDaliyDay.getTaskProgress() * taskUserDay.getTaskHours() - taskDaliyHistory.getTaskProgress() * previousTaskUser.getTaskHours()) /100;
                            completedWork += (taskDaliyDay.getTaskProgress() * taskUserDay.getTaskHours() - taskDaliyHistory.getTaskProgress() * previousTaskUser.getTaskHours()) / 100;
                        } else {
                            // 已完成工时
                            completedWork += taskUserDay.getTaskHours() * (taskDaliyDay.getTaskProgress() / 100);
                            // 已完成工时
                            completedWork += taskUserDay.getTaskHours() * (taskDaliyDay.getTaskProgress() / 100);
                        }
                    } else if (Constant.PERFORMANCE_TYPE_OFF.equals(task.getPerformanceType())) {
                        // 已完成工时
                        // 已完成工时
                        completedWork += taskDaliyDay.getConsumedHours() * 1.1;
                    }
@@ -477,17 +443,17 @@
        AttendanceLeaveQueryCriteria attendanceLeaveQueryCriteria = new AttendanceLeaveQueryCriteria();
        attendanceLeaveQueryCriteria.setUserId(criteria.getUserId());
        attendanceLeaveQueryCriteria.setLeaveType(Constant.LEAVE_TYPE_ANNUAL_LEAVE);
        attendanceLeaveQueryCriteria.setLeaveStartTimeLike(targetYearMonth.substring(0,7));
        attendanceLeaveQueryCriteria.setLeaveEndTimeLike(targetYearMonth.substring(0,7));
        attendanceLeaveQueryCriteria.setLeaveStartTimeLike(targetYearMonth.substring(0, 7));
        attendanceLeaveQueryCriteria.setLeaveEndTimeLike(targetYearMonth.substring(0, 7));
        attendanceLeaveQueryCriteria.setApprovalStatus(Constant.APPROVAL_STATUS_PASSED);
        // 获取本月请假列表
        List<AttendanceLeave> attendanceLeaveMonthList = attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,attendanceLeaveQueryCriteria,criteriaBuilder));
        List<AttendanceLeave> attendanceLeaveMonthList = attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, attendanceLeaveQueryCriteria, criteriaBuilder));
        for (AttendanceLeave attendanceLeave : attendanceLeaveMonthList) {
            if (Constant.LEAVE_TIME_TYPE_DAY.equals(attendanceLeave.getLeaveDurationUnit())) {
                completedWork += attendanceLeave.getLeaveDuration() * 8;
            } else {
                completedWork += attendanceLeave.getLeaveDuration();
            }
            if (Constant.LEAVE_TIME_TYPE_DAY.equals(attendanceLeave.getLeaveDurationUnit())) {
                completedWork += attendanceLeave.getLeaveDuration() * 8;
            } else {
                completedWork += attendanceLeave.getLeaveDuration();
            }
        }
        // 已完成工时
        return completedWork;
@@ -495,15 +461,16 @@
    /**
     * 设置日历类
     *
     * @return
     */
    private Calendar setUpCalendar(String targetYearMonth) {
        // 日历类
        Calendar cal = Calendar.getInstance();
        // 设置年份
        cal.set(Calendar.YEAR, Integer.valueOf(targetYearMonth.substring(0,4)));
        cal.set(Calendar.YEAR, Integer.valueOf(targetYearMonth.substring(0, 4)));
        // 设置月份
        cal.set(Calendar.MONTH, Integer.valueOf(targetYearMonth.substring(5,7)) - 1);
        cal.set(Calendar.MONTH, Integer.valueOf(targetYearMonth.substring(5, 7)) - 1);
        // 设置时数
        cal.set(Calendar.HOUR_OF_DAY, 0);
        // 设置分数
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskServiceImpl.java
@@ -121,20 +121,40 @@
    @Override
    public List<ProjectDto> getAllProjects(ProjectQueryCriteria criteria) {
        Query query = Query.query(Criteria.where("containUserList").is(SecurityUtils.getCurrentUserId()));
        List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
        // 获取登录用户角色等级
        List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
        // 登录用户最大角色等级
        int min = Collections.min(levels);
        ArrayList<Long> projectList = new ArrayList<>();
        for (TaskMongo taskMongo : taskMongoList) {
            projectList.add(taskMongo.getProjectId());
        if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) {
            ArrayList<Long> projectList = new ArrayList<>();
            Query query = Query.query(Criteria.where("containUserList").is(SecurityUtils.getCurrentUserId()));
            List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
            for (TaskMongo taskMongo : taskMongoList) {
                projectList.add(taskMongo.getProjectId());
            }
            // 根据用户ID查询负责的项目ID
            List<Long> projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId());
            Set<Long> projectIds = Stream.of(projectList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toSet());
            criteria.setApproveStatus(Constant.APPROVE_STATUS_ACKNOWLEDGED);
            criteria.setProjectStatusNotEqual(Constant.PROJECT_STATUS_COMPLETED);
            criteria.setIdInList(new ArrayList<Long>(projectIds));
        } else {
            // 根据用户ID查询负责的项目ID
            List<Project> projectIdList = projectRepository.findAll();
            List<Long> projectIds = new ArrayList<>();
            for (Project project : projectIdList) {
                projectIds.add(project.getId());
            }
            criteria.setApproveStatus(Constant.APPROVE_STATUS_ACKNOWLEDGED);
            criteria.setProjectStatusNotEqual(Constant.PROJECT_STATUS_COMPLETED);
            criteria.setIdInList(projectIds);
        }
        // 根据用户ID查询负责的项目ID
        List<Long> projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId());
        Set<Long> projectIds = Stream.of(projectList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toSet());
        criteria.setApproveStatus(Constant.APPROVE_STATUS_ACKNOWLEDGED);
        criteria.setProjectStatusNotEqual(Constant.PROJECT_STATUS_COMPLETED);
        criteria.setIdInList(new ArrayList<Long>(projectIds));
        return projectService.queryAll2(criteria);
    }
@@ -659,76 +679,105 @@
    }
    public List<TaskMongoDto> queryChildrenTaskAnyParent(TaskQueryCriteria criteria) {
        //看看当前这个用户是不是这个项目的项目负责人,如果是项目负责人的话显示全部的任务
        Long userId = SecurityUtils.getCurrentUserId();
        List<Long> idByLiableUserId = projectRepository.findIdByLiableUserId(userId);
        for (Long aLong : idByLiableUserId) {
            if (criteria.getProjectId().equals(aLong)) {
                Criteria criteriaAll = new Criteria();
                criteriaAll = criteriaAll.and("projectId").is(criteria.getProjectId());
                Query query = new Query(criteriaAll);
                List<TaskMongo> taskMongos = mongoTemplate.find(query, TaskMongo.class);
                List<TaskMongoDto> taskMongoDtoList = new ArrayList<TaskMongoDto>();
                for (TaskMongo taskMongo : taskMongos) {
                    TaskMongoDto taskMongoDto = new TaskMongoDto();
        // 获取登录用户角色等级
        List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
        // 登录用户最大角色等级
        int min = Collections.min(levels);
                    taskMongoDto.setId(taskMongo.getId());
                    taskMongoDto.setName(taskMongo.getName());
                    taskMongoDto.setProjectId(taskMongo.getProjectId());
                    taskMongoDto.setPlanStartTime(taskMongo.getPlanStartTime());
                    taskMongoDto.setPlanEndTime(taskMongo.getPlanEndTime());
        if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) {
            //看看当前这个用户是不是这个项目的项目负责人,如果是项目负责人的话显示全部的任务
            Long userId = SecurityUtils.getCurrentUserId();
            List<Long> idByLiableUserId = projectRepository.findIdByLiableUserId(userId);
            for (Long aLong : idByLiableUserId) {
                if (criteria.getProjectId().equals(aLong)) {
                    Criteria criteriaAll = new Criteria();
                    criteriaAll = criteriaAll.and("projectId").is(criteria.getProjectId());
                    Query query = new Query(criteriaAll);
                    List<TaskMongo> taskMongos = mongoTemplate.find(query, TaskMongo.class);
                    Query childrenQuery = new Query(Criteria.where("parent").is(taskMongo));
                    long children = mongoTemplate.count(childrenQuery, TaskMongo.class);
                    taskMongoDto.setLeaf(children == 0);
                    List<TaskMongoDto> taskMongoDtoList = new ArrayList<TaskMongoDto>();
                    for (TaskMongo taskMongo : taskMongos) {
                        TaskMongoDto taskMongoDto = new TaskMongoDto();
                    //如果时项目负责人有最高权限
                    taskMongoDto.setFlag(true);
                        taskMongoDto.setId(taskMongo.getId());
                        taskMongoDto.setName(taskMongo.getName());
                        taskMongoDto.setProjectId(taskMongo.getProjectId());
                        taskMongoDto.setPlanStartTime(taskMongo.getPlanStartTime());
                        taskMongoDto.setPlanEndTime(taskMongo.getPlanEndTime());
                    taskMongoDtoList.add(taskMongoDto);
                        Query childrenQuery = new Query(Criteria.where("parent").is(taskMongo));
                        long children = mongoTemplate.count(childrenQuery, TaskMongo.class);
                        taskMongoDto.setLeaf(children == 0);
                        //如果时项目负责人有最高权限
                        taskMongoDto.setFlag(true);
                        taskMongoDtoList.add(taskMongoDto);
                    }
                    return taskMongoDtoList;
                }
                return taskMongoDtoList;
            }
        }
        Criteria criteriaMongo = new Criteria();
        criteriaMongo = criteriaMongo.and("containUserList").is(userId);
        if (criteria.getProjectId() != null) {
            criteriaMongo = criteriaMongo.and("projectId").is(criteria.getProjectId());
        }
        if (criteria.getName() != null) {
            criteriaMongo = criteriaMongo.and("name").regex(Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE));
        }
        Query query = new Query(criteriaMongo);
        Long totalCount = mongoTemplate.count(query, TaskMongo.class);
        if (totalCount == 0) {
            return Collections.emptyList();
        }
        //获取包含成员
        List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
            Criteria criteriaMongo = new Criteria();
            criteriaMongo = criteriaMongo.and("containUserList").is(userId);
            if (criteria.getProjectId() != null) {
                criteriaMongo = criteriaMongo.and("projectId").is(criteria.getProjectId());
            }
            if (criteria.getName() != null) {
                criteriaMongo = criteriaMongo.and("name").regex(Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE));
            }
            Query query = new Query(criteriaMongo);
            Long totalCount = mongoTemplate.count(query, TaskMongo.class);
            if (totalCount == 0) {
                return Collections.emptyList();
            }
            //获取包含成员
            List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class);
        List<TaskMongoDto> taskMongoDtoList = new ArrayList<TaskMongoDto>();
        for (TaskMongo taskMongo : taskMongoList) {
            List<TaskMongoDto> taskMongoDtoList = new ArrayList<TaskMongoDto>();
            for (TaskMongo taskMongo : taskMongoList) {
            TaskMongoDto taskMongoDto = new TaskMongoDto();
                TaskMongoDto taskMongoDto = new TaskMongoDto();
            taskMongoDto.setId(taskMongo.getId());
            taskMongoDto.setName(taskMongo.getName());
            taskMongoDto.setProjectId(taskMongo.getProjectId());
            taskMongoDto.setPlanStartTime(taskMongo.getPlanStartTime());
            taskMongoDto.setPlanEndTime(taskMongo.getPlanEndTime());
                taskMongoDto.setId(taskMongo.getId());
                taskMongoDto.setName(taskMongo.getName());
                taskMongoDto.setProjectId(taskMongo.getProjectId());
                taskMongoDto.setPlanStartTime(taskMongo.getPlanStartTime());
                taskMongoDto.setPlanEndTime(taskMongo.getPlanEndTime());
            Query childrenQuery = new Query(Criteria.where("parent").is(taskMongo));
            long children = mongoTemplate.count(childrenQuery, TaskMongo.class);
            taskMongoDto.setLeaf(children == 0);
                Query childrenQuery = new Query(Criteria.where("parent").is(taskMongo));
                long children = mongoTemplate.count(childrenQuery, TaskMongo.class);
                taskMongoDto.setLeaf(children == 0);
            if(taskMongo.getUserIdList().contains(SecurityUtils.getCurrentUserId())){
                //如果当前用户是某个任务的任务负责人的话,也可拥有全部的分配任务的权限
                if (taskMongo.getUserIdList().contains(SecurityUtils.getCurrentUserId())) {
                    //如果当前用户是某个任务的任务负责人的话,也可拥有全部的分配任务的权限
                    taskMongoDto.setFlag(true);
                }
                taskMongoDtoList.add(taskMongoDto);
            }
            return taskMongoDtoList;
        } else {
            List<TaskMongoDto> taskMongoDtoList = new ArrayList<>();
            //获取所有的任务
            List<TaskMongo> all = mongoTemplate.find(Query.query(new Criteria("projectId").is(criteria.getProjectId())),TaskMongo.class);
            for (TaskMongo taskMongo : all) {
                TaskMongoDto taskMongoDto = new TaskMongoDto();
                taskMongoDto.setId(taskMongo.getId());
                taskMongoDto.setName(taskMongo.getName());
                taskMongoDto.setProjectId(taskMongo.getProjectId());
                taskMongoDto.setPlanStartTime(taskMongo.getPlanStartTime());
                taskMongoDto.setPlanEndTime(taskMongo.getPlanEndTime());
                Query childrenQuery = new Query(Criteria.where("parent").is(taskMongo));
                long children = mongoTemplate.count(childrenQuery, TaskMongo.class);
                taskMongoDto.setLeaf(children == 0);
                taskMongoDto.setFlag(true);
                taskMongoDtoList.add(taskMongoDto);
            }
            taskMongoDtoList.add(taskMongoDto);
            return taskMongoDtoList;
        }
        return taskMongoDtoList;
    }
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskUserServiceImpl.java
@@ -16,6 +16,7 @@
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;
@@ -29,6 +30,7 @@
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;
@@ -79,6 +81,7 @@
    private final TaskRepository taskRepository;
    private final UserService userService;
    private final MongoTemplate mongoTemplate;
    private final UserLevelWageRepository userLevelWageRepository;
    @Override
    public TaskUserTotalMongoDto sumTotalByTask(String taskId) {
@@ -97,6 +100,7 @@
        AggregationResults<TaskUserTotalDetailMongoDto> taskUserMongoList = mongoTemplate.aggregate(customerAgg, TaskUserMongo.class, TaskUserTotalDetailMongoDto.class);
        result.setDetails(taskUserMongoList.getMappedResults());
        return result;
    }
@@ -109,12 +113,12 @@
        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);
        }
@@ -130,11 +134,8 @@
        } 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());
@@ -152,7 +153,7 @@
            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());
@@ -167,8 +168,32 @@
            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);
        }
@@ -257,6 +282,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public TaskUserMongo create(TaskUserMongo resources) throws Exception {
//        // 查询字典
//        DictDetail dictDetail =  dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, resources.getTaskStatus());
//        //发送钉钉给审批人
@@ -268,6 +294,14 @@
//                "  \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);
    }
@@ -296,9 +330,9 @@
//            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);
            }
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/repository/CmnLevelRankRepository.java
@@ -18,6 +18,9 @@
import me.zhengjie.modules.treatment.domain.CmnLevelRank;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @website https://eladmin.vip
@@ -27,4 +30,7 @@
public interface CmnLevelRankRepository extends JpaRepository<CmnLevelRank, Long>, JpaSpecificationExecutor<CmnLevelRank> {
    void deleteByLevelId(Long levelId);
    @Query(value = "select * from new_cmn_level_rank where level_id = ?1",nativeQuery = true)
    List<CmnLevelRank> findByLevelId(Long levelId);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/repository/UserLevelWageRepository.java
@@ -18,6 +18,7 @@
import me.zhengjie.modules.treatment.domain.UserLevelWage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
/**
* @website https://eladmin.vip
@@ -27,4 +28,9 @@
public interface UserLevelWageRepository extends JpaRepository<UserLevelWage, Long>, JpaSpecificationExecutor<UserLevelWage> {
    UserLevelWage findByUserIdAndYearMonth(Long userId, String yearMonth);
    @Query(value = "(select performance_coefficient from new_user_level_wage where user_id = ?1) order by `year_month` DESC",nativeQuery = true)
    Double findPerformanceCoefficientByUserId(Long userId);
}