Skip to content

Commit

Permalink
升级版本,优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zuihou committed Apr 27, 2020
1 parent 3d0b7e4 commit ac1e432
Show file tree
Hide file tree
Showing 33 changed files with 63 additions and 99 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-admin-boot</artifactId>
<name>${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-authority-biz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-admin-boot</artifactId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.zuihou.authority.service.auth.impl;


import com.github.zuihou.authority.dao.auth.ResourceMapper;
import com.github.zuihou.authority.dto.auth.ResourceQueryDTO;
import com.github.zuihou.authority.entity.auth.Resource;
Expand Down Expand Up @@ -37,7 +36,6 @@
*/
@Slf4j
@Service

public class ResourceServiceImpl extends SuperCacheServiceImpl<ResourceMapper, Resource> implements ResourceService {

@Autowired
Expand Down Expand Up @@ -86,7 +84,7 @@ public List<Resource> findVisibleResource(ResourceQueryDTO resource) {
// 若list里面的值过多,而资源又均没有缓存(或者缓存击穿),则这里的效率并不高

List<Long> list = (List<Long>) cacheObject.getValue();
List<Resource> resourceList = list.stream().map(this::getByIdCache).collect(Collectors.toList());
List<Resource> resourceList = list.stream().map(this::getByIdCache).filter(Objects::nonNull).collect(Collectors.toList());

if (resource.getMenuId() == null) {
return resourceList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.oschina.j2cache.CacheChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -34,7 +35,6 @@
*/
@Slf4j
@Service

public class RoleAuthorityServiceImpl extends SuperServiceImpl<RoleAuthorityMapper, RoleAuthority> implements RoleAuthorityService {

@Autowired
Expand All @@ -45,6 +45,7 @@ public class RoleAuthorityServiceImpl extends SuperServiceImpl<RoleAuthorityMapp
private CacheChannel cache;

@Override
@Transactional(rollbackFor = Exception.class)
public boolean saveUserRole(UserRoleSaveDTO userRole) {
userRoleService.remove(Wraps.<UserRole>lbQ().eq(UserRole::getRoleId, userRole.getRoleId()));
List<UserRole> list = userRole.getUserIdList()
Expand All @@ -66,6 +67,7 @@ public boolean saveUserRole(UserRoleSaveDTO userRole) {
}

@Override
@Transactional(rollbackFor = Exception.class)
public boolean saveRoleAuthority(RoleAuthoritySaveDTO dto) {
//删除角色和资源的关联
super.remove(Wraps.<RoleAuthority>lbQ().eq(RoleAuthority::getRoleId, dto.getRoleId()));
Expand Down Expand Up @@ -119,7 +121,8 @@ public boolean saveRoleAuthority(RoleAuthoritySaveDTO dto) {
}

@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeByAuthorityId(List<Long> ids) {
return remove(Wraps.<RoleAuthority>lbQ().eq(RoleAuthority::getAuthorityId, ids));
return remove(Wraps.<RoleAuthority>lbQ().in(RoleAuthority::getAuthorityId, ids));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import java.util.*;
import java.util.stream.Collectors;

//import com.github.zuihou.authority.dao.defaults.TenantMapper;
//import com.github.zuihou.authority.entity.defaults.Tenant;

/**
* <p>
Expand All @@ -57,7 +55,6 @@
*/
@Slf4j
@Service

public class UserServiceImpl extends SuperCacheServiceImpl<UserMapper, User> implements UserService {

@Autowired
Expand Down Expand Up @@ -118,11 +115,11 @@ public Map<String, Object> getDataScopeById(Long userId) {

List<Role> list = roleService.findRoleByUserId(userId);

// 过滤最小角色
Optional<Role> min = list.stream().min(Comparator.comparingInt((item) -> item.getDsType().getVal()));
// 找到 dsType 最大的角色, dsType越大,角色拥有的权限最大
Optional<Role> max = list.stream().max(Comparator.comparingInt((item) -> item.getDsType().getVal()));

if (min.isPresent()) {
Role role = min.get();
if (max.isPresent()) {
Role role = max.get();
dsType = role.getDsType();
map.put("dsType", dsType.getVal());
if (DataScopeType.CUSTOMIZE.eq(dsType)) {
Expand Down Expand Up @@ -174,15 +171,6 @@ public int resetPassErrorNum(Long id) {
@Override
@Transactional(rollbackFor = Exception.class)
public User saveUser(User user) {
// Tenant tenant = tenantMapper.getByCode(BaseContextHandler.getTenant());
// BizAssert.notNull(tenant, "租户不存在,请联系管理员");
//TODO zuihou
// 永不过期
// if (tenant.getPasswordExpire() == null || tenant.getPasswordExpire() <= 0) {
// user.setPasswordExpireTime(null);
// } else {
// user.setPasswordExpireTime(LocalDateTime.now().plusDays(tenant.getPasswordExpire()));
// }
user.setPassword(SecureUtil.md5(user.getPassword()));
user.setPasswordErrorNum(0);
super.save(user);
Expand All @@ -195,22 +183,12 @@ public boolean reset(List<Long> ids) {
if (ids.isEmpty()) {
return true;
}
//TODO zuihou
// Tenant tenant = tenantMapper.getByCode(BaseContextHandler.getTenant());
// BizAssert.notNull(tenant, "租户不存在,请联系管理员");
//
// LocalDateTime passwordExpireTime = null;
// if (tenant.getPasswordExpire() != null && tenant.getPasswordExpire() > 0) {
// passwordExpireTime = LocalDateTime.now().plusDays(tenant.getPasswordExpire());
// }

String defPassword = BizConstant.DEF_PASSWORD_MD5;
super.update(Wraps.<User>lbU()
.set(User::getPassword, defPassword)
.set(User::getPasswordErrorNum, 0L)
.set(User::getPasswordErrorLastTime, null)
// .set(User::getPasswordExpireTime, passwordExpireTime)
.in(User::getId, ids)
.set(User::getPassword, defPassword)
.set(User::getPasswordErrorNum, 0L)
.set(User::getPasswordErrorLastTime, null)
.in(User::getId, ids)
);
String[] keys = ids.stream().map((id) -> key(id)).toArray(String[]::new);
cacheChannel.evict(getRegion(), keys);
Expand All @@ -221,15 +199,6 @@ public boolean reset(List<Long> ids) {
@Override
@Transactional(rollbackFor = Exception.class)
public User updateUser(User user) {
// Tenant tenant = tenantMapper.getByCode(BaseContextHandler.getTenant());
// BizAssert.notNull(tenant, "租户不存在,请联系管理员");
// // 永不过期
// if (tenant.getPasswordExpire() == null || tenant.getPasswordExpire() <= 0) {
// user.setPasswordExpireTime(null);
// } else {
// user.setPasswordExpireTime(LocalDateTime.now().plusDays(tenant.getPasswordExpire()));
// }

if (StrUtil.isNotEmpty(user.getPassword())) {
user.setPassword(SecureUtil.md5(user.getPassword()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ public interface DictionaryItemService extends SuperCacheService<DictionaryItem>
/**
* 根据类型查询字典
*
* @param codes
* @param types
* @return
*/
Map<String, Map<String, String>> map(String[] codes);
Map<String, Map<String, String>> map(String[] types);

/**
* 根据类型编码查询字典项
*
* @param codes
* @return
*/
Map<Serializable, Object> findDictionaryItem(Set<Serializable> codes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/
@Slf4j
@Service

public class DictionaryItemServiceImpl extends SuperCacheServiceImpl<DictionaryItemMapper, DictionaryItem> implements DictionaryItemService {

@Override
Expand All @@ -39,12 +38,12 @@ protected String getRegion() {
}

@Override
public Map<String, Map<String, String>> map(String[] codes) {
if (ArrayUtil.isEmpty(codes)) {
public Map<String, Map<String, String>> map(String[] types) {
if (ArrayUtil.isEmpty(types)) {
return Collections.emptyMap();
}
LbqWrapper<DictionaryItem> query = Wraps.<DictionaryItem>lbQ()
.in(DictionaryItem::getDictionaryType, codes)
.in(DictionaryItem::getDictionaryType, types)
.eq(DictionaryItem::getStatus, true)
.orderByAsc(DictionaryItem::getSortValue);
List<DictionaryItem> list = super.list(query);
Expand All @@ -67,21 +66,19 @@ public Map<Serializable, Object> findDictionaryItem(Set<Serializable> codes) {
if (codes.isEmpty()) {
return Collections.emptyMap();
}
// 1. 根据 字典编码查询可用的字典列表
LbqWrapper<DictionaryItem> query = Wraps.<DictionaryItem>lbQ()
.in(DictionaryItem::getCode, codes)
.eq(DictionaryItem::getStatus, true)
.orderByAsc(DictionaryItem::getSortValue);
List<DictionaryItem> list = super.list(query);

//key 是类型
// 2. 将 list 转换成 Map,Map的key是字典编码,value是字典名称
ImmutableMap<String, String> typeMap = MapHelper.uniqueIndex(list, DictionaryItem::getCode, DictionaryItem::getName);

//需要返回的map
// 3. 将 Map<String, String> 转换成 Map<Serializable, Object>
Map<Serializable, Object> typeCodeNameMap = new LinkedHashMap<>(typeMap.size());

typeMap.forEach((key, value) -> {
typeCodeNameMap.put(key, value);
});
typeMap.forEach((key, value) -> typeCodeNameMap.put(key, value));
return typeCodeNameMap;
}
}
2 changes: 1 addition & 1 deletion zuihou-authority-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-admin-boot</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-authority-entity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-admin-boot</artifactId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class Role extends Entity<Long> {

/**
* 数据权限类型
* #DataScopeType{ALL:1,全部;THIS_LEVEL:2,本级;THIS_LEVEL_CHILDREN:3,本级以及子级;CUSTOMIZE:4,自定义;SELF:5,个人;}
* #DataScopeType{ALL:5,全部;THIS_LEVEL:4,本级;THIS_LEVEL_CHILDREN:3,本级以及子级;CUSTOMIZE:2,自定义;SELF:1,个人;}
*/
@ApiModelProperty(value = "数据权限类型")
@NotNull(message = "数据权限类型不能为空")
Expand Down
2 changes: 1 addition & 1 deletion zuihou-authority-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-admin-boot</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-admin-boot</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion zuihou-file-biz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-admin-boot</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-file-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-admin-boot</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-file-entity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-admin-boot</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-jobs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-admin-boot</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>zuihou-jobs</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-jobs/zuihou-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-jobs</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-jobs/zuihou-jobs-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-jobs</artifactId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-jobs/zuihou-jobs-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-jobs</artifactId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-jobs/zuihou-jobs-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-jobs</artifactId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion zuihou-msgs-biz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-admin-boot</artifactId>
<groupId>com.github.zuihou</groupId>
<version>b.2.2-SNAPSHOT</version>
<version>b.2.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Loading

0 comments on commit ac1e432

Please sign in to comment.