package com.zxdmy.excite.system.service.impl.cloud.role;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxdmy.excite.system.entity.SysUserRole;
import com.zxdmy.excite.system.entity.cloud.role.CloudRole;
import com.zxdmy.excite.system.entity.cloud.role.CloudRoleUser;
import com.zxdmy.excite.system.mapper.cloud.role.CloudRoleMapper;
import com.zxdmy.excite.system.mapper.cloud.role.CloudRoleUserMapper;
import com.zxdmy.excite.system.service.ISysUserRoleService;
import com.zxdmy.excite.system.service.cloud.role.ICloudRoleUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxdmy.excite.system.utils.AuthUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 云盘权限用户表 服务实现类
 * </p>
 *
 * @author ss
 * @since 2026-01-27
 */
@Service
@AllArgsConstructor
public class CloudRoleUserServiceImpl extends ServiceImpl<CloudRoleUserMapper, CloudRoleUser> implements ICloudRoleUserService {
    CloudRoleUserMapper cloudRoleUserMapper;
    CloudRoleMapper cloudRoleMapper;
    @Override
    public List<CloudRoleUser> getListByUserId(Integer userId) {
        QueryWrapper<CloudRoleUser> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("user_id", userId);
        return cloudRoleUserMapper.selectList(wrapper1);
    }

    @Override
    public CloudRole getCloudShareRole(Integer id) {
        QueryWrapper<CloudRoleUser> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",id);
        List<CloudRoleUser> roleList = cloudRoleUserMapper.selectList(wrapper);
        CloudRole data = new CloudRole();
        data.setRoleUpload(0);
        data.setRoleDown(0);
        data.setRoleDelete(0);
        for (CloudRoleUser cloudRoleUser:roleList) {
            CloudRole cloudRole = cloudRoleMapper.selectById(cloudRoleUser.getRoleId());
            if(null!=cloudRole.getRoleUpload() && cloudRole.getRoleUpload()==1){
                data.setRoleUpload(1);
            }
            if(null!=cloudRole.getRoleDown() && cloudRole.getRoleDown()==1){
                data.setRoleDown(1);
            }
            if(null!=cloudRole.getRoleDelete() && cloudRole.getRoleDelete()==1){
                data.setRoleDelete(1);
            }
        }
        return data;
    }
}
