| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.config.mybatis.wrapper.NullFilterWrapper; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.entity.User; |
| | | import com.moral.api.mapper.OrganizationMapper; |
| | | import com.moral.api.mapper.UserMapper; |
| | | import com.moral.api.pojo.dto.organization.OrganizationDTO; |
| | | import com.moral.api.pojo.dto.organization.OrganizationQueryDTO; |
| | | import com.moral.api.pojo.dto.organization.OrganizationQueryNamesDTO; |
| | | import com.moral.api.pojo.form.organization.*; |
| | | import com.moral.api.service.OrganizationService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.api.util.LogUtils; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | import java.util.function.Predicate; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Autowired |
| | | LogUtils logUtils; |
| | | |
| | | @Autowired |
| | | UserService userService; |
| | | |
| | | @Autowired |
| | | UserMapper userMapper; |
| | | |
| | | Map<String, String> organizationFormMap; |
| | | |
| | |
| | | deleteWrapper.set("is_delete", Constants.DELETE); |
| | | organizationMapper.update(null, deleteWrapper); |
| | | |
| | | //删除组织账号 |
| | | userService.deleteUserByOrganizationId(id); |
| | | |
| | | //判断是否含有子组织 |
| | | List<Organization> children = getAllChildrenOrganization(existOrganization); |
| | | List<Organization> children = getAllChildrenOrganization(existOrganization.getId()); |
| | | if (!ObjectUtils.isEmpty(children)) {//如果含有子组织 |
| | | //判断是否删除所有子组织,如果不删除则所有子组织全部变为无父组织,孙子组织不变 |
| | | //判断是否删除所有子组织,如果不删除子组织则所有子组织全部变为无父组织,孙子组织不变 |
| | | UpdateWrapper updateWrapper = new UpdateWrapper(); |
| | | if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) {//删除所有子组织 |
| | | //获取所有子组织的id封装为集合 |
| | |
| | | updateWrapper.in("id", childrenId); |
| | | updateWrapper.set("is_delete", Constants.DELETE); |
| | | organizationMapper.update(null, updateWrapper); |
| | | //删除所有子组织账号 |
| | | childrenId.forEach(value->userService.deleteUserByOrganizationId(value)); |
| | | |
| | | } else {//不删除 |
| | | //提取所有直属子组织id |
| | | List<Integer> childrenId = new ArrayList<>(); |
| | |
| | | organizationMapper.update(null, updateWrapper); |
| | | } |
| | | } |
| | | |
| | | //删除组织对应账号 |
| | | |
| | | //封装返回结果 |
| | | dto.setOrganization(existOrganization); |
| | |
| | | Page<Organization> resultPage = organizationMapper.selectPage(page, queryWrapper); |
| | | List<Organization> organizations = resultPage.getRecords(); |
| | | List<OrganizationDTO> organizationDTOS = new ArrayList<>(); |
| | | //查找所有组织的父组织并且封装organization到DTO中 |
| | | for (Organization child : organizations) { |
| | | //查找所有组织的父组织和admin账号并且封装organization到DTO中 |
| | | for (Organization organization : organizations) { |
| | | OrganizationDTO resultDto = new OrganizationDTO(); |
| | | Organization parent = organizationMapper.selectById(child.getParentId());//查找父组织 |
| | | resultDto.setOrganization(child); |
| | | //查找父组织 |
| | | Organization parent = organizationMapper.selectById(organization.getParentId()); |
| | | resultDto.setOrganization(organization); |
| | | resultDto.setParentOrganization(parent); |
| | | //查找admin账号 |
| | | QueryWrapper userWrapper = new QueryWrapper(); |
| | | User adminUser = new User(); |
| | | adminUser.setIsAdmin(true); |
| | | adminUser.setOrganizationId(organization.getId()); |
| | | adminUser.setIsDelete(Constants.NOT_DELETE); |
| | | userWrapper.setEntity(adminUser); |
| | | adminUser = userMapper.selectOne(userWrapper); |
| | | resultDto.setAdminUser(adminUser); |
| | | organizationDTOS.add(resultDto); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * @Description: 查询所有组织的名称和Id |
| | | * @Param: [] |
| | | * @return: com.moral.api.pojo.dto.organization.OrganizationQueryNameDTO |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/4/13 |
| | | */ |
| | | * @Description: 如果form中id为空,则查询所有的组织 |
| | | * 如果id不为空,则查询该id和该id所有子组织之外的所有组织 |
| | | * @Param: [from] |
| | | * @return: com.moral.api.pojo.dto.organization.OrganizationQueryNamesDTO |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/5/7 |
| | | */ |
| | | @Override |
| | | public OrganizationQueryNamesDTO queryNames(OrganizationQueryNamesForm from) { |
| | | public OrganizationQueryNamesDTO queryNames(OrganizationQueryNamesForm form) { |
| | | OrganizationQueryNamesDTO dto = new OrganizationQueryNamesDTO(); |
| | | //取参 |
| | | Integer id = form.getId(); |
| | | //构造查询条件 |
| | | QueryWrapper<Organization> queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | //查询 |
| | | //查询所有组织 |
| | | List<Organization> organizations = organizationMapper.selectList(queryWrapper); |
| | | |
| | | //判断form是否含有id,如果有则对所有组织进行过滤 |
| | | if(!ObjectUtils.isEmpty(id)){ |
| | | List<Organization> children = getAllChildrenOrganization(id); |
| | | List<Integer> thisAndchildrenIds = new ArrayList<>();//该id以及其所有子组织的id集合 |
| | | thisAndchildrenIds.add(id); |
| | | for (Organization child : children) { |
| | | thisAndchildrenIds.add(child.getId()); |
| | | } |
| | | organizations.removeIf(new Predicate<Organization>() {//过滤 |
| | | @Override |
| | | public boolean test(Organization organization) { |
| | | if(thisAndchildrenIds.contains(organization.getId())) |
| | | return true; |
| | | return false; |
| | | } |
| | | }); |
| | | } |
| | | //封装返回对象 |
| | | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/4/14 |
| | | */ |
| | | private List<Organization> getAllChildrenOrganization(Organization parent) { |
| | | private List<Organization> getAllChildrenOrganization(Integer parentId) { |
| | | List<Organization> children = new ArrayList<>(); |
| | | recursionQueryChildren(parent, children); |
| | | recursionQueryChildren(parentId, children); |
| | | return children; |
| | | } |
| | | |
| | |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/4/14 |
| | | */ |
| | | private void recursionQueryChildren(Organization parent, List<Organization> children) { |
| | | Integer parentId = parent.getId(); |
| | | private void recursionQueryChildren(Integer parentId, List<Organization> children) { |
| | | QueryWrapper<Organization> queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | queryWrapper.eq("parent_id", parentId); |
| | |
| | | if (!ObjectUtils.isEmpty(organizations)) { |
| | | children.addAll(organizations); |
| | | for (Organization organization : organizations) { |
| | | recursionQueryChildren(organization, children); |
| | | recursionQueryChildren(organization.getId(), children); |
| | | } |
| | | } else { |
| | | return; |