Ver Fonte

Merge branch 'fu-dev' of uskycloud/usky-cloud into system-165

fuyuchuan há 1 mês atrás
pai
commit
4c26b9b8c7
31 ficheiros alterados com 1211 adições e 561 exclusões
  1. 40 11
      base-modules/service-file/pom.xml
  2. 42 5
      base-modules/service-file/src/main/java/com/ruoyi/file/RuoYiFileApplication.java
  3. 82 82
      base-modules/service-file/src/main/java/com/ruoyi/file/config/MinioConfig.java
  4. 2 2
      base-modules/service-file/src/main/java/com/ruoyi/file/config/ResourcesConfig.java
  5. 19 0
      base-modules/service-file/src/main/java/com/ruoyi/file/config/WebConfig.java
  6. 58 0
      base-modules/service-file/src/main/java/com/ruoyi/file/controller/FilesController.java
  7. 47 47
      base-modules/service-file/src/main/java/com/ruoyi/file/controller/SysFileController.java
  8. 10 0
      base-modules/service-file/src/main/java/com/ruoyi/file/mapper/FilesMapper.java
  9. 42 42
      base-modules/service-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java
  10. 30 0
      base-modules/service-file/src/main/java/com/ruoyi/file/service/FileUploadResponse.java
  11. 20 0
      base-modules/service-file/src/main/java/com/ruoyi/file/service/FilesService.java
  12. 227 0
      base-modules/service-file/src/main/java/com/ruoyi/file/service/FilesServiceImpl.java
  13. 44 0
      base-modules/service-file/src/main/java/com/ruoyi/file/service/FilesUpload.java
  14. 20 20
      base-modules/service-file/src/main/java/com/ruoyi/file/service/ISysFileService.java
  15. 50 50
      base-modules/service-file/src/main/java/com/ruoyi/file/service/LocalSysFileServiceImpl.java
  16. 202 202
      base-modules/service-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java
  17. 1 1
      base-modules/service-file/src/main/resources/bootstrap.yml
  18. 5 0
      base-modules/service-file/src/main/resources/mapper/file/FilesMapper.xml
  19. 39 18
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/controller/web/MceReceiveController.java
  20. 2 1
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/controller/web/SysUserController.java
  21. 2 1
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/mapper/SysRoleMapper.java
  22. 4 4
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/mapper/SysUserRoleMapper.java
  23. 1 1
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/ISysRoleService.java
  24. 6 0
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/MceReceiveService.java
  25. 65 6
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/MceReceiveServiceImpl.java
  26. 5 4
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysRoleServiceImpl.java
  27. 6 6
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysUserServiceImpl.java
  28. 25 11
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysUserTenantServiceImpl.java
  29. 56 0
      base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/vo/MceReceiveResponseVO.java
  30. 7 7
      base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysRoleMapper.xml
  31. 52 40
      base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysUserRoleMapper.xml

+ 40 - 11
base-modules/service-file/pom.xml

@@ -1,10 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xmlns="http://maven.apache.org/POM/4.0.0"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" 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>
-        <groupId>com.usky</groupId>
         <artifactId>base-modules</artifactId>
+        <groupId>com.usky</groupId>
         <version>0.0.1</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
@@ -48,11 +46,11 @@
         </dependency>
         
         <!-- Minio -->
-        <dependency>
-            <groupId>io.minio</groupId>
-            <artifactId>minio</artifactId>
-            <version>${minio.version}</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>io.minio</groupId>-->
+<!--            <artifactId>minio</artifactId>-->
+<!--            <version>${minio.version}</version>-->
+<!--        </dependency>-->
         
         <!-- RuoYi Api System -->
         <dependency>
@@ -72,7 +70,23 @@
         </dependency>
         <dependency>
             <groupId>com.usky</groupId>
-            <artifactId>ruoyi-common-core</artifactId>
+            <artifactId>common-cloud-starter</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.usky</groupId>
+            <artifactId>ruoyi-common-swagger</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>2.1.4</version>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>runtime</scope>
         </dependency>
 
     </dependencies>
@@ -92,7 +106,22 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>com.github.shalousun</groupId>
+                <artifactId>smart-doc-maven-plugin</artifactId>
+                <version>2.1.1</version>
+                <configuration>
+                    <!--指定生成文档的使用的配置文件,配置文件放在自己的项目中-->
+                    <configFile>./src/main/resources/smart-doc.json</configFile>
+                    <!--指定项目名称-->
+                    <projectName>test</projectName>
+                    <!--                    <excludes>-->
+                    <!--                        <exclude>com.bizmatics:product-service-provider</exclude>-->
+                    <!--                        <exclude>cn.afterturn:easypoi-web</exclude>-->
+                    <!--                    </excludes>-->
+                </configuration>
+            </plugin>
         </plugins>
     </build>
-   
+
 </project>

+ 42 - 5
base-modules/service-file/src/main/java/com/ruoyi/file/RuoYiFileApplication.java

@@ -1,21 +1,58 @@
 package com.ruoyi.file;
 
+import org.mybatis.spring.annotation.MapperScan;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.core.env.Environment;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 
 /**
  * 文件服务
  * 
  * @author ruoyi
  */
+//@EnableCustomSwagger2
+//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
+//public class RuoYiFileApplication
+//{
+//    public static void main(String[] args)
+//    {
+//        SpringApplication.run(RuoYiFileApplication.class, args);
+//    }
+//}
+
+
 @EnableCustomSwagger2
-@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
+@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
+@EnableFeignClients(basePackages = {"com.ruoyi"})
+@MapperScan(value = "com.ruoyi.file.mapper")
+@ComponentScan(basePackages = {"com.ruoyi"})
+@SpringBootApplication
 public class RuoYiFileApplication
 {
-    public static void main(String[] args)
-    {
-        SpringApplication.run(RuoYiFileApplication.class, args);
+    private static final Logger LOGGER = LoggerFactory.getLogger(RuoYiFileApplication.class);
+
+    public static void main(String[] args) throws UnknownHostException {
+        ConfigurableApplicationContext application = SpringApplication.run(RuoYiFileApplication.class, args);
+        Environment env = application.getEnvironment();
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        String port = env.getProperty("server.port");
+        String path = env.getProperty("server.servlet.context-path");
+        LOGGER.info("\n----------------------------------------------------------\n\t" +
+                "Application is running! Access URLs:\n\t" +
+                "Local: \t\thttp://localhost:" + port + (null==path?"":path) + "/\n\t" +
+                "External: \thttp://" + ip + ":" + port + (null==path?"":path) + "/\n\t" +
+                "Api: \t\thttp://" + ip + ":" + port + (null==path?"":path) + "/swagger-ui/index.html\n\t" +
+                "----------------------------------------------------------");
     }
-}
+}

+ 82 - 82
base-modules/service-file/src/main/java/com/ruoyi/file/config/MinioConfig.java

@@ -1,82 +1,82 @@
-package com.ruoyi.file.config;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import io.minio.MinioClient;
-
-/**
- * Minio 配置信息
- *
- * @author ruoyi
- */
-@Configuration
-@ConfigurationProperties(prefix = "minio")
-public class MinioConfig
-{
-    /**
-     * 服务地址
-     */
-    private String url;
-
-    /**
-     * 用户名
-     */
-    private String accessKey;
-
-    /**
-     * 密码
-     */
-    private String secretKey;
-
-    /**
-     * 存储桶名称
-     */
-    private String bucketName;
-
-    public String getUrl()
-    {
-        return url;
-    }
-
-    public void setUrl(String url)
-    {
-        this.url = url;
-    }
-
-    public String getAccessKey()
-    {
-        return accessKey;
-    }
-
-    public void setAccessKey(String accessKey)
-    {
-        this.accessKey = accessKey;
-    }
-
-    public String getSecretKey()
-    {
-        return secretKey;
-    }
-
-    public void setSecretKey(String secretKey)
-    {
-        this.secretKey = secretKey;
-    }
-
-    public String getBucketName()
-    {
-        return bucketName;
-    }
-
-    public void setBucketName(String bucketName)
-    {
-        this.bucketName = bucketName;
-    }
-
-    @Bean
-    public MinioClient getMinioClient()
-    {
-        return MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
-    }
-}
+//package com.ruoyi.file.config;
+//
+//import org.springframework.boot.context.properties.ConfigurationProperties;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import io.minio.MinioClient;
+//
+///**
+// * Minio 配置信息
+// *
+// * @author ruoyi
+// */
+//@Configuration
+//@ConfigurationProperties(prefix = "minio")
+//public class MinioConfig
+//{
+//    /**
+//     * 服务地址
+//     */
+//    private String url;
+//
+//    /**
+//     * 用户名
+//     */
+//    private String accessKey;
+//
+//    /**
+//     * 密码
+//     */
+//    private String secretKey;
+//
+//    /**
+//     * 存储桶名称
+//     */
+//    private String bucketName;
+//
+//    public String getUrl()
+//    {
+//        return url;
+//    }
+//
+//    public void setUrl(String url)
+//    {
+//        this.url = url;
+//    }
+//
+//    public String getAccessKey()
+//    {
+//        return accessKey;
+//    }
+//
+//    public void setAccessKey(String accessKey)
+//    {
+//        this.accessKey = accessKey;
+//    }
+//
+//    public String getSecretKey()
+//    {
+//        return secretKey;
+//    }
+//
+//    public void setSecretKey(String secretKey)
+//    {
+//        this.secretKey = secretKey;
+//    }
+//
+//    public String getBucketName()
+//    {
+//        return bucketName;
+//    }
+//
+//    public void setBucketName(String bucketName)
+//    {
+//        this.bucketName = bucketName;
+//    }
+//
+//    @Bean
+//    public MinioClient getMinioClient()
+//    {
+//        return MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
+//    }
+//}

+ 2 - 2
base-modules/service-file/src/main/java/com/ruoyi/file/config/ResourcesConfig.java

@@ -9,7 +9,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
 /**
  * 通用映射配置
- * 
+ *
  * @author ruoyi
  */
 @Configuration
@@ -34,7 +34,7 @@ public class ResourcesConfig implements WebMvcConfigurer
         registry.addResourceHandler(localFilePrefix + "/**")
                 .addResourceLocations("file:" + localFilePath + File.separator);
     }
-    
+
     /**
      * 开启跨域
      */

+ 19 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/config/WebConfig.java

@@ -0,0 +1,19 @@
+package com.ruoyi.file.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.format.FormatterRegistry;
+import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import java.time.format.DateTimeFormatter;
+
+@Configuration
+public class WebConfig implements WebMvcConfigurer {
+
+    @Override
+    public void addFormatters(FormatterRegistry registry) {
+        DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
+        registrar.setDateTimeFormatter(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        registrar.registerFormatters(registry);
+    }
+}

+ 58 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/controller/FilesController.java

@@ -0,0 +1,58 @@
+package com.ruoyi.file.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.file.service.FileUploadResponse;
+import com.ruoyi.file.service.FilesUpload;
+import com.ruoyi.file.service.FilesService;
+import com.usky.common.core.bean.CommonPage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.time.LocalDateTime;
+
+
+@RestController
+//@RequestMapping("/files")
+public class FilesController {
+
+    @Autowired
+    private FilesService filesService;
+
+    @PostMapping("/upload")
+    public R<FileUploadResponse> upload(@RequestParam MultipartFile file) {
+        // 获取上传文件
+        FileUploadResponse response = filesService.upload(file);
+        return R.ok(response);
+    }
+
+
+    @DeleteMapping("/delete/{id}")
+    public R<Void> delete(@PathVariable Integer id) {
+        try {
+            filesService.deleteFile(id);
+            return R.ok();
+        } catch (Exception e) {
+            return R.fail(e.getMessage()); // 删除失败,返回错误信息
+        }
+    }
+
+    @GetMapping("/query")
+    public R<CommonPage<FilesUpload>> queryFiles(
+            @RequestParam(required = false) String filesName,
+            @RequestParam(required = false) LocalDateTime startTime,
+            @RequestParam(required = false) LocalDateTime endTime,
+            @RequestParam(required = false) Boolean isDeleted,
+            @RequestParam(required = false) String fileType,
+            @RequestParam int current,
+            @RequestParam int size) {
+
+        // 调用服务层方法
+        CommonPage<FilesUpload> resultPage = filesService.queryFiles(filesName, startTime, endTime, isDeleted, fileType, current, size);
+
+        // 返回封装好的分页结果
+        return R.ok(resultPage);
+    }
+}

+ 47 - 47
base-modules/service-file/src/main/java/com/ruoyi/file/controller/SysFileController.java

@@ -1,47 +1,47 @@
-package com.ruoyi.file.controller;
-
-import com.ruoyi.common.core.domain.R;
-import com.usky.system.domain.SysFileVO;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-import com.ruoyi.file.service.ISysFileService;
-import com.ruoyi.common.core.utils.file.FileUtils;
-
-/**
- * 文件请求处理
- * @author ruoyi
- */
-@RestController
-public class SysFileController
-{
-    private static final Logger log = LoggerFactory.getLogger(SysFileController.class);
-
-    @Autowired
-    private ISysFileService sysFileService;
-
-    /**
-     * 文件上传请求
-     */
-    @PostMapping("upload")
-    public R<SysFileVO> upload(MultipartFile file)
-    {
-        try
-        {
-            // 上传并返回访问地址
-            String url = sysFileService.uploadFile(file);
-            SysFileVO sysFile = new SysFileVO();
-            sysFile.setName(FileUtils.getName(url));
-            sysFile.setUrl(url);
-            return R.ok(sysFile);
-        }
-        catch (Exception e)
-        {
-            log.error("上传文件失败", e);
-            return R.fail(e.getMessage());
-        }
-    }
-}
+//package com.ruoyi.file.controller;
+//
+//import com.ruoyi.common.core.domain.R;
+//import com.usky.system.domain.SysFileVO;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.web.bind.annotation.PostMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//import org.springframework.web.multipart.MultipartFile;
+//import com.ruoyi.file.service.ISysFileService;
+//import com.ruoyi.common.core.utils.file.FileUtils;
+//
+///**
+// * 文件请求处理
+// * @author ruoyi
+// */
+//@RestController
+//public class SysFileController
+//{
+//    private static final Logger log = LoggerFactory.getLogger(SysFileController.class);
+//
+//    @Autowired
+//    private ISysFileService sysFileService;
+//
+//    /**
+//     * 文件上传请求
+//     */
+//    @PostMapping("upload")
+//    public R<SysFileVO> upload(MultipartFile file)
+//    {
+//        try
+//        {
+//            // 上传并返回访问地址
+//            String url = sysFileService.uploadFile(file);
+//            SysFileVO sysFile = new SysFileVO();
+//            sysFile.setName(FileUtils.getName(url));
+//            sysFile.setUrl(url);
+//            return R.ok(sysFile);
+//        }
+//        catch (Exception e)
+//        {
+//            log.error("上传文件失败", e);
+//            return R.fail(e.getMessage());
+//        }
+//    }
+//}

+ 10 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/mapper/FilesMapper.java

@@ -0,0 +1,10 @@
+package com.ruoyi.file.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.file.service.FilesUpload;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface FilesMapper extends BaseMapper<FilesUpload> {
+
+}

+ 42 - 42
base-modules/service-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java

@@ -1,42 +1,42 @@
-package com.ruoyi.file.service;
-
-import org.apache.commons.io.FilenameUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-import com.github.tobato.fastdfs.domain.fdfs.StorePath;
-import com.github.tobato.fastdfs.service.FastFileStorageClient;
-
-/**
- * FastDFS 文件存储
- * 
- * @author ruoyi
- */
-@Service
-public class FastDfsSysFileServiceImpl implements ISysFileService
-{
-    /**
-     * 域名或本机访问地址
-     */
-    @Value("${fdfs.domain}")
-    public String domain;
-
-    @Autowired
-    private FastFileStorageClient storageClient;
-
-    /**
-     * FastDfs文件上传接口
-     * 
-     * @param file 上传的文件
-     * @return 访问地址
-     * @throws Exception
-     */
-    @Override
-    public String uploadFile(MultipartFile file) throws Exception
-    {
-        StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),
-                FilenameUtils.getExtension(file.getOriginalFilename()), null);
-        return domain + "/" + storePath.getFullPath();
-    }
-}
+//package com.ruoyi.file.service;
+//
+//import org.apache.commons.io.FilenameUtils;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.stereotype.Service;
+//import org.springframework.web.multipart.MultipartFile;
+//import com.github.tobato.fastdfs.domain.fdfs.StorePath;
+//import com.github.tobato.fastdfs.service.FastFileStorageClient;
+//
+///**
+// * FastDFS 文件存储
+// *
+// * @author ruoyi
+// */
+//@Service
+//public class FastDfsSysFileServiceImpl implements ISysFileService
+//{
+//    /**
+//     * 域名或本机访问地址
+//     */
+//    @Value("${fdfs.domain}")
+//    public String domain;
+//
+//    @Autowired
+//    private FastFileStorageClient storageClient;
+//
+//    /**
+//     * FastDfs文件上传接口
+//     *
+//     * @param file 上传的文件
+//     * @return 访问地址
+//     * @throws Exception
+//     */
+//    @Override
+//    public String uploadFile(MultipartFile file) throws Exception
+//    {
+//        StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),
+//                FilenameUtils.getExtension(file.getOriginalFilename()), null);
+//        return domain + "/" + storePath.getFullPath();
+//    }
+//}

+ 30 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/service/FileUploadResponse.java

@@ -0,0 +1,30 @@
+package com.ruoyi.file.service;
+
+import lombok.Data;
+
+@Data
+public class FileUploadResponse {
+    private String name;
+    private String url;
+
+    public FileUploadResponse(String name, String url) {
+        this.name = name;
+        this.url = url;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+}

+ 20 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/service/FilesService.java

@@ -0,0 +1,20 @@
+package com.ruoyi.file.service;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.usky.common.core.bean.CommonPage;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.time.LocalDateTime;
+
+public interface FilesService extends IService<FilesUpload> {
+    // 修改返回类型为 FileUploadResponse
+    FileUploadResponse upload(MultipartFile file);
+
+    // 删除文件
+    void deleteFile(Integer id);
+
+    // 查询方法
+    CommonPage<FilesUpload> queryFiles(String filesName, LocalDateTime startTime, LocalDateTime endTime, Boolean isDeleted, String fileType, int current, int size);
+}

+ 227 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/service/FilesServiceImpl.java

@@ -0,0 +1,227 @@
+package com.ruoyi.file.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.file.mapper.FilesMapper;
+import com.usky.common.core.bean.CommonPage;
+import com.usky.common.security.utils.SecurityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+@Service
+public class FilesServiceImpl extends ServiceImpl<FilesMapper, FilesUpload> implements FilesService {
+    @Value("${file.path}")
+    private String filesUploadPath;//获取文件路径
+
+    @Value("${file.domain}")
+    private String filesUploadDomain;//文件域名
+
+    @Value("${file.prefix}")
+    private String filesPrefix;//文件前缀
+
+
+
+    @Override
+    public FileUploadResponse upload(MultipartFile file) {
+
+        // 获取当前登录用户昵称(如果可用)
+        String userName = SecurityUtils.getUsername();
+
+        // 文件夹路径名称
+        String originalFilename = file.getOriginalFilename();
+
+        //文件大小
+        double size = file.getSize() / (1024.0);
+
+        // 获取当前日期时间
+        LocalDateTime now = LocalDateTime.now();
+        String timestamp = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
+
+        //文件类型
+        String type = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();
+
+        // 按照年月创建文件夹
+        String yearMonth = now.format(DateTimeFormatter.ofPattern("yyyyMM"));
+        // 获取每月递增值
+        int monthIncrement = getMonthIncrement(yearMonth);
+        // 新文件名格式:时间戳+每月递增值+文件类型
+        String fileUuid = timestamp + "A" + String.format("%04d", monthIncrement) + "." + type;
+
+        // 将相对路径转化为绝对路径
+        String destPath = filesUploadPath + "/" + yearMonth;
+
+        // 新的文件地址,绝对路径+新的文件名称
+        File uploadFile = new File(destPath + "/" + fileUuid);
+
+        // 判断配置的文件目录是否存在,若不存在则创建一个新的文件目录
+        File parentFile = uploadFile.getParentFile();
+        if (!parentFile.exists()) {
+            parentFile.mkdirs();
+        }
+
+        try {
+            // 存储文件到本地磁盘
+            file.transferTo(uploadFile);
+
+            // 设置文件url
+            String url = filesUploadDomain + filesPrefix + "/" + yearMonth + "/" + fileUuid;
+
+            // 将文件存储到数据库
+            FilesUpload saveFile = new FilesUpload();
+            saveFile.setFilesName(originalFilename);
+            saveFile.setName(fileUuid);
+            saveFile.setPath(destPath);
+            saveFile.setType(type);
+            saveFile.setSize(size); // (单位:KB)
+            saveFile.setUrl(url);
+            saveFile.setEnable(true);
+            saveFile.setIsDelete(0);
+            saveFile.setCreateBy(userName);
+            saveFile.setCreateTime(LocalDateTime.now());
+            saveFile.setUpdateBy(null);
+            saveFile.setUpdateTime(null);
+            // 保存操作
+            save(saveFile);
+
+            // 返回 FileUploadResponse 对象
+            return new FileUploadResponse(originalFilename, url);
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * 获取每月递增值
+     * @param yearMonth 年月(格式:yyyyMM)
+     * @return 递增值
+     */
+    private int getMonthIncrement(String yearMonth) {
+        // 目标文件夹路径
+        String destPath = filesUploadPath + "/" + yearMonth;
+        File folder = new File(destPath);
+
+        // 如果文件夹不存在,则递增值从1开始
+        if (!folder.exists()) {
+            folder.mkdirs();
+            return 1;
+        }
+
+        // 获取文件夹中已有的文件数量
+        File[] files = folder.listFiles();
+        if (files == null || files.length == 0) {
+            return 1;
+        }
+
+        // 递增值为文件夹中现有文件数量 + 1
+        return files.length + 1;
+    }
+
+    @Override
+    public void deleteFile(Integer id) {
+        try {
+            // 根据 id 查询文件信息
+            FilesUpload file = getById(id);
+            if (file == null) {
+                throw new RuntimeException("文件不存在,无法删除");
+            }
+
+            // 删除本地文件
+            String filePath = file.getPath() + "/" + file.getName();
+            File localFile = new File(filePath);
+            if (localFile.exists()) {
+                if (!localFile.delete()) {
+                    throw new RuntimeException("文件删除失败");
+                }
+            }
+
+            // 更新数据库记录
+            FilesUpload updateFile = new FilesUpload();
+            updateFile.setId(file.getId());
+            updateFile.setFilesName(file.getFilesName());
+            updateFile.setName(file.getName());
+            updateFile.setPath(file.getPath());
+            updateFile.setType(file.getType());
+            updateFile.setSize(file.getSize());
+            updateFile.setUrl(file.getUrl());
+            updateFile.setEnable(false);
+            updateFile.setIsDelete(1); // 设置为已删除
+            updateFile.setCreateBy(file.getCreateBy());
+            updateFile.setCreateTime(file.getCreateTime()); // 保留原始的 createTime
+            updateFile.setUpdateBy(file.getUpdateBy());
+            updateFile.setUpdateTime(LocalDateTime.now());
+
+            // 提交更新到数据库
+            updateById(updateFile); // 调用 updateById 方法更新数据库记录
+        } catch (Exception e) {
+            throw new RuntimeException("删除文件失败:" + e.getMessage());
+        }
+    }
+
+    @Override
+    public CommonPage<FilesUpload> queryFiles(String filesName, LocalDateTime startTime, LocalDateTime endTime, Boolean isDeleted, String fileType, int current, int size) {
+        QueryWrapper<FilesUpload> queryWrapper = new QueryWrapper<>();
+
+        // 默认查询未删除的文件
+        if (isDeleted == null) {
+            queryWrapper.eq("is_delete", 0);
+        } else {
+            queryWrapper.eq("is_delete", isDeleted ? 1 : 0);
+        }
+
+        if (filesName != null && !filesName.isEmpty()) {
+            queryWrapper.like("files_name", filesName);
+        }
+
+        if (startTime != null && endTime != null) {
+            queryWrapper.ge("create_time", startTime); // 大于等于起始时间
+            queryWrapper.le("create_time", endTime);   // 小于等于结束时间
+        } else if (startTime != null) {
+            queryWrapper.ge("create_time", startTime); // 只有起始时间
+        } else if (endTime != null) {
+            queryWrapper.le("create_time", endTime);   // 只有结束时间
+        }
+
+        if (fileType != null && !fileType.isEmpty()) {
+            queryWrapper.eq("type", fileType);
+        }
+
+        // 按照创建时间倒序排列
+        queryWrapper.orderByDesc("create_time");
+
+        // 创建分页请求对象
+        Page<FilesUpload> page = new Page<>(current, size);
+
+        // 执行分页查询
+        IPage<FilesUpload> iPage = baseMapper.selectPage(page, queryWrapper);
+
+        // 将 MyBatis Plus 的 IPage 转换为 CommonPage
+        CommonPage<FilesUpload> commonPage = new CommonPage<>();
+        commonPage.setRecords(iPage.getRecords());
+        commonPage.setTotal(iPage.getRecords().size());
+        commonPage.setSize(iPage.getSize());
+        commonPage.setCurrent(iPage.getCurrent());
+
+        return commonPage;
+    }
+
+    private String getUserNameFromSecurityContext() {
+        try {
+            return SecurityUtils.getUsername();
+        } catch (Exception e) {
+            // 如果无法获取用户信息,记录日志并返回默认值或抛出自定义异常
+            return "未知用户";
+        }
+    }
+}

+ 44 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/service/FilesUpload.java

@@ -0,0 +1,44 @@
+package com.ruoyi.file.service;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+@Data
+@TableName("file_upload")
+public class FilesUpload implements Serializable {
+    private Integer id;//编号
+
+    private String filesName;//文件真实名称
+
+    private String name;//文件名
+
+    private String path;
+
+    private String type;//文件类型
+
+    private Double size;//文件大小
+
+    private String url;//下载链接
+
+    private Boolean enable;//链接是否可用(1:是 0:否)
+
+    private String createBy;//创建者
+
+    @TableField(fill = FieldFill.INSERT)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime createTime;//创建时间
+
+    private String updateBy;//更新者
+
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime updateTime;//更新时间
+
+    private Integer isDelete;//是否删除(1:是 0:否)
+}

+ 20 - 20
base-modules/service-file/src/main/java/com/ruoyi/file/service/ISysFileService.java

@@ -1,20 +1,20 @@
-package com.ruoyi.file.service;
-
-import org.springframework.web.multipart.MultipartFile;
-
-/**
- * 文件上传接口
- * 
- * @author ruoyi
- */
-public interface ISysFileService
-{
-    /**
-     * 文件上传接口
-     * 
-     * @param file 上传的文件
-     * @return 访问地址
-     * @throws Exception
-     */
-    public String uploadFile(MultipartFile file) throws Exception;
-}
+//package com.ruoyi.file.service;
+//
+//import org.springframework.web.multipart.MultipartFile;
+//
+///**
+// * 文件上传接口
+// *
+// * @author ruoyi
+// */
+//public interface ISysFileService
+//{
+//    /**
+//     * 文件上传接口
+//     *
+//     * @param file 上传的文件
+//     * @return 访问地址
+//     * @throws Exception
+//     */
+//    public String uploadFile(MultipartFile file) throws Exception;
+//}

+ 50 - 50
base-modules/service-file/src/main/java/com/ruoyi/file/service/LocalSysFileServiceImpl.java

@@ -1,50 +1,50 @@
-package com.ruoyi.file.service;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Primary;
-import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-import com.ruoyi.file.utils.FileUploadUtils;
-
-/**
- * 本地文件存储
- *
- * @author ruoyi
- */
-@Primary
-@Service
-public class LocalSysFileServiceImpl implements ISysFileService
-{
-    /**
-     * 资源映射路径 前缀
-     */
-    @Value("${file.prefix}")
-    public String localFilePrefix;
-
-    /**
-     * 域名或本机访问地址
-     */
-    @Value("${file.domain}")
-    public String domain;
-
-    /**
-     * 上传文件存储在本地的根路径
-     */
-    @Value("${file.path}")
-    private String localFilePath;
-
-    /**
-     * 本地文件上传接口
-     *
-     * @param file 上传的文件
-     * @return 访问地址
-     * @throws Exception
-     */
-    @Override
-    public String uploadFile(MultipartFile file) throws Exception
-    {
-        String name = FileUploadUtils.upload(localFilePath, file);
-        String url = domain + localFilePrefix + name;
-        return url;
-    }
-}
+//package com.ruoyi.file.service;
+//
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.context.annotation.Primary;
+//import org.springframework.stereotype.Service;
+//import org.springframework.web.multipart.MultipartFile;
+//import com.ruoyi.file.utils.FileUploadUtils;
+//
+///**
+// * 本地文件存储
+// *
+// * @author ruoyi
+// */
+//@Primary
+//@Service
+//public class LocalSysFileServiceImpl implements ISysFileService
+//{
+//    /**
+//     * 资源映射路径 前缀
+//     */
+//    @Value("${file.prefix}")
+//    public String localFilePrefix;
+//
+//    /**
+//     * 域名或本机访问地址
+//     */
+//    @Value("${file.domain}")
+//    public String domain;
+//
+//    /**
+//     * 上传文件存储在本地的根路径
+//     */
+//    @Value("${file.path}")
+//    private String localFilePath;
+//
+//    /**
+//     * 本地文件上传接口
+//     *
+//     * @param file 上传的文件
+//     * @return 访问地址
+//     * @throws Exception
+//     */
+//    @Override
+//    public String uploadFile(MultipartFile file) throws Exception
+//    {
+//        String name = FileUploadUtils.upload(localFilePath, file);
+//        String url = domain + localFilePrefix + name;
+//        return url;
+//    }
+//}

+ 202 - 202
base-modules/service-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java

@@ -1,202 +1,202 @@
-package com.ruoyi.file.utils;
-
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Paths;
-import java.util.Date;
-import java.util.Objects;
-
-import com.ruoyi.common.core.exception.file.FileNameLengthLimitExceededException;
-import com.ruoyi.common.core.exception.file.InvalidExtensionException;
-import org.apache.commons.io.FilenameUtils;
-import com.ruoyi.common.core.exception.file.FileSizeLimitExceededException;
-import com.ruoyi.common.core.utils.DateUtils;
-import com.ruoyi.common.core.utils.StringUtils;
-import com.ruoyi.common.core.utils.file.MimeTypeUtils;
-import com.ruoyi.common.core.utils.uuid.Seq;
-import org.apache.commons.lang3.time.DateFormatUtils;
-import org.springframework.web.multipart.MultipartFile;
-
-
-/**
- * 文件上传工具类
- *
- * @author ruoyi
- */
-public class FileUploadUtils
-{
-    /**
-     * 默认大小 50M
-     */
-    public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
-
-    /**
-     * 默认的文件名最大长度 100
-     */
-    public static final int DEFAULT_FILE_NAME_LENGTH = 100;
-
-    /**
-     * 根据文件路径上传
-     *
-     * @param baseDir 相对应用的基目录
-     * @param file 上传的文件
-     * @return 文件名称
-     * @throws IOException
-     */
-    public static final String upload(String baseDir, MultipartFile file) throws IOException
-    {
-        try
-        {
-            return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
-        }
-        catch (Exception e)
-        {
-            throw new IOException(e.getMessage(), e);
-        }
-    }
-
-    /**
-     * 文件上传
-     *
-     * @param baseDir 相对应用的基目录
-     * @param file 上传的文件
-     * @param allowedExtension 上传文件类型
-     * @return 返回上传成功的文件名
-     * @throws FileSizeLimitExceededException 如果超出最大大小
-     * @throws FileNameLengthLimitExceededException 文件名太长
-     * @throws IOException 比如读写文件出错时
-     * @throws InvalidExtensionException 文件校验异常
-     */
-    public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
-            throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
-            InvalidExtensionException
-    {
-        int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
-        if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
-        {
-            throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
-        }
-
-        assertAllowed(file, allowedExtension);
-
-        String fileName = extractFilename(file);
-
-        String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
-        file.transferTo(Paths.get(absPath));
-        return getPathFileName(fileName);
-    }
-
-    /**
-     * 编码文件名
-     */
-    public static final String extractFilename(MultipartFile file)
-    {
-//        return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
-//                FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file));
-        String datePath = DateFormatUtils.format(new Date(), "yyyyMM");
-        return StringUtils.format("{}/{}.{}",datePath , Seq.getId(Seq.uploadSeqType), getExtension(file));
-    }
-
-    private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
-    {
-        File desc = new File(uploadDir + File.separator + fileName);
-
-        if (!desc.exists())
-        {
-            if (!desc.getParentFile().exists())
-            {
-                desc.getParentFile().mkdirs();
-            }
-        }
-        return desc.isAbsolute() ? desc : desc.getAbsoluteFile();
-    }
-
-    private static final String getPathFileName(String fileName) throws IOException
-    {
-        String pathFileName = "/" + fileName;
-        return pathFileName;
-    }
-
-    /**
-     * 文件大小校验
-     *
-     * @param file 上传的文件
-     * @throws FileSizeLimitExceededException 如果超出最大大小
-     * @throws InvalidExtensionException 文件校验异常
-     */
-    public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
-            throws FileSizeLimitExceededException, InvalidExtensionException
-    {
-        long size = file.getSize();
-        if (size > DEFAULT_MAX_SIZE)
-        {
-            throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE/1024/1024);
-        }
-
-        String fileName = file.getOriginalFilename();
-        String extension = getExtension(file);
-        if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
-        {
-            if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
-            {
-                throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
-                        fileName);
-            }
-            else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION)
-            {
-                throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
-                        fileName);
-            }
-            else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION)
-            {
-                throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
-                        fileName);
-            }
-            else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION)
-            {
-                throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension,
-                        fileName);
-            }
-            else
-            {
-                throw new InvalidExtensionException(allowedExtension, extension, fileName);
-            }
-        }
-    }
-
-    /**
-     * 判断MIME类型是否是允许的MIME类型
-     *
-     * @param extension 上传文件类型
-     * @param allowedExtension 允许上传文件类型
-     * @return true/false
-     */
-    public static final boolean isAllowedExtension(String extension, String[] allowedExtension)
-    {
-        for (String str : allowedExtension)
-        {
-            if (str.equalsIgnoreCase(extension))
-            {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * 获取文件名的后缀
-     *
-     * @param file 表单文件
-     * @return 后缀名
-     */
-    public static final String getExtension(MultipartFile file)
-    {
-        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
-        if (StringUtils.isEmpty(extension))
-        {
-            extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType()));
-        }
-        return extension;
-    }
-}
+//package com.ruoyi.file.utils;
+//
+//
+//import java.io.File;
+//import java.io.IOException;
+//import java.nio.file.Paths;
+//import java.util.Date;
+//import java.util.Objects;
+//
+//import com.ruoyi.common.core.exception.file.FileNameLengthLimitExceededException;
+//import com.ruoyi.common.core.exception.file.InvalidExtensionException;
+//import org.apache.commons.io.FilenameUtils;
+//import com.ruoyi.common.core.exception.file.FileSizeLimitExceededException;
+//import com.ruoyi.common.core.utils.DateUtils;
+//import com.ruoyi.common.core.utils.StringUtils;
+//import com.ruoyi.common.core.utils.file.MimeTypeUtils;
+//import com.ruoyi.common.core.utils.uuid.Seq;
+//import org.apache.commons.lang3.time.DateFormatUtils;
+//import org.springframework.web.multipart.MultipartFile;
+//
+//
+///**
+// * 文件上传工具类
+// *
+// * @author ruoyi
+// */
+//public class FileUploadUtils
+//{
+//    /**
+//     * 默认大小 50M
+//     */
+//    public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
+//
+//    /**
+//     * 默认的文件名最大长度 100
+//     */
+//    public static final int DEFAULT_FILE_NAME_LENGTH = 100;
+//
+//    /**
+//     * 根据文件路径上传
+//     *
+//     * @param baseDir 相对应用的基目录
+//     * @param file 上传的文件
+//     * @return 文件名称
+//     * @throws IOException
+//     */
+//    public static final String upload(String baseDir, MultipartFile file) throws IOException
+//    {
+//        try
+//        {
+//            return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
+//        }
+//        catch (Exception e)
+//        {
+//            throw new IOException(e.getMessage(), e);
+//        }
+//    }
+//
+//    /**
+//     * 文件上传
+//     *
+//     * @param baseDir 相对应用的基目录
+//     * @param file 上传的文件
+//     * @param allowedExtension 上传文件类型
+//     * @return 返回上传成功的文件名
+//     * @throws FileSizeLimitExceededException 如果超出最大大小
+//     * @throws FileNameLengthLimitExceededException 文件名太长
+//     * @throws IOException 比如读写文件出错时
+//     * @throws InvalidExtensionException 文件校验异常
+//     */
+//    public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
+//            throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
+//            InvalidExtensionException
+//    {
+//        int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
+//        if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
+//        {
+//            throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
+//        }
+//
+//        assertAllowed(file, allowedExtension);
+//
+//        String fileName = extractFilename(file);
+//
+//        String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
+//        file.transferTo(Paths.get(absPath));
+//        return getPathFileName(fileName);
+//    }
+//
+//    /**
+//     * 编码文件名
+//     */
+//    public static final String extractFilename(MultipartFile file)
+//    {
+////        return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
+////                FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file));
+//        String datePath = DateFormatUtils.format(new Date(), "yyyyMM");
+//        return StringUtils.format("{}/{}.{}",datePath , Seq.getId(Seq.uploadSeqType), getExtension(file));
+//    }
+//
+//    private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
+//    {
+//        File desc = new File(uploadDir + File.separator + fileName);
+//
+//        if (!desc.exists())
+//        {
+//            if (!desc.getParentFile().exists())
+//            {
+//                desc.getParentFile().mkdirs();
+//            }
+//        }
+//        return desc.isAbsolute() ? desc : desc.getAbsoluteFile();
+//    }
+//
+//    private static final String getPathFileName(String fileName) throws IOException
+//    {
+//        String pathFileName = "/" + fileName;
+//        return pathFileName;
+//    }
+//
+//    /**
+//     * 文件大小校验
+//     *
+//     * @param file 上传的文件
+//     * @throws FileSizeLimitExceededException 如果超出最大大小
+//     * @throws InvalidExtensionException 文件校验异常
+//     */
+//    public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
+//            throws FileSizeLimitExceededException, InvalidExtensionException
+//    {
+//        long size = file.getSize();
+//        if (size > DEFAULT_MAX_SIZE)
+//        {
+//            throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE/1024/1024);
+//        }
+//
+//        String fileName = file.getOriginalFilename();
+//        String extension = getExtension(file);
+//        if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
+//        {
+//            if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
+//            {
+//                throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
+//                        fileName);
+//            }
+//            else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION)
+//            {
+//                throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
+//                        fileName);
+//            }
+//            else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION)
+//            {
+//                throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
+//                        fileName);
+//            }
+//            else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION)
+//            {
+//                throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension,
+//                        fileName);
+//            }
+//            else
+//            {
+//                throw new InvalidExtensionException(allowedExtension, extension, fileName);
+//            }
+//        }
+//    }
+//
+//    /**
+//     * 判断MIME类型是否是允许的MIME类型
+//     *
+//     * @param extension 上传文件类型
+//     * @param allowedExtension 允许上传文件类型
+//     * @return true/false
+//     */
+//    public static final boolean isAllowedExtension(String extension, String[] allowedExtension)
+//    {
+//        for (String str : allowedExtension)
+//        {
+//            if (str.equalsIgnoreCase(extension))
+//            {
+//                return true;
+//            }
+//        }
+//        return false;
+//    }
+//
+//    /**
+//     * 获取文件名的后缀
+//     *
+//     * @param file 表单文件
+//     * @return 后缀名
+//     */
+//    public static final String getExtension(MultipartFile file)
+//    {
+//        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
+//        if (StringUtils.isEmpty(extension))
+//        {
+//            extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType()));
+//        }
+//        return extension;
+//    }
+//}

+ 1 - 1
base-modules/service-file/src/main/resources/bootstrap.yml

@@ -3,7 +3,7 @@ server:
   port: 9300
 
 # Spring
-spring: 
+spring:
   application:
     # 应用名称
     name: service-file

+ 5 - 0
base-modules/service-file/src/main/resources/mapper/file/FilesMapper.xml

@@ -0,0 +1,5 @@
+<?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.ruoyi.file.mapper.FilesMapper">
+
+</mapper>

+ 39 - 18
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/controller/web/MceReceiveController.java

@@ -7,7 +7,9 @@ import com.usky.common.log.annotation.Log;
 import com.usky.common.log.enums.BusinessType;
 import com.usky.system.domain.MceReceive;
 import com.usky.system.service.MceReceiveService;
+import com.usky.system.service.vo.MceReceiveResponseVO;
 import io.swagger.models.auth.In;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -45,11 +47,10 @@ public class MceReceiveController {
                                                  @RequestParam(value = "infoType", required = false) String infoType,
                                                  @RequestParam(value = "startTime", required = false) String startTime,
                                                  @RequestParam(value = "endTime", required = false) String endTime,
-                                                 @RequestParam(value = "id",required = false) Integer id,
+                                                 @RequestParam(value = "id", required = false) Integer id,
                                                  @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
-                                                 @RequestParam(value = "size", required = false, defaultValue = "10") Integer size)
-    {
-        return ApiResult.success(mceReceiveService.mceList(infoTitle, infoType,startTime, endTime, id,current, size));
+                                                 @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
+        return ApiResult.success(mceReceiveService.mceList(infoTitle, infoType, startTime, endTime, id, current, size));
     }
 
     /**
@@ -68,9 +69,8 @@ public class MceReceiveController {
                                                        @RequestParam(value = "startTime", required = false) String startTime,
                                                        @RequestParam(value = "endTime", required = false) String endTime,
                                                        @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
-                                                       @RequestParam(value = "size", required = false, defaultValue = "10") Integer size)
-    {
-        return ApiResult.success(mceReceiveService.mceManageList(infoTitle, infoType,startTime, endTime, current, size));
+                                                       @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
+        return ApiResult.success(mceReceiveService.mceManageList(infoTitle, infoType, startTime, endTime, current, size));
     }
 
     /**
@@ -83,9 +83,8 @@ public class MceReceiveController {
     @GetMapping("/mceManageById")
     public ApiResult<CommonPage<MceReceive>> mceManageById(@RequestParam(value = "id") Integer id,
                                                            @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
-                                                           @RequestParam(value = "size", required = false, defaultValue = "10") Integer size)
-    {
-        return ApiResult.success(mceReceiveService.mceManageById(id,current,size));
+                                                           @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
+        return ApiResult.success(mceReceiveService.mceManageById(id, current, size));
     }
 
     /**
@@ -93,17 +92,26 @@ public class MceReceiveController {
      * @return
      */
     @GetMapping("/mceReceiveStatic")
-    public ApiResult<Map<String, Object>> mceReceiveStatic()
-    {
+    public ApiResult<Map<String, Object>> mceReceiveStatic() {
         return ApiResult.success(mceReceiveService.mceReceiveStatic());
     }
 
+    /**
+     * 消息中心分页接口
+     * @return
+     */
+    @GetMapping("/getMceReceiveList")
+    public ApiResult<CommonPage<MceReceiveResponseVO>> getMceReceiveList(@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
+                                                                         @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize) {
+        return ApiResult.success(mceReceiveService.getMceReceiveResponseVOList(pageNumber, pageSize));
+    }
+
     /**
      * 已读
      * @return
      */
     @PutMapping
-    ApiResult<Void> updateMceReceive(@RequestBody MceReceive mceReceive){
+    ApiResult<Void> updateMceReceive(@RequestBody MceReceive mceReceive) {
         mceReceiveService.updateMceReceive(mceReceive);
         return ApiResult.success();
     }
@@ -114,20 +122,33 @@ public class MceReceiveController {
      */
     @Log(title = "新增发布消息", businessType = BusinessType.INSERT)
     @PostMapping("/mceAdd")
-    ApiResult<Void> add(@RequestBody String mceReceive){
+    ApiResult<Void> add(@RequestBody String mceReceive) {
         mceReceiveService.add(mceReceive);
         return ApiResult.success();
     }
 
     /**
-     * 删除
+     * 删除消息及内容,并清空所有的消息接收表数据
      */
     @Log(title = "删除已发布消息", businessType = BusinessType.DELETE)
-    @DeleteMapping("/{id}")
-    public ApiResult<Void> removeById(@PathVariable("id") Integer id)
-    {
+    @DeleteMapping("/remove/{contentId}")
+    public ApiResult<Void> removeById(@PathVariable("contentId") Integer id) {
         mceReceiveService.removeById(id);
         return ApiResult.success();
     }
+
+    /**
+     * 删除一条消息
+     **/
+    @Log(title = "删除消息", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{id}")
+    public ApiResult<Void> deleteById(@PathVariable("id") Integer id) {
+        boolean f = mceReceiveService.deleteById(id);
+        if (f) {
+            return ApiResult.success();
+        } else {
+            return ApiResult.error("删除失败");
+        }
+    }
 }
 

+ 2 - 1
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/controller/web/SysUserController.java

@@ -118,6 +118,7 @@ public class SysUserController extends BaseController
     @GetMapping(value = { "/", "/{userId}" })
     public ApiResult<Map<String,Object>> getInfo(@PathVariable(value = "userId", required = false) Long userId)
     {
+        Integer tenantId = SecurityUtils.getTenantId();
         Map<String,Object> ajax = new HashMap<>();
         List<SysRole> roles = roleService.selectRoleAll();
         ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
@@ -126,7 +127,7 @@ public class SysUserController extends BaseController
         {
             ajax.put("data", userService.selectUserById(userId));
             ajax.put("postIds", postService.selectPostListByUserId(userId));
-            ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
+            ajax.put("roleIds", roleService.selectRoleListByUserId(userId, tenantId));
         }
         return ApiResult.success(ajax);
     }

+ 2 - 1
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/mapper/SysRoleMapper.java

@@ -45,7 +45,8 @@ public interface SysRoleMapper extends CrudMapper<SysRole>
      * @param userId 用户ID
      * @return 选中角色ID列表
      */
-    public List<Integer> selectRoleListByUserId(@Param("userId") Long userId);
+    public List<Integer> selectRoleListByUserId(@Param("userId") Long userId,
+                                                @Param("tenantId") Integer tenantId);
 
     /**
      * 通过角色ID查询角色

+ 4 - 4
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/mapper/SysUserRoleMapper.java

@@ -22,7 +22,7 @@ public interface SysUserRoleMapper extends CrudMapper<SysUserRole>
      * @param userId 用户ID
      * @return 结果
      */
-    public int deleteUserRoleByUserId(@Param("userId") Long userId);
+    public int deleteUserRoleByUserId(@Param("userId") Long userId, @Param("tenantId") Integer tenantId);
 
     /**
      * 批量删除用户和角色关联
@@ -30,7 +30,7 @@ public interface SysUserRoleMapper extends CrudMapper<SysUserRole>
      * @param ids 需要删除的数据ID
      * @return 结果
      */
-    public int deleteUserRole(@Param("ids") Long[] ids);
+    public int deleteUserRole(@Param("ids") Long[] ids, @Param("tenantId") Integer tenantId);
 
     /**
      * 通过角色ID查询角色使用数量
@@ -38,7 +38,7 @@ public interface SysUserRoleMapper extends CrudMapper<SysUserRole>
      * @param roleId 角色ID
      * @return 结果
      */
-    public int countUserRoleByRoleId(@Param("roleId") Long roleId);
+    public int countUserRoleByRoleId(@Param("roleId") Long roleId, @Param("tenantId") Integer tenantId);
 
     /**
      * 批量新增用户角色信息
@@ -63,5 +63,5 @@ public interface SysUserRoleMapper extends CrudMapper<SysUserRole>
      * @param userIds 需要删除的用户数据ID
      * @return 结果
      */
-    public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
+    public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds, @Param("tenantId") Integer tenantId);
 }

+ 1 - 1
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/ISysRoleService.java

@@ -52,7 +52,7 @@ public interface ISysRoleService extends CrudService<SysRole>
      * @param userId 用户ID
      * @return 选中角色ID列表
      */
-    public List<Integer> selectRoleListByUserId(Long userId);
+    public List<Integer> selectRoleListByUserId(Long userId, Integer tenantId);
 
     /**
      * 通过角色ID查询角色

+ 6 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/MceReceiveService.java

@@ -4,7 +4,9 @@ import com.usky.common.core.bean.CommonPage;
 import com.usky.system.domain.MceReceive;
 import com.usky.common.mybatis.core.CrudService;
 import com.usky.system.domain.MceRequestVO;
+import com.usky.system.service.vo.MceReceiveResponseVO;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -33,4 +35,8 @@ public interface MceReceiveService extends CrudService<MceReceive> {
 
     boolean removeById(Integer id);
 
+    boolean deleteById(Integer id);
+
+    CommonPage<MceReceiveResponseVO> getMceReceiveResponseVOList(Integer pageNumber, Integer pageSize);
+
 }

+ 65 - 6
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/MceReceiveServiceImpl.java

@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.usky.common.core.bean.CommonPage;
+import com.usky.common.core.exception.BusinessException;
 import com.usky.common.security.utils.SecurityUtils;
 import com.usky.system.domain.*;
 import com.usky.system.mapper.MceReceiveMapper;
@@ -18,6 +19,7 @@ import com.usky.system.mapper.MceSettingMapper;
 import com.usky.system.mapper.SysUserMapper;
 import com.usky.system.service.*;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.system.service.vo.MceReceiveResponseVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -58,6 +60,9 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
     @Autowired
     private MceSettingMapper mceSettingMapper;
 
+    @Autowired
+    private MceReceiveMapper mceReceiveMapper;
+
     @Override
     public CommonPage<Object> mceList(String infoTitle, String infoType, String startTime, String endTime, Integer id, Integer current, Integer size) {
         List<Object> list = new ArrayList<>();
@@ -76,7 +81,7 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
             LambdaQueryWrapper<MceReceive> lambdaQuery = Wrappers.lambdaQuery();
             lambdaQuery.select(MceReceive::getId, MceReceive::getInfoType,
                             MceReceive::getContentId, MceReceive::getReadFlag, MceReceive::getCreateTime,
-                            MceReceive::getReceiverId, MceReceive::getModuleId)
+                            MceReceive::getReceiverId, MceReceive::getModuleId, MceReceive::getCreateBy)
                     .between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), MceReceive::getCreateTime,
                             startTime, endTime)
                     .eq(StringUtils.isNotBlank(infoType), MceReceive::getInfoType, infoType)
@@ -94,6 +99,7 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
                     map.put("readFlag", page.getRecords().get(i).getReadFlag());
                     map.put("moduleId", page.getRecords().get(i).getModuleId());
                     map.put("createTime", page.getRecords().get(i).getCreateTime());
+                    map.put("createBy", page.getRecords().get(i).getCreateBy());
                     if (CollectionUtils.isNotEmpty(list1)) {
                         for (int j = 0; j < list1.size(); j++) {
                             if (page.getRecords().get(i).getContentId().equals(list1.get(j).getId())) {
@@ -240,6 +246,7 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
     }
 
     @Async
+    @Override
     public void addMceReceive(MceRequestVO mceRequestVO) {
         // 如果 infoTypeName 为空,则从字典数据中获取
         if (mceRequestVO.getInfoTypeName() == null) {
@@ -247,8 +254,10 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
             mceRequestVO.setInfoTypeName(infoTypeName);
         }
 
+        Integer tenantId = userMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, mceRequestVO.getUserName()).select(SysUser::getTenantId)).getTenantId();
+
         // 获取当前租户的所有用户
-        List<SysUser> userList = userMapper.tenantIdUserList(SecurityUtils.getTenantId());
+        List<SysUser> userList = userMapper.tenantIdUserList(tenantId);
         if (CollectionUtils.isEmpty(userList)) {
             return;
         }
@@ -299,12 +308,12 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
             for (SysUser user : userList) {
                 if (user.getUserId().equals(userId)) {
                     // 创建消息接收记录
-                    List<MceSetting> setting =  mceSettingService.list(Wrappers.lambdaQuery(MceSetting.class).eq(MceSetting::getCreateBy, user.getUserName()));
+                    List<MceSetting> setting = mceSettingService.list(Wrappers.lambdaQuery(MceSetting.class).eq(MceSetting::getCreateBy, user.getUserName()));
                     Integer receiveId = 0;
-                    if (CollectionUtils.isNotEmpty(setting)){
+                    if (CollectionUtils.isNotEmpty(setting)) {
                         MceReceive mceReceive = createMceReceive(user, generatedContentId, mceRequestVO, userNameNickNameMap);
                         this.save(mceReceive);
-                       receiveId =  mceReceive.getId();
+                        receiveId = mceReceive.getId();
                     }
 
                     if (mbUserOptional.isPresent()) {
@@ -482,7 +491,8 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
             mceReceiveVO.put("infoTypeName", infoTypeName);
         }
 
-        List<SysUser> list = userMapper.tenantIdUserList(SecurityUtils.getTenantId());
+        Integer tenantId = userMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, mceReceiveVO.get("userName")).select(SysUser::getTenantId)).getTenantId();
+        List<SysUser> list = userMapper.tenantIdUserList(tenantId);
         // 获取用户昵称与真实姓名Map
         Map<String, String> userNameNickNameMap = list.stream().collect(Collectors.toMap(SysUser::getUserName, SysUser::getNickName));
         MceContent mceContent = new MceContent();
@@ -580,4 +590,53 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
         this.remove(lambdaQuery);
         return mceContentService.removeById(id);
     }
+
+    @Override
+    public boolean deleteById(Integer id) {
+        boolean f;
+        Integer userId = SecurityUtils.getUserId().intValue();
+        MceReceive mceReceive = mceReceiveMapper.selectOne(new LambdaQueryWrapper<MceReceive>().eq(MceReceive::getId, id));
+        if (mceReceive != null) {
+            if (userId.equals(mceReceive.getReceiverId())) {
+                mceReceiveMapper.deleteById(id);
+                f = true;
+            } else {
+                throw new BusinessException("您无权删除该条记录!");
+            }
+        } else {
+            throw new BusinessException("记录不存在,删除失败!");
+        }
+        return f;
+    }
+
+    @Override
+    public CommonPage<MceReceiveResponseVO> getMceReceiveResponseVOList(Integer pageNumber, Integer pageSize) {
+        IPage<MceReceive> page = new Page<>(pageNumber, pageSize);
+        Long userId = SecurityUtils.getUserId();
+        List<MceReceiveResponseVO> returnList = new ArrayList<>();
+
+        LambdaQueryWrapper<MceReceive> lambdaQuery = Wrappers.lambdaQuery();
+        lambdaQuery.eq(MceReceive::getReceiverId, userId);
+        page = this.page(page, lambdaQuery);
+        List<MceReceive> mceReceiveList = page.getRecords();
+        List<Integer> contentIdList = mceReceiveList.stream().map(MceReceive::getContentId).distinct().collect(Collectors.toList());
+
+        List<MceContent> mceContentList = mceContentService.list(new LambdaQueryWrapper<MceContent>().in(MceContent::getId, contentIdList));
+
+        for (MceContent mceContent : mceContentList) {
+            MceReceive mceReceive = mceReceiveList.stream().filter(mceReceive1 -> mceReceive1.getContentId().equals(mceContent.getId())).findFirst().get();
+            MceReceiveResponseVO mceReceiveResponseVO = new MceReceiveResponseVO();
+            mceReceiveResponseVO.setMceId(mceReceive.getId());
+            mceReceiveResponseVO.setInfoType(mceContent.getInfoType());
+            mceReceiveResponseVO.setInfoTitle(mceContent.getInfoTitle());
+            mceReceiveResponseVO.setContentId(mceContent.getId());
+            mceReceiveResponseVO.setInfoContent(mceContent.getInfoContent());
+            mceReceiveResponseVO.setCreateTime(mceContent.getCreateTime());
+            mceReceiveResponseVO.setCreateBy(mceContent.getCreateBy());
+            mceReceiveResponseVO.setModuleId(mceReceive.getModuleId());
+            returnList.add(mceReceiveResponseVO);
+        }
+
+        return new CommonPage<>(returnList, page.getTotal(), page.getSize(), page.getCurrent());
+    }
 }

+ 5 - 4
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysRoleServiceImpl.java

@@ -125,9 +125,9 @@ public class SysRoleServiceImpl extends AbstractCrudService<SysRoleMapper, SysRo
      * @return 选中角色ID列表
      */
     @Override
-    public List<Integer> selectRoleListByUserId(Long userId)
+    public List<Integer> selectRoleListByUserId(Long userId, Integer tenantId)
     {
-        return roleMapper.selectRoleListByUserId(userId);
+        return roleMapper.selectRoleListByUserId(userId,tenantId);
     }
 
     /**
@@ -201,7 +201,7 @@ public class SysRoleServiceImpl extends AbstractCrudService<SysRoleMapper, SysRo
     @Override
     public int countUserRoleByRoleId(Long roleId)
     {
-        return userRoleMapper.countUserRoleByRoleId(roleId);
+        return userRoleMapper.countUserRoleByRoleId(roleId,SecurityUtils.getTenantId());
     }
 
     /**
@@ -395,7 +395,8 @@ public class SysRoleServiceImpl extends AbstractCrudService<SysRoleMapper, SysRo
     @Override
     public int deleteAuthUsers(Long roleId, Long[] userIds)
     {
-        return userRoleMapper.deleteUserRoleInfos(roleId, userIds);
+        Integer tenantId = SecurityUtils.getTenantId();
+        return userRoleMapper.deleteUserRoleInfos(roleId, userIds, tenantId);
     }
 
     /**

+ 6 - 6
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysUserServiceImpl.java

@@ -406,7 +406,7 @@ public class SysUserServiceImpl extends AbstractCrudService<SysUserMapper, SysUs
     public int updateUser(SysUser user) {
         Long userId = user.getUserId();
         // 删除用户与角色关联
-        userRoleMapper.deleteUserRoleByUserId(userId);
+        userRoleMapper.deleteUserRoleByUserId(userId,SecurityUtils.getTenantId());
         // 新增用户与角色管理
         insertUserRole(user);
         // 删除用户与岗位关联
@@ -437,7 +437,7 @@ public class SysUserServiceImpl extends AbstractCrudService<SysUserMapper, SysUs
     @Override
     @Transactional
     public void insertUserAuth(Long userId, Long[] roleIds) {
-        userRoleMapper.deleteUserRoleByUserId(userId);
+        userRoleMapper.deleteUserRoleByUserId(userId, SecurityUtils.getTenantId());
         insertUserRole(userId, roleIds);
     }
 
@@ -512,7 +512,7 @@ public class SysUserServiceImpl extends AbstractCrudService<SysUserMapper, SysUs
                 SysUserRole ur = new SysUserRole();
                 ur.setUserId(user.getUserId());
                 ur.setRoleId(roleId);
-                ur.setTenantId(user.getTenantId());
+                ur.setTenantId(SecurityUtils.getTenantId());
                 list.add(ur);
             }
             if (list.size() > 0) {
@@ -577,7 +577,7 @@ public class SysUserServiceImpl extends AbstractCrudService<SysUserMapper, SysUs
     @Transactional
     public int deleteUserById(Long userId) {
         // 删除用户与角色关联
-        userRoleMapper.deleteUserRoleByUserId(userId);
+        userRoleMapper.deleteUserRoleByUserId(userId, SecurityUtils.getTenantId());
         // 删除用户与岗位表
         userPostMapper.deleteUserPostByUserId(userId);
         return userMapper.deleteUserById(userId);
@@ -596,7 +596,7 @@ public class SysUserServiceImpl extends AbstractCrudService<SysUserMapper, SysUs
             checkUserAllowed(new SysUser(userId));
         }
         // 删除用户与角色关联
-        userRoleMapper.deleteUserRole(userIds);
+        userRoleMapper.deleteUserRole(userIds, SecurityUtils.getTenantId());
         // 删除用户与岗位关联
         userPostMapper.deleteUserPost(userIds);
         return userMapper.deleteUserByIds(userIds);
@@ -609,7 +609,7 @@ public class SysUserServiceImpl extends AbstractCrudService<SysUserMapper, SysUs
         SysUser user = this.selectUserById(userId);
         if (user.getPassword().equals(password)) {
             // 删除用户与角色关联
-            userRoleMapper.deleteUserRoleByUserId(userId);
+            userRoleMapper.deleteUserRoleByUserId(userId, SecurityUtils.getTenantId());
             // 删除用户与岗位表
             userPostMapper.deleteUserPostByUserId(userId);
             return userMapper.deleteUserById(userId);

+ 25 - 11
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysUserTenantServiceImpl.java

@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.usky.common.core.exception.BusinessException;
 import com.usky.system.RemoteDeptService;
 import com.usky.system.domain.SysTenant;
+import com.usky.system.domain.SysUserRole;
 import com.usky.system.domain.SysUserTenant;
+import com.usky.system.mapper.SysUserRoleMapper;
 import com.usky.system.mapper.SysUserTenantMapper;
 import com.usky.system.service.SysTenantService;
 import com.usky.system.service.SysUserTenantService;
@@ -33,6 +35,9 @@ public class SysUserTenantServiceImpl extends AbstractCrudService<SysUserTenantM
     @Autowired
     private SysTenantService sysTenantService;
 
+    @Autowired
+    private SysUserRoleMapper sysUserRoleMapper;
+
     /**
      * 企业邀请用户
      *
@@ -42,9 +47,16 @@ public class SysUserTenantServiceImpl extends AbstractCrudService<SysUserTenantM
     @Transactional
     public void insertInviteUser(SysUserTenant sysUserTenant) {
         int userCount = baseMapper.checkUserIdUnique(sysUserTenant.getTenantId(), sysUserTenant.getUserId());
-        if (userCount > 0){
+        if (userCount > 0) {
             throw new BusinessException("用户已绑定,无法重复绑定!");
-        }else {
+        } else {
+            // SysUserRole sysUserRole = sysUserRoleMapper.selectOne(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, sysUserTenant.getUserId()).eq(SysUserRole::getTenantId, sysUserTenant.getTenantId()));
+            // if (sysUserRole == null) {
+            //     SysUserRole sysUserRole1 = new SysUserRole();
+            //     sysUserRole1.setUserId(sysUserTenant.getUserId());
+            //     sysUserRole1.setTenantId(sysUserTenant.getTenantId());
+            //     sysUserRoleMapper.insert(sysUserRole1);
+            // }
             this.save(sysUserTenant);
         }
     }
@@ -57,8 +69,10 @@ public class SysUserTenantServiceImpl extends AbstractCrudService<SysUserTenantM
      */
     @Override
     @Transactional
-    public void deleteUserTenant(Integer tenantId,Long userId) {
+    public void deleteUserTenant(Integer tenantId, Long userId) {
         baseMapper.deleteUserTenant(tenantId, userId);
+        Long[] userIds = new Long[]{userId};
+        sysUserRoleMapper.deleteUserRole(userIds, tenantId);
     }
 
     /**
@@ -66,19 +80,19 @@ public class SysUserTenantServiceImpl extends AbstractCrudService<SysUserTenantM
      */
     @Override
     @Transactional
-    public List<SysTenant> getTenantByUser(Long userId){
+    public List<SysTenant> getTenantByUser(Long userId) {
         LambdaQueryWrapper<SysUserTenant> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.eq(SysUserTenant::getUserId,userId);
+        queryWrapper.eq(SysUserTenant::getUserId, userId);
         List<SysUserTenant> userTenants = this.list(queryWrapper);
         List<Integer> tenantIdList = new ArrayList<>();
         List<SysTenant> tenantList = new ArrayList<>();
         LambdaQueryWrapper<SysTenant> queryWrapper1 = Wrappers.lambdaQuery();
-        if (CollectionUtils.isNotEmpty(userTenants)){
+        if (CollectionUtils.isNotEmpty(userTenants)) {
             for (int i = 0; i < userTenants.size(); i++) {
                 tenantIdList.add(userTenants.get(i).getTenantId());
             }
-            queryWrapper1.in(SysTenant::getId,tenantIdList)
-                    .eq(SysTenant::getStatus,0);
+            queryWrapper1.in(SysTenant::getId, tenantIdList)
+                    .eq(SysTenant::getStatus, 0);
             tenantList = sysTenantService.list(queryWrapper1);
         }
         return tenantList;
@@ -86,10 +100,10 @@ public class SysUserTenantServiceImpl extends AbstractCrudService<SysUserTenantM
 
     @Override
     @Transactional
-    public Boolean getIdByUser(Integer tenantId,Long userId){
+    public Boolean getIdByUser(Integer tenantId, Long userId) {
         LambdaQueryWrapper<SysUserTenant> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.eq(SysUserTenant::getUserId,userId)
-                .eq(SysUserTenant::getTenantId,tenantId);
+        queryWrapper.eq(SysUserTenant::getUserId, userId)
+                .eq(SysUserTenant::getTenantId, tenantId);
         List<SysUserTenant> userTenants = this.list(queryWrapper);
         return userTenants.get(0).getIsDefault();
     }

+ 56 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/vo/MceReceiveResponseVO.java

@@ -0,0 +1,56 @@
+package com.usky.system.service.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ *
+ * @author fyc
+ * @email yuchuan.fu@chinausky.com
+ * @date 2025/4/8
+ */
+@Data
+public class MceReceiveResponseVO {
+    /**
+     * 消息类型
+     */
+    private String infoType;
+
+    /**
+     * 消息id
+     */
+    private Integer mceId;
+
+    /**
+     * 消息标题
+     */
+    private String infoTitle;
+
+    /**
+     * 消息内容id
+     */
+    private Integer contentId;
+
+    /**
+     * 消息内容
+     */
+    private String infoContent;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime createTime;
+
+    /**
+     * 创建人
+     */
+    private String createBy;
+
+    /**
+     * 跳转id
+     */
+    private Integer moduleId;
+}

+ 7 - 7
base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysRoleMapper.xml

@@ -68,13 +68,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<select id="selectRoleAll" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 	</select>
-	
-	<select id="selectRoleListByUserId" parameterType="Long" resultType="Integer">
-		select r.role_id
-        from sys_role r
-	        left join sys_user_role ur on ur.role_id = r.role_id
-	        left join sys_user u on u.user_id = ur.user_id
-	    where u.user_id = #{userId}
+
+	<select id="selectRoleListByUserId" parameterType="map" resultType="Integer">
+		SELECT r.role_id
+		FROM sys_role r
+				 LEFT JOIN sys_user_role ur ON ur.role_id = r.role_id
+				 LEFT JOIN sys_user u ON u.user_id = ur.user_id
+		WHERE u.user_id = #{userId, jdbcType=BIGINT} AND r.tenant_id = #{tenantId, jdbcType=INTEGER}
 	</select>
 	
 	<select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">

+ 52 - 40
base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysUserRoleMapper.xml

@@ -1,45 +1,57 @@
 <?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">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.usky.system.mapper.SysUserRoleMapper">
 
-	<resultMap type="com.usky.system.domain.SysUserRole" id="SysUserRoleResult">
-		<result property="userId"     column="user_id"      />
-		<result property="roleId"     column="role_id"      />
-		<result property="tenantId"   column="tenant_id"    />
-	</resultMap>
-
-	<delete id="deleteUserRoleByUserId" parameterType="Long">
-		delete from sys_user_role where user_id=#{userId}
-	</delete>
-	
-	<select id="countUserRoleByRoleId" resultType="Integer">
-	    select count(1) from sys_user_role where role_id=#{roleId}  
-	</select>
-	
-	<delete id="deleteUserRole" parameterType="Long">
- 		delete from sys_user_role where user_id in
- 		<foreach collection="ids" item="ids" open="(" separator="," close=")">
- 			#{ids}
-        </foreach> 
- 	</delete>
-	
-	<insert id="batchUserRole">
-		insert into sys_user_role(user_id, role_id, tenant_id) values
-		<foreach item="item" index="index" collection="list" separator=",">
-			(#{item.userId},#{item.roleId},#{item.tenantId})
-		</foreach>
-	</insert>
-	
-	<delete id="deleteUserRoleInfo" parameterType="com.usky.system.domain.SysUserRole">
-		delete from sys_user_role where user_id=#{userId} and role_id=#{roleId}
-	</delete>
-	
-	<delete id="deleteUserRoleInfos">
-	    delete from sys_user_role where role_id=#{roleId} and user_id in
- 	    <foreach collection="userIds" item="userId" open="(" separator="," close=")">
- 	        #{userId}
-            </foreach> 
-	</delete>
+    <resultMap type="com.usky.system.domain.SysUserRole" id="SysUserRoleResult">
+        <result property="userId" column="user_id"/>
+        <result property="roleId" column="role_id"/>
+        <result property="tenantId" column="tenant_id"/>
+    </resultMap>
+
+    <delete id="deleteUserRoleByUserId" parameterType="map">
+        delete
+        from sys_user_role
+        where user_id = #{userId, jdbcType=BIGINT}
+          and tenant_id = #{tenantId, jdbcType=INTEGER}
+    </delete>
+
+    <select id="countUserRoleByRoleId" resultType="Integer">
+        select count(1)
+        from sys_user_role
+        where role_id = #{roleId, jdbcType=BIGINT}
+          and tenant_id = #{tenantId, jdbcType=INTEGER}
+    </select>
+
+    <delete id="deleteUserRole" parameterType="map">
+        delete from sys_user_role where user_id in
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id, jdbcType=BIGINT}
+        </foreach>
+        and tenant_id=#{tenantId, jdbcType=INTEGER}
+    </delete>
+
+    <insert id="batchUserRole">
+        insert into sys_user_role(user_id, role_id, tenant_id) values
+        <foreach item="item" index="index" collection="list" separator=",">
+            (#{item.userId, jdbcType=BIGINT}, #{item.roleId, jdbcType=INTEGER}, #{item.tenantId, jdbcType=INTEGER})
+        </foreach>
+    </insert>
+
+    <delete id="deleteUserRoleInfo" parameterType="map">
+        delete
+        from sys_user_role
+        where user_id = #{userId, jdbcType=BIGINT}
+          and role_id = #{roleId, jdbcType=INTEGER}
+    </delete>
+
+    <delete id="deleteUserRoleInfos" parameterType="map">
+        delete from sys_user_role where role_id=#{roleId, jdbcType=INTEGER} and user_id in
+        <foreach collection="userIds" item="userId" open="(" separator="," close=")">
+            #{userId, jdbcType=BIGINT}
+        </foreach>
+        and tenant_id=#{tenantId, jdbcType=INTEGER}
+    </delete>
+
 </mapper>