| | |
| | | import com.doumee.dao.business.model.YwElectricalRoom; |
| | | import com.doumee.dao.business.model.YwElectricalWarning; |
| | | import com.doumee.dao.business.model.YwRoom; |
| | | import com.doumee.dao.business.vo.WarningTypeStatVO; |
| | | import com.doumee.service.business.YwElectricalWarningService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | } |
| | | Map<String, YwElectrical> addressMap = buildElectricalAddressMap(); |
| | | Map<String, YwElectrical> didMap = buildElectricalDidMap(); |
| | | Set<Integer> affectedElectricalIds = new LinkedHashSet<>(); |
| | | Date now = new Date(); |
| | | int addCount = 0; |
| | | int updateCount = 0; |
| | |
| | | entity.setMsg(item.getMsg()); |
| | | entity.setEditDate(now); |
| | | resolveElectricalId(entity, addressMap, didMap); |
| | | if (entity.getElectricalId() != null) { |
| | | affectedElectricalIds.add(entity.getElectricalId()); |
| | | } |
| | | if (isNew) { |
| | | ywElectricalWarningMapper.insert(entity); |
| | | addCount++; |
| | |
| | | updateCount++; |
| | | } |
| | | } |
| | | return "同步完成:新增【" + addCount + "】条,更新【" + updateCount + "】条"; |
| | | int electricalUpdateCount = updateElectricalWarnTypes(affectedElectricalIds, now); |
| | | return "同步完成:新增【" + addCount + "】条,更新【" + updateCount + "】条,回写电表预警【" + electricalUpdateCount + "】台"; |
| | | } finally { |
| | | Constants.DEALING_ELECTRICAL_WARNING_SYNC = false; |
| | | } |
| | |
| | | List<WarningDefOptionDTO> list = new ArrayList<>(); |
| | | for (ElectronicConstant.warningDefId item : ElectronicConstant.warningDefId.listByDeviceType(ELECTRICAL_DEVICE_TYPE)) { |
| | | list.add(new WarningDefOptionDTO(item.getKey(), item.getName())); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<WarningTypeStatVO> warningTypeStats() { |
| | | QueryWrapper<YwElectricalWarning> wrapper = new QueryWrapper<>(); |
| | | wrapper.select("warning_def_id", "count(1) as cnt") |
| | | .eq("isdeleted", Constants.ZERO) |
| | | .eq("device_type", ELECTRICAL_DEVICE_TYPE) |
| | | .isNotNull("warning_def_id") |
| | | .groupBy("warning_def_id") |
| | | .orderByDesc("cnt"); |
| | | List<Map<String, Object>> rows = ywElectricalWarningMapper.selectMaps(wrapper); |
| | | List<WarningTypeStatVO> list = new ArrayList<>(); |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return list; |
| | | } |
| | | for (Map<String, Object> row : rows) { |
| | | Object defIdObj = row.get("warning_def_id"); |
| | | if (defIdObj == null) { |
| | | continue; |
| | | } |
| | | Integer warningDefId = Integer.parseInt(String.valueOf(defIdObj)); |
| | | Object cntObj = row.get("cnt"); |
| | | long count = cntObj == null ? 0L : Long.parseLong(String.valueOf(cntObj)); |
| | | WarningTypeStatVO stat = new WarningTypeStatVO(); |
| | | stat.setWarningDefId(warningDefId); |
| | | stat.setCount(count); |
| | | ElectronicConstant.warningDefId def = ElectronicConstant.warningDefId.getByKey(warningDefId); |
| | | stat.setWarningName(def != null ? def.getName() : "未知报警"); |
| | | list.add(stat); |
| | | } |
| | | return list; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** 按电表汇总全部报警类型,逗号分隔回写 warn_type */ |
| | | private int updateElectricalWarnTypes(Set<Integer> affectedElectricalIds, Date editDate) { |
| | | if (CollectionUtils.isEmpty(affectedElectricalIds)) { |
| | | return 0; |
| | | } |
| | | for (Integer electricalId : affectedElectricalIds) { |
| | | refreshElectricalWarnType(electricalId, editDate); |
| | | } |
| | | return affectedElectricalIds.size(); |
| | | } |
| | | |
| | | private void refreshElectricalWarnType(Integer electricalId, Date editDate) { |
| | | List<YwElectricalWarning> warnings = ywElectricalWarningMapper.selectList(new QueryWrapper<YwElectricalWarning>().lambda() |
| | | .eq(YwElectricalWarning::getElectricalId, electricalId) |
| | | .eq(YwElectricalWarning::getIsdeleted, Constants.ZERO)); |
| | | LinkedHashSet<Integer> defIds = new LinkedHashSet<>(); |
| | | if (!CollectionUtils.isEmpty(warnings)) { |
| | | for (YwElectricalWarning warning : warnings) { |
| | | if (warning.getWarningDefId() != null) { |
| | | defIds.add(warning.getWarningDefId()); |
| | | } |
| | | } |
| | | } |
| | | String warnType = defIds.stream().map(String::valueOf).collect(Collectors.joining(",")); |
| | | YwElectrical upd = new YwElectrical(); |
| | | upd.setId(electricalId); |
| | | upd.setWarnType(StringUtils.isBlank(warnType) ? null : warnType); |
| | | upd.setEditDate(editDate); |
| | | ywElectricalMapper.updateById(upd); |
| | | } |
| | | |
| | | private YwElectricalWarning findExisting(String deviceAddress, Integer warningDefId, Date startTime) { |
| | | return ywElectricalWarningMapper.selectOne(new QueryWrapper<YwElectricalWarning>().lambda() |
| | | .eq(YwElectricalWarning::getDeviceAddress, deviceAddress) |