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.WpsFileVersionMapper;
import org.jeecg.modules.wps.entity.WpsFileVersion;
import org.jeecg.modules.wps.service.IWpsFileVersionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * wps文件版本号
 * @author jeecg-boot
 * @date   2020-06-01
 * @version V1.0
 */
@Service
public class WpsFileVersionServiceImpl extends ServiceImpl<WpsFileVersionMapper, WpsFileVersion> implements IWpsFileVersionService {

    @Override
    public WpsFileVersion findByFileIdAndVersion(String fileId, Integer version) {
        QueryWrapper<WpsFileVersion>queryWrapper = new QueryWrapper<>();
        if(null!=fileId&&!"".equals(fileId.trim())){
            queryWrapper.eq("file_id",fileId);
        }
        if(null!=version&&version!=0){
            queryWrapper.eq("version",version);
        }
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);
    }

    @Override
    public List<WpsFileVersion> findByFileIdOrderByVersionDesc(String fileId) {
        QueryWrapper<WpsFileVersion>queryWrapper = new QueryWrapper<>();
        if(null!=fileId&& "".equals(fileId.trim())){
            queryWrapper.eq("file_id",fileId);
        }
        queryWrapper.orderByDesc("version");
        return this.list(queryWrapper);
    }
}
