diff --git a/src/main/java/com/zhgd/xmgl/modules/sanjiang/controller/SjSafeEnvironmentFileController.java b/src/main/java/com/zhgd/xmgl/modules/sanjiang/controller/SjSafeEnvironmentFileController.java index 3b4d8da42..d5b15f61c 100644 --- a/src/main/java/com/zhgd/xmgl/modules/sanjiang/controller/SjSafeEnvironmentFileController.java +++ b/src/main/java/com/zhgd/xmgl/modules/sanjiang/controller/SjSafeEnvironmentFileController.java @@ -1,276 +1,206 @@ package com.zhgd.xmgl.modules.sanjiang.controller; -import com.alibaba.fastjson.JSONObject; -import io.swagger.annotations.Api; -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.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.zhgd.annotation.OperLog; import com.zhgd.jeecg.common.api.vo.Result; -import com.zhgd.jeecg.common.system.query.QueryGenerator; -import com.zhgd.jeecg.common.util.oConvertUtils; +import com.zhgd.xmgl.base.TreeNode; import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile; import com.zhgd.xmgl.modules.sanjiang.service.ISjSafeEnvironmentFileService; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; - -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.apache.commons.collections.MapUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; -import org.springframework.web.servlet.ModelAndView; -import com.alibaba.fastjson.JSON; + +import java.util.*; /** * @Title: Controller * @Description: 三江安全环保资料中心 * @author: pds - * @date: 2023-04-20 + * @date: 2021-01-11 * @version: V1.0 */ @RestController @RequestMapping("/xmgl/sjSafeEnvironmentFile") @Slf4j -@Api(tags = "三江安全环保资料中心Controller") +@Api("ProjectFileController相关Api") public class SjSafeEnvironmentFileController { @Autowired private ISjSafeEnvironmentFileService sjSafeEnvironmentFileService; /** - * 分页列表查询 - * - * @param sjSafeEnvironmentFile - * @param pageNo - * @param pageSize - * @param req - * @return - */ - @ApiOperation(value = " 分页列表查询三江安全环保资料中心信息", notes = "分页列表查询三江安全环保资料中心信息", httpMethod = "GET") - @GetMapping(value = "/page") - public Result> queryPageList(SjSafeEnvironmentFile sjSafeEnvironmentFile, - @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, - @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, - HttpServletRequest req) { - Result> result = new Result>(); - QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(sjSafeEnvironmentFile, req.getParameterMap()); - Page page = new Page(pageNo, pageSize); - IPage pageList = sjSafeEnvironmentFileService.page(page, queryWrapper); - result.setSuccess(true); - result.setResult(pageList); - return result; - } + * 分页列表查询 + * @return + */ + @ApiOperation(value = " 列表查询项目文件档案信息", notes = "列表查询项目文件档案信息", httpMethod = "POST") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String"), + @ApiImplicitParam(name = "filePath", value = "路径", paramType = "query", required = true, dataType = "Integer"), + }) + @PostMapping(value = "/list") + public Result> getFileList(@RequestBody Map map) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(SjSafeEnvironmentFile::getProjectSn, MapUtils.getString(map, "projectSn")) + .eq(SjSafeEnvironmentFile::getFilePath, MapUtils.getString(map, "filePath")); + queryWrapper.orderByAsc("is_dir"); + List list = sjSafeEnvironmentFileService.list(queryWrapper); + return Result.success(list); + } - /** - * 列表查询 - * - * @param sjSafeEnvironmentFile - * @param req - * @return - */ - @ApiOperation(value = " 列表查询三江安全环保资料中心信息", notes = "列表查询三江安全环保资料中心信息", httpMethod = "GET") - @GetMapping(value = "/list") - public Result> queryList(SjSafeEnvironmentFile sjSafeEnvironmentFile, - HttpServletRequest req) { + /** + * 添加 + * @param sjSafeEnvironmentFile + * @return + */ + @OperLog(operModul = "项目文件管理", operType = "添加项目文件档案", operDesc = "添加项目文件档案") + @ApiOperation(value = " 添加项目文件档案信息", notes = "添加项目文件档案信息", httpMethod = "POST") + @PostMapping(value = "/add") + public Result add(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) { + sjSafeEnvironmentFileService.addProjectFile(sjSafeEnvironmentFile); + return Result.ok(); + } - QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(sjSafeEnvironmentFile, req.getParameterMap()); - return Result.success(sjSafeEnvironmentFileService.list(queryWrapper)); - } - /** - * 添加 - * - * @param sjSafeEnvironmentFile - * @return - */ - @ApiOperation(value = " 添加三江安全环保资料中心信息", notes = "添加三江安全环保资料中心信息", httpMethod = "POST") - @PostMapping(value = "/add") - public Result add(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) { - Result result = new Result(); - try { - sjSafeEnvironmentFileService.save(sjSafeEnvironmentFile); - result.success("添加成功!"); - } catch (Exception e) { - e.printStackTrace(); - log.info(e.getMessage()); - result.error500("操作失败"); - } - return result; - } + /** + * 编辑 + * + * @param sjSafeEnvironmentFile + * @return + */ + @OperLog(operModul = "项目文件管理", operType = "文件重命名", operDesc = "文件重命名") + @ApiOperation(value = "文件重命名", notes = "文件重命名", httpMethod = "POST") + @PostMapping(value = "/renameFile") + public Result edit(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) { + sjSafeEnvironmentFileService.renamefile(sjSafeEnvironmentFile); + return Result.ok(); + } - /** - * 编辑 - * - * @param sjSafeEnvironmentFile - * @return - */ - @ApiOperation(value = "编辑三江安全环保资料中心信息", notes = "编辑三江安全环保资料中心信息", httpMethod = "POST") - @PostMapping(value = "/edit") - public Result edit(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) { - Result result = new Result(); - SjSafeEnvironmentFile sjSafeEnvironmentFileEntity = sjSafeEnvironmentFileService.getById(sjSafeEnvironmentFile.getId()); - 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 batchDeleteFile(@RequestBody List list) { + sjSafeEnvironmentFileService.batchDeleteFile(list); + return Result.ok(); + } - /** - * 通过id删除 - * - * @param id - * @return - */ - @ApiOperation(value = "删除三江安全环保资料中心信息", notes = "删除三江安全环保资料中心信息", httpMethod = "POST") - @PostMapping(value = "/delete") - public Result delete(@RequestBody String id) { - JSONObject jsonObject = JSON.parseObject(id, JSONObject.class); - id = String.valueOf(jsonObject.get("id")); - Result result = new Result(); - SjSafeEnvironmentFile sjSafeEnvironmentFile = sjSafeEnvironmentFileService.getById(id); - if (sjSafeEnvironmentFile == null) { - result.error500("未找到对应实体"); - } else { - boolean ok = sjSafeEnvironmentFileService.removeById(id); - if (ok) { - result.success("删除成功!"); - } - } + @OperLog(operModul = "项目文件管理", operType = "删除文件", operDesc = "删除文件") + @ApiOperation(value = "删除文件", notes = "可以删除文件或者目录", httpMethod = "POST") + @RequestMapping(value = "/deleteFile", method = RequestMethod.POST) + public Result deleteFile(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) { + sjSafeEnvironmentFileService.deleteFile(sjSafeEnvironmentFile); + return Result.ok(); + } - return result; - } + @OperLog(operModul = "项目文件管理", operType = "文件移动", operDesc = "文件移动") + @ApiOperation(value = "文件移动", notes = "可以移动文件或者目录", httpMethod = "POST") + @RequestMapping(value = "/moveFile", method = RequestMethod.POST) + public Result moveFile(@RequestBody SjSafeEnvironmentFile sjSafeEnvironmentFile) { + sjSafeEnvironmentFileService.moveFile(sjSafeEnvironmentFile); + return Result.ok(); + } - /** - * 批量删除 - * - * @param ids - * @return - */ - @ApiOperation(value = "批量删除三江安全环保资料中心信息", notes = "批量删除三江安全环保资料中心信息", httpMethod = "POST") - @ApiImplicitParam(name = "id", value = "三江安全环保资料中心ID字符串", paramType = "query", required = true, dataType = "String") - @PostMapping(value = "/deleteBatch") - public Result deleteBatch(@RequestParam(name = "ids", required = true) String ids) { - Result result = new Result(); - if (ids == null || "".equals(ids.trim())) { - result.error500("参数不识别!"); - } else { - this.sjSafeEnvironmentFileService.removeByIds(Arrays.asList(ids.split(","))); - result.success("删除成功!"); - } - return result; - } + @OperLog(operModul = "项目文件管理", operType = "批量文件移动", operDesc = "批量文件移动") + @ApiOperation(value = "文件移动", notes = "可以移动文件或者目录", httpMethod = "POST") + @RequestMapping(value = "/batchmovefile", method = RequestMethod.POST) + public Result batchMoveFile(@RequestBody List list) { + for (SjSafeEnvironmentFile sjSafeEnvironmentFile : list) { + sjSafeEnvironmentFileService.moveFile(sjSafeEnvironmentFile); + } + return Result.ok(); + } - /** - * 通过id查询 - * - * @param id - * @return - */ - @ApiOperation(value = "通过id查询三江安全环保资料中心信息", notes = "通过id查询三江安全环保资料中心信息", httpMethod = "GET") - @ApiImplicitParam(name = "id", value = "三江安全环保资料中心ID", paramType = "query", required = true, dataType = "Integer") - @GetMapping(value = "/queryById") - public Result queryById(@RequestParam(name = "id", required = true) String id) { - Result result = new Result(); - SjSafeEnvironmentFile sjSafeEnvironmentFile = sjSafeEnvironmentFileService.getById(id); - if (sjSafeEnvironmentFile == null) { - result.error500("未找到对应实体"); - } else { - result.setResult(sjSafeEnvironmentFile); - result.setSuccess(true); - } - return result; - } + @ApiOperation(value = " 获取文件树", notes = "文件移动的时候需要用到该接口,用来展示目录树,展示机制为饱汉模式", httpMethod = "POST") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String"), + }) + @PostMapping(value = "/getFileTree") + public Result getFileTree(@RequestBody Map map) { + Result result = new Result(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(SjSafeEnvironmentFile::getProjectSn, MapUtils.getString(map, "projectSn")) + .eq(SjSafeEnvironmentFile::getIsDir, "1"); + List filePathList = sjSafeEnvironmentFileService.list(queryWrapper); - /** - * 导出excel - * - * @param request - * @param response - */ - @ApiOperation(value = "导出excel三江安全环保资料中心信息", notes = "导出excel三江安全环保资料中心信息", httpMethod = "POST") - @RequestMapping(value = "/exportXls") - public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) { - // Step.1 组装查询条件 - QueryWrapper 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) { - e.printStackTrace(); - } + TreeNode resultTreeNode = new TreeNode(); + resultTreeNode.setLabel("/"); + long treeid = 0; + for (int i = 0; i < filePathList.size(); i++) { + String filePath = filePathList.get(i).getFilePath() + filePathList.get(i).getFileName() + "/"; - //Step.2 AutoPoi 导出Excel - ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); - List 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; - } + Queue queue = new LinkedList<>(); - /** - * 通过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 fileMap = multipartRequest.getFileMap(); - for (Map.Entry entity : fileMap.entrySet()) { - MultipartFile file = entity.getValue();// 获取上传文件对象 - ImportParams params = new ImportParams(); - params.setTitleRows(2); - params.setHeadRows(1); - params.setNeedSave(true); - try { - List listSjSafeEnvironmentFiles = ExcelImportUtil.importExcel(file.getInputStream(), SjSafeEnvironmentFile.class, params); - for (SjSafeEnvironmentFile sjSafeEnvironmentFileExcel : listSjSafeEnvironmentFiles) { - sjSafeEnvironmentFileService.save(sjSafeEnvironmentFileExcel); - } - return Result.ok("文件导入成功!数据行数:" + listSjSafeEnvironmentFiles.size()); - } catch (Exception e) { - log.error(e.getMessage()); - return Result.error("文件导入失败!"); - } finally { - try { - file.getInputStream().close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - return Result.ok("文件导入失败!"); - } + 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.setResult(resultTreeNode); + return result; + } + + public TreeNode insertTreeNode(TreeNode treeNode, String filePath, Queue nodeNameQueue, long treeid) { + + List childrenTreeNodes = treeNode.getChildren(); + String currentNodeName = nodeNameQueue.peek(); + if (currentNodeName == null) { + return treeNode; + } + Map map = new HashMap<>(); + 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; + } + + public boolean isExistPath(List childrenTreeNodes, String path) { + boolean isExistPath = false; + try { + for (int i = 0; i < childrenTreeNodes.size(); i++) { + if (path.equals(childrenTreeNodes.get(i).getLabel())) { + isExistPath = true; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return isExistPath; + } } diff --git a/src/main/java/com/zhgd/xmgl/modules/sanjiang/entity/SjSafeEnvironmentFile.java b/src/main/java/com/zhgd/xmgl/modules/sanjiang/entity/SjSafeEnvironmentFile.java index 477353299..e359b89c2 100644 --- a/src/main/java/com/zhgd/xmgl/modules/sanjiang/entity/SjSafeEnvironmentFile.java +++ b/src/main/java/com/zhgd/xmgl/modules/sanjiang/entity/SjSafeEnvironmentFile.java @@ -2,6 +2,8 @@ package com.zhgd.xmgl.modules.sanjiang.entity; import java.io.Serializable; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import org.jeecgframework.poi.excel.annotation.Excel; @@ -11,7 +13,7 @@ import io.swagger.annotations.ApiModelProperty; /** * @Description: 三江安全环保资料中心 * @author: pds - * @date: 2023-04-20 + * @date: 2021-01-11 * @version: V1.0 */ @Data @@ -24,8 +26,9 @@ public class SjSafeEnvironmentFile implements Serializable { * fileId */ @Excel(name = "fileId", width = 15) - @ApiModelProperty(value = "id") - private java.lang.Long id; + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "fileId") + private java.lang.Long fileId; /** * 项目SN */ @@ -68,16 +71,7 @@ public class SjSafeEnvironmentFile implements Serializable { @Excel(name = "上传时间", width = 15) @ApiModelProperty(value = "上传时间") 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 = "文件大小") private java.lang.String fileSize; } diff --git a/src/main/java/com/zhgd/xmgl/modules/sanjiang/mapper/SjSafeEnvironmentFileMapper.java b/src/main/java/com/zhgd/xmgl/modules/sanjiang/mapper/SjSafeEnvironmentFileMapper.java index 4f2fe3ee1..933e17b49 100644 --- a/src/main/java/com/zhgd/xmgl/modules/sanjiang/mapper/SjSafeEnvironmentFileMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/sanjiang/mapper/SjSafeEnvironmentFileMapper.java @@ -1,16 +1,22 @@ package com.zhgd.xmgl.modules.sanjiang.mapper; -import org.apache.ibatis.annotations.Mapper; 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; /** * @Description: 三江安全环保资料中心 * @author: pds - * @date: 2023-04-20 + * @date: 2021-01-11 * @version: V1.0 */ @Mapper public interface SjSafeEnvironmentFileMapper extends BaseMapper { + 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); } diff --git a/src/main/java/com/zhgd/xmgl/modules/sanjiang/mapper/xml/SjSafeEnvironmentFileMapper.xml b/src/main/java/com/zhgd/xmgl/modules/sanjiang/mapper/xml/SjSafeEnvironmentFileMapper.xml index fa2f750ee..bdda18ddb 100644 --- a/src/main/java/com/zhgd/xmgl/modules/sanjiang/mapper/xml/SjSafeEnvironmentFileMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/sanjiang/mapper/xml/SjSafeEnvironmentFileMapper.xml @@ -1,5 +1,17 @@ + + UPDATE sj_safe_environment_file SET file_path=REPLACE(file_path, #{oldFilePath}, #{filePath}) + WHERE file_path LIKE N'${oldFilePath}%' and project_sn = #{projectSn}; + + + UPDATE sj_safe_environment_file SET file_path=REPLACE(file_path, #{oldfilePath}, #{newfilePath}) + WHERE file_path like N'${oldfilePath}%' and project_sn = #{projectSn}; + + + UPDATE sj_safe_environment_file SET file_path=#{filePath} + WHERE file_id=#{fileId} + diff --git a/src/main/java/com/zhgd/xmgl/modules/sanjiang/service/ISjSafeEnvironmentFileService.java b/src/main/java/com/zhgd/xmgl/modules/sanjiang/service/ISjSafeEnvironmentFileService.java index 88da192af..ae985c995 100644 --- a/src/main/java/com/zhgd/xmgl/modules/sanjiang/service/ISjSafeEnvironmentFileService.java +++ b/src/main/java/com/zhgd/xmgl/modules/sanjiang/service/ISjSafeEnvironmentFileService.java @@ -3,12 +3,23 @@ package com.zhgd.xmgl.modules.sanjiang.service; import com.zhgd.xmgl.modules.sanjiang.entity.SjSafeEnvironmentFile; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; + /** - * @Description: 三江安全环保资料中心 + * @Description: 项目文件档案 * @author: pds - * @date: 2023-04-20 + * @date: 2021-01-11 * @version: V1.0 */ public interface ISjSafeEnvironmentFileService extends IService { + void addProjectFile(SjSafeEnvironmentFile sjSafeEnvironmentFile); + + void renamefile(SjSafeEnvironmentFile sjSafeEnvironmentFile); + + void batchDeleteFile(List list); + + void deleteFile(SjSafeEnvironmentFile sjSafeEnvironmentFile); + + void moveFile(SjSafeEnvironmentFile sjSafeEnvironmentFile); } diff --git a/src/main/java/com/zhgd/xmgl/modules/sanjiang/service/impl/SjSafeEnvironmentFileServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/sanjiang/service/impl/SjSafeEnvironmentFileServiceImpl.java index 8ea66a404..2063b258e 100644 --- a/src/main/java/com/zhgd/xmgl/modules/sanjiang/service/impl/SjSafeEnvironmentFileServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/sanjiang/service/impl/SjSafeEnvironmentFileServiceImpl.java @@ -1,19 +1,123 @@ 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.mapper.SjSafeEnvironmentFileMapper; 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.transaction.annotation.Transactional; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; /** * @Description: 三江安全环保资料中心 * @author: pds - * @date: 2023-04-20 + * @date: 2021-01-11 * @version: V1.0 */ @Service +@Transactional(rollbackFor = Exception.class) public class SjSafeEnvironmentFileServiceImpl extends ServiceImpl implements ISjSafeEnvironmentFileService { + @Autowired + private SjSafeEnvironmentFileMapper sjSafeEnvironmentFileMapper; + @Override + public void addProjectFile(SjSafeEnvironmentFile sjSafeEnvironmentFile) { + QueryWrapper 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 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 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 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()); + } + } }