SysParameterService.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package com.jiayue.ipfcst.console.service;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.jiayue.ipfcst.common.core.exception.BusinessException;
  4. import com.jiayue.ipfcst.common.data.entity.SysParameter;
  5. import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
  6. import com.jiayue.ipfcst.common.data.service.BaseService;
  7. import lombok.extern.slf4j.Slf4j;
  8. import net.sf.ehcache.Cache;
  9. import net.sf.ehcache.Element;
  10. import net.sf.ehcache.search.Attribute;
  11. import net.sf.ehcache.search.Query;
  12. import net.sf.ehcache.search.Result;
  13. import net.sf.ehcache.search.Results;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.cache.ehcache.EhCacheCacheManager;
  16. import org.springframework.data.domain.*;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.transaction.annotation.Propagation;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import java.util.Optional;
  23. /**
  24. * 系统参数业务层
  25. *
  26. * @author zzy
  27. * @version 1.0
  28. * @since 2019/8/6 16:35
  29. */
  30. @Service
  31. @Slf4j
  32. public class SysParameterService extends BaseService {
  33. private final SysParameterRepository sysParameterRepository;
  34. private final EhCacheCacheManager ehCacheCacheManager;
  35. @Autowired
  36. public SysParameterService(SysParameterRepository sysParameterRepository, EhCacheCacheManager ehCacheCacheManager) {
  37. this.sysParameterRepository = sysParameterRepository;
  38. this.ehCacheCacheManager = ehCacheCacheManager;
  39. }
  40. /**
  41. * 新增系统参数
  42. *
  43. * @param sysParameter 系统参数实体
  44. * @throws BusinessException 业务异常
  45. */
  46. @Transactional(propagation = Propagation.SUPPORTS)
  47. public void add(SysParameter sysParameter) throws BusinessException {
  48. boolean b = this.sysParameterRepository.existsBySysKeyAndStationCode(sysParameter.getSysKey(),sysParameter.getStationCode());
  49. if (b) {// 参数已存在
  50. throw new BusinessException("系统参数已存在!");
  51. } else {
  52. this.sysParameterRepository.save(sysParameter);
  53. }
  54. }
  55. /**
  56. * 修改系统参数
  57. *
  58. * @param sysParameter 系统参数实体
  59. * @throws BusinessException 业务异常
  60. */
  61. @Transactional(propagation = Propagation.SUPPORTS)
  62. public void update(SysParameter sysParameter) throws BusinessException {
  63. if (StrUtil.isEmpty(sysParameter.getSysKey())) {
  64. throw new BusinessException("系统参数标识不能为空!");
  65. } else {
  66. this.sysParameterRepository.save(sysParameter);
  67. }
  68. }
  69. /**
  70. * 删除系统参数
  71. *
  72. * @param id 主键编号
  73. * @throws BusinessException 业务异常
  74. */
  75. @Transactional(rollbackFor = Exception.class, propagation = Propagation.SUPPORTS)
  76. public void delete(final Integer id) throws BusinessException {
  77. this.sysParameterRepository.deleteById(id);
  78. }
  79. /**
  80. * 查询参数
  81. *
  82. * @param sysParameter 查询条件
  83. * @param page 页码
  84. * @param size 每页记录数
  85. * @return 分页结果
  86. */
  87. @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
  88. public Page<SysParameter> get(final SysParameter sysParameter, final Integer page, final Integer size) {
  89. ExampleMatcher matcher = ExampleMatcher.matching()
  90. .withMatcher("sysKey", ExampleMatcher.GenericPropertyMatchers.contains())
  91. .withMatcher("sysValue", ExampleMatcher.GenericPropertyMatchers.contains())
  92. .withMatcher("describe", ExampleMatcher.GenericPropertyMatchers.contains());
  93. Example<SysParameter> example = Example.of(sysParameter, matcher);
  94. Pageable pageable = PageRequest.of(page - 1, size);
  95. return this.sysParameterRepository.findAll(example, pageable);
  96. }
  97. /**
  98. * 查询参数值
  99. *
  100. * @param id 主键编号
  101. * @return 参数
  102. */
  103. @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
  104. public String getParameter(final Integer id) {
  105. Optional<SysParameter> sysParameterOptional = this.sysParameterRepository.findById(id);
  106. return sysParameterOptional.map(SysParameter::getSysValue).orElse(null);
  107. }
  108. /**
  109. * 查询所有参数信息
  110. *
  111. * @return 通道信息
  112. */
  113. public List<SysParameter> getAll() {
  114. return sysParameterRepository.findAll();
  115. }
  116. public List<SysParameter> getAllByStationCode(String stationCode) {
  117. return sysParameterRepository.findAllByStationCode(stationCode);
  118. }
  119. }