| | |
| | | import com.sandu.ximon.dao.bo.LightBo; |
| | | import com.sandu.ximon.dao.domain.Light; |
| | | import com.sandu.ximon.dao.domain.LightReportData; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.domain.PoleBinding; |
| | | import com.sandu.ximon.dao.enums.DeviceRespStatusEnums; |
| | | import com.sandu.ximon.dao.mapper.LightMapper; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | |
| | | private final RedisService redisService; |
| | | private final LightReportDataService lightReportDataService; |
| | | private final PoleBindingService bindingService; |
| | | private final PoleService poleService; |
| | | |
| | | /** |
| | | * 录入当前设备码的路灯数据 |
| | |
| | | if (CollectionUtil.isNotEmpty(deviceCodeList)) { |
| | | List<LightReportData> reportDataList = lightReportDataService.getNewestReportByDeviceCode(deviceCodeList); |
| | | for (LightBo lightBo : listLight) { |
| | | deviceCodeList.forEach(code -> { |
| | | PoleBinding bind = bindingService.getPoleIdByMac(code); |
| | | if (bind != null&&lightBo.getDeviceCode().equals(bind.getDeviceCode())) { |
| | | Long poleId = bind.getPoleId(); |
| | | Pole pole = poleService.getById(poleId); |
| | | lightBo.setPoleId(pole.getId()); |
| | | lightBo.setPoleCode(pole.getDeviceCode()); |
| | | lightBo.setPoleName(pole.getPoleName()); |
| | | } |
| | | } |
| | | ); |
| | | for (LightReportData lightReportData : reportDataList) { |
| | | if (StrUtil.equals(lightBo.getDeviceCode(), lightReportData.getDeviceCode())) { |
| | | lightBo.setReportTime(lightReportData.getCreateTime()); |
| | |
| | | for (LightControlParam param : paramList) { |
| | | A5LightBrightnessReqInnerFrame lightControlFrame = new A5LightBrightnessReqInnerFrame(param.getBrightness()); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_LIGHT_DATA.getCode(), lightControlFrame); |
| | | WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(param.getDeviceCode(), a5Frame, A5LightBrightnessRespInnerFrame.class); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("deviceCode", param.getDeviceCode()); |
| | | if (frame == null) { |
| | | try { |
| | | map.put("deviceCode", param.getDeviceCode()); |
| | | WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(param.getDeviceCode(), a5Frame, A5LightBrightnessRespInnerFrame.class); |
| | | if (frame == null) { |
| | | map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | resultList.add(map); |
| | | continue; |
| | | } |
| | | String responseStatus = frame.getResponseInnerFrame().getResponseStatus(); |
| | | int status = HexUtil.hexToInt(responseStatus); |
| | | map.put("status", status); |
| | | resultList.add(map); |
| | | |
| | | // 更新亮度成功,修改到数据库 |
| | | if (DeviceRespStatusEnums.SUCCESS.getCode().equals(status)) { |
| | | Light light = new Light(); |
| | | light.setLightPercent(param.getBrightness()); |
| | | update(light, Wrappers.lambdaUpdate(Light.class).eq(Light::getDeviceCode, param.getDeviceCode())); |
| | | } |
| | | } catch (BusinessException e) { |
| | | map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | resultList.add(map); |
| | | continue; |
| | | } |
| | | String responseStatus = frame.getResponseInnerFrame().getResponseStatus(); |
| | | int status = HexUtil.hexToInt(responseStatus); |
| | | map.put("status", status); |
| | | resultList.add(map); |
| | | |
| | | // 更新亮度成功,修改到数据库 |
| | | if (DeviceRespStatusEnums.SUCCESS.getCode().equals(status)) { |
| | | Light light = new Light(); |
| | | light.setLightPercent(param.getBrightness()); |
| | | update(light, Wrappers.lambdaUpdate(Light.class).eq(Light::getDeviceCode, param.getDeviceCode())); |
| | | } |
| | | } |
| | | |