package com.ycwl.basic.service.pc.impl;

import com.ycwl.basic.mapper.PermissionMapper;
import com.ycwl.basic.model.pc.permission.entity.PermissionEntity;
import com.ycwl.basic.service.pc.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public PermissionEntity getPermissionByUserId(Long userId) {
        return permissionMapper.selectByUserId(userId);
    }

    @Override
    public boolean saveOrUpdate(Long userId, String permStr, String menuStr) {
        PermissionEntity entity = new PermissionEntity();
        entity.setUserId(userId);
        entity.setPermString(permStr);
        entity.setMenuString(menuStr);
        if (permissionMapper.selectByUserId(userId) == null) {
            permissionMapper.insertPermission(entity);
        } else {
            permissionMapper.updatePermission(entity);
        }
        return true;
    }
}