123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package com.jiayue.ipfcst.console.service;
- import cn.hutool.core.util.StrUtil;
- import com.jiayue.ipfcst.common.core.exception.BusinessException;
- import com.jiayue.ipfcst.common.data.entity.SysParameter;
- import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
- import com.jiayue.ipfcst.common.data.service.BaseService;
- import lombok.extern.slf4j.Slf4j;
- import net.sf.ehcache.Cache;
- import net.sf.ehcache.Element;
- import net.sf.ehcache.search.Attribute;
- import net.sf.ehcache.search.Query;
- import net.sf.ehcache.search.Result;
- import net.sf.ehcache.search.Results;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.cache.ehcache.EhCacheCacheManager;
- import org.springframework.data.domain.*;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Optional;
- /**
- * 系统参数业务层
- *
- * @author zzy
- * @version 1.0
- * @since 2019/8/6 16:35
- */
- @Service
- @Slf4j
- public class SysParameterService extends BaseService {
- private final SysParameterRepository sysParameterRepository;
- private final EhCacheCacheManager ehCacheCacheManager;
- @Autowired
- public SysParameterService(SysParameterRepository sysParameterRepository, EhCacheCacheManager ehCacheCacheManager) {
- this.sysParameterRepository = sysParameterRepository;
- this.ehCacheCacheManager = ehCacheCacheManager;
- }
- /**
- * 新增系统参数
- *
- * @param sysParameter 系统参数实体
- * @throws BusinessException 业务异常
- */
- @Transactional(propagation = Propagation.SUPPORTS)
- public void add(SysParameter sysParameter) throws BusinessException {
- boolean b = this.sysParameterRepository.existsBySysKeyAndStationCode(sysParameter.getSysKey(),sysParameter.getStationCode());
- if (b) {// 参数已存在
- throw new BusinessException("系统参数已存在!");
- } else {
- this.sysParameterRepository.save(sysParameter);
- }
- }
- /**
- * 修改系统参数
- *
- * @param sysParameter 系统参数实体
- * @throws BusinessException 业务异常
- */
- @Transactional(propagation = Propagation.SUPPORTS)
- public void update(SysParameter sysParameter) throws BusinessException {
- if (StrUtil.isEmpty(sysParameter.getSysKey())) {
- throw new BusinessException("系统参数标识不能为空!");
- } else {
- this.sysParameterRepository.save(sysParameter);
- }
- }
- /**
- * 删除系统参数
- *
- * @param id 主键编号
- * @throws BusinessException 业务异常
- */
- @Transactional(rollbackFor = Exception.class, propagation = Propagation.SUPPORTS)
- public void delete(final Integer id) throws BusinessException {
- this.sysParameterRepository.deleteById(id);
- }
- /**
- * 查询参数
- *
- * @param sysParameter 查询条件
- * @param page 页码
- * @param size 每页记录数
- * @return 分页结果
- */
- @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
- public Page<SysParameter> get(final SysParameter sysParameter, final Integer page, final Integer size) {
- ExampleMatcher matcher = ExampleMatcher.matching()
- .withMatcher("sysKey", ExampleMatcher.GenericPropertyMatchers.contains())
- .withMatcher("sysValue", ExampleMatcher.GenericPropertyMatchers.contains())
- .withMatcher("describe", ExampleMatcher.GenericPropertyMatchers.contains());
- Example<SysParameter> example = Example.of(sysParameter, matcher);
- Pageable pageable = PageRequest.of(page - 1, size);
- return this.sysParameterRepository.findAll(example, pageable);
- }
- /**
- * 查询参数值
- *
- * @param id 主键编号
- * @return 参数
- */
- @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
- public String getParameter(final Integer id) {
- Optional<SysParameter> sysParameterOptional = this.sysParameterRepository.findById(id);
- return sysParameterOptional.map(SysParameter::getSysValue).orElse(null);
- }
- /**
- * 查询所有参数信息
- *
- * @return 通道信息
- */
- public List<SysParameter> getAll() {
- return sysParameterRepository.findAll();
- }
- public List<SysParameter> getAllByStationCode(String stationCode) {
- return sysParameterRepository.findAllByStationCode(stationCode);
- }
- }
|