2021与蓝度共同重构项目,服务端
MercuryZ
2022-03-31 ef270bd1855b5ce3f398c5df024840a498e33a8f
ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java
@@ -7,6 +7,7 @@
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.param.AddClientPrarm;
import com.sandu.ximon.admin.param.ResetClientPasswordPrarm;
import com.sandu.ximon.admin.param.UpdateClientPrarm;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.Client;
@@ -14,6 +15,7 @@
import com.sandu.ximon.dao.domain.Role;
import com.sandu.ximon.dao.mapper.ClientMapper;
import lombok.AllArgsConstructor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
@@ -39,7 +41,11 @@
        if (addClientPrarm.getClientSuperior() != null && !"".equals(addClientPrarm.getClientSuperior())) {
            Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, addClientPrarm.getClientSuperior()));
            if (one != null) {
                client.setSuperiorId(one.getId());
                if (one.getSuperiorId() == null) {
                    client.setSuperiorId(one.getId());
                } else {
                    throw new BusinessException("上级客户不能为二级用户");
                }
            } else {
                throw new BusinessException("上级客户不存在");
            }
@@ -108,6 +114,25 @@
        return updateById(client);
    }
    public boolean resetPassword(ResetClientPasswordPrarm resetClientPasswordPrarm) {
        Client client = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, resetClientPasswordPrarm.getId()));
        if (client == null) {
            throw new BusinessException("该用户不存在!");
        }
        PasswordEncoder pw = new BCryptPasswordEncoder();
        //判断旧密码与数据库是否一致
        if (pw.matches(resetClientPasswordPrarm.getOldPassword(), client.getPassword())) {
            //加密新密码
            String encode = pw.encode(resetClientPasswordPrarm.getNewPassword());
            client.setPassword(encode);
            return updateById(client);
        } else {
            throw new BusinessException("旧密码不正确,请重新确认密码!");
        }
    }
    public boolean deleteClient(Long id) {
        //判断删除用户是否存在
        Client one = getById(id);
@@ -152,6 +177,23 @@
    }
    /**
     * \
     * 其他类用来查找客户id使用  如果没有上级客户 这返回用户ID
     *
     * @param
     * @return
     */
    public Long getClientId(Long userId) {
        Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, userId));
        if (one != null && one.getSuperiorId() != null) {
            return one.getSuperiorId();
        } else {
            return userId;
        }
    }
    /**
     * 一级客户返回false  二级客户返回true
     *
     * @return
@@ -166,4 +208,18 @@
        }
    }
    /**
     * 一级客户返回false  二级客户返回true
     *
     * @return
     */
    public boolean findClientId(Long userId) {
        Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, userId));
        if (one != null && one.getSuperiorId() != null) {
            return true;
        } else {
            return false;
        }
    }
}