CheckSpecialEquipJob.java 2.7 KB
package com.skua.modules.safe.quartz;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.skua.core.context.SpringContextUtils;
import com.skua.core.util.DateUtils;
import com.skua.core.util.push.IPushService;
import com.skua.core.util.push.MessageEntity;
import com.skua.core.util.push.PushMessageFactory;
import org.apache.commons.lang.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;



import lombok.extern.slf4j.Slf4j;

/**
 * <pre>
 * 	水质监控报警、预警推送
 * </pre>
 * @author Li Yuanyuan
 * @version V0.1, 2021年8月12日 上午9:31:35
 */
@Slf4j
@Service
public class CheckSpecialEquipJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
    	System.out.println("********特种设备检测定时服务开启********");
    	//获取极光消息推送服务类
    	IPushService appPushService = PushMessageFactory.getPushService("JG");
    	
    	JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
    	String date = DateUtils.formatDate();
    	String sql = "select user_id,equip_name from equip_special_info_statistics where check_date='"+date+"'";
    	List<Map<String, Object>> list = masterDB.queryForList(sql);
    	for(Map<String, Object> map : list) {
    		String equipName = (String) map.get("equip_name");
    		String userIds = (String) map.get("user_id");
    		String[] userIdArray = userIds.split(",");
    		String inSql = "";
    		for(String userId : userIdArray) {
    			inSql = inSql +",'"+userId+"'";
    		}
    		if(!StringUtils.isEmpty(inSql)&&inSql.length()>0) {
    			inSql = inSql.substring(1);
    			//获取用户cid
    			String userSql = "select DISTINCT cid from sys_user where id in("+inSql+")";
    			List<Map<String, Object>> userList = masterDB.queryForList(userSql);
    			List<String> cidList = new ArrayList<String>();
    			for(Map<String, Object> userMap : userList) {
    				String cid = (String) userMap.get("cid");
    				if(!StringUtils.isEmpty(cid)) {
    					cidList.add(cid);
    				}
    			}
    			if(cidList.size()>0) {
    				MessageEntity messageEntity = new MessageEntity();
    				messageEntity.setMessageTitle("特种设备检测提醒");
    				messageEntity.setMessageBody("您好,今天是【"+equipName+"】的检测日期,请及时进行检测!");
    				messageEntity.setReceiveUserCid(cidList);
    				appPushService.pushMessage(messageEntity);
    			}
    		}
    	}
        System.out.println("********特种设备检测定时服务结束********");
    }
    
}