Commit ac6a5f66 authored by lcl's avatar lcl

u

parent 7d391e12
package com.dsk.web.schedule; package com.dsk.web.schedule;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dsk.common.constant.PushConstants;
import com.dsk.common.utils.DateUtils;
import com.dsk.system.domain.SysConfig;
import com.dsk.system.domain.SysPush;
import com.dsk.system.domain.SysStatutoryHoliday;
import com.dsk.system.mapper.SysStatutoryHolidayMapper;
import com.dsk.system.service.ISysConfigService;
import com.dsk.system.service.ISysPushService; import com.dsk.system.service.ISysPushService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* 推送相关定时任务 * 推送相关定时任务
...@@ -21,13 +39,57 @@ public class PushTask { ...@@ -21,13 +39,57 @@ public class PushTask {
@Autowired @Autowired
private ISysPushService pushService; private ISysPushService pushService;
@Autowired
private ISysConfigService configService;
@Resource
private SysStatutoryHolidayMapper statutoryHolidayMapper;
/** /**
* 供应商不良推送(每分钟) * 供应商不良推送(每分钟)
*/ */
@Scheduled(cron = "0 * * * * ? ") // @Scheduled(cron = "0 * * * * ? ")
public void customerBadness(){ public void customerBadness() {
//1.是否推送时间段(日期、时间) //1.是否推送时间段(日期、时间)
if (!isPush()) return;
//2.推送数据(当前时段是否存在数据) //2.推送数据(当前时段是否存在数据)
//3.推送人员 //3.推送人员
List<SysPush> list = pushService.list(Wrappers.<SysPush>lambdaQuery().eq(SysPush::getStatus, 0));
if (CollectionUtils.isNotEmpty(list)) {
list.parallelStream().forEach(item -> {
Map<String, Object> param = new HashMap<>();
param.put("name", item.getName());
});
}
}
//是否推送
private boolean isPush() {
//推送类型
SysConfig type = configService.selectConfigByKey(PushConstants.CUSTOMEER_BADNESS_TYPE_KEY);
if (ObjectUtils.isEmpty(type)) return false;
if ("1".equals(type.getConfigValue()) && !isWorkingDay()) return false;
//推送时段
SysConfig frame = configService.selectConfigByKey(PushConstants.CUSTOMEER_BADNESS_FRAME_KEY);
return !ObjectUtils.isEmpty(frame) && isPushTime(frame.getConfigValue());
}
//判断当前是否工作日
private boolean isWorkingDay() {
LocalDate date = LocalDate.now();
SysStatutoryHoliday today = statutoryHolidayMapper.selectOne(Wrappers.<SysStatutoryHoliday>lambdaQuery()
.eq(SysStatutoryHoliday::getDate, date));
if (!ObjectUtils.isEmpty(today)) return today.getIsHoliday() == 0;
return date.getDayOfWeek() != DayOfWeek.SATURDAY && date.getDayOfWeek() != DayOfWeek.SUNDAY;
}
//判断是否在当前时段推送
private boolean isPushTime(String timeFrame) {
String date = LocalDate.now().toString();
String[] split = timeFrame.split("-");
Date currentTime = new Date();
return currentTime.after(DateUtils.parseDate(date + " " + split[0])) && currentTime.before(DateUtils.parseDate(date + " " + split[1]));
} }
} }
...@@ -9,5 +9,13 @@ public interface PushConstants { ...@@ -9,5 +9,13 @@ public interface PushConstants {
* 供应商不良推送短信模板 * 供应商不良推送短信模板
*/ */
String CUSTOMEER_BADNESS_SMS = "SMS_464311026"; String CUSTOMEER_BADNESS_SMS = "SMS_464311026";
/**
* 供应商不良推送类型
*/
String CUSTOMEER_BADNESS_TYPE_KEY = "customer-badness-date-type";
/**
* 供应商不良推送时段
*/
String CUSTOMEER_BADNESS_FRAME_KEY = "customer-badness-time-frame";
} }
package com.dsk.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dsk.system.domain.SysStatutoryHoliday;
public interface SysStatutoryHolidayMapper extends BaseMapper<SysStatutoryHoliday> {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment