三江-安全环保资料中心接口编写
This commit is contained in:
parent
72145d1e9b
commit
a615c2b0d5
@ -1,276 +1,206 @@
|
|||||||
package com.zhgd.xmgl.modules.sanjiang.controller;
|
package com.zhgd.xmgl.modules.sanjiang.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import io.swagger.annotations.Api;
|
import com.zhgd.annotation.OperLog;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import com.zhgd.jeecg.common.api.vo.Result;
|
import com.zhgd.jeecg.common.api.vo.Result;
|
||||||
import com.zhgd.jeecg.common.system.query.QueryGenerator;
|
import com.zhgd.xmgl.base.TreeNode;
|
||||||
import com.zhgd.jeecg.common.util.oConvertUtils;
|
|
||||||
import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile;
|
import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile;
|
||||||
import com.zhgd.xmgl.modules.sanjiang.service.ISjSafeEnvironmentFileService;
|
import com.zhgd.xmgl.modules.sanjiang.service.ISjSafeEnvironmentFileService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
||||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
||||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
||||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
|
||||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
import java.util.*;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Title: Controller
|
* @Title: Controller
|
||||||
* @Description: 三江安全环保资料中心
|
* @Description: 三江安全环保资料中心
|
||||||
* @author: pds
|
* @author: pds
|
||||||
* @date: 2023-04-20
|
* @date: 2021-01-11
|
||||||
* @version: V1.0
|
* @version: V1.0
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/xmgl/sjSafeEnvironmentFile")
|
@RequestMapping("/xmgl/sjSafeEnvironmentFile")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Api(tags = "三江安全环保资料中心Controller")
|
@Api("ProjectFileController相关Api")
|
||||||
public class SjSafeEnvironmentFileController {
|
public class SjSafeEnvironmentFileController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISjSafeEnvironmentFileService sjSafeEnvironmentFileService;
|
private ISjSafeEnvironmentFileService sjSafeEnvironmentFileService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表查询
|
* 分页列表查询
|
||||||
*
|
|
||||||
* @param sjSafeEnvironmentFile
|
|
||||||
* @param pageNo
|
|
||||||
* @param pageSize
|
|
||||||
* @param req
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ApiOperation(value = " 分页列表查询三江安全环保资料中心信息", notes = "分页列表查询三江安全环保资料中心信息", httpMethod = "GET")
|
@ApiOperation(value = " 列表查询项目文件档案信息", notes = "列表查询项目文件档案信息", httpMethod = "POST")
|
||||||
@GetMapping(value = "/page")
|
@ApiImplicitParams({
|
||||||
public Result<IPage<SjSafeEnvironmentFile>> queryPageList(SjSafeEnvironmentFile sjSafeEnvironmentFile,
|
@ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String"),
|
||||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@ApiImplicitParam(name = "filePath", value = "路径", paramType = "query", required = true, dataType = "Integer"),
|
||||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
})
|
||||||
HttpServletRequest req) {
|
@PostMapping(value = "/list")
|
||||||
Result<IPage<SjSafeEnvironmentFile>> result = new Result<IPage<SjSafeEnvironmentFile>>();
|
public Result<List<SjSafeEnvironmentFile>> getFileList(@RequestBody Map<String, Object> map) {
|
||||||
QueryWrapper<SjSafeEnvironmentFile> queryWrapper = QueryGenerator.initQueryWrapper(sjSafeEnvironmentFile, req.getParameterMap());
|
QueryWrapper<SjSafeEnvironmentFile> queryWrapper = new QueryWrapper<>();
|
||||||
Page<SjSafeEnvironmentFile> page = new Page<SjSafeEnvironmentFile>(pageNo, pageSize);
|
queryWrapper.lambda().eq(SjSafeEnvironmentFile::getProjectSn, MapUtils.getString(map, "projectSn"))
|
||||||
IPage<SjSafeEnvironmentFile> pageList = sjSafeEnvironmentFileService.page(page, queryWrapper);
|
.eq(SjSafeEnvironmentFile::getFilePath, MapUtils.getString(map, "filePath"));
|
||||||
result.setSuccess(true);
|
queryWrapper.orderByAsc("is_dir");
|
||||||
result.setResult(pageList);
|
List<SjSafeEnvironmentFile> list = sjSafeEnvironmentFileService.list(queryWrapper);
|
||||||
return result;
|
return Result.success(list);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 列表查询
|
|
||||||
*
|
|
||||||
* @param sjSafeEnvironmentFile
|
|
||||||
* @param req
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = " 列表查询三江安全环保资料中心信息", notes = "列表查询三江安全环保资料中心信息", httpMethod = "GET")
|
|
||||||
@GetMapping(value = "/list")
|
|
||||||
public Result<List<SjSafeEnvironmentFile>> queryList(SjSafeEnvironmentFile sjSafeEnvironmentFile,
|
|
||||||
HttpServletRequest req) {
|
|
||||||
|
|
||||||
QueryWrapper<SjSafeEnvironmentFile> queryWrapper = QueryGenerator.initQueryWrapper(sjSafeEnvironmentFile, req.getParameterMap());
|
|
||||||
return Result.success(sjSafeEnvironmentFileService.list(queryWrapper));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加
|
* 添加
|
||||||
*
|
|
||||||
* @param sjSafeEnvironmentFile
|
* @param sjSafeEnvironmentFile
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ApiOperation(value = " 添加三江安全环保资料中心信息", notes = "添加三江安全环保资料中心信息", httpMethod = "POST")
|
@OperLog(operModul = "项目文件管理", operType = "添加项目文件档案", operDesc = "添加项目文件档案")
|
||||||
|
@ApiOperation(value = " 添加项目文件档案信息", notes = "添加项目文件档案信息", httpMethod = "POST")
|
||||||
@PostMapping(value = "/add")
|
@PostMapping(value = "/add")
|
||||||
public Result<SjSafeEnvironmentFile> add(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
public Result<SjSafeEnvironmentFile> add(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
||||||
Result<SjSafeEnvironmentFile> result = new Result<SjSafeEnvironmentFile>();
|
sjSafeEnvironmentFileService.addProjectFile(sjSafeEnvironmentFile);
|
||||||
try {
|
return Result.ok();
|
||||||
sjSafeEnvironmentFileService.save(sjSafeEnvironmentFile);
|
|
||||||
result.success("添加成功!");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
log.info(e.getMessage());
|
|
||||||
result.error500("操作失败");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*
|
*
|
||||||
* @param sjSafeEnvironmentFile
|
* @param sjSafeEnvironmentFile
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ApiOperation(value = "编辑三江安全环保资料中心信息", notes = "编辑三江安全环保资料中心信息", httpMethod = "POST")
|
@OperLog(operModul = "项目文件管理", operType = "文件重命名", operDesc = "文件重命名")
|
||||||
@PostMapping(value = "/edit")
|
@ApiOperation(value = "文件重命名", notes = "文件重命名", httpMethod = "POST")
|
||||||
|
@PostMapping(value = "/renameFile")
|
||||||
public Result<SjSafeEnvironmentFile> edit(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
public Result<SjSafeEnvironmentFile> edit(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
||||||
Result<SjSafeEnvironmentFile> result = new Result<SjSafeEnvironmentFile>();
|
sjSafeEnvironmentFileService.renamefile(sjSafeEnvironmentFile);
|
||||||
SjSafeEnvironmentFile sjSafeEnvironmentFileEntity = sjSafeEnvironmentFileService.getById(sjSafeEnvironmentFile.getId());
|
return Result.ok();
|
||||||
if (sjSafeEnvironmentFileEntity == null) {
|
|
||||||
result.error500("未找到对应实体");
|
|
||||||
} else {
|
|
||||||
sjSafeEnvironmentFileService.updateById(sjSafeEnvironmentFile);
|
|
||||||
result.success("修改成功!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
|
@OperLog(operModul = "项目文件管理", operType = "批量删除文件", operDesc = "批量删除文件")
|
||||||
|
@ApiOperation(value = "批量删除文件", notes = "批量删除文件", httpMethod = "POST")
|
||||||
|
@RequestMapping(value = "/batchDeleteFile", method = RequestMethod.POST)
|
||||||
|
public Result<String> batchDeleteFile(@RequestBody List<SjSafeEnvironmentFile> list) {
|
||||||
|
sjSafeEnvironmentFileService.batchDeleteFile(list);
|
||||||
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@OperLog(operModul = "项目文件管理", operType = "删除文件", operDesc = "删除文件")
|
||||||
* 通过id删除
|
@ApiOperation(value = "删除文件", notes = "可以删除文件或者目录", httpMethod = "POST")
|
||||||
*
|
@RequestMapping(value = "/deleteFile", method = RequestMethod.POST)
|
||||||
* @param id
|
public Result<String> deleteFile(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
||||||
* @return
|
sjSafeEnvironmentFileService.deleteFile(sjSafeEnvironmentFile);
|
||||||
*/
|
return Result.ok();
|
||||||
@ApiOperation(value = "删除三江安全环保资料中心信息", notes = "删除三江安全环保资料中心信息", httpMethod = "POST")
|
|
||||||
@PostMapping(value = "/delete")
|
|
||||||
public Result<SjSafeEnvironmentFile> delete(@RequestBody String id) {
|
|
||||||
JSONObject jsonObject = JSON.parseObject(id, JSONObject.class);
|
|
||||||
id = String.valueOf(jsonObject.get("id"));
|
|
||||||
Result<SjSafeEnvironmentFile> result = new Result<SjSafeEnvironmentFile>();
|
|
||||||
SjSafeEnvironmentFile sjSafeEnvironmentFile = sjSafeEnvironmentFileService.getById(id);
|
|
||||||
if (sjSafeEnvironmentFile == null) {
|
|
||||||
result.error500("未找到对应实体");
|
|
||||||
} else {
|
|
||||||
boolean ok = sjSafeEnvironmentFileService.removeById(id);
|
|
||||||
if (ok) {
|
|
||||||
result.success("删除成功!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
@OperLog(operModul = "项目文件管理", operType = "文件移动", operDesc = "文件移动")
|
||||||
|
@ApiOperation(value = "文件移动", notes = "可以移动文件或者目录", httpMethod = "POST")
|
||||||
|
@RequestMapping(value = "/moveFile", method = RequestMethod.POST)
|
||||||
|
public Result<String> moveFile(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
||||||
|
sjSafeEnvironmentFileService.moveFile(sjSafeEnvironmentFile);
|
||||||
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@OperLog(operModul = "项目文件管理", operType = "批量文件移动", operDesc = "批量文件移动")
|
||||||
* 批量删除
|
@ApiOperation(value = "文件移动", notes = "可以移动文件或者目录", httpMethod = "POST")
|
||||||
*
|
@RequestMapping(value = "/batchmovefile", method = RequestMethod.POST)
|
||||||
* @param ids
|
public Result<String> batchMoveFile(@RequestBody List<SjSafeEnvironmentFile> list) {
|
||||||
* @return
|
for (SjSafeEnvironmentFile sjSafeEnvironmentFile : list) {
|
||||||
*/
|
sjSafeEnvironmentFileService.moveFile(sjSafeEnvironmentFile);
|
||||||
@ApiOperation(value = "批量删除三江安全环保资料中心信息", notes = "批量删除三江安全环保资料中心信息", httpMethod = "POST")
|
|
||||||
@ApiImplicitParam(name = "id", value = "三江安全环保资料中心ID字符串", paramType = "query", required = true, dataType = "String")
|
|
||||||
@PostMapping(value = "/deleteBatch")
|
|
||||||
public Result<SjSafeEnvironmentFile> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
|
||||||
Result<SjSafeEnvironmentFile> result = new Result<SjSafeEnvironmentFile>();
|
|
||||||
if (ids == null || "".equals(ids.trim())) {
|
|
||||||
result.error500("参数不识别!");
|
|
||||||
} else {
|
|
||||||
this.sjSafeEnvironmentFileService.removeByIds(Arrays.asList(ids.split(",")));
|
|
||||||
result.success("删除成功!");
|
|
||||||
}
|
}
|
||||||
return result;
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@ApiOperation(value = " 获取文件树", notes = "文件移动的时候需要用到该接口,用来展示目录树,展示机制为饱汉模式", httpMethod = "POST")
|
||||||
* 通过id查询
|
@ApiImplicitParams({
|
||||||
*
|
@ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String"),
|
||||||
* @param id
|
})
|
||||||
* @return
|
@PostMapping(value = "/getFileTree")
|
||||||
*/
|
public Result<TreeNode> getFileTree(@RequestBody Map<String, Object> map) {
|
||||||
@ApiOperation(value = "通过id查询三江安全环保资料中心信息", notes = "通过id查询三江安全环保资料中心信息", httpMethod = "GET")
|
Result<TreeNode> result = new Result<TreeNode>();
|
||||||
@ApiImplicitParam(name = "id", value = "三江安全环保资料中心ID", paramType = "query", required = true, dataType = "Integer")
|
QueryWrapper<SjSafeEnvironmentFile> queryWrapper = new QueryWrapper<>();
|
||||||
@GetMapping(value = "/queryById")
|
queryWrapper.lambda().eq(SjSafeEnvironmentFile::getProjectSn, MapUtils.getString(map, "projectSn"))
|
||||||
public Result<SjSafeEnvironmentFile> queryById(@RequestParam(name = "id", required = true) String id) {
|
.eq(SjSafeEnvironmentFile::getIsDir, "1");
|
||||||
Result<SjSafeEnvironmentFile> result = new Result<SjSafeEnvironmentFile>();
|
List<SjSafeEnvironmentFile> filePathList = sjSafeEnvironmentFileService.list(queryWrapper);
|
||||||
SjSafeEnvironmentFile sjSafeEnvironmentFile = sjSafeEnvironmentFileService.getById(id);
|
|
||||||
if (sjSafeEnvironmentFile == null) {
|
TreeNode resultTreeNode = new TreeNode();
|
||||||
result.error500("未找到对应实体");
|
resultTreeNode.setLabel("/");
|
||||||
} else {
|
long treeid = 0;
|
||||||
result.setResult(sjSafeEnvironmentFile);
|
for (int i = 0; i < filePathList.size(); i++) {
|
||||||
|
String filePath = filePathList.get(i).getFilePath() + filePathList.get(i).getFileName() + "/";
|
||||||
|
|
||||||
|
Queue<String> queue = new LinkedList<>();
|
||||||
|
|
||||||
|
String[] strArr = filePath.split("/");
|
||||||
|
for (int j = 0; j < strArr.length; j++) {
|
||||||
|
if (!"".equals(strArr[j]) && strArr[j] != null) {
|
||||||
|
queue.add(strArr[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (queue.size() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
resultTreeNode = insertTreeNode(resultTreeNode, "/", queue, treeid);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
}
|
result.setResult(resultTreeNode);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public TreeNode insertTreeNode(TreeNode treeNode, String filePath, Queue<String> nodeNameQueue, long treeid) {
|
||||||
* 导出excel
|
|
||||||
*
|
List<TreeNode> childrenTreeNodes = treeNode.getChildren();
|
||||||
* @param request
|
String currentNodeName = nodeNameQueue.peek();
|
||||||
* @param response
|
if (currentNodeName == null) {
|
||||||
*/
|
return treeNode;
|
||||||
@ApiOperation(value = "导出excel三江安全环保资料中心信息", notes = "导出excel三江安全环保资料中心信息", httpMethod = "POST")
|
|
||||||
@RequestMapping(value = "/exportXls")
|
|
||||||
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
|
|
||||||
// Step.1 组装查询条件
|
|
||||||
QueryWrapper<SjSafeEnvironmentFile> queryWrapper = null;
|
|
||||||
try {
|
|
||||||
String paramsStr = request.getParameter("paramsStr");
|
|
||||||
if (oConvertUtils.isNotEmpty(paramsStr)) {
|
|
||||||
String deString = URLDecoder.decode(paramsStr, "UTF-8");
|
|
||||||
SjSafeEnvironmentFile sjSafeEnvironmentFile = JSON.parseObject(deString, SjSafeEnvironmentFile.class);
|
|
||||||
queryWrapper = QueryGenerator.initQueryWrapper(sjSafeEnvironmentFile, request.getParameterMap());
|
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
Map<String, String> map = new HashMap<>();
|
||||||
e.printStackTrace();
|
filePath = filePath + currentNodeName + "/";
|
||||||
|
map.put("filePath", filePath);
|
||||||
|
if (!isExistPath(childrenTreeNodes, currentNodeName)) { //1、判断有没有该子节点,如果没有则插入
|
||||||
|
//插入
|
||||||
|
TreeNode resultTreeNode = new TreeNode();
|
||||||
|
resultTreeNode.setAttributes(map);
|
||||||
|
resultTreeNode.setLabel(nodeNameQueue.poll());
|
||||||
|
resultTreeNode.setId(treeid++);
|
||||||
|
childrenTreeNodes.add(resultTreeNode);
|
||||||
|
} else { //2、如果有,则跳过
|
||||||
|
nodeNameQueue.poll();
|
||||||
|
}
|
||||||
|
if (nodeNameQueue.size() != 0) {
|
||||||
|
for (int i = 0; i < childrenTreeNodes.size(); i++) {
|
||||||
|
TreeNode childrenTreeNode = childrenTreeNodes.get(i);
|
||||||
|
if (currentNodeName.equals(childrenTreeNode.getLabel())) {
|
||||||
|
childrenTreeNode = insertTreeNode(childrenTreeNode, filePath, nodeNameQueue, treeid);
|
||||||
|
childrenTreeNodes.remove(i);
|
||||||
|
childrenTreeNodes.add(childrenTreeNode);
|
||||||
|
treeNode.setChildren(childrenTreeNodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
treeNode.setChildren(childrenTreeNodes);
|
||||||
|
}
|
||||||
|
return treeNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Step.2 AutoPoi 导出Excel
|
public boolean isExistPath(List<TreeNode> childrenTreeNodes, String path) {
|
||||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
boolean isExistPath = false;
|
||||||
List<SjSafeEnvironmentFile> pageList = sjSafeEnvironmentFileService.list(queryWrapper);
|
|
||||||
//导出文件名称
|
|
||||||
mv.addObject(NormalExcelConstants.FILE_NAME, "三江安全环保资料中心列表");
|
|
||||||
mv.addObject(NormalExcelConstants.CLASS, SjSafeEnvironmentFile.class);
|
|
||||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("三江安全环保资料中心列表数据", "导出人:Jeecg", "导出信息"));
|
|
||||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
|
||||||
return mv;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过excel导入数据
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
* @param response
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "通过excel导入三江安全环保资料中心信息", notes = "通过excel导入三江安全环保资料中心信息", httpMethod = "POST")
|
|
||||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
||||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
||||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
||||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
||||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
||||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
|
||||||
ImportParams params = new ImportParams();
|
|
||||||
params.setTitleRows(2);
|
|
||||||
params.setHeadRows(1);
|
|
||||||
params.setNeedSave(true);
|
|
||||||
try {
|
try {
|
||||||
List<SjSafeEnvironmentFile> listSjSafeEnvironmentFiles = ExcelImportUtil.importExcel(file.getInputStream(), SjSafeEnvironmentFile.class, params);
|
for (int i = 0; i < childrenTreeNodes.size(); i++) {
|
||||||
for (SjSafeEnvironmentFile sjSafeEnvironmentFileExcel : listSjSafeEnvironmentFiles) {
|
if (path.equals(childrenTreeNodes.get(i).getLabel())) {
|
||||||
sjSafeEnvironmentFileService.save(sjSafeEnvironmentFileExcel);
|
isExistPath = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Result.ok("文件导入成功!数据行数:" + listSjSafeEnvironmentFiles.size());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
|
||||||
return Result.error("文件导入失败!");
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
file.getInputStream().close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
return isExistPath;
|
||||||
}
|
|
||||||
return Result.ok("文件导入失败!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package com.zhgd.xmgl.modules.sanjiang.entity;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
@ -11,7 +13,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
/**
|
/**
|
||||||
* @Description: 三江安全环保资料中心
|
* @Description: 三江安全环保资料中心
|
||||||
* @author: pds
|
* @author: pds
|
||||||
* @date: 2023-04-20
|
* @date: 2021-01-11
|
||||||
* @version: V1.0
|
* @version: V1.0
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ -24,8 +26,9 @@ public class SjSafeEnvironmentFile implements Serializable {
|
|||||||
* fileId
|
* fileId
|
||||||
*/
|
*/
|
||||||
@Excel(name = "fileId", width = 15)
|
@Excel(name = "fileId", width = 15)
|
||||||
@ApiModelProperty(value = "id")
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
private java.lang.Long id;
|
@ApiModelProperty(value = "fileId")
|
||||||
|
private java.lang.Long fileId;
|
||||||
/**
|
/**
|
||||||
* 项目SN
|
* 项目SN
|
||||||
*/
|
*/
|
||||||
@ -68,16 +71,7 @@ public class SjSafeEnvironmentFile implements Serializable {
|
|||||||
@Excel(name = "上传时间", width = 15)
|
@Excel(name = "上传时间", width = 15)
|
||||||
@ApiModelProperty(value = "上传时间")
|
@ApiModelProperty(value = "上传时间")
|
||||||
private java.lang.String uploadTime;
|
private java.lang.String uploadTime;
|
||||||
/**
|
|
||||||
* 父级ID
|
|
||||||
*/
|
|
||||||
@Excel(name = "父级ID", width = 15)
|
|
||||||
@ApiModelProperty(value = "父级ID")
|
|
||||||
private java.lang.Long parentId;
|
|
||||||
/**
|
|
||||||
* 文件大小
|
|
||||||
*/
|
|
||||||
@Excel(name = "文件大小", width = 15)
|
|
||||||
@ApiModelProperty(value = "文件大小")
|
@ApiModelProperty(value = "文件大小")
|
||||||
private java.lang.String fileSize;
|
private java.lang.String fileSize;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,22 @@
|
|||||||
package com.zhgd.xmgl.modules.sanjiang.mapper;
|
package com.zhgd.xmgl.modules.sanjiang.mapper;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile;
|
import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 三江安全环保资料中心
|
* @Description: 三江安全环保资料中心
|
||||||
* @author: pds
|
* @author: pds
|
||||||
* @date: 2023-04-20
|
* @date: 2021-01-11
|
||||||
* @version: V1.0
|
* @version: V1.0
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SjSafeEnvironmentFileMapper extends BaseMapper<SjSafeEnvironmentFile> {
|
public interface SjSafeEnvironmentFileMapper extends BaseMapper<SjSafeEnvironmentFile> {
|
||||||
|
|
||||||
|
void replaceProjectFilePath(@Param("filePath") String filePath, @Param("oldFilePath") String oldFilePath, @Param("projectSn") String projectSn);
|
||||||
|
|
||||||
|
void updateFilepathByFilepath(@Param("oldfilePath") String oldfilePath, @Param("newfilePath") String newfilePath, @Param("projectSn") String projectSn);
|
||||||
|
|
||||||
|
void updateFilepathByPathAndName(SjSafeEnvironmentFile sjSafeEnvironmentFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.zhgd.xmgl.modules.sanjiang.mapper.SjSafeEnvironmentFileMapper">
|
<mapper namespace="com.zhgd.xmgl.modules.sanjiang.mapper.SjSafeEnvironmentFileMapper">
|
||||||
|
<update id="replaceProjectFilePath">
|
||||||
|
UPDATE sj_safe_environment_file SET file_path=REPLACE(file_path, #{oldFilePath}, #{filePath})
|
||||||
|
WHERE file_path LIKE N'${oldFilePath}%' and project_sn = #{projectSn};
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateFilepathByFilepath">
|
||||||
|
UPDATE sj_safe_environment_file SET file_path=REPLACE(file_path, #{oldfilePath}, #{newfilePath})
|
||||||
|
WHERE file_path like N'${oldfilePath}%' and project_sn = #{projectSn};
|
||||||
|
</update>
|
||||||
|
<update id="updateFilepathByPathAndName">
|
||||||
|
UPDATE sj_safe_environment_file SET file_path=#{filePath}
|
||||||
|
WHERE file_id=#{fileId}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@ -3,12 +3,23 @@ package com.zhgd.xmgl.modules.sanjiang.service;
|
|||||||
import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile;
|
import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 三江安全环保资料中心
|
* @Description: 项目文件档案
|
||||||
* @author: pds
|
* @author: pds
|
||||||
* @date: 2023-04-20
|
* @date: 2021-01-11
|
||||||
* @version: V1.0
|
* @version: V1.0
|
||||||
*/
|
*/
|
||||||
public interface ISjSafeEnvironmentFileService extends IService<SjSafeEnvironmentFile> {
|
public interface ISjSafeEnvironmentFileService extends IService<SjSafeEnvironmentFile> {
|
||||||
|
|
||||||
|
void addProjectFile(SjSafeEnvironmentFile sjSafeEnvironmentFile);
|
||||||
|
|
||||||
|
void renamefile(SjSafeEnvironmentFile sjSafeEnvironmentFile);
|
||||||
|
|
||||||
|
void batchDeleteFile(List<SjSafeEnvironmentFile> list);
|
||||||
|
|
||||||
|
void deleteFile(SjSafeEnvironmentFile sjSafeEnvironmentFile);
|
||||||
|
|
||||||
|
void moveFile(SjSafeEnvironmentFile sjSafeEnvironmentFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,123 @@
|
|||||||
package com.zhgd.xmgl.modules.sanjiang.service.impl;
|
package com.zhgd.xmgl.modules.sanjiang.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||||
import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile;
|
import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile;
|
||||||
import com.zhgd.xmgl.modules.sanjiang.mapper.SjSafeEnvironmentFileMapper;
|
import com.zhgd.xmgl.modules.sanjiang.mapper.SjSafeEnvironmentFileMapper;
|
||||||
import com.zhgd.xmgl.modules.sanjiang.service.ISjSafeEnvironmentFileService;
|
import com.zhgd.xmgl.modules.sanjiang.service.ISjSafeEnvironmentFileService;
|
||||||
|
import com.zhgd.xmgl.util.MessageUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 三江安全环保资料中心
|
* @Description: 三江安全环保资料中心
|
||||||
* @author: pds
|
* @author: pds
|
||||||
* @date: 2023-04-20
|
* @date: 2021-01-11
|
||||||
* @version: V1.0
|
* @version: V1.0
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public class SjSafeEnvironmentFileServiceImpl extends ServiceImpl<SjSafeEnvironmentFileMapper, SjSafeEnvironmentFile> implements ISjSafeEnvironmentFileService {
|
public class SjSafeEnvironmentFileServiceImpl extends ServiceImpl<SjSafeEnvironmentFileMapper, SjSafeEnvironmentFile> implements ISjSafeEnvironmentFileService {
|
||||||
|
@Autowired
|
||||||
|
private SjSafeEnvironmentFileMapper sjSafeEnvironmentFileMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addProjectFile(SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
||||||
|
QueryWrapper<SjSafeEnvironmentFile> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.lambda().eq(SjSafeEnvironmentFile::getProjectSn, sjSafeEnvironmentFile.getProjectSn())
|
||||||
|
.eq(SjSafeEnvironmentFile::getFileName, sjSafeEnvironmentFile.getFileName())
|
||||||
|
.eq(SjSafeEnvironmentFile::getFilePath, sjSafeEnvironmentFile.getFilePath())
|
||||||
|
.eq(SjSafeEnvironmentFile::getIsDir, sjSafeEnvironmentFile.getIsDir());
|
||||||
|
int count = sjSafeEnvironmentFileMapper.selectCount(queryWrapper);
|
||||||
|
if (count > 0) {
|
||||||
|
if (sjSafeEnvironmentFile.getIsDir() == 1) {
|
||||||
|
throw new OpenAlertException(MessageUtil.get("nameExistErr"));
|
||||||
|
} else {
|
||||||
|
sjSafeEnvironmentFile.setFileName(sjSafeEnvironmentFile.getFileName() + "(1)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
sjSafeEnvironmentFile.setUploadTime(df.format(new Date()));
|
||||||
|
sjSafeEnvironmentFileMapper.insert(sjSafeEnvironmentFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renamefile(SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
||||||
|
SjSafeEnvironmentFile oldSjSafeEnvironmentFile = sjSafeEnvironmentFileMapper.selectById(sjSafeEnvironmentFile.getFileId());
|
||||||
|
QueryWrapper<SjSafeEnvironmentFile> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.lambda().eq(SjSafeEnvironmentFile::getProjectSn, oldSjSafeEnvironmentFile.getProjectSn())
|
||||||
|
.eq(SjSafeEnvironmentFile::getFileName, sjSafeEnvironmentFile.getFileName())
|
||||||
|
.eq(SjSafeEnvironmentFile::getFilePath, oldSjSafeEnvironmentFile.getFilePath())
|
||||||
|
.eq(SjSafeEnvironmentFile::getIsDir, oldSjSafeEnvironmentFile.getIsDir());
|
||||||
|
int count = sjSafeEnvironmentFileMapper.selectCount(queryWrapper);
|
||||||
|
if (count > 0) {
|
||||||
|
if (sjSafeEnvironmentFile.getIsDir() == 1) {
|
||||||
|
throw new OpenAlertException(MessageUtil.get("nameExistErr"));
|
||||||
|
} else {
|
||||||
|
sjSafeEnvironmentFile.setFileName(sjSafeEnvironmentFile.getFileName() + "(1)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String time = df.format(new Date());
|
||||||
|
if (1 == oldSjSafeEnvironmentFile.getIsDir()) {
|
||||||
|
SjSafeEnvironmentFile newSjSafeEnvironmentFile = new SjSafeEnvironmentFile();
|
||||||
|
newSjSafeEnvironmentFile.setFileId(oldSjSafeEnvironmentFile.getFileId());
|
||||||
|
newSjSafeEnvironmentFile.setUploadTime(time);
|
||||||
|
newSjSafeEnvironmentFile.setFileName(sjSafeEnvironmentFile.getFileName());
|
||||||
|
sjSafeEnvironmentFileMapper.updateById(newSjSafeEnvironmentFile);
|
||||||
|
sjSafeEnvironmentFileMapper.replaceProjectFilePath(oldSjSafeEnvironmentFile.getFilePath() + sjSafeEnvironmentFile.getFileName() + "/",
|
||||||
|
oldSjSafeEnvironmentFile.getFilePath() + oldSjSafeEnvironmentFile.getFileName() + "/", oldSjSafeEnvironmentFile.getProjectSn());
|
||||||
|
} else {
|
||||||
|
SjSafeEnvironmentFile newSjSafeEnvironmentFile = new SjSafeEnvironmentFile();
|
||||||
|
newSjSafeEnvironmentFile.setFileId(oldSjSafeEnvironmentFile.getFileId());
|
||||||
|
newSjSafeEnvironmentFile.setUploadTime(time);
|
||||||
|
newSjSafeEnvironmentFile.setFileName(sjSafeEnvironmentFile.getFileName());
|
||||||
|
sjSafeEnvironmentFileMapper.updateById(newSjSafeEnvironmentFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void batchDeleteFile(List<SjSafeEnvironmentFile> list) {
|
||||||
|
for (SjSafeEnvironmentFile sjSafeEnvironmentFile : list) {
|
||||||
|
deleteFile(sjSafeEnvironmentFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteFile(SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
||||||
|
SjSafeEnvironmentFile oldSjSafeEnvironmentFile = sjSafeEnvironmentFileMapper.selectById(sjSafeEnvironmentFile.getFileId());
|
||||||
|
if (1 == oldSjSafeEnvironmentFile.getIsDir()) {
|
||||||
|
String filePath = oldSjSafeEnvironmentFile.getFilePath() + oldSjSafeEnvironmentFile.getFileName() + "/";
|
||||||
|
QueryWrapper<SjSafeEnvironmentFile> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.lambda().eq(SjSafeEnvironmentFile::getProjectSn, oldSjSafeEnvironmentFile.getProjectSn())
|
||||||
|
.likeRight(SjSafeEnvironmentFile::getFilePath, filePath);
|
||||||
|
sjSafeEnvironmentFileMapper.delete(queryWrapper);
|
||||||
|
sjSafeEnvironmentFileMapper.deleteById(sjSafeEnvironmentFile.getFileId());
|
||||||
|
} else {
|
||||||
|
sjSafeEnvironmentFileMapper.deleteById(sjSafeEnvironmentFile.getFileId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveFile(SjSafeEnvironmentFile sjSafeEnvironmentFile) {
|
||||||
|
SjSafeEnvironmentFile oldSjSafeEnvironmentFile = sjSafeEnvironmentFileMapper.selectById(sjSafeEnvironmentFile.getFileId());
|
||||||
|
//移动根目录
|
||||||
|
sjSafeEnvironmentFileMapper.updateFilepathByPathAndName(sjSafeEnvironmentFile);
|
||||||
|
if (1 == oldSjSafeEnvironmentFile.getIsDir()) {
|
||||||
|
//移动子目录
|
||||||
|
String oldfilePath = oldSjSafeEnvironmentFile.getFilePath() + oldSjSafeEnvironmentFile.getFileName() + "/";
|
||||||
|
String newfilePath = sjSafeEnvironmentFile.getFilePath() + oldSjSafeEnvironmentFile.getFileName() + "/";
|
||||||
|
oldfilePath = oldfilePath.replace("\\", "\\\\\\\\");
|
||||||
|
oldfilePath = oldfilePath.replace("'", "\\'");
|
||||||
|
oldfilePath = oldfilePath.replace("%", "\\%");
|
||||||
|
oldfilePath = oldfilePath.replace("_", "\\_");
|
||||||
|
sjSafeEnvironmentFileMapper.updateFilepathByFilepath(oldfilePath, newfilePath, oldSjSafeEnvironmentFile.getProjectSn());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user