Blame view

parking-module-park/src/main/java/com/zteits/park/configuration/schedule/GetExceptionMsgSchedule.java 5.05 KB
9af4a544   王彪总   新项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  //package com.zteits.park.configuration.schedule;
  //
  //import java.util.List;
  //import java.util.concurrent.TimeUnit;
  //
  //import org.apache.curator.framework.CuratorFramework;
  //import org.apache.curator.framework.recipes.locks.InterProcessMutex;
  //import org.slf4j.Logger;
  //import org.slf4j.LoggerFactory;
  //import org.springframework.beans.factory.annotation.Autowired;
  //import org.springframework.context.annotation.Conditional;
  //import org.springframework.scheduling.annotation.Scheduled;
  //import org.springframework.stereotype.Component;
  //
  //import org.apache.commons.collections4.CollectionUtils;
  //import org.apache.commons.lang3.StringUtils;
  //import com.clouds.common.cache.sys.SysCodeValueCacheUtil;
  //import com.clouds.common.constants.CodeValKindEnum;
  //import com.clouds.common.constants.ParkConstant;
  //import com.zteits.park.configuration.mail.MailService;
  //import com.zteits.park.configuration.zookeeper.ZkClientFactory;
  //import com.zteits.park.constant.ZKConstant;
  //import com.zteits.park.domain.TpPExceptionLogExample;
  //import com.zteits.park.domain.TpPExceptionLogWithBLOBs;
  //import com.zteits.park.mapper.TpPExceptionLogMapper;
  //
  ///**
  // * 显示异常信息 <br/>
  // * 
  // * Copyright: Copyright (c) 2017  zteits
  // * 
  // * @ClassName: ParkingLotHeatMapHourJob.java
  // * @Description: 
  // * @version: v1.0.0
  // * @author: wangfs
  // * @date: 2017年7月10日   下午5:24:36 
  // * Modification History:
  // * Date             Author          Version            Description
  // *---------------------------------------------------------*
  // * 2017年7月10日      wangfs           v1.0.0               创建
  // */
  //@Conditional(GetExceptionMsgCondition.class)
  //@Component("com.zteits.park.configuration.schedule.GetExceptionMsgSchedule")
  //public class GetExceptionMsgSchedule{
  //	private static final Logger logger = LoggerFactory.getLogger(GetExceptionMsgSchedule.class);
  //	
  //	@Autowired
  //	private TpPExceptionLogMapper exceptionLogMapper;
  //	@Autowired
  //	private MailService mailService;
  //	@Autowired
  //	private ZkClientFactory zkClientFactory;
  //	/**
  //	 * 30分钟一次
  //	 * @throws Exception
  //	 * 2017年9月15日 zhaowg
  //	 */
  //	@Scheduled(cron="0 30 * * * ?")
  //	public void execute() throws Exception {
  //		logger.info("============================开始查询异常表==============================");
  //		CuratorFramework client = zkClientFactory.getZKClient();
  //		InterProcessMutex lock = new InterProcessMutex(client, ZKConstant.GETEXCEPTION_LOCK_PATH);
  //		try {
  //        	if (lock.acquire(10 * 1000, TimeUnit.SECONDS)) {
  //        		logger.info("============================获取锁成功,开始查询异常表==============================");
  //        		this.getExceptionMsg();
  //            }else{
  //            	logger.info("============================获取锁失败,不查询异常表==============================");
  //            }
  //        } catch (Exception e) {
  //            e.printStackTrace();
  //        } finally {
  //            try {
  //                lock.release();
  //            } catch (Exception e) {
  //                e.printStackTrace();
  //            }
  //        }
  //		logger.info("============================查询异常表结束==============================");
  //	}
  //	
  //	private void getExceptionMsg() {
  //		//获取要发送的邮箱
  //		String mailAddrs = SysCodeValueCacheUtil.queryCodeValue(CodeValKindEnum.PARK_SEND_MAIL_ADDRS);
  //		if(StringUtils.isBlank(mailAddrs)){
  //			logger.info("查询异常表,邮件地址为空,不发送邮件");
  //			return;
  //		}
  //		
  //		TpPExceptionLogExample example = new TpPExceptionLogExample();
  //		//example.createCriteria()
  //		//.andDealStatusEqualTo(ParkConstant.TpPException.NO_DEALED);
  //		example.setOrderByClause("create_time desc");
  //		List<TpPExceptionLogWithBLOBs> list = exceptionLogMapper.selectByExampleWithBLOBs(example );
  //		if(CollectionUtils.isEmpty(list)){
  //			logger.info("异常表数据为空,直接返回成功");
  //			return;
  //		}
  //		StringBuilder content = new StringBuilder();
  //		content.append("发现异常信息条数为:"+list.size()+",请及时查看,具体详细信息请到PARK->Tp_p_Exception表中查看。");
  //		content.append("最新的两条堆栈信息为:");
  //		TpPExceptionLogWithBLOBs e;
  //		//最多只发送最新的前2条异常信息,防止内容过多
  //		for (int i=0;i<(2>list.size()?list.size():2);i++) {
  //			e = list.get(i);
  //			content.append("业务描述:"+e.getBusiDesc());
  //			content.append("堆栈信息:"+e.getErrorMsg());
  //			//更新该异常信息状态为-未处理-已告警
  //			TpPExceptionLogWithBLOBs record = new TpPExceptionLogWithBLOBs();
  //			record.setId(e.getId());
  //			//record.setDealStatus(ParkConstant.TpPException.ALARM);
  //			exceptionLogMapper.updateByPrimaryKeySelective(record);
  //		}
  //		
  //		String[] address = mailAddrs.split(",");
  //		for (String addr : address) {
  //			//暂时没有开启线程,因为该任务30分钟执行一次,不存在高并发阻塞等待
  //			//TODO 后期修改为MQ
  //			mailService.sendSimpleMail(addr, "扫描PARK域异常表获取的异常信息", content.toString());
  //		}
  //	}
  //}