|
@@ -3,14 +3,20 @@ package com.backendsys.modules.material.service.impl;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.backendsys.exception.CustException;
|
|
|
import com.backendsys.modules.common.config.redis.utils.RedisUtil;
|
|
|
+import com.backendsys.modules.common.config.security.entity.SecurityUserInfo;
|
|
|
import com.backendsys.modules.common.config.security.utils.CaptchaUtil;
|
|
|
+import com.backendsys.modules.common.config.security.utils.JwtUtil;
|
|
|
import com.backendsys.modules.common.config.security.utils.LockStatusUtil;
|
|
|
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
|
import com.backendsys.modules.material.entity.MaterialAudit;
|
|
|
import com.backendsys.modules.material.entity.MaterialUser;
|
|
|
import com.backendsys.modules.material.service.MaterialUserService;
|
|
|
+import com.backendsys.modules.sse.entity.SseResponse;
|
|
|
+import com.backendsys.modules.sse.entity.SseResponseEnum;
|
|
|
+import com.backendsys.modules.sse.utils.SseUtil;
|
|
|
import com.backendsys.modules.system.dao.SysUserDao;
|
|
|
import com.backendsys.modules.system.dao.SysUserInfoDao;
|
|
|
import com.backendsys.modules.system.dao.SysUserRoleDao;
|
|
@@ -20,6 +26,7 @@ import com.backendsys.modules.system.service.SysAuthService;
|
|
|
import com.backendsys.modules.system.service.SysCommonService;
|
|
|
import com.backendsys.modules.system.service.SysUserIntegralService;
|
|
|
import com.backendsys.modules.system.service.SysUserService;
|
|
|
+import com.backendsys.modules.system.utils.UserUtil;
|
|
|
import com.backendsys.utils.response.PageEntity;
|
|
|
import com.backendsys.utils.response.PageInfoResult;
|
|
|
import com.backendsys.utils.v2.PageUtils;
|
|
@@ -40,6 +47,11 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class MaterialUserServiceImpl implements MaterialUserService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserUtil userUtil;
|
|
|
+ @Autowired
|
|
|
+ private SseUtil sseUtil;
|
|
|
+
|
|
|
@Value("${spring.application.name}")
|
|
|
private String APPLICATION_NAME;
|
|
|
@Value("${tencent.sms.debug}")
|
|
@@ -108,11 +120,11 @@ public class MaterialUserServiceImpl implements MaterialUserService {
|
|
|
public Map<String, Object> auditMaterialUser(MaterialAudit materialAudit) {
|
|
|
|
|
|
// 判断是否为素材用户 / 用户是否存在
|
|
|
- LambdaQueryWrapper<SysUserInfo> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(SysUserInfo::getUser_id, materialAudit.getUser_id());
|
|
|
- wrapper.eq(SysUserInfo::getInvite_code, "Material");
|
|
|
- SysUserInfo user_info_detail = sysUserInfoDao.selectOne(wrapper);
|
|
|
- if (user_info_detail == null) throw new CustException("用户不存在");
|
|
|
+ SysUserInfo entity = new SysUserInfo();
|
|
|
+ entity.setUser_id(materialAudit.getUser_id());
|
|
|
+ entity.setInvite_code("Material");
|
|
|
+ SysUserInfo userInfo = sysUserService.selectUserInfo(entity);
|
|
|
+ if (userInfo == null) throw new CustException("用户不存在");
|
|
|
|
|
|
// 判断用户是否待审核状态 (-1审核拒绝, 1待审核, 2审核通过)
|
|
|
if (materialAudit.getUser_id() == SecurityUtil.getUserId()) throw new CustException("不能审核自己");
|
|
@@ -123,10 +135,14 @@ public class MaterialUserServiceImpl implements MaterialUserService {
|
|
|
if (!role_ids.contains(materialAudit.getRole_id())) throw new CustException("必须指定素材用户角色");
|
|
|
|
|
|
// [DB] 更新用户信息-审核状态/用户状态
|
|
|
- SysUserInfo entity = new SysUserInfo();
|
|
|
- entity.setAudit_status(materialAudit.getAudit_status());
|
|
|
- entity.setStatus(materialAudit.getStatus());
|
|
|
- sysUserInfoDao.update(entity, wrapper);
|
|
|
+ LambdaQueryWrapper<SysUserInfo> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SysUserInfo::getUser_id, materialAudit.getUser_id());
|
|
|
+ wrapper.eq(SysUserInfo::getInvite_code, "Material");
|
|
|
+ //
|
|
|
+ userInfo.setAudit_status(materialAudit.getAudit_status());
|
|
|
+ userInfo.setAudit_note("素材管理审核通过");
|
|
|
+ userInfo.setStatus(materialAudit.getStatus());
|
|
|
+ sysUserInfoDao.update(userInfo, wrapper);
|
|
|
|
|
|
// 如果是禁用状态,则清除该用户的登录信息
|
|
|
if (materialAudit.getStatus() == -1) {
|
|
@@ -139,6 +155,45 @@ public class MaterialUserServiceImpl implements MaterialUserService {
|
|
|
sysUserRoleRelationDao.delete(wrapperRoleRelation);
|
|
|
sysUserRoleRelationDao.insertBatch(materialAudit.getUser_id(), Arrays.asList(materialAudit.getRole_id()));
|
|
|
|
|
|
+ /*
|
|
|
+ Token 解析结果:
|
|
|
+ Claims claims = jwtUtil.extractAllClaims(token);
|
|
|
+ {
|
|
|
+ "sub": "8fc878c1-0a67-4cd0-a0de-eced643e5546",
|
|
|
+ "userInfo": {
|
|
|
+ "id": 1,
|
|
|
+ "user_id": 1,
|
|
|
+ "username": "admin",
|
|
|
+ "last_login_uuid": "8fc878c1-0a67-4cd0-a0de-eced643e5546",
|
|
|
+ "is_super": -1,
|
|
|
+ "token_expiration": "2025-08-24 14:55:44",
|
|
|
+ "target": null,
|
|
|
+ "roles": [
|
|
|
+ {
|
|
|
+ "role_id": 4,
|
|
|
+ "role_sign": "MATERIAL_ADMIN",
|
|
|
+ "role_name": "素材库-管理员",
|
|
|
+ "login_default_page": "/material/materialList"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "target": "System",
|
|
|
+ "exp": 1756018544
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Redis Key:backendsys:local:login:token:8fc878c1-0a67-4cd0-a0de-eced643e5546
|
|
|
+ Redis Value:
|
|
|
+ "\"{\\\"token\\\":\\\"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI4ZmM4NzhjMS0wYTY3LTRjZDAtYTBkZS1lY2VkNjQzZTU1NDYiLCJ1c2VySW5mbyI6eyJpZCI6MSwidXNlcl9pZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsImxhc3RfbG9naW5fdXVpZCI6IjhmYzg3OGMxLTBhNjctNGNkMC1hMGRlLWVjZWQ2NDNlNTU0NiIsImlzX3N1cGVyIjotMSwidG9rZW5fZXhwaXJhdGlvbiI6IjIwMjUtMDgtMjQgMTQ6NTU6NDQiLCJ0YXJnZXQiOm51bGwsInJvbGVzIjpbeyJyb2xlX2lkIjo0LCJyb2xlX3NpZ24iOiJNQVRFUklBTF9BRE1JTiIsInJvbGVfbmFtZSI6Iue0oOadkOW6ky3nrqHnkIblkZgiLCJsb2dpbl9kZWZhdWx0X3BhZ2UiOiIvbWF0ZXJpYWwvbWF0ZXJpYWxMaXN0In1dfSwidGFyZ2V0IjoiU3lzdGVtIiwiZXhwIjoxNzU2MDE4NTQ0fQ.Mz9juWF2sqioaFMAdTJtcoTQONZFfCGDaRuibbVn2Mw\\\",\\\"permission_ids\\\":[\\\"1.1.2\\\",\\\"1.1.3\\\",\\\"1.1.6\\\",\\\"3.2.3.3\\\",\\\"3.5.1\\\",\\\"20\\\",\\\"20.1\\\",\\\"20.1.1\\\",\\\"20.1.2\\\",\\\"20.1.3\\\",\\\"20.1.4\\\",\\\"20.1.5\\\",\\\"20.2\\\",\\\"20.3\\\",\\\"20.4\\\",\\\"20.4.1\\\"]}\""
|
|
|
+
|
|
|
+
|
|
|
+ // SecurityUserInfo(id=1, user_id=1, username=admin, last_login_uuid=8fc878c1-0a67-4cd0-a0de-eced643e5546, is_super=-1, token_expiration=2025-08-24 14:55:44, target=null, roles=[{role_id=4, role_sign=MATERIAL_ADMIN, role_name=素材库-管理员, login_default_page=/material/materialList}])
|
|
|
+
|
|
|
+ */
|
|
|
+ // 实时更新:用户信息/角色/权限 (发送SSE)
|
|
|
+ userUtil.syncUpdateUserCatch(userInfo);
|
|
|
+ sseUtil.send(userInfo.getUser_id(), new SseResponse(SseResponseEnum.SYSTEM_USER_UPDATE, userInfo).toJsonStr());
|
|
|
+
|
|
|
return Map.of("user_id", materialAudit.getUser_id());
|
|
|
}
|
|
|
|