Blame view

parking-module-park/src/main/java/com/zteits/park/job/PDAHeartBeatJob.java 3.2 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
  package com.zteits.park.job;
  
  import org.apache.commons.collections4.CollectionUtils;
  import org.apache.commons.lang3.StringUtils;
  import com.xxl.job.core.biz.model.ReturnT;
  import com.xxl.job.core.context.XxlJobHelper;
  import com.xxl.job.core.handler.annotation.XxlJob;
  import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
  import com.zteits.park.constant.EqpConstant;
  import com.zteits.park.constant.ParkConstant;
  import com.zteits.park.domain.TpPPda;
  import com.zteits.park.domain.TpPPdaExample;
  import com.zteits.park.mapper.TpPPdaMapper;
  import com.zteits.park.service.employee.oper.EmployeeChargeOperInnerService;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Component;
  
  import java.util.Calendar;
  import java.util.Date;
  import java.util.List;
  
  /**
   * 修改PDA状态,在线,离线,同时签退收费员
   *
   * Copyright: Copyright (c) 2017  zteits
   *
   * @ClassName: EqpHeartBeatJob.java
   * @Description:
   * @version: v1.0.0
   * @author: zhaowg
   * @date: 2017年12月11日   上午10:12:45
   * Modification History:
   * Date             Author          Version            Description
   *---------------------------------------------------------*
   * 2017年12月11日      zhaowg              v1.0.0               创建
   */
  @Component
  public class PDAHeartBeatJob{
  	private static final Logger logger = LoggerFactory.getLogger(PDAHeartBeatJob.class);
  	@Autowired
  	private EmployeeChargeOperInnerService employeeChargeOperInnerService;
  	@Autowired
  	private TpPPdaMapper tpPPdaMapper;
  	@XxlJob("pdaHeartBeatJob")
  	public ReturnT<String> execute(String... params) throws Exception {
  		String param = XxlJobHelper.getJobParam();
  		if (StringUtils.isNotEmpty(param) && params == null) {
  			params = param.split(",");
  		}
  
  		try{
  			log("开始查询需要更新的PDA记录,超过15分钟没有心跳且状态是在线的设备,系统判定为离线,执行签退操作");
  			Calendar calendar = Calendar.getInstance();
  	        calendar.add(Calendar.MINUTE, -15);
  	        Date date = new Date(calendar.getTimeInMillis());
  			TpPPdaExample example = new TpPPdaExample();
  			example.createCriteria()
  			.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
  			.andOnlineFlgEqualTo(EqpConstant.IS_ONLINE.ON_LINE)
  			.andPdaTypeEqualTo(ParkConstant.PdaType.CHARGER_PDA_TYPE)
  			.andLatestUsedTimeLessThanOrEqualTo(date);
  			List<TpPPda> tpPPdas = tpPPdaMapper.selectByExample(example);
  			if(CollectionUtils.isEmpty(tpPPdas)){
  				log("查询到记录条数为0条");
  				return ReturnT.SUCCESS;
  			}
  			log("查询到记录条数为:"+tpPPdas.size());
  			for (TpPPda tpPPda : tpPPdas) {
  				log("开始执行签退操作,设备号:"+tpPPda.getPdaNo()+",收费员:"+tpPPda.getChargerCode());
  				try{
  					employeeChargeOperInnerService.pdaSignOut(tpPPda.getChargerCode(), tpPPda.getPdaNo(),ParkConstant.SignRecord.SIGN_OUT_TYPE_3);
  				}catch(Exception e){
  					log("更新PDA在线离线状态异常:"+e.getMessage());
  				}
  			}
  		}catch(Exception e){
  			log("更新PDA在线离线状态异常:"+e.getMessage());
  		}
  		return ReturnT.SUCCESS;
  	}
  	private void log(String msg){
  		XxlJobHelper.log(msg);
  		logger.info(msg);
  	}
  
  }