| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.zy.asrs.entity.BasErrLog; |
| | | import com.zy.asrs.entity.mes.MesReturn; |
| | | import com.zy.asrs.service.BasErrLogService; |
| | | import com.zy.asrs.service.impl.RcsServiceImpl; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.task.handler.ErrorStockHandler; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/7/7 |
| | | */ |
| | | @Component |
| | | public class ErrorStockScheduler { |
| | | |
| | | @Value("${mes.url}") |
| | | public String MES_URL; |
| | | |
| | | @Autowired |
| | | private BasErrLogService basErrLogService; |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(ErrorStockScheduler.class); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 每日故障信息上报 |
| | | */ |
| | | @Scheduled(cron = "0 0 20 * * ? ") |
| | | public void faultReport() { |
| | | // 获取今天的开始时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | Date todayStart = calendar.getTime(); |
| | | |
| | | // 获取今天的结束时间 |
| | | calendar.set(Calendar.HOUR_OF_DAY, 23); |
| | | calendar.set(Calendar.MINUTE, 59); |
| | | calendar.set(Calendar.SECOND, 59); |
| | | calendar.set(Calendar.MILLISECOND, 999); |
| | | Date todayEnd = calendar.getTime(); |
| | | |
| | | List<BasErrLog> basErrLogs = basErrLogService.selectList( |
| | | new EntityWrapper<BasErrLog>() |
| | | .between("create_time", todayStart, todayEnd) |
| | | .orderBy("create_time", false) |
| | | ); |
| | | |
| | | int totalCount = basErrLogs.size(); |
| | | long totalTime = 0; |
| | | |
| | | for (BasErrLog basErrLog : basErrLogs) { |
| | | if (basErrLog.getStartTime() != null && basErrLog.getEndTime() != null) { |
| | | totalTime += basErrLog.getEndTime().getTime() - basErrLog.getStartTime().getTime(); |
| | | } |
| | | } |
| | | |
| | | JSONObject params = new JSONObject(); |
| | | params.put("totalCount", totalCount); |
| | | params.put("totalTime", totalTime / 1000); |
| | | |
| | | String url = "ErrorLogReport"; |
| | | String URL = MES_URL + url; |
| | | String response = RcsServiceImpl.sendPost(URL, JSONObject.toJSONString(params)); |
| | | if (!StringUtils.isEmpty(response) && response.contains("Success")){ |
| | | MesReturn mesReturn = JSONObject.parseObject(response, MesReturn.class); |
| | | if("1".equals(mesReturn.getSuccess())) { |
| | | log.info("上报完成 ==> 故障次数:{}, 总时长:{}", totalCount, totalTime); |
| | | }else { |
| | | log.error("上报失败 ==> 故障次数:{}, 总时长:{}", totalCount, totalTime); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |