【7.6.0】【sys】【portal】更新获取用户常用功能的接口

pull/57/head
fengshuonan 2023-06-26 21:42:09 +08:00
parent 486a4b134b
commit 616bf10208
4 changed files with 56 additions and 172 deletions

View File

@ -1,11 +1,11 @@
package cn.stylefeng.roses.kernel.sys.modular.userapp.controller;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo;
import cn.stylefeng.roses.kernel.sys.modular.userapp.entity.PortalUserApp;
import cn.stylefeng.roses.kernel.sys.modular.userapp.pojo.request.PortalUserAppRequest;
import cn.stylefeng.roses.kernel.sys.modular.userapp.service.PortalUserAppService;
@ -30,72 +30,27 @@ public class PortalUserAppController {
private PortalUserAppService portalUserAppService;
/**
*
*
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
@PostResource(name = "添加", path = "/portalUserApp/add")
public ResponseData<PortalUserApp> add(@RequestBody @Validated(PortalUserAppRequest.add.class) PortalUserAppRequest portalUserAppRequest) {
portalUserAppService.add(portalUserAppRequest);
@GetResource(name = "获取用户常用功能", path = "/portalUserApp/getUserAppList")
public ResponseData<List<UserAppMenuInfo>> getUserAppList() {
return new SuccessResponseData<>(portalUserAppService.getUserAppList());
}
/**
*
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
@PostResource(name = "添加", path = "/portalUserApp/updateUserAppList")
public ResponseData<PortalUserApp> updateUserAppList(
@RequestBody @Validated(PortalUserAppRequest.add.class) PortalUserAppRequest portalUserAppRequest) {
portalUserAppService.updateUserAppList(portalUserAppRequest);
return new SuccessResponseData<>();
}
/**
*
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
@PostResource(name = "删除", path = "/portalUserApp/delete")
public ResponseData<?> delete(@RequestBody @Validated(PortalUserAppRequest.delete.class) PortalUserAppRequest portalUserAppRequest) {
portalUserAppService.del(portalUserAppRequest);
return new SuccessResponseData<>();
}
/**
*
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
@PostResource(name = "编辑", path = "/portalUserApp/edit")
public ResponseData<?> edit(@RequestBody @Validated(PortalUserAppRequest.edit.class) PortalUserAppRequest portalUserAppRequest) {
portalUserAppService.edit(portalUserAppRequest);
return new SuccessResponseData<>();
}
/**
*
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
@GetResource(name = "查看详情", path = "/portalUserApp/detail")
public ResponseData<PortalUserApp> detail(@Validated(PortalUserAppRequest.detail.class) PortalUserAppRequest portalUserAppRequest) {
return new SuccessResponseData<>(portalUserAppService.detail(portalUserAppRequest));
}
/**
*
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
@GetResource(name = "获取列表", path = "/portalUserApp/list")
public ResponseData<List<PortalUserApp>> list(PortalUserAppRequest portalUserAppRequest) {
return new SuccessResponseData<>(portalUserAppService.findList(portalUserAppRequest));
}
/**
*
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
@GetResource(name = "分页查询", path = "/portalUserApp/page")
public ResponseData<PageResult<PortalUserApp>> page(PortalUserAppRequest portalUserAppRequest) {
return new SuccessResponseData<>(portalUserAppService.findPage(portalUserAppRequest));
}
}

View File

@ -27,6 +27,13 @@ public class PortalUserApp extends BaseEntity {
@ChineseDescription("主键id")
private Long appLinkId;
/**
* id
*/
@TableField("user_id")
@ChineseDescription("所属用户id")
private Long userId;
/**
* id
*/

View File

@ -1,6 +1,6 @@
package cn.stylefeng.roses.kernel.sys.modular.userapp.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo;
import cn.stylefeng.roses.kernel.sys.modular.userapp.entity.PortalUserApp;
import cn.stylefeng.roses.kernel.sys.modular.userapp.pojo.request.PortalUserAppRequest;
import com.baomidou.mybatisplus.extension.service.IService;
@ -15,60 +15,22 @@ import java.util.List;
*/
public interface PortalUserAppService extends IService<PortalUserApp> {
/**
*
/**
*
*
* @param portalUserAppRequest
* @author fengshuonan
* @date 2023/06/26 21:25
*/
void add(PortalUserAppRequest portalUserAppRequest);
void updateUserAppList(PortalUserAppRequest portalUserAppRequest);
/**
*
*
* @param portalUserAppRequest
* @author fengshuonan
* @date 2023/06/26 21:25
*/
void del(PortalUserAppRequest portalUserAppRequest);
/**
*
*
* @param portalUserAppRequest
* @author fengshuonan
* @date 2023/06/26 21:25
*/
void edit(PortalUserAppRequest portalUserAppRequest);
/**
*
*
* @param portalUserAppRequest
* @author fengshuonan
* @date 2023/06/26 21:25
*/
PortalUserApp detail(PortalUserAppRequest portalUserAppRequest);
/**
/**
*
*
* @param portalUserAppRequest
* @return List<PortalUserApp>
* @author fengshuonan
* @date 2023/06/26 21:25
*/
List<PortalUserApp> findList(PortalUserAppRequest portalUserAppRequest);
/**
*
*
* @param portalUserAppRequest
* @return PageResult<PortalUserApp>
* @author fengshuonan
* @date 2023/06/26 21:25
*/
PageResult<PortalUserApp> findPage(PortalUserAppRequest portalUserAppRequest);
List<UserAppMenuInfo> getUserAppList();
}

View File

@ -2,21 +2,22 @@ package cn.stylefeng.roses.kernel.sys.modular.userapp.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.sys.api.SysMenuServiceApi;
import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo;
import cn.stylefeng.roses.kernel.sys.modular.userapp.entity.PortalUserApp;
import cn.stylefeng.roses.kernel.sys.modular.userapp.enums.PortalUserAppExceptionEnum;
import cn.stylefeng.roses.kernel.sys.modular.userapp.mapper.PortalUserAppMapper;
import cn.stylefeng.roses.kernel.sys.modular.userapp.pojo.request.PortalUserAppRequest;
import cn.stylefeng.roses.kernel.sys.modular.userapp.service.PortalUserAppService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
*
@ -27,78 +28,37 @@ import java.util.List;
@Service
public class PortalUserAppServiceImpl extends ServiceImpl<PortalUserAppMapper, PortalUserApp> implements PortalUserAppService {
@Override
public void add(PortalUserAppRequest portalUserAppRequest) {
@Resource
private SysMenuServiceApi sysMenuServiceApi;
@Override
public void updateUserAppList(PortalUserAppRequest portalUserAppRequest) {
PortalUserApp portalUserApp = new PortalUserApp();
BeanUtil.copyProperties(portalUserAppRequest, portalUserApp);
this.save(portalUserApp);
}
@Override
public void del(PortalUserAppRequest portalUserAppRequest) {
PortalUserApp portalUserApp = this.queryPortalUserApp(portalUserAppRequest);
this.removeById(portalUserApp.getAppLinkId());
}
public List<UserAppMenuInfo> getUserAppList() {
@Override
public void edit(PortalUserAppRequest portalUserAppRequest) {
PortalUserApp portalUserApp = this.queryPortalUserApp(portalUserAppRequest);
BeanUtil.copyProperties(portalUserAppRequest, portalUserApp);
this.updateById(portalUserApp);
}
// 获取当前登录用户id
Long userId = LoginContext.me().getLoginUser().getUserId();
@Override
public PortalUserApp detail(PortalUserAppRequest portalUserAppRequest) {
return this.queryPortalUserApp(portalUserAppRequest);
}
// 获取所有的用户常用功能(功能其实对应的就是菜单)
LambdaQueryWrapper<PortalUserApp> portalUserAppLambdaQueryWrapper = new LambdaQueryWrapper<>();
portalUserAppLambdaQueryWrapper.eq(PortalUserApp::getUserId, userId);
portalUserAppLambdaQueryWrapper.select(PortalUserApp::getMenuId);
List<PortalUserApp> userAppList = this.list(portalUserAppLambdaQueryWrapper);
@Override
public PageResult<PortalUserApp> findPage(PortalUserAppRequest portalUserAppRequest) {
LambdaQueryWrapper<PortalUserApp> wrapper = createWrapper(portalUserAppRequest);
Page<PortalUserApp> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(sysRolePage);
}
@Override
public List<PortalUserApp> findList(PortalUserAppRequest portalUserAppRequest) {
LambdaQueryWrapper<PortalUserApp> wrapper = this.createWrapper(portalUserAppRequest);
return this.list(wrapper);
}
/**
*
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
private PortalUserApp queryPortalUserApp(PortalUserAppRequest portalUserAppRequest) {
PortalUserApp portalUserApp = this.getById(portalUserAppRequest.getAppLinkId());
if (ObjectUtil.isEmpty(portalUserApp)) {
throw new ServiceException(PortalUserAppExceptionEnum.PORTAL_USER_APP_NOT_EXISTED);
if (ObjectUtil.isEmpty(userAppList)) {
return new ArrayList<>();
}
return portalUserApp;
}
/**
* wrapper
*
* @author fengshuonan
* @date 2023/06/26 21:25
*/
private LambdaQueryWrapper<PortalUserApp> createWrapper(PortalUserAppRequest portalUserAppRequest) {
LambdaQueryWrapper<PortalUserApp> queryWrapper = new LambdaQueryWrapper<>();
// 获取这些功能的菜单id集合
Set<Long> totalMenuIdList = userAppList.stream().map(PortalUserApp::getMenuId).collect(Collectors.toSet());
Long appLinkId = portalUserAppRequest.getAppLinkId();
Long appId = portalUserAppRequest.getAppId();
Long menuId = portalUserAppRequest.getMenuId();
Long tenantId = portalUserAppRequest.getTenantId();
queryWrapper.eq(ObjectUtil.isNotNull(appLinkId), PortalUserApp::getAppLinkId, appLinkId);
queryWrapper.eq(ObjectUtil.isNotNull(appId), PortalUserApp::getAppId, appId);
queryWrapper.eq(ObjectUtil.isNotNull(menuId), PortalUserApp::getMenuId, menuId);
queryWrapper.eq(ObjectUtil.isNotNull(tenantId), PortalUserApp::getTenantId, tenantId);
return queryWrapper;
// 通过这些菜单id查询到菜单的名称、图标、路由返回给前端
return sysMenuServiceApi.getUserAppMenuDetailList(totalMenuIdList);
}
}