zf
2023-09-14 395f924baaf24f421eb378f3730b28acaefd027c
Merge branch 'master' of https://sinanoaq.cn:8888/r/swspkmas into zf1
已修改5个文件
107 ■■■■■ 文件已修改
ruoyi-file/src/main/java/com/ruoyi/file/service/AttachmentService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-file/src/main/java/com/ruoyi/file/service/impl/AttachmentInfoServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-file/src/main/java/com/ruoyi/file/service/impl/AttachmentServiceImpl.java 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-file/src/main/resources/mapper/AttachmentInfoMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-file/src/main/java/com/ruoyi/file/service/AttachmentService.java
@@ -26,7 +26,11 @@
    Object saveBatchFileToPath(MultipartFile[] file, String module);
    Object saveBatchFileToPath(MultipartFile[] file, String module,Long businessId);
    void downloadForStream(HttpServletResponse response, String key);
    void downloadById(HttpServletResponse response, HttpServletRequest request, Long id);
    void updateBatchById(List<AttachmentInfo> attachmentInfo);
}
ruoyi-file/src/main/java/com/ruoyi/file/service/impl/AttachmentInfoServiceImpl.java
@@ -58,7 +58,7 @@
        AttachmentInfo attachmentInfo = new AttachmentInfo();
        attachmentInfo.setId(id);
        attachmentInfo.setUpdateTime(new Date());
        //attachmentInfo.setUpdateBy(SecurityUtils.getUsername());
        attachmentInfo.setUpdateBy(SecurityUtils.getUsername());
        attachmentInfo.setDelFlag(1);
        attachmentInfoMapper.updateById(attachmentInfo);
    }
ruoyi-file/src/main/java/com/ruoyi/file/service/impl/AttachmentServiceImpl.java
@@ -243,8 +243,90 @@
                attachmentInfo.setFileSize(file.getSize());
                attachmentInfo.setModule(module);
                attachmentInfo.setFileType(getType(suffix));
              /*  attachmentInfo.setCreateBy(SecurityUtils.getUsername());
                attachmentInfo.setUpdateBy(SecurityUtils.getUsername());*/
                attachmentInfo.setCreateBy(SecurityUtils.getUsername());
                attachmentInfo.setUpdateBy(SecurityUtils.getUsername());
                attachmentInfo.setUpdateTime(new Date());
                attachmentInfo.setCreateTime(new Date());
                attachmentInfoList.add(attachmentInfo);
            } catch (IOException e) {
                if (newFile != null && newFile.exists()) {
                    newFile.delete();
                }
                logger.error(ERROR_FORMATTER, "文件上传失败", e.getMessage());
                throw new ServiceException("文件上传失败");
            }
        }
        List<AttachmentInfo> detailList = attachmentInfoService.saveBatchAttachment(attachmentInfoList);
        return detailList;
    }
    @Override
    public Object saveBatchFileToPath(MultipartFile[] fileList, String module,Long businessId) {
        //获取对应模块路径
        String path;
        //获取对应模块根路径
        String dcPath;
        path = filePathProperties.getModule().get(module);
        dcPath = filePathProperties.getDcPath();
        List<AttachmentInfo> attachmentInfoList = new ArrayList<>();
        for (MultipartFile file : fileList) {
            String originalFilename = file.getOriginalFilename();
            if (StringUtils.isEmpty(originalFilename)) {
                logger.error(ERROR_FORMATTER,module, "文件不存在");
                throw new ServiceException("文件不存在");
            }
            if (StringUtils.isEmpty(path)) {
                logger.error(ERROR_FORMATTER, module, "文件路径不存在");
                throw new ServiceException("文件路径不存在");
            }
            assert originalFilename != null;
            LocalDateTime now = LocalDateTime.now();
            File newFile = null;
            try {
                //文件标识 UUID 如4d6873609b144945935ae84442711fd6
                String key = "";
                String suffix = "";
                if (originalFilename.contains(".mp3")) {
                    key = originalFilename;
                    suffix = "";
                } else {
                    key = UUID.randomUUID().toString().replace("-", "");
                    //文件后缀  包含.
                    suffix = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
                }
                path = path.replace("/", File.separator);
                //文件模块路径 如 2021/base/build/0421
                String modulePath = now.getYear() + path + now.format(DateTimeFormatter.ofPattern("MMdd"));
                //文件路径  如 2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀
                String newFilePath = modulePath + File.separator + key + suffix;
                //文件绝对路径 如 /home/img/2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀
                String localPath = dcPath + newFilePath;
                //文件访问路径 如 /upload/2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀
                String url = filePathProperties.getUrlRootPath() + newFilePath.replace(File.separator, "/");
                newFile = new File(localPath);
                if (!newFile.exists() && !newFile.mkdirs()) {
                    logger.error(ERROR_FORMATTER, newFilePath, "文件上传失败");
                    throw new ServiceException("文件上传失败");
                }
                //上传文件
                file.transferTo(newFile);
                //创建文件信息
                AttachmentInfo attachmentInfo = new AttachmentInfo();
                attachmentInfo.setDelFlag(0);
                attachmentInfo.setFileKey(key);
                attachmentInfo.setFileSuffix(suffix);
                attachmentInfo.setFilePath(localPath);
                attachmentInfo.setFileUrl(url);
                attachmentInfo.setBusinessId(businessId);
                attachmentInfo.setFileName(file.getOriginalFilename());
                attachmentInfo.setFileSize(file.getSize());
                attachmentInfo.setModule(module);
                attachmentInfo.setFileType(getType(suffix));
                attachmentInfo.setCreateBy(SecurityUtils.getUsername());
                attachmentInfo.setUpdateBy(SecurityUtils.getUsername());
                attachmentInfo.setUpdateTime(new Date());
                attachmentInfo.setCreateTime(new Date());
                attachmentInfoList.add(attachmentInfo);
@@ -319,4 +401,11 @@
            throw new ServiceException("文件不存在");
        }
    }
    @Override
    public void updateBatchById(List<AttachmentInfo> attachmentInfo) {
        boolean saveBatch = attachmentInfoService.updateBatchById(attachmentInfo);
        if (!saveBatch)
            throw new ServiceException("文件批量保存失败");
    }
}
ruoyi-file/src/main/resources/mapper/AttachmentInfoMapper.xml
@@ -3,11 +3,11 @@
<mapper namespace="com.ruoyi.file.mapper.AttachmentInfoMapper" >
  <insert id="saveBatch" useGeneratedKeys="true" keyProperty="id" >
    insert into attachment (file_key,file_path,file_url,file_name,file_suffix,file_desc,file_size,file_type,module,del_flag
    ,create_by,create_time,update_by,update_time)values
    ,create_by,create_time,update_by,update_time,business_id,remark)values
    <foreach collection="attachmentList" item="attachment" separator=",">
      (#{attachment.fileKey},#{attachment.filePath},#{attachment.fileUrl},#{attachment.fileName},#{attachment.fileSuffix},#{attachment.fileDesc},
       #{attachment.fileSize},#{attachment.fileType},#{attachment.module},#{attachment.delFlag},#{attachment.createBy},
       #{attachment.createTime},#{attachment.updateBy},#{attachment.updateTime})
       #{attachment.createTime},#{attachment.updateBy},#{attachment.updateTime},#{attachment.businessId},#{attachment.remark})
    </foreach>
  </insert>
  <update id="updateBusinessIdBatch">
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
@@ -7,6 +7,8 @@
    <resultMap type="SysUser" id="SysUserResult">
        <id     property="userId"       column="user_id"      />
        <result property="deptId"       column="dept_id"      />
        <result property="districtId"       column="district_id"      />
        <result property="unit"       column="unit"      />
        <result property="userName"     column="user_name"    />
        <result property="nickName"     column="nick_name"    />
        <result property="email"        column="email"        />
@@ -47,7 +49,7 @@
    </resultMap>
    
    <sql id="selectUserVo">
        select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
        select u.user_id, u.dept_id, u.district_id,u.unit,u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
        d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
        r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
        from sys_user u