merge
This commit is contained in:
@@ -22,4 +22,5 @@ public interface SysAuthorityRepository extends JpaRepository<SysAuthority, Stri
|
||||
|
||||
List<SysAuthority> getByEnableAndIdIn(String enable, List<String> ids);
|
||||
|
||||
List<SysAuthority> getByIdIn(List<String> ids);
|
||||
}
|
||||
|
||||
@@ -16,5 +16,7 @@ public interface SysRoleRepository extends JpaRepository<SysRole, String> {
|
||||
|
||||
SysRole getByCode(String code);
|
||||
|
||||
List<SysRole> getByEnableAndIdIn(String enable,List<String> ids);
|
||||
List<SysRole> getByEnableAndIdIn(String enable, List<String> ids);
|
||||
|
||||
List<SysRole> getByIdIn(List<String> ids);
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.xwbing.service;
|
||||
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 说明:
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/5 16:44
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
public class BaseService<T> {
|
||||
private JpaRepository<T, String> jpaRepository;
|
||||
|
||||
public BaseService(JpaRepository<T, String> jpaRepository) {
|
||||
this.jpaRepository = jpaRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增
|
||||
*
|
||||
* @param t
|
||||
* @return
|
||||
*/
|
||||
public RestMessage saveOrUpdate(T t) {
|
||||
RestMessage result = new RestMessage();
|
||||
t = jpaRepository.save(t);
|
||||
if (Objects.isNull(t)) {
|
||||
result.setMessage("保存数据失败");
|
||||
} else {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("保存数据成功");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public RestMessage removeById(String id) {
|
||||
RestMessage result = new RestMessage();
|
||||
jpaRepository.delete(id);
|
||||
result.setSuccess(true);
|
||||
result.setMessage("删除数据成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个查找
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public T findById(String id) {
|
||||
return jpaRepository.findOne(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表查找
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<T> findList() {
|
||||
return jpaRepository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class SysAuthorityService {
|
||||
*/
|
||||
public RestMessage save(SysAuthority sysAuthority) {
|
||||
RestMessage result = new RestMessage();
|
||||
boolean b = uniqueCode(sysAuthority.getCode(), "");
|
||||
boolean b = uniqueCode(sysAuthority.getCode(), null);
|
||||
if (!b)
|
||||
throw new BusinessException("该编码已存在");
|
||||
String id = PassWordUtil.createId();
|
||||
@@ -123,7 +123,10 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysAuthority> listByEnable(String enable) {
|
||||
return sysAuthorityRepository.getByEnable(enable);
|
||||
if (StringUtils.isNotEmpty(enable))
|
||||
return sysAuthorityRepository.getByEnable(enable);
|
||||
else
|
||||
return sysAuthorityRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +159,10 @@ public class SysAuthorityService {
|
||||
return list;
|
||||
List<String> authorityIds = roleAuthorities.stream().map(SysRoleAuthority::getAuthorityId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(authorityIds))
|
||||
list = sysAuthorityRepository.getByEnableAndIdIn(enable, authorityIds);
|
||||
if (StringUtils.isNotEmpty(enable))
|
||||
list = sysAuthorityRepository.getByEnableAndIdIn(enable, authorityIds);
|
||||
else
|
||||
list = sysAuthorityRepository.getByIdIn(authorityIds);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ import com.xwbing.util.PassWordUtil;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -33,7 +31,6 @@ public class SysRoleService {
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Resource
|
||||
private SysRoleAuthorityService sysRoleAuthorityService;
|
||||
private final Logger logger = LoggerFactory.getLogger(SysRoleService.class);
|
||||
|
||||
/**
|
||||
* 保存角色
|
||||
@@ -43,7 +40,7 @@ public class SysRoleService {
|
||||
*/
|
||||
public RestMessage save(SysRole sysRole) {
|
||||
RestMessage result = new RestMessage();
|
||||
boolean b = uniqueCode(sysRole.getCode(), "");
|
||||
boolean b = uniqueCode(sysRole.getCode(), null);
|
||||
if (!b)
|
||||
throw new BusinessException("该编码已存在");
|
||||
String id = PassWordUtil.createId();
|
||||
@@ -92,9 +89,8 @@ public class SysRoleService {
|
||||
RestMessage result = new RestMessage();
|
||||
String id = sysRole.getId();
|
||||
SysRole old = getById(id);
|
||||
if (old == null) {
|
||||
if (old == null)
|
||||
throw new BusinessException("该角色不存在");
|
||||
}
|
||||
boolean b = uniqueCode(sysRole.getCode(), id);
|
||||
if (!b)
|
||||
throw new BusinessException("该编码已存在");
|
||||
@@ -131,7 +127,10 @@ public class SysRoleService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysRole> listAllByEnable(String enable) {
|
||||
return sysRoleRepository.getByEnable(enable);
|
||||
if (StringUtils.isNotEmpty(enable))
|
||||
return sysRoleRepository.getByEnable(enable);
|
||||
else
|
||||
return sysRoleRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +147,10 @@ public class SysRoleService {
|
||||
return list;
|
||||
List<String> roleIds = sysUserRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(roleIds))
|
||||
list = sysRoleRepository.getByEnableAndIdIn(enable, roleIds);
|
||||
if (StringUtils.isNotEmpty(enable))
|
||||
list = sysRoleRepository.getByEnableAndIdIn(enable, roleIds);
|
||||
else
|
||||
list = sysRoleRepository.getByIdIn(roleIds);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user