ty
11 months ago
17 changed files with 311 additions and 14 deletions
@ -0,0 +1,102 @@ |
|||||||
|
package com.hnac.hzims.safeproduct.scheduled; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.hnac.hzims.common.constant.CommonConstant; |
||||||
|
import com.hnac.hzims.message.MessageConstants; |
||||||
|
import com.hnac.hzims.message.dto.BusinessMessageDTO; |
||||||
|
import com.hnac.hzims.message.dto.SmsImmediatelyPushDTO; |
||||||
|
import com.hnac.hzims.message.fegin.IMessageClient; |
||||||
|
import com.hnac.hzims.safeproduct.constants.RedisConstants; |
||||||
|
import com.hnac.hzims.safeproduct.entity.SafetyToolEntity; |
||||||
|
import com.hnac.hzims.safeproduct.service.ISafetyToolService; |
||||||
|
import com.xxl.job.core.biz.model.ReturnT; |
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob; |
||||||
|
import com.xxl.job.core.log.XxlJobLogger; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.DateUtil; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
@Component |
||||||
|
@Slf4j |
||||||
|
@RequiredArgsConstructor |
||||||
|
public class ToolsPushMsgSchedule { |
||||||
|
|
||||||
|
private final ISafetyToolService toolService; |
||||||
|
private final RedisTemplate redisTemplate; |
||||||
|
private final IMessageClient messageClient; |
||||||
|
|
||||||
|
@Value("${hzims.safeProduct.safeTool.sms-code}") |
||||||
|
private String smsCode; |
||||||
|
|
||||||
|
@XxlJob("toolsPushMessage") |
||||||
|
public ReturnT execute(String params) { |
||||||
|
Set<String> keys = redisTemplate.keys(RedisConstants.TOOLS_REMIND_MSG + "*"); |
||||||
|
XxlJobLogger.log("===========安全工器具key值为:"+ JSON.toJSONString(keys) +"==========="); |
||||||
|
keys.forEach(key -> { |
||||||
|
Set<SafetyToolEntity> toolList = redisTemplate.opsForZSet().reverseRangeByScore(key, 0, new Date().getTime()); |
||||||
|
toolList.forEach(tool -> { |
||||||
|
SafetyToolEntity safetyTool = toolService.getById(tool.getId()); |
||||||
|
// 安全工器具推送消息
|
||||||
|
this.pushMessageByTool(safetyTool); |
||||||
|
}); |
||||||
|
redisTemplate.opsForZSet().remove(key,toolList.toArray()); |
||||||
|
}); |
||||||
|
return ReturnT.SUCCESS; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 推送安全工器具消息 |
||||||
|
* @param safetyTool 安全工器具实体类 |
||||||
|
*/ |
||||||
|
private void pushMessageByTool(SafetyToolEntity safetyTool) { |
||||||
|
String alert = "工器具检查提醒:工器具("+safetyTool.getToolName()+")将于"+ DateUtil.format(safetyTool.getNextCheckTime(),DateUtil.PATTERN_DATE)+"到检查时间,请安排时间复核!"; |
||||||
|
// APP推送
|
||||||
|
if(SafeToolTypePushUserTask.JG_PUSH == safetyTool.getSendType()) { |
||||||
|
BusinessMessageDTO request = new BusinessMessageDTO(); |
||||||
|
request.setTenantId(CommonConstant.TENANT_ID); |
||||||
|
request.setDeptId(safetyTool.getCreateDept()); |
||||||
|
request.setBusinessKey("安全工器具提醒"); |
||||||
|
request.setBusinessClassify(MessageConstants.BusinessClassifyEnum.SAFE_PRODUCT.getKey()); |
||||||
|
request.setTaskId(safetyTool.getId()); |
||||||
|
request.setContent(alert); |
||||||
|
request.setSubject("安全工器具复核时间到期提醒"); |
||||||
|
request.setUserIds(safetyTool.getNoticeUsers()); |
||||||
|
request.setCreateUser(safetyTool.getCreateUser()); |
||||||
|
R<Boolean> messageResult = messageClient.sendAppAndWsMsgByUsers(request); |
||||||
|
if(!messageResult.isSuccess()) { |
||||||
|
XxlJobLogger.log(safetyTool.getToolCode() + "推送消息失败!"); |
||||||
|
} |
||||||
|
} |
||||||
|
// 短信推送
|
||||||
|
else if(SafeToolTypePushUserTask.APP_PUSH == safetyTool.getSendType()) { |
||||||
|
SmsImmediatelyPushDTO smsPush = SmsImmediatelyPushDTO.builder() |
||||||
|
.deptId(safetyTool.getCreateDept()) |
||||||
|
.taskId(safetyTool.getId()) |
||||||
|
.businessKey("安全工器具提醒") |
||||||
|
.businessClassify(MessageConstants.BusinessClassifyEnum.SAFE_PRODUCT.getKey()) |
||||||
|
.content(alert) |
||||||
|
.subject("安全工器具复核时间到期提醒") |
||||||
|
.pusher(safetyTool.getNoticeUsers()) |
||||||
|
.createUser(safetyTool.getCreateUser()) |
||||||
|
.tenantId(CommonConstant.TENANT_ID) |
||||||
|
.resourceCode(smsCode) |
||||||
|
.params(new HashMap<String,String>(){{ |
||||||
|
put("one",safetyTool.getToolName()); |
||||||
|
put("two",DateUtil.format(safetyTool.getNextCheckTime(),DateUtil.PATTERN_DATE)); |
||||||
|
}}).build(); |
||||||
|
R<Boolean> messageResult = messageClient.sendSmsImmediatelyMsg(smsPush); |
||||||
|
if(!messageResult.isSuccess()) { |
||||||
|
XxlJobLogger.log(safetyTool.getToolCode() + "推送消息失败!"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue