| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Hidden //不公开接口,其只有通信中间件调用 |
| | | @PostMapping(path = "/receive") |
| | | public BaseResponse<Boolean> receive(@RequestBody UpgradeInfo info, HttpServletRequest req, HttpServletResponse rep){ |
| | | /* |
| | | log.info("接收到的RTU远程升级状态数据为:{}", info.toString("532328000214")); |
| | | //进行排序 |
| | | //Comparator<UpgradeRtu> comparator = Comparator.comparing(UpgradeRtu::getRtuAddr, Comparator.naturalOrder()); |
| | | //info.ugRtuStateList = info.ugRtuStateList.stream().sorted(comparator).collect(Collectors.toList()); |
| | | |
| | | //通信中间件传过来的机构tag,以用于查找数据源 |
| | | String token = req.getHeader(Constant.UserTokenKeyInHeader); |
| | | DataSourceContext.set(token); |
| | | |
| | | if(info.ugRtuStateList != null && info.ugRtuStateList.size() > 0){ |
| | | if(info.ugRtuStateList.size() < 10){ |
| | | for (UpgradeRtu rtuVo : info.ugRtuStateList) { |
| | |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | |
| | | //进行排序 |
| | | Comparator<UpgradeRtu> comparator = Comparator.comparing(UpgradeRtu::getRtuAddr, Comparator.naturalOrder()); |
| | | info.ugRtuStateList = info.ugRtuStateList.stream().sorted(comparator).collect(Collectors.toList()); |
| | | |
| | | //通信中间件传过来的机构tag,以用于查找数据源 |
| | | String token = req.getHeader(Constant.UserTokenKeyInHeader); |
| | | DataSourceContext.set(token); |
| | | |
| | | if(cache == null){ |
| | | cache = info; |
| | | //此时不做任务操作,只保障cache不为空, 等待下次发来数据 |
| | |
| | | } |
| | | //cache赋值必须放在上面处理的后面,否则上面的比较不成功 |
| | | cache = info; |
| | | if(info.ugOverallState != null && info.ugOverallState.allOver){ |
| | | this.saveTaskOver(info.ugTaskId) ; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | |
| | | */ |
| | | private void save2Db(String taskId, List<UpgradeRtu> newList, List<UpgradeRtu> oldList){ |
| | | List<UpgradeRtu> newOverList = newList.stream().filter(vo -> vo.isOver).collect(Collectors.toList()) ; |
| | | List<UpgradeRtu> oldNoOverList = newList.stream().filter(vo -> !vo.isOver).collect(Collectors.toList()) ; |
| | | boolean oldExist = false ; |
| | | for(UpgradeRtu nvo : newOverList){ |
| | | if(nvo != null) { |
| | | if(oldList.stream().anyMatch(vo -> vo.rtuAddr.equals(nvo.rtuAddr) && vo.isOver == false)){ |
| | | //上次没有升级结束,而当前升级结束了 |
| | | this.sv.saveRtuUpgradeState(Long.parseLong(taskId), nvo); |
| | | } |
| | | oldExist = false ; |
| | | if(oldNoOverList.stream().anyMatch(vo -> vo.rtuAddr.equals(nvo.rtuAddr))){ |
| | | oldExist = true ; |
| | | } |
| | | if(!oldExist){ |
| | | //上次没有升级结束,而当前升级结束了 |
| | | this.sv.saveRtuUpgradeState(Long.parseLong(taskId), nvo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存升级任务已经执行完成 |
| | | * @param taskId |
| | | */ |
| | | private void saveTaskOver(String taskId){ |
| | | this.sv.updateTaskOver(taskId) ; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | ///////////////////////////////////////////////////// |
| | | // |
| | | // 以下模拟数据 |