测试文件预览
This commit is contained in:
parent
7c8281a35e
commit
26bce15c72
22
pom.xml
22
pom.xml
|
@ -352,6 +352,28 @@
|
|||
<artifactId>ruoyi-file</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!--office工具-->
|
||||
<dependency>
|
||||
<groupId>com.luhuiguo</groupId>
|
||||
<artifactId>aspose-words</artifactId>
|
||||
<version>23.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.luhuiguo</groupId>
|
||||
<artifactId>aspose-pdf</artifactId>
|
||||
<version>23.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.luhuiguo</groupId>
|
||||
<artifactId>aspose-cells</artifactId>
|
||||
<version>23.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.luhuiguo</groupId>
|
||||
<artifactId>aspose-slides</artifactId>
|
||||
<version>23.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
|
@ -55,6 +55,11 @@ public interface CacheNames {
|
|||
*/
|
||||
String SYS_DEPT = "sys_dept#30d";
|
||||
|
||||
/**
|
||||
* 租户部门
|
||||
*/
|
||||
String SYS_TENANT_DEPT = "sys_tenant_dept#30d";
|
||||
|
||||
/**
|
||||
* OSS内容
|
||||
*/
|
||||
|
|
|
@ -14,5 +14,12 @@ public interface DeptService {
|
|||
* @return 部门名称串逗号分隔
|
||||
*/
|
||||
String selectDeptNameByIds(String deptIds);
|
||||
/**
|
||||
* 通过部门名称查询租户部门Id
|
||||
*
|
||||
* @param deptName 部门名称
|
||||
* @return 部门ID
|
||||
*/
|
||||
Long selectDeptIdByName(String deptName);
|
||||
|
||||
}
|
||||
|
|
|
@ -78,6 +78,23 @@
|
|||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.luhuiguo</groupId>
|
||||
<artifactId>aspose-words</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.luhuiguo</groupId>
|
||||
<artifactId>aspose-pdf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.luhuiguo</groupId>
|
||||
<artifactId>aspose-cells</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.luhuiguo</groupId>
|
||||
<artifactId>aspose-slides</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.dromara.file.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.file.service.IFileService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>TODO<p>
|
||||
*
|
||||
* @author cjw
|
||||
* @version V1.0.0
|
||||
* @date 2024/5/31 14:22
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/file")
|
||||
public class FileController {
|
||||
|
||||
private final IFileService fileService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 预览OSS对象
|
||||
*
|
||||
* @param ossId OSS对象ID
|
||||
*/
|
||||
//@SaCheckPermission("system:oss:download")
|
||||
@GetMapping("/preview/{ossId}")
|
||||
public void preview(@PathVariable Long ossId, HttpServletResponse response) throws Exception {
|
||||
fileService.preview(ossId, response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.alibaba.excel.context.AnalysisContext;
|
|||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.service.DeptService;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.ValidatorUtils;
|
||||
import org.dromara.common.excel.core.ExcelListener;
|
||||
|
@ -15,7 +16,6 @@ import org.dromara.file.domain.bo.SysTeacherBo;
|
|||
import org.dromara.file.domain.vo.SysTeacherImportVo;
|
||||
import org.dromara.file.domain.vo.SysTeacherVo;
|
||||
import org.dromara.file.service.ISysTeacherService;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||
public class SysTeacherImportListener extends AnalysisEventListener<SysTeacherImportVo> implements ExcelListener<SysTeacherImportVo> {
|
||||
|
||||
private final ISysTeacherService teacherService;
|
||||
private final ISysDeptService deptService;
|
||||
private final DeptService deptService;
|
||||
private final Long operUserId;
|
||||
private int successNum = 0;
|
||||
private int failureNum = 0;
|
||||
|
@ -37,7 +37,7 @@ public class SysTeacherImportListener extends AnalysisEventListener<SysTeacherIm
|
|||
|
||||
public SysTeacherImportListener() {
|
||||
this.teacherService = SpringUtils.getBean(ISysTeacherService.class);
|
||||
this.deptService = SpringUtils.getBean(ISysDeptService.class);
|
||||
this.deptService = SpringUtils.getBean(DeptService.class);
|
||||
this.operUserId = LoginHelper.getUserId();
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,9 @@ public class SysTeacherImportListener extends AnalysisEventListener<SysTeacherIm
|
|||
SysTeacherVo sysTeacher = this.teacherService.selectTeacherByPhonenumber(userVo.getPhonenumber());
|
||||
try {
|
||||
// 验证是否存在这个用户
|
||||
Long deptId = this.deptService.selectDeptIdByName( userVo.getDeptName());
|
||||
if (ObjectUtil.isNotNull(deptId)) {
|
||||
if (ObjectUtil.isNull(sysTeacher)) {
|
||||
Long deptId = this.deptService.selectIdBuName(userVo.getDeptName());
|
||||
SysTeacherBo teacher = BeanUtil.toBean(userVo, SysTeacherBo.class);
|
||||
ValidatorUtils.validate(teacher);
|
||||
teacher.setCreateBy(operUserId);
|
||||
|
@ -59,6 +60,10 @@ public class SysTeacherImportListener extends AnalysisEventListener<SysTeacherIm
|
|||
failureNum++;
|
||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(sysTeacher.getTeacherName()).append(" 已存在");
|
||||
}
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(sysTeacher.getTeacherName()).append(" 查询不到部门");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、账号 " + userVo.getTeacherName() + " 导入失败:";
|
||||
|
@ -85,6 +90,7 @@ public class SysTeacherImportListener extends AnalysisEventListener<SysTeacherIm
|
|||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysTeacherImportVo> getList() {
|
||||
return null;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.dromara.file.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.dromara.file.domain.SysTeacher;
|
||||
import org.dromara.file.domain.vo.SysTeacherVo;
|
||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
|
@ -10,6 +11,7 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
|||
* @author cjw
|
||||
* @date 2024-05-30
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysTeacherMapper extends BaseMapperPlus<SysTeacher, SysTeacherVo> {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.dromara.file.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IFileService {
|
||||
|
||||
/**
|
||||
* 预览文件
|
||||
*
|
||||
* @param ossId
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
void preview(Long ossId, HttpServletResponse response) throws Exception;
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.dromara.file.service.impl;
|
||||
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.SaveFormat;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.oss.core.OssClient;
|
||||
import org.dromara.common.oss.factory.OssFactory;
|
||||
import org.dromara.file.service.IFileService;
|
||||
import org.dromara.system.domain.vo.SysOssVo;
|
||||
import org.dromara.system.service.ISysOssService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* <p>TODO<p>
|
||||
*
|
||||
* @author cjw
|
||||
* @version V1.0.0
|
||||
* @date 2024/5/31 14:39
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class FileService implements IFileService {
|
||||
|
||||
private final ISysOssService ossService;
|
||||
|
||||
/**
|
||||
* 预览文件
|
||||
*
|
||||
* @param ossId
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void preview(Long ossId, HttpServletResponse response) throws Exception {
|
||||
SysOssVo sysOss = ossService.getById(ossId);
|
||||
OssClient storage = OssFactory.instance(sysOss.getService());
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
is = storage.getObjectContent(sysOss.getFileName());
|
||||
os = response.getOutputStream();
|
||||
byte[] byteData = new byte[1024];
|
||||
// 前端word预览仅支持.docx,将.doc转换为.docx
|
||||
if ((".doc").equals(sysOss.getFileSuffix())) {
|
||||
Document doc = new Document(is);
|
||||
doc.save(os, SaveFormat.DOCX);
|
||||
}
|
||||
int len = 0;
|
||||
while ((len = is.read(byteData)) != -1) {
|
||||
os.write(byteData, 0, len);
|
||||
}
|
||||
os.flush();
|
||||
} finally {
|
||||
if (os != null) {
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
//log.error("IO异常", e);
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
//log.error("IO异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package org.dromara.system.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import org.dromara.system.domain.SysDept;
|
||||
import org.dromara.system.domain.bo.SysDeptBo;
|
||||
import org.dromara.system.domain.vo.SysDeptVo;
|
||||
|
||||
|
@ -131,5 +132,12 @@ public interface ISysDeptService {
|
|||
*/
|
||||
int deleteDeptById(Long deptId);
|
||||
|
||||
Long selectIdBuName(String deptName);
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有部门信息
|
||||
*
|
||||
* @return 部门信息
|
||||
*/
|
||||
List<SysDept> selectAllDept();
|
||||
}
|
||||
|
|
|
@ -77,4 +77,6 @@ public interface ISysOssService {
|
|||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.dromara.system.mapper.SysUserMapper;
|
|||
import org.dromara.system.service.ISysDeptService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -166,6 +167,19 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||
return String.join(StringUtils.SEPARATOR, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long selectDeptIdByName(String deptName) {
|
||||
List<SysDept> deptList = SpringUtils.getAopProxy(this).selectAllDept();
|
||||
if (ObjectUtil.isNotEmpty(deptList)) {
|
||||
for (SysDept dept : deptList) {
|
||||
if (ObjectUtil.equals(deptName, dept.getDeptName())) {
|
||||
return dept.getDeptId();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询所有子部门数(正常状态)
|
||||
*
|
||||
|
@ -274,7 +288,11 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||
* @param bo 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId")
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId"),
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT)
|
||||
})
|
||||
@Override
|
||||
public int updateDept(SysDeptBo bo) {
|
||||
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
|
||||
|
@ -342,15 +360,19 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
|
||||
@Caching(evict = {
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"),
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT)
|
||||
})
|
||||
@Override
|
||||
public int deleteDeptById(Long deptId) {
|
||||
return baseMapper.deleteById(deptId);
|
||||
}
|
||||
|
||||
@Cacheable(cacheNames = CacheNames.SYS_TENANT_DEPT)
|
||||
@Override
|
||||
public Long selectIdBuName(String deptName) {
|
||||
SysDept sysDept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>().select(SysDept::getDeptId).eq(SysDept::getDeptName, deptName));
|
||||
return sysDept.getDeptId();
|
||||
public List<SysDept> selectAllDept() {
|
||||
return baseMapper.selectList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -250,6 +250,8 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 桶类型为 private 的URL 修改为临时URL时长为120s
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue