package com.qmth.teachcloud.mark.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.boot.core.exception.ParameterException;
import com.qmth.teachcloud.mark.entity.ScanFileProperty;
import com.qmth.teachcloud.mark.mapper.ScanFilePropertyMapper;
import com.qmth.teachcloud.mark.service.ScanFilePropertyService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Service
public class ScanFilePropertyServiceImpl extends ServiceImpl<ScanFilePropertyMapper, ScanFileProperty> implements ScanFilePropertyService {
	
	@Transactional
	@Override
	public void save(Long examId, String path, String md5,Long fileSize) {
		if (examId == null) {
            throw new ParameterException("examId 不能为空");
        }
        if (StringUtils.isBlank(path)) {
            throw new ParameterException("path 不能为空");
        }
        if (StringUtils.isBlank(md5)) {
            throw new ParameterException("md5 不能为空");
        }
        ScanFileProperty file = getById(path);
        if (file == null) {
        	file=new ScanFileProperty();
        	file.setPath(path);
        	file.setCreateTime(System.currentTimeMillis());
        	file.setExamId(examId);
        	file.setFileSize(fileSize);
        }
        file.setMd5(md5);
        this.saveOrUpdate(file);
	}
}
