| | |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.dao.bo.MenuNode; |
| | | import com.sandu.ximon.dao.domain.Client; |
| | | import com.sandu.ximon.dao.domain.ClientRoleRelation; |
| | | import com.sandu.ximon.dao.domain.Role; |
| | | import com.sandu.ximon.dao.domain.RoleMenuRelation; |
| | | import com.sandu.ximon.dao.domain.*; |
| | | import com.sandu.ximon.dao.enums.AdministratorEnums; |
| | | import com.sandu.ximon.dao.mapper.ClientMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.security.crypto.password.PasswordEncoder; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | return updateById(client); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteClient(Long id) { |
| | | boolean flag = false; |
| | | //判断删除用户是否存在 |
| | | Client one = getById(id); |
| | | if (one == null) { |
| | | Client client = getById(id); |
| | | if (client == null) { |
| | | throw new BusinessException("该客户不存在"); |
| | | } |
| | | |
| | | //只有超管能删除 或 上级客户删除自己的下级用户 |
| | | if (!AdministratorEnums.ADMIN.getCode().equals(SecurityUtils.getUserDetails().getAdministratorType())) { |
| | | Client temp = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getSuperiorId, SecurityUtils.getUserId()).eq(Client::getId, id)); |
| | | if (temp == null) { |
| | | throw new BusinessException("删除的用户不存在或该用户不是你的下级用户"); |
| | | } |
| | | } |
| | | |
| | | //判断删除的用户有无下级用户 |
| | |
| | | if (list != null && list.size() != 0) { |
| | | throw new BusinessException("删除的用户下有下级用户,不允许删除"); |
| | | } |
| | | |
| | | //管理员角色关系表 |
| | | ClientRoleRelationService clientRoleRelationService = SpringContextHolder.getBean(ClientRoleRelationService.class); |
| | | //有用户必定有用户与角色的关系数据 |
| | | ClientRoleRelation one = clientRoleRelationService.getOne(Wrappers.lambdaQuery(ClientRoleRelation.class).eq(ClientRoleRelation::getClientId, client.getId())); |
| | | |
| | | //删用户 |
| | | if (removeById(id)) { |
| | | //删角色关系表信息 |
| | | flag = clientRoleRelationService.removeById(one); |
| | | //删除失败回滚数据 |
| | | if (!flag) { |
| | | throw new BusinessException("删除用户失败!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除普通用户 日志记录开始 |
| | | */ |
| | | String content = "删除普通用户:" + one.getClientName() + "用户id:" + id; |
| | | String content = "删除普通用户:" + client.getClientName() + "用户id:" + id; |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "删除普通用户", content); |
| | | /** |
| | | * 删除普通用户 日志记录结束 |
| | | */ |
| | | |
| | | return removeById(id); |
| | | return flag; |
| | | } |
| | | |
| | | public List<Client> clientList(Long userId, BaseConditionVO baseConditionVO) { |