parent
51f8308ab7
commit
c8f445de18
@ -0,0 +1,233 @@
|
||||
package com.ruoyi.web.controller.manager;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.config.RuoYiConfig;
|
||||
import com.ruoyi.common.config.ServerConfig;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.file.FileUploadUtils;
|
||||
import com.ruoyi.common.utils.file.FileUtils;
|
||||
import com.ruoyi.system.domain.file.TdFileRelation;
|
||||
import com.ruoyi.system.service.file.TdFileRelationService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* packageName com.hyp.web.controller.manager
|
||||
*
|
||||
* @author wangxy
|
||||
* @version JDK 8
|
||||
* @className FileRelationManager
|
||||
* @date 2024/4/12
|
||||
* @description 文件
|
||||
*/
|
||||
@Component
|
||||
public class FileRelationManager {
|
||||
|
||||
@Resource
|
||||
private TdFileRelationService fileRelationService;
|
||||
|
||||
|
||||
@Resource
|
||||
private ServerConfig serverConfig;
|
||||
|
||||
/**
|
||||
* 未通过
|
||||
*
|
||||
*/
|
||||
private static final Integer FILE_STATE_WTG = 2;
|
||||
|
||||
/**
|
||||
*
|
||||
* 删除文件
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean delFile(String fileId){
|
||||
TdFileRelation fileRelation = fileRelationService.getById(fileId);
|
||||
if(Objects.isNull(fileRelation)){
|
||||
throw new ServiceException("文件不存在");
|
||||
}
|
||||
FileUtil.del(fileRelation.getFilePath());
|
||||
return fileRelationService.removeById(fileId);
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 材料审核
|
||||
* @param applyId
|
||||
* @param fileCode
|
||||
* @param fileState
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean filePass( String applyId, String fileCode, Integer fileState){
|
||||
return fileRelationService.lambdaUpdate()
|
||||
.eq(TdFileRelation::getApplyId,applyId)
|
||||
.eq(TdFileRelation::getFileCode,fileCode)
|
||||
.set(TdFileRelation::getFileState,fileState)
|
||||
.update();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 材料审核
|
||||
* @param fileId
|
||||
* @param fileState
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean pass( String fileId, Integer fileState){
|
||||
return fileRelationService.lambdaUpdate()
|
||||
.eq(TdFileRelation::getFileId,fileId)
|
||||
.set(TdFileRelation::getFileState,fileState)
|
||||
.update();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 验证文件是否审查
|
||||
* @param applyId
|
||||
* @return com.hyp.common.core.domain.AjaxResult
|
||||
*/
|
||||
public AjaxResult checkFile(String applyId){
|
||||
List<TdFileRelation> list = fileRelationService.lambdaQuery()
|
||||
.eq(TdFileRelation::getApplyId, applyId)
|
||||
.list();
|
||||
if(CollUtil.isNotEmpty(list)){
|
||||
for(TdFileRelation rewFileRelation : list){
|
||||
if(Objects.equals(rewFileRelation.getFileState(),FILE_STATE_WTG) || Objects.isNull(rewFileRelation.getFileState())){
|
||||
return AjaxResult.error("材料存在未审核情况,请检查");
|
||||
}
|
||||
}
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 单个保存
|
||||
* @param applyId
|
||||
* @param filename
|
||||
* @param fileCode
|
||||
* @param url
|
||||
* @param originalFilename
|
||||
* @return com.hyp.system.domain.RewFileRelation
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TdFileRelation save(String applyId,String filename,String fileCode,String url,String originalFilename){
|
||||
TdFileRelation rewFileRelation = new TdFileRelation();
|
||||
rewFileRelation.setApplyId(applyId);
|
||||
rewFileRelation.setFileName(filename);
|
||||
rewFileRelation.setFileCode(fileCode);
|
||||
rewFileRelation.setFilePath(url);
|
||||
rewFileRelation.setRealName(originalFilename);
|
||||
fileRelationService.save(rewFileRelation);
|
||||
return rewFileRelation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 批量保存文件
|
||||
* @param files
|
||||
* @param applyId
|
||||
* @param filename
|
||||
* @param fileCode
|
||||
* @return java.util.List<com.hyp.system.domain.RewFileRelation>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<TdFileRelation> saveBatch(List<MultipartFile> files,
|
||||
String applyId,
|
||||
String filename,
|
||||
String fileCode) throws IOException {
|
||||
List<TdFileRelation> fileRelations = new ArrayList<>();
|
||||
// 上传文件路径
|
||||
String filePath = RuoYiConfig.getUploadPath();
|
||||
for (MultipartFile file : files) {
|
||||
if (!file.isEmpty()) {
|
||||
// 上传并返回新文件名称
|
||||
String fileNames = FileUploadUtils.upload(filePath, file);
|
||||
String url = serverConfig.getUrl() + fileNames;
|
||||
if(StringUtils.isBlank(filename)){
|
||||
filename = fileNames;
|
||||
}
|
||||
TdFileRelation rewFileRelation = new TdFileRelation();
|
||||
rewFileRelation.setApplyId(applyId);
|
||||
rewFileRelation.setFileName(filename);
|
||||
rewFileRelation.setFileCode(fileCode);
|
||||
rewFileRelation.setFilePath(url);
|
||||
rewFileRelation.setRealName(FileUtils.getNameNotSuffix(file.getOriginalFilename()));
|
||||
fileRelations.add(rewFileRelation);
|
||||
}
|
||||
}
|
||||
fileRelationService.saveBatch(fileRelations);
|
||||
return fileRelations;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取文件路劲
|
||||
* @param fileId
|
||||
* @return java.lang.String
|
||||
*/
|
||||
public String getFilePath(String fileId){
|
||||
TdFileRelation fileRelation = fileRelationService.getById(fileId);
|
||||
if(Objects.nonNull(fileRelation)){
|
||||
return fileRelation.getFilePath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取文件名
|
||||
* @param fileId
|
||||
* @return java.lang.String
|
||||
*/
|
||||
public String getRealName(String fileId){
|
||||
TdFileRelation fileRelation = fileRelationService.getById(fileId);
|
||||
if(Objects.nonNull(fileRelation)){
|
||||
return fileRelation.getRealName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 文件列表啥
|
||||
* @param applyId
|
||||
* @param fileCode
|
||||
* @return java.util.List<com.hyp.system.domain.RewFileRelation>
|
||||
*/
|
||||
public List<TdFileRelation> getFileInfo(String applyId,String fileCode){
|
||||
LambdaQueryWrapper<TdFileRelation> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TdFileRelation::getApplyId,applyId);
|
||||
queryWrapper.eq(Objects.nonNull(fileCode), TdFileRelation::getFileCode, fileCode);
|
||||
return fileRelationService.list(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 文件列表啥
|
||||
* @return java.util.List<com.hyp.system.domain.RewFileRelation>
|
||||
*/
|
||||
public TdFileRelation getRewFileRelation(String fileId){
|
||||
return fileRelationService.getById(fileId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.ruoyi.system.mapper.file;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.system.domain.file.TdFileRelation;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【td_file_relation(奖项文件表)】的数据库操作Mapper
|
||||
* @createDate 2025-05-14 08:44:27
|
||||
* @Entity generator.domain.TdFileRelation
|
||||
*/
|
||||
public interface TdFileRelationMapper extends BaseMapper<TdFileRelation> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.ruoyi.system.service.file;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.system.domain.file.TdFileRelation;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【td_file_relation(奖项文件表)】的数据库操作Service
|
||||
* @createDate 2025-05-14 08:44:27
|
||||
*/
|
||||
public interface TdFileRelationService extends IService<TdFileRelation> {
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.ruoyi.system.service.file.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.system.domain.file.TdFileRelation;
|
||||
import com.ruoyi.system.mapper.file.TdFileRelationMapper;
|
||||
import com.ruoyi.system.service.file.TdFileRelationService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【td_file_relation(奖项文件表)】的数据库操作Service实现
|
||||
* @createDate 2025-05-14 08:44:27
|
||||
*/
|
||||
@Service
|
||||
public class TdFileRelationServiceImpl extends ServiceImpl<TdFileRelationMapper, TdFileRelation>
|
||||
implements TdFileRelationService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.system.mapper.file.TdFileRelationMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ruoyi.system.domain.file.TdFileRelation">
|
||||
<id property="fileId" column="file_id" jdbcType="VARCHAR"/>
|
||||
<result property="applyId" column="apply_id" jdbcType="VARCHAR"/>
|
||||
<result property="fileName" column="file_name" jdbcType="VARCHAR"/>
|
||||
<result property="fileCode" column="file_code" jdbcType="VARCHAR"/>
|
||||
<result property="filePath" column="file_path" jdbcType="VARCHAR"/>
|
||||
<result property="realName" column="real_name" jdbcType="VARCHAR"/>
|
||||
<result property="fileState" column="file_state" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
file_id,apply_id,file_name,
|
||||
file_code,file_path,real_name,
|
||||
file_state
|
||||
</sql>
|
||||
</mapper>
|
Loading…
Reference in new issue