WeatherStationInfoService.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package com.jiayue.ipfcst.console.service;
  2. import com.jiayue.ipfcst.common.core.exception.BusinessException;
  3. import com.jiayue.ipfcst.common.data.entity.InverterInfo;
  4. import com.jiayue.ipfcst.common.data.entity.WeatherStationInfo;
  5. import com.jiayue.ipfcst.common.data.repository.WeatherStationInfoRepository;
  6. import com.jiayue.ipfcst.common.data.service.BaseService;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.data.domain.*;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Propagation;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import org.springframework.util.StringUtils;
  14. import java.util.ArrayList;
  15. import java.util.Comparator;
  16. import java.util.List;
  17. import java.util.Optional;
  18. import java.util.stream.Collectors;
  19. /**
  20. * 环境监测仪业务层
  21. *
  22. * @author zzy
  23. * @version 1.0
  24. * @since 2019/8/7 10:58
  25. */
  26. @Service
  27. @Slf4j
  28. public class WeatherStationInfoService extends BaseService {
  29. private final WeatherStationInfoRepository weatherStationInfoRepository;
  30. @Autowired
  31. public WeatherStationInfoService(WeatherStationInfoRepository weatherStationInfoRepository) {
  32. this.weatherStationInfoRepository = weatherStationInfoRepository;
  33. }
  34. /**
  35. * 新增环境监测仪
  36. *
  37. * @param weatherStationInfo 气象站
  38. * @throws BusinessException 业务异常
  39. */
  40. @Transactional(propagation = Propagation.SUPPORTS)
  41. public void add(WeatherStationInfo weatherStationInfo) throws BusinessException {
  42. this.weatherStationInfoRepository.save(weatherStationInfo);
  43. }
  44. /**
  45. * 修改环境监测仪
  46. *
  47. * @param weatherStationInfo 监测仪
  48. * @throws BusinessException 业务异常
  49. */
  50. @Transactional(propagation = Propagation.SUPPORTS)
  51. public void update(WeatherStationInfo weatherStationInfo) throws BusinessException {
  52. if (StringUtils.isEmpty(weatherStationInfo.getId())) {
  53. throw new BusinessException("环境监测仪编号不能为空!");
  54. } else {
  55. this.weatherStationInfoRepository.save(weatherStationInfo);
  56. }
  57. }
  58. /**
  59. * 删除环境监测仪
  60. *
  61. * @param id 监测仪编号
  62. * @throws BusinessException 业务异常
  63. */
  64. @Transactional(propagation = Propagation.SUPPORTS)
  65. public void delete(final Integer id) throws BusinessException {
  66. if (StringUtils.isEmpty(id)) {
  67. throw new BusinessException("环境监测仪编号不能为空!");
  68. } else {
  69. this.weatherStationInfoRepository.deleteById(id);
  70. }
  71. }
  72. /**
  73. * 查询环境监测仪
  74. *
  75. * @param no 测风塔编号
  76. * @return 逆变器
  77. * @throws BusinessException 业务异常
  78. */
  79. @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
  80. public WeatherStationInfo get(final Integer no) throws BusinessException {
  81. Optional<WeatherStationInfo> optional = this.weatherStationInfoRepository.findById(no);
  82. if (optional.isPresent()) {
  83. return optional.get();
  84. } else {
  85. throw new BusinessException("环境监测仪不存在!");
  86. }
  87. }
  88. /**
  89. * 查询环境监测仪【分页查询】
  90. *
  91. * @param stationCode 场站编号
  92. * @return 分页结果
  93. */
  94. @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
  95. public List<WeatherStationInfo> get(String stationCode) {
  96. List<WeatherStationInfo> resultList = new ArrayList<>();
  97. resultList = this.weatherStationInfoRepository.findAll();
  98. if (!"ALL".equals(stationCode)){
  99. resultList = resultList.stream().filter(s->s.getStationCode().equals(stationCode)).collect(Collectors.toList());
  100. }
  101. return resultList.stream().sorted(Comparator.comparing(WeatherStationInfo::getStationCode)).collect(Collectors.toList());
  102. }
  103. /**
  104. * 查询环境监测仪
  105. *
  106. * @return 分页结果
  107. */
  108. @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
  109. public List<WeatherStationInfo> getAll() {
  110. return this.weatherStationInfoRepository.findAll();
  111. }
  112. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  113. public void saveCloud(WeatherStationInfo bean) {
  114. // WeatherStationInfo weatherStationInfo = weatherStationInfoRepository.findByName(bean.getName());
  115. // if (null != weatherStationInfo) {
  116. // bean.setId(weatherStationInfo.getId());
  117. // }
  118. weatherStationInfoRepository.save(bean);
  119. }
  120. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  121. public void saveCloud(List<WeatherStationInfo> beans) {
  122. if(beans != null && beans.size() > 0){
  123. weatherStationInfoRepository.deleteAll();
  124. weatherStationInfoRepository.saveAll(beans);
  125. }
  126. }
  127. }