package org.jeecg.modules.wps.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.wps.mapper.WpsUserAclMapper;
import org.jeecg.modules.wps.entity.WpsUserAcl;
import org.jeecg.modules.wps.service.IWpsUserAclService;
import org.springframework.stereotype.Service;

/**
 * wps用户权限
 * @author jeecg-boot
 * @date   2020-06-01
 * @version V1.0
 */
@Service
public class WpsUserAclServiceImpl extends ServiceImpl<WpsUserAclMapper, WpsUserAcl> implements IWpsUserAclService {
    @Override
    public WpsUserAcl findFirstByFileIdAndUserId(String fileId, String userId) {
        QueryWrapper<WpsUserAcl> queryWrapper = new QueryWrapper<>();
        if(null!=fileId&&!"".equals(fileId.trim())){
            queryWrapper.eq("file_id",fileId);
        }
        if(null!=userId&&!"".equals(userId.trim())){
            queryWrapper.eq("user_id",userId);
        }
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);
    }

    @Override
    public void saveUserFileAcl(String userId, String fileId) {
        this.save(new WpsUserAcl(userId,fileId));
    }
}
