package com.wtkj.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.wtkj.entity.IndexMessage; import com.wtkj.entity.ProjectAuth; import com.wtkj.entity.Task; import com.wtkj.service.*; import com.wtkj.vo.IndexProjectAndTaskSummaryVO; import com.wtkj.vo.MyIndexTaskStatistics; import com.wtkj.vo.ScheduleUserVO; import lombok.AllArgsConstructor; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.*; import java.util.stream.Collectors; import static com.wtkj.config.MagicValue.*; /** * @author Blizzard * @create at 2023-09-20 14:51 * @describe */ @Service @AllArgsConstructor public class IndexServiceImpl implements IIndexService { private final ITaskService taskService; private final IProjectService projectService; private final IIndexMessageService indexMessageService; private final IUserClient userClient; private final IProjectAuthService projectAuthService; @Override public IndexProjectAndTaskSummaryVO projectAndTaskSummary(Long topDept) { IndexProjectAndTaskSummaryVO vo = new IndexProjectAndTaskSummaryVO(); Long userId = AuthUtil.getUserId(); //1.全部项目数量 ---> 权限表下 topDept是 参数topDept List auths = projectAuthService.getByDeptAndUser(topDept, null, null); if (!CollectionUtils.isEmpty(auths)) { Set collect = auths.stream().map(ProjectAuth::getProjectId).collect(Collectors.toSet()); vo.setProjectCount(collect.size()); } //2.我参与的项目 ---> 权限表下user_id List userAuth = projectAuthService.getByDeptAndUser(null, null, userId); if (!CollectionUtils.isEmpty(userAuth)) { Set collect = userAuth.stream().map(ProjectAuth::getProjectId).collect(Collectors.toSet()); vo.setMyProjectCount(collect.size()); } // 3. 机构下的任务总数 -->执行单位是topdept List tasks = taskService.getByExecute(topDept, null); if (!CollectionUtils.isEmpty(tasks)) { vo.setTaskCount(tasks.size()); } //4.我的任务 ---> 执行人是userid List byExecute = taskService.getByExecute(null, String.valueOf(userId)); if (!CollectionUtils.isEmpty(byExecute)) { vo.setMyTaskCount(byExecute.size()); } //5.我的今日任务数 ---> 截至日期是今天且未完成的和未取消的任务 String now = DateUtil.format(new Date(), "yyyy-MM-dd"); List todayTask = taskService.todayTodo(userId, now); if (!CollectionUtils.isEmpty(todayTask)) { vo.setTodayTask(todayTask.size()); } return vo; } @Override public IPage todoList(Integer isRead, IPage page) { LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(IndexMessage::getCategory, 1); lqw.eq(IndexMessage::getToUser, AuthUtil.getUserId()); if (isRead == 1) { lqw.eq(IndexMessage::getIsRead, 1); lqw.orderByDesc(IndexMessage::getCreateTime); } else if (isRead == 2) { lqw.eq(IndexMessage::getIsRead, 0); lqw.orderByDesc(IndexMessage::getCreateTime); } else if (isRead == 0) { lqw.orderByAsc(IndexMessage::getIsRead); lqw.orderByDesc(IndexMessage::getCreateTime); } return indexMessageService.page(page, lqw); } @Override public Object studyList(IPage page) { return null; } @Override public IndexMessage messageDetail(Long id) { IndexMessage byId = indexMessageService.getById(id); if (byId != null) { byId.setIsRead(1); indexMessageService.updateById(byId); } return byId; } @Override public List schedule(Long topDept, String date) { List result = new ArrayList<>(); Set res = new HashSet<>(); String roleName = AuthUtil.getUserRole(); Long userId = AuthUtil.getUserId(); String deptId = AuthUtil.getDeptId(); if (roleName != null) { if (roleName.contains(STAFF_ADMIN)) { //如果是机构管理员 ---> 可以查看机构下的待完成的和逾期的任务 List list = taskService.getByDeptAndDate(topDept, null, null, date); if (!CollectionUtils.isEmpty(list)) { for (Task task : list) { String executeUser = task.getExecuteUser(); if (StringUtil.isNotBlank(executeUser)) { List userIds = Func.toLongList(executeUser); res.addAll(userIds); } } } } else if (roleName.contains(STAFF_SECOND_ADMIN)) { List list = taskService.getByDeptAndDate(null, Long.valueOf(deptId), null, null); if (!CollectionUtils.isEmpty(list)){ for (Task task : list) { String executeUser = task.getExecuteUser(); if (StringUtil.isNotBlank(executeUser)) { List userIds = Func.toLongList(executeUser); res.addAll(userIds); } } } } else if (roleName.contains(STAFF_USER)) { res.add(userId); } } if (!CollectionUtils.isEmpty(res)) { for (Long id : res) { R rpc = userClient.userInfoById(id); if (rpc.isSuccess()) { ScheduleUserVO vo = new ScheduleUserVO(); vo.setUser(rpc.getData()); List tasks = taskService.todayTodo(userId, date); if (!CollectionUtils.isEmpty(tasks)) { vo.setTodayTodo(tasks.size()); } List tasks1 = taskService.todayExpire(userId, date); if (!CollectionUtils.isEmpty(tasks1)) { vo.setTodayExpire(tasks1.size()); } result.add(vo); } } } return result; } @Override public List scheduleExpand(Long userId, String date) { return taskService.getTodoAndExpireByUserId(userId, date); } @Override public List> mapStatistics(Long topDept, String date) { List> res = new ArrayList<>(); //1.机构下有今日待完成的任务的用户 List tasks = taskService.getTodayTodoByOrgDeptId(topDept, date); Set userIds = new HashSet<>(); if (!CollectionUtils.isEmpty(tasks)) { for (Task task : tasks) { String executeUser = task.getExecuteUser(); if (StringUtil.isNotBlank(executeUser)) { List ids = Func.toLongList(executeUser); userIds.addAll(ids); } } } if (!CollectionUtils.isEmpty(userIds)) { userIds.forEach(userId -> { Map map = new HashMap<>(); R userR = userClient.userInfoById(userId); if (userR.isSuccess()) { List tasks1 = taskService.todayTodo(userId, date); if (!CollectionUtils.isEmpty(tasks1)) { map.put(userR.getData().getName(), tasks1.size()); res.add(map); } } }); } return res; } @Override public MyIndexTaskStatistics myStatistics(String date) { Long userId = AuthUtil.getUserId(); MyIndexTaskStatistics statistics = new MyIndexTaskStatistics(); //1.任务总数 List tasks = taskService.listByUser(userId, null, null); if (!CollectionUtils.isEmpty(tasks)) { statistics.setAll(tasks.size()); //2.当日待完成 即今日逾期 List todo = taskService.todayTodo(userId, date); if (!CollectionUtils.isEmpty(todo)) { statistics.setTodayTodo(todo.size()); } //3.逾期任务数 List expires = taskService.todayExpire(userId, date); if (!CollectionUtils.isEmpty(expires)) { statistics.setExpire(expires.size()); } } return statistics; } }