默认初始化页面权限修改

This commit is contained in:
张松 2025-04-02 16:53:09 +08:00
parent 9453ec0fcd
commit f67a917977
3 changed files with 34 additions and 17 deletions

View File

@ -41,4 +41,6 @@ public class ShopStaffPagePermission implements Serializable {
*/
private Long pagePathId;
private Integer isUse;
}

View File

@ -34,20 +34,21 @@ public class ShopPagePathServiceImpl extends ServiceImpl<ShopPagePathMapper, Sho
@Override
public List<ShopPagePath> detail(Long staffId) {
Set<Long> pageIdList = shopStaffPagePermissionMapper.selectListByQuery(new QueryWrapper().eq(ShopStaffPagePermission::getShopId,
StpKit.USER.getShopId()).eq(ShopStaffPagePermission::getStaffId, staffId)).stream().map(ShopStaffPagePermission::getPagePathId).collect(Collectors.toSet());
if (pageIdList.isEmpty()) {
List<ShopStaffPagePermission> shopStaffPagePermissions = shopStaffPagePermissionMapper.selectListByQuery(new QueryWrapper().eq(ShopStaffPagePermission::getShopId,
StpKit.USER.getShopId()).eq(ShopStaffPagePermission::getStaffId, staffId));
if (shopStaffPagePermissions.isEmpty()) {
list().forEach(item -> {
ShopStaffPagePermission permission = new ShopStaffPagePermission();
permission.setShopId(StpKit.USER.getShopId());
permission.setStaffId(staffId);
permission.setPagePathId(item.getId());
// shopStaffPagePermissionMapper.insert(permission);
// pageIdList.add(permission.getPagePathId());
permission.setIsUse(1);
shopStaffPagePermissionMapper.insert(permission);
});
return new ArrayList<>();
return list();
}
Set<Long> pageIdList = shopStaffPagePermissions.stream().filter(item -> item.getIsUse() == 1).map(ShopStaffPagePermission::getPagePathId).collect(Collectors.toSet());
return list(new QueryWrapper().in(ShopPagePath::getId, pageIdList));
}
}

View File

@ -16,6 +16,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collector;
import java.util.stream.Collectors;
/**
* 服务层实现
@ -43,19 +47,29 @@ public class ShopStaffPagePermissionServiceImpl extends ServiceImpl<ShopStaffPag
throw new ApiNotPrintException("存在错误id");
}
ArrayList<ShopStaffPagePermission> pagePermissions = new ArrayList<>();
remove(new QueryWrapper().eq(ShopStaffPagePermission::getStaffId, pagePathPermissionAddDTO.getStaffId()));
Map<Long, ShopStaffPagePermission> map = list(new QueryWrapper().eq(ShopStaffPagePermission::getStaffId,
pagePathPermissionAddDTO.getStaffId())).stream().collect(Collectors.toMap(ShopStaffPagePermission::getPagePathId, item -> item));
pagePathPermissionAddDTO.getPagePathIdList().forEach(item -> {
long count1 = count(new QueryWrapper().eq(ShopStaffPagePermission::getStaffId, shopStaff).eq(ShopStaffPagePermission::getPagePathId, item));
if (count1 > 0) {
return;
ShopStaffPagePermission permission1 = map.get(item);
if (permission1 == null) {
ShopStaffPagePermission permission = new ShopStaffPagePermission();
permission.setShopId(shopId);
permission.setPagePathId(item);
permission.setStaffId(pagePathPermissionAddDTO.getStaffId());
permission.setIsUse(1);
save(permission);
}else {
permission1.setIsUse(1);
updateById(permission1);
map.remove(item);
}
ShopStaffPagePermission permission = new ShopStaffPagePermission();
permission.setShopId(shopId);
permission.setPagePathId(item);
permission.setStaffId(pagePathPermissionAddDTO.getStaffId());
pagePermissions.add(permission);
});
return saveBatch(pagePermissions);
Set<Long> collect = map.values().stream().map(ShopStaffPagePermission::getId).collect(Collectors.toSet());
if (!collect.isEmpty()) {
updateChain().set(ShopStaffPagePermission::getIsUse, 0).in(ShopStaffPagePermission::getId, collect);
}
return true;
}
}