Commit 4b06caab authored by 赵啸非's avatar 赵啸非

修改设备管理系统单点登录

parent b0cd12b9
......@@ -18,7 +18,7 @@ import java.util.List;
* @author zxfei
* @date 2022-07-06
*/
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = UserFeignFallbackFactory.class)
@FeignClient(name = "portal-manager", path = "/zwfw", fallbackFactory = UserFeignFallbackFactory.class)
public interface IUserFeign extends IFeign {
......
......@@ -5,5 +5,8 @@ NODE_ENV = development
VUE_APP_BASE_API =http://plm.testnew.com:8082/m
# websocket地址
VUE_APP_WEBSOCKET_API =127.0.0.1:18221/m
VUE_APP_WEBSOCKET_API =127.0.0.1:18222/m
# 门户登录地址
VUE_APP_PORTAL_URL = http://192.168.0.98:11072
......@@ -5,5 +5,8 @@ NODE_ENV = production
VUE_APP_BASE_API = http://192.168.0.26:9005/m
# websocket地址
VUE_APP_WEBSOCKET_API =192.168.0.26:18221/m
VUE_APP_WEBSOCKET_API =192.168.0.98:18222/m
# 门户登录地址
VUE_APP_PORTAL_URL = http://192.168.0.98:11072
......@@ -7,3 +7,6 @@ VUE_APP_BASE_API = http://192.168.0.98:11091/m
# websocket地址
VUE_APP_WEBSOCKET_API =192.168.0.98:18222/m
# 门户登录地址
VUE_APP_PORTAL_URL = http://192.168.0.98:11072
......@@ -6,11 +6,19 @@ import fileNotFound from './views/errors/fileNotFound.vue'
Vue.use(Router);
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
const router = new Router({
routes: [
builder('/authentication', 'login/authentication'),
builder('/login', 'login/login'),
builder('/go', 'codeGen/index'),
builder('/sso', 'SSO'),
{
path: '/',
name: 'layout',
......@@ -38,7 +46,7 @@ const router = new Router({
...restBuilder('platform', 'platform'),//平台
...restBuilder('product', 'product'),//产品
...restBuilder('device', 'device'),//设备
...restBuilder('device/alarm/info', 'device/alarm/info'),//设备告警信息
...restBuilder('device/module', 'device/module'),//设备模块使用率
...restBuilder('device/module/use', 'device/module/use'),//设备模块使用率
......@@ -104,7 +112,10 @@ function getComponent(fileName) {
}
}
//检查是否跳转到sso地址
function ssoCheck (to, from, next) {
function ssoCheck(to, from, next) {
console.log("to", to)
console.log("from", from)
console.log("next", next)
let redirect = (to.path === '/login/updatePwd') ? '/#/updatePwd' : ''
redirect = (redirect === '' && to.path === '/login') ? (location.protocol + '//' + location.host + '/#' + from.fullPath) : redirect
if (redirect != '') {
......
......@@ -215,6 +215,8 @@ export default {
this.findDeviceAlarm(beforeday);
this.findDevicePush(beforeday);
console.log("process",process.env)
},
methods: {
findDeviceTotalStat(beforeday) {
......
......@@ -22,12 +22,17 @@ export default {
},
loginFail(error) {
this.$message.error(error.message || '请登录');
this.$router.replace({
path: '/login',
query: {
redirect: this.redirect,
}
});
console.log("href:"+process.env.VUE_APP_PORTAL_URL)
// window.location.href=process.env.VUE_APP_PORTAL_URL=='undefined'?'http://192.168.0.98:11072':process.env.VUE_APP_PORTAL_URL
// window.location.href=process.env.VUE_APP_PORTAL_URL
// this.$router.replace({
// path: '/login',
// query: {
// redirect: this.redirect,
// }
// });
}
},
computed: {
......
......@@ -28,11 +28,11 @@
<![CDATA[jdbc:mysql://localhost:3306/device-new-platform?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong]]></profiles.datasource.uri>
<profiles.datasource.username>root</profiles.datasource.username>
<profiles.datasource.password>12345678</profiles.datasource.password>
<profiles.redis.uri>127.0.0.1</profiles.redis.uri>
<profiles.redis.uri>192.168.0.252</profiles.redis.uri>
<profiles.redis.port>6379</profiles.redis.port>
<profiles.redis.username></profiles.redis.username>
<profiles.redis.password></profiles.redis.password>
<profiles.redis.database>1</profiles.redis.database>
<profiles.redis.password>hotel@2020</profiles.redis.password>
<profiles.redis.database>7</profiles.redis.database>
<profiles.kafka.brokers>192.168.0.251:9092</profiles.kafka.brokers>
<profiles.queue.type>rabbitmq</profiles.queue.type>
<profiles.rabbitmq.host>192.168.0.98</profiles.rabbitmq.host>
......
......@@ -8,6 +8,7 @@ import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.user.model.UserEntity;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
......@@ -28,7 +29,7 @@ import java.util.Map;
* @author zxfei
*/
//@Service
@Service
@Order(1)
@Slf4j
public class AuthTokenServiceImpl implements IAuthTokenService {
......@@ -51,20 +52,20 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
@Value("${spring.redis.database:}")
private Integer db;
@Value("${token.database:1}")
@Value("${token.database:0}")
private Integer portalDb;
protected static final Long MILLIS_SECOND = 1000l;
protected static final Long SECOND = 1l;
protected static final Long MILLIS_MINUTE = 60 * MILLIS_SECOND;
protected static final Long SECOND_MINUTE = 60 * SECOND;
protected static final Long MILLIS_HOUR = 60 * MILLIS_MINUTE;
protected static final Long SECOND_HOUR = 60 * SECOND_MINUTE;
protected static final Long MILLIS_DAY = 24 * MILLIS_HOUR;
protected static final Long SECOND_DAY = 24 * SECOND_HOUR;
protected static final Long MILLIS_WEEK = 7 * MILLIS_DAY;
protected static final Long SECOND_WEEK = 7 * SECOND_DAY;
private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L;
private static final Long SECOND_MINUTE_TEN = 1 * SECOND_MINUTE;
@Autowired
private ICacheService cacheService;
......@@ -88,122 +89,9 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
String userStr = cacheService.get(userKey);
cacheService.select(db);
if (StringUtils.isNotEmpty(userStr)) {
JSONObject userObj = JSON.parseObject(userStr);
Long userId = userObj.getLongValue("id");
Integer userType = userObj.getIntValue("userType");
Long customerId = userObj.getLongValue("customerId");
Long siteId = userObj.getLongValue("siteId");
Long loginTime = userObj.getLongValue("loginTime");
Long expireTime = userObj.getLongValue("expireTime");
String loginName = userObj.getString("loginName");
String realName = userObj.getString("realName");
String siteIds = userObj.getString("siteIds");
String menuUrl = userObj.getString("menuUrl");
Boolean isManager = userObj.getBoolean("manager");
Boolean isSystemUser = userObj.getBoolean("systemUser");
return new IUser() {
@Override
public Long getId() {
return userId;
}
@Override
public Long getDeptId() {
return null;
}
@Override
public String getDeptName() {
return null;
}
@Override
public Long getCustomerId() {
return customerId;
}
@Override
public Long getSiteId() {
return siteId;
}
@Override
public String getSiteIds() {
return siteIds;
}
@Override
public Long getCustomerJoinId() {
return null;
}
@Override
public String getCustomerNum() {
return null;
}
@Override
public String getLoginName() {
return loginName;
}
@Override
public String getRealName() {
return realName;
}
@Override
public boolean isAdmin() {
return userId == 1L;
}
@Override
public boolean isSystemUser() {
return isSystemUser;
}
@Override
public boolean isManager() {
return isManager;
}
@Override
public Integer getUserType() {
return userType;
}
@Override
public String getToken() {
return token;
}
@Override
public Long getLoginTime() {
return loginTime;
}
@Override
public Long getExpireTime() {
return expireTime;
}
@Override
public void setExpireTime(Long expireTime) {
}
@Override
public String getMenuUrl() {
return menuUrl;
}
};
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
return userEntity;
}
// return cacheService.get(userKey, IUser.class);
} catch (Exception e) {
log.error("解析jwt token异常!", e);
return null;
......@@ -259,7 +147,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
public void verifyToken(IUser user) {
long expireTime = user.getExpireTime();
long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= MILLIS_MINUTE_TEN) {
if (expireTime - currentTime <= SECOND_MINUTE_TEN) {
log.info("不足十分钟,刷新过期时间");
refreshToken(user);
}
......@@ -272,11 +160,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
*/
public void refreshToken(IUser user) {
//user.setLoginTime(System.currentTimeMillis());
user.setExpireTime(user.getLoginTime() == null ? System.currentTimeMillis() : user.getLoginTime() + expireTime * MILLIS_MINUTE);
user.setExpireTime(user.getLoginTime() == null ? System.currentTimeMillis() : user.getLoginTime() + expireTime * SECOND_MINUTE);
// 根据uuid将user缓存
String userKey = getTokenKey(user.getToken());
//设置有效时间 单位秒
cacheService.setnx(userKey, user, expireTime * MILLIS_MINUTE);
cacheService.set(userKey, user, expireTime * SECOND_MINUTE);
}
......
......@@ -10,6 +10,7 @@ import com.mortals.framework.model.Result;
import com.mortals.framework.service.IAuthTokenService;
import com.mortals.xhx.common.code.DeviceStatusEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.ErrorCode;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.common.utils.MemoryPagination;
......@@ -31,6 +32,8 @@ import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
/**
* SitestatService
* 站点统计 service实现
......@@ -121,18 +124,20 @@ public class SitestatServiceImpl extends AbstractCRUDServiceImpl<SitestatDao, Si
@Override
public String getSiteTree(Context context) {
//
UserPdu userPdu = new UserPdu();
userPdu.setLoginName("admin");
userPdu.setPassword("admin");
userPdu.setSecurityCode("8888");
String loginResp = userFeign.portalLogin(userPdu);
JSONObject loginRespJson = JSON.parseObject(loginResp);
String token = loginRespJson.getJSONObject("data").getString("token");
// String token = context.getUser().getToken();
String resp = siteFeign.siteTree(token);
log.info("treeResp:"+resp);
return resp;
// UserPdu userPdu = new UserPdu();
// userPdu.setLoginName("admin");
// userPdu.setPassword("admin");
// userPdu.setSecurityCode("8888");
// String loginResp = userFeign.portalLogin(userPdu);
// JSONObject loginRespJson = JSON.parseObject(loginResp);
// String token = loginRespJson.getJSONObject("data").getString("token");
String token = context.getUser().getToken();
if (!ObjectUtils.isEmpty(token)) {
String resp = siteFeign.siteTree(token);
log.info("treeResp:" + resp);
}
return JSON.toJSONString(Rest.fail(ErrorCode.ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT));
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment