Commit e7e17b9b authored by 赵啸非's avatar 赵啸非

修改门户资源鉴权

parent d500463e
......@@ -5,6 +5,7 @@ import cn.hutool.core.util.URLUtil;
import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
......@@ -13,6 +14,7 @@ import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.HttpUtil;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.AreaLevelDxTypeEnum;
......@@ -60,6 +62,7 @@ import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
import static com.mortals.framework.util.HttpUtil.HEADER_CONTENT_TYPE;
import static com.mortals.xhx.common.key.Constant.*;
/**
......@@ -189,7 +192,6 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
//刷新站点树
//ThreadPool.getInstance().execute(new SyncTreeSiteThread(this,context));
Rest<String> rest = userFeign.synchSiteAuth();
log.info("站点更新2");
if (rest.getCode().equals(YesNoEnum.YES.getValue())) {
UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
......@@ -197,10 +199,23 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
Rest<RespData<List<UserPdu>>> list = userFeign.list(userPdu);
userService.updateUserList(list.getData().getData());
}
log.info("站点更新3");
//更新同步部门相关
deptService.syncDeptBySiteId(entity, context);
log.info("站点更新4");
//通知php系统更新
String phpUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://172.15.28.116:8090");
HashMap<String, String> paramsMap = new HashMap<>();
paramsMap.put("siteid", entity.getId().toString());
phpUrl += "/api/site/childSiteSet";
String resp = null;
try {
resp = HttpUtil.doGet(phpUrl, paramsMap);
log.info("thirdPartyUrl =>resp:{}", resp);
} catch (Exception e) {
log.error("异常:", e);
}
}
......@@ -327,17 +342,13 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
protected void updateAfter(SiteEntity entity, Context context) throws AppException {
super.updateAfter(entity,context);
//刷新站点树
log.info("update1");
Rest<String> rest = userFeign.synchSiteAuth();
if (rest.getCode().equals(YesNoEnum.YES.getValue())) {
log.info("update2");
UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> list = userFeign.list(userPdu);
log.info("update21");
userService.updateUserList(list.getData().getData());
log.info("update22");
}
if (refresh) {
//通知设备更新站点信息
......
......@@ -17,6 +17,8 @@ import com.mortals.xhx.common.code.FiletypeEnum;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.common.utils.FreeMarkerUtils;
import com.mortals.xhx.feign.skin.ISkinFillFeign;
import com.mortals.xhx.feign.skin.ISkinSampleFeign;
import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.service.ProductService;
import com.mortals.xhx.module.skin.dao.SkinBaseDao;
......@@ -64,6 +66,10 @@ public class SkinBaseServiceImpl extends AbstractCRUDServiceImpl<SkinBaseDao, Sk
private ProductService productService;
@Autowired
private ParamService paramService;
@Autowired
private ISkinSampleFeign skinSampleFeign;
@Autowired
private ISkinFillFeign skinFillFeign;
@Override
protected void validData(SkinBaseEntity entity, Context context) throws AppException {
......@@ -161,6 +167,9 @@ public class SkinBaseServiceImpl extends AbstractCRUDServiceImpl<SkinBaseDao, Sk
});
skinFieldService.save(entity.getSkinFieldList(), context);
}
//通知子系统同步皮肤数据
skinSampleFeign.refreshSkin();
skinFillFeign.refreshSkin();
}
@Override
......
package com.mortals.xhx.feign.area;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.pdu.SitePdu;
import com.mortals.xhx.feign.IFeign;
......@@ -70,6 +71,15 @@ public interface IApiAreaFeign extends IFeign {
@PostMapping(value = "/site/getFlatSitesByAreaIds")
String getFlatSitesByAreaIds(@RequestBody SitePdu query);
/**
* 用户刷新通知
*
* @param
* @return
*/
@PostMapping(value = "/usr/refreshUser")
Rest<Void> refreshUser();
// /**
// * 根据条件查询站点列表
// * @param query
......@@ -134,6 +144,16 @@ class AreaFeignFallbackFactory implements FallbackFactory<IApiAreaFeign> {
return JSON.toJSONString(failResp);
}
/**
* @return
*/
@Override
public Rest<Void> refreshUser() {
return Rest.fail("暂时无法通知设备,请稍后再试!");
}
// @Override
// public String getSitesByQuery(SitePdu query) {
// ApiResp<String> failResp = new ApiResp<>();
......
......@@ -69,6 +69,16 @@ public interface IDeviceFeign extends IFeign {
Rest<Void> refreshMessage(@RequestBody DevicePdu devicePdu);
/**
* 用户刷新通知
*
* @param
* @return
*/
@PostMapping(value = "/usr/refreshUser")
Rest<Void> refreshUser();
}
......@@ -106,6 +116,14 @@ class DeviceFeignFallbackFactory implements FallbackFactory<IDeviceFeign> {
public Rest<Void> refreshMessage(DevicePdu devicePdu) {
return Rest.fail("暂时无法通知设备,请稍后再试!");
}
/**
* @return
*/
@Override
public Rest<Void> refreshUser() {
return Rest.fail("暂时无法通知设备,请稍后再试!");
}
};
}
}
......
package com.mortals.xhx.feign.skin;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.feign.IFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
/**
* 填单皮肤 Feign接口
* @author zxfei
* @date 2022-10-26
*/
@FeignClient(name = "fill-manager", path = "/fm", fallbackFactory = SkinFillFeignFallbackFactory.class)
public interface ISkinFillFeign extends IFeign {
/**
* 皮肤变更通知
*
* @param
* @return
*/
@PostMapping(value = "/skin/refreshSkin")
Rest<Void> refreshSkin();
/**
* 用户刷新通知
*
* @param
* @return
*/
@PostMapping(value = "/usr/refreshUser")
Rest<Void> refreshUser();
}
@Slf4j
@Component
class SkinFillFeignFallbackFactory implements FallbackFactory<ISkinFillFeign> {
@Override
public ISkinFillFeign create(Throwable t) {
return new ISkinFillFeign() {
/**
* @param
* @return
*/
@Override
public Rest<Void> refreshSkin() {
return Rest.fail("暂时无法通知设备,请稍后再试!");
}
/**
* @return
*/
@Override
public Rest<Void> refreshUser() {
return Rest.fail("暂时无法通知设备,请稍后再试!");
}
};
}
}
package com.mortals.xhx.feign.skin;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.feign.IFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
/**
* 样表皮肤 Feign接口
* @author zxfei
* @date 2022-10-26
*/
@FeignClient(name = "sample-form-manager", path = "/sampleform", fallbackFactory = SkinFillFeignFallbackFactory.class)
public interface ISkinSampleFeign extends IFeign {
/**
* 皮肤变更通知
*
* @param
* @return
*/
@PostMapping(value = "/skin/refreshSkin")
Rest<Void> refreshSkin();
/**
* 用户刷新通知
*
* @param
* @return
*/
@PostMapping(value = "/usr/refreshUser")
Rest<Void> refreshUser();
}
@Slf4j
@Component
class SkinSampleFeignFallbackFactory implements FallbackFactory<ISkinFillFeign> {
@Override
public ISkinFillFeign create(Throwable t) {
return new ISkinFillFeign() {
/**
* @param
* @return
*/
@Override
public Rest<Void> refreshSkin() {
return Rest.fail("暂时无法通知设备,请稍后再试!");
}
/**
* @return
*/
@Override
public Rest<Void> refreshUser() {
return Rest.fail("暂时无法通知设备,请稍后再试!");
}
};
}
}
......@@ -61,4 +61,12 @@ CREATE TABLE `mortals_xhx_user_model_collect` (
ALTER TABLE `mortals_xhx_user_model_collect`
ADD COLUMN `siteId` bigint(20) DEFAULT NULL COMMENT '站点ID';
UPDATE mortals_xhx_user_model_collect SET siteId=1;
\ No newline at end of file
UPDATE mortals_xhx_user_model_collect SET siteId=1;
-- ----------------------------
2023-11-13
-- ----------------------------
ALTER TABLE mortals_xhx_role_auth ADD COLUMN `resourceId` bigint(20) COMMENT '资源ID';
ALTER TABLE mortals_xhx_role_auth ADD COLUMN `createTime` datetime COMMENT '创建时间';
ALTER TABLE mortals_xhx_role_auth ADD COLUMN `createUserId` bigint(20) COMMENT '创建用户';
ALTER TABLE mortals_xhx_role_auth ADD COLUMN `createUserName` varchar(50) COMMENT '创建用户名称';
......@@ -8,6 +8,11 @@ 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.resource.service.ResourceService;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.utils.MenuEncodeUtil;
import com.mortals.xhx.module.user.model.UserEntity;
import com.mortals.xhx.module.user.service.UserService;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
......@@ -50,6 +55,9 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
@Value("${token.prefix:}")
private String tokenPrefix;
@Autowired
private UserService userService;
protected static final Long MILLIS_SECOND = 1l;
protected static final Long MILLIS_MINUTE = 60 * MILLIS_SECOND;
......@@ -65,6 +73,9 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
@Autowired
private ICacheService cacheService;
@Autowired
private ResourceService resourceService;
/**
* 获取信息
*
......@@ -85,7 +96,25 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid);
String userStr = cacheService.get(userKey);
if (StringUtils.isNotEmpty(userStr)) {
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
userEntity.setToken(token);
//更新portal 中的id 为 device中的id
// UserEntity temp = userService.selectOne(new UserQuery().loginName(userEntity.getLoginName()));
UserEntity temp = userService.getExtCache(userEntity.getLoginName());
if (!ObjectUtils.isEmpty(temp)) {
userEntity.setId(temp.getId());
}
//更新resource 路径
String menuUrlCode = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class);
if (ObjectUtils.isEmpty(menuUrlCode)) {
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
menuUrlCode = MenuEncodeUtil.generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrlCode);
}
userEntity.setMenuUrl(menuUrlCode);
return userEntity;
/* if (StringUtils.isNotEmpty(userStr)) {
JSONObject userObj = JSON.parseObject(userStr);
Long userId = userObj.getLongValue("id");
Integer userType = userObj.getIntValue("userType");
......@@ -198,8 +227,6 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
public void setExpireTime(Long expireTime) {
}
@Override
public String getMenuUrl() {
return menuUrl;
......@@ -207,7 +234,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
};
}
}*/
// return cacheService.get(userKey, IUser.class);
} catch (Exception e) {
log.error("解析jwt token异常!", e);
......
/**
* 文件:ResourceServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
* 文件:ResourceServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.resource.service.impl;
......@@ -19,9 +19,14 @@ import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.model.ResourceQuery;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.module.role.model.RoleAuthEntity;
import com.mortals.xhx.module.role.model.RoleAuthQuery;
import com.mortals.xhx.module.role.service.RoleAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -33,15 +38,20 @@ import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
* <p>Description: ResourceServiceImpl service接口 </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
*
* @author
* @version 1.0.0
*/
@Service("resourceService")
public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,ResourceEntity,Long> implements ResourceService {
public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, ResourceEntity, Long> implements ResourceService {
@Autowired
private ICacheService cacheService;
@Autowired
private RoleAuthService roleAuthService;
@Override
public List<ResourceEntity> findAllEnable() throws AppException {
ResourceQuery params = new ResourceQuery();
......@@ -90,13 +100,27 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,Res
updateUserMenuUrlCache();
}
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
//删除关联表中数据
if (!ObjectUtils.isEmpty(ids)) {
RoleAuthQuery query = new RoleAuthQuery();
query.setResourceIdList(Arrays.asList(ids));
List<RoleAuthEntity> roleAuthEntities = roleAuthService.find(query);
if (!ObjectUtils.isEmpty(roleAuthEntities)) {
roleAuthService.remove(roleAuthEntities.stream().map(m -> m.getId()).toArray(Long[]::new), context);
updateUserMenuUrlCache();
}
}
}
private void updateUserMenuUrlCache() {
//更新用户菜单
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE);
for (String userId : hkeys) {
Set<String> urls = this.findUrlSetByUserId(DataUtil.converStr2Long(userId,0L));
Set<String> urls = this.findUrlSetByUserId(DataUtil.converStr2Long(userId, 0L));
String menuUrlCode = generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId,menuUrlCode);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId, menuUrlCode);
}
}
}
\ No newline at end of file
package com.mortals.xhx.module.role.model;
import java.util.List;
import java.util.ArrayList;
import java.math.BigDecimal;
import cn.hutool.core.date.DateUtil;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.role.model.vo.RoleAuthVo;
import lombok.Data;
/**
* 角色菜单权限关联实体对象
*
* @author zxfei
* @date 2022-06-02
*/
* 角色菜单权限关联实体对象
*
* @author zxfei
* @date 2023-11-13
*/
@Data
public class RoleAuthEntity extends RoleAuthVo {
private static final long serialVersionUID = 1L;
/**
* 角色ID
*/
* 角色ID
*/
private Long roleId;
/**
* 菜单ID
*/
* 菜单ID
*/
private Long menuId;
public RoleAuthEntity(){}
/**
* 获取 角色ID
* @return Long
*/
public Long getRoleId(){
return roleId;
}
/**
* 设置 角色ID
* @param roleId
*/
public void setRoleId(Long roleId){
this.roleId = roleId;
}
/**
* 获取 菜单ID
* @return Long
*/
public Long getMenuId(){
return menuId;
}
* 资源ID
*/
private Long resourceId;
/**
* 设置 菜单ID
* @param menuId
*/
public void setMenuId(Long menuId){
this.menuId = menuId;
}
* 创建用户名称
*/
private String createUserName;
@Override
public int hashCode() {
return this.getId().hashCode();
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
......@@ -70,23 +45,16 @@ public class RoleAuthEntity extends RoleAuthVo {
if (obj instanceof RoleAuthEntity) {
RoleAuthEntity tmp = (RoleAuthEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
return true;
}
}
return false;
}
public String toString(){
StringBuilder sb = new StringBuilder("");
sb.append(",roleId:").append(getRoleId());
sb.append(",menuId:").append(getMenuId());
return sb.toString();
}
public void initAttrValue(){
this.roleId = null;
this.menuId = null;
this.roleId = null;
this.menuId = null;
this.resourceId = null;
this.createUserName = "";
}
}
\ No newline at end of file
......@@ -28,4 +28,8 @@ public interface RoleAuthService extends ICRUDService<RoleAuthEntity, Long> {
* @return
*/
Map<Long,List<Long>> getMenuIdByRole(Long userId);
/** 角色分配资源 */
void doDistributionSource(RoleAuthQuery query);
}
\ No newline at end of file
......@@ -29,6 +29,27 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
@Autowired
private RoleUserService roleUserService;
@Override
public void doDistributionSource(RoleAuthQuery query) {
// 删除角色资源老数据
Long roleId = query.getRoleId();
Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId);
condition.put("menuId", null);
this.dao.delete(condition);
List<RoleAuthEntity> list = new ArrayList<>();
for (Long sourceId : query.getResourceIdList()) {
RoleAuthEntity entity = new RoleAuthEntity();
entity.setRoleId(roleId);
entity.setResourceId(sourceId);
list.add(entity);
}
this.dao.insertBatch(list);
}
@Override
public void assignMenu(RoleAuthQuery query) {
Map<Long, MenuEntity> menuEntityMap = menuService.find(new MenuQuery()).stream().collect(Collectors.toMap(x -> x.getId(), y -> y));
......@@ -36,6 +57,7 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
Long roleId = query.getRoleId();
Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId);
condition.put("resoruceId", null);
this.dao.delete(condition);
Set<Long> curSet = query.getMenuIdList().stream().collect(Collectors.toSet());
......@@ -70,27 +92,27 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
}
@Override
public Map<Long,List<Long>> getMenuIdByRole(Long roleId) {
public Map<Long, List<Long>> getMenuIdByRole(Long roleId) {
RoleAuthQuery condition = new RoleAuthQuery();
condition.setRoleId(roleId);
List<RoleAuthEntity> roleModelEntities = this.find(condition);
if(CollectionUtils.isNotEmpty(roleModelEntities)) {
if (CollectionUtils.isNotEmpty(roleModelEntities)) {
List<Long> menuIds = roleModelEntities.stream().map(RoleAuthEntity::getMenuId).collect(Collectors.toList());
MenuQuery query1 = new MenuQuery();
query1.setIdList(menuIds);
List<MenuEntity> menuEntities = menuService.find(query1);
Map<Long,List<Long>> map = new HashMap<>();
menuEntities.forEach(m->{
if(map.containsKey(m.getParentId())){
Map<Long, List<Long>> map = new HashMap<>();
menuEntities.forEach(m -> {
if (map.containsKey(m.getParentId())) {
map.get(m.getParentId()).add(m.getId());
}else {
} else {
List<Long> menuIdList = new ArrayList<>();
menuIdList.add(m.getId());
map.put(m.getParentId(),menuIdList);
map.put(m.getParentId(), menuIdList);
}
});
return map;
}else {
} else {
return Collections.emptyMap();
}
}
......
......@@ -37,6 +37,27 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
super.init(model, context);
}
/**
* 分配资源
*/
@PostMapping(value = "distributionSource")
public String distributionUser(@RequestBody RoleAuthQuery query) {
try {
service.doDistributionSource(query);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色资源错误", e);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
/**
* 分配菜单到角色
*/
......
......@@ -57,6 +57,11 @@ public class UserVo extends BaseEntityLong {
private String oldPwd;
private String newPwd;
/**
* 菜单栏
*/
private String menuUrl;
public static void main(String[] args) {
UserQuery userEntity = new UserQuery();
......
......@@ -4,6 +4,7 @@ import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.user.model.UserEntity;
import com.mortals.xhx.module.user.model.UserEntityExt;
......@@ -16,7 +17,7 @@ import com.mortals.xhx.module.user.model.UserEntityExt;
* @author zxfei
* @date 2022-05-25
*/
public interface UserService extends ICRUDService<UserEntity,Long>{
public interface UserService extends ICRUDCacheService<UserEntity,Long> {
/**
* 用户登录
*
......
......@@ -12,6 +12,7 @@ import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.IAuthTokenService;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.*;
import com.mortals.xhx.common.code.YesNoEnum;
......@@ -44,7 +45,7 @@ import java.util.stream.Collectors;
* @date 2022-05-25
*/
@Service("userService")
public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity, Long> implements UserService {
public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserEntity, Long> implements UserService {
@Autowired
private MenuService menuService;
@Autowired
......@@ -60,8 +61,17 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
@Autowired
private UserPwdRecordDao userPwdRecordDao;
/**
* @param data
* @return
*/
@Override
protected String getExtKey(UserEntity data) {
return data.getLoginName();
}
/* @Override
/* @Override
protected void findAfter(UserEntity entity, PageInfo pageInfo, Context context, List<UserEntity> list) throws AppException {
Map<Long, String> roleMap = roleService.find(new RoleQuery()).stream().collect(Collectors.toMap(x -> x.getId(), y -> y.getName()));
List<Long> userIdList = list.stream().map(item -> item.getId()).collect(Collectors.toList());
......@@ -79,22 +89,22 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
private void doHandlerUser(UserEntity entity) throws AppException {
if (StringUtils.isNotEmpty(entity.getLoginPwd())) {
if(!Solution.strongPasswordCheckerII(entity.getLoginPwd())){
if (!Solution.strongPasswordCheckerII(entity.getLoginPwd())) {
throw new AppException("新密码至少八位以上,包含大小写加特殊字符加数字");
}
try {
if(StringUtils.isEmpty(entity.getSaltKey())){
String saltKey = SecurityCode.getSecurityCode(6,SecurityCode.SecurityCodeLevel.Medium,false);
if (StringUtils.isEmpty(entity.getSaltKey())) {
String saltKey = SecurityCode.getSecurityCode(6, SecurityCode.SecurityCodeLevel.Medium, false);
entity.setSaltKey(saltKey);
}
entity.setLoginPwd(SecurityUtil.md5DoubleEncoding(entity.getLoginPwd() + entity.getSaltKey()));
} catch (Exception e) {
throw new AppException("密码转换异常");
}
if(entity.getId()!=null) {
if (entity.getId() != null) {
UserEntity old = this.get(entity.getId());
if (old != null ) {
if(!old.getLoginPwd().equals(entity.getLoginPwd())){
if (old != null) {
if (!old.getLoginPwd().equals(entity.getLoginPwd())) {
//判断新密码与最近五次修改密码是否相同
UserPwdRecordQuery recordQuery = new UserPwdRecordQuery();
recordQuery.setUserId(entity.getId());
......@@ -103,10 +113,10 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
add(new OrderCol("a.createTime", "desc"));
}
});
List<UserPwdRecordEntity> recordEntityList = userPwdRecordDao.getList(recordQuery,0,5);
if(CollectionUtils.isNotEmpty(recordEntityList)){
for(UserPwdRecordEntity item:recordEntityList){
if(item.getLoginPwd().equals(entity.getLoginPwd())){
List<UserPwdRecordEntity> recordEntityList = userPwdRecordDao.getList(recordQuery, 0, 5);
if (CollectionUtils.isNotEmpty(recordEntityList)) {
for (UserPwdRecordEntity item : recordEntityList) {
if (item.getLoginPwd().equals(entity.getLoginPwd())) {
throw new AppException("新密码不能与最近五次密码相同!");
}
}
......@@ -178,39 +188,39 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
throw new AppException("用户名不存在!");
}
if(sysUser.getErrorCount()==null){
if (sysUser.getErrorCount() == null) {
sysUser.setErrorCount(0);
}
if(sysUser.getLoginLock()==null){
if (sysUser.getLoginLock() == null) {
sysUser.setLoginLock(0);
}
if(sysUser.getLoginLock() == 1 && sysUser.getLockTime()!=null){
if (sysUser.getLoginLock() == 1 && sysUser.getLockTime() != null) {
String nowStr = DateUtils.getCurrStrDate();
String loginDateStr = DateUtils.getDateTime(sysUser.getLockTime(),"yyyy-MM-dd");
if(nowStr.equals(loginDateStr)) {
String loginDateStr = DateUtils.getDateTime(sysUser.getLockTime(), "yyyy-MM-dd");
if (nowStr.equals(loginDateStr)) {
throw new AppException("此账号当天密码错误次数已达上限,已被锁定");
}
}
try {
if(StringUtils.isNotEmpty(sysUser.getSaltKey())) {
if (StringUtils.isNotEmpty(sysUser.getSaltKey())) {
password += sysUser.getSaltKey();
}
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(password))) {
UserEntity update = new UserEntity();
update.setId(sysUser.getId());
update.setErrorCount(sysUser.getErrorCount()+1);
if(update.getErrorCount()==5){
update.setErrorCount(sysUser.getErrorCount() + 1);
if (update.getErrorCount() == 5) {
update.setLoginLock(1);
update.setLockTime(new Date());
}
this.dao.update(update);
throw new AppException("登录密码错误!");
}else {
if(sysUser.getLastUpdatePwdTime()!=null) {
} else {
if (sysUser.getLastUpdatePwdTime() != null) {
long day = DateUtils.getBetween(sysUser.getLastUpdatePwdTime(), new Date(), 2);
if (day >= 90) {
throw new AppException(99998,"密码已超过三个月没有更改,请修改以后再登录");
throw new AppException(99998, "密码已超过三个月没有更改,请修改以后再登录");
}
}
}
......@@ -261,13 +271,13 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
throw new AppException("帐号错误!");
}
try {
if(StringUtils.isNotEmpty(sysUser.getSaltKey())) {
if (StringUtils.isNotEmpty(sysUser.getSaltKey())) {
oldPwd += sysUser.getSaltKey();
}
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(oldPwd))) {
throw new AppException("原始密码错误!");
}
if(!Solution.strongPasswordCheckerII(newPwd)){
if (!Solution.strongPasswordCheckerII(newPwd)) {
throw new AppException("新密码至少八位以上,包含大小写加特殊字符加数字");
}
} catch (Exception e) {
......@@ -275,8 +285,8 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
}
try {
if(StringUtils.isEmpty(sysUser.getSaltKey())) {
String saltKey = SecurityCode.getSecurityCode(6,SecurityCode.SecurityCodeLevel.Medium,false);
if (StringUtils.isEmpty(sysUser.getSaltKey())) {
String saltKey = SecurityCode.getSecurityCode(6, SecurityCode.SecurityCodeLevel.Medium, false);
sysUser.setSaltKey(saltKey);
}
newPwd += sysUser.getSaltKey();
......@@ -289,10 +299,10 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
add(new OrderCol("a.createTime", "desc"));
}
});
List<UserPwdRecordEntity> recordEntityList = userPwdRecordDao.getList(recordQuery,0,5);
if(CollectionUtils.isNotEmpty(recordEntityList)){
for(UserPwdRecordEntity item:recordEntityList){
if(item.getLoginPwd().equals(sysUser.getLoginPwd())){
List<UserPwdRecordEntity> recordEntityList = userPwdRecordDao.getList(recordQuery, 0, 5);
if (CollectionUtils.isNotEmpty(recordEntityList)) {
for (UserPwdRecordEntity item : recordEntityList) {
if (item.getLoginPwd().equals(sysUser.getLoginPwd())) {
throw new AppException("新密码不能与最近五次密码相同!");
}
}
......@@ -445,8 +455,8 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
throw new AppException("帐号错误!");
}
try {
if(StringUtils.isEmpty(sysUser.getSaltKey())) {
String saltKey = SecurityCode.getSecurityCode(6,SecurityCode.SecurityCodeLevel.Medium,false);
if (StringUtils.isEmpty(sysUser.getSaltKey())) {
String saltKey = SecurityCode.getSecurityCode(6, SecurityCode.SecurityCodeLevel.Medium, false);
sysUser.setSaltKey(saltKey);
}
sysUser.setLoginPwd(SecurityUtil.md5DoubleEncoding(newPwd + sysUser.getSaltKey()));
......
<?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.xhx.base.system.resource.dao.ibatis.ResourceDaoImpl">
<!-- 获取列表 -->
<select id="getListByUserId" parameterType="paramDto" resultMap="ResourceEntity-Map">
select <include refid="_columns"/>
from mortals_xhx_resource as a
where a.authType in(0,1,2) or a.id IN
(select resourceId
from mortals_xhx_role_auth as b
left join mortals_xhx_role_user as c
on b.roleId=c.roleId
where c.userId=#{condition.userId})
</select>
<select id="getAllByUserType" parameterType="java.util.HashMap" resultMap="ResourceEntity-Map">
select <include refid="_columns"/>
from mortals_xhx_resource as a
where a.userType=#{userType}
</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