| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | 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.ximon.admin.param.ClientPrarm; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | 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.mapper.ClientMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.security.crypto.password.PasswordEncoder; |
| | |
| | | |
| | | private final ClientMapper clientMapper; |
| | | private final PasswordEncoder passwordEncoder; |
| | | private final ClientRoleRelationService clientRoleRelationService; |
| | | private final RoleService roleService; |
| | | |
| | | |
| | | public boolean addClient(AddClientPrarm addClientPrarm) { |
| | |
| | | throw new BusinessException("上级客户不存在"); |
| | | } |
| | | } |
| | | |
| | | Role role = roleService.getById(addClientPrarm.getRoleId()); |
| | | if (role == null) { |
| | | throw new BusinessException("角色不存在"); |
| | | } |
| | | if (!RoleLevelStatus.NORMAL.getCode().equals(role.getLevel())) { |
| | | throw new BusinessException("无法添加超级管理员或用户管理员"); |
| | | } |
| | | |
| | | |
| | | client.setClientName(addClientPrarm.getClientName()); |
| | | client.setLinkMan(addClientPrarm.getLinkMan()); |
| | | client.setMobile(addClientPrarm.getMobile()); |
| | | client.setClientSuperior(addClientPrarm.getClientSuperior()); |
| | | client.setPassword(passwordEncoder.encode(addClientPrarm.getPassword())); |
| | | boolean flag = save(client); |
| | | |
| | | ClientRoleRelation clientRoleRelation = new ClientRoleRelation(); |
| | | clientRoleRelation.setClientId(client.getId()); |
| | | clientRoleRelation.setRoleId(addClientPrarm.getRoleId()); |
| | | if (!clientRoleRelationService.save(clientRoleRelation)) { |
| | | throw new BusinessException("添加管理员角色失败"); |
| | | } |
| | | |
| | | return save(client); |
| | | return flag; |
| | | } |
| | | |
| | | |