package com.muyu.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.domain.FirmPermission;
import com.muyu.domain.req.FirmUpdPermissionReq;
import com.muyu.server.mapper.FirmPermissionMapper;
import com.muyu.server.service.FirmManageService;
import com.muyu.server.service.FirmPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 企业权限分配业务实现层
 * @Author：weiran
 * @Package：com.muyu.server.service.impl
 * @Project：cloud-server-8
 * @name：FirmPermissionServiceImpl
 * @Date：2024/10/7 21:31
 */
@Service
public class FirmPermissionServiceImpl extends ServiceImpl<FirmPermissionMapper, FirmPermission> implements FirmPermissionService {
    @Autowired
    private FirmManageService firmManageService;

    /**
     * 修改企业权限分配
     * @param firmUpdPermissionReq
     * @return
     */
    @Override
    public void updpermission(FirmUpdPermissionReq firmUpdPermissionReq) {
        String permissionLevel = firmUpdPermissionReq.getPermissionLevel();
        //根据权限等级获取对应权限Id
        LambdaQueryWrapper<FirmPermission> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FirmPermission::getPermissionLevel, firmUpdPermissionReq.getPermissionLevel());
        List<FirmPermission> list = this.list(queryWrapper);
        FirmPermission firmPermission = list.get(0);
        long permissionId=firmPermission.getPermissionId();
        //修改企业对应权限
        firmManageService.updpermission(firmUpdPermissionReq,permissionId);
    }


    /**
     * 权限等级列表
     * @return
     */
    @Override
    public List<FirmPermission> permissionlist() {
        LambdaQueryWrapper<FirmPermission> queryWrapper = new LambdaQueryWrapper<>();
        List<FirmPermission> list = this.list(queryWrapper);
        return list;
    }
}
