home il y a 2 ans
Parent
commit
ffd87f7eff

+ 10 - 2
hx-serve/file-serve/pom.xml → hx-api/file-serve-api/pom.xml

@@ -3,13 +3,13 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>hx-serve</artifactId>
+        <artifactId>hx-api</artifactId>
         <groupId>com.fjhx</groupId>
         <version>3.2.0</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
-    <artifactId>iot-management</artifactId>
+    <artifactId>file-serve-api</artifactId>
 
     <properties>
         <maven.compiler.source>8</maven.compiler.source>
@@ -18,6 +18,14 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.springblade</groupId>
+            <artifactId>blade-starter-mybatis</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.fjhx</groupId>
             <artifactId>hx-tool</artifactId>
         </dependency>

+ 1 - 0
hx-api/pom.xml

@@ -25,6 +25,7 @@
         <module>iot-management-api</module>
         <module>storage-api</module>
         <module>product-library-api</module>
+        <module>file-serve-api</module>
     </modules>
 
     <dependencyManagement>

+ 0 - 18
hx-serve/file-serve/src/main/java/com/fjhx/FileServeApplication.java

@@ -1,18 +0,0 @@
-package com.fjhx;
-
-import org.springblade.core.launch.BladeApplication;
-import org.springframework.cloud.client.SpringCloudApplication;
-
-/**
- * 杰生模块启动器
- */
-@SpringCloudApplication
-public class FileServeApplication {
-
-    private static final String APP_NAME = "file-serve";
-
-    public static void main(String[] args) {
-        BladeApplication.run(APP_NAME, FileServeApplication.class, args);
-    }
-
-}

+ 0 - 34
hx-serve/file-serve/src/main/java/com/fjhx/controller/FileInfoController.java

@@ -1,34 +0,0 @@
-package com.fjhx.controller;
-
-import com.fjhx.service.FileInfoService;
-import org.springblade.core.tool.api.R;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.util.Map;
-
-/**
- * <p>
- * 文件 前端控制器
- * </p>
- *
- * @author ${author}
- * @since 2022-07-07
- */
-@RestController
-public class FileInfoController {
-
-    @Autowired
-    private FileInfoService fileInfoService;
-
-    @PostMapping("/uploadFile")
-    public R uploadFile(@RequestParam("file") MultipartFile file) {
-        Map<String, String> result = fileInfoService.uploadFile(file);
-        return R.success(result);
-    }
-
-}
-

+ 0 - 66
hx-serve/file-serve/src/main/java/com/fjhx/entity/FileInfo.java

@@ -1,66 +0,0 @@
-package com.fjhx.entity;
-
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.fjhx.base.BaseEntity;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * <p>
- * 文件
- * </p>
- *
- * @author ${author}
- * @since 2022-07-07
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-public class FileInfo extends BaseEntity {
-
-
-    /**
-     * 文件名称
-     */
-    private String fileName;
-
-    /**
-     * 文件后缀
-     */
-    private String fileSuffix;
-
-    /**
-     * 文件类型
-     */
-    private String contentType;
-
-    /**
-     * 文件大小
-     */
-    private Long fileSize;
-
-    /**
-     * 文件大小
-     */
-    private String filePath;
-
-    /**
-     * 业务id
-     */
-    private Long businessId;
-
-    /**
-     * 业务类型
-     */
-    private Integer businessType;
-
-    /**
-     * 逻辑删除 0未删除 1已删除
-     */
-    @TableField(fill = FieldFill.INSERT)
-    @TableLogic
-    private Integer delFlag;
-
-
-}

+ 0 - 16
hx-serve/file-serve/src/main/java/com/fjhx/mapper/FileInfoMapper.java

@@ -1,16 +0,0 @@
-package com.fjhx.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.fjhx.entity.FileInfo;
-
-/**
- * <p>
- * 文件 Mapper 接口
- * </p>
- *
- * @author ${author}
- * @since 2022-07-07
- */
-public interface FileInfoMapper extends BaseMapper<FileInfo> {
-
-}

+ 0 - 5
hx-serve/file-serve/src/main/java/com/fjhx/mapper/FileInfoMapper.xml

@@ -1,5 +0,0 @@
-<?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.fjhx.mapper.FileInfoMapper">
-
-</mapper>

+ 0 - 40
hx-serve/file-serve/src/main/java/com/fjhx/service/FileInfoService.java

@@ -1,40 +0,0 @@
-package com.fjhx.service;
-
-import com.fjhx.base.BaseService;
-import com.fjhx.entity.FileInfo;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * <p>
- * 文件 服务类
- * </p>
- *
- * @author ${author}
- * @since 2022-07-07
- */
-public interface FileInfoService extends BaseService<FileInfo> {
-
-    /**
-     * 文件上传
-     */
-    Map<String, String> uploadFile(MultipartFile file);
-
-    /**
-     * 新增文件
-     */
-    void addFile(Long businessId, Integer businessType, List<FileInfo> fileInfoList);
-
-    /**
-     * 编辑文件
-     */
-    void updateFile(Long businessId, Integer businessType, List<FileInfo> fileInfoList);
-
-    /**
-     * 编辑文件
-     */
-    void deleteFile(Long businessId);
-
-}

+ 0 - 151
hx-serve/file-serve/src/main/java/com/fjhx/service/impl/FileInfoServiceImpl.java

@@ -1,151 +0,0 @@
-package com.fjhx.service.impl;
-
-import cn.hutool.core.io.FileUtil;
-import cn.hutool.core.lang.UUID;
-import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fjhx.base.BaseEntity;
-import com.fjhx.entity.FileInfo;
-import com.fjhx.mapper.FileInfoMapper;
-import com.fjhx.service.FileInfoService;
-import org.springblade.core.launch.BladeApplication;
-import org.springblade.core.log.exception.ServiceException;
-import org.springblade.core.tool.utils.DateUtil;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * <p>
- * 文件 服务实现类
- * </p>
- *
- * @author ${author}
- * @since 2022-07-07
- */
-@Service
-public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> implements FileInfoService {
-
-    @Value("${spring.application.name}")
-    public String applicationName;
-
-    @Override
-    public Map<String, String> uploadFile(MultipartFile file) {
-
-        String fileName = file.getOriginalFilename();
-        String suffix = FileUtil.getSuffix(fileName);
-
-        String path = getFilePath();
-        String filePath = path + UUID.randomUUID() + "." + suffix;
-
-        FileUtil.mkdir(path);
-        FileOutputStream fileOutputStream = null;
-        InputStream inputStream = null;
-
-        try {
-            inputStream = file.getInputStream();
-            fileOutputStream = new FileOutputStream(filePath);
-            int index;
-            byte[] bytes = new byte[1024];
-
-            while ((index = inputStream.read(bytes)) != -1) {
-                fileOutputStream.write(bytes, 0, index);
-                fileOutputStream.flush();
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-            throw new ServiceException("上传文件失败");
-        } finally {
-            try {
-                if (fileOutputStream != null) {
-                    fileOutputStream.close();
-                }
-                if (inputStream != null) {
-                    inputStream.close();
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-
-        FileInfo fileInfo = new FileInfo();
-        fileInfo.setFileName(fileName);
-        fileInfo.setFileSuffix(suffix);
-        fileInfo.setContentType(file.getContentType());
-        fileInfo.setFileSize(file.getSize());
-        fileInfo.setFilePath(filePath);
-        save(fileInfo);
-
-        Map<String, String> map = new HashMap<>();
-
-        map.put("fileName", fileName);
-        map.put("filePath", filePath);
-        map.put("id", fileInfo.getId().toString());
-
-        return map;
-    }
-
-    @Override
-    public void addFile(Long businessId, Integer businessType, List<FileInfo> fileInfoList) {
-        if (fileInfoList.size() == 0) {
-            return;
-        }
-        fileInfoList.forEach(item -> {
-            item.setBusinessId(businessId);
-            item.setBusinessType(businessType);
-        });
-        updateBatchById(fileInfoList);
-    }
-
-    @Override
-    public void updateFile(Long businessId, Integer businessType, List<FileInfo> fileInfoList) {
-
-        List<Long> excludeIdList = new ArrayList<>();
-
-        List<FileInfo> collect = fileInfoList.stream().filter(fileInfo -> {
-            if (ObjectUtil.isNotEmpty(fileInfo.getBusinessId())) {
-                excludeIdList.add(fileInfo.getId());
-                return false;
-            }
-            fileInfo.setId(businessId);
-            fileInfo.setBusinessType(businessType);
-            return true;
-        }).collect(Collectors.toList());
-
-        remove(Wrappers.<FileInfo>lambdaQuery()
-                .eq(FileInfo::getBusinessId, businessId)
-                .eq(FileInfo::getBusinessType, businessType)
-                .notIn(excludeIdList.size() > 0, BaseEntity::getId, collect));
-
-        if (collect.size() > 0) {
-            saveBatch(collect);
-        }
-
-    }
-
-    @Override
-    public void deleteFile(Long businessId) {
-        remove(FileInfo::getBusinessId, businessId);
-    }
-
-    private String getFilePath() {
-        StringJoiner joiner = new StringJoiner("/");
-        boolean localDev = BladeApplication.isLocalDev();
-        if (localDev) {
-            joiner.add("D:/hx");
-        } else {
-            joiner.add("/mnt/file");
-        }
-        joiner.add(applicationName).add(DateUtil.format(new Date(), "yyyy-MM/dd/"));
-
-        return joiner.toString();
-    }
-
-}

+ 0 - 13
hx-serve/file-serve/src/main/resources/application-dev.yml

@@ -1,13 +0,0 @@
-# 服务器端口
-server:
-  port: 8300
-logging:
-  level:
-    org.springframework.data.mongodb.core: DEBUG
-# 数据源配置
-spring:
-  # 数据库
-  datasource:
-    url: ${blade.datasource.file_serve.dev.url}
-    username: ${blade.datasource.file_serve.dev.username}
-    password: ${blade.datasource.file_serve.dev.password}

+ 0 - 12
hx-serve/file-serve/src/main/resources/application-prod.yml

@@ -1,12 +0,0 @@
-# 服务器端口
-server:
-  port: 8300
-
-# 数据源配置
-spring:
-  # 数据库
-  datasource:
-    url: ${blade.datasource.file_serve.prod.url}
-    username: ${blade.datasource.file_serve.prod.username}
-    password: ${blade.datasource.file_serve.prod.password}
-

+ 0 - 11
hx-serve/file-serve/src/main/resources/application-test.yml

@@ -1,11 +0,0 @@
-# 服务器端口
-server:
-  port: 8300
-
-# 数据源配置
-spring:
-  # 数据库
-  datasource:
-    url: ${blade.datasource.file_serve.test.url}
-    username: ${blade.datasource.file_serve.test.username}
-    password: ${blade.datasource.file_serve.test.password}

+ 6 - 1
hx-serve/pom.xml

@@ -21,7 +21,6 @@
     </properties>
 
     <modules>
-        <module>file-serve</module>
         <module>iot-management</module>
         <module>storage</module>
         <module>product-library</module>
@@ -70,6 +69,12 @@
                 <version>${hx.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>com.fjhx</groupId>
+                <artifactId>file-serve-api</artifactId>
+                <version>${hx.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>