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.alibaba.nacos.shaded.com.google.common.collect.ImmutableMap;
|
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.SystemApi;
|
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.model.module.MenuListModel;
|
import jnpf.base.service.CommonWordsService;
|
import jnpf.base.service.ModuleService;
|
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.NoticeApi;
|
import jnpf.permission.AuthorizeApi;
|
import jnpf.permission.RoleApi;
|
import jnpf.permission.RoleRelationApi;
|
import jnpf.permission.UserApi;
|
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.rolerelaiton.RoleRelationModel;
|
import jnpf.permission.model.user.UserSystemCountModel;
|
import jnpf.permission.model.user.WorkHandoverModel;
|
import jnpf.permission.model.user.vo.BaseInfoVo;
|
import jnpf.util.JsonUtil;
|
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("/System")
|
public class SystemController extends SuperController<SystemService, SystemEntity> implements SystemApi {
|
|
@Autowired
|
private RoleApi roleService;
|
@Autowired
|
private RoleRelationApi roleRelationService;
|
@Autowired
|
private UserApi userApi;
|
@Autowired
|
private SystemService systemService;
|
@Autowired
|
private CommonWordsService commonWordsService;
|
@Autowired
|
private ModuleService moduleService;
|
@Autowired
|
private AuthorizeApi authorizeService;
|
@Autowired
|
private NoticeApi noticeApi;
|
|
@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() {
|
List<RoleEntity> listAll = roleService.getListAll();
|
List<RoleEntity> list = listAll.stream().filter(t -> PermissionConst.DEVELOPER_CODE.equals(t.getEnCode())).collect(Collectors.toList());
|
String id = list.get(0).getId();
|
//获取用户id集合
|
List<String> collect = roleRelationService.getListByRoleId(new RoleRelationModel(null, PermissionConst.USER, Arrays.asList(id)))
|
.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 (null == collect) {
|
return Collections.emptyList();
|
}
|
|
|
List<UserEntity> entities = userApi.page(new UserSystemCountModel(pagination,filter,collect));
|
if (CollectionUtils.isEmpty(entities)) {
|
return Collections.emptyList();
|
}
|
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) {
|
// 通知下线
|
noticeApi.autoSystem(ImmutableMap.of("entity", systemEntity, "message", "应用已被禁用,正为您切换应用"));
|
}
|
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());
|
}
|
// 查询平台下菜单
|
MenuListModel paramW = new MenuListModel();
|
paramW.setAppCode(entity.getEnCode());
|
paramW.setCategory(JnpfConst.WEB);
|
paramW.setRelease(false);
|
AuthorizeVO authorize = authorizeService.getAuthorize(true, entity.getEnCode(), null);
|
paramW.setModuleList(authorize.getModuleList());
|
MenuListModel paramA = BeanUtil.copyProperties(paramW, MenuListModel.class);
|
paramW.setCategory(JnpfConst.APP);
|
List<ModuleEntity> webData = moduleService.getList(paramW);
|
List<ModuleEntity> appData = moduleService.getList(paramA);
|
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);
|
// 通知下线
|
noticeApi.autoSystem(ImmutableMap.of("entity", entity, "message", "应用已被删除,正为您切换应用"));
|
}
|
return ActionResult.success(MsgCode.SU003.get());
|
}
|
|
@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);
|
}
|
|
//++++++++++++++++++++++++++++++++++以下为api接口
|
@Override
|
@GetMapping("/getList")
|
public List<SystemEntity> getList() {
|
return systemService.getList();
|
}
|
|
@Override
|
@PostMapping("/getList")
|
public List<SystemEntity> getList(@RequestBody SystemApiListModel model) {
|
return systemService.getList(model.getKeyword(), model.getFilterEnableMark(), model.getVerifyAuth(), model.getFilterMain(), model.getIsList(), model.getModuleAuthorize());
|
}
|
|
@Override
|
@PostMapping("/getListByIds")
|
public List<SystemEntity> getListByIds(@RequestBody SystemApiByIdsModel model) {
|
return systemService.getListByIds(model.getIds(), model.getModuleAuthorize(), model.getStand());
|
}
|
|
@Override
|
@GetMapping("/getInfoById")
|
public SystemEntity getInfoById(@RequestParam("systemId") String systemId) {
|
return systemService.getInfo(systemId);
|
}
|
|
@Override
|
@GetMapping("/getInfoByEnCode")
|
public SystemEntity getInfoByEnCode(@RequestParam("enCode") String enCode) {
|
return systemService.getInfoByEnCode(enCode);
|
}
|
|
@Override
|
@PostMapping("/findSystemAdmin")
|
public List<SystemEntity> findSystemAdmin(@RequestBody SystemApiModel model) {
|
return systemService.findSystemAdmin(model.getModuleAuthorize());
|
}
|
|
@Override
|
@PostMapping("/getListAll")
|
public List<SystemEntity> getListAll() {
|
return systemService.getList();
|
}
|
|
@PostMapping("/addCommonWordsNum")
|
public void addCommonWordsNum(@RequestBody String commonWordsText) {
|
commonWordsService.addCommonWordsNum(commonWordsText);
|
}
|
|
@Override
|
@GetMapping("/getListByCreUser")
|
public List<SystemEntity> getListByCreUser(@RequestParam("userId") String userId) {
|
return systemService.getListByCreUser(userId);
|
}
|
|
@Override
|
@GetMapping("/getAuthListByUser")
|
public List<SystemEntity> getAuthListByUser(@RequestParam("userId")String userId, @RequestParam(value = "isStand")Boolean isStand) {
|
return systemService.getAuthListByUser(userId, isStand);
|
}
|
|
@Override
|
@PostMapping("/workHandover")
|
public void workHandover(@RequestBody WorkHandoverModel workHandoverModel) {
|
systemService.workHandover(workHandoverModel);
|
}
|
|
@Override
|
@PostMapping("/changeSystemAuthorizion")
|
public void changeSystemAuthorizion(@RequestBody AppAuthorizationModel model) {
|
systemService.changeSystemAuthorizion(model);
|
}
|
}
|