Compare commits
2 Commits
061711a9c0
...
5ea65a8d25
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ea65a8d25 | |||
| 3f1c4df78a |
7
pom.xml
7
pom.xml
@@ -125,6 +125,13 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara.x-file-storage</groupId>
|
||||
<artifactId>x-file-storage-spring</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -46,7 +46,8 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
"/user/doLogin",
|
||||
"/tenant/get-id-by-name",
|
||||
"/user/bigbrother-doLogin",
|
||||
"/user/aiChat-doLogin"
|
||||
"/user/aiChat-doLogin",
|
||||
"/error"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.yupi.springbootinit.controller;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/8/25 13:36
|
||||
*/
|
||||
|
||||
import com.yupi.springbootinit.common.BaseResponse;
|
||||
import com.yupi.springbootinit.common.ResultUtils;
|
||||
import com.yupi.springbootinit.service.ServerAiLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/log")
|
||||
@Slf4j
|
||||
@CrossOrigin
|
||||
public class FileController {
|
||||
|
||||
@Resource
|
||||
private ServerAiLogService serverAiLogService;
|
||||
|
||||
@PostMapping("upload")
|
||||
public BaseResponse<Boolean> upload(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam Long tenantId,
|
||||
@RequestParam Long userId) {
|
||||
return ResultUtils.success(serverAiLogService.saveLog(file,tenantId,userId));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,15 @@ import com.yupi.springbootinit.common.BaseResponse;
|
||||
import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.common.ResultUtils;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import com.yupi.springbootinit.model.entity.SystemTenant;
|
||||
import com.yupi.springbootinit.model.vo.user.SystemTenantVO;
|
||||
import com.yupi.springbootinit.model.vo.user.SystemUsersVO;
|
||||
import com.yupi.springbootinit.service.SystemTenantService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.annotation.security.PermitAll;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
@@ -30,7 +33,12 @@ public class TenantController {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
return ResultUtils.success( systemTenantService.getTenantIdByName(name));
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/get-expired-time")
|
||||
public BaseResponse<SystemTenantVO> getTenantIdExpired(@RequestParam("tenantId") Long tenantId) {
|
||||
return ResultUtils.success(systemTenantService.getTenantIdExpired(tenantId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yupi.springbootinit.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yupi.springbootinit.model.entity.ServerAiLog;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/8/25 13:37
|
||||
*/
|
||||
|
||||
public interface ServerAiLogMapper extends BaseMapper<ServerAiLog> {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yupi.springbootinit.model.dto.file;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/8/25 14:32
|
||||
*/
|
||||
@Data
|
||||
public class FileDTO {
|
||||
/**
|
||||
* 日志租户
|
||||
*/
|
||||
@TableField(value = "log_tenant_id")
|
||||
@ApiModelProperty(value="日志租户")
|
||||
private Long logTenantId;
|
||||
|
||||
/**
|
||||
* 用户 Id
|
||||
*/
|
||||
@TableField(value = "log_user_id")
|
||||
@ApiModelProperty(value="用户 Id")
|
||||
private Long logUserId;
|
||||
|
||||
@ApiModelProperty(value="日志文件")
|
||||
private MultipartFile file;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.yupi.springbootinit.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/8/25 13:37
|
||||
*/
|
||||
|
||||
@ApiModel(description="server_ai_log")
|
||||
@Data
|
||||
@TableName(value = "server_ai_log")
|
||||
public class ServerAiLog {
|
||||
/**
|
||||
* 日志主键
|
||||
*/
|
||||
@TableId(value = "log_id", type = IdType.AUTO)
|
||||
@ApiModelProperty(value="日志主键")
|
||||
private Long logId;
|
||||
|
||||
/**
|
||||
* 日志主键
|
||||
*/
|
||||
@TableField(value = "log_name")
|
||||
@ApiModelProperty(value="日志主键")
|
||||
private String logName;
|
||||
|
||||
/**
|
||||
* 日志路径
|
||||
*/
|
||||
@TableField(value = "log_file_path")
|
||||
@ApiModelProperty(value="日志路径")
|
||||
private String logFilePath;
|
||||
|
||||
/**
|
||||
* 日志租户
|
||||
*/
|
||||
@TableField(value = "log_tenant_id")
|
||||
@ApiModelProperty(value="日志租户")
|
||||
private Long logTenantId;
|
||||
|
||||
/**
|
||||
* 用户 Id
|
||||
*/
|
||||
@TableField(value = "log_user_id")
|
||||
@ApiModelProperty(value="用户 Id")
|
||||
private Long logUserId;
|
||||
|
||||
@TableField(value = "creator")
|
||||
@ApiModelProperty(value="")
|
||||
private String creator;
|
||||
|
||||
@TableField(value = "create_time")
|
||||
@ApiModelProperty(value="")
|
||||
private Date createTime;
|
||||
|
||||
@TableField(value = "updater")
|
||||
@ApiModelProperty(value="")
|
||||
private String updater;
|
||||
|
||||
@TableField(value = "update_time")
|
||||
@ApiModelProperty(value="")
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yupi.springbootinit.model.vo.user;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/8/25 14:12
|
||||
*/
|
||||
@Data
|
||||
public class SystemTenantVO {
|
||||
private Date expiredTime;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yupi.springbootinit.service;
|
||||
|
||||
import com.yupi.springbootinit.model.entity.ServerAiLog;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/8/25 13:37
|
||||
*/
|
||||
|
||||
public interface ServerAiLogService extends IService<ServerAiLog>{
|
||||
|
||||
|
||||
Boolean saveLog(MultipartFile file, Long tenantId, Long userId);
|
||||
}
|
||||
@@ -3,7 +3,8 @@ package com.yupi.springbootinit.service;
|
||||
import com.yupi.springbootinit.common.BaseResponse;
|
||||
import com.yupi.springbootinit.model.entity.SystemTenant;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/*
|
||||
import com.yupi.springbootinit.model.vo.user.SystemTenantVO;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/6/20 14:50
|
||||
*/
|
||||
@@ -12,4 +13,6 @@ public interface SystemTenantService extends IService<SystemTenant>{
|
||||
|
||||
|
||||
Long getTenantIdByName(String name);
|
||||
|
||||
SystemTenantVO getTenantIdExpired(Long tenantId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.yupi.springbootinit.service.impl;
|
||||
|
||||
import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yupi.springbootinit.mapper.ServerAiLogMapper;
|
||||
import com.yupi.springbootinit.model.entity.ServerAiLog;
|
||||
import com.yupi.springbootinit.service.ServerAiLogService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/8/25 13:37
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ServerAiLogServiceImpl extends ServiceImpl<ServerAiLogMapper, ServerAiLog> implements ServerAiLogService{
|
||||
|
||||
@Resource
|
||||
private ServerAiLogMapper serverAiLogMapper;
|
||||
|
||||
@Value("${ai_log_path}")
|
||||
private String basePath;
|
||||
|
||||
@Override
|
||||
public Boolean saveLog(MultipartFile file, Long tenantId, Long userId) {
|
||||
|
||||
if (file.isEmpty()) {
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"上传文件为空");
|
||||
}
|
||||
Path dir = Paths.get(basePath, tenantId.toString(), userId.toString());
|
||||
if (!Files.exists(dir)) {
|
||||
try {
|
||||
Files.createDirectories(dir);
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"创建目录失败");
|
||||
}
|
||||
}
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
Path target = dir.resolve(originalFilename);
|
||||
try {
|
||||
Files.copy(file.getInputStream(), target, StandardCopyOption.REPLACE_EXISTING);
|
||||
log.info("文件名{},文件上传路径{},",originalFilename,target);
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"保存文件失败");
|
||||
}
|
||||
ServerAiLog log = new ServerAiLog();
|
||||
log.setLogName(originalFilename);
|
||||
log.setLogFilePath(target.toString());
|
||||
log.setLogTenantId(tenantId);
|
||||
log.setLogUserId(userId);
|
||||
log.setCreator(String.valueOf(userId)); // 可替换为当前登录用户
|
||||
return serverAiLogMapper.insert(log) == 1;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.yupi.springbootinit.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.yupi.springbootinit.common.BaseResponse;
|
||||
import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import com.yupi.springbootinit.model.vo.user.SystemTenantVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
@@ -11,6 +13,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yupi.springbootinit.model.entity.SystemTenant;
|
||||
import com.yupi.springbootinit.mapper.SystemTenantMapper;
|
||||
import com.yupi.springbootinit.service.SystemTenantService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/6/20 14:50
|
||||
@@ -19,6 +23,9 @@ import com.yupi.springbootinit.service.SystemTenantService;
|
||||
@Service
|
||||
public class SystemTenantServiceImpl extends ServiceImpl<SystemTenantMapper, SystemTenant> implements SystemTenantService{
|
||||
|
||||
@Resource
|
||||
private SystemTenantMapper systemTenantMapper;
|
||||
|
||||
@Override
|
||||
public Long getTenantIdByName(String name) {
|
||||
QueryWrapper<SystemTenant> queryWrapper = new QueryWrapper<>();
|
||||
@@ -31,4 +38,12 @@ public class SystemTenantServiceImpl extends ServiceImpl<SystemTenantMapper, Sys
|
||||
return systemTenant.getId();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemTenantVO getTenantIdExpired(Long tenantId) {
|
||||
SystemTenant systemTenant = systemTenantMapper.selectById(tenantId);
|
||||
SystemTenantVO systemTenantVO = new SystemTenantVO();
|
||||
systemTenantVO.setExpiredTime(systemTenant.getExpireTime());
|
||||
return systemTenantVO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,4 +107,6 @@ sa-token:
|
||||
|
||||
|
||||
md5:
|
||||
salt: (-FhqvXO,wMz
|
||||
salt: (-FhqvXO,wMz
|
||||
|
||||
ai_log_path: /test/ai_log
|
||||
22
src/main/resources/mapper/ServerAiLogMapper.xml
Normal file
22
src/main/resources/mapper/ServerAiLogMapper.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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.yupi.springbootinit.mapper.ServerAiLogMapper">
|
||||
<resultMap id="BaseResultMap" type="com.yupi.springbootinit.model.entity.ServerAiLog">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table server_ai_log-->
|
||||
<id column="log_id" jdbcType="BIGINT" property="logId" />
|
||||
<result column="log_name" jdbcType="VARCHAR" property="logName" />
|
||||
<result column="log_file_path" jdbcType="VARCHAR" property="logFilePath" />
|
||||
<result column="log_tenant_id" jdbcType="BIGINT" property="logTenantId" />
|
||||
<result column="log_user_id" jdbcType="BIGINT" property="logUserId" />
|
||||
<result column="creator" jdbcType="VARCHAR" property="creator" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="updater" jdbcType="VARCHAR" property="updater" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
log_id, log_name, log_file_path, log_tenant_id, log_user_id, creator, create_time,
|
||||
updater, update_time
|
||||
</sql>
|
||||
</mapper>
|
||||
@@ -10,7 +10,8 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
* @from <a href="https://yupi.icu">编程导航知识星球</a>
|
||||
*/
|
||||
@SpringBootTest
|
||||
class MainApplicationTests {
|
||||
class
|
||||
MainApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
|
||||
Reference in New Issue
Block a user