|
@@ -1,24 +1,31 @@
|
|
|
package com.ym.mec.auth.service.impl;
|
|
|
|
|
|
import com.ym.mec.auth.api.dto.MenuQueryInfo;
|
|
|
-import com.ym.mec.auth.api.enums.YesOrNoEnum;
|
|
|
-import com.ym.mec.common.page.PageInfo;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import com.ym.mec.auth.api.entity.SysMenu;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.ym.mec.auth.api.enums.SysUserType;
|
|
|
import com.ym.mec.auth.dal.dao.SysMenuDao;
|
|
|
+import com.ym.mec.auth.dal.dao.SysUserDao;
|
|
|
import com.ym.mec.auth.service.SysMenuService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
+import com.ym.mec.common.page.PageInfo;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
+import com.ym.mec.util.collection.MapUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class SysMenuServiceImpl extends BaseServiceImpl<Integer, SysMenu> implements SysMenuService {
|
|
|
|
|
|
@Autowired
|
|
|
private SysMenuDao sysMenuDao;
|
|
|
+ @Autowired
|
|
|
+ private SysUserDao sysUserDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, SysMenu> getDAO() {
|
|
@@ -32,17 +39,47 @@ public class SysMenuServiceImpl extends BaseServiceImpl<Integer, SysMenu> imple
|
|
|
|
|
|
@Override
|
|
|
public PageInfo<SysMenu> findByUser(MenuQueryInfo menuQueryInfo) {
|
|
|
- PageInfo<SysMenu> pageInfo = queryPage(menuQueryInfo);
|
|
|
+ SysUser sysUser = sysUserDao.get(menuQueryInfo.getUserId());
|
|
|
+ PageInfo<SysMenu> pageInfo = null;
|
|
|
+ if(sysUser.getUserType() == SysUserType.SYSTEM){
|
|
|
+ pageInfo = findBySys(menuQueryInfo);
|
|
|
+ }else {
|
|
|
+ pageInfo = queryPage(menuQueryInfo);
|
|
|
+ }
|
|
|
for (SysMenu menu:pageInfo.getRows()) {
|
|
|
menu = getTree(menu,menuQueryInfo.getDelFlag(),menuQueryInfo.getUserId());
|
|
|
}
|
|
|
return pageInfo;
|
|
|
}
|
|
|
|
|
|
+ private PageInfo<SysMenu> findBySys(MenuQueryInfo menuQueryInfo){
|
|
|
+ PageInfo<SysMenu> pageInfo = new PageInfo<>(menuQueryInfo.getPage(), menuQueryInfo.getRows());
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ MapUtil.populateMap(params, menuQueryInfo);
|
|
|
+
|
|
|
+ List<SysMenu> dataList = null;
|
|
|
+ int count = sysMenuDao.findCountBySys(params);
|
|
|
+ if (count > 0) {
|
|
|
+ pageInfo.setTotal(count);
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
+ dataList = sysMenuDao.findList(menuQueryInfo.getParentId(),menuQueryInfo.getDelFlag());
|
|
|
+ }
|
|
|
+ if (count == 0) {
|
|
|
+ dataList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
private SysMenu getTree(SysMenu menu, String delFlag,Integer userId){
|
|
|
//得到根节点对象
|
|
|
//获取子节点list
|
|
|
- List<SysMenu> sysMenus = sysMenuDao.findByParentId(menu.getId(),delFlag,userId);
|
|
|
+ List<SysMenu> sysMenus = null;
|
|
|
+ if(userId == null){
|
|
|
+ sysMenus = sysMenuDao.findList(menu.getId(),delFlag);
|
|
|
+ }else {
|
|
|
+ sysMenus = sysMenuDao.findByParentId(menu.getId(),delFlag,userId);
|
|
|
+ }
|
|
|
//如果存在子节点
|
|
|
if(sysMenus != null && sysMenus.size() > 0) {
|
|
|
//将子节点list放入父节点对象
|