From 2704e921c80baf212e74ddbf75a87c47e8a2679e Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期日, 04 七月 2021 19:18:06 +0800
Subject: [PATCH] update 增加 feign 熔断 自定义结构体解析方法 与 demo 注释
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java | 383 +++++++++++++++++++++++++++++-------------------------
1 files changed, 208 insertions(+), 175 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
index 76dab69..82f67c3 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
@@ -1,204 +1,237 @@
package com.ruoyi.system.service.impl;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Validator;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysDictType;
+import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
+import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DictUtils;
-import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.mapper.SysDictTypeMapper;
import com.ruoyi.system.service.ISysDictTypeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.PostConstruct;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
/**
* 瀛楀吀 涓氬姟灞傚鐞�
- *
+ *
* @author ruoyi
*/
@Service
-public class SysDictTypeServiceImpl implements ISysDictTypeService
-{
- @Autowired
- private SysDictTypeMapper dictTypeMapper;
+public class SysDictTypeServiceImpl extends ServicePlusImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService {
- @Autowired
- private SysDictDataMapper dictDataMapper;
+ @Autowired
+ private SysDictDataMapper dictDataMapper;
- /**
- * 椤圭洰鍚姩鏃讹紝鍒濆鍖栧瓧鍏稿埌缂撳瓨
- */
- @PostConstruct
- public void init()
- {
- List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
- for (SysDictType dictType : dictTypeList)
- {
- List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
- DictUtils.setDictCache(dictType.getDictType(), dictDatas);
- }
- }
+ /**
+ * 椤圭洰鍚姩鏃讹紝鍒濆鍖栧瓧鍏稿埌缂撳瓨
+ */
+ @PostConstruct
+ public void init() {
+ loadingDictCache();
+ }
- /**
- * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀绫诲瀷
- *
- * @param dictType 瀛楀吀绫诲瀷淇℃伅
- * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅
- */
- @Override
- public List<SysDictType> selectDictTypeList(SysDictType dictType)
- {
- return dictTypeMapper.selectDictTypeList(dictType);
- }
+ @Override
+ public TableDataInfo<SysDictType> selectPageDictTypeList(SysDictType dictType) {
+ Map<String, Object> params = dictType.getParams();
+ LambdaQueryWrapper<SysDictType> lqw = new LambdaQueryWrapper<SysDictType>()
+ .like(StrUtil.isNotBlank(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName())
+ .eq(StrUtil.isNotBlank(dictType.getStatus()), SysDictType::getStatus, dictType.getStatus())
+ .like(StrUtil.isNotBlank(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType())
+ .apply(Validator.isNotEmpty(params.get("beginTime")),
+ "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')",
+ params.get("beginTime"))
+ .apply(Validator.isNotEmpty(params.get("endTime")),
+ "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')",
+ params.get("endTime"));
+ return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw));
+ }
- /**
- * 鏍规嵁鎵�鏈夊瓧鍏哥被鍨�
- *
- * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅
- */
- @Override
- public List<SysDictType> selectDictTypeAll()
- {
- return dictTypeMapper.selectDictTypeAll();
- }
+ /**
+ * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀绫诲瀷
+ *
+ * @param dictType 瀛楀吀绫诲瀷淇℃伅
+ * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅
+ */
+ @Override
+ public List<SysDictType> selectDictTypeList(SysDictType dictType) {
+ Map<String, Object> params = dictType.getParams();
+ return list(new LambdaQueryWrapper<SysDictType>()
+ .like(StrUtil.isNotBlank(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName())
+ .eq(StrUtil.isNotBlank(dictType.getStatus()), SysDictType::getStatus, dictType.getStatus())
+ .like(StrUtil.isNotBlank(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType())
+ .apply(Validator.isNotEmpty(params.get("beginTime")),
+ "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')",
+ params.get("beginTime"))
+ .apply(Validator.isNotEmpty(params.get("endTime")),
+ "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')",
+ params.get("endTime")));
+ }
- /**
- * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁
- *
- * @param dictType 瀛楀吀绫诲瀷
- * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅
- */
- @Override
- public List<SysDictData> selectDictDataByType(String dictType)
- {
- List<SysDictData> dictDatas = DictUtils.getDictCache(dictType);
- if (StringUtils.isNotNull(dictDatas))
- {
- return dictDatas;
- }
- dictDatas = dictDataMapper.selectDictDataByType(dictType);
- if (StringUtils.isNotNull(dictDatas))
- {
- DictUtils.setDictCache(dictType, dictDatas);
- return dictDatas;
- }
- return null;
- }
+ /**
+ * 鏍规嵁鎵�鏈夊瓧鍏哥被鍨�
+ *
+ * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅
+ */
+ @Override
+ public List<SysDictType> selectDictTypeAll() {
+ return list();
+ }
- /**
- * 鏍规嵁瀛楀吀绫诲瀷ID鏌ヨ淇℃伅
- *
- * @param dictId 瀛楀吀绫诲瀷ID
- * @return 瀛楀吀绫诲瀷
- */
- @Override
- public SysDictType selectDictTypeById(Long dictId)
- {
- return dictTypeMapper.selectDictTypeById(dictId);
- }
+ /**
+ * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁
+ *
+ * @param dictType 瀛楀吀绫诲瀷
+ * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅
+ */
+ @Override
+ public List<SysDictData> selectDictDataByType(String dictType) {
+ List<SysDictData> dictDatas = DictUtils.getDictCache(dictType);
+ if (CollUtil.isNotEmpty(dictDatas)) {
+ return dictDatas;
+ }
+ dictDatas = dictDataMapper.selectDictDataByType(dictType);
+ if (CollUtil.isNotEmpty(dictDatas)) {
+ DictUtils.setDictCache(dictType, dictDatas);
+ return dictDatas;
+ }
+ return null;
+ }
- /**
- * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ淇℃伅
- *
- * @param dictType 瀛楀吀绫诲瀷
- * @return 瀛楀吀绫诲瀷
- */
- @Override
- public SysDictType selectDictTypeByType(String dictType)
- {
- return dictTypeMapper.selectDictTypeByType(dictType);
- }
+ /**
+ * 鏍规嵁瀛楀吀绫诲瀷ID鏌ヨ淇℃伅
+ *
+ * @param dictId 瀛楀吀绫诲瀷ID
+ * @return 瀛楀吀绫诲瀷
+ */
+ @Override
+ public SysDictType selectDictTypeById(Long dictId) {
+ return getById(dictId);
+ }
- /**
- * 鎵归噺鍒犻櫎瀛楀吀绫诲瀷淇℃伅
- *
- * @param dictIds 闇�瑕佸垹闄ょ殑瀛楀吀ID
- * @return 缁撴灉
- */
- @Override
- public int deleteDictTypeByIds(Long[] dictIds)
- {
- for (Long dictId : dictIds)
- {
- SysDictType dictType = selectDictTypeById(dictId);
- if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0)
- {
- throw new CustomException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", dictType.getDictName()));
- }
- }
- int count = dictTypeMapper.deleteDictTypeByIds(dictIds);
- if (count > 0)
- {
- DictUtils.clearDictCache();
- }
- return count;
- }
+ /**
+ * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ淇℃伅
+ *
+ * @param dictType 瀛楀吀绫诲瀷
+ * @return 瀛楀吀绫诲瀷
+ */
+ @Override
+ public SysDictType selectDictTypeByType(String dictType) {
+ return getOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType));
+ }
- /**
- * 娓呯┖缂撳瓨鏁版嵁
- */
- @Override
- public void clearCache()
- {
- DictUtils.clearDictCache();
- }
+ /**
+ * 鎵归噺鍒犻櫎瀛楀吀绫诲瀷淇℃伅
+ *
+ * @param dictIds 闇�瑕佸垹闄ょ殑瀛楀吀ID
+ * @return 缁撴灉
+ */
+ @Override
+ public void deleteDictTypeByIds(Long[] dictIds) {
+ for (Long dictId : dictIds) {
+ SysDictType dictType = selectDictTypeById(dictId);
+ if (dictDataMapper.selectCount(new LambdaQueryWrapper<SysDictData>()
+ .eq(SysDictData::getDictType, dictType.getDictType())) > 0) {
+ throw new CustomException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", dictType.getDictName()));
+ }
+ DictUtils.removeDictCache(dictType.getDictType());
+ }
+ baseMapper.deleteBatchIds(Arrays.asList(dictIds));
+ }
- /**
- * 鏂板淇濆瓨瀛楀吀绫诲瀷淇℃伅
- *
- * @param dictType 瀛楀吀绫诲瀷淇℃伅
- * @return 缁撴灉
- */
- @Override
- public int insertDictType(SysDictType dictType)
- {
- int row = dictTypeMapper.insertDictType(dictType);
- if (row > 0)
- {
- DictUtils.clearDictCache();
- }
- return row;
- }
+ /**
+ * 鍔犺浇瀛楀吀缂撳瓨鏁版嵁
+ */
+ @Override
+ public void loadingDictCache() {
+ List<SysDictType> dictTypeList = list();
+ for (SysDictType dictType : dictTypeList) {
+ List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
+ DictUtils.setDictCache(dictType.getDictType(), dictDatas);
+ }
+ }
- /**
- * 淇敼淇濆瓨瀛楀吀绫诲瀷淇℃伅
- *
- * @param dictType 瀛楀吀绫诲瀷淇℃伅
- * @return 缁撴灉
- */
- @Override
- @Transactional
- public int updateDictType(SysDictType dictType)
- {
- SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId());
- dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType());
- int row = dictTypeMapper.updateDictType(dictType);
- if (row > 0)
- {
- DictUtils.clearDictCache();
- }
- return row;
- }
+ /**
+ * 娓呯┖瀛楀吀缂撳瓨鏁版嵁
+ */
+ @Override
+ public void clearDictCache() {
+ DictUtils.clearDictCache();
+ }
- /**
- * 鏍¢獙瀛楀吀绫诲瀷绉版槸鍚﹀敮涓�
- *
- * @param dict 瀛楀吀绫诲瀷
- * @return 缁撴灉
- */
- @Override
- public String checkDictTypeUnique(SysDictType dict)
- {
- Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId();
- SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType());
- if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue())
- {
- return UserConstants.NOT_UNIQUE;
- }
- return UserConstants.UNIQUE;
- }
+ /**
+ * 閲嶇疆瀛楀吀缂撳瓨鏁版嵁
+ */
+ @Override
+ public void resetDictCache() {
+ clearDictCache();
+ loadingDictCache();
+ }
+
+ /**
+ * 鏂板淇濆瓨瀛楀吀绫诲瀷淇℃伅
+ *
+ * @param dict 瀛楀吀绫诲瀷淇℃伅
+ * @return 缁撴灉
+ */
+ @Override
+ public int insertDictType(SysDictType dict) {
+ int row = baseMapper.insert(dict);
+ if (row > 0) {
+ DictUtils.setDictCache(dict.getDictType(), null);
+ }
+ return row;
+ }
+
+ /**
+ * 淇敼淇濆瓨瀛楀吀绫诲瀷淇℃伅
+ *
+ * @param dict 瀛楀吀绫诲瀷淇℃伅
+ * @return 缁撴灉
+ */
+ @Override
+ @Transactional
+ public int updateDictType(SysDictType dict) {
+ SysDictType oldDict = getById(dict.getDictId());
+ dictDataMapper.update(null, new LambdaUpdateWrapper<SysDictData>()
+ .set(SysDictData::getDictType, dict.getDictType())
+ .eq(SysDictData::getDictType, oldDict.getDictType()));
+ int row = baseMapper.updateById(dict);
+ if (row > 0) {
+ List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
+ DictUtils.setDictCache(dict.getDictType(), dictDatas);
+ }
+ return row;
+ }
+
+ /**
+ * 鏍¢獙瀛楀吀绫诲瀷绉版槸鍚﹀敮涓�
+ *
+ * @param dict 瀛楀吀绫诲瀷
+ * @return 缁撴灉
+ */
+ @Override
+ public String checkDictTypeUnique(SysDictType dict) {
+ Long dictId = Validator.isNull(dict.getDictId()) ? -1L : dict.getDictId();
+ SysDictType dictType = getOne(new LambdaQueryWrapper<SysDictType>()
+ .eq(SysDictType::getDictType, dict.getDictType())
+ .last("limit 1"));
+ if (Validator.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) {
+ return UserConstants.NOT_UNIQUE;
+ }
+ return UserConstants.UNIQUE;
+ }
}
--
Gitblit v1.9.3