NotifySmartMeterV1InnerServiceSMOImpl.java 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2017-2020 吴学文 and java110 team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.java110.common.smo.impl;
  17. import com.java110.common.smartMeter.ISmartMeterFactoryAdapt;
  18. import com.java110.core.base.smo.BaseServiceSMO;
  19. import com.java110.core.log.LoggerFactory;
  20. import com.java110.dto.meterMachine.MeterMachineFactoryDto;
  21. import com.java110.dto.meterWater.NotifyMeterWaterOrderDto;
  22. import com.java110.intf.common.IMeterMachineFactoryV1InnerServiceSMO;
  23. import com.java110.intf.common.IMeterMachineV1InnerServiceSMO;
  24. import com.java110.intf.common.INotifySmartMeterV1InnerServiceSMO;
  25. import com.java110.utils.exception.CmdException;
  26. import com.java110.utils.factory.ApplicationContextFactory;
  27. import com.java110.utils.util.Assert;
  28. import com.java110.vo.ResultVo;
  29. import org.slf4j.Logger;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.http.ResponseEntity;
  32. import org.springframework.web.bind.annotation.RequestBody;
  33. import org.springframework.web.bind.annotation.RestController;
  34. import java.util.List;
  35. /**
  36. * 类表述: 服务之前调用的接口实现类,不对外提供接口能力 只用于接口建调用
  37. * add by 吴学文 at 2022-08-08 09:22:37 mail: 928255095@qq.com
  38. * open source address: https://gitee.com/wuxw7/MicroCommunity
  39. * 官网:http://www.homecommunity.cn
  40. * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
  41. * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
  42. */
  43. @RestController
  44. public class NotifySmartMeterV1InnerServiceSMOImpl extends BaseServiceSMO implements INotifySmartMeterV1InnerServiceSMO {
  45. private static final Logger logger = LoggerFactory.getLogger(NotifySmartMeterV1InnerServiceSMOImpl.class);
  46. private ISmartMeterFactoryAdapt smartMeterFactoryAdapt;
  47. @Autowired
  48. private IMeterMachineV1InnerServiceSMO meterMachineV1InnerServiceSMOImpl;
  49. @Autowired
  50. private IMeterMachineFactoryV1InnerServiceSMO meterMachineFactoryV1InnerServiceSMOImpl;
  51. /**
  52. * 通知类
  53. *
  54. * @param notifyMeterWaterOrderDto 数据对象分享
  55. * @return
  56. */
  57. @Override
  58. public ResponseEntity<String> notifySmartMater(@RequestBody NotifyMeterWaterOrderDto notifyMeterWaterOrderDto) {
  59. try {
  60. MeterMachineFactoryDto meterMachineFactoryDto = new MeterMachineFactoryDto();
  61. meterMachineFactoryDto.setBeanImpl(notifyMeterWaterOrderDto.getImplBean());
  62. List<MeterMachineFactoryDto> meterMachineFactoryDtos = meterMachineFactoryV1InnerServiceSMOImpl.queryMeterMachineFactorys(meterMachineFactoryDto);
  63. Assert.listOnlyOne(meterMachineFactoryDtos, "智能水电表厂家不存在");
  64. smartMeterFactoryAdapt = ApplicationContextFactory.getBean(meterMachineFactoryDtos.get(0).getBeanImpl(), ISmartMeterFactoryAdapt.class);
  65. if (smartMeterFactoryAdapt == null) {
  66. throw new CmdException("厂家接口未实现");
  67. }
  68. // 通知 厂家适配器数据
  69. ResultVo resultVo = smartMeterFactoryAdapt.notifyReadData(notifyMeterWaterOrderDto.getParam());
  70. return ResultVo.createResponseEntity(resultVo);
  71. } catch (Exception e) {
  72. logger.error("通知是配置异常", e);
  73. throw e;
  74. }
  75. }
  76. }