Skip to content

Commit

Permalink
v1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Mar 19, 2020
1 parent ead6f81 commit b9e0e5c
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ private void codeGenerator(VelocityContext context, Map<String, String> codeTemp
int targetIndex = StringUtils.indexOf(projectPath, targetDir);
projectPath = projectPath.substring(0, targetIndex + targetDir.length() + 1);
projectPath = projectPath.replace("target/", "").replaceFirst("/", "");

Velocity.setProperty("input.encoding", "UTF-8");
Velocity.setProperty("output.encoding", "UTF-8");

for (Entry<String, String> entry : codeTemplates.entrySet()) {
String template = entry.getKey();
String filePath = projectPath + entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum IdGeneratorEnum {

ORDER(1, "order");

private int id;
private long id;
private String keyName;

IdGeneratorEnum(int id, String keyName) {
Expand All @@ -34,7 +34,7 @@ public String toString() {
return "IdGeneratorEnum{" + "id=" + id + ", keyName='" + keyName + '\'' + '}';
}

public int getId() {
public long getId() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,19 @@ public Boolean isSuperman(Long employeeId) {
* @return
*/
public List<PrivilegeEntity> getPrivilegesByEmployeeId(Long employeeId) {
List<PrivilegeEntity> privilegeEntities = null;
// 如果是超管的话
Boolean isSuperman = this.isSuperman(employeeId);
if (isSuperman) {
List<PrivilegeEntity> privilegeEntities = privilegeDao.selectAll();
if (privilegeEntities == null) {
return Lists.newArrayList();
}
return privilegeEntities;
privilegeEntities = privilegeDao.selectAll();
} else {
privilegeEntities = loadPrivilegeFromDb(employeeId);
}
List<PrivilegeEntity> privilegeEntities = loadPrivilegeFromDb(employeeId);

if (privilegeEntities == null) {
privilegeEntities = Lists.newArrayList();
}

this.updateCachePrivilege(employeeId, privilegeEntities);
return privilegeEntities;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.gangquan360.smartadmin.third.SmartApplicationContext;
import com.gangquan360.smartadmin.util.SmartIPUtil;
import com.gangquan360.smartadmin.util.SmartQuartzUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
Expand All @@ -28,6 +29,7 @@
* @date
* @since JDK1.8
*/
@Slf4j
public class QuartzTask extends QuartzJobBean {

@Override
Expand Down Expand Up @@ -59,14 +61,15 @@ protected void executeInternal(JobExecutionContext context) throws JobExecutionE
ITask taskClass = (ITask) SmartApplicationContext.getBean(quartzTaskEntity.getTaskBean());
taskClass.execute(paramsStr);
taskLogEntity.setProcessStatus(TaskResultEnum.SUCCESS.getStatus());
} catch (Exception e) {
} catch (Throwable e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
e.printStackTrace(pw);
pw.flush();
sw.flush();
taskLogEntity.setProcessStatus(TaskResultEnum.FAIL.getStatus());
taskLogEntity.setProcessLog(sw.toString());
log.error("",e);
} finally {
long times = System.currentTimeMillis() - startTime;
taskLogEntity.setProcessDuration(times);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public boolean reload(String args) {
* @return
*/
public ResponseDTO<PageResultDTO<SystemConfigVO>> getSystemConfigPage(SystemConfigQueryDTO queryDTO) {
if(queryDTO.getKey() != null){
queryDTO.setKey(queryDTO.getKey().toLowerCase());
}
Page page = SmartPaginationUtil.convert2PageQueryInfo(queryDTO);
List<SystemConfigEntity> entityList = systemConfigDao.selectSystemSettingList(page, queryDTO);
PageResultDTO<SystemConfigVO> pageResultDTO = SmartPaginationUtil.convert2PageResultDTO(page, entityList, SystemConfigVO.class);
Expand All @@ -95,6 +98,9 @@ public ResponseDTO<PageResultDTO<SystemConfigVO>> getSystemConfigPage(SystemConf
* @return
*/
public ResponseDTO<SystemConfigVO> selectByKey(String configKey) {
if(configKey != null){
configKey = configKey.toLowerCase();
}
SystemConfigEntity entity = systemConfigDao.getByKey(configKey);
if (entity == null) {
return ResponseDTO.wrap(SystemConfigResponseCodeConst.NOT_EXIST);
Expand All @@ -112,6 +118,9 @@ public ResponseDTO<SystemConfigVO> selectByKey(String configKey) {
* @return
*/
public <T> T selectByKey2Obj(String configKey, Class<T> clazz) {
if(configKey != null){
configKey = configKey.toLowerCase();
}
SystemConfigEntity entity = systemConfigDao.getByKey(configKey);
if (entity == null) {
return null;
Expand Down Expand Up @@ -140,14 +149,15 @@ public SystemConfigDTO getCacheByKey(SystemConfigEnum.Key key) {
* @return
*/
public ResponseDTO<String> addSystemConfig(SystemConfigAddDTO configAddDTO) {
SystemConfigEntity entity = systemConfigDao.getByKey(configAddDTO.getConfigKey());
SystemConfigEntity entity = systemConfigDao.getByKey(configAddDTO.getConfigKey().toLowerCase());
if (entity != null) {
return ResponseDTO.wrap(SystemConfigResponseCodeConst.ALREADY_EXIST);
}
ResponseDTO valueValid = this.configValueValid(configAddDTO.getConfigKey(),configAddDTO.getConfigValue());
if(!valueValid.isSuccess()){
return valueValid;
}
configAddDTO.setConfigKey(configAddDTO.getConfigKey().toLowerCase());
SystemConfigEntity addEntity = SmartBeanUtil.copy(configAddDTO, SystemConfigEntity.class);
addEntity.setIsUsing(JudgeEnum.YES.getValue());
systemConfigDao.insert(addEntity);
Expand All @@ -168,7 +178,7 @@ public ResponseDTO<String> updateSystemConfig(SystemConfigUpdateDTO updateDTO) {
if (entity == null) {
return ResponseDTO.wrap(SystemConfigResponseCodeConst.NOT_EXIST);
}
SystemConfigEntity alreadyEntity = systemConfigDao.getByKeyExcludeId(updateDTO.getConfigKey(), updateDTO.getId());
SystemConfigEntity alreadyEntity = systemConfigDao.getByKeyExcludeId(updateDTO.getConfigKey().toLowerCase(), updateDTO.getId());
if (alreadyEntity != null) {
return ResponseDTO.wrap(SystemConfigResponseCodeConst.ALREADY_EXIST);
}
Expand All @@ -177,6 +187,7 @@ public ResponseDTO<String> updateSystemConfig(SystemConfigUpdateDTO updateDTO) {
return valueValid;
}
entity = SmartBeanUtil.copy(updateDTO, SystemConfigEntity.class);
updateDTO.setConfigKey(updateDTO.getConfigKey().toLowerCase());
systemConfigDao.updateById(entity);

//刷新缓存
Expand Down
2 changes: 1 addition & 1 deletion smart-admin-web/src/api/task-manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const taskApi = {
return getAxios(`/quartz/task/resume/${taskId}`);
},
// 删除任务
deleteTasks: (taskId) => {
deleteTask: (taskId) => {
return getAxios(`/quartz/task/delete/${taskId}`);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
return showTitle(item, this);
},
showChildren (item) {
return item.children && (item.children.length > 1 || (item.meta && item.meta.showAlways));
return item.children && (item.children.length > 0 || (item.meta && item.meta.showAlways));
},
getNameOrHref (item, children0) {
return item.href ? `isTurnByHref_${item.href}` : (children0 ? item.children[0].name : item.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
v-show="!collapsed"
width="auto"
>
<template v-for="item in menuList">
<template v-for="item in menuList">
<template v-if="item.children && item.children.length === 1">
<side-menu-item :key="`menu-${item.name}`" :parent-item="item" v-if="showChildren(item)"></side-menu-item>
<side-menu-item :key="`menu-${item.name}`" :parent-item="item.children[0]" v-if="item.children[0].children && item.children[0].children.length > 0 "></side-menu-item>
<menu-item
:key="`menu-${item.children[0].name}`"
:name="getNameOrHref(item, true)"
Expand All @@ -24,7 +24,7 @@
</menu-item>
</template>
<template v-else>
<side-menu-item :key="`menu-${item.name}`" :parent-item="item" v-if="showChildren(item)"></side-menu-item>
<side-menu-item :key="`menu-${item.name}`" :parent-item="item" v-if="item.children && item.children.length > 0"></side-menu-item>
<menu-item :key="`menu-${item.name}`" :name="getNameOrHref(item)" v-else>
<common-icon :type="item.icon || ''" />
<span>{{ showTitle(item) }}</span>
Expand Down Expand Up @@ -81,6 +81,13 @@ export default {
CollapsedMenu
},
props: {
// 菜单path数组
menuNameMatchedMap:{
type: Map,
default() {
return new Map();
}
},
// 菜单集合
menuList: {
type: Array,
Expand Down Expand Up @@ -161,6 +168,7 @@ export default {
},
methods: {
updateActiveName(name){
this.updateOpenName(name);
this.$nextTick(() => {
this.$refs.menu.updateOpened();
this.$refs.menu.updateActiveName(name);
Expand All @@ -171,13 +179,15 @@ export default {
},
// 从激活菜单的名称中获取打开的菜单
getOpenedNamesByActiveName(name) {
return this.$route.matched
.map(item => item.name)
.filter(item => item !== name);
let array = this.menuNameMatchedMap.get(name);
if(array){
return array;
}else{
return [];
}
},
updateOpenName(name) {
if (name === this.$config.homeName) this.openedNames = [];
else this.openedNames = this.getOpenedNamesByActiveName(name);
this.openedNames = this.menuNameMatchedMap.get(name);
}
}
};
Expand Down
15 changes: 14 additions & 1 deletion smart-admin-web/src/components/main/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
v-model="collapsed"
>
<SideMenu
:menuNameMatchedMap="menuNameMatchedMap"
:active-name="$route.name"
:collapsed="collapsed"
:menu-list="menuList"
Expand Down Expand Up @@ -123,7 +124,8 @@ export default {
searchKeyWord: '',
searchList: [],
searchListResult: [],
menuList: []
menuList: [],
menuNameMatchedMap:new Map()
};
},
computed: {
Expand Down Expand Up @@ -284,6 +286,7 @@ export default {
icon: _.isUndefined(router.meta.icon) ? '' : router.meta.icon,
children: []
};
this.menuNameMatchedMap.set(menu.name,[menu.name]);
privilegeTree.push(menu);
//存在孩子节点,开始递归
if (router.children && router.children.length > 0) {
Expand All @@ -292,11 +295,17 @@ export default {
}
}
}
console.log('privilegeTree',privilegeTree)
this.menuList = privilegeTree;
},
recursion(children, parentMenu) {
for (const router of children) {
//验证权限
if (this.$store.state.user.privilegeMenuKeyList.indexOf(router.name) ===-1) {
continue;
}
//过滤非菜单
if (!router.meta.hideInMenu) {
let menu = {
Expand All @@ -309,6 +318,10 @@ export default {
name: router.name,
title: router.meta.title
});
let menuNameArray = this.menuNameMatchedMap.get(parentMenu.name);
this.menuNameMatchedMap.set(menu.name,[...menuNameArray,menu.name]);
parentMenu.children.push(menu);
//存在孩子节点,开始递归
if (router.children && router.children.length > 0) {
Expand Down
71 changes: 66 additions & 5 deletions smart-admin-web/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import config from '@/config';

const { homeName } = config;

Vue.use(Router);
Vue.use(Router);
const router = new Router({
routes: routers
// routes: routers,
routes: buildRouters(routers)
// mode: 'history'
});
const LOGIN_PAGE_NAME = 'login';
Expand Down Expand Up @@ -107,6 +108,63 @@ let tempCheckObj = {
checkRouterPathMap: new Map()
};

function buildRouters (routerArray) {
let lineRouters = [];
for (let routerItem of routerArray) {
//如果是顶层菜单
if (routerItem.meta.topMenu) {
// for (let children of routerItem.children) {
let lineRouterArray = convertRouterTree2Line(routerItem.children);
lineRouters.push(...lineRouterArray);
// }
} else {
let lineRouterArray = convertRouterTree2Line([routerItem]);
lineRouters.push(...lineRouterArray);
}
}
return lineRouters;
}

function convertRouterTree2Line (routerArray) {
//一级,比如 人员管理
let topArray = [];
for (let router1Item of routerArray) {
let level2Array = [];
//二级,比如员工管理
if (router1Item.children) {
for (let level2Item of router1Item.children) {

let level2ItemCopy = {};
for (let property in level2Item) {
if ('children' !== property) {
level2ItemCopy[property] = level2Item[property];
}
}

//三级,
if (level2Item.children) {
level2Array.push(...level2Item.children)
}

level2ItemCopy.children = [];
level2Array.push(level2Item);
}
}

let newTopRouterItem = {};
for (let property in router1Item) {
if ('children' !== property) {
newTopRouterItem[property] = router1Item[property];
}
}

newTopRouterItem.children = level2Array;
topArray.push(newTopRouterItem);
}

return topArray;
}

function recursionRouter (routerArray) {
for (let routerItem of routerArray) {
if (!routerItem.name) {
Expand Down Expand Up @@ -146,9 +204,12 @@ function recursionRouter (routerArray) {
}
}

recursionRouter(routers);

delete tempCheckObj.checkRouterNameMap;
delete tempCheckObj.checkRouterPathMap;
//如果是开发环境,需要检测router的规范性
if (process.env.NODE_ENV === 'development') {
recursionRouter(routers);
delete tempCheckObj.checkRouterNameMap;
delete tempCheckObj.checkRouterPathMap;
}

export default router;
Loading

0 comments on commit b9e0e5c

Please sign in to comment.