package com.zhangmeng.file.service.impl;

import com.zhangmeng.file.service.FileInfoService;
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
import com.zhangmeng.model.base.baseUtil.CommonUtil;
import com.zhangmeng.model.entity.FileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


@Service
public class FileInfoServiceImpl extends AbstractBaseServiceImpl<FileInfo> implements FileInfoService {

    @Override
    public FileInfo findByMd5(String md5) {
        Condition condition = new Condition(FileInfo.class);
        Example.Criteria criteria = condition.createCriteria();
        if (CommonUtil.isNotNull(md5)) {
            criteria.andEqualTo("md5", md5);
        }
        List<FileInfo> fileInfos = this.findByCondition(condition);
        if (fileInfos.size() > 0) {
            return fileInfos.get(0);
        }
        return null;
    }
}
