xucaiqin před 2 měsíci
rodič
revize
d74d3ec216

+ 11 - 4
sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/server/KwsEnterpriseServerController.java

@@ -1,14 +1,12 @@
 package com.sckw.system.controller.server;
 
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
 import com.sckw.system.model.vo.res.EntInfo;
 import com.sckw.system.service.KwsEnterpriseService;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.Data;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -35,4 +33,13 @@ public class KwsEnterpriseServerController {
     public List<EntInfo> queryEntInfos(@RequestBody List<Long> entIds) {
         return kwsEntService.queryEntInfoByKeys(entIds);
     }
+
+    /**
+     * @return HttpResult
+     * @desc: 根据企业id列表查询企业信息
+     */
+    @GetMapping("queryEntCacheById")
+    public EntCacheResDto queryEntCacheById(@RequestParam("entId") Long entId) {
+        return kwsEntService.queryEntCacheById(entId);
+    }
 }

+ 56 - 4
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsEnterpriseService.java

@@ -30,10 +30,9 @@ import com.sckw.stream.enums.MessageEnum;
 import com.sckw.stream.model.UserInfo;
 import com.sckw.system.api.RemoteUserService;
 import com.sckw.system.api.model.dto.req.RegisterReqDto;
-import com.sckw.system.api.model.dto.res.EntCacheResDto;
-import com.sckw.system.api.model.dto.res.KwsEntDeptDto;
-import com.sckw.system.api.model.dto.res.RegisterResDto;
+import com.sckw.system.api.model.dto.res.*;
 import com.sckw.system.dao.*;
+import com.sckw.system.dubbo.RemoteBaseService;
 import com.sckw.system.dubbo.RemoteSystemServiceImpl;
 import com.sckw.system.model.*;
 import com.sckw.system.model.pojo.FindEntListPojo;
@@ -51,6 +50,7 @@ import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.redisson.api.RSet;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -122,7 +122,8 @@ public class KwsEnterpriseService {
 
     @Autowired
     private KwsSpecialDao specialDao;
-
+    @Autowired
+    private RemoteBaseService remoteBaseService;
     private final KwsEntTypeRepository kwsEntTypeRepository;
     private final KwsEnterpriseRepository kwsEnterpriseRepository;
 
@@ -1686,4 +1687,55 @@ public class KwsEnterpriseService {
         List<KwsEnterprise> kwsEnterprises = kwsEnterpriseDao.selectList(new LambdaQueryWrapper<KwsEnterprise>().eq(KwsEnterprise::getPid, 0).eq(KwsEnterprise::getApproval, 1).eq(KwsEnterprise::getStatus, 0));
         return kwsEnterprises.stream().map(d -> BeanUtils.toBean(d, EntBaseInfo.class)).collect(Collectors.toList());
     }
+    @Nullable
+    private EntCacheResDto getEntCacheResDto(Long entId) {
+        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));
+        KwsUser kwsUser = remoteBaseService.queryManageByEntId(entId);
+        if (Objects.nonNull(kwsUser)) {
+            entCacheResDto.setContactsId(kwsUser.getId());
+            entCacheResDto.setContacts(kwsUser.getName());
+            entCacheResDto.setPhone(kwsUser.getPhone());
+        }
+        List<EntTypeResDto> entTypeResDtos = remoteBaseService.queryEntTypeById(entId);
+        if (CollectionUtils.isNotEmpty(entTypeResDtos)) {
+            entCacheResDto.setEntTypes(String.join(Global.COMMA, entTypeResDtos.stream().map(EntTypeResDto::getType).map(String::valueOf).distinct().toList()));
+            entCacheResDto.setEntTypeNames(EntTypeEnum.getNames(entCacheResDto.getEntTypes()));
+        }
+        return entCacheResDto;
+    }
+    public EntCacheResDto queryEntCacheById(Long entId) {
+        if (Objects.isNull(entId)) {
+            return null;
+        }
+        String key = Global.REDIS_ENTERPRISE_PREFIX + entId;
+        String dictCache = RedissonUtils.getString(key);
+        //从redis查,查不到从数据库查,并写入redis
+        if (StringUtils.isBlank(dictCache)) {
+            EntCacheResDto entCacheResDto = getEntCacheResDto(entId);
+            if (Objects.isNull(entCacheResDto)) {
+                return null;
+            }
+            RedissonUtils.putString(key, JSON.toJSONString(entCacheResDto), Global.COMMON_EXPIRE);
+            return entCacheResDto;
+        }
+
+        EntCacheResDto entCacheResDto = JSONObject.parseObject(dictCache, EntCacheResDto.class);
+        if (Objects.isNull(entCacheResDto.getContactsId())) {
+            entCacheResDto = getEntCacheResDto(entId);
+            if (Objects.isNull(entCacheResDto)) {
+                return null;
+            }
+        }
+
+        RedissonUtils.putString(key, dictCache, Global.COMMON_EXPIRE);
+        return entCacheResDto;
+    }
 }