| | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.http.HttpUtils; |
| | | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.telemetry.vo.MesDvTelemetryCheckSummaryRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.telemetry.vo.MesDvTelemetryDeviceRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.telemetry.vo.MesDvTelemetryLatestReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.telemetry.vo.MesDvTelemetryPageReqVO; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<MesDvTelemetryCheckSummaryRespVO> getCheckSummary(MesDvTelemetryLatestReqVO reqVO) { |
| | | List<MesDvTelemetryDO> list = getLatestTelemetry(reqVO); |
| | | Map<String, MesDvTelemetryCheckSummaryRespVO> deviceMap = new LinkedHashMap<>(); |
| | | for (MesDvTelemetryDO row : list) { |
| | | String key = StrUtil.blankToDefault(row.getTbDeviceId(), ""); |
| | | MesDvTelemetryCheckSummaryRespVO vo = deviceMap.get(key); |
| | | if (vo == null) { |
| | | vo = new MesDvTelemetryCheckSummaryRespVO(); |
| | | vo.setTbDeviceId(row.getTbDeviceId()); |
| | | vo.setDeviceName(row.getDeviceName()); |
| | | vo.setTotalCount(0); |
| | | vo.setNormalCount(0); |
| | | vo.setAnomalyCount(0); |
| | | deviceMap.put(key, vo); |
| | | } |
| | | vo.setTotalCount(vo.getTotalCount() + 1); |
| | | if (Boolean.TRUE.equals(row.getWhetherAnomaly())) { |
| | | vo.setAnomalyCount(vo.getAnomalyCount() + 1); |
| | | } else { |
| | | vo.setNormalCount(vo.getNormalCount() + 1); |
| | | } |
| | | } |
| | | List<MesDvTelemetryCheckSummaryRespVO> result = new ArrayList<>(deviceMap.values()); |
| | | for (MesDvTelemetryCheckSummaryRespVO vo : result) { |
| | | if (vo.getTotalCount() != null && vo.getTotalCount() > 0) { |
| | | BigDecimal rate = BigDecimal.valueOf(vo.getAnomalyCount() * 100.0 / vo.getTotalCount()); |
| | | vo.setAnomalyRate(rate.setScale(1, RoundingMode.HALF_UP)); |
| | | } else { |
| | | vo.setAnomalyRate(BigDecimal.ZERO); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<MesDvTelemetryDeviceRespVO> getDeviceList() { |
| | | List<MesDvTelemetryDeviceRespVO> result = new ArrayList<>(); |
| | | for (MesDvTelemetryDO row : telemetryMapper.selectDeviceList()) { |