|
@@ -0,0 +1,183 @@
|
|
|
+package org.springblade.control.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.commons.lang.time.DateUtils;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.control.dto.LogHistoryInfoDTO;
|
|
|
+import org.springblade.control.entity.LogHistoryInfo;
|
|
|
+import org.springblade.control.mapper.LogHistoryMapper;
|
|
|
+import org.springblade.control.service.LogHistoryService;
|
|
|
+import org.springblade.control.vo.LogHistoryInfoReadVO;
|
|
|
+import org.springblade.control.vo.LogHistoryInfoVO;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.DateUtil;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class LogHistoryServiceImpl extends BaseServiceImpl<LogHistoryMapper, LogHistoryInfo> implements LogHistoryService {
|
|
|
+
|
|
|
+ private final IUserClient iUserClient;
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, List<LogHistoryInfoVO>> logList(LogHistoryInfoDTO dto) {
|
|
|
+ LambdaQueryWrapper<LogHistoryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getOrgDept())) {
|
|
|
+ queryWrapper.eq(LogHistoryInfo::getOrgDept, dto.getOrgDept());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getUserId())) {
|
|
|
+ queryWrapper.eq(LogHistoryInfo::getUserId, dto.getUserId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(dto.getStartTime()) && StringUtils.isNotEmpty(dto.getEndTime())) {
|
|
|
+ String endTime = dto.getEndTime();
|
|
|
+ endTime = DateUtil.format(DateUtils.addDays(DateUtil.parse(endTime, "yyyy-MM-dd"), 1), "yyyy-MM-dd");
|
|
|
+ queryWrapper.between(LogHistoryInfo::getCreateTime, dto.getStartTime(), endTime);
|
|
|
+ } else {
|
|
|
+ //默认查询7天内日志
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate tomorrow = today.plusDays(1);
|
|
|
+ LocalDate sevenDaysAgo = today.minusDays(6);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String todayStr = tomorrow.format(formatter);
|
|
|
+ String sevenDaysAgoStr = sevenDaysAgo.format(formatter);
|
|
|
+ queryWrapper.between(LogHistoryInfo::getCreateTime, sevenDaysAgoStr, todayStr);
|
|
|
+ }
|
|
|
+ queryWrapper.orderByDesc(true, LogHistoryInfo::getCreateTime);
|
|
|
+ List<LogHistoryInfo> logHistoryInfos = baseMapper.selectList(queryWrapper);
|
|
|
+ List<LogHistoryInfoVO> voList = BeanUtil.copyProperties(logHistoryInfos, LogHistoryInfoVO.class);
|
|
|
+ List<Long> logIds = voList.stream().map(LogHistoryInfo::getId).collect(Collectors.toList());
|
|
|
+ if (logIds.size() > 0) {
|
|
|
+ //用户信息
|
|
|
+ List<User> userList = iUserClient.selectUserAll();
|
|
|
+ Map<Long, User> userMap = new HashMap<>();
|
|
|
+ for (User user : userList) {
|
|
|
+ userMap.put(user.getId(), user);
|
|
|
+ }
|
|
|
+ //7天内已读日志记录信息
|
|
|
+ List<LogHistoryInfoReadVO> infoReadVOS = jdbcTemplate.query("select * from c_log_history_read_record where log_id in(" + StringUtils.join(logIds, ",") + ")", new BeanPropertyRowMapper<>(LogHistoryInfoReadVO.class));
|
|
|
+ Map<String, LogHistoryInfoReadVO> readMap = new HashMap<>();
|
|
|
+ for (LogHistoryInfoReadVO readVO : infoReadVOS) {
|
|
|
+ readMap.put(readVO.getUserId() + readVO.getLogId() + "", readVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (LogHistoryInfoVO vo : voList) {
|
|
|
+ User user = userMap.get(vo.getUserId());
|
|
|
+ if (user != null) {
|
|
|
+ vo.setLogTitle(user.getRealName() + "的日志");
|
|
|
+ vo.setHeadPicture(StringUtils.isNotEmpty(user.getAvatar()) ? user.getAvatar() : "");
|
|
|
+ }
|
|
|
+ String readIndex = SecureUtil.getUserId() + vo.getId() + "";
|
|
|
+ LogHistoryInfoReadVO readVO = readMap.get(readIndex);
|
|
|
+ if (readVO != null) {
|
|
|
+ vo.setIsRead(1);
|
|
|
+ } else {
|
|
|
+ vo.setIsRead(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return voList.stream()
|
|
|
+ .collect(Collectors.groupingBy(vo -> {
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.ofInstant(vo.getCreateTime().toInstant(), ZoneId.systemDefault());
|
|
|
+ return localDateTime.toLocalDate().toString();
|
|
|
+ }, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean logSubmit(LogHistoryInfoDTO dto) {
|
|
|
+ if (ObjectUtil.isEmpty(SecureUtil.getUserId())) {
|
|
|
+ throw new ServiceException("获取当前用户信息失败,请联系管理员");
|
|
|
+ }
|
|
|
+ dto.setUserId(SecureUtil.getUserId());
|
|
|
+ this.saveOrUpdate(dto);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getTaskIds())){
|
|
|
+ //新增日志与任务关系信息 TODO
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getExpenseReimbursementAmount())) {
|
|
|
+ //报销金额不为空,在财务报销里面新增一条草稿箱内容 TODO
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LogHistoryInfoVO logDetail(Long id) {
|
|
|
+ if (ObjectUtil.isEmpty(SecureUtil.getUserId())) {
|
|
|
+ throw new ServiceException("获取当前用户信息失败,请联系管理员");
|
|
|
+ }
|
|
|
+ LogHistoryInfo obj = baseMapper.selectById(id);
|
|
|
+ if (obj != null) {
|
|
|
+ LogHistoryInfoVO vo = BeanUtil.copyProperties(obj, LogHistoryInfoVO.class);
|
|
|
+ if (vo != null) {
|
|
|
+ User user = iUserClient.userInfoById(vo.getUserId()).getData();
|
|
|
+ if (user != null) {
|
|
|
+ vo.setLogTitle(user.getRealName() + "的日志");
|
|
|
+ vo.setHeadPicture(StringUtils.isNotEmpty(user.getAvatar()) ? user.getAvatar() : "");
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理当前用户查看当前日志信息为已读状态
|
|
|
+ Long row = jdbcTemplate.queryForObject("select count(1) from c_log_history_read_record where log_id = " + vo.getId() + " and user_id = " + SecureUtil.getUserId(), Long.class);
|
|
|
+ if (row == null || row == 0L) {
|
|
|
+ jdbcTemplate.execute("insert into c_log_history_read_record(id,log_id,user_id) values (" + SnowFlakeUtil.getId() + "," + vo.getId() + "," + SecureUtil.getUserId() + ")");
|
|
|
+ vo.setIsRead(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理当前日志taskList任务列表 TODO
|
|
|
+
|
|
|
+ //处理所有已读人信息
|
|
|
+ List<LogHistoryInfoReadVO> readUsersInfo = jdbcTemplate.query("select * from c_log_history_read_record where log_id = " + vo.getId(), new BeanPropertyRowMapper<>(LogHistoryInfoReadVO.class));
|
|
|
+ List<Long> userIds = readUsersInfo.stream().map(LogHistoryInfoReadVO::getUserId).distinct().collect(Collectors.toList());
|
|
|
+ if (userIds.size() > 0) {
|
|
|
+ List<User> readUserInfoList = iUserClient.userInfoByIds(userIds);
|
|
|
+ List<LogHistoryInfoVO.ReadUser> readUsers = new ArrayList<>();
|
|
|
+ for (User userRead : readUserInfoList) {
|
|
|
+ readUsers.add(new LogHistoryInfoVO.ReadUser(userRead.getAvatar(), userRead.getRealName()));
|
|
|
+ }
|
|
|
+ vo.setReadUsers(readUsers);
|
|
|
+ }
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean logTaskComplete(Long logId, Long taskId) {
|
|
|
+ if (ObjectUtil.isEmpty(logId)) {
|
|
|
+ throw new ServiceException("请先提交日志后,再变更任务");
|
|
|
+ }
|
|
|
+ //修改计划任务的状态为已完成,推送到对应的当前部门负责人审批(此处修改的任务状态为计划任务,新增推送的任务为审批任务) TODO
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object logTaskList(Long logId) {
|
|
|
+ if (ObjectUtil.isEmpty(SecureUtil.getUserId())) {
|
|
|
+ throw new ServiceException("获取当前用户信息失败,请联系管理员");
|
|
|
+ }
|
|
|
+ //获取当前用户当天的所有任务信息 TODO
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|