| | |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.highdatas.mdm.entity.SysMenu; |
| | | import com.highdatas.mdm.entity.*; |
| | | import com.highdatas.mdm.pojo.ActivitiBusinessType; |
| | | import com.highdatas.mdm.pojo.ActivitiStatus; |
| | | import com.highdatas.mdm.pojo.CodeMsg; |
| | | import com.highdatas.mdm.pojo.MaintainDataType; |
| | | import com.highdatas.mdm.pojo.Result; |
| | | import com.highdatas.mdm.service.ISysMenuService; |
| | | import com.highdatas.mdm.service.*; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import com.highdatas.mdm.util.NoticeClient; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.util.Date; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RequestMapping("/menu") |
| | | public class SysMenuController { |
| | | @Autowired |
| | | private ISysMenuService menuService; |
| | | ISysMenuService menuService; |
| | | |
| | | @RequestMapping(value = "/all", method = RequestMethod.GET) |
| | | @Autowired |
| | | IMenuMappingService menuMappingService; |
| | | @Autowired |
| | | ISysFieldService fieldService; |
| | | @Autowired |
| | | IFlowsService flowsService; |
| | | @Autowired |
| | | IMaintainService maintainService; |
| | | @Autowired |
| | | IMaintainFieldService maintainFieldService; |
| | | @Autowired |
| | | IMasterAuthorService masterAuthorService; |
| | | @Autowired |
| | | NoticeClient noticeClient; |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取所有主题列表 |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/all") |
| | | public Result<List<SysMenu>> getAll() { |
| | | EntityWrapper<SysMenu> sysMenuEntityWrapper = new EntityWrapper<>(); |
| | | sysMenuEntityWrapper.orderBy(" parent_id, order_no"); |
| | | sysMenuEntityWrapper.orderBy("parent_id, order_no"); |
| | | return Result.success(menuService.selectList(sysMenuEntityWrapper)) ; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取有权限的所有主题列表 |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/author/all", method = RequestMethod.GET) |
| | | public Result<List<SysMenu>> getAllBak(HttpServletRequest request) { |
| | | //获取用户信息 |
| | | TUser user = DbUtils.getUser(request); |
| | | //获取权限下的主题信息 |
| | | List<SysMenu> menu = masterAuthorService.getMenu(user); |
| | | return Result.success(menu) ; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取待审批所有主题列表 |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/audit", method = RequestMethod.GET) |
| | | public Result<List<SysMenu>> audit(HttpServletRequest request) { |
| | | //获取用户信息 |
| | | HttpSession session = request.getSession(); |
| | | TUser user = (TUser) session.getAttribute("user"); |
| | | String userId = user.getUserId(); |
| | | //获取正在跑的流程 |
| | | List<Flows> flows = flowsService.selectList(new EntityWrapper<Flows>().ne("business_type", ActivitiBusinessType.exists).ne("status", ActivitiStatus.open).ne("status", ActivitiStatus.close)); |
| | | //获取用户拥有权限审批的流程 |
| | | flows = flows.stream().filter(flow -> flowsService.isNextAudit(flow, userId)).collect(Collectors.toList()); |
| | | |
| | | HashSet<String> tableNameSet = new HashSet<>(); |
| | | List<String> maintainIds = flows.stream().filter(flow -> flow.getBusinessType().equals(ActivitiBusinessType.maintain)).map(Flows::getBusinessId).collect(Collectors.toList()); |
| | | List<String> maintainFieldIds = flows.stream().filter(flow -> flow.getBusinessType().equals(ActivitiBusinessType.field)).map(Flows::getBusinessId).collect(Collectors.toList()); |
| | | // BY 字段版本和数据版本获取表名 |
| | | if (maintainIds.isEmpty() && maintainFieldIds.isEmpty()) { |
| | | return Result.success(null); |
| | | } |
| | | for (String maintainFieldId : maintainFieldIds) { |
| | | MaintainField maintainField = maintainFieldService.selectById(maintainFieldId); |
| | | if (maintainField == null) { |
| | | continue; |
| | | } |
| | | String tableName = maintainField.getTableName(); |
| | | if (StringUtils.isEmpty(tableName)) { |
| | | continue; |
| | | } |
| | | tableNameSet.add(tableName); |
| | | } |
| | | maintainIds = maintainIds.stream().filter(s -> masterAuthorService.checkMaintainAuthor(user,s)).collect(Collectors.toList()); |
| | | if (!maintainIds.isEmpty()) { |
| | | List<Maintain> maintains = maintainService.selectBatchIds(maintainIds); |
| | | |
| | | List<String> tableNameList = maintains.stream().map(Maintain::getTableName).collect(Collectors.toList()); |
| | | tableNameSet.addAll(tableNameList); |
| | | } |
| | | if (tableNameSet.size() == 0) { |
| | | return Result.success(null); |
| | | } |
| | | //通过表名获取主题 |
| | | List<MenuMapping> menuMappingList = menuMappingService.selectList(new EntityWrapper<MenuMapping>().in("table_name", tableNameSet)); |
| | | List<String> menuIds = menuMappingList.stream().map(MenuMapping::getMenuId).collect(Collectors.toList()); |
| | | if (menuIds.isEmpty()) { |
| | | return Result.success(null); |
| | | } |
| | | //通过主题获取父级主题链 |
| | | LinkedHashSet<String> parentIdSet = new LinkedHashSet<>(menuIds); |
| | | List<SysMenu> parentList = menuService.getMenuByParentId(parentIdSet); |
| | | if (parentList == null) { |
| | | return Result.success(null); |
| | | } |
| | | |
| | | return Result.success(parentList); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取所有的非父级主题列表 |
| | | * @return: 非父级主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/list", method = RequestMethod.GET) |
| | | public Result<List<SysMenu>> getMenuList() { |
| | | EntityWrapper<SysMenu> sysMenuEntityWrapper = new EntityWrapper<>(); |
| | | //获取非父级主题 |
| | | sysMenuEntityWrapper.eq("menu_type", "DataMenu"); |
| | | sysMenuEntityWrapper.orderBy("parent_id, order_no"); |
| | | List<SysMenu> sysMenus = menuService.selectList(sysMenuEntityWrapper); |
| | | LinkedHashSet<String> parentIdSet = new LinkedHashSet<>(); |
| | | for (SysMenu sysMenu : sysMenus) { |
| | | MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("menu_id", sysMenu.getId())); |
| | | if (menuMapping == null) { |
| | | continue; |
| | | } |
| | | String tableName = menuMapping.getTableName(); |
| | | List<SysField> fieldByTable = fieldService.getFieldByTable(tableName); |
| | | //判断是否有实际的表存在 |
| | | if (fieldByTable == null || fieldByTable.size() == 0) { |
| | | continue; |
| | | } |
| | | parentIdSet.add(sysMenu.getId()); |
| | | } |
| | | List<SysMenu> parentList = menuService.getMenuByParentId(parentIdSet); |
| | | |
| | | return Result.success(parentList) ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取所有父级主题列表 |
| | | * @return: 父级主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/allTheme", method = RequestMethod.GET) |
| | | public Result<List<SysMenu>> getAllTheme() { |
| | | EntityWrapper<SysMenu> sysMenuEntityWrapper = new EntityWrapper<>(); |
| | | sysMenuEntityWrapper.eq("menu_type",Constant.StructureMenu).orderBy("parent_id desc "); |
| | | //仅获取父级主题列表 |
| | | sysMenuEntityWrapper.eq("menu_type",Constant.StructureMenu).orderBy("parent_id desc"); |
| | | return Result.success(menuService.selectList(sysMenuEntityWrapper)) ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 分页获取所有主题列表 |
| | | * @param pageno 页数 |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/{pageno}", method = RequestMethod.GET) |
| | | public Result<Page<SysMenu>> getAll(@PathVariable int pageno, HttpServletRequest request) { |
| | | //pageSize 每页数据 |
| | | String pageSize = request.getParameter("pageSize"); |
| | | if (StringUtils.isEmpty(pageSize)) { |
| | | pageSize = "20"; |
| | | pageSize = "15"; |
| | | } |
| | | Integer size = Integer.valueOf(pageSize); |
| | | Page page = new Page(pageno, size); |
| | | //分页获取主题 |
| | | Page<SysMenu> menuPage = menuService.selectPage(page); |
| | | return Result.success(menuPage); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过id获取主题信息 |
| | | * @param id 主题id |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | |
| | | @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) |
| | | public Result<SysMenu> get(@PathVariable String id) throws Exception { |
| | | return Result.success(menuService.selectById(id)); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 添加主题 |
| | | * @param name 主题名称 |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/add", method = RequestMethod.GET) |
| | | public Result<Object> insert(@RequestParam String name, HttpServletRequest request){ |
| | | //前端获取主题参数 |
| | | String ordernoStr = request.getParameter("orderno"); |
| | | String parentId = request.getParameter("parentId"); |
| | | String dataType = request.getParameter("dataType"); |
| | | String menuType = request.getParameter("menuType"); |
| | | |
| | | Integer orderno = null; |
| | | //设置默认顺序 |
| | | if (StringUtils.isEmpty(ordernoStr)){ |
| | | orderno = Integer.valueOf("1"); |
| | | EntityWrapper<SysMenu> menuEntityWrapper = new EntityWrapper<>(); |
| | |
| | | }else { |
| | | orderno = Integer.valueOf(ordernoStr); |
| | | } |
| | | //保存数据 |
| | | SysMenu menu = new SysMenu(); |
| | | menu.setName(name); |
| | | String uuid = DbUtils.getUUID(); |
| | | menu.setId(uuid); |
| | | menu.setParentId(parentId); |
| | | menu.setOrderNo(orderno); |
| | | menu.setDataType(MaintainDataType.parse(dataType)); |
| | | menu.setMenuType(menuType); |
| | | menu.setMenuType(menuType).setCreateTime(new Date()); |
| | | boolean inserted = menuService.insert(menu); |
| | | if (inserted) { |
| | | return Result.success("插入成功", null); |
| | | return Result.success(menu); |
| | | } else { |
| | | return Result.error(CodeMsg.INSERT_ERROR); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 添加数据主题 原先设计使用 |
| | | * @param id 主题id |
| | | * @param operateCode 参数类型 |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/add/version", method = RequestMethod.GET) |
| | | public Result insertAll(@RequestParam String id, @RequestParam String operateCode, HttpServletRequest request) { |
| | | SysMenu menu = menuService.selectById(id); |
| | |
| | | }else { |
| | | orderno = Integer.valueOf(ordernoStr); |
| | | } |
| | | menu = new SysMenu().setId(id).setParentId(parentId).setMenuType(menuType).setName(name).setOrderNo(orderno); |
| | | menu = new SysMenu().setCreateTime(new Date()).setId(id).setParentId(parentId).setMenuType(menuType).setName(name).setOrderNo(orderno); |
| | | menu.insert(); |
| | | } |
| | | |
| | | if (menu.getMenuType().equalsIgnoreCase(Constant.DataMenu)) { |
| | | Result<List<SysMenu>> listResult = menuByParentId(id); |
| | | List<SysMenu> data = listResult.getData(); |
| | | long count = data.stream().filter(sysMenu -> sysMenu.getDataType().equals(MaintainDataType.unkonwn)).count(); |
| | | if (count != data.size()) { |
| | | return Result.error(CodeMsg.SELECT_ERROR); |
| | | } |
| | | } |
| | | new SysMenu().setParentId(id).setId(DbUtils.getUUID()).setName(Constant.UnMatched).setOrderNo(1).setCreateTime(new Date()).setDataType(MaintainDataType.afterData).insert(); |
| | | new SysMenu().setParentId(id).setId(DbUtils.getUUID()).setName(Constant.Current).setOrderNo(2).setCreateTime(new Date()).setDataType(MaintainDataType.currentData).insert(); |
| | | new SysMenu().setParentId(id).setId(DbUtils.getUUID()).setName(Constant.History).setOrderNo(3).setCreateTime(new Date()).setDataType(MaintainDataType.beforeData).insert(); |
| | | |
| | | return Result.success(CodeMsg.SUCCESS); |
| | | return Result.success(menu); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 更新主题信息 |
| | | * @param id 主题id |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/update", method = RequestMethod.GET) |
| | | public Result<Object> update(@RequestParam String id, HttpServletRequest request) { |
| | | //获取主题数据 |
| | | SysMenu menu = menuService.selectById(id); |
| | | |
| | | if (menu == null) { |
| | | return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); |
| | | } |
| | | menu.setUpdateTime(new Date()); |
| | | String ordernoStr = request.getParameter("orderNo"); |
| | | String parentId = request.getParameter("parentId"); |
| | | String menuType = request.getParameter("menuType"); |
| | |
| | | return Result.error(CodeMsg.UPDATE_ERROR); |
| | | } |
| | | } |
| | | /** |
| | | * |
| | | * @description: 批量删除主题 |
| | | * @param parentId 父级主题 |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | private HashSet<SysMenu> deleteMenuByParentId(List<SysMenu> data, String parentId) { |
| | | HashSet<SysMenu> resultSet = new HashSet<>(); |
| | | for (SysMenu menu : data) { |
| | |
| | | result.addAll(resultSet); |
| | | return result; |
| | | } |
| | | /** |
| | | * |
| | | * @description: 通过id删除主题信息 |
| | | * @param menuid 主题id |
| | | * @return: 主题数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/delete/{menuid}", method = RequestMethod.GET) |
| | | public Result<Object> delete(@PathVariable String menuid) throws Exception { |
| | | public Result<Object> delete(@PathVariable String menuid, HttpServletRequest request) throws Exception { |
| | | Result<List<SysMenu>> all = getAll(); |
| | | List<SysMenu> data = all.getData(); |
| | | SysMenu parentMenu = menuService.selectById(menuid); |
| | | |
| | | HashSet<SysMenu> sysMenus = deleteMenuByParentId(data, menuid); |
| | | |
| | | for (SysMenu sysMenu : sysMenus) { |
| | | List<MenuMapping> menuMappingList = menuMappingService.selectList(new EntityWrapper<MenuMapping>().eq("menu_id", sysMenu.getId())); |
| | | for (MenuMapping menuMapping : menuMappingList) { |
| | | //若已经有主题生成 则添加到删除日志里 |
| | | DeletedTableLog deletedTableLog = new DeletedTableLog(); |
| | | deletedTableLog.setId(DbUtils.getUUID()).setTableName(menuMapping.getTableName()).setCreateTime(new Date()); |
| | | deletedTableLog.insert(); |
| | | menuMapping.deleteById(); |
| | | } |
| | | |
| | | sysMenu.deleteById(); |
| | | } |
| | | boolean delete = menuService.deleteById(menuid); |
| | | if (parentMenu == null) { |
| | | return Result.success(null); |
| | | } |
| | | String menuType = parentMenu.getMenuType(); |
| | | boolean delete = parentMenu.deleteById(); |
| | | if (delete) { |
| | | return Result.success(null); |
| | | } else { |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过parentid分页获取主题信息 |
| | | * @param parentid 父级主题id |
| | | * @param pageno : 页数 |
| | | * @return: 主题数据list |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/byParent/{parentid}/{pageno}", method = RequestMethod.GET) |
| | | public Result<Page<SysMenu>> menuByParentIdPage(@PathVariable String parentid, @PathVariable int pageno, HttpServletRequest request) throws Exception { |
| | | //pageSize 每页数据 |
| | | String pageSize = request.getParameter("pageSize"); |
| | | if (StringUtils.isEmpty(pageSize)) { |
| | | pageSize = "15"; |
| | |
| | | return Result.success(menuPage); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过parentid获取主题信息 |
| | | * @param parentid 父级主题id |
| | | * @return: 主题数据list |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/byParent/{parentid}", method = RequestMethod.GET) |
| | | public Result<List<SysMenu>> menuByParentId(@PathVariable String parentid) { |
| | | EntityWrapper<SysMenu> menuEntityWrapper = new EntityWrapper<>(); |
| | |
| | | List<SysMenu> sysMenus = menuService.selectList(menuEntityWrapper); |
| | | return Result.success(sysMenus); |
| | | } |
| | | |
| | | |
| | | } |