| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- package jnpf.base.controller;
- import cn.dev33.satoken.annotation.SaCheckPermission;
- import cn.dev33.satoken.annotation.SaMode;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.util.ObjectUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.Parameter;
- import io.swagger.v3.oas.annotations.Parameters;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import jnpf.base.ActionResult;
- import jnpf.base.Pagination;
- import jnpf.base.UserInfo;
- import jnpf.base.entity.ModuleEntity;
- import jnpf.base.entity.SystemEntity;
- import jnpf.base.model.AppAuthorizationModel;
- import jnpf.base.model.AppAuthorizeVo;
- import jnpf.base.model.UserAuthorize;
- import jnpf.base.model.base.*;
- import jnpf.base.service.CommonWordsService;
- import jnpf.base.service.ModuleService;
- import jnpf.base.service.PortalManageService;
- import jnpf.base.service.SystemService;
- import jnpf.base.vo.ListVO;
- import jnpf.base.vo.PaginationVO;
- import jnpf.constant.JnpfConst;
- import jnpf.constant.MsgCode;
- import jnpf.constant.PermissionConst;
- import jnpf.constant.model.MCode;
- import jnpf.emnus.SysParamEnum;
- import jnpf.message.util.OnlineUserModel;
- import jnpf.message.util.OnlineUserProvider;
- import jnpf.permission.entity.RoleEntity;
- import jnpf.permission.entity.RoleRelationEntity;
- import jnpf.permission.entity.UserEntity;
- import jnpf.permission.model.authorize.AuthorizeVO;
- import jnpf.permission.model.user.vo.BaseInfoVo;
- import jnpf.permission.service.AuthorizeService;
- import jnpf.permission.service.RoleRelationService;
- import jnpf.permission.service.RoleService;
- import jnpf.permission.service.UserService;
- import jnpf.util.JsonUtil;
- import jnpf.util.StringUtil;
- import jnpf.util.UploaderUtil;
- import jnpf.util.UserProvider;
- import org.apache.commons.collections4.CollectionUtils;
- import org.jetbrains.annotations.NotNull;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 应用中心
- *
- * @author :JNPF开发平台组
- * @version: V3.1.0
- * @copyright 引迈信息技术有限公司
- * @date :2022/6/21 15:33
- */
- @Tag(name = "应用中心", description = "system")
- @RestController
- @RequestMapping("/api/system/System")
- public class SystemController extends SuperController<SystemService, SystemEntity> {
- @Autowired
- private RoleService roleService;
- @Autowired
- private RoleRelationService roleRelationService;
- @Autowired
- private UserService userService;
- @Autowired
- private SystemService systemService;
- @Autowired
- private CommonWordsService commonWordsService;
- @Autowired
- private PortalManageService portalManageService;
- @Autowired
- private ModuleService moduleService;
- @Autowired
- private AuthorizeService authorizeService;
- @Operation(summary = "应用列表")
- @SaCheckPermission(value = {"appCenter", "workFlow.flowQuickLaunch", "teamwork.printTemplate", "monitor.flowMonitor", "monitor.userOnline"}, mode = SaMode.OR)
- @GetMapping
- public ActionResult<ListVO<SystemListVO>> list(SystemPageVO page) {
- Boolean enabledMark = false;
- if (ObjectUtil.equal(page.getEnabledMark(), "0")) {
- enabledMark = null;
- }
- if (ObjectUtil.equal(page.getEnabledMark(), "1")) {
- enabledMark = true;
- }
- List<SystemEntity> list = systemService.getList(page.getKeyword(), enabledMark, true, true, true, new ArrayList<>());
- List<SystemListVO> jsonToList = JsonUtil.getJsonToList(list, SystemListVO.class);
- //有修改权限列表
- List<String> authList = systemService.getAuthListByUser(UserProvider.getUser().getUserId(), true).stream().map(SystemEntity::getId).collect(Collectors.toList());
- UserInfo user = UserProvider.getUser();
- for (SystemListVO vo : jsonToList) {
- vo.setHasDelete(user.getIsAdministrator() || user.getUserId().equals(vo.getUserId()) ? 1 : 0);
- vo.setHasUpdate(user.getIsAdministrator() || authList.contains(vo.getId()) ? 1 : 0);
- }
- return ActionResult.success(new ListVO<>(jsonToList));
- }
- @Operation(summary = "获取应用授权信息")
- @SaCheckPermission(value = {"appConfig.appAuth"})
- @GetMapping("/getAppAuthorization/{systemId}")
- public ActionResult<AppAuthorizeVo> getAppAuthorization(@PathVariable String systemId) {
- Pagination pagination = new Pagination();
- AppAuthorizeVo appAuthorizeVo = new AppAuthorizeVo();
- SystemEntity info = systemService.getInfo(systemId);
- if (BeanUtil.isEmpty(info)) {
- return ActionResult.fail(MsgCode.FA001.getDesc());
- }
- String userId = "";
- String authorizeId = "";
- List<BaseInfoVo> baseInfoVos = new ArrayList<>();
- if (null == info.getUserId() || info.getUserId().isEmpty()) {
- appAuthorizeVo.setDevUsers(new ArrayList<>());
- appAuthorizeVo.setIsAllDevUser(1);
- appAuthorizeVo.setCreateUserId(info.getCreatorUserId());
- return ActionResult.success(appAuthorizeVo);
- } else {
- userId = info.getUserId();
- List<String> strings = new ArrayList<>();
- strings.add(userId);
- baseInfoVos = getBaseInfoVos(pagination, strings);
- List<UserAuthorize> userAuthorizes = baseInfoVos.stream()
- .map(item -> BeanUtil.copyProperties(item, UserAuthorize.class)).collect(Collectors.toList());
- appAuthorizeVo.setCreateUserId(userAuthorizes.get(0).getId());
- appAuthorizeVo.setFullName(baseInfoVos.get(0).getFullName());
- }
- if (null == info.getAuthorizeId()) {
- appAuthorizeVo.setDevUsers(new ArrayList<>());
- appAuthorizeVo.setIsAllDevUser(0);
- return ActionResult.success(appAuthorizeVo);
- }
- authorizeId = info.getAuthorizeId();
- if (PermissionConst.ALL_DEV_USER.equals(authorizeId)) {
- List<String> collect = getUserIdListByRoleId();
- baseInfoVos = getBaseInfoVos(pagination, collect);
- appAuthorizeVo.setIsAllDevUser(1);
- } else {
- String[] split = authorizeId.split(",");
- List<String> collect = Arrays.stream(split).distinct().collect(Collectors.toList());
- baseInfoVos = getBaseInfoVos(pagination, collect);
- appAuthorizeVo.setIsAllDevUser(0);
- }
- List<UserAuthorize> userAuthorizes = baseInfoVos.stream()
- .map(item -> BeanUtil.copyProperties(item, UserAuthorize.class)).collect(Collectors.toList());
- appAuthorizeVo.setDevUsers(userAuthorizes.stream().map(UserAuthorize::getId).collect(Collectors.toList()));
- return ActionResult.success(appAuthorizeVo);
- }
- @Operation(summary = "保存应用授权信息")
- @SaCheckPermission(value = {"appConfig.appAuth"})
- @PostMapping("/saveAppAuthorization")
- public ActionResult<MCode> appAuthorization(@RequestBody AppAuthorizationModel model) {
- systemService.saveSystemAuthorizion(model);
- return ActionResult.success(MsgCode.SU005.get());
- }
- @Operation(summary = "移交应用创建者")
- @SaCheckPermission(value = {"appConfig.appAuth"})
- @PostMapping("/changeAppAuthorization")
- public ActionResult<MCode> changeAppAuthorization(@RequestBody AppAuthorizationModel model) {
- systemService.changeSystemAuthorizion(model);
- return ActionResult.success(MsgCode.SU005.get());
- }
- @Operation(summary = "获取开发人员")
- @SaCheckPermission(value = {"appConfig.appAuth", "permission.user"}, mode = SaMode.OR)
- @GetMapping("/getDevUser")
- public ActionResult getDevRole(Pagination pagination) {
- List<String> collect = getUserIdListByRoleId();
- List<BaseInfoVo> baseInfoVoList = getBaseInfoVos(pagination, collect, true);
- PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
- return ActionResult.page(baseInfoVoList, paginationVO);
- }
- /**
- * 根据开发者角色获取用户id集合
- *
- * @return 返回用户id集合
- */
- private @NotNull List<String> getUserIdListByRoleId() {
- LambdaQueryWrapper<RoleEntity> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(RoleEntity::getEnCode, PermissionConst.DEVELOPER_CODE);
- List<RoleEntity> list = roleService.list(queryWrapper);
- String id = list.get(0).getId();
- //获取用户id集合
- List<String> collect = roleRelationService.getListByRoleId(id, PermissionConst.USER)
- .stream()
- .map(RoleRelationEntity::getObjectId)
- .collect(Collectors.toList());
- return collect;
- }
- /**
- * 根据关键词查询用户信息
- *
- * @param pagination 关键词
- * @param collect 用户id集合
- * @return 用户信息集合
- */
- private @NotNull List<BaseInfoVo> getBaseInfoVos(Pagination pagination, List<String> collect) {
- return getBaseInfoVos(pagination, collect, false);
- }
- private @NotNull List<BaseInfoVo> getBaseInfoVos(Pagination pagination, List<String> collect, Boolean filter) {
- if (CollectionUtils.isEmpty(collect)) {
- return Collections.emptyList();
- }
- QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
- if (filter) {
- queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
- }
- if (!StringUtil.isEmpty(pagination.getKeyword())) {
- queryWrapper.lambda().and(
- t -> t.like(UserEntity::getAccount, pagination.getKeyword())
- .or().like(UserEntity::getRealName, pagination.getKeyword())
- .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
- );
- }
- queryWrapper.lambda().in(UserEntity::getId, collect);
- queryWrapper.lambda().orderByAsc(UserEntity::getId);
- Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
- page.setOptimizeCountSql(true);
- Page<UserEntity> actionEntityPage = userService.page(page, queryWrapper);
- List<UserEntity> entities = pagination.setData(actionEntityPage.getRecords(), page.getTotal());
- return entities.stream()
- .map(item -> {
- BaseInfoVo vo = JsonUtil.getJsonToBean(item, BaseInfoVo.class);
- vo.setType(SysParamEnum.USER.getCode());
- vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
- vo.setFullName(vo.getRealName() + "/" + vo.getAccount());
- return vo;
- }).collect(Collectors.toList());
- }
- @Operation(summary = "应用基础设置详情")
- @Parameters({
- @Parameter(name = "id", description = "主键", required = true)
- })
- @SaCheckPermission(value = {"appConfig.baseConfig"})
- @GetMapping("/{id}")
- public ActionResult<SystemVO> info(@PathVariable("id") String id) {
- SystemEntity entity = systemService.getInfo(id);
- if (entity == null) {
- return ActionResult.fail(MsgCode.FA001.get());
- }
- SystemVO jsonToBean = JsonUtil.getJsonToBean(entity, SystemVO.class);
- return ActionResult.success(jsonToBean);
- }
- @Operation(summary = "应用主题配置保存")
- @Parameters({
- @Parameter(name = "id", description = "主键", required = true)
- })
- @SaCheckPermission(value = {"appConfig.baseConfig"})
- @PostMapping("/preferenceSave/{id}")
- public ActionResult<SystemVO> preferenceSave(@PathVariable("id") String id, @RequestBody SystemUpModel upModel) {
- SystemEntity entity = systemService.getInfo(id);
- if (entity == null) {
- return ActionResult.fail(MsgCode.FA001.get());
- }
- entity.setPreferenceJson(upModel.getPreferenceJson());
- systemService.saveOrUpdate(entity);
- return ActionResult.success(MsgCode.SU005.get());
- }
- @Operation(summary = "新建应用")
- @Parameters({
- @Parameter(name = "systemCrModel", description = "新建模型", required = true)
- })
- @SaCheckPermission(value = {"appCenter"})
- @PostMapping
- public ActionResult create(@RequestBody SystemCrModel systemCrModel) {
- SystemEntity entity = JsonUtil.getJsonToBean(systemCrModel, SystemEntity.class);
- if (systemService.isExistEnCode(entity.getId(), entity.getEnCode())) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- systemService.create(entity);
- return ActionResult.success(MsgCode.SU001.get(), entity.getEnCode());
- }
- @Operation(summary = "修改应用")
- @Parameters({
- @Parameter(name = "id", description = "主键", required = true),
- @Parameter(name = "systemCrModel", description = "修改模型", required = true)
- })
- @SaCheckPermission(value = {"appConfig.baseConfig"})
- @PutMapping("/{id}")
- public ActionResult update(@PathVariable("id") String id, @RequestBody SystemUpModel systemUpModel) {
- SystemEntity systemEntity = systemService.getInfo(id);
- if (systemEntity == null) {
- return ActionResult.fail(MsgCode.FA002.get());
- }
- SystemEntity entity = JsonUtil.getJsonToBean(systemUpModel, SystemEntity.class);
- entity.setIsMain(systemEntity.getIsMain());
- if (systemService.isExistEnCode(id, entity.getEnCode())) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- systemService.update(id, entity);
- // 如果禁用了系统,则需要将系统
- if (systemEntity.getEnabledMark() == 1 && entity.getEnabledMark() == 0) {
- sentMessage("应用已被禁用,正为您切换应用", systemEntity);
- }
- return ActionResult.success(MsgCode.SU004.get());
- }
- @Operation(summary = "删除应用")
- @Parameters({
- @Parameter(name = "id", description = "主键", required = true)
- })
- @SaCheckPermission(value = {"appCenter"})
- @DeleteMapping("/{id}")
- public ActionResult<String> delete(@PathVariable("id") String id) {
- SystemEntity entity = systemService.getInfo(id);
- if (entity == null) {
- return ActionResult.fail(MsgCode.FA003.get());
- }
- // 查询平台下菜单
- List<ModuleEntity> webData = moduleService.getList(entity.getEnCode(), JnpfConst.WEB, null, null, null, null, false);
- List<ModuleEntity> appData = moduleService.getList(entity.getEnCode(), JnpfConst.APP, null, null, null, null, false);
- if (CollectionUtils.isNotEmpty(webData) || CollectionUtils.isNotEmpty(appData)) {
- return ActionResult.fail(MsgCode.SYS040.get());
- }
- if (entity.getIsMain() != null && entity.getIsMain() == 1) {
- return ActionResult.fail(MsgCode.SYS102.get());
- }
- // 系统绑定审批常用语时不允许被删除
- if (commonWordsService.existSystem(id)) {
- return ActionResult.fail(MsgCode.SYS103.get());
- } else {
- systemService.delete(id);
- sentMessage("应用已被删除,正为您切换应用", entity);
- }
- return ActionResult.success(MsgCode.SU003.get());
- }
- private void sentMessage(String message, SystemEntity entity) {
- // 如果禁用了系统,则需要将系统
- List<OnlineUserModel> onlineUserList = OnlineUserProvider.getOnlineUserList();
- for (OnlineUserModel item : onlineUserList) {
- String systemId = item.getSystemId();
- if (entity.getId().equals(systemId)) {
- if (item.getWebSocket().isOpen()) {
- Map<String, String> maps = new HashMap<>(1);
- maps.put("method", "logout");
- maps.put("msg", "应用已被禁用或删除");
- if (StringUtil.isNotEmpty(UserProvider.getUser().getTenantId())) {
- if (UserProvider.getUser().getTenantId().equals(item.getTenantId())) {
- item.getWebSocket().getAsyncRemote().sendText(JsonUtil.getObjectToString(maps));
- }
- } else {
- item.getWebSocket().getAsyncRemote().sendText(JsonUtil.getObjectToString(maps));
- }
- }
- }
- }
- }
- @Operation(summary = "获取当前用户有权限的应用")
- @GetMapping("/userAuthList")
- public ActionResult<List<SystemListVO>> userAuthList(Pagination pagination) {
- AuthorizeVO authorizeByUser = authorizeService.getAuthorizeByUser(false);
- List<String> systemIds = authorizeByUser.getSystemList().stream().filter(t -> !Objects.equals(t.getIsMain(), 1))
- .map(SystemBaeModel::getId).collect(Collectors.toList());
- List<SystemEntity> list = systemService.getListByIdsKey(systemIds, pagination.getKeyword());
- List<SystemListVO> listVo = JsonUtil.getJsonToList(list, SystemListVO.class);
- return ActionResult.success(listVo);
- }
- @Operation(summary = "获取所有应用")
- @GetMapping("/Selector")
- public ActionResult<List<SystemListVO>> getSelector() {
- List<SystemEntity> list = systemService.getList().stream().filter(t -> !Objects.equals(t.getIsMain(), 1)).collect(Collectors.toList());
- List<SystemListVO> listVo = JsonUtil.getJsonToList(list, SystemListVO.class);
- return ActionResult.success(listVo);
- }
- }
|