| | |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.domain.Result; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.domain.SearchResult; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.enums.ResultCode; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.enums.SystemCacheKeyEnum; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.exception.BusinessException; |
| | | import com.gkhy.fourierSpecialGasMonitor.commons.model.PageQuery; |
| | | import com.gkhy.fourierSpecialGasMonitor.domain.account.entity.User; |
| | |
| | | import com.gkhy.fourierSpecialGasMonitor.service.GasCategoryService; |
| | | import com.gkhy.fourierSpecialGasMonitor.utils.ThreadLocalUtil; |
| | | import io.micrometer.core.instrument.util.StringUtils; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.FormulaEvaluator; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.redisson.api.RBucket; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.PageRequest; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.jpa.domain.Specification; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.persistence.criteria.CriteriaBuilder; |
| | | import javax.persistence.criteria.CriteriaQuery; |
| | | import javax.persistence.criteria.Predicate; |
| | | import javax.persistence.criteria.Root; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result createGasCategory(CreateGasCategoryReqDTO reqDto) { |
| | | public synchronized Result createGasCategory(CreateGasCategoryReqDTO reqDto) { |
| | | if (reqDto == null) |
| | | throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"参数不能为空"); |
| | | if (StringUtils.isBlank(reqDto.getMolecularFormula())) |
| | |
| | | gasCategoryMolecularFormulaRepeatlock.unlock(); |
| | | } |
| | | //清除redis缓存 |
| | | RBucket<List<GasCategory>> bucket = redissonClient.getBucket("gas_category_cache_info"); |
| | | RBucket<List<GasCategory>> bucket = redissonClient.getBucket(SystemCacheKeyEnum.KEY_GAS_CATEGORY.getKey()); |
| | | if (bucket.isExists()) { |
| | | bucket.delete(); |
| | | } |
| | |
| | | gasCategoryMolecularFormulaRepeatlock.unlock(); |
| | | } |
| | | //清除redis缓存 |
| | | RBucket<List<GasCategory>> bucket = redissonClient.getBucket("gas_category_cache_info"); |
| | | RBucket<List<GasCategory>> bucket = redissonClient.getBucket(SystemCacheKeyEnum.KEY_GAS_CATEGORY.getKey()); |
| | | if (bucket.isExists()) { |
| | | bucket.delete(); |
| | | } |
| | |
| | | @Override |
| | | public Result gasCategoryList() { |
| | | Result success = Result.success(); |
| | | RBucket<List<GasCategory>> bucket = redissonClient.getBucket("gas_category_cache_info"); |
| | | RBucket<List<GasCategory>> bucket = redissonClient.getBucket(SystemCacheKeyEnum.KEY_GAS_CATEGORY.getKey()); |
| | | List<GasCategory> categories = bucket.get(); |
| | | if (CollectionUtils.isEmpty(categories)){ |
| | | categories = gasCategoryRepository.findAll(); |
| | |
| | | searchResult.setTotal(pageResult.getTotalElements()); |
| | | searchResult.setPages(pageResult.getTotalPages()); |
| | | if (!CollectionUtils.isEmpty(pageResult.getContent())){ |
| | | List<FindGasCategoryPageRespDTO> respDTOS = new ArrayList<>(); |
| | | BeanUtils.copyProperties(pageResult.getContent(),respDTOS); |
| | | List<FindGasCategoryPageRespDTO> respDTOS = pageResult.getContent().stream().map(gasCategory -> { |
| | | FindGasCategoryPageRespDTO dto = new FindGasCategoryPageRespDTO(); |
| | | BeanUtils.copyProperties(gasCategory,dto); |
| | | return dto; |
| | | }).collect(Collectors.toList()); |
| | | searchResult.setData(respDTOS); |
| | | } |
| | | return searchResult; |