| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.lang.Snowflake; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.enums.RoleLevelStatus; |
| | |
| | | import com.sandu.ximon.admin.param.PwdParam; |
| | | import com.sandu.ximon.admin.param.UserPwsParm; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.security.authcode.MD5Util; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.dao.bo.AdminBo; |
| | | import com.sandu.ximon.dao.bo.MenuNode; |
| | | import com.sandu.ximon.dao.domain.Admin; |
| | | import com.sandu.ximon.dao.domain.AdminRoleRelation; |
| | | 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.AdminMapper; |
| | |
| | | private final AdminRoleRelationService adminRoleRelationService; |
| | | private final RoleService roleService; |
| | | private AdminMapper adminMapper; |
| | | private Snowflake snowflake; |
| | | |
| | | public Admin findByUserName(String username) { |
| | | return getOne(Wrappers.lambdaQuery(Admin.class).eq(Admin::getUsername, username).last("limit 1")); |
| | |
| | | public boolean register(AdminParam param) { |
| | | Admin admin = findByUserName(param.getUsername()); |
| | | if (admin != null) { |
| | | throw new BusinessException("当前账号" + param.getUsername() + "已经存在"); |
| | | throw new BusinessException("当前账号" + param.getUsername() + "已经在管理员中存在"); |
| | | } |
| | | Client one = SpringContextHolder.getBean(ClientService.class).getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, param.getUsername())); |
| | | if (one != null) { |
| | | throw new BusinessException("当前账号" + param.getUsername() + "已经在客户中存在"); |
| | | } |
| | | Admin save = new Admin(); |
| | | save.setId(snowflake.nextId()); |
| | | save.setUsername(param.getUsername()); |
| | | save.setPassword(passwordEncoder.encode(param.getPassword())); |
| | | save.setNickName(param.getNickName()); |
| | |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 生成key |
| | | * |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | public String creatUserKey(Long userId, Integer type) { |
| | | if (userId == null) { |
| | | throw new BusinessException("用户ID不能为空!"); |
| | | } |
| | | //0:充重置key,1:获取key |
| | | if (type == null || (type != 0 && type != 1)) { |
| | | type = 1; |
| | | } |
| | | |
| | | ClientService clientService = SpringContextHolder.getBean(ClientService.class); |
| | | Client client = clientService.getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, userId)); |
| | | if (client == null) { |
| | | throw new BusinessException("用户不存在,请重新确认!"); |
| | | } |
| | | |
| | | /** |
| | | * key操作日志 |
| | | */ |
| | | String content = "操作用户key:" + SecurityUtils.getUsername() + " 被操作用户id:" + userId; |
| | | |
| | | |
| | | //获取 |
| | | if (type == 1) { |
| | | content += "操作类型:获取key"; |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "操作用户key", content); |
| | | return "用户的便捷登录key为:" + client.getUserKey(); |
| | | } else { |
| | | //更新 |
| | | String md5 = MD5Util.md5("uesrId:" + userId + "_AdministratorType:" + 2 + "time:" + System.currentTimeMillis()); |
| | | client.setUserKey(md5); |
| | | boolean flag = clientService.updateById(client); |
| | | if (flag) { |
| | | content += "操作类型:生成key,新的key为:" + md5; |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "操作用户key", content); |
| | | return "生成便捷登录key成功,该用户key为:" + md5 + ",请妥善保管!"; |
| | | } else { |
| | | throw new BusinessException("生成便捷登录key失败!"); |
| | | } |
| | | } |
| | | } |
| | | } |