xingjinshuang
2024-12-18 77535f97d178eb7411b8649a1839934cb4a02249
@xingjs@20241218@修改实体库查询系列接口,返回实体库相关属性信息
已修改1个文件
49 ■■■■■ 文件已修改
src/main/java/com/se/simu/service/Impl/ProjectRelatedServiceImpl.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/Impl/ProjectRelatedServiceImpl.java
@@ -7,19 +7,17 @@
import cn.hutool.crypto.asymmetric.RSA;
import com.alibaba.fastjson.JSONObject;
import com.se.simu.constant.CacheConstants;
import com.se.simu.constant.RedisCache;
import com.se.simu.domain.EntityTypeInfo;
import com.se.simu.domain.LoginParams;
import com.se.simu.helper.CaffeineHelper;
import com.se.simu.service.ProjectRelatedService;
import com.se.simu.utils.CustomWebClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
@@ -27,18 +25,11 @@
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@Slf4j
@Service
public class ProjectRelatedServiceImpl implements ProjectRelatedService {
    @Resource
    private RedisCache redisCache;
    @Resource
    public RedisTemplate redisTemplate;
    // 公钥地址
@@ -75,8 +66,8 @@
                    log.info("statusCode = " + statusCode);
                    String data = postResponseJson.getString("data");
                    // 缓存data,并设置1小时有效期
                    redisCache.deleteObject(CacheConstants.USER_CACHE_KEY + "rsa_data_set");
                    redisCache.setCacheObject(CacheConstants.USER_CACHE_KEY + "rsa_data_set", data, 1, TimeUnit.HOURS);
                    CaffeineHelper.remove(CacheConstants.USER_CACHE_KEY + "rsa_data_set");
                    CaffeineHelper.put(CacheConstants.USER_CACHE_KEY + "rsa_data_set", data);
                    log.info("publicKey = " + data);
                } catch (Exception e) {
                    log.info("Failed to parse JSON: " + e.getMessage());
@@ -97,13 +88,13 @@
    @Override
    public Object loginEntity(LoginParams loginParams) {
        // 判断redis中缓存是否存在(过期)
        Boolean isExists = redisCache.hasKey(CacheConstants.USER_CACHE_KEY + "entity_db_response");
        boolean isExists = Objects.nonNull(CaffeineHelper.getMd5(CacheConstants.USER_CACHE_KEY + "entity_db_response"));
        if (isExists) {
            return JSONObject.parseObject(redisCache.getCacheObject(CacheConstants.USER_CACHE_KEY + "entity_db_response"));
            return JSONObject.parseObject((String) CaffeineHelper.get(CacheConstants.USER_CACHE_KEY + "entity_db_response"));
        }
        // 设置请求体
        // 获取私钥和公钥,长度必须是16、24或32
        String publicKey = redisCache.getCacheObject(CacheConstants.USER_CACHE_KEY + "rsa_data_set");
        String publicKey = (String) CaffeineHelper.get(CacheConstants.USER_CACHE_KEY + "rsa_data_set");
        // 假设从Redis中获取到用户名,判断
        if (!StringUtils.isNotBlank(publicKey)) {
            // 缓存中没有用户名,则进行登录
@@ -117,7 +108,7 @@
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        publicKey = redisCache.getCacheObject(CacheConstants.USER_CACHE_KEY + "rsa_data_set");
        publicKey = (String) CaffeineHelper.get(CacheConstants.USER_CACHE_KEY + "rsa_data_set");
        log.info("publicKey = " + publicKey);
        // 公钥加密
        AsymmetricCrypto rsa = SecureUtil.rsa(null, publicKey);
@@ -141,11 +132,11 @@
                String data = JSONObject.parseObject(response).getString("data");
                String token = JSONObject.parseObject(data).getString("token");
                // 设置data到Redis中
                redisCache.deleteObject(CacheConstants.USER_CACHE_KEY + "entity_db_response");
                redisCache.setCacheObject(CacheConstants.USER_CACHE_KEY + "entity_db_response", response, 1, TimeUnit.HOURS);
                CaffeineHelper.remove(CacheConstants.USER_CACHE_KEY + "entity_db_response");
                CaffeineHelper.put(CacheConstants.USER_CACHE_KEY + "entity_db_response", response);
                // 设置data到Redis中
                redisCache.deleteObject(CacheConstants.USER_CACHE_KEY + "entity_db_token");
                redisCache.setCacheObject(CacheConstants.USER_CACHE_KEY + "entity_db_token", token, 1, TimeUnit.HOURS);
                CaffeineHelper.remove(CacheConstants.USER_CACHE_KEY + "entity_db_token");
                CaffeineHelper.put(CacheConstants.USER_CACHE_KEY + "entity_db_token", token);
            } else {
                // 登录失败
                log.error("登录失败 $= " + response);
@@ -224,10 +215,10 @@
     */
    @Override
    public Object getEntityPublicKey() {
        // 判断redis中缓存是否存在(过期)
        Boolean isExists = redisCache.hasKey(CacheConstants.USER_CACHE_KEY + "EntityPublicKey");
        // 判断中缓存是否存在(过期)
        boolean isExists = Objects.nonNull(CaffeineHelper.getMd5(CacheConstants.USER_CACHE_KEY + "EntityPublicKey"));
        if (isExists) {
            return JSONObject.parseObject(redisCache.getCacheObject(CacheConstants.USER_CACHE_KEY + "EntityPublicKey"));
            return JSONObject.parseObject((String) CaffeineHelper.get(CacheConstants.USER_CACHE_KEY + "EntityPublicKey"));
        }
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
@@ -242,8 +233,8 @@
                    log.info("statusCode = " + statusCode);
                    String data = postResponseJson.getString("data");
                    // 缓存data,并设置1小时有效期
                    redisCache.deleteObject(CacheConstants.USER_CACHE_KEY + "EntityPublicKey");
                    redisCache.setCacheObject(CacheConstants.USER_CACHE_KEY + "EntityPublicKey", response, 1, TimeUnit.HOURS);
                    CaffeineHelper.remove(CacheConstants.USER_CACHE_KEY + "EntityPublicKey");
                    CaffeineHelper.put(CacheConstants.USER_CACHE_KEY + "EntityPublicKey", response);
                    log.info("EntityPublicKey = " + data);
                } catch (Exception e) {
                    log.info("Failed to parse JSON: " + e.getMessage());
@@ -265,7 +256,7 @@
    public Object getDbLits() {
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String token = redisCache.getCacheObject(CacheConstants.USER_CACHE_KEY + "entity_db_token");
        String token = (String) CaffeineHelper.get(CacheConstants.USER_CACHE_KEY + "entity_db_token");
        log.info("token = " + token);
        // 添加form参数
        HashMap<String, Object> params = new HashMap<>();
@@ -282,8 +273,8 @@
                    log.info("statusCode = " + statusCode);
                    String data = postResponseJson.getString("data");
                    // 缓存data,并设置1小时有效期
                    redisCache.deleteObject(CacheConstants.USER_CACHE_KEY + "EntityDbNameList");
                    redisCache.setCacheObject(CacheConstants.USER_CACHE_KEY + "EntityDbNameList", response, 1, TimeUnit.HOURS);
                    CaffeineHelper.remove(CacheConstants.USER_CACHE_KEY + "EntityDbNameList");
                    CaffeineHelper.put(CacheConstants.USER_CACHE_KEY + "EntityDbNameList", response);
                    log.info("EntityDbNameList = " + data);
                } catch (Exception e) {
                    log.info("Failed to parse JSON: " + e.getMessage());
@@ -299,7 +290,7 @@
    public Object getEntityTypeInfo(EntityTypeInfo entityTypeInfo) {
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String token = redisCache.getCacheObject(CacheConstants.USER_CACHE_KEY + "entity_db_token");
        String token = (String) CaffeineHelper.get(CacheConstants.USER_CACHE_KEY + "entity_db_token");
        log.info("token = " + token);
        // 添加form参数
        HashMap<String, Object> params = new HashMap<>();