|
|
@@ -8,15 +8,16 @@ import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
-import com.sckw.system.api.model.dto.res.SysDictResDto;
|
|
|
+import com.sckw.system.api.model.dto.res.*;
|
|
|
import com.sckw.system.dao.SysDictDao;
|
|
|
+import com.sckw.system.model.KwsUser;
|
|
|
import com.sckw.system.model.SysDict;
|
|
|
+import com.sckw.system.service.KwsUserService;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author czh
|
|
|
@@ -30,13 +31,26 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
|
|
|
@Autowired
|
|
|
private SysDictDao sysDictDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private KwsUserService kwsUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RemoteBaseService remoteBaseService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param type 类型
|
|
|
+ * @return SysDictResDto
|
|
|
+ * @desc: 根据类型id查字典,先查redis,没查到查数据库,查出来了存redis
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/7/5
|
|
|
+ */
|
|
|
@Override
|
|
|
- public List<SysDictResDto> queryDictByTypeId(Long typeId) {
|
|
|
- String key = Global.REDIS_SYS_DICT_PREFIX + typeId;
|
|
|
+ public List<SysDictResDto> queryDictByType(String type) {
|
|
|
+ String key = Global.REDIS_SYS_DICT_TYPE_PREFIX + type;
|
|
|
String dictCache = RedissonUtils.getString(key);
|
|
|
//从redis查,查不到从数据库查,并写入redis
|
|
|
if (StringUtils.isBlank(dictCache)) {
|
|
|
- List<SysDict> sysDictList = sysDictDao.queryByType(typeId);
|
|
|
+ List<SysDict> sysDictList = sysDictDao.queryByType(type);
|
|
|
if (CollectionUtils.isEmpty(sysDictList)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
@@ -48,4 +62,139 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
|
|
|
return JSONObject.parseArray(dictCache, SysDictResDto.class);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param type 字典类型,value key
|
|
|
+ * @return SysDictResDto
|
|
|
+ * @desc: 根据字典类型和key查
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/7/7
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SysDictResDto queryDictByTypeAndValue(String type, String value) {
|
|
|
+ String key = Global.REDIS_SYS_DICT_PREFIX + type + "#" + value;
|
|
|
+ String dictCache = RedissonUtils.getString(key);
|
|
|
+ //从redis查,查不到从数据库查,并写入redis
|
|
|
+ if (StringUtils.isBlank(dictCache)) {
|
|
|
+ SysDict sysDict = sysDictDao.queryByTypeAndValue(type, value);
|
|
|
+ if (Objects.isNull(sysDict)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ SysDictResDto sysDictResDto = new SysDictResDto();
|
|
|
+ BeanUtils.copyProperties(sysDict, sysDictResDto);
|
|
|
+ RedissonUtils.putString(key, JSON.toJSONString(sysDictResDto), Global.COMMON_EXPIRE);
|
|
|
+ return sysDictResDto;
|
|
|
+ }
|
|
|
+ return JSONObject.parseObject(dictCache, SysDictResDto.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param type 字典类型,value key
|
|
|
+ * @return SysDictGroupResDto
|
|
|
+ * @desc: 根据字典类型和key查字典组
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/7/7
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SysDictGroupResDto queryDictGroupByTypeAndValue(String type, String value) {
|
|
|
+ String key = Global.REDIS_SYS_DICT_GROUP_PREFIX + type + "#" + value;
|
|
|
+ String dictCache = RedissonUtils.getString(key);
|
|
|
+ //从redis查,查不到从数据库查,并写入redis
|
|
|
+ if (StringUtils.isBlank(dictCache)) {
|
|
|
+ List<SysDict> list = sysDictDao.selectAll();
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Optional<SysDict> first = list.stream().filter(item -> item.getType().equals(type) && item.getValue().equals(value)).findFirst();
|
|
|
+ if (first.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ SysDictGroupResDto sysDictGroupResDto = new SysDictGroupResDto();
|
|
|
+ BeanUtils.copyProperties(first.get(), sysDictGroupResDto);
|
|
|
+ sysDictGroupResDto.setChild(getChild(sysDictGroupResDto.getId(), list));
|
|
|
+ RedissonUtils.putString(key, JSON.toJSONString(sysDictGroupResDto), Global.COMMON_EXPIRE);
|
|
|
+ return sysDictGroupResDto;
|
|
|
+ }
|
|
|
+ return JSONObject.parseObject(dictCache, SysDictGroupResDto.class);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param entId 企业id
|
|
|
+ * @return EntCacheResDto
|
|
|
+ * @desc: 从缓存查企业信息
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/7/7
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public EntCacheResDto queryEntCacheById(Long entId) {
|
|
|
+ String key = Global.REDIS_ENTERPRISE_PREFIX + entId;
|
|
|
+ String dictCache = RedissonUtils.getString(key);
|
|
|
+ //从redis查,查不到从数据库查,并写入redis
|
|
|
+ if (StringUtils.isBlank(dictCache)) {
|
|
|
+ KwsEnterpriseResDto kwsEnterpriseResDto = remoteBaseService.queryEnterpriseById(entId);
|
|
|
+ if (Objects.isNull(kwsEnterpriseResDto)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ EntCacheResDto entCacheResDto = new EntCacheResDto();
|
|
|
+ BeanUtils.copyProperties(kwsEnterpriseResDto, entCacheResDto);
|
|
|
+ entCacheResDto.setDeptInfo(remoteBaseService.queryDeftInfoByEntId(entId));
|
|
|
+ entCacheResDto.setCertificateInfo(remoteBaseService.queryCertificateByEntId(entId));
|
|
|
+ RedissonUtils.putString(key, JSON.toJSONString(entCacheResDto), Global.COMMON_EXPIRE);
|
|
|
+ return entCacheResDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ return JSONObject.parseObject(dictCache, EntCacheResDto.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserCacheResDto queryUserCacheById(Long userId) {
|
|
|
+ String key = Global.REDIS_USER_PREFIX + userId;
|
|
|
+ String dictCache = RedissonUtils.getString(key);
|
|
|
+ //从redis查,查不到从数据库查,并写入redis
|
|
|
+ if (StringUtils.isBlank(dictCache)) {
|
|
|
+ KwsUser kwsUser = kwsUserService.selectByKey(userId);
|
|
|
+ if (Objects.isNull(kwsUser)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ UserCacheResDto userCacheResDto = new UserCacheResDto();
|
|
|
+ BeanUtils.copyProperties(kwsUser, userCacheResDto);
|
|
|
+ userCacheResDto.setRoleInfo(remoteBaseService.queryRoleInfoByUserId(userId));
|
|
|
+
|
|
|
+ List<KwsUserDeptResDto> kwsUserDeptResDtos = remoteBaseService.queryUserDeptByUserId(userId);
|
|
|
+ if (!CollectionUtils.isEmpty(kwsUserDeptResDtos)) {
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param id 父id,需要遍历的list
|
|
|
+ * @return SysDictGroupResDto
|
|
|
+ * @desc: 构建字典组
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/7/7
|
|
|
+ */
|
|
|
+ private List<SysDictGroupResDto> getChild(Long id, List<SysDict> list) {
|
|
|
+ List<SysDictGroupResDto> child = new ArrayList<>();
|
|
|
+ for (SysDict sysDict : list) {
|
|
|
+ if (sysDict.getParentId().equals(String.valueOf(id))) {
|
|
|
+ SysDictGroupResDto sysDictGroupResDto = new SysDictGroupResDto();
|
|
|
+ BeanUtils.copyProperties(sysDict, sysDictGroupResDto);
|
|
|
+ child.add(sysDictGroupResDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(child)) {
|
|
|
+ for (SysDictGroupResDto sysDictGroupResDto : child) {
|
|
|
+ sysDictGroupResDto.setChild(getChild(sysDictGroupResDto.getId(), list));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return child;
|
|
|
+ }
|
|
|
+
|
|
|
}
|