fix: 补报表内容表的相关Service Dao代码
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.adc.da.report.dao.mysql;
|
||||
|
||||
import com.adc.da.report.eo.ReportContentEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【ts_report_content】的数据库操作Mapper
|
||||
* @createDate 2023-04-27 11:48:22
|
||||
* @Entity com.adc.da.report.eo.ReportContentEntity
|
||||
*/
|
||||
public interface ReportContentDao extends BaseMapper<ReportContentEntity> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.adc.da.report.eo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Caihaohan
|
||||
* @TableName ts_report_content
|
||||
*/
|
||||
@TableName(value ="ts_report_content")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class ReportContentEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value = "id",type = IdType.INPUT)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 报告id
|
||||
*/
|
||||
@TableField(value = "report_id")
|
||||
private String reportId;
|
||||
|
||||
/**
|
||||
* 文件内容
|
||||
*/
|
||||
@TableField(value = "report_content")
|
||||
private String reportContent;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.adc.da.report.service;
|
||||
|
||||
import com.adc.da.report.eo.ReportContentEntity;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author ThinkBook
|
||||
* @description 针对表【ts_report_content】的数据库操作Service
|
||||
* @createDate 2023-04-27 11:48:22
|
||||
*/
|
||||
public interface IReportContentService extends IService<ReportContentEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* 插入报告内容表
|
||||
*
|
||||
* @param reportId 报告id
|
||||
* @param fileId 文件id
|
||||
*/
|
||||
void insertReportContent(String reportId, String fileId) throws IOException;
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.adc.da.report.service.impl;
|
||||
|
||||
import com.adc.da.report.dao.mysql.FileDao;
|
||||
import com.adc.da.report.eo.FileEntity;
|
||||
import com.adc.da.report.util.FileContentUtil;
|
||||
import com.adc.da.report.util.LocalFileUtil;
|
||||
import com.adc.da.report.util.OSSClientUtil;
|
||||
import com.adc.da.report.util.ObsBootUtil;
|
||||
import com.adc.da.util.utils.FileUtil;
|
||||
import com.adc.da.util.utils.UUID;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.adc.da.report.eo.ReportContentEntity;
|
||||
import com.adc.da.report.service.IReportContentService;
|
||||
import com.adc.da.report.dao.mysql.ReportContentDao;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Caihaohan
|
||||
* @description 针对表【ts_report_content】的数据库操作Service实现
|
||||
* @createDate 2023-04-27 11:48:22
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class IReportContentServiceImpl extends ServiceImpl<ReportContentDao, ReportContentEntity>
|
||||
implements IReportContentService {
|
||||
|
||||
@Value("${uploadFile}")
|
||||
private String uploadFile;
|
||||
|
||||
@Value("${uploadType}")
|
||||
private String uploadType;
|
||||
|
||||
@Resource
|
||||
private OSSClientUtil ossClientUtil;
|
||||
|
||||
@Resource
|
||||
private ObsBootUtil obsBootUtil;
|
||||
|
||||
@Resource
|
||||
private LocalFileUtil localFileUtil;
|
||||
|
||||
@Resource
|
||||
private FileDao fileDao;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void insertReportContent(String reportId, String fileId) throws IOException {
|
||||
//获取文件
|
||||
FileEntity fileEntity = fileDao.selectById(fileId);
|
||||
String path = uploadFile + fileEntity.getSavePath();
|
||||
FileOutputStream outputStream = new FileOutputStream(path);
|
||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||
if ("hwobs".equals(uploadType)) {
|
||||
obsBootUtil.getFileFromOBS(fileEntity.getSavePath(), outputStream);
|
||||
} else if ("alioss".equals(uploadType)) {
|
||||
ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream);
|
||||
} else if ("local".equals(uploadType)) {
|
||||
localFileUtil.getFileFromLocal(fileEntity.getSavePath(), outputStream);
|
||||
}
|
||||
File file = new File(path);
|
||||
//解析出内容
|
||||
String content = FileContentUtil.readFileContent(file);
|
||||
//将内容存入
|
||||
ReportContentEntity reportContentEntity = new ReportContentEntity(UUID.randomUUID10(), reportId, content);
|
||||
save(reportContentEntity);
|
||||
//将文件删除
|
||||
FileUtil.deleteFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user