package com.corewing.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.corewing.app.entity.FeedbackLog;
import com.corewing.app.mapper.FeedbackLogMapper;
import com.corewing.app.service.FeedbackLogService;
import com.corewing.app.util.OSSUploadUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
public class FeedbackLogServiceImpl extends ServiceImpl<FeedbackLogMapper, FeedbackLog> implements FeedbackLogService {

    @Override
    public boolean uploadFeedbackLog(MultipartFile file, FeedbackLog feedbackLog) {

        feedbackLog.setLogSize(file.getSize());
        feedbackLog.setLogName(feedbackLog.getUserId() + "_" + file.getOriginalFilename());

        try {
           String ossPath = OSSUploadUtil.uploadFile(file.getInputStream(), "feedback_log/" + feedbackLog.getLogName());
           feedbackLog.setOssPath(ossPath);
           return save(feedbackLog);
        } catch (IOException e) {
            return false;
        }
    }
}
