| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | 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.service.impl.BaseServiceImpl; |
| | | import com.sandu.common.util.IpUtil; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.dto.ClientDto; |
| | | import com.sandu.ximon.admin.dto.ClientDtoNode; |
| | | import com.sandu.ximon.admin.param.AddClientPrarm; |
| | | import com.sandu.ximon.admin.param.PwdParam; |
| | | import com.sandu.ximon.admin.param.UpdateClientPrarm; |
| | |
| | | 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.enums.OrderByEnums; |
| | | import com.sandu.ximon.dao.mapper.ClientMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.security.core.GrantedAuthority; |
| | | 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; |
| | |
| | | @AllArgsConstructor |
| | | public class ClientService extends BaseServiceImpl<ClientMapper, Client> { |
| | | |
| | | private final ClientMapper clientMapper; |
| | | private final PasswordEncoder passwordEncoder; |
| | | private final ClientRoleRelationService clientRoleRelationService; |
| | | private final RoleService roleService; |
| | |
| | | return flag; |
| | | } |
| | | |
| | | public List<Client> clientList(Long userId, BaseConditionVO baseConditionVO) { |
| | | return clientMapper.clientList(userId, baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | /** |
| | | * 用户列表 |
| | | * |
| | | * @param keyword |
| | | * @param order |
| | | * @param seq |
| | | * @return |
| | | */ |
| | | public List<ClientDtoNode> listLikeClient(String keyword, Integer order, Integer seq) { |
| | | |
| | | |
| | | LambdaQueryWrapper<Client> wrapper = Wrappers.lambdaQuery(Client.class); |
| | | if (AdministratorEnums.NORMAL.getCode().equals(SecurityUtils.getAdministratorIdentity())) { |
| | | wrapper.eq(Client::getSuperiorId, SecurityUtils.getUserId()).or(w -> w.eq( |
| | | Client::getId, SecurityUtils.getUserId() |
| | | )); |
| | | } |
| | | if (keyword != null && !keyword.isEmpty()) { |
| | | wrapper.like(Client::getClientName, keyword) |
| | | .or(w1 -> w1.like(Client::getMobile, keyword)) |
| | | .or(w2 -> w2.like(Client::getLinkMan, keyword)); |
| | | } |
| | | //排序字段 |
| | | String orderByResult = "id"; |
| | | //正序、倒叙 |
| | | String orderBySeq = OrderByEnums.ASC.getCode(); |
| | | if (order != null) { |
| | | switch (order) { |
| | | case 1: |
| | | orderByResult = OrderByEnums.CLIENT_CREATE_TIME.getCode(); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | if (seq != null) { |
| | | switch (seq) { |
| | | case 1: |
| | | orderBySeq = OrderByEnums.ASC.getCode(); |
| | | break; |
| | | case 2: |
| | | orderBySeq = OrderByEnums.DESC.getCode(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | //排序方式 |
| | | String orderBy = orderByResult + " " + orderBySeq; |
| | | |
| | | // if (baseConditionVO != null) { |
| | | // PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy); |
| | | // } |
| | | |
| | | List<Client> clientList = list(wrapper); |
| | | |
| | | List<ClientDto> clientDtoList = new ArrayList<>(); |
| | | for (Client demo : clientList) { |
| | | ClientDto clientDto = new ClientDto(); |
| | | BeanUtil.copyProperties(demo, clientDto); |
| | | ClientRoleRelation one = clientRoleRelationService.getOne(Wrappers.lambdaQuery(ClientRoleRelation.class) |
| | | .eq(ClientRoleRelation::getClientId, demo.getId())); |
| | | |
| | | if (one != null) { |
| | | clientDto.setRoleId(one.getRoleId()); |
| | | } |
| | | clientDtoList.add(clientDto); |
| | | } |
| | | |
| | | return clientDtoList.stream() |
| | | .filter(bean -> null == bean.getSuperiorId()) |
| | | .map(bean -> covertClientDtoNode(bean, clientDtoList)).collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | | * 数据整理成树状图 |
| | | * |
| | | * @param clientDto |
| | | * @param clientDtoList |
| | | * @return |
| | | */ |
| | | private ClientDtoNode covertClientDtoNode(ClientDto clientDto, List<ClientDto> clientDtoList) { |
| | | ClientDtoNode node = new ClientDtoNode(); |
| | | BeanUtils.copyProperties(clientDto, node); |
| | | List<ClientDtoNode> children = clientDtoList.stream() |
| | | .filter(subClientDto -> (subClientDto.getSuperiorId() != null && subClientDto.getSuperiorId().equals(clientDto.getId()))) |
| | | .map(subClientDto -> covertClientDtoNode(subClientDto, clientDtoList)).collect(Collectors.toList()); |
| | | node.setChildren(children); |
| | | return node; |
| | | } |
| | | |
| | | public Client findByPhone(String phone) { |