APP修改管理员 新增店铺运维人员角色控制

This commit is contained in:
SjS 2025-05-16 11:35:09 +08:00
parent 0ac82d9da0
commit 8174f55648
8 changed files with 76 additions and 36 deletions

View File

@ -14,5 +14,7 @@ public class RoleConstants {
public static final String MCH = "mch";
// 运维人员
public static final String STAFF = "staff";
// APP 管理员
public static final String APP_ADMIN = "app_admin";
}

View File

@ -7,9 +7,14 @@ import com.ruoyi.bst.app.domain.vo.AppAllVO;
import com.ruoyi.bst.app.mapper.AppMapper;
import com.ruoyi.bst.app.service.AppService;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.constant.RoleConstants;
import com.ruoyi.common.core.domain.entity.Role;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.system.role.mapper.RoleMapper;
import com.ruoyi.system.role.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
@ -24,8 +29,8 @@ import java.util.List;
* @date 2025-01-08
*/
@Service
public class AppServiceImpl implements AppService
{
@Slf4j
public class AppServiceImpl implements AppService {
@Autowired
private AppMapper appMapper;
@ -34,6 +39,12 @@ public class AppServiceImpl implements AppService
@Autowired
private TransactionTemplate transactionTemplate;
@Autowired
private RoleService roleService;
@Autowired
private RoleMapper roleMapper;
@Autowired
private AppService appService;
/**
* 查询APP信息
@ -42,8 +53,7 @@ public class AppServiceImpl implements AppService
* @return APP信息
*/
@Override
public AppVO selectAppById(Long id)
{
public AppVO selectAppById(Long id) {
return appMapper.selectAppById(id);
}
@ -54,8 +64,7 @@ public class AppServiceImpl implements AppService
* @return APP信息
*/
@Override
public List<AppVO> selectAppList(AppQuery app)
{
public List<AppVO> selectAppList(AppQuery app) {
return appMapper.selectAppList(app);
}
@ -66,12 +75,14 @@ public class AppServiceImpl implements AppService
* @return 结果
*/
@Override
public int insertApp(App app)
{
public int insertApp(App app) {
Integer result = transactionTemplate.execute(status -> {
app.setCreateTime(DateUtils.getNowDate());
int insert = appMapper.insertApp(app);
if (insert > 0) {
// 尝试修改用户角色
this.tryUpdateUserRole(app);
clearCache();
}
return insert;
@ -79,6 +90,19 @@ public class AppServiceImpl implements AppService
return result;
}
/**
* 尝试修改用户角色
*
* @param app
*/
private void tryUpdateUserRole(App app) {
try {
roleService.insertAuthUsers(RoleConstants.APP_ADMIN, app.getOwnerIds());
} catch (Exception e) {
log.warn("尝试修改ID为{}的用户角色失败:{}", app.getOwnerIds(), e);
}
}
/**
* 修改APP信息
*
@ -86,11 +110,20 @@ public class AppServiceImpl implements AppService
* @return 结果
*/
@Override
public int updateApp(App app)
{
public int updateApp(App app) {
Integer result = transactionTemplate.execute(status -> {
// 清空当前APP管理员角色信息
Role role = roleMapper.selectRoleByKey(RoleConstants.APP_ADMIN);
AppVO vo = appService.selectAppById(app.getId());
roleService.deleteAuthUsers(role.getRoleId(), vo.getOwnerIds());
// 更新APP信息
int update = appMapper.updateApp(app);
if (update > 0) {
// 尝试修改用户角色
this.tryUpdateUserRole(app);
clearCache();
}
return update;
@ -105,8 +138,7 @@ public class AppServiceImpl implements AppService
* @return 结果
*/
@Override
public int deleteAppByIds(Long[] ids)
{
public int deleteAppByIds(Long[] ids) {
Integer result = transactionTemplate.execute(status -> {
int delete = appMapper.deleteAppByIds(ids);
if (delete > 0) {
@ -124,8 +156,7 @@ public class AppServiceImpl implements AppService
* @return 结果
*/
@Override
public int deleteAppById(Long id)
{
public int deleteAppById(Long id) {
Integer result = transactionTemplate.execute(status -> {
int delete = appMapper.deleteAppById(id);
if (delete > 0) {

View File

@ -27,8 +27,7 @@ import org.springframework.transaction.support.TransactionTemplate;
*/
@Service
@Slf4j
public class StoreStaffServiceImpl implements StoreStaffService
{
public class StoreStaffServiceImpl implements StoreStaffService {
@Autowired
private StoreStaffMapper storeStaffMapper;
@Autowired
@ -45,8 +44,7 @@ public class StoreStaffServiceImpl implements StoreStaffService
* @return 员工运维
*/
@Override
public StoreStaffVO selectStoreStaffById(Long id,boolean scope)
{
public StoreStaffVO selectStoreStaffById(Long id, boolean scope) {
if (id == null) {
return null;
}
@ -70,8 +68,7 @@ public class StoreStaffServiceImpl implements StoreStaffService
* @return 员工运维
*/
@Override
public List<StoreStaffVO> selectStoreStaffList(StoreStaffQuery storeStaff)
{
public List<StoreStaffVO> selectStoreStaffList(StoreStaffQuery storeStaff) {
return storeStaffMapper.selectStoreStaffList(storeStaff);
}
@ -82,8 +79,7 @@ public class StoreStaffServiceImpl implements StoreStaffService
* @return 结果
*/
@Override
public int insertStoreStaff(StoreStaff storeStaff)
{
public int insertStoreStaff(StoreStaff storeStaff) {
storeStaff.setCreateTime(DateUtils.getNowDate());
Integer result = transactionTemplate.execute(status -> {
int rows = storeStaffMapper.insertStoreStaff(storeStaff);
@ -93,7 +89,7 @@ public class StoreStaffServiceImpl implements StoreStaffService
this.tryUpdateUserRole(storeStaff);
// 后校验
// storeStaffValidator.afterCheck(storeStaff.getId());
storeStaffValidator.afterCheck(storeStaff.getId());
}
return rows;
@ -122,9 +118,22 @@ public class StoreStaffServiceImpl implements StoreStaffService
* @return 结果
*/
@Override
public int updateStoreStaff(StoreStaff storeStaff)
{
return storeStaffMapper.updateStoreStaff(storeStaff);
public int updateStoreStaff(StoreStaff storeStaff) {
Integer result = transactionTemplate.execute(status -> {
int rows = storeStaffMapper.updateStoreStaff(storeStaff);
if (rows > 0) {
// 尝试修改用户角色
this.tryUpdateUserRole(storeStaff);
// 后校验
storeStaffValidator.afterCheck(storeStaff.getId());
}
return rows;
});
return result == null ? 0 : result;
}
/**
@ -134,8 +143,7 @@ public class StoreStaffServiceImpl implements StoreStaffService
* @return 结果
*/
@Override
public int deleteStoreStaffByIds(Long[] ids)
{
public int deleteStoreStaffByIds(Long[] ids) {
return storeStaffMapper.deleteStoreStaffByIds(ids);
}
@ -146,8 +154,7 @@ public class StoreStaffServiceImpl implements StoreStaffService
* @return 结果
*/
@Override
public int deleteStoreStaffById(Long id)
{
public int deleteStoreStaffById(Long id) {
return storeStaffMapper.deleteStoreStaffById(id);
}
}

View File

@ -40,7 +40,7 @@ public class StoreStaffValidatorImpl implements StoreStaffValidator {
StoreStaffVO vo = storeStaffMapper.selectStoreStaffById(id);
ServiceUtil.assertion(vo == null, "ID为%s的运维员工数据不存在", id);
// 校验用户是否重复绑定到一个运营区
// 校验用户是否重复绑定到一个店铺
this.checkRepeat(vo);
}
@ -53,7 +53,7 @@ public class StoreStaffValidatorImpl implements StoreStaffValidator {
query.setStoreId(vo.getStoreId());
query.setExcludeId(vo.getId());
int count = storeStaffMapper.selectCount(query);
ServiceUtil.assertion(count > 0, "用户%s已是%s的运维人员请勿重复操作", vo.getUserId(), vo.getStoreId());
ServiceUtil.assertion(count > 0, "用户%s已是ID为%s的店铺运维人员,请勿重复操作", vo.getUserId(), vo.getStoreId());
}
private boolean canView(List<Long> ids) {

View File

@ -161,7 +161,7 @@ public interface RoleService
* @param userIds 需要取消授权的用户数据ID
* @return 结果
*/
public int deleteAuthUsers(Long roleId, Long[] userIds);
public int deleteAuthUsers(Long roleId,List<Long> userIds);
/**
* 批量选择授权用户角色

View File

@ -397,7 +397,7 @@ public class RoleServiceImpl implements RoleService
* @return 结果
*/
@Override
public int deleteAuthUsers(Long roleId, Long[] userIds)
public int deleteAuthUsers(Long roleId, List<Long> userIds)
{
return userRoleMapper.deleteUserRoleInfos(roleId, userIds);
}

View File

@ -58,5 +58,5 @@ public interface UserRoleMapper
* @param userIds 需要删除的用户数据ID
* @return 结果
*/
public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") List<Long> userIds);
}

View File

@ -234,7 +234,7 @@ public class SysRoleController extends BaseController
@PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PutMapping("/authUser/cancelAll")
public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
public AjaxResult cancelAuthUserAll(Long roleId, List<Long> userIds)
{
return toAjax(roleService.deleteAuthUsers(roleId, userIds));
}