Commit 18144407 authored by trumansdo's avatar trumansdo
Browse files

应用codestyle


千万千万要用vscode打开前端项目,或者关闭eslint,移除它
Signed-off-by: default avatartrumansdo <1012243881@qq.com>
parent 9b3d96a6
......@@ -4,11 +4,13 @@ import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 数据权限接口类
* @author Administrator
*
* @author Administrator
*/
public interface DataAccess {
DataAccessResullt getOrg(Long userId,Long orgId );
DataAccessResullt getOrg(Long userId, Long orgId);
String getName();
Integer getType();
}
......@@ -8,18 +8,18 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
public interface DataAccessFactory {
/**
* 得到数去访问权限
*
* @param type
* @return
*/
public DataAccess getDataAccess(Integer type);
/**
* 得到用户能看到得到组织机构树,比如,用户只能看到公司级别的组织机构树。
* DefaultDataAccessFactory 默认实现了能看到所在公司(集团,母公司)的组织机构树
* 得到用户能看到得到组织机构树,比如,用户只能看到公司级别的组织机构树。 DefaultDataAccessFactory 默认实现了能看到所在公司(集团,母公司)的组织机构树
*
* @param OrgItem
* @return
*/
public OrgItem getUserOrgTree(OrgItem item) ;
public OrgItem getUserOrgTree(OrgItem item);
public List<DataAccess> all();
}
......@@ -3,34 +3,36 @@ package com.ibeetl.admin.core.rbac;
import java.util.List;
/**
* 通过DataAccess 得出跟查询相关的用户或者组织机构列表
* @author lijiazhi
*
* @author lijiazhi
*/
public class DataAccessResullt {
private List<Long> userIds;
private List<Long> orgIds;
//1 结果仅仅包含用户, 2 ,结果仅仅包含组织机构 3 结果匹配所有组织结构 4 结果不匹配任何组织机构
private AccessType status ;
// 1 结果仅仅包含用户, 2 ,结果仅仅包含组织机构 3 结果匹配所有组织结构 4 结果不匹配任何组织机构
private AccessType status;
public List<Long> getUserIds() {
return userIds;
}
public void setUserIds(List<Long> userIds) {
this.userIds = userIds;
}
public List<Long> getOrgIds() {
return orgIds;
}
public void setOrgIds(List<Long> orgIds) {
this.orgIds = orgIds;
}
public AccessType getStatus() {
return status;
}
public void setStatus(AccessType status) {
this.status = status;
}
}
......@@ -8,29 +8,34 @@ import com.ibeetl.admin.core.entity.CoreOrg;
import com.ibeetl.admin.core.entity.CoreUser;
public class UserLoginInfo {
//用户所在机构
// 用户所在机构
List<CoreOrg> orgs = new ArrayList<CoreOrg>();
//用户信息
// 用户信息
CoreUser user;
//用户默认登录机构
// 用户默认登录机构
CoreOrg currentOrg = null;
public List<CoreOrg> getOrgs() {
return orgs;
}
public void setOrgs(List<CoreOrg> orgs) {
this.orgs = orgs;
}
public CoreUser getUser() {
return user;
}
public void setUser(CoreUser user) {
this.user = user;
}
public CoreOrg getCurrentOrg() {
return currentOrg;
}
public void setCurrentOrg(CoreOrg currentOrg) {
this.currentOrg = currentOrg;
}
}
......@@ -15,23 +15,20 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 所有机构
* @author lijiazhi
*
* @author lijiazhi
*/
@Component
public class AllGroupAccess implements DataAccess {
@Autowired
CorePlatformService platformService;
@Autowired CorePlatformService platformService;
@Override
public DataAccessResullt getOrg(Long userId, Long orgId) {
DataAccessResullt ret = new DataAccessResullt();
ret.setStatus(AccessType.AllOrg);
return ret;
}
@Override
......@@ -43,5 +40,4 @@ public class AllGroupAccess implements DataAccess {
public Integer getType() {
return 5;
}
}
......@@ -14,20 +14,18 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
* 系统提供的数据访问权限设置,适合大多数情况。如果只是小型公司,只需要配置数据字典组织机构类型和数据访问类型为系统默认的子集即可
*
* @author xiandafu
*
*/
public class DefaultDataAccessFactory implements DataAccessFactory {
public static final String GROUP_TYPE = "ORGT0"; // 集团
public static final String COMPANY_TYPE = "ORGT1"; // 公司
public static final String DEPARTMENT_TYPE = "ORGT2"; // 部门
public static final String TEAM_TYPE = "ORGT3"; //小组
public static final String TEAM_TYPE = "ORGT3"; // 小组
public static final String PARENT_CORP_TYPE = "ORGT99"; // 母公司
protected Map<Integer,DataAccess> map = new HashMap<Integer,DataAccess> ();
protected Map<Integer, DataAccess> map = new HashMap<Integer, DataAccess>();
protected ApplicationContext applicationContext;
public DefaultDataAccessFactory(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
DataAccess da1 = applicationContext.getBean(OwnerDataAccess.class);
......@@ -48,19 +46,18 @@ public class DefaultDataAccessFactory implements DataAccessFactory {
this.addDataAccessType(da6);
this.addDataAccessType(da7);
this.addDataAccessType(da8);
}
public DataAccess getDataAccess(Integer type){
public DataAccess getDataAccess(Integer type) {
return map.get(type);
}
public List<DataAccess> all(){
public List<DataAccess> all() {
return new ArrayList<DataAccess>(map.values());
}
public void addDataAccessType(DataAccess da){
if(da.getType()>255){
public void addDataAccessType(DataAccess da) {
if (da.getType() > 255) {
throw new RuntimeException("数据权限类型支持1-255");
}
map.put(da.getType(), da);
......@@ -68,18 +65,15 @@ public class DefaultDataAccessFactory implements DataAccessFactory {
@Override
public OrgItem getUserOrgTree(OrgItem item) {
while (item != null ) {
while (item != null) {
String orgType = item.getOrg().getType();
if(orgType.equals(COMPANY_TYPE)||orgType.equals(PARENT_CORP_TYPE)||orgType.equals(GROUP_TYPE)) {
if (orgType.equals(COMPANY_TYPE)
|| orgType.equals(PARENT_CORP_TYPE)
|| orgType.equals(GROUP_TYPE)) {
return item;
}
}
return null;
}
}
......@@ -15,14 +15,13 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 集团公司所有
* @author lijiazhi
*
* @author lijiazhi
*/
@Component
public class GroupDataAccess implements DataAccess {
@Autowired
CorePlatformService platformService;
@Autowired CorePlatformService platformService;
@Override
public DataAccessResullt getOrg(Long userId, Long orgId) {
......@@ -31,7 +30,7 @@ public class GroupDataAccess implements DataAccess {
OrgItem group = root.findParentOrgItem(DefaultDataAccessFactory.GROUP_TYPE);
List<OrgItem> all = group.findAllChildOrgItem();
List<Long> list = new ArrayList<Long>(all.size());
for(OrgItem org:all){
for (OrgItem org : all) {
list.add(org.getId());
}
......@@ -39,7 +38,6 @@ public class GroupDataAccess implements DataAccess {
ret.setStatus(AccessType.OnlyOrg);
ret.setOrgIds(list);
return ret;
}
@Override
......@@ -51,5 +49,4 @@ public class GroupDataAccess implements DataAccess {
public Integer getType() {
return 6;
}
}
......@@ -15,24 +15,23 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 集团公司所有,但不包含集团下的公司,仅仅集团职能部门
* @author lijiazhi
*
* @author lijiazhi
*/
@Component
public class GroupOnlyDataAccess implements DataAccess {
@Autowired
CorePlatformService platformService;
@Autowired CorePlatformService platformService;
@Override
public DataAccessResullt getOrg(Long userId, Long orgId) {
OrgItem root = platformService.buildOrg();
OrgItem company = root.findChild(orgId);
OrgItem group = root.findParentOrgItem(DefaultDataAccessFactory.GROUP_TYPE);
//排除集团下的所有公司
List<OrgItem> all = group.findAllChildOrgItem(null,DefaultDataAccessFactory.COMPANY_TYPE);
// 排除集团下的所有公司
List<OrgItem> all = group.findAllChildOrgItem(null, DefaultDataAccessFactory.COMPANY_TYPE);
List<Long> list = new ArrayList<Long>(all.size());
for(OrgItem org:all){
for (OrgItem org : all) {
list.add(org.getId());
}
......@@ -40,7 +39,6 @@ public class GroupOnlyDataAccess implements DataAccess {
ret.setStatus(AccessType.OnlyOrg);
ret.setOrgIds(list);
return ret;
}
@Override
......@@ -52,5 +50,4 @@ public class GroupOnlyDataAccess implements DataAccess {
public Integer getType() {
return 8;
}
}
......@@ -11,14 +11,13 @@ import com.ibeetl.admin.core.rbac.DataAccessResullt;
import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 只查看自己
* @author lijiazhi
*
* @author lijiazhi
*/
@Component
public class OwnerDataAccess implements DataAccess {
@Autowired
CorePlatformService platformService;
@Autowired CorePlatformService platformService;
@Override
public DataAccessResullt getOrg(Long userId, Long orgId) {
......@@ -26,7 +25,6 @@ public class OwnerDataAccess implements DataAccess {
ret.setStatus(AccessType.OnlyUser);
ret.setUserIds(Arrays.asList(userId));
return ret;
}
@Override
......@@ -38,5 +36,4 @@ public class OwnerDataAccess implements DataAccess {
public Integer getType() {
return 1;
}
}
......@@ -15,14 +15,13 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 母公司所有
* @author lijiazhi
*
* @author lijiazhi
*/
@Component
public class ParentCorpDataAccess implements DataAccess {
@Autowired
CorePlatformService platformService;
@Autowired CorePlatformService platformService;
@Override
public DataAccessResullt getOrg(Long userId, Long orgId) {
......@@ -30,7 +29,7 @@ public class ParentCorpDataAccess implements DataAccess {
OrgItem company = root.findAllChildOrgItem(DefaultDataAccessFactory.PARENT_CORP_TYPE).get(0);
List<OrgItem> all = company.findAllChildOrgItem();
List<Long> list = new ArrayList<Long>(all.size());
for(OrgItem org:all){
for (OrgItem org : all) {
list.add(org.getId());
}
......@@ -38,7 +37,6 @@ public class ParentCorpDataAccess implements DataAccess {
ret.setStatus(AccessType.OnlyOrg);
ret.setOrgIds(list);
return ret;
}
@Override
......@@ -50,5 +48,4 @@ public class ParentCorpDataAccess implements DataAccess {
public Integer getType() {
return 7;
}
}
......@@ -16,14 +16,13 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 同公司下所有
* @author lijiazhi
*
* @author lijiazhi
*/
@Component
public class SameCompanyAllDataAccess implements DataAccess {
@Autowired
CorePlatformService platformService;
@Autowired CorePlatformService platformService;
@Override
public DataAccessResullt getOrg(Long userId, Long orgId) {
......@@ -32,19 +31,18 @@ public class SameCompanyAllDataAccess implements DataAccess {
OrgItem item = platformService.getCurrentOrgItem();
OrgItem company = item.findParentOrgItem(DefaultDataAccessFactory.COMPANY_TYPE);
if(company==null){
if (company == null) {
ret.setOrgIds(Collections.EMPTY_LIST);
return ret;
}
List<OrgItem> all = company.findAllChildOrgItem(null,DefaultDataAccessFactory.COMPANY_TYPE);
List<OrgItem> all = company.findAllChildOrgItem(null, DefaultDataAccessFactory.COMPANY_TYPE);
all.add(company);
List<Long> list = new ArrayList<Long>(all.size());
for(OrgItem org:all){
for (OrgItem org : all) {
list.add(org.getId());
}
ret.setOrgIds(list);
return ret;
}
@Override
......@@ -56,5 +54,4 @@ public class SameCompanyAllDataAccess implements DataAccess {
public Integer getType() {
return 2;
}
}
......@@ -16,14 +16,13 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 同部门下所有
* @author lijiazhi
*
* @author lijiazhi
*/
@Component
public class SameDeparmentAllDataAccess implements DataAccess {
@Autowired
CorePlatformService platformService;
@Autowired CorePlatformService platformService;
@Override
public DataAccessResullt getOrg(Long userId, Long orgId) {
......@@ -31,21 +30,19 @@ public class SameDeparmentAllDataAccess implements DataAccess {
ret.setStatus(AccessType.OnlyOrg);
OrgItem item = platformService.getCurrentOrgItem();
OrgItem dept = item.findParentOrgItem(DefaultDataAccessFactory.DEPARTMENT_TYPE);
if(dept==null){
if (dept == null) {
ret.setOrgIds(Collections.EMPTY_LIST);
return ret;
}
List<OrgItem> all = dept.findAllChildOrgItem(null);
all.add(dept);
List<Long> list = new ArrayList<Long>(all.size());
for(OrgItem org:all){
for (OrgItem org : all) {
list.add(org.getId());
}
ret.setOrgIds(list);
return ret;
}
@Override
......@@ -57,5 +54,4 @@ public class SameDeparmentAllDataAccess implements DataAccess {
public Integer getType() {
return 4;
}
}
......@@ -15,14 +15,13 @@ import com.ibeetl.admin.core.rbac.tree.OrgItem;
import com.ibeetl.admin.core.service.CorePlatformService;
/**
* 同机构
* @author lijiazhi
*
* @author lijiazhi
*/
@Component
public class SameOrgDataAccess implements DataAccess {
@Autowired
CorePlatformService platformService;
@Autowired CorePlatformService platformService;
@Override
public DataAccessResullt getOrg(Long userId, Long orgId) {
......@@ -30,7 +29,6 @@ public class SameOrgDataAccess implements DataAccess {
ret.setStatus(AccessType.OnlyOrg);
ret.setOrgIds(Arrays.asList(orgId));
return ret;
}
@Override
......@@ -42,5 +40,4 @@ public class SameOrgDataAccess implements DataAccess {
public Integer getType() {
return 3;
}
}
......@@ -7,85 +7,80 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ibeetl.admin.core.entity.CoreFunction;
public class FunctionItem implements TreeItem{
public class FunctionItem implements TreeItem {
CoreFunction sysFunction = null;
List<FunctionItem> children = new ArrayList<>();
@JsonIgnore
FunctionItem parent = null;
String name ;
public FunctionItem(CoreFunction sysFunction){
@JsonIgnore FunctionItem parent = null;
String name;
public FunctionItem(CoreFunction sysFunction) {
this.sysFunction = sysFunction;
this.name = sysFunction!=null?sysFunction.getName():null;
this.name = sysFunction != null ? sysFunction.getName() : null;
}
public void setParent(FunctionItem parent){
public void setParent(FunctionItem parent) {
this.parent = parent;
parent.children.add(this);
}
public List<FunctionItem> getChildren(){
public List<FunctionItem> getChildren() {
return this.children;
}
public Long getId(){
public Long getId() {
return sysFunction.getId();
}
public CoreFunction getData(){
public CoreFunction getData() {
return this.sysFunction;
}
/**
* 查找某个指定的子功能
*
* @param functionId
* @return
*/
public FunctionItem findChild(long functionId){
if(sysFunction.getId()==functionId){
public FunctionItem findChild(long functionId) {
if (sysFunction.getId() == functionId) {
return this;
}
for(FunctionItem item:children){
for (FunctionItem item : children) {
FunctionItem find = item.findChild(functionId);
if(find!=null){
if (find != null) {
return find;
}
}
return null;
}
/**
* 查找所有的子功能
*
* @return
*/
public List<FunctionItem> findAllItem(){
public List<FunctionItem> findAllItem() {
List<FunctionItem> all = new LinkedList<>();
findAllChildItem(all,this);
findAllChildItem(all, this);
return all;
}
public List<Long> findAllChildrenId(){
List<FunctionItem> items =findAllItem();
public List<Long> findAllChildrenId() {
List<FunctionItem> items = findAllItem();
List<Long> children = new ArrayList<Long>();
for(FunctionItem item:items){
for (FunctionItem item : items) {
children.add(item.getId());
}
return children;
}
private void findAllChildItem(List<FunctionItem> all,FunctionItem parent){
for(FunctionItem item:parent.children){
private void findAllChildItem(List<FunctionItem> all, FunctionItem parent) {
for (FunctionItem item : parent.children) {
all.add(item);
findAllChildItem(all,item);
findAllChildItem(all, item);
}
}
@Override
public int hashCode() {
final int prime = 31;
......@@ -94,41 +89,25 @@ public class FunctionItem implements TreeItem{
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
FunctionItem other = (FunctionItem) obj;
if (sysFunction == null) {
if (other.sysFunction != null)
return false;
} else if (!sysFunction.equals(other.sysFunction))
return false;
if (other.sysFunction != null) return false;
} else if (!sysFunction.equals(other.sysFunction)) return false;
return true;
}
@Override
public String toString() {
return "MenuItem [sysFunction=" + sysFunction.getName() + ","+this.children.size()+"]";
return "MenuItem [sysFunction=" + sysFunction.getName() + "," + this.children.size() + "]";
}
@Override
public String getName() {
return sysFunction==null?"":sysFunction.getName();
return sysFunction == null ? "" : sysFunction.getName();
}
}
......@@ -9,100 +9,90 @@ import java.util.Set;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ibeetl.admin.core.entity.CoreMenu;
public class MenuItem implements TreeItem{
public class MenuItem implements TreeItem {
CoreMenu sysMenu = null;
List<MenuItem> children = new ArrayList<MenuItem>();
@JsonIgnore
MenuItem parent = null;
@JsonIgnore MenuItem parent = null;
String name;
private Integer seq;
public MenuItem(CoreMenu sysMenu){
public MenuItem(CoreMenu sysMenu) {
this.sysMenu = sysMenu;
this.name = sysMenu!=null?sysMenu.getName():null;
this.name = sysMenu != null ? sysMenu.getName() : null;
this.seq = sysMenu.getSeq();
}
public void setParent(MenuItem parent){
public void setParent(MenuItem parent) {
this.parent = parent;
parent.children.add(this);
}
public List<MenuItem> getChildren(){
public List<MenuItem> getChildren() {
return this.children;
}
public Long getId(){
public Long getId() {
return sysMenu.getId();
}
public CoreMenu getData(){
public CoreMenu getData() {
return this.sysMenu;
}
public void filter(Set<Long> allows){
public void filter(Set<Long> allows) {
Iterator<MenuItem> it = this.children.iterator();
while(it.hasNext()){
while (it.hasNext()) {
MenuItem item = it.next();
if(item.getChildren().size()==0&&!allows.contains(item.getData().getId())){
if (item.getChildren().size() == 0 && !allows.contains(item.getData().getId())) {
it.remove();
}
if(item.getChildren().size()!=0){
if (item.getChildren().size() != 0) {
item.filter(allows);
if(item.getChildren().size()==0){
if (item.getChildren().size() == 0) {
it.remove();
}
}
}
}
/**
* 查找某个指定的子功能
*
* @param functionId
* @return
*/
public MenuItem findChild(Long menuId){
if(sysMenu.getId().equals(menuId)){
public MenuItem findChild(Long menuId) {
if (sysMenu.getId().equals(menuId)) {
return this;
}
for(MenuItem item:children){
for (MenuItem item : children) {
MenuItem find = item.findChild(menuId);
if(find!=null){
if (find != null) {
return find;
}
}
return null;
}
/**
* 查找所有的子菜单
*
* @return
*/
public List<MenuItem> findAllItem(){
public List<MenuItem> findAllItem() {
List<MenuItem> all = new LinkedList<>();
findAllChildItem(all,this);
findAllChildItem(all, this);
return all;
}
private void findAllChildItem(List<MenuItem> all,MenuItem parent){
for(MenuItem item:parent.children){
private void findAllChildItem(List<MenuItem> all, MenuItem parent) {
for (MenuItem item : parent.children) {
all.add(item);
findAllChildItem(all,item);
findAllChildItem(all, item);
}
}
@Override
public int hashCode() {
final int prime = 31;
......@@ -111,56 +101,37 @@ public class MenuItem implements TreeItem{
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
MenuItem other = (MenuItem) obj;
if (sysMenu == null) {
if (other.sysMenu != null)
return false;
} else if (!sysMenu.equals(other.sysMenu))
return false;
if (other.sysMenu != null) return false;
} else if (!sysMenu.equals(other.sysMenu)) return false;
return true;
}
public MenuItem getParent() {
return parent;
}
@Override
public String toString() {
return "MenuItem [sysMenu=" + sysMenu.getName() + ","+this.children.size()+"]";
return "MenuItem [sysMenu=" + sysMenu.getName() + "," + this.children.size() + "]";
}
@Override
public String getName() {
return this.name;
}
public Integer getSeq() {
return seq;
}
public void setSeq(Integer seq) {
this.seq = seq;
}
}
......@@ -10,39 +10,36 @@ import com.ibeetl.admin.core.entity.CoreOrg;
public class OrgItem implements TreeItem {
private Long id;
private CoreOrg org;
@JsonIgnore
private OrgItem parent;
@JsonIgnore private OrgItem parent;
private List<OrgItem> children = new ArrayList<>();
private String name;
public OrgItem(CoreOrg org){
public OrgItem(CoreOrg org) {
this.id = org.getId();
this.org = org;
this.name =org!=null?org.getName():null;
this.name = org != null ? org.getName() : null;
}
public OrgItem findChild(Long orgId){
if(id.equals(orgId)){
public OrgItem findChild(Long orgId) {
if (id.equals(orgId)) {
return this;
}
for(OrgItem item:children){
for (OrgItem item : children) {
OrgItem find = item.findChild(orgId);
if(find!=null){
if (find != null) {
return find;
}
}
return null;
}
public OrgItem findParentOrgItem(String type){
if(this.org.getType().equals(type)){
public OrgItem findParentOrgItem(String type) {
if (this.org.getType().equals(type)) {
return this;
}
OrgItem parent = this;
while((parent=parent.getParent())!=null){
if(parent.getId()!=0&&parent.org.getType().equals(type)){
while ((parent = parent.getParent()) != null) {
if (parent.getId() != 0 && parent.org.getType().equals(type)) {
return parent;
}
}
......@@ -50,65 +47,62 @@ public class OrgItem implements TreeItem {
return null;
}
/** 查询所有符合条件的的组织机构
/**
* 查询所有符合条件的的组织机构
*
* @param type 参考SysOrg,type=0 获取所有子机构
* @return
*/
public List<OrgItem> findAllChildOrgItem(String type){
public List<OrgItem> findAllChildOrgItem(String type) {
return findAllChildOrgItem(type,null);
return findAllChildOrgItem(type, null);
}
/**
* 取得当前机构的所有子机构
*
* @return
*/
public List<Long> findAllChildrenId(){
List<OrgItem> items =findAllChildOrgItem(null);
public List<Long> findAllChildrenId() {
List<OrgItem> items = findAllChildOrgItem(null);
List<Long> children = new ArrayList<Long>();
for(OrgItem item:items){
for (OrgItem item : items) {
children.add(item.getId());
}
return children;
}
/** 查询下级所期望的机构,但不查询breakType 指定的机构
/**
* 查询下级所期望的机构,但不查询breakType 指定的机构
*
* @param type 期望机构,0代表所有 ,1 集团 2 公司 等
* @param breakType 不希望出现的机构
* @return
*/
public List<OrgItem> findAllChildOrgItem(String type ,String breakType){
public List<OrgItem> findAllChildOrgItem(String type, String breakType) {
List<OrgItem> all = new LinkedList<>();
findChildOrgItem(all,this,type,breakType);
findChildOrgItem(all, this, type, breakType);
return all;
}
public List<OrgItem> findAllChildOrgItem(){
public List<OrgItem> findAllChildOrgItem() {
return this.findAllChildOrgItem(null, null);
}
private void findChildOrgItem(List<OrgItem> all,OrgItem parent,String type,String breakType){
for(OrgItem item:parent.children){
if(item.org.getType().equals(breakType)){
continue ;
private void findChildOrgItem(List<OrgItem> all, OrgItem parent, String type, String breakType) {
for (OrgItem item : parent.children) {
if (item.org.getType().equals(breakType)) {
continue;
}
if(type==null||type.equals(item.org.getType())){
if (type == null || type.equals(item.org.getType())) {
all.add(item);
}
findChildOrgItem(all,item,type,breakType);
findChildOrgItem(all, item, type, breakType);
}
}
@Override
public int hashCode() {
final int prime = 31;
......@@ -116,54 +110,54 @@ public class OrgItem implements TreeItem {
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
OrgItem other = (OrgItem) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (other.id != null) return false;
} else if (!id.equals(other.id)) return false;
return true;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public CoreOrg getOrg() {
return org;
}
public void setOrg(CoreOrg org) {
this.org = org;
}
public OrgItem getParent() {
return parent;
}
public void setParent(OrgItem parent) {
this.parent = parent;
this.parent.children.add(this);
}
public List<OrgItem> getChildren() {
return children;
}
public void setChildren(List<OrgItem> children) {
this.children = children;
}
@Override
public String getName() {
return this.name;
}
}
......@@ -3,11 +3,13 @@ package com.ibeetl.admin.core.rbac.tree;
import java.util.List;
/**
* 菜单,功能点,组织机构等跟树有关的结构的接口
* @author lijiazhi
*
* @author lijiazhi
*/
public interface TreeItem extends java.io.Serializable {
public String getName();
public Long getId();
public List getChildren();
}
......@@ -11,8 +11,5 @@ import com.ibeetl.admin.core.entity.CoreAudit;
@Transactional
public class CoreAuditService extends CoreBaseService<CoreAudit> {
@Autowired
private CoreAuditDao sysAuditDao;
@Autowired private CoreAuditDao sysAuditDao;
}
......@@ -18,22 +18,21 @@ import com.ibeetl.admin.core.util.enums.DelFlagEnum;
import org.springframework.beans.factory.annotation.Qualifier;
/**
*
* 描述:
*
* @author : xiandafu
*/
public class CoreBaseService<T> {
@Autowired
protected CoreDictService dictUtil;
@Autowired protected CoreDictService dictUtil;
@Autowired
@Qualifier("baseDataSourceSqlManagerFactoryBean")
protected SQLManager sqlManager;
/**
* 根据id查询对象,如果主键ID不存在
*
* @param id
* @return
*/
......@@ -45,6 +44,7 @@ public class CoreBaseService<T> {
/**
* 根据id查询
*
* @param classz 返回的对象类型
* @param id 主键id
* @return
......@@ -57,17 +57,17 @@ public class CoreBaseService<T> {
/**
* 新增一条数据
*
* @param model 实体类
* @return
*/
public boolean save(T model) {
return sqlManager.insert(model,true) > 0;
return sqlManager.insert(model, true) > 0;
}
/**
* 删除数据(一般为逻辑删除,更新del_flag字段为1)
*
* @param ids
* @return
*/
......@@ -76,9 +76,7 @@ public class CoreBaseService<T> {
throw new PlatformException("删除数据ID不能为空");
}
for (Long id : ids) {
}
for (Long id : ids) {}
List<Object> list = new ArrayList<>();
for (Long id : ids) {
......@@ -104,10 +102,11 @@ public class CoreBaseService<T> {
map.put("id", id);
map.put("delFlag", DelFlagEnum.DELETED.getValue());
int ret = sqlManager.updateTemplateById(getCurrentEntityClassz(), map);
return ret==1;
return ret == 1;
}
/**
* 根据id删除数据
*
* @param id 主键值
* @return
*/
......@@ -117,6 +116,7 @@ public class CoreBaseService<T> {
/**
* 根据id删除数据
*
* @param id 主键值
* @return
*/
......@@ -126,15 +126,17 @@ public class CoreBaseService<T> {
/**
* 更新,只更新不为空的字段
*
* @param model
* @return
*/
public boolean updateTemplate(T model) {
return sqlManager.updateTemplateById(model)>0;
return sqlManager.updateTemplateById(model) > 0;
}
/**
* 更新所有字段
*
* @param model
* @return
*/
......@@ -142,18 +144,17 @@ public class CoreBaseService<T> {
return sqlManager.updateById(model) > 0;
}
/**
* 获取当前注入泛型T的类型
*
* @return 具体类型
*/
@SuppressWarnings("unchecked")
private Class<T> getCurrentEntityClassz() {
return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
return (Class<T>)
((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
public void queryListAfter(List list) {
for (Object bean : list) {
queryEntityAfter(bean);
......@@ -165,11 +166,11 @@ public class CoreBaseService<T> {
return;
}
if(!(bean instanceof TailBean)){
throw new PlatformException("指定的pojo"+bean.getClass()+" 不能获取数据字典,需要继承TailBean");
if (!(bean instanceof TailBean)) {
throw new PlatformException("指定的pojo" + bean.getClass() + " 不能获取数据字典,需要继承TailBean");
}
TailBean ext = (TailBean)bean;
TailBean ext = (TailBean) bean;
Class c = ext.getClass();
do {
Field[] fields = c.getDeclaredFields();
......@@ -182,21 +183,16 @@ public class CoreBaseService<T> {
String display = "";
Object fieldValue = field.get(ext);
if (fieldValue != null) {
CoreDict dbDict = dictUtil.findCoreDict(dict.type(),fieldValue.toString());
display = dbDict!=null?dbDict.getName():null;
CoreDict dbDict = dictUtil.findCoreDict(dict.type(), fieldValue.toString());
display = dbDict != null ? dbDict.getName() : null;
}
ext.set(field.getName() + dict.suffix(), display);
} catch (Exception e) {
e.printStackTrace();
}
}
}
c = c.getSuperclass();
}while(c!=TailBean.class);
} while (c != TailBean.class);
}
}
......@@ -24,16 +24,14 @@ import com.ibeetl.admin.core.gen.model.Attribute;
import com.ibeetl.admin.core.gen.model.Entity;
/**
* 代码生成,用于根据表或者视图生成entity,mapper,service,conroller
* 未来可以生成swagger api,界面
* 代码生成,用于根据表或者视图生成entity,mapper,service,conroller 未来可以生成swagger api,界面
*
* @author xiandafu
*/
@Service
public class CoreCodeGenService {
@Autowired
SQLManager sqlManager;
@Autowired
CorePlatformService platformService;
@Autowired SQLManager sqlManager;
@Autowired CorePlatformService platformService;
Log log = LogFactory.getLog(CoreCodeGenService.class);
......@@ -41,11 +39,11 @@ public class CoreCodeGenService {
sqlManager.refresh();
}
public List<Entity> getAllEntityInfo(){
public List<Entity> getAllEntityInfo() {
MetadataManager meta = sqlManager.getMetaDataManager();
Set<String> set = meta.allTable();
List<Entity> list = new ArrayList<Entity>();
for(String table:set) {
for (String table : set) {
list.add(getEntitySimpleInfo(table));
}
return list;
......@@ -55,10 +53,10 @@ public class CoreCodeGenService {
MetadataManager meta = sqlManager.getMetaDataManager();
NameConversion nc = sqlManager.getNc();
TableDesc tableDesc = meta.getTable(table);
if(tableDesc==null) {
if (tableDesc == null) {
return null;
}
ClassDesc classDesc = tableDesc .getClassDesc(nc);
ClassDesc classDesc = tableDesc.getClassDesc(nc);
Entity e = new Entity();
e.setName(nc.getClassName(table));
e.setComment(tableDesc.getRemark());
......@@ -70,10 +68,10 @@ public class CoreCodeGenService {
MetadataManager meta = sqlManager.getMetaDataManager();
NameConversion nc = sqlManager.getNc();
TableDesc tableDesc = meta.getTable(table);
if(tableDesc==null) {
if (tableDesc == null) {
return null;
}
ClassDesc classDesc = tableDesc .getClassDesc(nc);
ClassDesc classDesc = tableDesc.getClassDesc(nc);
Entity e = new Entity();
e.setName(nc.getClassName(table));
e.setComment(tableDesc.getRemark());
......@@ -82,159 +80,150 @@ public class CoreCodeGenService {
Set<String> cols = tableDesc.getCols();
ArrayList<Attribute> attrs = new ArrayList<Attribute>();
int i=1;
for(String col:cols) {
int i = 1;
for (String col : cols) {
ColDesc desc = tableDesc.getColDesc(col);
Attribute attr = new Attribute();
attr.setColName(col);
attr.setName(nc.getPropertyName(col));
if(tableDesc.getIdNames().contains(col)) {
//TODO,代码生成实际上用了一个Id,因此具备联合主键的,不应该生成代码
if (tableDesc.getIdNames().contains(col)) {
// TODO,代码生成实际上用了一个Id,因此具备联合主键的,不应该生成代码
attr.setId(true);
e.setIdAttribute(attr);
}
attr.setComment(desc.remark);
String type = JavaType.getType(desc.sqlType, desc.size, desc.digit);
if(type.equals("Double")){
if (type.equals("Double")) {
type = "BigDecimal";
}
if(type.equals("Timestamp")){
type ="Date";
if (type.equals("Timestamp")) {
type = "Date";
}
attr.setJavaType(type);
setGetDisplayName(attr);
attrs.add(attr);
}
e.setList(attrs);
return e;
}
/**
*
* @param data
* @param urlBase
* @return 增删改查中的查
*/
public Long insertFunction(Entity data,String urlBase){
public Long insertFunction(Entity data, String urlBase) {
String preffix = urlBase.replace('/', '.');
String functionCode = preffix+"."+data.getCode();
String indexFunctonCode = functionCode+".query";
String functionCode = preffix + "." + data.getCode();
String indexFunctonCode = functionCode + ".query";
CoreFunction query = new CoreFunction();
query.setCode(indexFunctonCode);
Object o = sqlManager.templateOne(query);
if(o != null){
if (o != null) {
return -1l;
}
//设置父功能点
// 设置父功能点
CoreFunction rootFunction = new CoreFunction();
rootFunction.setName(data.getDisplayName());
rootFunction.setCode(functionCode);
rootFunction.setCreateTime(new Date());
rootFunction.setParentId(0L);
rootFunction.setType("FN0");
sqlManager.insert(rootFunction,true);
Long parentId =rootFunction.getId();
sqlManager.insert(rootFunction, true);
Long parentId = rootFunction.getId();
//设置曾删改查功能点
// 设置曾删改查功能点
CoreFunction indexFunction = new CoreFunction();
indexFunction.setName("查询"+data.getDisplayName());
indexFunction.setName("查询" + data.getDisplayName());
indexFunction.setCode(indexFunctonCode);
indexFunction.setCreateTime(new Date());
indexFunction.setParentId(parentId);
indexFunction.setAccessUrl("/"+urlBase+"/"+data.getCode()+"/index.do");
//设置为查询功能
indexFunction.setAccessUrl("/" + urlBase + "/" + data.getCode() + "/index.do");
// 设置为查询功能
indexFunction.setType("FN1");
sqlManager.insert(indexFunction,true);
sqlManager.insert(indexFunction, true);
CoreFunction upateFunction = new CoreFunction();
String updateFunctonCode = functionCode+".edit";
upateFunction.setName("修改"+data.getDisplayName());
String updateFunctonCode = functionCode + ".edit";
upateFunction.setName("修改" + data.getDisplayName());
upateFunction.setCode(updateFunctonCode);
upateFunction.setCreateTime(new Date());
upateFunction.setParentId(parentId);
upateFunction.setType("FN0");
sqlManager.insert(upateFunction,true);
sqlManager.insert(upateFunction, true);
CoreFunction addFunction = new CoreFunction();
String addFunctionCode = functionCode+".add";
addFunction.setName("添加"+data.getDisplayName());
String addFunctionCode = functionCode + ".add";
addFunction.setName("添加" + data.getDisplayName());
addFunction.setCode(addFunctionCode);
addFunction.setCreateTime(new Date());
addFunction.setParentId(parentId);
addFunction.setType("FN0");
sqlManager.insert(addFunction,true);
sqlManager.insert(addFunction, true);
CoreFunction delFunction = new CoreFunction();
String delFunctionCode = functionCode+".delete";
delFunction.setName("删除"+data.getDisplayName());
String delFunctionCode = functionCode + ".delete";
delFunction.setName("删除" + data.getDisplayName());
delFunction.setCode(delFunctionCode);
delFunction.setCreateTime(new Date());
delFunction.setParentId(parentId);
delFunction.setType("FN0");
sqlManager.insert(delFunction,true);
sqlManager.insert(delFunction, true);
//刷新缓存
// 刷新缓存
platformService.clearFunctionCache();
return indexFunction.getId();
}
public boolean insertMenu(Long functionId,Entity data,String urlBase){
public boolean insertMenu(Long functionId, Entity data, String urlBase) {
CoreMenu query = new CoreMenu();
query.setCode("代码生成导航");
query.setType("MENU_N");
CoreMenu menu = this.sqlManager.templateOne(query);
if(menu==null) {
log.warn("未找到对应的父菜单:"+query.getCode());
return false ;
if (menu == null) {
log.warn("未找到对应的父菜单:" + query.getCode());
return false;
}
Long parentId = menu.getId();
CoreMenu newMenu = new CoreMenu();
newMenu.setCode(data.getName()+".Manager");
newMenu.setName(data.getDisplayName()+"管理");
newMenu.setCode(data.getName() + ".Manager");
newMenu.setName(data.getDisplayName() + "管理");
newMenu.setParentMenuId(parentId);
newMenu.setFunctionId(functionId);
newMenu.setType("MENU_M");
//任意设置一个顺序
// 任意设置一个顺序
newMenu.setSeq(3);
this.sqlManager.insert(newMenu);
this.platformService.clearMenuCache();
return true;
}
//根据类名提供一个变量名
// 根据类名提供一个变量名
private String getEntityCode(String s) {
//找到最后一个大写字母,以此为变量名
if (Character.isLowerCase(s.charAt(0)))
return s;
// 找到最后一个大写字母,以此为变量名
if (Character.isLowerCase(s.charAt(0))) return s;
else
return (new StringBuilder())
.append(Character.toLowerCase(s.charAt(0)))
.append(s.substring(1)).toString();
.append(s.substring(1))
.toString();
}
/*根据数据库注释来判断显示名称*/
private void setGetDisplayName(Attribute attr) {
String comment = attr.getComment();
if(StringUtils.isEmpty(comment)) {
if (StringUtils.isEmpty(comment)) {
attr.setDisplayName(attr.getName());
return ;
return;
}
String displayName = null;
int index = comment.indexOf(",");
if(index!=-1) {
displayName = comment.substring(0,index);
if (index != -1) {
displayName = comment.substring(0, index);
attr.setDisplayName(displayName);
}else {
} else {
attr.setDisplayName(comment);
}
}
}
Supports Markdown
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