commit
98761ef1d3
@ -0,0 +1,39 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.framework.security;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.web.config.WebProperties;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.config.Customizer;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WebProperties webProperties;
|
||||||
|
|
||||||
|
@Value("${spring.boot.admin.context-path:''}")
|
||||||
|
private String adminSeverContextPath;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() {
|
||||||
|
return registry -> {
|
||||||
|
// 通用的接口,可匿名访问 TODO 芋艿:需要抽象出去
|
||||||
|
registry.antMatchers(api("/system/captcha/**")).anonymous();
|
||||||
|
// Spring Boot Admin Server 的安全配置 TODO 芋艿:需要抽象出去
|
||||||
|
registry.antMatchers(adminSeverContextPath).anonymous()
|
||||||
|
.antMatchers(adminSeverContextPath + "/**").anonymous();
|
||||||
|
// 短信回调 API
|
||||||
|
registry.antMatchers(api("/system/sms/callback/**")).anonymous();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String api(String url) {
|
||||||
|
return webProperties.getApiPrefix() + url;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package cn.iocoder.yudao.framework.security.core.aop;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||||
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.UNAUTHORIZED;
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
|
||||||
|
@Aspect
|
||||||
|
@Slf4j
|
||||||
|
public class PreAuthenticatedAspect {
|
||||||
|
|
||||||
|
@Around("@annotation(preAuthenticated)")
|
||||||
|
public Object around(ProceedingJoinPoint joinPoint, PreAuthenticated preAuthenticated) throws Throwable {
|
||||||
|
if (SecurityFrameworkUtils.getLoginUser() == null) {
|
||||||
|
throw exception(UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package cn.iocoder.yudao.userserver;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class UserServerApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(UserServerApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.framework.async.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableAsync
|
||||||
|
public class AsyncConfiguration {
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<http://www.iocoder.cn/Spring-Boot/Async-Job/?yudao>
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* 属于整个 yudao-user-server 的 framework 封装
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
package cn.iocoder.yudao.userserver.framework;
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.framework.security;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.web.config.WebProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.config.Customizer;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WebProperties webProperties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() {
|
||||||
|
return registry -> {
|
||||||
|
registry.antMatchers(api("/**")).anonymous(); // 默认 API 都是用户可访问
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String api(String url) {
|
||||||
|
return webProperties.getApiPrefix() + url;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.controller;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.access.annotation.Secured;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author weir
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
public class HelloController {
|
||||||
|
|
||||||
|
@RequestMapping("/user/hello")
|
||||||
|
public String hello(String hello) {
|
||||||
|
return "echo + " + hello;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/user/info")
|
||||||
|
@PreAuthenticated
|
||||||
|
public String xx() {
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.convert.logger;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 访问日志 Convert
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface InfApiAccessLogConvert {
|
||||||
|
|
||||||
|
InfApiAccessLogConvert INSTANCE = Mappers.getMapper(InfApiAccessLogConvert.class);
|
||||||
|
|
||||||
|
InfApiAccessLogDO convert(ApiAccessLogCreateDTO bean);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.convert.logger;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 错误日志 Convert
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface InfApiErrorLogConvert {
|
||||||
|
|
||||||
|
InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class);
|
||||||
|
|
||||||
|
InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* 提供 POJO 类的实体转换
|
||||||
|
*
|
||||||
|
* 目前使用 MapStruct 框架
|
||||||
|
*/
|
||||||
|
package cn.iocoder.yudao.userserver.modules.infra.convert;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao>
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.file;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
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 lombok.*;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件表
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("inf_file")
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class InfFileDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件路径
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.INPUT)
|
||||||
|
private String id;
|
||||||
|
/**
|
||||||
|
* 文件类型
|
||||||
|
*
|
||||||
|
* 通过 {@link cn.hutool.core.io.FileTypeUtil#getType(InputStream)} 获取
|
||||||
|
*/
|
||||||
|
@TableField(value = "`type`")
|
||||||
|
private String type;
|
||||||
|
/**
|
||||||
|
* 文件内容
|
||||||
|
*/
|
||||||
|
private byte[] content;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.config;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO;
|
||||||
|
import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO;
|
||||||
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfigFrameworkDAO 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class InfConfigDAOImpl implements ConfigFrameworkDAO {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public InfConfigDAOImpl(String jdbcUrl, String username, String password) {
|
||||||
|
DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password);
|
||||||
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) {
|
||||||
|
return jdbcTemplate.query("SELECT id FROM inf_config WHERE update_time > ? LIMIT 1",
|
||||||
|
ResultSet::next, maxUpdateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ConfigRespDTO> selectList() {
|
||||||
|
return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM inf_config", new BeanPropertyRowMapper<>(ConfigRespDTO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.file;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.file.InfFileDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface InfFileMapper extends BaseMapperX<InfFileDO> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 访问日志 Mapper
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface InfApiAccessLogMapper extends BaseMapperX<InfApiAccessLogDO> {
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 错误日志 Mapper
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface InfApiErrorLogMapper extends BaseMapperX<InfApiErrorLogDO> {
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.enums.logger;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 异常数据的处理状态
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum InfApiErrorLogProcessStatusEnum {
|
||||||
|
|
||||||
|
INIT(0, "未处理"),
|
||||||
|
DONE(1, "已处理"),
|
||||||
|
IGNORE(2, "已忽略");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private final Integer status;
|
||||||
|
/**
|
||||||
|
* 资源类型名
|
||||||
|
*/
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.service.auth;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证 Service 接口
|
||||||
|
*
|
||||||
|
* 提供用户的账号密码登陆、token 的校验等认证相关的功能
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface SysAuthService extends SecurityAuthFrameworkService {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.service.auth.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.service.auth.SysAuthService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auth Service 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class SysAuthServiceImpl implements SysAuthService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoginUser verifyTokenAndRefresh(String token) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoginUser mockLogin(Long userId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logout(String token) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.service.logger;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 访问日志 Service 接口
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface InfApiAccessLogService extends ApiAccessLogFrameworkService {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.service.logger;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 错误日志 Service 接口
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface InfApiErrorLogService extends ApiErrorLogFrameworkService {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.service.logger.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.convert.logger.InfApiAccessLogConvert;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.service.logger.InfApiAccessLogService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.annotation.AsyncResult;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 访问日志 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
@Slf4j
|
||||||
|
public class InfApiAccessLogServiceImpl implements InfApiAccessLogService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private InfApiAccessLogMapper apiAccessLogMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Future<Boolean> createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) {
|
||||||
|
InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO);
|
||||||
|
int insert = apiAccessLogMapper.insert(apiAccessLog);
|
||||||
|
return new AsyncResult<>(insert > 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.infra.service.logger.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.convert.logger.InfApiErrorLogConvert;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.infra.service.logger.InfApiErrorLogService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.annotation.AsyncResult;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 错误日志 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
@Slf4j
|
||||||
|
public class InfApiErrorLogServiceImpl implements InfApiErrorLogService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private InfApiErrorLogMapper apiErrorLogMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Future<Boolean> createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) {
|
||||||
|
InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO);
|
||||||
|
apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus());
|
||||||
|
int insert = apiErrorLogMapper.insert(apiErrorLog);
|
||||||
|
return new AsyncResult<>(insert == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules;
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.system.convert.dict;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict.SysDictDataDO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SysDictDataConvert {
|
||||||
|
|
||||||
|
SysDictDataConvert INSTANCE = Mappers.getMapper(SysDictDataConvert.class);
|
||||||
|
|
||||||
|
DictDataRespDTO convert02(SysDictDataDO bean);
|
||||||
|
|
||||||
|
List<DictDataRespDTO> convertList03(Collection<SysDictDataDO> list);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.system.convert;
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典数据表
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@TableName("sys_dict_data")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class SysDictDataDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典数据编号
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 字典排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
/**
|
||||||
|
* 字典标签
|
||||||
|
*/
|
||||||
|
private String label;
|
||||||
|
/**
|
||||||
|
* 字典值
|
||||||
|
*/
|
||||||
|
private String value;
|
||||||
|
/**
|
||||||
|
* 字典类型
|
||||||
|
*
|
||||||
|
* 冗余 {@link SysDictDataDO#getDictType()}
|
||||||
|
*/
|
||||||
|
private String dictType;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*
|
||||||
|
* 枚举 {@link CommonStatusEnum}
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.system.dal.dataobject;
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.system.dal.mysql.dict;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.dict.SysDictDataDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SysDictDataMapper extends BaseMapperX<SysDictDataDO> {
|
||||||
|
|
||||||
|
default SysDictDataDO selectByDictTypeAndValue(String dictType, String value) {
|
||||||
|
return selectOne(new QueryWrapper<SysDictDataDO>().eq("dict_type", dictType)
|
||||||
|
.eq("value", value));
|
||||||
|
}
|
||||||
|
|
||||||
|
default int selectCountByDictType(String dictType) {
|
||||||
|
return selectCount("dict_type", dictType);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) {
|
||||||
|
return selectOne(new QueryWrapper<SysDictDataDO>().select("id")
|
||||||
|
.gt("update_time", maxUpdateTime).last("LIMIT 1")) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.system.dal.mysql;
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package cn.iocoder.yudao.userserver.modules.system.dict;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典数据 Service 接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public interface SysDictDataService extends DictDataFrameworkService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化字典数据的本地缓存
|
||||||
|
*/
|
||||||
|
void initLocalCache();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: yudao-user-server
|
||||||
|
|
||||||
|
profiles:
|
||||||
|
active: local
|
||||||
|
|
||||||
|
# Servlet 配置
|
||||||
|
servlet:
|
||||||
|
# 文件上传相关配置项
|
||||||
|
multipart:
|
||||||
|
max-file-size: 16MB # 单个文件大小
|
||||||
|
max-request-size: 32MB # 设置总上传的文件大小
|
||||||
|
|
||||||
|
# Jackson 配置项
|
||||||
|
jackson:
|
||||||
|
serialization:
|
||||||
|
write-dates-as-timestamps: true # 设置 Date 的格式,使用时间戳
|
||||||
|
write-date-timestamps-as-nanoseconds: false # 设置不使用 nanoseconds 的格式。例如说 1611460870.401,而是直接 1611460870401
|
||||||
|
write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳
|
||||||
|
fail-on-empty-beans: false # 允许序列化无属性的 Bean
|
||||||
|
|
||||||
|
# MyBatis Plus 的配置项
|
||||||
|
mybatis-plus:
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
|
||||||
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印日志
|
||||||
|
global-config:
|
||||||
|
db-config:
|
||||||
|
id-type: AUTO # 自增 ID
|
||||||
|
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
|
||||||
|
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
|
||||||
|
mapper-locations: classpath*:mapper/*.xml
|
||||||
|
type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject
|
||||||
|
|
||||||
|
--- #################### 芋道相关配置 ####################
|
||||||
|
|
||||||
|
yudao:
|
||||||
|
info:
|
||||||
|
version: 1.0.0
|
||||||
|
base-package: cn.iocoder.yudao.userserver
|
||||||
|
web:
|
||||||
|
api-prefix: /api
|
||||||
|
controller-package: ${yudao.info.base-package}
|
||||||
|
swagger:
|
||||||
|
title: 管理后台
|
||||||
|
description: 提供管理员管理的所有功能
|
||||||
|
version: ${yudao.info.version}
|
||||||
|
base-package: ${yudao.info.base-package}.modules
|
||||||
|
captcha:
|
||||||
|
timeout: 5m
|
||||||
|
width: 160
|
||||||
|
height: 60
|
||||||
|
codegen:
|
||||||
|
base-package: ${yudao.info.base-package}
|
||||||
|
db-schemas: ${spring.datasource.dynamic.datasource.master.name}
|
||||||
|
error-code: # 错误码相关配置项
|
||||||
|
constants-class-list:
|
||||||
|
|
||||||
|
debug: false
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
芋道源码 http://www.iocoder.cn
|
||||||
|
Application Version: ${yudao.info.version}
|
||||||
|
Spring Boot Version: ${spring-boot.version}
|
||||||
|
|
||||||
|
.__ __. ______ .______ __ __ _______
|
||||||
|
| \ | | / __ \ | _ \ | | | | / _____|
|
||||||
|
| \| | | | | | | |_) | | | | | | | __
|
||||||
|
| . ` | | | | | | _ < | | | | | | |_ |
|
||||||
|
| |\ | | `--' | | |_) | | `--' | | |__| |
|
||||||
|
|__| \__| \______/ |______/ \______/ \______|
|
||||||
|
|
||||||
|
███╗ ██╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗
|
||||||
|
████╗ ██║██╔═══██╗ ██╔══██╗██║ ██║██╔════╝
|
||||||
|
██╔██╗ ██║██║ ██║ ██████╔╝██║ ██║██║ ███╗
|
||||||
|
██║╚██╗██║██║ ██║ ██╔══██╗██║ ██║██║ ██║
|
||||||
|
██║ ╚████║╚██████╔╝ ██████╔╝╚██████╔╝╚██████╔╝
|
||||||
|
╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝
|
||||||
Loading…
Reference in New Issue