| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** 按电表汇总全部报警类型,逗号分隔回写 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) |