推送项目重构代码
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
package com.ruoyi.oa.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.oa.domain.OaReportSummary;
|
||||
import com.ruoyi.oa.im.ImSendService;
|
||||
import com.ruoyi.oa.mapper.OaReportSummaryMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 每日 18:00 扫描没报工的员工,通过 IM 推送提醒。
|
||||
*
|
||||
* @author wangyu
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DailyReportRemindScheduler {
|
||||
|
||||
/** Web 端跳转路径("我的报工") */
|
||||
private static final String WEB_ROUTE = "/hint/my";
|
||||
/** 手机端跳转路径(uniapp 报工页) */
|
||||
private static final String MOBILE_ROUTE = "/pages/workbench/reportWork/reportWork";
|
||||
|
||||
private final OaReportSummaryMapper summaryMapper;
|
||||
private final SysUserMapper userMapper;
|
||||
private final ImSendService imSendService;
|
||||
|
||||
/** 工作日 18:00 触发 */
|
||||
@Scheduled(cron = "0 0 18 * * MON-FRI")
|
||||
public void notifyMissingReporters() {
|
||||
LocalDate today = LocalDate.now();
|
||||
if (today.getDayOfWeek() == DayOfWeek.SATURDAY || today.getDayOfWeek() == DayOfWeek.SUNDAY) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 今天报过工的人(按 reporter 名字去重)
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0);
|
||||
c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0);
|
||||
Date start = c.getTime();
|
||||
c.add(Calendar.DAY_OF_MONTH, 1);
|
||||
Date end = c.getTime();
|
||||
|
||||
List<OaReportSummary> reportedToday = summaryMapper.selectList(
|
||||
Wrappers.<OaReportSummary>lambdaQuery()
|
||||
.ge(OaReportSummary::getReportDate, start)
|
||||
.lt(OaReportSummary::getReportDate, end)
|
||||
.eq(OaReportSummary::getDelFlag, 0L));
|
||||
Set<String> reportedReporters = new HashSet<>();
|
||||
for (OaReportSummary s : reportedToday) {
|
||||
if (s.getReporter() != null) reportedReporters.add(s.getReporter().trim());
|
||||
}
|
||||
|
||||
// 全部在职用户
|
||||
List<SysUser> users = userMapper.selectList(Wrappers.<SysUser>lambdaQuery()
|
||||
.eq(SysUser::getDelFlag, "0")
|
||||
.eq(SysUser::getStatus, "0"));
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
|
||||
String todayStr = sdf.format(new Date());
|
||||
int pushed = 0;
|
||||
for (SysUser u : users) {
|
||||
if (u.getUserId() == null) continue;
|
||||
String key = u.getNickName() != null ? u.getNickName() : u.getUserName();
|
||||
if (key != null && reportedReporters.contains(key.trim())) continue;
|
||||
|
||||
String title = "报工提醒";
|
||||
String desc = String.format("【%s】您今天(%s)还未提交日报,请尽快填写。点击立即报工。",
|
||||
u.getNickName() == null ? u.getUserName() : u.getNickName(), todayStr);
|
||||
|
||||
imSendService.sendToOaUser(u.getUserId(), title, desc,
|
||||
"report", System.currentTimeMillis(),
|
||||
WEB_ROUTE, MOBILE_ROUTE);
|
||||
pushed++;
|
||||
}
|
||||
log.info("[DailyReportRemind] 已推送 {} 人未报工提醒(总员工 {},今日已报工 {})",
|
||||
pushed, users.size(), reportedReporters.size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user