代码提交

This commit is contained in:
liang.chao 2025-09-17 17:38:51 +08:00
parent 866f8be845
commit e404f57cd1
8 changed files with 100 additions and 11 deletions

View File

@ -3,6 +3,7 @@ package com.bonus.web.controller.archive;
import com.bonus.common.annotation.RequiresPermissions;
import com.bonus.common.annotation.SysLog;
import com.bonus.common.core.controller.BaseController;
import com.bonus.common.core.domain.AjaxResult;
import com.bonus.common.core.domain.R;
import com.bonus.common.core.page.TableDataInfo;
import com.bonus.common.enums.OperaType;
@ -17,15 +18,26 @@ import com.bonus.web.domain.vo.DaKyProFilesContentsVo;
import com.bonus.web.mapper.FileManageMapper;
import com.bonus.web.service.FileManageService;
import com.bonus.web.service.ProjectService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static com.bonus.common.utils.SecurityUtils.getLoginUser;
@ -111,12 +123,37 @@ public class FileManagementController extends BaseController {
}
}
@ApiOperation(value = "获取当前节点数据")
@GetMapping("getFileManageById")
@SysLog(title = "获取当前节点数据", module = "档案管理->档案右侧列表", businessType = OperaType.QUERY, details = "获取当前节点数据", logType = 1)
@RequiresPermissions("file:manage:query")
public AjaxResult getFileManageById(DaKyProFilesContentsDto dto) {
return AjaxResult.success(fileManageService.getFileManageById(dto));
}
@ApiOperation(value = "新增右侧档案树")
@PostMapping("addFileManageRight")
@SysLog(title = "新增右侧档案树", module = "档案管理->档案目录管理", businessType = OperaType.INSERT, details = "新增右侧档案树", logType = 1)
@RequiresPermissions("file:manage:add")
public R saveArchivalCatalogue(@ModelAttribute @Validated DaKyProFilesContentsVo dto, @RequestParam("file") MultipartFile file) {
public R saveArchivalCatalogue(@RequestPart("file") MultipartFile file,
@RequestParam("params") String params) {
try {
// 手动解析JSON
ObjectMapper objectMapper = new ObjectMapper();
DaKyProFilesContentsVo dto = objectMapper.readValue(params, DaKyProFilesContentsVo.class);
// 手动验证
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<DaKyProFilesContentsVo>> violations = validator.validate(dto);
if (!violations.isEmpty()) {
// 处理验证错误
List<String> errors = violations.stream()
.map(ConstraintViolation::getMessage)
.collect(Collectors.toList());
return R.fail(400, "参数验证失败: " + String.join(", ", errors));
}
if (dto.getParentId() == null) {
return R.fail("父级有误");
}
@ -148,11 +185,13 @@ public class FileManagementController extends BaseController {
dto.setUpdateUserName(getLoginUser().getUsername());
dto.setCreateUserId(getLoginUser().getUserId());
dto.setCreateUserName(getLoginUser().getUsername());
fileManageMapper.saveFileSource(dto);
} else if (file == null || file.isEmpty()) {
return R.fail("请上传文件");
}
return fileManageService.saveFileManage(dto);
R r = fileManageService.saveFileManage(dto);
dto.setBusinessId(dto.getId());
fileManageMapper.saveFileSource(dto);
return r;
} catch (Exception e) {
log.error(e.toString(), e);
return R.fail("请求出错了");

View File

@ -38,6 +38,15 @@ public class DaKyProFilesContentsDto {
private String parentId;
private String parentName;
/**
* 所属专业
*/
private String major;
/**
* 文件分类标记
*/
private String classifyMark;
/**
* 层级

View File

@ -57,6 +57,16 @@ public class DaKyProFilesContentsVo {
* 案卷期限
*/
private String term;
/**
* 所属专业
*/
private String major;
/**
* 文件分类标记
*/
private String classifyMark;
/**
* 归档责任单位
@ -118,7 +128,6 @@ public class DaKyProFilesContentsVo {
/**
* 文件地址
*/
@NotBlank(message = "请上传文件")
private String filePath;
/**
* 文件名称

View File

@ -43,4 +43,6 @@ public interface FileManageMapper {
Integer getMaxSort(DaKyProFilesContentsDto dto);
Integer getSortById(String id);
DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto);
}

View File

@ -30,4 +30,6 @@ public interface FileManageService {
Integer getSortById(String id);
List<DaKyProFilesContentsDto> getFileManageTree(DaKyProFilesContentsDto dto);
DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto);
}

View File

@ -124,4 +124,9 @@ public class FileManageServiceImpl implements FileManageService {
List<DaKyProFilesContentsDto> tree = TreeBuilder.buildTreeDaKyProFilesContents(list);
return tree;
}
@Override
public DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto) {
return fileManageMapper.getFileManageById(dto);
}
}

View File

@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.web.mapper.FileManageMapper">
<insert id="saveFileManage">
<insert id="saveFileManage" useGeneratedKeys="true" keyProperty="id">
INSERT INTO da_ky_pro_files_contents
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">id,</if>
@ -14,6 +14,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sort != null">sort,</if>
<if test="markCode != null and markCode != ''">mark_code,</if>
<if test="term != null and term != ''">term,</if>
<if test="major != null and major != ''">major,</if>
<if test="classifyMark != null and classifyMark != ''">classify_mark,</if>
<if test="unitName != null and unitName != ''">unit_name,</if>
<if test="dataSource != null and dataSource != ''">data_source,</if>
<if test="isUnique != null and isUnique != ''">is_unique,</if>
@ -35,6 +37,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sort != null">#{sort},</if>
<if test="markCode != null and markCode != ''">#{markCode},</if>
<if test="term != null and term != ''">#{term},</if>
<if test="major != null and major != ''">#{major},</if>
<if test="classifyMark != null and classifyMark != ''">#{classifyMark},</if>
<if test="unitName != null and unitName != ''">#{unitName},</if>
<if test="dataSource != null and dataSource != ''">#{dataSource},</if>
<if test="isUnique != null and isUnique != ''">#{isUnique},</if>
@ -59,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sourceType != null and sourceType != ''">source_type,</if>
<if test="createUserId != null">create_user_id,</if>
<if test="createUserName != null and createUserName != ''">create_user_name,</if>
createTime
create_time
</trim>
VALUES
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -84,6 +88,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sort != null">sort = #{sort},</if>
<if test="markCode != null and markCode != ''">mark_code = #{markCode},</if>
<if test="term != null and term != ''">term = #{term},</if>
<if test="major != null and major != ''">major = #{major},</if>
<if test="classifyMark != null and classifyMark != ''">classify_mark = #{classifyMark},</if>
<if test="unitName != null and unitName != ''">unit_name = #{unitName},</if>
<if test="dataSource != null and dataSource != ''">data_source = #{dataSource},</if>
<if test="isUnique != null and isUnique != ''">is_unique = #{isUnique},</if>
@ -162,7 +168,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
da_ky_pro_files_contents dkpfc
left join da_ky_sys_file_source dkfs on dkpfc.id = dkfs.business_id
WHERE
dkpfc.del_flag = '1' and dkpfc.parent_id = #{parentId} and dkpfc.level = 4
dkpfc.del_flag = '1' and dkpfc.parent_id = #{parentId} and dkpfc.level = 5
<if test="contentName != null and contentName != ''">
and dkpfc.content_name like concat('%', #{contentName}, '%')
</if>
@ -215,4 +221,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE
dkfcns.del_flag = '1'
</select>
<select id="getFileManageById" resultType="com.bonus.web.domain.DaKyProFilesContentsDto">
select dkpfc.*,
dksdd.dict_label AS markCode,
dkfcm.classify_mark_name AS classifyMark
from da_ky_pro_files_contents dkpfc
left join da_ky_sys_dict_data dksdd on dkpfc.mark_code = dksdd.dict_value and dksdd.dict_type = 'mark_code'
left join da_ky_files_classify_mark dkfcm on dkpfc.classify_mark = dkfcm.id
where dkpfc.id = #{id}
</select>
</mapper>

View File

@ -14,6 +14,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -28,6 +29,7 @@ import com.bonus.common.utils.DateUtils;
import com.bonus.common.utils.StringUtils;
import com.bonus.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
/**
@ -35,12 +37,13 @@ import org.springframework.web.multipart.MultipartFile;
*
* @author bonus
*/
@Component
public class FileUtils {
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
// 常见的图片扩展名小写
// 常见的图片扩展名小写
private static final Set<String> IMAGE_EXTENSIONS;
private static String UPLOAD_DIR;
static {
HashSet<String> set = new HashSet<>();
set.add("jpg");
@ -57,7 +60,12 @@ public class FileUtils {
@Value("${bonus.profile}")
private static String uploadDir;
private String uploadDir;
@PostConstruct
public void init() {
UPLOAD_DIR = uploadDir; // 在对象初始化时赋值给 static 变量
}
/**
* 输出指定文件的byte数组
@ -300,12 +308,12 @@ public class FileUtils {
} else {
bean.setFileType("2");
}
File targetDir = new File(uploadDir);
File targetDir = new File(UPLOAD_DIR);
if (!targetDir.exists()) {
targetDir.mkdirs();
}
String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename();
File targetFile = new File(uploadDir, fileName);
File targetFile = new File(UPLOAD_DIR, fileName);
file.transferTo(targetFile);
String pathName = targetFile.getAbsolutePath();
bean.setFilePath(pathName);