Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
60204813
Commit
60204813
authored
Jun 25, 2021
by
郭武斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*)删除冗余代码
parent
3b7d53fa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1048 additions
and
1052 deletions
+1048
-1052
BaseController.java
...ejoin/amos/boot/biz/common/controller/BaseController.java
+191
-195
ControllerAop.java
...m/yeejoin/amos/boot/module/jcs/biz/aop/ControllerAop.java
+128
-128
FeignAop.java
...va/com/yeejoin/amos/boot/module/jcs/biz/aop/FeignAop.java
+69
-69
UserController.java
...n/amos/boot/module/jcs/biz/controller/UserController.java
+346
-346
RemoteSecurityService.java
...ot/module/jcs/biz/service/impl/RemoteSecurityService.java
+314
-314
No files found.
amos-boot-biz-common/src/main/java/com/yeejoin/amos/boot/biz/common/controller/BaseController.java
View file @
60204813
...
...
@@ -28,22 +28,22 @@ import java.util.HashMap;
@RestController
@RequestMapping
(
"/base"
)
public
class
BaseController
{
/**
* 成功返回状态
*/
protected
static
final
String
SUCCESS
=
"SUCCESS"
;
/**
* 失败返回状态
*/
protected
static
final
String
FAILED
=
"FAILED"
;
/**
* 默认页大小
*/
protected
static
final
int
DEFAULT_PAGE_SIZE
=
10
;
@Autowired
protected
HttpServletRequest
request
;
//
//
/**
//
* 成功返回状态
//
*/
//
protected static final String SUCCESS = "SUCCESS";
//
/**
//
* 失败返回状态
//
*/
//
protected static final String FAILED = "FAILED";
//
/**
//
* 默认页大小
//
*/
//
protected static final int DEFAULT_PAGE_SIZE = 10;
//
//
@Autowired
//
protected HttpServletRequest request;
@Autowired
private
RedisUtils
redisUtils
;
...
...
@@ -52,92 +52,88 @@ public class BaseController {
* 获取token
**/
protected
String
getToken
()
{
String
authToken
=
request
.
getHeader
(
"token"
);
if
(
authToken
==
null
)
{
authToken
=
request
.
getHeader
(
"X-Access-Token"
);
}
return
authToken
;
return
RequestContext
.
getToken
();
}
/**
* 获取Product
**/
protected
String
getProduct
()
{
String
product
=
request
.
getHeader
(
"product"
);
if
(
product
==
null
)
{
product
=
request
.
getParameter
(
"product"
);
}
return
product
;
}
/**
* 获取AppKey
**/
protected
String
getAppKey
()
{
String
appKey
=
request
.
getHeader
(
"appKey"
);
if
(
appKey
==
null
)
{
appKey
=
request
.
getParameter
(
"appKey"
);
}
return
appKey
;
}
/**
* redi缓存选择的用户信息key
*
* @param userId
* @param token
* @return
*/
// private String buildKey(String userId, String token) {
//
// return "region_" + userId + "_" + token;
//
// /**
// * 获取Product
// **/
// protected String getProduct() {
// String product = request.getHeader("product");
// if (product == null) {
// product = request.getParameter("product");
// }
// return product;
// }
//
// /**
// * 获取AppKey
// **/
// protected String getAppKey() {
// String appKey = request.getHeader("appKey");
// if (appKey == null) {
// appKey = request.getParameter("appKey");
// }
// return appKey;
// }
//
// /**
// * redi缓存选择的用户信息key
// *
// * @param userId
// * @param token
// * @return
// */
//// private String buildKey(String userId, String token) {
////
//// return "region_" + userId + "_" + token;
////
//// }
protected
String
buildKey
(
String
token
)
{
//由于用户id 不是接口携带参数,为了避免,公共字段填充时频繁访问平台,缓存用户信息时,
return
"region_"
+
token
;
}
/**
* 用户选择信息保存redis
*/
protected
void
saveSelectedOrgInfo
(
ReginParams
reginParams
)
{
//由于用户id 不是接口携带参数,为了避免,公共字段填充时频繁访问平台,缓存用户信息时,
redisUtils
.
set
(
buildKey
(
getToken
()),
JSONObject
.
toJSONString
(
reginParams
));
}
protected
void
saveUser
(
AgencyUserModel
agencyUserModel
)
{
//由于用户id 不是接口携带参数,为了避免,公共字段填充时频繁访问平台,缓存用户信息时,
redisUtils
.
set
(
getToken
(),
JSONObject
.
toJSONString
(
agencyUserModel
));
}
/**
* 获取结构code
*
* @return
*/
protected
String
getOrgCode
()
{
ReginParams
reginParams
=
getSelectedOrgInfo
();
if
(
reginParams
==
null
)
{
return
null
;
}
if
(
reginParams
.
getCompany
()
!=
null
)
{
return
reginParams
.
getCompany
().
getOrgCode
();
}
return
null
;
}
//
/**
//
* 用户选择信息保存redis
//
*/
//
protected void saveSelectedOrgInfo(ReginParams reginParams) {
//
//由于用户id 不是接口携带参数,为了避免,公共字段填充时频繁访问平台,缓存用户信息时,
//
redisUtils.set(buildKey(getToken()), JSONObject.toJSONString(reginParams));
//
//
}
//
//
protected void saveUser(AgencyUserModel agencyUserModel) {
//
//由于用户id 不是接口携带参数,为了避免,公共字段填充时频繁访问平台,缓存用户信息时,
//
redisUtils.set(getToken(), JSONObject.toJSONString(agencyUserModel));
//
//
}
//
//
/**
//
* 获取结构code
//
*
//
* @return
//
*/
//
protected String getOrgCode() {
//
ReginParams reginParams = getSelectedOrgInfo();
//
if (reginParams == null) {
//
return null;
//
}
//
if (reginParams.getCompany() != null) {
//
return reginParams.getCompany().getOrgCode();
//
}
//
//
return null;
//
}
//
/**
* 用户选择信心redis获取
**/
protected
ReginParams
getSelectedOrgInfo
()
{
//由于用户id 不是接口携带参数,为了避免,公共字段填充时频繁访问平台,缓存用户信息时,
// return JSONObject.parseObject(redisUtils.get(buildKey(getUserId(), getToken())).toString(), ReginParams.class);
return
JSONObject
.
parseObject
(
redisUtils
.
get
(
buildKey
(
getToken
())).
toString
(),
ReginParams
.
class
);
return
JSONObject
.
parseObject
(
redisUtils
.
get
(
buildKey
(
RequestContext
.
getToken
())).
toString
(),
ReginParams
.
class
);
}
/**
...
...
@@ -146,9 +142,9 @@ public class BaseController {
protected
AgencyUserModel
getUserInfo
()
{
AgencyUserModel
userModel
=
null
;
if
(
getToken
()
!=
null
)
{
RequestContext
.
setToken
(
getToken
());
RequestContext
.
setProduct
(
getProduct
());
RequestContext
.
setAppKey
(
getAppKey
());
//
RequestContext.setToken(getToken());
//
RequestContext.setProduct(getProduct());
//
RequestContext.setAppKey(getAppKey());
FeignClientResult
<?>
feignClientResult
;
try
{
feignClientResult
=
Privilege
.
agencyUserClient
.
getme
();
...
...
@@ -162,109 +158,109 @@ public class BaseController {
return
userModel
;
}
/**
* 获取当前登录用户id
**/
protected
String
getUserId
()
{
String
userId
=
null
;
if
(
getUserInfo
()
!=
null
)
{
userId
=
getUserInfo
().
getUserId
();
}
return
userId
;
}
/**
* 获取请求的cookies
*
* @return
*/
protected
HashMap
<
String
,
String
>
getCookInfoMap
()
{
HashMap
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
Cookie
[]
cookies
=
request
.
getCookies
();
if
(
cookies
!=
null
)
{
for
(
Cookie
ck
:
cookies
)
{
map
.
put
(
ck
.
getName
(),
ck
.
getValue
());
}
}
return
map
;
}
/**
* 获取登录用户getLoginOrgCode
**/
protected
String
getLoginOrgCode
(
ReginParams
reginParams
)
{
if
(
reginParams
==
null
)
{
return
null
;
}
if
(
reginParams
.
getDepartment
()
!=
null
)
{
return
reginParams
.
getDepartment
().
getOrgCode
();
}
if
(
reginParams
.
getCompany
()
!=
null
)
{
return
reginParams
.
getCompany
().
getOrgCode
();
}
return
null
;
}
/**
* 获取部门id
**/
protected
Long
getDepartmentId
(
ReginParams
reginParams
)
{
if
(
reginParams
==
null
)
{
return
null
;
}
if
(
reginParams
.
getDepartment
()
!=
null
)
{
return
reginParams
.
getDepartment
().
getSequenceNbr
();
}
return
null
;
}
/**
* 获取公司id
**/
protected
Long
getCompanyId
(
ReginParams
reginParams
)
{
if
(
reginParams
==
null
)
{
return
null
;
}
if
(
reginParams
.
getCompany
()
!=
null
)
{
return
reginParams
.
getCompany
().
getSequenceNbr
();
}
return
null
;
}
/**
* <pre>
* 提取错误异常中的错误消息
* </pre>
*
* <p>
* 当实体类中对属相注解了以下类似的注解,需要用try.catch语句捕获异常,使用 #getErrorMessage(Exception)
* 提取出异常信息NotNull(message = "属性不能为空!")
* </p>
*
* @param e
* @return
* @see {@code NotBlank} ... NotNull、NotEmpty...
* @see {@code Valid}
*/
public
String
getErrorMessage
(
Exception
e
)
{
StringBuilder
message
=
new
StringBuilder
();
if
(
e
instanceof
TransactionSystemException
)
{
TransactionSystemException
exception
=
(
TransactionSystemException
)
e
;
if
(
exception
.
getRootCause
()
instanceof
ConstraintViolationException
)
{
ConstraintViolationException
root
=
(
ConstraintViolationException
)
exception
.
getRootCause
();
root
.
getConstraintViolations
().
forEach
(
constraintViolation
->
{
message
.
append
(
constraintViolation
.
getMessageTemplate
());
});
}
else
{
message
.
append
(
e
.
getMessage
());
}
}
else
if
(
e
instanceof
ConstraintViolationException
)
{
((
ConstraintViolationException
)
e
).
getConstraintViolations
()
.
forEach
(
constraintViolation
->
message
.
append
(
constraintViolation
.
getMessageTemplate
()));
}
else
{
message
.
append
(
"操作异常!"
);
}
return
message
.
toString
();
}
//
//
/**
//
* 获取当前登录用户id
//
**/
//
protected String getUserId() {
//
String userId = null;
//
if (getUserInfo() != null) {
//
userId = getUserInfo().getUserId();
//
}
//
return userId;
//
}
//
//
/**
//
* 获取请求的cookies
//
*
//
* @return
//
*/
//
protected HashMap<String, String> getCookInfoMap() {
//
HashMap<String, String> map = new HashMap<String, String>();
//
Cookie[] cookies = request.getCookies();
//
if (cookies != null) {
//
for (Cookie ck : cookies) {
//
map.put(ck.getName(), ck.getValue());
//
}
//
}
//
return map;
//
}
//
//
/**
//
* 获取登录用户getLoginOrgCode
//
**/
//
protected String getLoginOrgCode(ReginParams reginParams) {
//
if (reginParams == null) {
//
return null;
//
}
//
if (reginParams.getDepartment() != null) {
//
return reginParams.getDepartment().getOrgCode();
//
}
//
if (reginParams.getCompany() != null) {
//
return reginParams.getCompany().getOrgCode();
//
}
//
return null;
//
}
//
//
/**
//
* 获取部门id
//
**/
//
protected Long getDepartmentId(ReginParams reginParams) {
//
if (reginParams == null) {
//
return null;
//
}
//
if (reginParams.getDepartment() != null) {
//
return reginParams.getDepartment().getSequenceNbr();
//
}
//
return null;
//
}
//
//
/**
//
* 获取公司id
//
**/
//
protected Long getCompanyId(ReginParams reginParams) {
//
if (reginParams == null) {
//
return null;
//
}
//
if (reginParams.getCompany() != null) {
//
return reginParams.getCompany().getSequenceNbr();
//
}
//
return null;
//
}
//
//
/**
//
* <pre>
//
* 提取错误异常中的错误消息
//
* </pre>
//
*
//
* <p>
//
* 当实体类中对属相注解了以下类似的注解,需要用try.catch语句捕获异常,使用 #getErrorMessage(Exception)
//
* 提取出异常信息NotNull(message = "属性不能为空!")
//
* </p>
//
*
//
* @param e
//
* @return
//
* @see {@code NotBlank} ... NotNull、NotEmpty...
//
* @see {@code Valid}
//
*/
//
public String getErrorMessage(Exception e) {
//
StringBuilder message = new StringBuilder();
//
if (e instanceof TransactionSystemException) {
//
TransactionSystemException exception = (TransactionSystemException) e;
//
if (exception.getRootCause() instanceof ConstraintViolationException) {
//
ConstraintViolationException root = (ConstraintViolationException) exception.getRootCause();
//
root.getConstraintViolations().forEach(constraintViolation -> {
//
message.append(constraintViolation.getMessageTemplate());
//
});
//
} else {
//
message.append(e.getMessage());
//
}
//
} else if (e instanceof ConstraintViolationException) {
//
((ConstraintViolationException) e).getConstraintViolations()
//
.forEach(constraintViolation -> message.append(constraintViolation.getMessageTemplate()));
//
} else {
//
message.append("操作异常!");
//
}
//
return message.toString();
//
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/aop/ControllerAop.java
View file @
60204813
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jcs
.
biz
.
aop
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.boot.biz.common.bo.CompanyBo
;
import
com.yeejoin.amos.boot.biz.common.bo.DepartmentBo
;
import
com.yeejoin.amos.boot.biz.common.bo.ReginParams
;
import
com.yeejoin.amos.boot.biz.common.bo.RoleBo
;
import
com.yeejoin.amos.boot.biz.common.utils.RedisUtils
;
import
com.yeejoin.amos.boot.module.jcs.biz.service.impl.RemoteSecurityService
;
import
com.yeejoin.amos.feign.privilege.model.AgencyUserModel
;
import
com.yeejoin.amos.feign.privilege.model.CompanyModel
;
import
com.yeejoin.amos.feign.privilege.model.DepartmentModel
;
import
com.yeejoin.amos.feign.privilege.model.RoleModel
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.typroject.tyboot.core.foundation.utils.Bean
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
/**
* controller层切面 用于用户数据缓存 供 sql自动填充使用
*
* @author Admin
*/
@Aspect
@Component
public
class
ControllerAop
{
/**
* saveUserRedis设置过期时间
*/
@Value
(
"${redis_region_time_second}"
)
private
Long
redisRegionTimeSecond
;
@Autowired
private
RemoteSecurityService
remoteSecurityService
;
@Autowired
private
RedisUtils
redisUtils
;
@Pointcut
(
"execution(public * com.yeejoin.amos.boot.module.jcs.biz.controller..*(..))"
)
public
void
userCache
()
{
}
@Before
(
"userCache()"
)
public
void
doBefore
(
JoinPoint
joinPoint
)
throws
Throwable
{
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attributes
.
getRequest
();
String
token
=
request
.
getHeader
(
"token"
);
if
(
token
!=
null
)
{
//验证token有效性,防止token失效
AgencyUserModel
userModel
;
try
{
userModel
=
remoteSecurityService
.
getAgencyUser
();
if
(
userModel
==
null
)
{
throw
new
Exception
(
"无法获取用户信息"
);
}
}
catch
(
Exception
e
)
{
//删除失效token缓存
redisUtils
.
del
(
buildKey
(
token
));
throw
new
RuntimeException
(
e
.
getMessage
());
}
// 不需要添加请求头的接口
String
[]
url
=
new
String
[]{
"/api/user/selectInfo"
,
"/api/user/save/curCompany"
};
// 获取请求路径
if
(
Arrays
.
asList
(
url
).
contains
(
request
.
getRequestURI
()))
{
// 暂无需要
}
else
{
if
(!
redisUtils
.
hasKey
(
buildKey
(
token
)))
{
saveUserRedis
(
userModel
,
token
);
}
}
}
System
.
out
.
println
(
redisUtils
.
get
(
buildKey
(
token
)));
}
public
void
saveUserRedis
(
AgencyUserModel
user
,
String
token
)
{
CompanyBo
company
=
new
CompanyBo
();
DepartmentBo
department
=
new
DepartmentBo
();
RoleBo
role
=
new
RoleBo
();
CompanyModel
companyM
=
user
.
getCompanys
().
get
(
0
);
Bean
.
copyExistPropertis
(
companyM
,
company
);
Map
<
Long
,
List
<
DepartmentModel
>>
mapDepartments
=
user
.
getCompanyDepartments
();
DepartmentModel
departmentM
=
mapDepartments
.
get
(
companyM
.
getSequenceNbr
()).
get
(
0
);
Bean
.
copyExistPropertis
(
departmentM
,
department
);
Map
<
Long
,
List
<
RoleModel
>>
roles
=
user
.
getOrgRoles
();
Long
sequenceNbr
;
if
(
departmentM
==
null
)
{
sequenceNbr
=
null
;
}
else
{
sequenceNbr
=
departmentM
.
getSequenceNbr
();
}
RoleModel
roleM
=
null
;
if
(
sequenceNbr
==
null
)
{
roleM
=
roles
.
get
(
companyM
.
getSequenceNbr
()).
get
(
0
);
}
else
{
roleM
=
roles
.
get
(
sequenceNbr
).
get
(
0
);
}
Bean
.
copyExistPropertis
(
roleM
,
role
);
ReginParams
reginParams
=
new
ReginParams
();
reginParams
.
setCompany
(
company
);
reginParams
.
setRole
(
role
);
reginParams
.
setDepartment
(
department
);
reginParams
.
setUserModel
(
user
);
redisUtils
.
set
(
buildKey
(
token
),
JSONObject
.
toJSONString
(
reginParams
),
redisRegionTimeSecond
);
}
public
String
buildKey
(
String
token
)
{
//由于用户id 不是接口携带参数,为了避免,公共字段填充时频繁访问平台,缓存用户信息时,
//return "region_" + userId + "_" + token;
return
"region_"
+
token
;
}
@AfterReturning
(
returning
=
"ret"
,
pointcut
=
"userCache()"
)
public
void
doAfterReturning
(
Object
ret
)
throws
Throwable
{
//统一redis管理
//package com.yeejoin.amos.boot.module.jcs.biz.aop;
//
//import com.alibaba.fastjson.JSONObject;
//import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
//import com.yeejoin.amos.boot.biz.common.bo.DepartmentBo;
//import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
//import com.yeejoin.amos.boot.biz.common.bo.RoleBo;
//import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
//import com.yeejoin.amos.boot.module.jcs.biz.service.impl.RemoteSecurityService;
//import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
//import com.yeejoin.amos.feign.privilege.model.CompanyModel;
//import com.yeejoin.amos.feign.privilege.model.DepartmentModel;
//import com.yeejoin.amos.feign.privilege.model.RoleModel;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//import org.typroject.tyboot.core.foundation.utils.Bean;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Map;
//
///**
// * controller层切面 用于用户数据缓存 供 sql自动填充使用
// *
// * @author Admin
// */
//@Aspect
//@Component
//public class ControllerAop {
// /**
// * saveUserRedis设置过期时间
// */
// @Value("${redis_region_time_second}")
// private Long redisRegionTimeSecond;
// @Autowired
// private RemoteSecurityService remoteSecurityService;
//
// @Autowired
// private RedisUtils redisUtils;
//
// @Pointcut("execution(public * com.yeejoin.amos.boot.module.jcs.biz.controller..*(..))")
// public void userCache() {
//
// }
//
// @Before("userCache()")
// public void doBefore(JoinPoint joinPoint) throws Throwable {
// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// HttpServletRequest request = attributes.getRequest();
// String token = request.getHeader("token");
// if (token != null) {
// GlobalCache.paramMap.remove(token);
// //验证token有效性,防止token失效
// AgencyUserModel userModel;
// try {
// userModel = remoteSecurityService.getAgencyUser();
// if (userModel == null) {
// throw new Exception("无法获取用户信息");
// }
// } catch (Exception e) {
// //删除失效token缓存
// redisUtils.del(buildKey(token));
// throw new RuntimeException(e.getMessage());
// }
// // 不需要添加请求头的接口
// String[] url = new String[]{"/api/user/selectInfo", "/api/user/save/curCompany"};
// // 获取请求路径
// if (Arrays.asList(url).contains(request.getRequestURI())) {
// // 暂无需要
// } else {
// if (!redisUtils.hasKey(buildKey(token))) {
// saveUserRedis(userModel, token);
// }
// }
// }
}
}
// System.out.println(redisUtils.get(buildKey(token)));
// }
//
// public void saveUserRedis(AgencyUserModel user, String token) {
// CompanyBo company = new CompanyBo();
// DepartmentBo department = new DepartmentBo();
// RoleBo role = new RoleBo();
// CompanyModel companyM = user.getCompanys().get(0);
// Bean.copyExistPropertis(companyM, company);
// Map<Long, List<DepartmentModel>> mapDepartments = user.getCompanyDepartments();
// DepartmentModel departmentM = mapDepartments.get(companyM.getSequenceNbr()).get(0);
// Bean.copyExistPropertis(departmentM, department);
// Map<Long, List<RoleModel>> roles = user.getOrgRoles();
// Long sequenceNbr;
// if (departmentM == null) {
// sequenceNbr = null;
// } else {
// sequenceNbr = departmentM.getSequenceNbr();
// }
// RoleModel roleM = null;
// if (sequenceNbr == null) {
// roleM = roles.get(companyM.getSequenceNbr()).get(0);
// } else {
// roleM = roles.get(sequenceNbr).get(0);
// }
// Bean.copyExistPropertis(roleM, role);
// ReginParams reginParams = new ReginParams();
// reginParams.setCompany(company);
// reginParams.setRole(role);
// reginParams.setDepartment(department);
// reginParams.setUserModel(user);
// redisUtils.set(buildKey(token), JSONObject.toJSONString(reginParams), redisRegionTimeSecond);
// }
// public String buildKey(String token) {
// //由于用户id 不是接口携带参数,为了避免,公共字段填充时频繁访问平台,缓存用户信息时,
// //return "region_" + userId + "_" + token;
// return "region_"+ token;
// }
//
// @AfterReturning(returning = "ret", pointcut = "userCache()")
// public void doAfterReturning(Object ret) throws Throwable {
// //统一redis管理
//// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//// HttpServletRequest request = attributes.getRequest();
//// String token = request.getHeader("token");
//// if (token != null) {
//// GlobalCache.paramMap.remove(token);
//// }
// }
//}
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/aop/FeignAop.java
View file @
60204813
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jcs
.
biz
.
aop
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.typroject.tyboot.core.foundation.context.RequestContext
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Arrays
;
/**
* feign请求header设置
* @author DELL
*
*/
@Aspect
@Component
public
class
FeignAop
{
@Pointcut
(
"execution(public * com.yeejoin.amos.boot.module.jcs.biz.service.impl.RemoteSecurityService.*(..))"
)
public
void
webLog
(){}
/**
* 前置通知:在连接点之前执行的通知
* @param joinPoint
* @throws Throwable
*/
@Before
(
"webLog()"
)
public
void
doBefore
(
JoinPoint
joinPoint
)
throws
Throwable
{
// 接收到请求,记录请求内容
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attributes
.
getRequest
();
//不需要添加请求头的接口
String
[]
url
=
new
String
[]{
"/api/user/mobile/login"
};
//获取请求路径
if
(
Arrays
.
asList
(
url
).
contains
(
request
.
getRequestURI
())){
//暂无需要
}
else
{
String
token
=
request
.
getHeader
(
"token"
);
String
product
=
request
.
getHeader
(
"product"
);
String
appKey
=
request
.
getHeader
(
"appKey"
);
if
(
token
==
null
||
product
==
null
||
appKey
==
null
||
""
.
equals
(
token
)||
""
.
equals
(
product
)||
""
.
equals
(
appKey
)){
//没有请求头信息直接转异常到403
throw
new
RuntimeException
(
"非法异常请求!请重新登录!"
);
}
RequestContext
.
setToken
(
token
);
RequestContext
.
setProduct
(
product
);
RequestContext
.
setAppKey
(
appKey
);
}
}
@AfterReturning
(
returning
=
"ret"
,
pointcut
=
"webLog()"
)
public
void
doAfterReturning
(
Object
ret
)
throws
Throwable
{
}
}
//
package com.yeejoin.amos.boot.module.jcs.biz.aop;
//
//
//
import org.aspectj.lang.JoinPoint;
//
import org.aspectj.lang.annotation.AfterReturning;
//
import org.aspectj.lang.annotation.Aspect;
//
import org.aspectj.lang.annotation.Before;
//
import org.aspectj.lang.annotation.Pointcut;
//
import org.springframework.stereotype.Component;
//
import org.springframework.web.context.request.RequestContextHolder;
//
import org.springframework.web.context.request.ServletRequestAttributes;
//
import org.typroject.tyboot.core.foundation.context.RequestContext;
//
//
import javax.servlet.http.HttpServletRequest;
//
import java.util.Arrays;
//
//
/
//
**
//
* feign请求header设置
//
* @author DELL
//
*
//
*/
//
@Aspect
//
@Component
//
public class FeignAop {
//
//
//
//
@Pointcut("execution(public * com.yeejoin.amos.boot.module.jcs.biz.service.impl.RemoteSecurityService.*(..))")
//
public void webLog(){}
//
//
/**
//
* 前置通知:在连接点之前执行的通知
//
* @param joinPoint
//
* @throws Throwable
//
*/
//
@Before("webLog()")
//
public void doBefore(JoinPoint joinPoint) throws Throwable {
//
// 接收到请求,记录请求内容
//
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//
HttpServletRequest request = attributes.getRequest();
//
//不需要添加请求头的接口
//
String[] url=new String[]{"/api/user/mobile/login"};
//
//获取请求路径
//
if(Arrays.asList(url).contains(request.getRequestURI())){
//
//暂无需要
//
}else{
//
//
String token = request.getHeader("token");
//
String product = request.getHeader("product");
//
String appKey = request.getHeader("appKey");
//
if(token==null||product==null||appKey==null||"".equals(token)||"".equals(product)||"".equals(appKey)){
//
//没有请求头信息直接转异常到403
//
throw new RuntimeException("非法异常请求!请重新登录!");
//
}
//
RequestContext.setToken(token);
//
RequestContext.setProduct(product);
//
RequestContext.setAppKey(appKey);
//
}
//
//
//
//
}
//
//
@AfterReturning(returning = "ret",pointcut = "webLog()")
//
public void doAfterReturning(Object ret) throws Throwable {
//
}
//
}
//
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/controller/UserController.java
View file @
60204813
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jcs
.
biz
.
controller
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
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.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.foundation.utils.Bean
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Maps
;
import
com.yeejoin.amos.boot.biz.common.bo.CompanyBo
;
import
com.yeejoin.amos.boot.biz.common.bo.DepartmentBo
;
import
com.yeejoin.amos.boot.biz.common.bo.ReginParams
;
import
com.yeejoin.amos.boot.biz.common.bo.RoleBo
;
import
com.yeejoin.amos.boot.biz.common.controller.BaseController
;
import
com.yeejoin.amos.boot.module.jcs.biz.service.impl.RemoteSecurityService
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.feign.privilege.model.AgencyUserModel
;
import
com.yeejoin.amos.feign.privilege.model.CompanyModel
;
import
com.yeejoin.amos.feign.privilege.model.DepartmentModel
;
import
com.yeejoin.amos.feign.privilege.model.RoleModel
;
import
com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
/**
* 获取用户信息
*
* @author gaodongdong
*/
@RestController
@RequestMapping
(
value
=
"/user"
)
@Api
(
tags
=
"用户信息api"
)
public
class
UserController
extends
BaseController
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
@Autowired
private
RemoteSecurityService
remoteSecurityService
;
@Autowired
private
RestTemplate
restTemplate
;
@Value
(
"${security.systemctl.name}"
)
private
String
systemctl
;
private
static
final
String
appType
=
"APP"
;
/**
* 获取公司选择信息
*/
@ApiOperation
(
value
=
"获取公司选择信息"
,
notes
=
"获取公司选择信息"
)
@GetMapping
(
value
=
"/selectInfo"
)
@TycloudOperation
(
needAuth
=
true
,
ApiLevel
=
UserType
.
AGENCY
)
public
JSONObject
selectInfo
()
{
try
{
JSONObject
result
=
new
JSONObject
();
AgencyUserModel
user
=
getUserInfo
();
if
(
user
!=
null
)
{
List
<
CompanyModel
>
list
=
user
.
getCompanys
();
Map
<
Long
,
List
<
DepartmentModel
>>
mapDepartments
=
user
.
getCompanyDepartments
();
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
mapdate
=
new
HashMap
<
String
,
List
<
Map
<
String
,
Object
>>>();
List
<
Map
>
listCompanyModel
=
new
ArrayList
();
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
CompanyModel
article
:
list
)
{
Map
<
String
,
Object
>
map
=
objectToMap
(
article
);
map
.
put
(
"companySeq"
,
map
.
get
(
"sequenceNbr"
)
+
""
);
map
.
put
(
"parentId"
,
map
.
get
(
"parentId"
)
+
""
);
listCompanyModel
.
add
(
map
);
long
key
=
Long
.
valueOf
(
map
.
get
(
"sequenceNbr"
).
toString
());
List
<
DepartmentModel
>
listdep
=
mapDepartments
.
get
(
key
);
List
<
Map
<
String
,
Object
>>
dep
=
new
ArrayList
();
for
(
DepartmentModel
departmentModel
:
listdep
)
{
if
(
departmentModel
!=
null
)
{
Map
<
String
,
Object
>
mapo
=
objectToMap
(
departmentModel
);
mapo
.
put
(
"sequenceNbr"
,
mapo
.
get
(
"sequenceNbr"
).
toString
());
dep
.
add
(
mapo
);
}
}
mapdate
.
put
(
map
.
get
(
"sequenceNbr"
).
toString
(),
dep
);
}
}
Map
<
String
,
Object
>
mapRoles
=
objectToMap
(
user
.
getOrgRoles
());
result
.
put
(
"companys"
,
listCompanyModel
);
result
.
put
(
"orgRoles"
,
user
.
getOrgRoles
());
result
.
put
(
"companyDepartments"
,
mapdate
);
return
result
;
}
else
{
throw
new
RuntimeException
(
"请重新登录"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"获取公司选择信息异常"
,
e
);
throw
new
RuntimeException
(
e
.
getMessage
());
}
}
// 对象转map
public
static
Map
<
String
,
Object
>
objectToMap
(
Object
obj
)
throws
IllegalAccessException
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
if
(
obj
!=
null
)
{
Class
<?>
clazz
=
obj
.
getClass
();
for
(
Field
field
:
clazz
.
getDeclaredFields
())
{
field
.
setAccessible
(
true
);
String
fieldName
=
field
.
getName
();
Object
value
=
nvl
(
field
.
get
(
obj
));
if
(
fieldName
.
equals
(
"sequenceNbr"
))
{
map
.
put
(
fieldName
,
value
+
""
);
}
else
if
(
fieldName
.
equals
(
"companySeq"
))
{
map
.
put
(
fieldName
,
value
+
""
);
}
else
if
(
fieldName
.
equals
(
"children"
))
{
map
.
put
(
fieldName
,
value
);
}
else
{
map
.
put
(
fieldName
,
value
);
}
}
return
map
;
}
return
map
;
}
public
static
Object
nvl
(
Object
param
)
{
return
param
!=
null
?
param
:
""
;
}
/**
* 保存登陆用户选择公司信息
*/
@ApiOperation
(
value
=
"保存登陆用户选择公司信息"
,
notes
=
"保存登陆用户选择公司信息"
)
@PostMapping
(
value
=
"/save/curCompany"
)
@TycloudOperation
(
needAuth
=
true
,
ApiLevel
=
UserType
.
AGENCY
)
public
JSONObject
saveCurCompany
(
@ApiParam
(
value
=
"当前登陆用户所选单位机构编号"
,
required
=
true
)
@RequestBody
ReginParams
selectUserInfo
)
{
try
{
AgencyUserModel
user
=
getUserInfo
();
CompanyBo
company
=
new
CompanyBo
();
DepartmentBo
department
=
new
DepartmentBo
();
RoleBo
role
=
new
RoleBo
();
if
(
ObjectUtils
.
isEmpty
(
selectUserInfo
.
getCompany
())){
CompanyModel
companyM
=
user
.
getCompanys
().
get
(
0
);
Bean
.
copyExistPropertis
(
companyM
,
company
);
Map
<
Long
,
List
<
DepartmentModel
>>
mapDepartments
=
user
.
getCompanyDepartments
();
DepartmentModel
departmentM
=
mapDepartments
.
get
(
companyM
.
getSequenceNbr
()).
get
(
0
);
Bean
.
copyExistPropertis
(
departmentM
,
department
);
Map
<
Long
,
List
<
RoleModel
>>
roles
=
user
.
getOrgRoles
();
RoleModel
roleM
=
roles
.
get
(
departmentM
.
getSequenceNbr
()).
get
(
0
);
Bean
.
copyExistPropertis
(
roleM
,
role
);
selectUserInfo
.
setCompany
(
company
);
selectUserInfo
.
setDepartment
(
department
);
selectUserInfo
.
setRole
(
role
);
}
else
{
company
=
selectUserInfo
.
getCompany
();
role
=
selectUserInfo
.
getRole
();
department
=
selectUserInfo
.
getDepartment
();
}
ReginParams
reginParams
=
new
ReginParams
();
reginParams
.
setCompany
(
company
);
reginParams
.
setRole
(
role
);
reginParams
.
setDepartment
(
department
);
saveSelectedOrgInfo
(
reginParams
);
//保存用户信息
saveUser
(
user
);
return
buildCurCompany
(
selectUserInfo
,
user
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"保存登陆用户选择公司信息异常"
,
e
);
throw
new
RuntimeException
(
"系统繁忙,请稍后再试"
);
}
}
private
JSONObject
buildCurCompany
(
ReginParams
selectUserInfo
,
AgencyUserModel
user
)
{
JSONObject
result
=
new
JSONObject
();
result
.
put
(
"userId"
,
user
.
getUserId
());
result
.
put
(
"realName"
,
user
.
getRealName
());
result
.
put
(
"userMobile"
,
user
.
getMobile
());
result
.
put
(
"userName"
,
user
.
getUserName
());
result
.
put
(
"email"
,
user
.
getEmail
());
ResponseModel
secResponse
=
remoteSecurityService
.
searchPermissionTree
(
selectUserInfo
.
getRole
().
getSequenceNbr
(),
appType
);
List
<
JSONObject
>
listp
=
new
ArrayList
<>();
if
(
secResponse
.
getStatus
()==
HttpStatus
.
OK
.
value
()
&&
secResponse
.
getResult
()
!=
null
)
{
JSONArray
arr
=
JSON
.
parseArray
(
JSONArray
.
toJSONString
(
secResponse
.
getResult
()));
Map
<
String
,
JSONObject
>
map
=
Maps
.
newHashMap
();
if
(
arr
!=
null
&&
arr
.
size
()
>
0
)
{
JSONObject
obj
=
arr
.
getJSONObject
(
0
);
if
(
obj
!=
null
)
{
JSONArray
childrens
=
obj
.
getJSONArray
(
"children"
);
if
(
childrens
!=
null
&&
childrens
.
size
()
>
0
)
{
for
(
int
i
=
0
;
i
<
childrens
.
size
();
i
++)
{
JSONObject
child
=
childrens
.
getJSONObject
(
i
);
// map.put(child.getString("path"), child);
listp
.
add
(
child
);
}
}
}
// result.put("userPower", map.get("app"));
}
}
result
.
put
(
"userPower"
,
JSON
.
toJSON
(
listp
));
result
.
put
(
"companyModel"
,
selectUserInfo
.
getCompany
());
result
.
put
(
"departmentModel"
,
selectUserInfo
.
getDepartment
());
result
.
put
(
"roleModel"
,
selectUserInfo
.
getRole
());
return
result
;
}
/**
*
* 获取字典
*
*/
@ApiOperation
(
value
=
"查询指定的字典信息"
,
notes
=
"查询指定的字典信息"
)
@GetMapping
(
value
=
"listDictionaryByDictCode/{dictCode}"
)
@TycloudOperation
(
needAuth
=
true
,
ApiLevel
=
UserType
.
AGENCY
)
public
List
<
DictionarieValueModel
>
listDictionaryByDictCode
(
@PathVariable
String
dictCode
)
{
try
{
List
<
DictionarieValueModel
>
list
=
remoteSecurityService
.
listDictionaryByDictCode
(
dictCode
);
return
list
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
();
}
}
/**
*
*
* 上传图片到平台
*
**/
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"文件上传(<font color='blue'>release</font>)"
,
notes
=
"文件上传"
)
@RequestMapping
(
value
=
"/upload-file"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@TycloudOperation
(
needAuth
=
true
,
ApiLevel
=
UserType
.
AGENCY
)
public
ResponseModel
uploadFile
(
@RequestParam
(
"file"
)
MultipartFile
file
)
{
FeignClientResult
<
Map
<
String
,
String
>>
date
=
remoteSecurityService
.
fileImage
(
file
);
Map
<
String
,
String
>
map1
=
new
HashMap
<>();
if
(
date
!=
null
)
{
Map
<
String
,
String
>
map
=
date
.
getResult
();
Iterator
<
String
>
it
=
map
.
keySet
().
iterator
();
while
(
it
.
hasNext
())
{
map1
.
put
(
"url"
,
it
.
next
());
}
}
return
ResponseHelper
.
buildResponse
(
map1
);
}
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"文件上传(<font color='blue'>release</font>)"
,
notes
=
"文件上传"
)
@RequestMapping
(
value
=
"/upload-files"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@TycloudOperation
(
needAuth
=
true
,
ApiLevel
=
UserType
.
AGENCY
)
public
ResponseModel
uploadFile
(
@RequestParam
(
"files"
)
MultipartFile
[]
files
)
throws
IOException
{
// 设置请求头
HttpHeaders
headers
=
new
HttpHeaders
();
MediaType
type
=
MediaType
.
parseMediaType
(
"multipart/form-data"
);
headers
.
setContentType
(
type
);
headers
.
set
(
"product"
,
getProduct
());
headers
.
set
(
"token"
,
getToken
());
headers
.
set
(
"appKey"
,
getAppKey
());
// 设置请求体,注意是LinkedMultiValueMap
MultiValueMap
<
String
,
Object
>
form
=
new
LinkedMultiValueMap
<>();
List
<
Object
>
fileList
=
new
ArrayList
<>();
for
(
MultipartFile
file
:
files
)
{
ByteArrayResource
byteArrayResource
=
new
ByteArrayResource
(
file
.
getBytes
())
{
@Override
public
String
getFilename
()
throws
IllegalStateException
{
return
file
.
getOriginalFilename
();
}
};
fileList
.
add
(
byteArrayResource
);
}
form
.
put
(
"files"
,
fileList
);
// 用HttpEntity封装整个请求报文
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
files1
=
new
HttpEntity
<>(
form
,
headers
);
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
"http://"
+
systemctl
+
"/systemctl/v1/filestorage/image"
,
HttpMethod
.
POST
,
files1
,
String
.
class
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
responseEntity
.
getBody
());
Map
<
String
,
String
>
map1
=
new
HashMap
<>();
if
(
jsonObject
!=
null
)
{
Map
<
String
,
String
>
map
=
JSON
.
parseObject
(
jsonObject
.
get
(
"result"
).
toString
(),
Map
.
class
);
Iterator
<
String
>
it
=
map
.
keySet
().
iterator
();
String
url
=
""
;
while
(
it
.
hasNext
())
{
url
=
url
+
it
.
next
()
+
","
;
}
map1
.
put
(
"url"
,
url
);
}
return
ResponseHelper
.
buildResponse
(
map1
);
}
}
\ No newline at end of file
//package com.yeejoin.amos.boot.module.jcs.biz.controller;
//
//import java.io.IOException;
//import java.lang.reflect.Field;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.core.io.ByteArrayResource;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.util.LinkedMultiValueMap;
//import org.springframework.util.MultiValueMap;
//import org.springframework.util.ObjectUtils;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//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.RequestMethod;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.client.RestTemplate;
//import org.springframework.web.multipart.MultipartFile;
//import org.typroject.tyboot.core.foundation.enumeration.UserType;
//import org.typroject.tyboot.core.foundation.utils.Bean;
//import org.typroject.tyboot.core.restful.doc.TycloudOperation;
//import org.typroject.tyboot.core.restful.utils.ResponseHelper;
//import org.typroject.tyboot.core.restful.utils.ResponseModel;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.google.common.collect.Maps;
//import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
//import com.yeejoin.amos.boot.biz.common.bo.DepartmentBo;
//import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
//import com.yeejoin.amos.boot.biz.common.bo.RoleBo;
//import com.yeejoin.amos.boot.biz.common.controller.BaseController;
//import com.yeejoin.amos.boot.module.jcs.biz.service.impl.RemoteSecurityService;
//import com.yeejoin.amos.component.feign.model.FeignClientResult;
//import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
//import com.yeejoin.amos.feign.privilege.model.CompanyModel;
//import com.yeejoin.amos.feign.privilege.model.DepartmentModel;
//import com.yeejoin.amos.feign.privilege.model.RoleModel;
//import com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel;
//
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//
///**
// * 获取用户信息
// *
// * @author gaodongdong
// */
//@RestController
//@RequestMapping(value = "/user")
//@Api(tags = "用户信息api")
//public class UserController extends BaseController {
//
// private final Logger logger = LoggerFactory.getLogger(UserController.class);
//
// @Autowired
// private RemoteSecurityService remoteSecurityService;
// @Autowired
// private RestTemplate restTemplate;
//
// @Value("${security.systemctl.name}")
// private String systemctl;
// private static final String appType = "APP";
//
// /**
// * 获取公司选择信息
// */
// @ApiOperation(value = "获取公司选择信息", notes = "获取公司选择信息")
// @GetMapping(value = "/selectInfo")
// @TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY)
// public JSONObject selectInfo() {
// try {
// JSONObject result = new JSONObject();
// AgencyUserModel user = getUserInfo();
// if (user != null) {
// List<CompanyModel> list = user.getCompanys();
// Map<Long, List<DepartmentModel>> mapDepartments = user.getCompanyDepartments();
// Map<String, List<Map<String, Object>>> mapdate = new HashMap<String, List<Map<String, Object>>>();
// List<Map> listCompanyModel = new ArrayList();
// if (list != null && list.size() > 0) {
// for (CompanyModel article : list) {
// Map<String, Object> map = objectToMap(article);
// map.put("companySeq", map.get("sequenceNbr") + "");
// map.put("parentId", map.get("parentId") + "");
// listCompanyModel.add(map);
// long key = Long.valueOf(map.get("sequenceNbr").toString());
// List<DepartmentModel> listdep = mapDepartments.get(key);
// List<Map<String, Object>> dep = new ArrayList();
// for (DepartmentModel departmentModel : listdep) {
// if (departmentModel != null) {
// Map<String, Object> mapo = objectToMap(departmentModel);
// mapo.put("sequenceNbr", mapo.get("sequenceNbr").toString());
// dep.add(mapo);
// }
// }
// mapdate.put(map.get("sequenceNbr").toString(), dep);
// }
// }
// Map<String, Object> mapRoles = objectToMap(user.getOrgRoles());
//
// result.put("companys", listCompanyModel);
// result.put("orgRoles", user.getOrgRoles());
// result.put("companyDepartments", mapdate);
// return result;
// } else {
// throw new RuntimeException("请重新登录");
// }
// } catch (Exception e) {
// e.printStackTrace();
// logger.error("获取公司选择信息异常", e);
// throw new RuntimeException(e.getMessage());
// }
// }
//
//
// // 对象转map
//
// public static Map<String, Object> objectToMap(Object obj) throws IllegalAccessException {
// Map<String, Object> map = new HashMap<String, Object>();
// if (obj != null) {
// Class<?> clazz = obj.getClass();
// for (Field field : clazz.getDeclaredFields()) {
// field.setAccessible(true);
// String fieldName = field.getName();
// Object value = nvl(field.get(obj));
//
// if (fieldName.equals("sequenceNbr")) {
// map.put(fieldName, value + "");
// } else if (fieldName.equals("companySeq")) {
// map.put(fieldName, value + "");
// } else if (fieldName.equals("children")) {
// map.put(fieldName, value);
// } else {
// map.put(fieldName, value);
// }
//
// }
// return map;
// }
// return map;
// }
//
// public static Object nvl(Object param) {
// return param != null ? param : "";
// }
//
// /**
// * 保存登陆用户选择公司信息
// */
// @ApiOperation(value = "保存登陆用户选择公司信息", notes = "保存登陆用户选择公司信息")
// @PostMapping(value = "/save/curCompany")
// @TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY)
// public JSONObject saveCurCompany(
// @ApiParam(value = "当前登陆用户所选单位机构编号", required = true) @RequestBody ReginParams selectUserInfo) {
// try {
// AgencyUserModel user = getUserInfo();
// CompanyBo company = new CompanyBo();
// DepartmentBo department = new DepartmentBo();
// RoleBo role = new RoleBo();
// if(ObjectUtils.isEmpty(selectUserInfo.getCompany())){
// CompanyModel companyM = user.getCompanys().get(0);
// Bean.copyExistPropertis(companyM,company);
//
// Map<Long, List<DepartmentModel>> mapDepartments = user.getCompanyDepartments();
// DepartmentModel departmentM = mapDepartments.get(companyM.getSequenceNbr()).get(0);
// Bean.copyExistPropertis(departmentM,department);
// Map<Long, List<RoleModel>> roles = user.getOrgRoles();
// RoleModel roleM = roles.get(departmentM.getSequenceNbr()).get(0);
//
// Bean.copyExistPropertis(roleM,role);
// selectUserInfo.setCompany(company);
// selectUserInfo.setDepartment(department);
// selectUserInfo.setRole(role);
// }else{
// company = selectUserInfo.getCompany();
// role = selectUserInfo.getRole();
// department = selectUserInfo.getDepartment();
// }
// ReginParams reginParams = new ReginParams();
// reginParams.setCompany(company);
// reginParams.setRole(role);
// reginParams.setDepartment(department);
// saveSelectedOrgInfo(reginParams);
// //保存用户信息
// saveUser(user);
//
// return buildCurCompany(selectUserInfo, user);
// } catch (Exception e) {
// e.printStackTrace();
// logger.error("保存登陆用户选择公司信息异常", e);
// throw new RuntimeException("系统繁忙,请稍后再试");
// }
// }
// private JSONObject buildCurCompany(ReginParams selectUserInfo, AgencyUserModel user) {
// JSONObject result = new JSONObject();
// result.put("userId", user.getUserId());
// result.put("realName", user.getRealName());
// result.put("userMobile", user.getMobile());
// result.put("userName", user.getUserName());
// result.put("email", user.getEmail());
//
// ResponseModel secResponse = remoteSecurityService
// .searchPermissionTree(selectUserInfo.getRole().getSequenceNbr(), appType);
// List<JSONObject> listp = new ArrayList<>();
// if (secResponse.getStatus()==HttpStatus.OK.value() && secResponse.getResult() != null) {
// JSONArray arr = JSON.parseArray(JSONArray.toJSONString(secResponse.getResult()));
// Map<String, JSONObject> map = Maps.newHashMap();
//
// if (arr != null && arr.size() > 0) {
// JSONObject obj = arr.getJSONObject(0);
// if (obj != null) {
// JSONArray childrens = obj.getJSONArray("children");
// if (childrens != null && childrens.size() > 0) {
// for (int i = 0; i < childrens.size(); i++) {
// JSONObject child = childrens.getJSONObject(i);
// // map.put(child.getString("path"), child);
// listp.add(child);
// }
// }
// }
//
// // result.put("userPower", map.get("app"));
// }
// }
// result.put("userPower", JSON.toJSON(listp));
// result.put("companyModel", selectUserInfo.getCompany());
// result.put("departmentModel", selectUserInfo.getDepartment());
// result.put("roleModel", selectUserInfo.getRole());
// return result;
// }
//
//
//
// /**
// *
// * 获取字典
// *
// */
//
// @ApiOperation(value = "查询指定的字典信息", notes = "查询指定的字典信息")
// @GetMapping(value = "listDictionaryByDictCode/{dictCode}")
// @TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY)
// public List<DictionarieValueModel> listDictionaryByDictCode(@PathVariable String dictCode) {
// try {
// List<DictionarieValueModel> list = remoteSecurityService.listDictionaryByDictCode(dictCode);
//
// return list;
// } catch (Exception e) {
//
// throw new RuntimeException();
// }
// }
//
// /**
// *
// *
// * 上传图片到平台
// *
// **/
// @ApiOperation(httpMethod = "POST", value = "文件上传(<font color='blue'>release</font>)", notes = "文件上传")
// @RequestMapping(value = "/upload-file", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
// @TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY)
// public ResponseModel uploadFile(@RequestParam("file") MultipartFile file) {
//
// FeignClientResult<Map<String, String>> date = remoteSecurityService.fileImage(file);
// Map<String, String> map1 = new HashMap<>();
// if (date != null) {
// Map<String, String> map = date.getResult();
// Iterator<String> it = map.keySet().iterator();
//
// while (it.hasNext()) {
// map1.put("url", it.next());
// }
//
// }
// return ResponseHelper.buildResponse(map1);
// }
//
// @ApiOperation(httpMethod = "POST", value = "文件上传(<font color='blue'>release</font>)", notes = "文件上传")
// @RequestMapping(value = "/upload-files", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
// @TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY)
// public ResponseModel uploadFile(@RequestParam("files") MultipartFile[] files) throws IOException {
//
// // 设置请求头
// HttpHeaders headers = new HttpHeaders();
// MediaType type = MediaType.parseMediaType("multipart/form-data");
// headers.setContentType(type);
// headers.set("product", getProduct());
// headers.set("token", getToken());
// headers.set("appKey", getAppKey());
// // 设置请求体,注意是LinkedMultiValueMap
// MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
// List<Object> fileList = new ArrayList<>();
// for (MultipartFile file : files) {
// ByteArrayResource byteArrayResource = new ByteArrayResource(file.getBytes()) {
// @Override
// public String getFilename() throws IllegalStateException {
// return file.getOriginalFilename();
// }
// };
// fileList.add(byteArrayResource);
// }
//
// form.put("files", fileList);
//
// // 用HttpEntity封装整个请求报文
// HttpEntity<MultiValueMap<String, Object>> files1 = new HttpEntity<>(form, headers);
//
// ResponseEntity<String> responseEntity = restTemplate.exchange(
// "http://" + systemctl + "/systemctl/v1/filestorage/image", HttpMethod.POST, files1, String.class);
//
// JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
//
// Map<String, String> map1 = new HashMap<>();
// if (jsonObject != null) {
// Map<String, String> map = JSON.parseObject(jsonObject.get("result").toString(), Map.class);
// Iterator<String> it = map.keySet().iterator();
// String url = "";
// while (it.hasNext()) {
// url = url + it.next() + ",";
// }
// map1.put("url", url);
// }
// return ResponseHelper.buildResponse(map1);
// }
//
//}
\ No newline at end of file
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/service/impl/RemoteSecurityService.java
View file @
60204813
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jcs
.
biz
.
service
.
impl
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.typroject.tyboot.core.foundation.context.RequestContext
;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.yeejoin.amos.component.feign.config.InnerInvokException
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.component.feign.utils.FeignUtil
;
import
com.yeejoin.amos.feign.privilege.Privilege
;
import
com.yeejoin.amos.feign.privilege.client.AgencyUserClient
;
import
com.yeejoin.amos.feign.privilege.model.AgencyUserModel
;
import
com.yeejoin.amos.feign.privilege.model.CompanyModel
;
import
com.yeejoin.amos.feign.privilege.model.DepartmentModel
;
import
com.yeejoin.amos.feign.privilege.model.PermissionModel
;
import
com.yeejoin.amos.feign.systemctl.Systemctl
;
import
com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel
;
/***
*
* 平台安全接口实现类
*
* ***/
@Service
(
"remoteSecurityService"
)
public
class
RemoteSecurityService
{
@Autowired
private
HttpServletRequest
request
;
// * 根据公司id查询机构用户
public
List
<
AgencyUserModel
>
listUserByCompanyId
(
String
companyId
)
{
if
(
StringUtils
.
isEmpty
(
companyId
))
{
return
null
;
}
List
<
AgencyUserModel
>
AgencyUserModel
=
null
;
FeignClientResult
feignClientResult
;
try
{
feignClientResult
=
Privilege
.
agencyUserClient
.
queryByCompanyId
(
Long
.
valueOf
(
companyId
),
null
);
AgencyUserModel
=
(
List
<
AgencyUserModel
>)
feignClientResult
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
return
AgencyUserModel
;
}
/**
* 用户id批量获取用户信息
*
* @param userIds 用户ids
* @return List<AgencyUserModel>
*/
public
List
<
AgencyUserModel
>
listUserByUserIds
(
String
userIds
)
{
List
<
AgencyUserModel
>
agencyUserModel
=
null
;
FeignClientResult
feignClientResult
;
try
{
feignClientResult
=
Privilege
.
agencyUserClient
.
queryByIds
(
userIds
);
agencyUserModel
=
(
List
<
AgencyUserModel
>)
feignClientResult
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
return
agencyUserModel
;
}
/**
* 用户id获取用户信息
*
* @param userId 用户编号
* @return AgencyUserModel
*/
public
AgencyUserModel
getUserById
(
String
userId
)
{
if
(
StringUtils
.
isEmpty
(
userId
))
{
return
null
;
}
AgencyUserModel
agencyUserModel
;
try
{
agencyUserModel
=
FeignUtil
.
remoteCall
(()
->
Privilege
.
agencyUserClient
.
queryByUserId
(
userId
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
return
agencyUserModel
;
}
// 根据orgCode查询机构用户
public
List
<
AgencyUserModel
>
listUserByOrgCode
(
String
orgCode
)
{
if
(
StringUtils
.
isEmpty
(
orgCode
))
{
return
null
;
}
Set
<
AgencyUserModel
>
agencyUserModel
;
try
{
agencyUserModel
=
FeignUtil
.
remoteCall
(()
->
Privilege
.
agencyUserClient
.
queryByOrgCode
(
orgCode
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
return
new
ArrayList
<>(
agencyUserModel
);
}
// 根据部门id查询机构用户
public
List
<
AgencyUserModel
>
listUserByDepartmentId
(
Long
departmentId
)
{
if
(
departmentId
==
null
)
{
return
null
;
}
List
<
AgencyUserModel
>
agencyUserModel
;
try
{
agencyUserModel
=
FeignUtil
.
remoteCall
(
()
->
Privilege
.
agencyUserClient
.
queryByDepartmentId
(
departmentId
,
null
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
return
agencyUserModel
;
}
// 根据orgCode查询机构
public
Map
<
String
,
Object
>
listByOrgCode
(
String
orgCode
)
{
if
(
StringUtils
.
isEmpty
(
orgCode
))
{
return
null
;
}
Map
<
String
,
Object
>
agencyUserModel
=
null
;
FeignClientResult
feignClientResult
;
try
{
feignClientResult
=
Privilege
.
companyClient
.
queryByOrgcode
(
orgCode
);
agencyUserModel
=
(
Map
<
String
,
Object
>)
feignClientResult
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
return
agencyUserModel
;
}
// 查询指定公司的部门树
public
List
<
DepartmentModel
>
getDepartmentTreeByCompanyId
(
Long
companyId
)
{
if
(
companyId
==
null
)
{
return
null
;
}
List
<
DepartmentModel
>
departmentModel
=
null
;
FeignClientResult
feignClientResult
;
try
{
feignClientResult
=
Privilege
.
departmentClient
.
queryDeptTree
(
null
,
companyId
);
departmentModel
=
(
List
<
DepartmentModel
>)
feignClientResult
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
return
departmentModel
;
}
/**
* 基础平台全部菜单权限树,用于平台登录前端初始化路由
*/
public
ResponseModel
<
Object
>
searchPermissionTree
(
long
id
,
String
appType
)
{
List
<
PermissionModel
>
dictionarieModel
=
null
;
FeignClientResult
<
Collection
<
PermissionModel
>>
feignClientResult
;
try
{
feignClientResult
=
Privilege
.
permissionClient
.
treeByRole
(
id
,
appType
,
null
,
null
);
dictionarieModel
=
(
List
<
PermissionModel
>)
feignClientResult
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
throw
new
RuntimeException
();
}
ResponseModel
<
Object
>
commonResponse
=
ResponseHelper
.
buildResponse
(
dictionarieModel
);
return
commonResponse
;
}
/**
* 根据Code查询指定的字典信息
*
* @param dictCode 字典编号
* @return List<DictionarieValueModel>
*/
public
List
<
DictionarieValueModel
>
listDictionaryByDictCode
(
String
dictCode
)
{
List
<
DictionarieValueModel
>
dictionarieModel
=
null
;
FeignClientResult
<
List
<
DictionarieValueModel
>>
feignClientResult
;
try
{
feignClientResult
=
Systemctl
.
dictionarieClient
.
dictValues
(
dictCode
);
dictionarieModel
=
(
List
<
DictionarieValueModel
>)
feignClientResult
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
throw
new
RuntimeException
();
}
return
dictionarieModel
;
}
/**
* 查询指定公司信息与其部门用户树
*/
public
CompanyModel
listUserByCompanyId1
(
Long
companyId
)
{
if
(
companyId
==
null
)
{
return
null
;
}
CompanyModel
companyModel
=
null
;
FeignClientResult
feignClientResult
;
try
{
feignClientResult
=
Privilege
.
companyClient
.
withDeptAndUsers
(
companyId
);
companyModel
=
(
CompanyModel
)
feignClientResult
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
throw
new
RuntimeException
();
}
return
companyModel
;
}
public
JSONArray
listDepartmentUserTree
(
Long
companyId
)
{
CompanyModel
companyModel
=
null
;
FeignClientResult
feignClientResult
;
try
{
feignClientResult
=
Privilege
.
companyClient
.
withDeptAndUsers
(
companyId
);
companyModel
=
(
CompanyModel
)
feignClientResult
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
if
(
companyModel
!=
null
)
{
String
jsonStr
=
null
;
jsonStr
=
JSON
.
toJSONString
(
companyModel
.
getChildren
());
return
JSONArray
.
parseArray
(
jsonStr
);
}
return
null
;
}
public
boolean
editPassword
(
String
userId
,
String
oldPassword
,
String
newPassword
)
throws
InnerInvokException
{
boolean
flag
=
false
;
AgencyUserModel
agencyUserModel
=
new
AgencyUserModel
();
agencyUserModel
.
setPassword
(
newPassword
);
agencyUserModel
.
setRePassword
(
newPassword
);
agencyUserModel
.
setOriginalPassword
(
oldPassword
);
AgencyUserModel
agencyUserModel2
=
null
;
FeignClientResult
feignClientResult
;
feignClientResult
=
Privilege
.
agencyUserClient
.
modifyPassword
(
userId
,
agencyUserModel
);
agencyUserModel
=
(
AgencyUserModel
)
feignClientResult
.
getResult
();
if
(
agencyUserModel2
!=
null
)
{
flag
=
true
;
}
return
false
;
}
public
FeignClientResult
<
Map
<
String
,
String
>>
fileImage
(
MultipartFile
file
)
{
String
product
=
request
.
getHeader
(
"product"
);
String
appKey
=
request
.
getHeader
(
"appKey"
);
try
{
RequestContext
.
setProduct
(
product
);
RequestContext
.
setAppKey
(
appKey
);
FeignClientResult
<
Map
<
String
,
String
>>
date
=
Systemctl
.
fileStorageClient
.
updateCommonFile
(
file
);
return
date
;
}
catch
(
InnerInvokException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
}
public
FeignClientResult
<
Map
<
String
,
String
>>
fileImage
(
MultipartFile
[]
files
)
{
try
{
FeignClientResult
<
java
.
util
.
Map
<
String
,
String
>>
date
=
Systemctl
.
fileStorageClient
.
updateCommonFiles
(
files
);
return
date
;
}
catch
(
InnerInvokException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
();
}
}
public
AgencyUserModel
getAgencyUser
()
{
FeignClientResult
<
AgencyUserModel
>
agencyUser
=
null
;
AgencyUserModel
userModel
=
null
;
try
{
AgencyUserClient
agencyUserClient
=
Privilege
.
agencyUserClient
;
agencyUser
=
agencyUserClient
.
getme
();
userModel
=
agencyUser
.
getResult
();
}
catch
(
InnerInvokException
e
)
{
throw
new
RuntimeException
(
e
.
getMessage
());
}
return
userModel
;
}
}
//
package com.yeejoin.amos.boot.module.jcs.biz.service.impl;
//
//
import java.util.ArrayList;
//
import java.util.Collection;
//
import java.util.List;
//
import java.util.Map;
//
import java.util.Set;
//
//
import javax.servlet.http.HttpServletRequest;
//
//
import org.springframework.beans.factory.annotation.Autowired;
//
import org.springframework.stereotype.Service;
//
import org.springframework.util.StringUtils;
//
import org.springframework.web.multipart.MultipartFile;
//
import org.typroject.tyboot.core.foundation.context.RequestContext;
//
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
//
import org.typroject.tyboot.core.restful.utils.ResponseModel;
//
//
import com.alibaba.fastjson.JSON;
//
import com.alibaba.fastjson.JSONArray;
//
import com.yeejoin.amos.component.feign.config.InnerInvokException;
//
import com.yeejoin.amos.component.feign.model.FeignClientResult;
//
import com.yeejoin.amos.component.feign.utils.FeignUtil;
//
import com.yeejoin.amos.feign.privilege.Privilege;
//
import com.yeejoin.amos.feign.privilege.client.AgencyUserClient;
//
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
//
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
//
import com.yeejoin.amos.feign.privilege.model.DepartmentModel;
//
import com.yeejoin.amos.feign.privilege.model.PermissionModel;
//
import com.yeejoin.amos.feign.systemctl.Systemctl;
//
import com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel;
//
/
//
***
//
*
//
* 平台安全接口实现类
//
*
//
* ***/
//
@Service("remoteSecurityService")
//
public class RemoteSecurityService {
//
//
//
@Autowired
//
private HttpServletRequest request;
//
//
// * 根据公司id查询机构用户
//
////
public List<AgencyUserModel> listUserByCompanyId(String companyId) {
////
if (StringUtils.isEmpty(companyId)) {
////
return null;
////
}
////
List<AgencyUserModel> AgencyUserModel = null;
////
FeignClientResult feignClientResult;
////
try {
////
feignClientResult = Privilege.agencyUserClient.queryByCompanyId(Long.valueOf(companyId), null);
////
AgencyUserModel = (List<AgencyUserModel>) feignClientResult.getResult();
////
////
} catch (InnerInvokException e) {
////
e.printStackTrace();
////
throw new RuntimeException();
////
}
////
return AgencyUserModel;
////
}
//
//
/**
//
* 用户id批量获取用户信息
//
*
//
* @param userIds 用户ids
//
* @return List<AgencyUserModel>
//
*/
////
public List<AgencyUserModel> listUserByUserIds(String userIds) {
////
List<AgencyUserModel> agencyUserModel = null;
////
FeignClientResult feignClientResult;
////
try {
////
feignClientResult = Privilege.agencyUserClient.queryByIds(userIds);
////
agencyUserModel = (List<AgencyUserModel>) feignClientResult.getResult();
////
////
} catch (InnerInvokException e) {
////
e.printStackTrace();
////
throw new RuntimeException();
////
}
////
return agencyUserModel;
////
}
//
//
/**
//
* 用户id获取用户信息
//
*
//
* @param userId 用户编号
//
* @return AgencyUserModel
//
*/
//
public AgencyUserModel getUserById(String userId) {
//
if (StringUtils.isEmpty(userId)) {
//
return null;
//
}
//
AgencyUserModel agencyUserModel;
//
try {
//
agencyUserModel = FeignUtil.remoteCall(() -> Privilege.agencyUserClient.queryByUserId(userId));
//
} catch (Exception e) {
//
e.printStackTrace();
//
throw new RuntimeException();
//
}
//
return agencyUserModel;
//
}
//
//
// 根据orgCode查询机构用户
////
public List<AgencyUserModel> listUserByOrgCode(String orgCode) {
////
if (StringUtils.isEmpty(orgCode)) {
////
return null;
////
}
////
Set<AgencyUserModel> agencyUserModel;
////
try {
////
agencyUserModel = FeignUtil.remoteCall(() -> Privilege.agencyUserClient.queryByOrgCode(orgCode));
////
} catch (Exception e) {
////
e.printStackTrace();
////
throw new RuntimeException();
////
}
////
return new ArrayList<>(agencyUserModel);
////
}
//
//
// 根据部门id查询机构用户
////
public List<AgencyUserModel> listUserByDepartmentId(Long departmentId) {
////
if (departmentId == null) {
////
return null;
////
}
////
List<AgencyUserModel> agencyUserModel;
////
try {
//// agencyUserModel = FeignUtil.remoteCall
() -> Privilege.agencyUserClient.queryByDepartmentId(departmentId, null));
////
} catch (Exception e) {
////
e.printStackTrace();
////
throw new RuntimeException();
////
}
////
return agencyUserModel;
////
}
//
//
// 根据orgCode查询机构
//
public Map<String, Object> listByOrgCode(String orgCode) {
//
if (StringUtils.isEmpty(orgCode)) {
//
return null;
//
}
//
Map<String, Object> agencyUserModel = null;
//
FeignClientResult feignClientResult;
//
try {
//
feignClientResult = Privilege.companyClient.queryByOrgcode(orgCode);
//
agencyUserModel = (Map<String, Object>) feignClientResult.getResult();
//
} catch (InnerInvokException e) {
//
e.printStackTrace();
//
throw new RuntimeException();
//
}
//
return agencyUserModel;
//
}
//
//
// 查询指定公司的部门树
//
public List<DepartmentModel> getDepartmentTreeByCompanyId(Long companyId) {
//
if (companyId == null) {
//
return null;
//
}
//
List<DepartmentModel> departmentModel = null;
//
FeignClientResult feignClientResult;
//
try {
//
feignClientResult = Privilege.departmentClient.queryDeptTree(null, companyId);
//
departmentModel = (List<DepartmentModel>) feignClientResult.getResult();
//
//
} catch (InnerInvokException e) {
//
e.printStackTrace();
//
throw new RuntimeException();
//
}
//
return departmentModel;
//
//
}
//
//
//
/**
//
* 基础平台全部菜单权限树,用于平台登录前端初始化路由
//
*/
//
public ResponseModel<Object> searchPermissionTree(long id, String appType) {
//
List<PermissionModel> dictionarieModel = null;
//
FeignClientResult<Collection<PermissionModel>> feignClientResult;
//
try {
//
feignClientResult = Privilege.permissionClient.treeByRole(id, appType, null, null);
//
dictionarieModel = (List<PermissionModel>) feignClientResult.getResult();
//
//
} catch (InnerInvokException e) {
//
throw new RuntimeException();
//
}
//
ResponseModel<Object> commonResponse = ResponseHelper.buildResponse( dictionarieModel);
//
return commonResponse;
//
}
//
//
/**
//
* 根据Code查询指定的字典信息
//
*
//
* @param dictCode 字典编号
//
* @return List<DictionarieValueModel>
//
*/
//
public List<DictionarieValueModel> listDictionaryByDictCode(String dictCode) {
//
List<DictionarieValueModel> dictionarieModel = null;
//
FeignClientResult<List<DictionarieValueModel>> feignClientResult;
//
try {
//
feignClientResult = Systemctl.dictionarieClient.dictValues(dictCode);
//
dictionarieModel = (List<DictionarieValueModel>) feignClientResult.getResult();
//
//
} catch (InnerInvokException e) {
//
throw new RuntimeException();
//
}
//
//
return dictionarieModel;
//
}
//
//
/**
//
* 查询指定公司信息与其部门用户树
//
*/
//
public CompanyModel listUserByCompanyId1(Long companyId) {
//
if (companyId == null) {
//
return null;
//
}
//
CompanyModel companyModel = null;
//
FeignClientResult feignClientResult;
//
try {
//
feignClientResult = Privilege.companyClient.withDeptAndUsers(companyId);
//
companyModel = (CompanyModel) feignClientResult.getResult();
//
//
} catch (InnerInvokException e) {
//
throw new RuntimeException();
//
}
//
return companyModel;
//
//
}
//
//
//
//
//
//
public JSONArray listDepartmentUserTree(Long companyId) {
//
//
CompanyModel companyModel = null;
//
FeignClientResult feignClientResult;
//
try {
//
feignClientResult = Privilege.companyClient.withDeptAndUsers(companyId);
//
companyModel = (CompanyModel) feignClientResult.getResult();
//
//
} catch (InnerInvokException e) {
//
e.printStackTrace();
//
throw new RuntimeException();
//
}
//
//
if (companyModel != null) {
//
String jsonStr = null;
//
//
jsonStr = JSON.toJSONString(companyModel.getChildren());
//
//
return JSONArray.parseArray(jsonStr);
//
}
//
return null;
//
//
}
//
//
public boolean editPassword(String userId, String oldPassword, String newPassword) throws InnerInvokException {
//
boolean flag = false;
//
AgencyUserModel agencyUserModel = new AgencyUserModel();
//
agencyUserModel.setPassword(newPassword);
//
agencyUserModel.setRePassword(newPassword);
//
agencyUserModel.setOriginalPassword(oldPassword);
//
AgencyUserModel agencyUserModel2 = null;
//
FeignClientResult feignClientResult;
//
feignClientResult = Privilege.agencyUserClient.modifyPassword(userId, agencyUserModel);
//
agencyUserModel = (AgencyUserModel) feignClientResult.getResult();
//
if (agencyUserModel2 != null) {
//
flag = true;
//
}
//
return false;
//
}
//
//
public FeignClientResult<Map<String, String>> fileImage(MultipartFile file) {
//
String product = request.getHeader("product");
//
String appKey = request.getHeader("appKey");
//
try {
//
RequestContext.setProduct(product);
//
RequestContext.setAppKey(appKey);
//
FeignClientResult<Map<String, String>> date = Systemctl.fileStorageClient.updateCommonFile(file);
//
//
return date;
//
} catch (InnerInvokException e) {
//
e.printStackTrace();
//
throw new RuntimeException();
//
}
//
//
}
//
//
public FeignClientResult<Map<String, String>> fileImage(MultipartFile[] files) {
//
//
try {
//
FeignClientResult<java.util.Map<String, String>> date = Systemctl.fileStorageClient
//
.updateCommonFiles(files);
//
//
return date;
//
} catch (InnerInvokException e) {
//
e.printStackTrace();
//
throw new RuntimeException();
//
}
//
//
}
//
//
public AgencyUserModel getAgencyUser() {
//
FeignClientResult<AgencyUserModel> agencyUser = null;
//
AgencyUserModel userModel = null;
//
try {
//
AgencyUserClient agencyUserClient = Privilege.agencyUserClient;
//
agencyUser = agencyUserClient.getme();
//
userModel = agencyUser.getResult();
//
} catch (InnerInvokException e) {
//
throw new RuntimeException(e.getMessage());
//
}
//
return userModel;
//
}
//
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment