|
@@ -1,21 +1,28 @@
|
|
|
package com.backendsys.modules.material.service.impl;
|
|
|
|
|
|
+import com.backendsys.exception.CustException;
|
|
|
+import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
|
+import com.backendsys.modules.material.entity.MaterialAudit;
|
|
|
import com.backendsys.modules.material.service.MaterialUserService;
|
|
|
import com.backendsys.modules.system.dao.SysUserDao;
|
|
|
import com.backendsys.modules.system.dao.SysUserInfoDao;
|
|
|
import com.backendsys.modules.system.dao.SysUserRoleDao;
|
|
|
+import com.backendsys.modules.system.dao.SysUserRoleRelationDao;
|
|
|
import com.backendsys.modules.system.entity.SysUserDTO;
|
|
|
import com.backendsys.modules.system.entity.SysUserInfo;
|
|
|
import com.backendsys.modules.system.entity.SysUserRole;
|
|
|
+import com.backendsys.modules.system.entity.SysUserRoleRelation;
|
|
|
import com.backendsys.utils.response.PageEntity;
|
|
|
import com.backendsys.utils.response.PageInfoResult;
|
|
|
import com.backendsys.utils.v2.PageUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class MaterialUserServiceImpl implements MaterialUserService {
|
|
@@ -26,6 +33,8 @@ public class MaterialUserServiceImpl implements MaterialUserService {
|
|
|
private SysUserInfoDao sysUserInfoDao;
|
|
|
@Autowired
|
|
|
private SysUserRoleDao sysUserRoleDao;
|
|
|
+ @Autowired
|
|
|
+ private SysUserRoleRelationDao sysUserRoleRelationDao;
|
|
|
|
|
|
/**
|
|
|
* 获取素材用户列表 ({ invite_code = Material })
|
|
@@ -46,6 +55,7 @@ public class MaterialUserServiceImpl implements MaterialUserService {
|
|
|
/**
|
|
|
* 获取素材用户角色列表
|
|
|
*/
|
|
|
+ @Override
|
|
|
public List<SysUserRole> selectMaterialUserRoleList() {
|
|
|
LambdaQueryWrapper<SysUserRole> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.likeRight(SysUserRole::getRole_sign, "MATERIAL");
|
|
@@ -54,4 +64,42 @@ public class MaterialUserServiceImpl implements MaterialUserService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 审核素材用户
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ 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("用户不存在");
|
|
|
+
|
|
|
+ // 判断用户是否待审核状态 (-1审核拒绝, 1待审核, 2审核通过)
|
|
|
+// Integer audit_status = user_info_detail.getAudit_status();
|
|
|
+// if (audit_status == 2) throw new CustException("用户已通过审核");
|
|
|
+ if (materialAudit.getUser_id() == SecurityUtil.getUserId()) throw new CustException("不能审核自己");
|
|
|
+
|
|
|
+ // [DB] 获取素材用户角色ID集合
|
|
|
+ List<SysUserRole> role_list = selectMaterialUserRoleList();
|
|
|
+ List<Long> role_ids = role_list.stream().map(SysUserRole::getRole_id).toList();
|
|
|
+ if (!role_ids.contains(materialAudit.getRole_id())) throw new CustException("必须指定素材用户角色");
|
|
|
+
|
|
|
+ // [DB] 更新用户信息-审核状态
|
|
|
+ SysUserInfo entity = new SysUserInfo();
|
|
|
+ entity.setAudit_status(materialAudit.getAudit_status());
|
|
|
+ sysUserInfoDao.update(entity, wrapper);
|
|
|
+
|
|
|
+ // [DB] 更新用户与角色关系 (先删,后增)
|
|
|
+ LambdaQueryWrapper<SysUserRoleRelation> wrapperRoleRelation = new LambdaQueryWrapper<>();
|
|
|
+ wrapperRoleRelation.eq(SysUserRoleRelation::getUser_id, materialAudit.getUser_id());
|
|
|
+ sysUserRoleRelationDao.delete(wrapperRoleRelation);
|
|
|
+ sysUserRoleRelationDao.insertBatch(materialAudit.getUser_id(), Arrays.asList(materialAudit.getRole_id()));
|
|
|
+
|
|
|
+ return Map.of("user_id", materialAudit.getUser_id());
|
|
|
+ }
|
|
|
+
|
|
|
}
|