|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.config.mybatis.wrapper.NullFilterWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.MonitorPoint; | 
|---|
|  |  |  | import com.moral.api.entity.Organization; | 
|---|
|  |  |  | import com.moral.api.entity.User; | 
|---|
|  |  |  | import com.moral.api.mapper.MonitorPointMapper; | 
|---|
|  |  |  | 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.MonitorPointService; | 
|---|
|  |  |  | import com.moral.api.service.OrganizationService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.service.UserService; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | UserMapper userMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | MonitorPointService monitorPointService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, String> organizationFormMap; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //取参 | 
|---|
|  |  |  | Integer id = form.getOrganizationId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断组织是否含有站点 | 
|---|
|  |  |  | List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(id); | 
|---|
|  |  |  | if(!ObjectUtils.isEmpty(monitorPoints)){ | 
|---|
|  |  |  | dto.setCode(ResponseCodeEnum.ORGANIZATION_EXIST_MONITORPOINT.getCode()); | 
|---|
|  |  |  | dto.setMsg(ResponseCodeEnum.ORGANIZATION_EXIST_MONITORPOINT.getMsg()); | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询要删除的组织用于插入日志 | 
|---|
|  |  |  | Organization existOrganization = new Organization(); | 
|---|
|  |  |  | existOrganization.setIsDelete(Constants.NOT_DELETE); | 
|---|
|  |  |  | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //逻辑删除组织 | 
|---|
|  |  |  | UpdateWrapper deleteWrapper = new UpdateWrapper(); | 
|---|
|  |  |  | deleteWrapper.eq("id", id); | 
|---|
|  |  |  | deleteWrapper.set("is_delete", Constants.DELETE); | 
|---|
|  |  |  | organizationMapper.update(null, deleteWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除组织账号 | 
|---|
|  |  |  | userService.deleteUserByOrganizationId(id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断是否含有子组织 | 
|---|
|  |  |  | List<Organization> children = getAllChildrenOrganization(existOrganization.getId()); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(children)) {//如果含有子组织 | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(children)) { | 
|---|
|  |  |  | //判断是否删除所有子组织,如果不删除子组织则所有子组织全部变为无父组织,孙子组织不变 | 
|---|
|  |  |  | UpdateWrapper updateWrapper = new UpdateWrapper(); | 
|---|
|  |  |  | if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) {//删除所有子组织 | 
|---|
|  |  |  | 
|---|
|  |  |  | children.forEach(value -> { | 
|---|
|  |  |  | childrenId.add(value.getId()); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | //判断子组织是否含有站点,有一个子组织含有站点则不能删除 | 
|---|
|  |  |  | for (Integer childId : childrenId) { | 
|---|
|  |  |  | List<MonitorPoint> childMonitorPoints = monitorPointService.getMonitorPointsByOrganizationId(childId); | 
|---|
|  |  |  | if(!ObjectUtils.isEmpty(childMonitorPoints)){ | 
|---|
|  |  |  | dto.setCode(ResponseCodeEnum.CHILDREN_ORGANIZATION_EXIST_MONITORPOINT.getCode()); | 
|---|
|  |  |  | dto.setMsg(ResponseCodeEnum.CHILDREN_ORGANIZATION_EXIST_MONITORPOINT.getMsg()); | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //进行删除 | 
|---|
|  |  |  | updateWrapper.in("id", childrenId); | 
|---|
|  |  |  | updateWrapper.set("is_delete", Constants.DELETE); | 
|---|
|  |  |  | organizationMapper.update(null, updateWrapper); | 
|---|
|  |  |  | //删除所有子组织账号 | 
|---|
|  |  |  | childrenId.forEach(value->userService.deleteUserByOrganizationId(value)); | 
|---|
|  |  |  | childrenId.forEach(value->userService.deleteUsersByOrganizationId(value)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else {//不删除 | 
|---|
|  |  |  | //提取所有直属子组织id | 
|---|
|  |  |  | 
|---|
|  |  |  | organizationMapper.update(null, updateWrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //逻辑删除组织 | 
|---|
|  |  |  | UpdateWrapper deleteWrapper = new UpdateWrapper(); | 
|---|
|  |  |  | deleteWrapper.eq("id", id); | 
|---|
|  |  |  | deleteWrapper.set("is_delete", Constants.DELETE); | 
|---|
|  |  |  | organizationMapper.update(null, deleteWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除组织账号 | 
|---|
|  |  |  | userService.deleteUsersByOrganizationId(id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //封装返回结果 | 
|---|
|  |  |  | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | 
|---|
|  |  |  | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | dto.setOrganizationDTOS(organizationDTOS); | 
|---|
|  |  |  | dto.setCurrent(page.getCurrent()); | 
|---|
|  |  |  | dto.setPage(page.getPages()); | 
|---|
|  |  |  | dto.setPages(page.getPages()); | 
|---|
|  |  |  | dto.setSize(page.getSize()); | 
|---|
|  |  |  | dto.setTotal(page.getTotal()); | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | //查询所有组织 | 
|---|
|  |  |  | List<Organization> organizations = organizationMapper.selectList(queryWrapper); | 
|---|
|  |  |  | //判断form是否含有id,如果有则对所有组织进行过滤 | 
|---|
|  |  |  | //判断form是否含有id,如果有则对其所有子组织进行过滤 | 
|---|
|  |  |  | if(!ObjectUtils.isEmpty(id)){ | 
|---|
|  |  |  | List<Organization> children = getAllChildrenOrganization(id); | 
|---|
|  |  |  | List<Integer> thisAndchildrenIds = new ArrayList<>();//该id以及其所有子组织的id集合 | 
|---|