浏览代码

通过id获取公司

lyhzzz 3 年之前
父节点
当前提交
aa66af08d9

+ 18 - 17
platform-common/src/main/java/com/platform/service/impl/ZhiHouseService.java

@@ -196,23 +196,6 @@ public class ZhiHouseService {
         return responseEntity.getBody().getMessage();
     }
 
-    public JSONObject getComponyInfo(String phone) {
-        if(org.apache.commons.lang3.StringUtils.isBlank(phone)){
-            throw new CommonBaseException(ResultCodeEnum.D101 , "入参不全,无法获取四维场景列表");
-        }
-        String url = zhiHouseHost + "company/getCompony";
-        Map<String ,Object> params = new HashMap<>(1);
-        params.put("phone",phone);
-        ResponseEntity<ReturnDTO> responseEntity = restTemplate.postForEntity(url,params,ReturnDTO.class);
-        if(responseEntity.getStatusCode()!= HttpStatus.OK){
-            throw new CommonBaseException(ResultCodeEnum.D100);
-        }
-        if (responseEntity.getBody().getCode() != 200) {
-            throw new CommonBaseException(ResultCodeEnum.D100,responseEntity.getBody().getError());
-        }
-        //把信息封装为json
-        return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getMessage()));
-    }
 
     public List<TbUser> getSysUserListByDeptIds(Long deptId) {
         Map<String, Object> mp = new HashMap<>();
@@ -354,4 +337,22 @@ public class ZhiHouseService {
         List<String> list = (List<String>) responseEntity.getBody().getMessage();
         return list;
     }
+
+    public JSONObject getCompanyId(Long companyId) {
+        if(companyId == null){
+            throw new CommonBaseException(ResultCodeEnum.D101 , "入参不全,无法获取四维场景列表");
+        }
+        String url = zhiHouseHost + "company/getCompony";
+        Map<String ,Object> params = new HashMap<>(1);
+        params.put("id",companyId);
+        ResponseEntity<ReturnDTO> responseEntity = restTemplate.postForEntity(url,params,ReturnDTO.class);
+        if(responseEntity.getStatusCode()!= HttpStatus.OK){
+            throw new CommonBaseException(ResultCodeEnum.D100);
+        }
+        if (responseEntity.getBody().getCode() != 200) {
+            throw new CommonBaseException(ResultCodeEnum.D100,responseEntity.getBody().getError());
+        }
+        //把信息封装为json
+        return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getMessage()));
+    }
 }

+ 7 - 5
platform-common/src/main/java/com/platform/shiro/UserRealm.java

@@ -100,11 +100,13 @@ public class UserRealm extends AuthorizingRealm {
         Session session = subject.getSession(true);
         if (!ObjectUtils.isEmpty(user.getCompanyId())) {
             // 获取用户所在企业信息
-            JSONObject componyInfo = zhiHouseService.getComponyInfo(user.getPhone());
-            user.setCompanyName(componyInfo.getString("name"));
-            user.setCompanyId(componyInfo.getLong("id"));
-            user.setCompanyManagerPhoneNum(componyInfo.getString("phone"));
-            user.setCompanyExpirationDate(componyInfo.getDate("expirationTime"));
+            JSONObject componyInfo = zhiHouseService.getCompanyId(user.getCompanyId());
+            if(componyInfo !=null){
+                user.setCompanyName(componyInfo.getString("name"));
+                user.setCompanyId(componyInfo.getLong("id"));
+                user.setCompanyManagerPhoneNum(componyInfo.getString("phone"));
+                user.setCompanyExpirationDate(componyInfo.getDate("expirationTime"));
+            }
         }
         session.setAttribute(Constant.CURRENT_USER, user);
         SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, token, getName());