修改用户档案目录权限

master
hansha 2 years ago
parent 30076b98d2
commit 266b8d5166

@ -1,25 +1,21 @@
package com.da.dangan.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.da.common.annotation.Log;
import com.da.common.core.controller.BaseController;
import com.da.common.core.domain.AjaxResult;
import com.da.common.core.page.TableDataInfo;
import com.da.common.enums.BusinessType;
import com.da.common.utils.StringUtils;
import com.da.common.utils.poi.ExcelUtil;
import com.da.dangan.domain.DaUserCatalog;
import com.da.dangan.service.IDaUserCatalogService;
import com.da.common.utils.poi.ExcelUtil;
import com.da.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* Controller
@ -91,6 +87,35 @@ public class DaUserCatalogController extends BaseController
return toAjax(daUserCatalogService.updateDaUserCatalog(daUserCatalog));
}
/**
*
*/
@Log(title = "用户目录关联", businessType = BusinessType.UPDATE)
@PutMapping("/modify")
@Transactional
public AjaxResult modifyUserCatalog(@RequestBody DaUserCatalog daUserCatalog)
{
Long[] muIds = daUserCatalog.getMuIds();
// 更新用户权限
if (StringUtils.isNotNull(muIds))
{
try {
//根据userId删除数据
int result = daUserCatalogService.deleteDaUserCatalogByUserId(daUserCatalog.getUserId());
//根据userId添加数据
for(Long muId: muIds){
daUserCatalog.setMuId(muId);
daUserCatalogService.insertDaUserCatalog(daUserCatalog);
}
} catch (Exception e) {
e.printStackTrace();
return error("操作失败,系统错误");
}
}
return success();
}
/**
*
*/

@ -1,9 +1,8 @@
package com.da.dangan.domain;
import com.da.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.da.common.annotation.Excel;
import com.da.common.core.domain.BaseEntity;
/**
* da_user_catalog
@ -21,6 +20,17 @@ public class DaUserCatalog extends BaseEntity
/** 目录ID */
private Long muId;
public Long[] getMuIds() {
return muIds;
}
public void setMuIds(Long[] muIds) {
this.muIds = muIds;
}
/** 目录IDS */
private Long[] muIds;
public void setUserId(Long userId)
{
this.userId = userId;
@ -45,6 +55,7 @@ public class DaUserCatalog extends BaseEntity
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("userId", getUserId())
.append("muId", getMuId())
.append("muIds", getMuIds())
.toString();
}
}

@ -1,12 +1,21 @@
package com.da.dangan.service.impl;
import java.util.List;
import com.da.common.constant.UserConstants;
import com.da.common.core.domain.TreeSelect;
import com.da.common.core.domain.entity.SysUser;
import com.da.common.exception.ServiceException;
import com.da.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.da.common.utils.StringUtils;
import com.da.common.core.domain.entity.DaCatalog;
import com.da.dangan.mapper.DaCatalogMapper;
import com.da.dangan.domain.DaCatalog;
import com.da.dangan.service.IDaCatalogService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* Service
@ -17,7 +26,7 @@ import com.da.dangan.service.IDaCatalogService;
@Service
public class DaCatalogServiceImpl implements IDaCatalogService
{
@Autowired
@Resource
private DaCatalogMapper daCatalogMapper;
/**
@ -32,6 +41,50 @@ public class DaCatalogServiceImpl implements IDaCatalogService
return daCatalogMapper.selectDaCatalogById(id);
}
@Override
public List<Long> selectCatalogListByUserId(Long userId) {
return daCatalogMapper.selectCatalogListByUserId(userId);
}
@Override
public List<TreeSelect> buildCatalogTreeSelect(List<DaCatalog> catalogs) {
List<DaCatalog> catalogTrees = buildCatalogTree(catalogs);
return catalogTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
/**
*
*
* @param catalogs
* @return
*/
@Override
public List<DaCatalog> buildCatalogTree(List<DaCatalog> catalogs)
{
List<DaCatalog> returnList = new ArrayList<>();
List<Long> tempList = catalogs.stream().map(DaCatalog::getId).collect(Collectors.toList());
for (Iterator<DaCatalog> iterator = catalogs.iterator(); iterator.hasNext();)
{
DaCatalog catalog = iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(catalog.getPid()))
{
recursionFn(catalogs, catalog);
returnList.add(catalog);
}
}
if (returnList.isEmpty())
{
returnList = catalogs;
}
return returnList;
}
@Override
public List<DaCatalog> selectCatalogList(Long userId) {
return selectAllDaCatalogList(new DaCatalog(), userId);
}
/**
*
*
@ -44,6 +97,22 @@ public class DaCatalogServiceImpl implements IDaCatalogService
return daCatalogMapper.selectDaCatalogList(daCatalog);
}
@Override
public List<DaCatalog> selectAllDaCatalogList(DaCatalog daCatalog, Long userId)
{
List<DaCatalog> catalogList = null;
// 管理员显示所有菜单信息
if (SysUser.isAdmin(userId))
{
catalogList = daCatalogMapper.selectDaCatalogList(daCatalog);
}
else
{
daCatalog.getParams().put("userId", userId);
catalogList = daCatalogMapper.selectDaCatalogListByUserId(daCatalog);
}
return catalogList;
}
/**
*
*
@ -54,6 +123,17 @@ public class DaCatalogServiceImpl implements IDaCatalogService
public int insertDaCatalog(DaCatalog daCatalog)
{
daCatalog.setCreateTime(DateUtils.getNowDate());
if(daCatalog.getPid()==0){ //代表添加的是主目录
daCatalog.setAncestors(daCatalog.getPid().toString());
}else{
DaCatalog info = daCatalogMapper.selectDaCatalogById(daCatalog.getPid());
// 如果父节点不为正常状态,则不允许新增子节点
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
{
throw new ServiceException("此目录停用,不允许新增");
}
daCatalog.setAncestors(info.getAncestors() + "," + daCatalog.getPid());
}
return daCatalogMapper.insertDaCatalog(daCatalog);
}
@ -82,6 +162,17 @@ public class DaCatalogServiceImpl implements IDaCatalogService
return daCatalogMapper.deleteDaCatalogByIds(ids);
}
@Override
public boolean checkDaCatalogNameUnique(DaCatalog daCatalog) {
Long daCatalogId = StringUtils.isNull(daCatalog.getId()) ? -1L : daCatalog.getId();
DaCatalog info = daCatalogMapper.checkDaCatalogNameUnique(daCatalog.getMuName(), daCatalog.getPid());
if (StringUtils.isNotNull(info) && info.getId().longValue() != daCatalogId.longValue())
{
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
/**
*
*
@ -93,4 +184,50 @@ public class DaCatalogServiceImpl implements IDaCatalogService
{
return daCatalogMapper.deleteDaCatalogById(id);
}
/**
*
*
* @param list
* @param t
*/
private void recursionFn(List<DaCatalog> list, DaCatalog t)
{
// 得到子节点列表
List<DaCatalog> childList = getChildList(list, t);
t.setChildren(childList);
for (DaCatalog tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
}
}
/**
*
*/
private List<DaCatalog> getChildList(List<DaCatalog> list, DaCatalog t)
{
List<DaCatalog> tlist = new ArrayList<DaCatalog>();
Iterator<DaCatalog> it = list.iterator();
while (it.hasNext())
{
DaCatalog n = (DaCatalog) it.next();
if (n.getPid().longValue() == t.getId().longValue())
{
tlist.add(n);
}
}
return tlist;
}
/**
*
*/
private boolean hasChild(List<DaCatalog> list, DaCatalog t)
{
return getChildList(list, t).size() > 0;
}
}

Loading…
Cancel
Save