对比新文件 |
| | |
| | | package com.iailab.module.ansteel.job.task; |
| | | |
| | | import com.iailab.module.ansteel.power.entity.PowerCapacitorDetEntity; |
| | | import com.iailab.module.ansteel.power.service.PowerCapacitorDetService; |
| | | import com.iailab.module.ansteel.power.service.PowerCapacitorHisService; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 电容器投退历史 |
| | | * 检测电容器电流状态变化,何时投入,何时退出 |
| | | * 每5分钟检测一次 |
| | | * 20 0/5 * * * ? |
| | | * |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年05月13日 |
| | | */ |
| | | @Component("runPowerCapacitorHisTask") |
| | | public class RunPowerCapacitorHisTask implements ITask { |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | @Autowired |
| | | private PowerCapacitorHisService powerCapacitorHisService; |
| | | |
| | | @Autowired |
| | | private PowerCapacitorDetService powerCapacitorDetService; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | private final static BigDecimal MIN_V = BigDecimal.valueOf(1); |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | | logger.info("RunPowerCapacitorHisTask start"); |
| | | try { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | Date endTime = calendar.getTime(); |
| | | calendar.add(Calendar.MINUTE, -5); |
| | | Date startTime = calendar.getTime(); |
| | | List<PowerCapacitorDetEntity> detList = powerCapacitorDetService.list(new HashMap<>()); |
| | | if (CollectionUtils.isEmpty(detList)) { |
| | | logger.info("detList is empty"); |
| | | return; |
| | | } |
| | | for (PowerCapacitorDetEntity det : detList) { |
| | | if (StringUtils.isBlank(det.getPointNo())) { |
| | | logger.info("det.getPointNo is empty"); |
| | | continue; |
| | | } |
| | | ApiPointValueQueryDTO apiPointValueQuery = new ApiPointValueQueryDTO(); |
| | | apiPointValueQuery.setPointNo(det.getPointNo()); |
| | | apiPointValueQuery.setStart(startTime); |
| | | apiPointValueQuery.setEnd(endTime); |
| | | List<ApiPointValueDTO> hisValue = dataPointApi.queryPointHistoryValue(apiPointValueQuery); |
| | | if (CollectionUtils.isEmpty(hisValue)) { |
| | | logger.info("hisValue is empty"); |
| | | continue; |
| | | } |
| | | BigDecimal firstValue = BigDecimal.valueOf(hisValue.get(0).getV()).setScale(2, RoundingMode.HALF_UP); |
| | | int lastStatus = firstValue.compareTo(MIN_V) > 0 ? 1 : 0; |
| | | |
| | | logger.info("det=" + det.getId()); |
| | | for (int i = 1; i < hisValue.size(); i++) { |
| | | BigDecimal value = BigDecimal.valueOf(hisValue.get(i).getV()).setScale(2, RoundingMode.HALF_UP); |
| | | int curStatus = value.compareTo(MIN_V) > 0 ? 1 : 0; |
| | | if (curStatus > lastStatus) { |
| | | logger.info("投入"); |
| | | powerCapacitorHisService.add(det.getId(), det.getName(), curStatus); |
| | | } else if (curStatus < lastStatus) { |
| | | logger.info("退出"); |
| | | powerCapacitorHisService.add(det.getId(), det.getName(), curStatus); |
| | | } else { |
| | | logger.info("状态无变化"); |
| | | } |
| | | lastStatus = curStatus; |
| | | } |
| | | } |
| | | logger.info("RunPowerCapacitorHisTask success"); |
| | | } catch (Exception e) { |
| | | logger.error("RunPowerCapacitorHisTask error", e); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |