|
@@ -1,6 +1,7 @@
|
|
|
package org.jeecg.modules.system.service.impl;
|
|
|
|
|
|
-import cn.hutool.system.UserInfo;
|
|
|
+import bp.wf.Dev2Interface;
|
|
|
+import java.lang.reflect.Field;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
@@ -13,16 +14,16 @@ import org.jeecg.modules.system.entity.*;
|
|
|
import org.jeecg.modules.system.entity.AppmanageEntity.*;
|
|
|
import org.jeecg.modules.system.mapper.*;
|
|
|
import org.jeecg.modules.system.service.*;
|
|
|
+import org.jeecg.modules.system.util.AppManageUtil;
|
|
|
import org.jeecg.modules.system.vo.SysUserRoleVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
import java.util.stream.Collectors;
|
|
|
-
|
|
|
+import org.apache.commons.beanutils.BeanUtils;
|
|
|
/**
|
|
|
* 功能描述
|
|
|
*
|
|
@@ -32,6 +33,10 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class AppmanageServiceImpl implements AppmanageService {
|
|
|
|
|
|
+ // 简单查询用户信息
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private BaseCommonService baseCommonService;
|
|
|
|
|
@@ -75,26 +80,12 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
@Autowired
|
|
|
private ISysDictService sysDictService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ISysUserService sysUserService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
private final ReentrantLock lock = new ReentrantLock();
|
|
|
private final String UNCHECK_TAG_BASE_PATH = "AppInfouncheckTag:";
|
|
|
|
|
|
- // 判断当前用户是否有编辑当前信息的权限
|
|
|
- private boolean hasEditCurrentInfoPermission(String appid){
|
|
|
- // 获取当前登录用户
|
|
|
- LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
- // 查询基础信息的应用管理员id,比较是否和当前登录用户一致
|
|
|
- QueryWrapper<AppBaseInfo> baseInfoPOQueryWrapper = new QueryWrapper<>();
|
|
|
- baseInfoPOQueryWrapper.select("admin").eq("id", appid);
|
|
|
- AppBaseInfo baseInfo = baseInfoMapper.selectOne(baseInfoPOQueryWrapper);
|
|
|
- return loginUser.getId().equals(baseInfo.getAdmin());
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 注册应用信息 简易注册与完整注册
|
|
|
* @param appInfo
|
|
@@ -102,89 +93,69 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public String addAppInfo(AppInfo appInfo) {
|
|
|
- // 创建人
|
|
|
- LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
- // 先行添加应用基础信息。获得appid
|
|
|
- AppBaseInfo appBaseInfo = appInfo.getAppBaseInfoDTO();
|
|
|
+ public String addAppInfo(AppInfo appInfo) throws Exception {
|
|
|
// 查询有无相同的应用名
|
|
|
+ AppBaseInfo appBaseInfo = appInfo.getAppBaseInfoDTO();
|
|
|
QueryWrapper<AppBaseInfo> appBaseInfoQueryWrapper = new QueryWrapper<>();
|
|
|
appBaseInfoQueryWrapper.eq("name", appBaseInfo.getName());
|
|
|
if (baseInfoMapper.selectOne(appBaseInfoQueryWrapper) != null) return "应用名称已存在";
|
|
|
-
|
|
|
+ // 创建人
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
appBaseInfo.setCreateBy(loginUser.getId());
|
|
|
appBaseInfo.setAddType(appInfo.getAddType());
|
|
|
+ appBaseInfo.setDelFlag(1);
|
|
|
baseInfoMapper.insert(appBaseInfo);
|
|
|
+ // 提交至工作流的表单信息(需要将用户id换成真名,字典值换成字典文本)
|
|
|
+ AppBaseInfo sendCheck_appBaseInfo = appBaseInfo;
|
|
|
+ sendCheck_appBaseInfo.setAdmin(customMapper.queryRealnameByUserId(appBaseInfo.getAdmin()));
|
|
|
+ if (appBaseInfo.getDevelopUser()!=null)
|
|
|
+ sendCheck_appBaseInfo.setDevelopUser(customMapper.queryRealnameByUserId(appBaseInfo.getDevelopUser()));
|
|
|
+ if (appBaseInfo.getOperationUser()!=null)
|
|
|
+ sendCheck_appBaseInfo.setOperationUser(customMapper.queryRealnameByUserId(appBaseInfo.getOperationUser()));
|
|
|
+ if (appBaseInfo.getRequirementUser()!=null)
|
|
|
+ sendCheck_appBaseInfo.setRequirementUser(customMapper.queryRealnameByUserId(appBaseInfo.getRequirementUser()));
|
|
|
+ if (appBaseInfo.getBusinessUser()!=null)
|
|
|
+ sendCheck_appBaseInfo.setBusinessUser(customMapper.queryRealnameByUserId(appBaseInfo.getBusinessUser()));
|
|
|
+ sendCheck_appBaseInfo.setType(sysDictService.queryDictTextByKey("app_type", appBaseInfo.getType()));
|
|
|
+ sendCheck_appBaseInfo.setStatus(sysDictService.queryDictTextByKey("app_status", appBaseInfo.getStatus()));
|
|
|
+ AppDocInfo appDocInfo = appInfo.getAppDocInfoDTO();
|
|
|
+ Boolean hasEnvInfo = appInfo.getAppEnvInfoDTO().size()>0;
|
|
|
// 简易注册模式下添加基础信息即可
|
|
|
- if (appBaseInfo.getAddType().equals("easy")) return "提交成功";
|
|
|
+ if (appBaseInfo.getAddType().equals("easy")){
|
|
|
+ sendCheckWordFlow(sendCheck_appBaseInfo, "021",loginUser.getUsername());
|
|
|
+ return "提交成功";
|
|
|
+ }else {
|
|
|
+ APP_Register_workFlow_FormEntity appRegisterWorkFlowFormEntity = new APP_Register_workFlow_FormEntity();
|
|
|
+ BeanUtils.copyProperties(appRegisterWorkFlowFormEntity, appDocInfo);
|
|
|
+ // 基础信息最后一个复制,避免id为null
|
|
|
+ BeanUtils.copyProperties(appRegisterWorkFlowFormEntity, sendCheck_appBaseInfo);
|
|
|
+ if (hasEnvInfo){
|
|
|
+ AppManageUtil appManageUtil = new AppManageUtil();
|
|
|
+ appRegisterWorkFlowFormEntity = appManageUtil.TransitionEnvInfoToAppRegisterWorkFlowForm(appRegisterWorkFlowFormEntity, appInfo.getAppEnvInfoDTO());
|
|
|
+ }
|
|
|
+ sendCheckWordFlow(appRegisterWorkFlowFormEntity, "022",loginUser.getUsername());
|
|
|
+ }
|
|
|
String appid = appBaseInfo.getId();
|
|
|
|
|
|
- // 添加默认角色信息
|
|
|
- SysRole role = new SysRole();
|
|
|
- role.setAppId(appid); // 设置角色所属应用信息
|
|
|
- role.setRoleCode("default"); // 设置角色编码
|
|
|
- role.setAppName(appBaseInfo.getName()) ; // 设置角色的应用名称
|
|
|
- role.setRoleName(appBaseInfo.getName()+"_默认用户角色"); // 设置角色名
|
|
|
- sysRoleService.save(role); // 添加角色
|
|
|
-
|
|
|
- // 获取角色编码
|
|
|
- String roleid = role.getId();
|
|
|
- ArrayList<String> useridlist = new ArrayList<>();
|
|
|
// 添加应用用户信息
|
|
|
appInfo.getUserInfo().forEach(userid -> {
|
|
|
AppUserInfo userInfo = new AppUserInfo();
|
|
|
userInfo.setAppid(appid);
|
|
|
userInfo.setUserid(userid);
|
|
|
- useridlist.add(userid);
|
|
|
userInfoMapper.insert(userInfo);
|
|
|
});
|
|
|
|
|
|
- // 给应用默认角色分配用户
|
|
|
- SysUserRoleVO sysUserRoleVO = new SysUserRoleVO();
|
|
|
- sysUserRoleVO.setRoleId(roleid);
|
|
|
- sysUserRoleVO.setUserIdList(useridlist);
|
|
|
- sysUserController.addSysUserRole(sysUserRoleVO);
|
|
|
-
|
|
|
- // 创建该应用的一级菜单
|
|
|
- SysPermission sysPermission = new SysPermission();
|
|
|
- // 设置菜单名称即为应用名称
|
|
|
- sysPermission.setName(appBaseInfo.getName());
|
|
|
- // 设置菜单所属应用
|
|
|
- sysPermission.setAppId(appid);
|
|
|
-// // 设置菜单权限编码
|
|
|
-// sysPermission.setPerms("sys:appmanage:enter:"+sysPermission.getName());
|
|
|
- // 设置菜单路径
|
|
|
- sysPermission.setUrl(appBaseInfo.getMenuInfo());
|
|
|
- // 设置组件(即 菜单路径去掉第一个 "/")
|
|
|
- String component = sysPermission.getUrl().replaceFirst("^/", "");
|
|
|
- sysPermission.setComponent(component);
|
|
|
- // 设置菜单类型 (0: 一级菜单)
|
|
|
- sysPermission.setMenuType(0);
|
|
|
- // 是否路由
|
|
|
- sysPermission.setRoute(true);
|
|
|
- sysPermissionService.addPermission(sysPermission);
|
|
|
-
|
|
|
- // 授予应用默认角色访问一级菜单权限
|
|
|
- try {
|
|
|
- sysRolePermissionService.saveRolePermission(roleid, sysPermission.getId(),"");
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
-
|
|
|
- // 走审核流 (暂放)
|
|
|
-
|
|
|
// 添加应用环境信息
|
|
|
- if (!appInfo.getAppEnvInfoDTO().isEmpty()){
|
|
|
- System.out.println("环境信息不为空");
|
|
|
+ if (hasEnvInfo){
|
|
|
for (AppEnvInfo appEnvInfo : appInfo.getAppEnvInfoDTO()){
|
|
|
appEnvInfo.setAppid(appid);
|
|
|
envInfoMapper.insert(appEnvInfo);
|
|
|
}
|
|
|
}
|
|
|
// 添加应用文档信息
|
|
|
- AppDocInfo appDocInfo = appInfo.getAppDocInfoDTO();
|
|
|
appDocInfo.setAppid(appid);
|
|
|
docInfoMapper.insert(appDocInfo);
|
|
|
+
|
|
|
return "提交成功";
|
|
|
}
|
|
|
|
|
@@ -204,8 +175,9 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
// 不能删除基础平台的应用信息
|
|
|
if (id.equals("0")) return false;
|
|
|
AppBaseInfo appBaseInfo = baseInfoMapper.selectById(id);
|
|
|
- if (!(appBaseInfo.getAdmin().equals(loginUser.getId()))) return false;
|
|
|
-
|
|
|
+ if (!loginUser.getUsername().equals("admin")){
|
|
|
+ if (!(appBaseInfo.getAdmin().equals(loginUser.getId()))) return false;
|
|
|
+ }
|
|
|
// 删除所属该应用的基础信息、环境信息、文档信息、用户信息
|
|
|
baseInfoMapper.deleteById(id);
|
|
|
envInfoMapper.delete(new QueryWrapper<AppEnvInfo>().eq("appid", id));
|
|
@@ -221,10 +193,11 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
|
|
|
query.eq(SysPermission::getAppId, id);
|
|
|
List<SysPermission> list = sysPermissionService.list(query);
|
|
|
- for (SysPermission sysPermission : list){
|
|
|
- sysPermissionService.deletePermission(sysPermission.getId());
|
|
|
+ if (list.size() != 0){
|
|
|
+ for (SysPermission sysPermission : list){
|
|
|
+ sysPermissionService.deletePermission(sysPermission.getId());
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
// 删除该应用下所创建的角色信息
|
|
|
String[] Approleids = sysRoleService.listRoleIdsByAppId(id);
|
|
|
if (Approleids!=null){
|
|
@@ -336,11 +309,22 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
userInfoMapper.insert(userInfoPO);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
// 解除反审核状态
|
|
|
uncheckLock("AppuserInfo"+updataUserInfo.getAppid());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 默认角色与应用用户强绑定
|
|
|
+ */
|
|
|
+ public Boolean appDefaultRoleSyncappUser(List<String> userids, String appid) {
|
|
|
+ QueryWrapper<AppUserInfo> appUserInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ appUserInfoQueryWrapper.eq("appid", appid);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 组合条件查询应用基础信息
|
|
|
* @param key 模糊查询关键字
|
|
@@ -359,7 +343,6 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
Map<String, String> appManagerInfo = new HashMap<>();
|
|
|
baseInfos.forEach(baseInfo -> {
|
|
|
appManagerInfo.put(baseInfo.getId(), baseInfo.getAdminid());
|
|
|
-
|
|
|
// 查询字典
|
|
|
String typeText = sysDictService.queryDictTextByKey("app_type", baseInfo.getType());
|
|
|
String statusText = sysDictService.queryDictTextByKey("app_status", baseInfo.getStatus());
|
|
@@ -386,7 +369,6 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
// }
|
|
|
// return baseInfos;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 根据id查询应用基础信息
|
|
|
* @param id
|
|
@@ -564,6 +546,7 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ // 获取某个应用用户id集合
|
|
|
@Override
|
|
|
public List<String> getAppuserids(String appid) {
|
|
|
QueryWrapper<AppUserInfo> userInfoQueryWrapper = new QueryWrapper<>();
|
|
@@ -577,6 +560,7 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ // 是否为信息部用户
|
|
|
@Override
|
|
|
public boolean isInfoUser() {
|
|
|
String deptId = customMapper.queryDepartIdByDepartName("信息部");
|
|
@@ -649,5 +633,88 @@ public class AppmanageServiceImpl implements AppmanageService {
|
|
|
return roleNameInfo;
|
|
|
}
|
|
|
|
|
|
+ // 加入流程
|
|
|
+ private <T> void sendCheckWordFlow(T object, String flowNo, String username) throws Exception {
|
|
|
+ Hashtable<String, String> hashtable = new Hashtable<>();
|
|
|
+ Class<?> clazz = object.getClass();
|
|
|
+ // 获取所有字段
|
|
|
+ Field[] fields = clazz.getDeclaredFields();
|
|
|
+ // 遍历所有字段
|
|
|
+ for (Field field : fields) {
|
|
|
+ // 设置访问权限
|
|
|
+ field.setAccessible(true);
|
|
|
+ try {
|
|
|
+ Object value = field.get(object);
|
|
|
+ if (value != null) {
|
|
|
+ // 将值转换为字符串
|
|
|
+ String stringValue = value.toString();
|
|
|
+ hashtable.put(field.getName(), stringValue);
|
|
|
+ }
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ throw new RuntimeException("Failed to access field: " + field.getName(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Dev2Interface dev2Interface = new Dev2Interface();
|
|
|
+ long workID = Dev2Interface.Node_CreateBlankWork(flowNo, username);
|
|
|
+ if (hashtable.size()>0) dev2Interface.Node_SendWork(flowNo,workID, hashtable);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断当前用户是否有编辑当前信息的权限
|
|
|
+ private boolean hasEditCurrentInfoPermission(String appid){
|
|
|
+ // 获取当前登录用户
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ // 查询基础信息的应用管理员id,比较是否和当前登录用户一致
|
|
|
+ QueryWrapper<AppBaseInfo> baseInfoPOQueryWrapper = new QueryWrapper<>();
|
|
|
+ baseInfoPOQueryWrapper.select("admin").eq("id", appid);
|
|
|
+ AppBaseInfo baseInfo = baseInfoMapper.selectOne(baseInfoPOQueryWrapper);
|
|
|
+ return loginUser.getId().equals(baseInfo.getAdmin());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用审核通过后一系列创建应用一级菜单、默认角色、授权操作(完整注册时)
|
|
|
+ public void afterAppCheckPass(String appid) {
|
|
|
+ AppBaseInfo appBaseInfo = baseInfoMapper.selectById(appid);
|
|
|
+
|
|
|
+ // 添加默认角色信息
|
|
|
+ SysRole role = new SysRole();
|
|
|
+ role.setAppId(appid); // 设置角色所属应用信息
|
|
|
+ role.setRoleCode("default"); // 设置角色编码
|
|
|
+ role.setAppName(appBaseInfo.getName()) ; // 设置角色的应用名称
|
|
|
+ role.setRoleName(appBaseInfo.getName()+"_默认用户角色"); // 设置角色名
|
|
|
+ sysRoleService.save(role); // 添加角色
|
|
|
+
|
|
|
+ // 获取角色编码
|
|
|
+ String roleid = role.getId();
|
|
|
+
|
|
|
+ // 查询应用用户id集合
|
|
|
+ QueryWrapper<AppUserInfo> appUserInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ appUserInfoQueryWrapper.select("userid").eq("appid", appid);
|
|
|
+ List<AppUserInfo> appUserInfos = userInfoMapper.selectList(appUserInfoQueryWrapper);
|
|
|
+ List<String> useridlist = appUserInfos.stream().map(AppUserInfo::getUserid).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 应用默认角色分配给应用用户
|
|
|
+ SysUserRoleVO sysUserRoleVO = new SysUserRoleVO();
|
|
|
+ sysUserRoleVO.setRoleId(roleid);
|
|
|
+ sysUserRoleVO.setUserIdList(useridlist);
|
|
|
+ sysUserController.addSysUserRole(sysUserRoleVO);
|
|
|
|
|
|
+ // 创建该应用的一级菜单
|
|
|
+ SysPermission sysPermission = new SysPermission();
|
|
|
+ sysPermission.setName(appBaseInfo.getName());
|
|
|
+ sysPermission.setAppId(appid);
|
|
|
+ sysPermission.setUrl(appBaseInfo.getMenuInfo());
|
|
|
+ // 设置组件(即 菜单路径去掉第一个 "/")
|
|
|
+ String component = sysPermission.getUrl().replaceFirst("^/", "");
|
|
|
+ sysPermission.setComponent(component);
|
|
|
+ sysPermission.setMenuType(0);
|
|
|
+ sysPermission.setRoute(true);
|
|
|
+ sysPermissionService.addPermission(sysPermission);
|
|
|
+
|
|
|
+ // 授予应用默认角色访问一级菜单权限
|
|
|
+ sysRolePermissionService.saveRolePermission(roleid, sysPermission.getId(),"");
|
|
|
+ }
|
|
|
+
|
|
|
+// // 根据用户id查询用户姓名,先从redis数据库中查询,若没有再从数据库中查询
|
|
|
+// private String queryUserNameByUserId(String userid){
|
|
|
+//
|
|
|
+// }
|
|
|
}
|