Commit 2acbd4e5 authored by 赵啸非's avatar 赵啸非

Merge branch 'master' into reg

# Conflicts:
#	log-manager/src/main/java/com/mortals/xhx/base/framework/interceptor/AuthTokenServiceImpl.java
parents 0462f743 7872d6b0
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
fuzzy: true fuzzy: true
}, },
{ {
name: "appName", name: "targetServer",
type: "text", type: "text",
label: "应用名称", label: "应用名称",
fuzzy: true fuzzy: true
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
{ {
name: "deviceCode", name: "deviceCode",
type: "text", type: "text",
label: "设备唯一标识", label: "设备Id",
fuzzy: true fuzzy: true
}, },
{ {
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
{label: "用户标识", prop: "userCode"}, {label: "用户标识", prop: "userCode"},
{label: "设备标识", prop: "deviceCode"}, {label: "设备ID", prop: "deviceCode"},
{label: "事件主题", prop: "eventTopic"}, {label: "事件主题", prop: "eventTopic"},
......
...@@ -38,18 +38,17 @@ ...@@ -38,18 +38,17 @@
toView(row) { toView(row) {
this.$refs.drawerform.view(row); this.$refs.drawerform.view(row);
}, },
}, },
data() { data() {
return { return {
config: { config: {
search: [ search: [
{ {
name: "traceID", name: "traceID",
type: "text", type: "text",
label: "TraceId", label: "追踪Id",
fuzzy: true fuzzy: true
}, },
{ {
name: "appName", name: "appName",
type: "select", type: "select",
...@@ -81,7 +80,7 @@ ...@@ -81,7 +80,7 @@
{type: "index",label: "序号",align:"center",width: 50}, {type: "index",label: "序号",align:"center",width: 50},
{label: "追踪Id", prop: "id"}, {label: "TraceID", prop: "traceID"},
{label: "日志来源", prop: "appName",formatter:this.formatter}, {label: "日志来源", prop: "appName",formatter:this.formatter},
......
...@@ -188,25 +188,25 @@ ...@@ -188,25 +188,25 @@
</profile> </profile>
<profile> <profile>
<id>sngx</id> <id>xuanhan</id>
<properties> <properties>
<profiles.active>sngx</profiles.active> <profiles.active>yibin</profiles.active>
<profiles.server.ip>127.0.0.1</profiles.server.ip> <profiles.server.ip>192.168.2.144</profiles.server.ip>
<profiles.server.port>18225</profiles.server.port> <profiles.server.port>18225</profiles.server.port>
<profiles.nginx.port>11092</profiles.nginx.port> <profiles.nginx.port>11092</profiles.nginx.port>
<profiles.server.gatewayport>11078</profiles.server.gatewayport> <profiles.server.gatewayport>11078</profiles.server.gatewayport>
<profiles.server.path>/logservice</profiles.server.path> <profiles.server.path>/logService</profiles.server.path>
<profiles.publish.path>/home/publish</profiles.publish.path> <profiles.publish.path>/home/publish</profiles.publish.path>
<profiles.datasource.uri> <profiles.datasource.uri>
<![CDATA[jdbc:mysql://127.0.0.1:3306/log-platform?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong]]></profiles.datasource.uri> <![CDATA[jdbc:mysql://127.0.0.1:3306/log-platform?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong]]></profiles.datasource.uri>
<profiles.datasource.username>root</profiles.datasource.username> <profiles.datasource.username>root</profiles.datasource.username>
<profiles.datasource.password>root</profiles.datasource.password> <profiles.datasource.password>xhx@2022</profiles.datasource.password>
<profiles.redis.uri>127.0.0.1</profiles.redis.uri> <profiles.redis.uri>127.0.0.1</profiles.redis.uri>
<profiles.redis.port>6379</profiles.redis.port> <profiles.redis.port>6379</profiles.redis.port>
<profiles.redis.username></profiles.redis.username> <profiles.redis.username></profiles.redis.username>
<profiles.redis.password>hotel@2020</profiles.redis.password> <profiles.redis.password>hotel@2020</profiles.redis.password>
<profiles.redis.database>9</profiles.redis.database> <profiles.redis.database>9</profiles.redis.database>
<profiles.rabbitmq.host>192.168.0.250</profiles.rabbitmq.host> <profiles.rabbitmq.host>127.0.0.1</profiles.rabbitmq.host>
<profiles.rabbitmq.port>5672</profiles.rabbitmq.port> <profiles.rabbitmq.port>5672</profiles.rabbitmq.port>
<profiles.rabbitmq.username>taxi_mq</profiles.rabbitmq.username> <profiles.rabbitmq.username>taxi_mq</profiles.rabbitmq.username>
<profiles.rabbitmq.password>admin@2020</profiles.rabbitmq.password> <profiles.rabbitmq.password>admin@2020</profiles.rabbitmq.password>
...@@ -215,15 +215,15 @@ ...@@ -215,15 +215,15 @@
<profiles.nacos.server-addr>127.0.0.1:8848</profiles.nacos.server-addr> <profiles.nacos.server-addr>127.0.0.1:8848</profiles.nacos.server-addr>
<profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group> <profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group>
<profiles.nacos.namespace>smart-gov</profiles.nacos.namespace> <profiles.nacos.namespace>smart-gov</profiles.nacos.namespace>
<profiles.log.path>/home/mortals/app/logs</profiles.log.path> <profiles.log.path>D:/home/mortals/app/logs</profiles.log.path>
<profiles.filepath>/mortals/app/data</profiles.filepath> <profiles.filepath>D:/mortals/app/data</profiles.filepath>
<package.environment>build</package.environment> <package.environment>yibin</package.environment>
<skipDeploy>false</skipDeploy> <skipDeploy>true</skipDeploy>
</properties> </properties>
</profile> </profile>
</profiles> </profiles>
<properties> <properties>
</properties> </properties>
......
...@@ -94,10 +94,12 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -94,10 +94,12 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY); String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid); String userKey = getTokenKey(uuid);
/* cacheService.select(portalDb); /* cacheService.select(portalDb);
String userStr = cacheService.get(userKey);*/ String userStr = cacheService.get(userKey);
cacheService.select(db);*/
RedisTemplate<String, String> redisTemplate = cacheService.selectDbRedisTemplate(portalDb); RedisTemplate<String, String> redisTemplate = cacheService.selectDbRedisTemplate(portalDb);
String userStr =redisTemplate.opsForValue().get(userKey); String userStr =redisTemplate.opsForValue().get(userKey);
// cacheService.select(db);
if (StringUtils.isNotEmpty(userStr)) { if (StringUtils.isNotEmpty(userStr)) {
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class); UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
userEntity.setToken(token); userEntity.setToken(token);
......
...@@ -81,10 +81,10 @@ public class AccessMessageConsumerListener { ...@@ -81,10 +81,10 @@ public class AccessMessageConsumerListener {
entity.setCreateUserId(1L); entity.setCreateUserId(1L);
entity.setCreateTime(new Date()); entity.setCreateTime(new Date());
//判断 超过一定时间的请求 才记录 //判断 超过一定时间的请求 才记录
// if (!ObjectUtils.isEmpty(entity.getDuration()) && entity.getDuration() < Constant.ACCESS_EXPIRE_TIME) { if (!ObjectUtils.isEmpty(entity.getDuration()) && entity.getDuration() < Constant.ACCESS_EXPIRE_TIME) {
// // log.info("Duration:{}",entity.getDuration()); // log.info("Duration:{}",entity.getDuration());
// return null; return null;
// } }
return entity; return entity;
} catch (Exception e) { } catch (Exception e) {
log.info("反序列化异常", e); log.info("反序列化异常", e);
......
...@@ -8,11 +8,10 @@ ...@@ -8,11 +8,10 @@
package com.mortals.xhx.base.system.user.dao.ibatis; package com.mortals.xhx.base.system.user.dao.ibatis;
import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis; import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.framework.model.ParamDto; import com.mortals.framework.model.ParamDto;
import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
......
...@@ -131,8 +131,7 @@ public class UserEntity extends UserVo implements IUser { ...@@ -131,8 +131,7 @@ public class UserEntity extends UserVo implements IUser {
@Override @Override
public boolean isAdmin() { public boolean isAdmin() {
return true; return super.getId() == null ? false : super.getId().longValue() == SysConstains.ADMIN_ID;
// return super.getId() == null ? false : super.getId().longValue() == SysConstains.ADMIN_ID;
} }
@Override @Override
......
package com.mortals.xhx.base.system.user.model;
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
import java.util.List;
/**
* Description:User
* date: 2021-9-26 16:11:48
*/
@Data
public class UserEntityExt extends BaseEntityLong {
/**
* 站点名称
*/
private String siteName;
private String roleIds;
/**
* 唯一标识
*/
private String token;
/**
* 菜单栏
*/
private String menuUrl;
/**
* 登录时间
*/
private Long loginTime;
/**
* 过期时间
*/
private Long expireTime;
}
\ No newline at end of file
package com.mortals.xhx.base.system.user.model; package com.mortals.xhx.base.system.user.model;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
* 用户信息业务查询对象 * 用户信息业务查询对象
......
...@@ -4,9 +4,6 @@ package com.mortals.xhx.base.system.user.model.vo; ...@@ -4,9 +4,6 @@ package com.mortals.xhx.base.system.user.model.vo;
import com.mortals.framework.model.BaseEntityLong; import com.mortals.framework.model.BaseEntityLong;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/** /**
* 用户信息业务视图对象 * 用户信息业务视图对象
* *
...@@ -15,6 +12,7 @@ import java.util.List; ...@@ -15,6 +12,7 @@ import java.util.List;
*/ */
@Data @Data
public class UserVo extends BaseEntityLong { public class UserVo extends BaseEntityLong {
/** /**
* 站点名称 * 站点名称
*/ */
...@@ -39,4 +37,8 @@ public class UserVo extends BaseEntityLong { ...@@ -39,4 +37,8 @@ public class UserVo extends BaseEntityLong {
* 过期时间 * 过期时间
*/ */
private Long expireTime; private Long expireTime;
private String oldPassword;
private String newPassword;
private String siteIds;
} }
\ No newline at end of file
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
package com.mortals.xhx.base.system.user.service; package com.mortals.xhx.base.system.user.service;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Result; import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.ICRUDService;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.xhx.base.system.menu.model.MenuEntity; import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.user.dao.UserDao; import com.mortals.xhx.base.system.user.dao.UserDao;
...@@ -28,17 +28,9 @@ import java.util.Set; ...@@ -28,17 +28,9 @@ import java.util.Set;
* @version 1.0.0 * @version 1.0.0
*/ */
public interface UserService extends ICRUDService<UserEntity,Long> { public interface UserService extends ICRUDCacheService<UserEntity,Long> {
/**
* 用户登录
*
* @param loginName 登录用户名
* @param password 登录密码
* @param loginIp 登录IP
* @return
* @throws AppException
*/
UserEntity doLogin(String loginName, String password, String loginIp) throws AppException;
/** /**
* 校验用户名与密码是否正确 * 校验用户名与密码是否正确
...@@ -48,16 +40,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -48,16 +40,7 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
UserEntity doCheckUser(String loginName, String password) throws AppException; UserEntity doCheckUser(String loginName, String password) throws AppException;
/**
* 检查用户是否存在
*
* @param loginName 登录用户名
* @param userId 密码
* @return
*/
boolean existUser(String loginName, Long userId) throws AppException;
/** /**
* 通过登录用户获取菜单功能权限 * 通过登录用户获取菜单功能权限
...@@ -73,49 +56,10 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -73,49 +56,10 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
* @param userEntity * @param userEntity
* @return * @return
*/ */
Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException; Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException;
/**
* 查询用户记录
*
* @param platformId
* @param params
* @param currPage
* @param prePageResult
* @return
* @throws AppException
*/
Result<UserEntity> find(Long platformId, UserEntity params, int currPage, int prePageResult) throws AppException;
/**
* 为客户创建用户
*
* @param currUser 当前用户
* @param customerId 客户ID
* @param customerName 客户名称
* @param loginName
* @param password
* @param userName
* @param mobile
* @return
* @throws AppException
*/
UserEntity createUser(IUser currUser, Long customerId, String customerName, String loginName, String password,
String userName, String mobile) throws AppException;
/**
* 用户修改密码
*
* @param loginName
* @param oldPwd
* @param newPwd
* @return
* @throws AppException
*/
boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException;
Rest<Void> refreshUser();
UserDao getUserDao(); UserDao getUserDao();
} }
\ No newline at end of file
...@@ -9,13 +9,12 @@ ...@@ -9,13 +9,12 @@
package com.mortals.xhx.base.system.user.service.impl; package com.mortals.xhx.base.system.user.service.impl;
import com.mortals.framework.ap.SysConstains; import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.code.UserType; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.SecurityUtil; import com.mortals.framework.util.SecurityUtil;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.menu.model.MenuEntity; import com.mortals.xhx.base.system.menu.model.MenuEntity;
...@@ -24,15 +23,19 @@ import com.mortals.xhx.base.system.resource.model.ResourceEntity; ...@@ -24,15 +23,19 @@ import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.service.ResourceService; import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.model.RoleUserEntity; import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery; import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleService;
import com.mortals.xhx.base.system.role.service.RoleUserService; import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.base.system.user.dao.UserDao; import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity; import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery; import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService; import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -49,69 +52,67 @@ import java.util.stream.Collectors; ...@@ -49,69 +52,67 @@ import java.util.stream.Collectors;
* @version 1.0.0 * @version 1.0.0
*/ */
@Service("userService") @Service("userService")
public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity, Long> implements UserService { @Slf4j
public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserEntity, Long> implements UserService {
@Autowired @Autowired
private MenuService menuService; private MenuService menuService;
@Autowired @Autowired
private ResourceService resourceService; private ResourceService resourceService;
@Autowired
private RoleService roleService;
@Autowired @Autowired
private RoleUserService roleUserService; private RoleUserService roleUserService;
private void doHandlerUser(UserEntity entity) throws AppException { @Lazy
if (StringUtils.isNotEmpty(entity.getLoginPwd())) { @Autowired
try { private IUserFeign userFeign;
entity.setLoginPwd(SecurityUtil.md5DoubleEncoding(entity.getLoginPwd()));
} catch (Exception e) {
throw new AppException("密码转换异常");
}
} else {
entity.setLoginPwd(null);
}
}
@Override @Override
protected void saveBefore(UserEntity entity, Context context) throws AppException { protected String getExtKey(UserEntity data) {
if (!ObjectUtils.isEmpty(entity.getLoginName()) && existUser(entity.getLoginName(), entity.getId())) { return data.getLoginName();
throw new AppException("登录名已存在!");
}
this.doHandlerUser(entity);
} }
@Override @Override
protected void updateBefore(UserEntity entity, Context context) throws AppException { public UserEntity doCheckUser(String loginName, String password) throws AppException {
// if (entity.getId().longValue() == SysConstains.ADMIN_ID && !context.getUser().isAdmin()) {
// throw new AppException("你没有权限执行该操作");
// }
//更新不更新密码字段 UserQuery params = new UserQuery();
entity.setLoginPwd(null); params.setLoginName(loginName);
this.doHandlerUser(entity); UserEntity sysUser = this.selectOne(params);
//更新角色 if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
if(entity.getId().longValue() != SysConstains.ADMIN_ID &&!ObjectUtils.isEmpty(entity.getRoleIds())){ return null;
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
List<Long> idList = Arrays.asList(entity.getRoleIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
roleUserQuery.setRoleIdList(idList);
roleUserService.doDistributionRole(roleUserQuery);
} }
try {
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(password))) {
return null;
}
} catch (Exception e) {
log.error("查询用户异常,loginName:" + loginName, e);
return null;
}
return sysUser;
} }
@Override @Override
protected void saveAfter(UserEntity entity, Context context) throws AppException { protected void saveAfter(UserEntity entity, Context context) throws AppException {
//更新角色 updateUserRole(entity);
if(!ObjectUtils.isEmpty(entity.getId())&&entity.getId().longValue() != SysConstains.ADMIN_ID &&!ObjectUtils.isEmpty(entity.getRoleIds())){ }
@Override
protected void updateAfter(UserEntity entity, Context context) throws AppException {
updateUserRole(entity);
}
private void updateUserRole(UserEntity entity) {
if (!ObjectUtils.isEmpty(entity.getId()) && entity.getId().longValue() != SysConstains.ADMIN_ID && !ObjectUtils.isEmpty(entity.getRoleIds())) {
RoleUserQuery roleUserQuery = new RoleUserQuery(); RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId()); roleUserQuery.setUserId(entity.getId());
List<Long> idList = Arrays.asList(entity.getRoleIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList()); List<Long> idList = Arrays.asList(entity.getRoleIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
roleUserQuery.setRoleIdList(idList); roleUserQuery.setRoleIdList(idList);
roleUserService.doDistributionRole(roleUserQuery); roleUserService.doDistributionRole(roleUserQuery);
} }
super.saveAfter(entity, context);
} }
@Override @Override
...@@ -122,66 +123,8 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -122,66 +123,8 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
String roleIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getRoleId).map(String::valueOf).collect(Collectors.joining(",")); String roleIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getRoleId).map(String::valueOf).collect(Collectors.joining(","));
item.setRoleIds(roleIds); item.setRoleIds(roleIds);
}).count(); }).count();
super.findAfter(params, pageInfo, context, list);
}
@Override
protected UserEntity findBefore(UserEntity params, Context context) throws AppException {
// if (StringUtils.isNotEmpty(params.getDeptIds())) {
// params.setDeptIds(StringUtils.fillWithMark(params.getDeptIds(), ","));
// }
return super.findBefore(params, context);
}
@Override
protected UserEntity findBefore(UserEntity params, PageInfo pageInfo, Context context) throws AppException {
// if (StringUtils.isNotEmpty(params.getDeptIds())) {
// params.setDeptIds(StringUtils.fillWithMark(params.getDeptIds(), ","));
// }
return super.findBefore(params, pageInfo, context);
} }
public UserEntity findByLoginName(String loginName) {
UserQuery params = new UserQuery();
params.setLoginName(loginName);
List<UserEntity> userList = super.dao.getList(params);
if (userList != null && userList.size() > 0) {
return userList.get(0);
}
return null;
}
@Override
public UserEntity doLogin(String loginName, String password, String loginIp) throws AppException {
UserEntity sysUser = this.findByLoginName(loginName);
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
throw new AppException("用户名不存在!");
}
try {
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(password))) {
throw new AppException("登录密码错误!");
}
} catch (Exception e) {
throw new AppException("密码验认出错!", e);
}
return sysUser;
}
@Override
public UserEntity doCheckUser(String loginName, String password) throws AppException {
UserEntity sysUser = this.findByLoginName(loginName);
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
return null;
}
try {
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(password))) {
return null;
}
} catch (Exception e) {
return null;
}
return sysUser;
}
@Override @Override
public Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException { public Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException {
...@@ -207,7 +150,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -207,7 +150,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
urls.addAll(StringUtils.converStr2Set(url)); urls.addAll(StringUtils.converStr2Set(url));
} }
} }
Set<Long> authIds = new HashSet<>(); Set<Long> authIds = new HashSet<Long>();
Map<Long, MenuEntity> menuMap = new HashMap<Long, MenuEntity>(); Map<Long, MenuEntity> menuMap = new HashMap<Long, MenuEntity>();
List<MenuEntity> userModuleList = this.menuService.findAllEnable(); List<MenuEntity> userModuleList = this.menuService.findAllEnable();
for (MenuEntity sysModule : userModuleList) { for (MenuEntity sysModule : userModuleList) {
...@@ -215,7 +158,6 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -215,7 +158,6 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
continue; continue;
} }
menuMap.put(sysModule.getId(), sysModule); menuMap.put(sysModule.getId(), sysModule);
if (!user.isAdmin() && urls.contains(StringUtils.trim(sysModule.getUrl()))) { if (!user.isAdmin() && urls.contains(StringUtils.trim(sysModule.getUrl()))) {
authIds.add(sysModule.getId()); authIds.add(sysModule.getId());
} }
...@@ -250,86 +192,85 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -250,86 +192,85 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
} }
@Override @Override
public Result<UserEntity> find(Long platformId, UserEntity params, int currPage, int prePageResult) throws AppException { public Rest<Void> refreshUser() {
PageInfo pageInfo = new PageInfo(prePageResult); UserPdu userPdu = new UserPdu();
pageInfo.setCurrPage(currPage); userPdu.setPage(1);
return super.find(params, pageInfo, null); userPdu.setSize(-1);
} Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu);
if (resp.getCode() == YesNoEnum.YES.getValue()) {
List<UserPdu> userPduList = resp.getData().getData();
log.info("用户总数量:{}", userPduList.size());
if (!ObjectUtils.isEmpty(userPduList)) {
List<UserEntity> newUserList = userPduList.stream().map(newUser -> {
UserEntity userEntity = new UserEntity();
userEntity.initAttrValue();
BeanUtils.copyProperties(newUser, userEntity, new String[]{"id", "lastLoginTime", "lastLoginAddress"});
return userEntity;
}).collect(Collectors.toList());
@Override List<UserEntity> saveUpdateUserList = newUserList.parallelStream().map(item -> {
public UserEntity createUser(IUser currUser, Long customerId, String customerName, String loginName, String password, UserEntity extCache = this.getExtCache(item.getLoginName());
String userName, String mobile) throws AppException { if (ObjectUtils.isEmpty(extCache)) {
try { item.setCreateUserId(1L);
UserEntity entity = new UserEntity(); item.setCreateUserName("系统管理员");
entity.initAttrValue(); item.setCreateTime(new Date());
entity.setLoginName(loginName); return item;
entity.setRealName(userName); } else {
entity.setLoginPwd(password); //更新用户列表
entity.setMobile(mobile); item.setId(extCache.getId());
entity.setUserType(UserType.CUSTOMER.getValue()); item.setUpdateUserId(1L);
entity.setCreateTime(new Date()); item.setUpdateUserName("系统管理员");
if (currUser != null) { item.setUpdateTime(new Date());
entity.setCreateUser(currUser.getLoginName()); return item;
entity.setCreateUserName(currUser.getRealName()); }
} }).collect(Collectors.toList());
this.doHandlerUser(entity); Map<Boolean, List<UserEntity>> saveUpdateCollect = saveUpdateUserList.stream().collect(Collectors.partitioningBy(x -> x.getId() == null));
dao.insert(entity); if (!ObjectUtils.isEmpty(saveUpdateCollect.get(true))) {
return entity; //需要新增的用户
} catch (Exception e) { log.info("需要新增用户数量:{}", saveUpdateCollect.get(true).size());
log.error("给客户创建用户异常-->customerId:" + customerId + ",customerName:" + customerName + ",loginName:" + loginName + saveUpdateCollect.get(true).stream().forEach(item -> {
"-->原因:" + e.getMessage()); this.getUserDao().insert(item);
return null; this.putCache(item.getId() == null ? "" : item.getId().toString(), item);
} RoleUserQuery roleUserQuery = new RoleUserQuery();
} roleUserQuery.setUserId(item.getId());
roleUserQuery.setRoleIdList(Arrays.asList(1L));
roleUserService.doDistributionRole(roleUserQuery);
});
}
@Override if (!ObjectUtils.isEmpty(saveUpdateCollect.get(false))) {
public boolean existUser(String loginName, Long userId) throws AppException { //需要新增的用户
UserEntity sysUser = this.findByLoginName(loginName); log.info("需要更新用户数量:{}", saveUpdateCollect.get(false).size());
boolean bRet = false; saveUpdateCollect.get(false).stream().forEach(item -> {
if (sysUser != null) { this.getUserDao().update(item);
if (userId == null || userId == 0 || userId.longValue() != sysUser.getId().longValue()) { this.putCache(item.getId() == null ? "" : item.getId().toString(), item);
bRet = true; });
}
//差集删除
Set<String> collectSet = newUserList.parallelStream().map(x -> x.getLoginName()).collect(Collectors.toSet());
Long[] removeUserIds = this.getCacheList().parallelStream().filter(f -> !collectSet.contains(f.getLoginName())).map(i -> i.getId()).distinct().toArray(Long[]::new);
if (!ObjectUtils.isEmpty(removeUserIds)) {
log.info("需要删除的本地用户数量:{}", removeUserIds.length);
this.remove(removeUserIds, null);
}
} }
//查找新增 与更新
} }
return bRet; return Rest.ok();
} }
@Override @Override
public boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException { protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
UserEntity sysUser = this.findByLoginName(loginName); super.removeAfter(ids, context, result);
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) { RoleUserQuery roleUserQuery = new RoleUserQuery();
throw new AppException("帐号错误!"); roleUserQuery.setUserIdList(Arrays.asList(ids));
} Long[] userIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getId).toArray(Long[]::new);
try { roleUserService.remove(userIds, context);
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(oldPwd))) {
throw new AppException("原始密码错误!");
}
} catch (Exception e) {
throw new AppException("密码验认出错!", e);
}
try {
sysUser.setLoginPwd(SecurityUtil.md5DoubleEncoding(newPwd));
} catch (Exception e) {
throw new AppException("密码转换异常!", e);
}
dao.update(sysUser);
return true;
} }
@Override
public UserDao getUserDao() {
return getDao();
}
@Override @Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException { public UserDao getUserDao() {
Arrays.asList(ids).stream().peek(userId->{ return this.getDao();
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(userId);
Long[] userIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getId).toArray(Long[]::new);
roleUserService.remove(userIds,context);
}).count();
super.removeAfter(ids, context, result);
} }
} }
\ No newline at end of file
/**
* 文件:UserController.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.user.web; package com.mortals.xhx.base.system.user.web;
import com.alibaba.fastjson.JSONObject; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.IBaseEnum; import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType; import com.mortals.framework.common.code.UserType;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BaseCRUDJsonMappingController; import com.mortals.xhx.base.system.role.model.RoleEntity;
import com.mortals.xhx.base.framework.annotation.Operlog;
import com.mortals.xhx.base.system.role.model.RoleQuery;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleService; import com.mortals.xhx.base.system.role.service.RoleService;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.base.system.user.model.UserEntity; import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.service.UserService; import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.UserStatus; import com.mortals.xhx.common.code.UserStatus;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping; 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.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import java.util.List;
import javax.servlet.http.HttpServletResponse;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 用户信息 * <p>Title: 用户信息</p>
* * <p>Description: UserController </p>
* @author: zxfei * <p>Copyright: Copyright &reg; </p>
* @date: 2022/5/7 15:42 * <p>Company: </p>
* @author
* @version 1.0.0
*/ */
@RestController @RestController
@RequestMapping("user") @RequestMapping("user")
...@@ -46,91 +42,28 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic ...@@ -46,91 +42,28 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
@Autowired @Autowired
private RoleService roleService; private RoleService roleService;
@Autowired
private RoleUserService roleUserService;
public UserController() { public UserController() {
super.setFormClass(UserForm.class);
super.setModuleDesc("用户信息"); super.setModuleDesc("用户信息");
} }
@Override @Override
protected void init(Map<String, Object> model, Context context) { protected void init(Map<String, Object> model, Context context) {
this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class)); this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class));
this.addDict(model,"status", UserStatus.getEnumMap()); this.addDict(model,"status", UserStatus.getEnumMap());
this.addDict(model, "roleIds", roleService.find(new RoleQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getName()))); List<RoleEntity> roleList = roleService.find(new RoleEntity());
this.addDict(model,"roleId", roleList.stream().collect(Collectors.toMap(e->e.getId().toString(), e->e.getName())));
super.init(model, context);
} }
@Override
protected void doListBefore(UserEntity query, Map<String, Object> model, Context context) throws AppException {
if (!StringUtils.isEmpty(query.getRealName())) {
query.setRealName("%".concat(query.getRealName()).concat("%"));
}
if (!StringUtils.isEmpty(query.getLoginName())) {
query.setLoginName("%".concat(query.getLoginName()).concat("%"));
}
}
@Override
protected int editAfter(Long id, Map<String, Object> model, UserEntity entity, Context context) throws AppException {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
String roleIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getRoleId).map(String::valueOf).collect(Collectors.joining(","));
entity.setRoleIds(roleIds);
return super.editAfter(id, model, entity, context);
}
@Override
protected int saveAfter(UserEntity entity, Map<String, Object> model, Context context) throws AppException {
if (entity.getId() == getCurUser().getId()) {
// TODO: 2022/8/15 更新redis session信息
//saveCurrUserForSession(request, response, userService.get(form.getEntity().getId(), false));
}
return super.saveAfter(entity, model, context);
}
// @Override
// protected void saveBefore(UserEntity entity, Map<String, Object> model, Context context) throws AppException {
// if (!ObjectUtils.isEmpty(entity.getLoginName()) && service.existUser(entity.getLoginName(), entity.getId())) {
// throw new AppException("登录名已存在!");
// }
// super.saveBefore(entity, model, context);
// }
@RequestMapping(value = "change/password", method = RequestMethod.POST)
@Operlog(msg = "密码修改成功!")
public String changePassword(@RequestParam String oldPwd, @RequestParam String newPwd) {
JSONObject ret = new JSONObject();
try {
service.updateUserPwd(super.getCurUser().getLoginName(), oldPwd, newPwd);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "密码修改成功!");
} catch (Exception e) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
}
return ret.toJSONString();
}
public static void main(String[] args) {
String token = "eyJhbGciOiJIUzI1NiJ9.eyJsb2dpbl91c2VyX2tleSI6IjIzNGE5NDA5ZDVhOTQ3MWNhMzdkYjZkYmMwY2JjZTc5In0.MWyQW40HYDxyUz7PJRf_nRsFPWx3Hr811Ime984nixs";
String secret = "026db82420614469897fcc2dc1b4ce38";
Claims claims = Jwts.parser()
.setSigningKey(Base64.getEncoder().encodeToString(secret.getBytes()))
.parseClaimsJws(token)
.getBody();
String uuid = (String) claims.get("login_user_key");
System.out.println(uuid);
@PostMapping({"refreshUser"})
@UnAuth
public Rest<Object> refreshUser() {
log.info("刷新用户");
this.service.refreshUser();
return Rest.ok("用户同步刷新操作成功");
} }
} }
\ No newline at end of file
/**
* 文件:UserForm.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.user.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
/**
* <p>Title: 用户信息</p>
* <p>Description: UserForm </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
*/
public class UserForm extends BaseCRUDFormLong<UserEntity> {
private UserEntity entity = new UserEntity();
private UserQuery query = new UserQuery();
public UserForm(){
}
@Override
public UserEntity getEntity() {
return entity;
}
public void setEntity(UserEntity entity) {
this.entity = entity;
}
@Override
public UserQuery getQuery() {
return query;
}
public void setQuery(UserQuery query) {
this.query = query;
}
}
\ No newline at end of file
...@@ -115,8 +115,8 @@ public final class Constant { ...@@ -115,8 +115,8 @@ public final class Constant {
public static final String DISTRIBUTE_PATH = "distribute_path"; public static final String DISTRIBUTE_PATH = "distribute_path";
/** /**
* 访问超时时间,默认2 * 访问超时时间,默认1
*/ */
public static final Long ACCESS_EXPIRE_TIME = 2000L; public static final Long ACCESS_EXPIRE_TIME = 1000L;
} }
package com.mortals.xhx.daemon.applicationservice;
import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.framework.util.ThreadPool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 应用级服务,在应用启动后、停止过程中调用
* 应用已经完成启动完成,才调用该服务
* 应用场景:
* 1、应用任务,应用启动后定时或间隔执行的任务
* 2、Socket服务端
*/
@Component
@Slf4j
public class DemoStartedService implements IApplicationStartedService {
@Override
public void start() {
ThreadPool.getInstance().init(10);
}
@Override
public void stop() {
log.info("停止服务..");
}
@Override
public int getOrder() {
return 10;
}
}
package com.mortals.xhx.daemon.task;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;
/**
* 同步用户
*/
@Slf4j
@Service("SyncUserTask")
@ConditionalOnExpression("'${spring.profiles.active}'!='develop'")
public class SyncUserTaskImpl implements ITaskExcuteService {
@Autowired
private UserService userService;
@Autowired
private IUserFeign userFeign;
@Override
public void excuteTask(ITask task) throws AppException {
userService.refreshUser();
log.info("同步用户");
/* UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> list = userFeign.list(userPdu);
userService.updateUserList(list.getData().getData());*/
//resourceService.updateUserList();
/* UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> list = userFeign.list(userPdu);
*//* List<UserPdu> firstList = list.getData().getData();
List<UserEntity> secondList = userService.find(new UserQuery());
//交叉对比后,多的新增 少的删除
List<UserEntity> diffList = secondList.parallelStream()
.filter(item -> !firstList.parallelStream().map(e -> e.getId()).collect(Collectors.toList()).contains(item.getId()))
.collect(Collectors.toList());*//*
//log.info("diffList:{}",JSON.toJSONString(diffList));
//更新本地用户信息,并且更新用户站点树
list.getData().getData().forEach(user -> {
//查询用户是否存在,
//UserEntity userEntity = userService.get(user.getId());
UserEntity userEntity =userService.selectOne(new UserQuery().loginName(user.getLoginName()));
if (ObjectUtils.isEmpty(userEntity)) {
//新增
UserEntity entity = new UserEntity();
entity.initAttrValue();
BeanUtils.copyProperties(user, entity, BeanUtil.getNullPropertyNames(user));
userService.save(entity);
Context context = new Context();
context.setUser(entity);
new Thread(new SyncTreeSiteThread(siteService, context)).start();
}
});*/
}
@Override
public void stopTask(ITask task) throws AppException {
}
}
...@@ -87,20 +87,20 @@ ...@@ -87,20 +87,20 @@
</trim> </trim>
</sql> </sql>
<!-- 新增 区分主键自增加还是业务插入 --> <!-- 新增 区分主键自增加还是业务插入 -->
<insert id="insert" parameterType="UserEntity" useGeneratedKeys="true" keyProperty="id"> <insert id="insert" parameterType="UserEntity" >
insert into mortals_xhx_user insert into mortals_xhx_user
(loginName,loginPwd,loginLimitAddress,realName,mobile,phone,email,qq,userType,siteIds,areaCodes,status,createTime,createUserId,createUserName,lastLoginTime,lastLoginAddress) (id,loginName,loginPwd,loginLimitAddress,realName,mobile,phone,email,qq,userType,siteIds,areaCodes,status,createTime,createUserId,createUserName,lastLoginTime,lastLoginAddress)
VALUES VALUES
(#{loginName},#{loginPwd},#{loginLimitAddress},#{realName},#{mobile},#{phone},#{email},#{qq},#{userType},#{siteIds},#{areaCodes},#{status},#{createTime},#{createUserId},#{createUserName},#{lastLoginTime},#{lastLoginAddress}) (#{id},#{loginName},#{loginPwd},#{loginLimitAddress},#{realName},#{mobile},#{phone},#{email},#{qq},#{userType},#{siteIds},#{areaCodes},#{status},#{createTime},#{createUserId},#{createUserName},#{lastLoginTime},#{lastLoginAddress})
</insert> </insert>
<!-- 批量新增 --> <!-- 批量新增 -->
<insert id="insertBatch" parameterType="paramDto"> <insert id="insertBatch" parameterType="paramDto">
insert into mortals_xhx_user insert into mortals_xhx_user
(loginName,loginPwd,loginLimitAddress,realName,mobile,phone,email,qq,userType,siteIds,areaCodes,status,createTime,createUserId,createUserName,lastLoginTime,lastLoginAddress) (id,loginName,loginPwd,loginLimitAddress,realName,mobile,phone,email,qq,userType,siteIds,areaCodes,status,createTime,createUserId,createUserName,lastLoginTime,lastLoginAddress)
VALUES VALUES
<foreach collection="data.dataList" item="item" index="index" separator="," > <foreach collection="data.dataList" item="item" index="index" separator="," >
(#{item.loginName},#{item.loginPwd},#{item.loginLimitAddress},#{item.realName},#{item.mobile},#{item.phone},#{item.email},#{item.qq},#{item.userType},#{item.siteIds},#{item.areaCodes},#{item.status},#{item.createTime},#{item.createUserId},#{item.createUserName},#{item.lastLoginTime},#{item.lastLoginAddress}) (#{item.id},#{item.loginName},#{item.loginPwd},#{item.loginLimitAddress},#{item.realName},#{item.mobile},#{item.phone},#{item.email},#{item.qq},#{item.userType},#{item.siteIds},#{item.areaCodes},#{item.status},#{item.createTime},#{item.createUserId},#{item.createUserName},#{item.lastLoginTime},#{item.lastLoginAddress})
</foreach> </foreach>
</insert> </insert>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.iot.base.system.user.dao.ibatis.UserDaoImpl">
<!-- 获取列表 -->
<select id="getAuthListById" parameterType="paramDto" resultType="Long">
select resourceId
from mortals_iot_role_auth as a
left join mortals_iot_role_user as b
on a.roleId=b.roleId
where b.userId=#{condition.id}
</select>
</mapper>
\ No newline at end of file
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