2021与蓝度共同重构项目,服务端
liuhaonan
2022-10-25 dda268997ca8f8a364f7c19b45d7a43a50a98efe
ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java
@@ -3,10 +3,8 @@
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.enums.RoleLevelStatus;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.redis.RedisService;
import com.sandu.common.security.LoginUserInfo;
import com.sandu.common.security.token.TokenProvider;
@@ -32,7 +30,6 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.ArrayList;
import java.util.Collection;
@@ -52,7 +49,11 @@
    public boolean addClient(AddClientPrarm addClientPrarm) {
        if (getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, addClientPrarm.getClientName().trim())) != null) {
            throw new BusinessException("该用户名已存在!");
            throw new BusinessException("该用户名已在客户中存在!");
        }
        Admin admin = SpringContextHolder.getBean(AdminService.class).findByUserName(addClientPrarm.getClientName());
        if (admin != null) {
            throw new BusinessException("当前账号" + addClientPrarm.getClientName() + "已经在管理员中存在");
        }
        Long userId = SecurityUtils.getUserId();
        boolean clientId = findClientId();
@@ -256,6 +257,27 @@
        if (removeById(id)) {
            //删角色关系表信息
            flag = clientRoleRelationService.removeById(one);
            List<Pole> poles = SpringContextHolder.getBean(PoleService.class).list(Wrappers.lambdaQuery(Pole.class).eq(Pole::getClientId, id));
            poles.forEach(
                    pole -> {
                        pole.setClientId(-1L);
                        pole.setUserId(-1L);
                    }
            );
            //删除用户后需要自动解绑该用户的设备
            //灯杆id集合
            List<Long> collect = poles.stream().map(p -> p.getId()).collect(Collectors.toList());
            List<Long> collect1 = poles.stream().map(Pole::getId).collect(Collectors.toList());
            //删除绑定关系
            SpringContextHolder.getBean(PoleBindingService.class)
                    .remove(Wrappers.lambdaQuery(PoleBinding.class)
                            .in(PoleBinding::getPoleId, collect));
            //更改灯杆归属
            flag = SpringContextHolder.getBean(PoleService.class).updateBatchById(poles);
            //删除失败回滚数据
            if (!flag) {
                throw new BusinessException("删除用户失败!");
@@ -388,7 +410,7 @@
    /**
     * \
     * 其他类用来查找客户id使用  如果没有上级客户 这返回用户ID
     * 其他类用来查找客户id使用  如果没有上级客户 返回-1
     *
     * @param
     * @return
@@ -398,7 +420,7 @@
        if (one != null && one.getSuperiorId() != null) {
            return one.getSuperiorId();
        } else {
            return userId;
            return -1L;
        }
    }