|
@@ -6,14 +6,13 @@ import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
|
|
import cn.hfln.framework.extension.BizException;
|
|
|
import cn.hfln.framework.redis.util.RedisUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.hfln.portal.common.constant.redis.RedisCacheConstant;
|
|
|
import com.hfln.portal.common.dto.DevInfoImportDto;
|
|
|
import com.hfln.portal.common.dto.data.device.DeviceDTO;
|
|
|
-import com.hfln.portal.common.request.admin.AdminAddParam;
|
|
|
-import com.hfln.portal.common.request.admin.AdminLoginParam;
|
|
|
-import com.hfln.portal.common.request.admin.AdminResetParam;
|
|
|
-import com.hfln.portal.common.request.admin.DeviceAddParam;
|
|
|
+import com.hfln.portal.common.dto.data.role.RoleListDTO;
|
|
|
+import com.hfln.portal.common.request.admin.*;
|
|
|
import com.hfln.portal.common.request.device.DeviceListQueryReq;
|
|
|
import com.hfln.portal.common.response.admin.AdminLoginRes;
|
|
|
import com.hfln.portal.common.vo.PageRecord;
|
|
@@ -25,16 +24,17 @@ import com.hfln.portal.domain.exception.ErrorEnum;
|
|
|
import com.hfln.portal.domain.gateway.AdminGateway;
|
|
|
import com.hfln.portal.domain.gateway.sms.SmsGateway;
|
|
|
import com.hfln.portal.infrastructure.config.UserAuthService;
|
|
|
-import com.hfln.portal.infrastructure.po.AdminUserInfo;
|
|
|
-import com.hfln.portal.infrastructure.po.BasePO;
|
|
|
-import com.hfln.portal.infrastructure.po.DevInfo;
|
|
|
+import com.hfln.portal.infrastructure.po.*;
|
|
|
import com.hfln.portal.infrastructure.service.AdminUserService;
|
|
|
import com.hfln.portal.infrastructure.service.DevInfoService;
|
|
|
+import com.hfln.portal.infrastructure.service.TblRoleService;
|
|
|
+import com.hfln.portal.infrastructure.service.TblUserRoleService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -64,6 +64,12 @@ public class AdminGatewayImpl implements AdminGateway {
|
|
|
@Autowired
|
|
|
private UserAuthService userAuthService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TblUserRoleService tblUserRoleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TblRoleService tblRoleService;
|
|
|
+
|
|
|
@Value("${sa-token.admin.timeout}")
|
|
|
private long adminTimeout;
|
|
|
|
|
@@ -220,15 +226,76 @@ public class AdminGatewayImpl implements AdminGateway {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void add(AdminAddParam param) {
|
|
|
-
|
|
|
+ @Transactional
|
|
|
+ public void addAccount(AdminAddParam param) {
|
|
|
+ // 1. 检查账号是否已存在
|
|
|
AdminUserInfo exist = adminUserService.queryByAccount(param.getAccount());
|
|
|
if (Objects.nonNull(exist)) {
|
|
|
throw new BizException(ErrorEnum.USER_ALREADY_EXISTS.getErrorCode(), ErrorEnum.USER_ALREADY_EXISTS.getErrorMessage());
|
|
|
}
|
|
|
-
|
|
|
+ //2.保存新用户到 admin_user_info 表
|
|
|
AdminUserInfo adminUserInfo = CopyUtils.copy(param, AdminUserInfo.class);
|
|
|
adminUserInfo.setPassword(PasswordUtil.encrypt(param.getPassword()));
|
|
|
adminUserService.save(adminUserInfo);
|
|
|
+
|
|
|
+ //3.保存用户角色到 tbl_user_role 表
|
|
|
+ TblUserRole userRole = new TblUserRole();
|
|
|
+ userRole.setUserId(adminUserInfo.getUserId());
|
|
|
+ userRole.setRoleId(param.getRoleId());
|
|
|
+ tblUserRoleService.save(userRole);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addRole(AddRoleParam param) {
|
|
|
+ //1.检查角色是否存在
|
|
|
+ TblRole exist = tblRoleService.queryByRoleCode(param.getRoleCode());
|
|
|
+ if (Objects.nonNull(exist)){
|
|
|
+ throw new BizException(ErrorEnum.ROLE_ALREADY_EXISTS.getErrorCode(), ErrorEnum.ROLE_ALREADY_EXISTS.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.保存角色信息
|
|
|
+ TblRole role = CopyUtils.copy(param, TblRole.class);
|
|
|
+ role.setIsDeleted(BasePO.DeleteFlag.NOT_DELETED);
|
|
|
+ tblRoleService.save(role);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void disableRole(String roleCode){
|
|
|
+ //1.判断roleCode非空
|
|
|
+ if (Objects.isNull(roleCode)){
|
|
|
+ throw new BizException(ErrorEnum.ROLE_CODE_NOT_NULL.getErrorCode(), ErrorEnum.ROLE_CODE_NOT_NULL.getErrorMessage());
|
|
|
+ }
|
|
|
+ TblRole role = tblRoleService.queryByRoleCode(roleCode);
|
|
|
+ //2.判断rolecode是否存在
|
|
|
+ if (role == null){
|
|
|
+ throw new BizException(ErrorEnum.ROLE_NOT_EXIST.getErrorCode(), ErrorEnum.ROLE_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //3.检查角色是否已经禁用
|
|
|
+ if (Objects.equals(role.getIsDeleted(), 1)){
|
|
|
+ throw new BizException(ErrorEnum.ROLE_ALREADY_DISABLED.getErrorCode(), ErrorEnum.ROLE_ALREADY_DISABLED.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //4.将对应数据is_deleted 字段置为1
|
|
|
+ role.setIsDeleted(BasePO.DeleteFlag.DELETED);
|
|
|
+ tblRoleService.updateById(role);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RoleListDTO> roleList() {
|
|
|
+ // 1. 查询所有未被删除的角色
|
|
|
+ LambdaQueryWrapper<TblRole> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(TblRole::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED);
|
|
|
+ List<TblRole> roleList = tblRoleService.list(queryWrapper);
|
|
|
+
|
|
|
+ // 2. 将TblRole转换为RoleListDTO
|
|
|
+ List<RoleListDTO> dtoList = roleList.stream().map(role -> {
|
|
|
+ RoleListDTO dto = new RoleListDTO();
|
|
|
+ dto.setRoleCode(role.getRoleCode());
|
|
|
+ dto.setRoleName(role.getRoleName());
|
|
|
+ return dto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return dtoList;
|
|
|
}
|
|
|
}
|