| | |
| | | package com.highdatas.mdm.controller; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.highdatas.mdm.entity.MasterAuthor; |
| | | import com.highdatas.mdm.entity.MasterAuthorDetail; |
| | | import com.highdatas.mdm.entity.TUser; |
| | | import com.highdatas.mdm.entity.TUserRole; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.highdatas.mdm.entity.*; |
| | | import com.highdatas.mdm.pojo.CodeMsg; |
| | | import com.highdatas.mdm.pojo.MasterAuthorType; |
| | | import com.highdatas.mdm.pojo.Result; |
| | | import com.highdatas.mdm.service.IMasterAuthorDetailService; |
| | | import com.highdatas.mdm.service.IMasterAuthorService; |
| | | import com.highdatas.mdm.service.ITUserRoleService; |
| | | import com.highdatas.mdm.service.*; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | IMasterAuthorDetailService authorDetailService; |
| | | @Autowired |
| | | ITUserRoleService userRoleService; |
| | | @Autowired |
| | | IMenuMappingService menuMappingService; |
| | | @Autowired |
| | | ISysMenuService menuService; |
| | | |
| | | public static final String masterAuthorType = "masterAuthorType"; |
| | | public static final String masterId = "masterId"; |
| | | public static final String tableName = "table_name"; |
| | | public static final String characterId = "characterId"; |
| | | public static final String character_id = "character_id"; |
| | | public static final String fields = "fields"; |
| | | private String maintainFieldId = "maintainFieldId"; |
| | | private String maintain_field_id = "maintain_field_id"; |
| | | |
| | | @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST) |
| | | public Result deleteModel(@RequestBody MasterAuthor masterAuthor) { |
| | |
| | | }else { |
| | | masterAuthor.setId(DbUtils.getUUID()).setCreateTime(new Date()); |
| | | } |
| | | |
| | | String menuId = masterAuthor.getMenuId(); |
| | | String tableName = menuMappingService.getTableNameByMenu(menuId); |
| | | masterAuthor.setTableName(tableName); |
| | | //delete pre |
| | | boolean delete = authorDetailService.delete(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId())); |
| | | if (!delete){ |
| | |
| | | }else { |
| | | return Result.error(CodeMsg.UPDATE_ERROR); |
| | | } |
| | | |
| | | } |
| | | |
| | | @RequestMapping(value = "/get/{characterId}", method = RequestMethod.GET) |
| | |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | }else if (type.equals(MasterAuthorType.user) && masterAuthorList.isEmpty()){ |
| | | //user 获取角色 多脚色混合 |
| | | TUser user = DbUtils.getUser(request); |
| | | String userId = user.getUserId(); |
| | | String userId = characterId; |
| | | List<TUserRole> tUserRoles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq(Constant.USERID, userId)); |
| | | List<String> roleIdList = tUserRoles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList()); |
| | | return authorService.merageRoleAuthor(roleIdList); |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdList); |
| | | if (tableMasterAuthor == null) { |
| | | Result.success(null); |
| | | } |
| | | JSONObject object = new JSONObject(); |
| | | ArrayList<MasterAuthor> list = new ArrayList(tableMasterAuthor.values()); |
| | | |
| | | object.fluentPut("type", MasterAuthorType.role); |
| | | object.fluentPut("author",list); |
| | | |
| | | Set<String> collect = list.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toSet()); |
| | | LinkedHashSet<String> menuIds= new LinkedHashSet<>(collect); |
| | | LinkedHashSet<String> byParentId = menuService.getByParentId(menuIds); |
| | | List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId); |
| | | object.fluentPut("audit",sysMenus); |
| | | return Result.success(object); |
| | | } |
| | | |
| | | for (MasterAuthor masterAuthor : masterAuthorList) { |
| | |
| | | masterAuthor.setFields(masterAuthorDetails); |
| | | } |
| | | |
| | | return Result.success(masterAuthorList); |
| | | JSONObject object = new JSONObject(); |
| | | Set<String> collect = masterAuthorList.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toSet()); |
| | | LinkedHashSet<String> menuIds= new LinkedHashSet<>(collect); |
| | | LinkedHashSet<String> byParentId = menuService.getByParentId(menuIds); |
| | | List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId); |
| | | |
| | | object.fluentPut("type", MasterAuthorType.user); |
| | | object.fluentPut("author",masterAuthorList); |
| | | object.fluentPut("audit",sysMenus); |
| | | return Result.success(object); |
| | | } |
| | | |
| | | @RequestMapping(value = "/delete/{characterId}", method = RequestMethod.GET) |
| | | public Result delete(@PathVariable String characterId, @RequestParam MasterAuthorType type){ |
| | | List<MasterAuthor> masterAuthorList = authorService.selectList(new EntityWrapper<MasterAuthor>() |
| | | .eq(Constant.TYPE, type).eq(this.characterId, characterId)); |
| | | .eq(Constant.TYPE, type).eq(this.character_id, characterId)); |
| | | if (masterAuthorList.isEmpty()) { |
| | | return Result.success(null); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/delete/menu/{menuId}", method = RequestMethod.GET) |
| | | public Result deleteTable(@PathVariable String menuId, @RequestParam String characterId, @RequestParam MasterAuthorType type, HttpServletRequest request){ |
| | | String maintainFieldId = request.getParameter(this.maintainFieldId); |
| | | Wrapper<MasterAuthor> masterAuthorWrapper = new EntityWrapper<MasterAuthor>() |
| | | .eq(Constant.TYPE, type) |
| | | .eq(character_id, characterId) |
| | | .eq("menu_id", menuId); |
| | | if (!StringUtils.isEmpty(maintainFieldId)) { |
| | | masterAuthorWrapper.eq(this.maintain_field_id, maintainFieldId); |
| | | } |
| | | |
| | | List<MasterAuthor> masterAuthorList = authorService.selectList(masterAuthorWrapper); |
| | | if (masterAuthorList.isEmpty()) { |
| | | return Result.success(null); |
| | | } |
| | | boolean partDel = false; |
| | | if (masterAuthorList.size() == 1 && !StringUtils.isEmpty(maintainFieldId)) { |
| | | // 只有一个且删除 字段版本 保留本条 |
| | | partDel = true; |
| | | } |
| | | boolean delete = false; |
| | | for (MasterAuthor masterAuthor : masterAuthorList) { |
| | | delete = authorDetailService.delete(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId())); |
| | | if (delete) { |
| | | if (partDel) { |
| | | delete = masterAuthor.setMaintainFieldId(null).updateById(); |
| | | }else { |
| | | delete = masterAuthor.deleteById(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | if (delete) { |
| | | return Result.success(CodeMsg.DELETE_SUCCESS); |
| | | }else { |
| | | return Result.error(CodeMsg.DELETE_ERROR); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/addRole/{roleId}", method = RequestMethod.GET) |
| | | public Result addRole(@PathVariable String roleId, HttpServletRequest request){ |
| | | TUser user = DbUtils.getUser(request); |
| | |
| | | List<String> roleIdList = tUserRoles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList()); |
| | | roleIdList.add(roleId); |
| | | |
| | | return authorService.merageRoleAuthor(roleIdList); |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdList); |
| | | if (tableMasterAuthor == null) { |
| | | Result.success(null); |
| | | } |
| | | return Result.success(tableMasterAuthor.values()); |
| | | } |
| | | } |