mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-29 20:53:40 +00:00
更新
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
<modules>
|
||||
<module>udf-api-server</module>
|
||||
<module>udf-api-common</module>
|
||||
<module>udf-api-general</module>
|
||||
</modules>
|
||||
<!-- 依赖管理 -->
|
||||
<dependencyManagement>
|
||||
@@ -38,6 +39,12 @@
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!--udf-api-general-->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-api-general</artifactId>
|
||||
<version>${udf-api.version}</version>
|
||||
</dependency>
|
||||
<!-- udf-api-common -->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
|
||||
@@ -30,6 +30,16 @@
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter-datasource-dynamic</artifactId>
|
||||
</dependency>
|
||||
<!-- udf-starter-cache-db -->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter-cache-db</artifactId>
|
||||
</dependency>
|
||||
<!-- udf-starter-queue-db -->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter-queue-db</artifactId>
|
||||
</dependency>
|
||||
<!-- thymeleaf -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
@@ -42,16 +52,7 @@
|
||||
<!-- <version>${itext7.version}</version>-->
|
||||
<!-- <type>pom</type>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- udf-starter-cache-db -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.itkk.udf</groupId>-->
|
||||
<!-- <artifactId>udf-starter-cache-db</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- udf-starter-queue-db -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.itkk.udf</groupId>-->
|
||||
<!-- <artifactId>udf-starter-queue-db</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- udf-starter-file-db -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.itkk.udf</groupId>-->
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.itkk.udf.api.common;
|
||||
|
||||
import org.itkk.udf.starter.cache.db.DbCacheServiceRegistration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@@ -9,4 +11,14 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Configuration
|
||||
public class CommonConfiguration implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* dbCacheServiceRegistration
|
||||
*
|
||||
* @return DbCacheServiceRegistration
|
||||
*/
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
public DbCacheServiceRegistration dbCacheServiceRegistration() {
|
||||
return new DbCacheServiceRegistration();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,67 @@ package org.itkk.udf.api.common;
|
||||
* 常量类
|
||||
*/
|
||||
public class CommonConstant {
|
||||
|
||||
/**
|
||||
* web根路径
|
||||
*/
|
||||
public static final String URL_ROOT_WEB = "/api/udf/web";
|
||||
|
||||
/**
|
||||
* 需认证的web根路径
|
||||
*/
|
||||
public static final String URL_ROOT_WEB_PRIVATE = URL_ROOT_WEB + "/private";
|
||||
|
||||
/**
|
||||
* 无需认证的web根路径
|
||||
*/
|
||||
public static final String URL_ROOT_WEB_PUBLIC = URL_ROOT_WEB + "/public";
|
||||
|
||||
/**
|
||||
* 默认时间格式
|
||||
*/
|
||||
public static final String DEF_DATA_FMT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
/**
|
||||
* 默认锁失败信息
|
||||
*/
|
||||
public static final String DEF_LOCK_FAIL_MSG = "该数据正在被处理中,请稍后再试";
|
||||
|
||||
/**
|
||||
* token参数名
|
||||
*/
|
||||
public static final String PARAMETER_NAME_TOKEN = "token";
|
||||
|
||||
/**
|
||||
* token信息参数名
|
||||
*/
|
||||
public static final String PARAMETER_NAME_TOKEN_INFO = "tokenInfo";
|
||||
|
||||
/**
|
||||
* token超时时间
|
||||
*/
|
||||
public static final long TOKEN_CACHE_TTL = 30 * 60 * 1000L;
|
||||
|
||||
/**
|
||||
* 刷新token时间
|
||||
*/
|
||||
public static final long REFRESH_TOKEN_CACHE_TTL = 15 * 60 * 1000L;
|
||||
|
||||
/**
|
||||
* 锁超时时间
|
||||
*/
|
||||
public static final Long LOCK_EXPAIR = 5 * 60 * 1000L;
|
||||
|
||||
/**
|
||||
* 发送邮件队列名
|
||||
*/
|
||||
public static final String SEND_EMAIL_QUEUE = "SEND_EMAIL_QUEUE";
|
||||
|
||||
/**
|
||||
* 发送邮件队列处理器
|
||||
*/
|
||||
public static final String SEND_EMAIL_QUEUE_HANDLE = "SEND_EMAIL_QUEUE_HANDLE";
|
||||
|
||||
/**
|
||||
* 私有化构造函数
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 属性类
|
||||
*/
|
||||
@@ -17,4 +19,15 @@ public class CommonProperties {
|
||||
* 配置文件前缀
|
||||
*/
|
||||
protected static final String UDF_API_PROPERTIES = "org.itkk.udf.api.common.properties";
|
||||
|
||||
/**
|
||||
* 追踪日志保留天数
|
||||
*/
|
||||
@NotNull(message = UDF_API_PROPERTIES + ".traceLogKeepDays不能为空")
|
||||
private Integer traceLogKeepDays = 5;
|
||||
|
||||
/**
|
||||
* 发送邮件队列并发数
|
||||
*/
|
||||
private Integer sendEmailQueueMaxConcurrency = 1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.itkk.udf.api.common.component;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.itkk.udf.api.common.service.DataHisService;
|
||||
import org.itkk.udf.api.common.service.TraceInfoService;
|
||||
import org.itkk.udf.starter.core.exception.SystemRuntimeException;
|
||||
import org.itkk.udf.starter.core.exception.handle.IExceptionAlert;
|
||||
import org.itkk.udf.starter.core.trace.IDataHis;
|
||||
import org.itkk.udf.starter.core.trace.ITraceAlert;
|
||||
import org.itkk.udf.starter.core.trace.TraceDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DbLogImpl implements ITraceAlert, IExceptionAlert, IDataHis {
|
||||
|
||||
/**
|
||||
* traceInfoService
|
||||
*/
|
||||
@Autowired
|
||||
private TraceInfoService traceInfoService;
|
||||
|
||||
/**
|
||||
* dataHisService
|
||||
*/
|
||||
@Autowired
|
||||
private DataHisService dataHisService;
|
||||
|
||||
/**
|
||||
* internalObjectMapper
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier("internalObjectMapper")
|
||||
private ObjectMapper internalObjectMapper;
|
||||
|
||||
@Override
|
||||
public void save(String traceId, String name, String pk, Object content, String userId) {
|
||||
try {
|
||||
dataHisService.save(traceId, name, pk, internalObjectMapper.writeValueAsString(content), userId);
|
||||
} catch (JsonProcessingException ex) {
|
||||
throw new SystemRuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void alert(String traceId, Exception e) {
|
||||
try {
|
||||
final String type = "IExceptionAlert";
|
||||
traceInfoService.save(traceId, type, internalObjectMapper.writeValueAsString(ExceptionUtils.getStackTrace(e)));
|
||||
} catch (JsonProcessingException ex) {
|
||||
log.warn(traceId + " (IExceptionAlert)记录trace日志失败,错误信息为 : " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void alert(TraceDto traceDto) {
|
||||
try {
|
||||
final String type = "ITraceAlert";
|
||||
traceInfoService.save(traceDto.getTraceId(), type, internalObjectMapper.writeValueAsString(traceDto));
|
||||
} catch (JsonProcessingException e) {
|
||||
log.warn(traceDto.getTraceId() + " (ITraceAlert)记录trace日志失败,错误信息为 : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.itkk.udf.api.common.component;
|
||||
|
||||
import org.itkk.udf.starter.cache.db.service.DbCacheService;
|
||||
import org.itkk.udf.starter.queue.db.IDbQueueLock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DbQueueLockImpl implements IDbQueueLock {
|
||||
|
||||
/**
|
||||
* dbCacheService
|
||||
*/
|
||||
@Autowired
|
||||
private DbCacheService dbCacheService;
|
||||
|
||||
@Override
|
||||
public boolean lock(String key) {
|
||||
final long expire = 30 * 60 * 1000L;
|
||||
return dbCacheService.setNx(key, key, expire);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlock(String key) {
|
||||
dbCacheService.delete(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.itkk.udf.api.common.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SendMailDto implements Serializable {
|
||||
private static final long serialVersionUID = 6443090530533741230L; //ID
|
||||
private String emailSubject; //标题
|
||||
private String emailContent; //主题
|
||||
private Set<String> addres; //地址列表
|
||||
private Map<String, File> fileMap; //附件列表
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package org.itkk.udf.api.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("TF_DATA_HIS")
|
||||
public class DataHisEntity {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId("ID")
|
||||
private String id;
|
||||
/**
|
||||
* 追踪ID
|
||||
*/
|
||||
@TableField("TRACE_ID")
|
||||
private String traceId;
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
@TableField("TABLE_NAME")
|
||||
private String TABLE_NAME;
|
||||
/**
|
||||
* 表主键
|
||||
*/
|
||||
@TableField("TABLE_PK")
|
||||
private String TABLE_PK;
|
||||
/**
|
||||
* 表内容
|
||||
*/
|
||||
@TableField("CONTENT")
|
||||
private String content;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("CREATE_DATE")
|
||||
private Date createDate;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField("CREATE_BY")
|
||||
private String createBy;
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package org.itkk.udf.api.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("TM_PARAMETER")
|
||||
public class ParameterEntity {
|
||||
|
||||
/**
|
||||
* 代码
|
||||
*/
|
||||
@TableId("CODE")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 类别
|
||||
*/
|
||||
@TableField("TYPE")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@TableField("NAME")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@TableField("CONTENT")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField("CREATE_BY")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("CREATE_DATE")
|
||||
private Date createDate;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField("UPDATE_BY")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("UPDATE_DATE")
|
||||
private Date updateDate;
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package org.itkk.udf.api.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("TF_TRACE_INFO")
|
||||
public class TraceInfoEntity {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId("ID")
|
||||
private String ID;
|
||||
/**
|
||||
* 追踪ID
|
||||
*/
|
||||
@TableField("TRACE_ID")
|
||||
private String traceId;
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@TableField("TYPE")
|
||||
private String type;
|
||||
/**
|
||||
* 追踪消息体
|
||||
*/
|
||||
@TableField("CONTENT")
|
||||
private String content;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("CREATE_DATE")
|
||||
private Date createDate;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package org.itkk.udf.api.common.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.itkk.udf.api.common.entity.DataHisEntity;
|
||||
|
||||
@Mapper
|
||||
public interface IDataHisRepository extends BaseMapper<DataHisEntity> {
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.itkk.udf.api.common.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.itkk.udf.api.common.entity.ParameterEntity;
|
||||
|
||||
@Mapper
|
||||
public interface IParameterRepository extends BaseMapper<ParameterEntity> {
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package org.itkk.udf.api.common.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.itkk.udf.api.common.entity.TraceInfoEntity;
|
||||
|
||||
@Mapper
|
||||
public interface ITraceInfoRepository extends BaseMapper<TraceInfoEntity> {
|
||||
/**
|
||||
* 清理追踪日志
|
||||
*
|
||||
* @param traceLogKeepDays traceLogKeepDays
|
||||
*/
|
||||
void clearTraceInfo(@Param("traceLogKeepDays") Integer traceLogKeepDays);
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.itkk.udf.api.common.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.itkk.udf.api.common.entity.DataHisEntity;
|
||||
import org.itkk.udf.api.common.repository.IDataHisRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DataHisService {
|
||||
|
||||
/**
|
||||
* iDataHisRepository
|
||||
*/
|
||||
@Autowired
|
||||
private IDataHisRepository iDataHisRepository;
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param traceId traceId
|
||||
* @param name name
|
||||
* @param pk pk
|
||||
* @param content content
|
||||
* @param userId userId
|
||||
*/
|
||||
public void save(String traceId, String name, String pk, String content, String userId) {
|
||||
DataHisEntity entity = new DataHisEntity();
|
||||
entity.setId(UUID.randomUUID().toString());
|
||||
entity.setTraceId(traceId);
|
||||
entity.setTABLE_NAME(name);
|
||||
entity.setTABLE_PK(pk);
|
||||
entity.setContent(content);
|
||||
entity.setCreateDate(new Date());
|
||||
entity.setCreateBy(userId);
|
||||
iDataHisRepository.insert(entity);
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package org.itkk.udf.api.common.service;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.itkk.udf.api.common.entity.ParameterEntity;
|
||||
import org.itkk.udf.api.common.repository.IParameterRepository;
|
||||
import org.itkk.udf.starter.core.exception.ParameterValidException;
|
||||
import org.itkk.udf.starter.core.exception.SystemRuntimeException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ParameterService {
|
||||
|
||||
/**
|
||||
* iParameterRepository
|
||||
*/
|
||||
@Autowired
|
||||
private IParameterRepository iParameterRepository;
|
||||
|
||||
/**
|
||||
* internalObjectMapper
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier("internalObjectMapper")
|
||||
private ObjectMapper internalObjectMapper;
|
||||
|
||||
/**
|
||||
* 批量返回String类型的内容
|
||||
*
|
||||
* @param codes codes
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> getStringBatch(List<String> codes) {
|
||||
//定义返回值
|
||||
final Map<String, String> rv = new HashMap<>();
|
||||
//判空
|
||||
if (CollectionUtils.isNotEmpty(codes)) {
|
||||
//去重
|
||||
codes = codes.stream().distinct().collect(Collectors.toList());
|
||||
//遍历
|
||||
codes.forEach(code -> {
|
||||
try {
|
||||
rv.put(code, this.getString(code));
|
||||
} catch (Exception e) {
|
||||
rv.put(code, e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
//返回
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回String类型的内容
|
||||
*
|
||||
* @param code code
|
||||
* @return String
|
||||
*/
|
||||
public String getString(String code) {
|
||||
return this.getContent(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回json类型的内容
|
||||
*
|
||||
* @param code code
|
||||
* @param <T> <T>
|
||||
* @return T
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
public <T> T getJson(String code, TypeReference<T> typeReference) {
|
||||
try {
|
||||
//获得内容
|
||||
String content = this.getContent(code);
|
||||
//判空
|
||||
if (StringUtils.isBlank(code)) {
|
||||
return null;
|
||||
}
|
||||
//转换 & 返回
|
||||
return internalObjectMapper.readValue(content, typeReference);
|
||||
} catch (Exception e) {
|
||||
throw new SystemRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得内容
|
||||
*
|
||||
* @param code code
|
||||
* @return String
|
||||
*/
|
||||
private String getContent(String code) {
|
||||
//获得数据
|
||||
ParameterEntity parameterEntity = iParameterRepository.selectById(code);
|
||||
//判空
|
||||
if (parameterEntity == null) {
|
||||
throw new ParameterValidException("代码为" + code + "的变量不存在");
|
||||
}
|
||||
//返回
|
||||
return parameterEntity.getContent();
|
||||
}
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package org.itkk.udf.api.common.service;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.itkk.udf.api.common.CommonProperties;
|
||||
import org.itkk.udf.api.common.entity.TraceInfoEntity;
|
||||
import org.itkk.udf.api.common.repository.ITraceInfoRepository;
|
||||
import org.itkk.udf.starter.cache.db.service.DbCacheService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TraceInfoService {
|
||||
/**
|
||||
* iTraceInfoRepository
|
||||
*/
|
||||
@Autowired
|
||||
private ITraceInfoRepository iTraceInfoRepository;
|
||||
|
||||
/**
|
||||
* dbCacheService
|
||||
*/
|
||||
@Autowired
|
||||
private DbCacheService dbCacheService;
|
||||
|
||||
/**
|
||||
* commonProperties
|
||||
*/
|
||||
@Autowired
|
||||
private CommonProperties commonProperties;
|
||||
|
||||
/**
|
||||
* 定时清理追踪日志
|
||||
*/
|
||||
public void clearTraceInfo() {
|
||||
iTraceInfoRepository.clearTraceInfo(commonProperties.getTraceLogKeepDays());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存log(异步)
|
||||
*
|
||||
* @param traceId traceId
|
||||
* @param type type
|
||||
* @param content content
|
||||
*/
|
||||
@Async
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void save(String traceId, String type, String content) {
|
||||
TraceInfoEntity traceInfoEntity = new TraceInfoEntity();
|
||||
traceInfoEntity.setID(UUID.randomUUID().toString());
|
||||
traceInfoEntity.setTraceId(traceId);
|
||||
traceInfoEntity.setType(type);
|
||||
traceInfoEntity.setContent(content);
|
||||
traceInfoEntity.setCreateDate(new Date());
|
||||
iTraceInfoRepository.insert(traceInfoEntity);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package org.itkk.udf.api.common.web;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import org.itkk.udf.api.common.service.ParameterService;
|
||||
import org.itkk.udf.starter.core.RestResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ParameterBaseController {
|
||||
|
||||
/**
|
||||
* parameterService
|
||||
*/
|
||||
@Autowired
|
||||
private ParameterService parameterService;
|
||||
|
||||
/**
|
||||
* 批量返回String类型的内容
|
||||
*
|
||||
* @param codes codes
|
||||
* @return RestResponse<Map < String, String>>
|
||||
*/
|
||||
@PostMapping("string/batch")
|
||||
public RestResponse<Map<String, String>> getStringBatch(@RequestBody List<String> codes) {
|
||||
return new RestResponse<>(parameterService.getStringBatch(codes));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回String类型的内容
|
||||
*
|
||||
* @param code code
|
||||
* @return RestResponse<String>
|
||||
*/
|
||||
@GetMapping("string/{code}")
|
||||
public RestResponse<String> getString(@PathVariable String code) {
|
||||
return new RestResponse<>(parameterService.getString(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回json类型的map内容
|
||||
*
|
||||
* @param code code
|
||||
* @return RestResponse<Map < String, Object>>
|
||||
*/
|
||||
@GetMapping("json/map/{code}")
|
||||
public RestResponse<Map<String, Object>> getJsonMap(@PathVariable String code) {
|
||||
return new RestResponse<>(parameterService.getJson(code, new TypeReference<Map<String, Object>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回json类型的array内容
|
||||
*
|
||||
* @param code code
|
||||
* @return RestResponse<List < Map < String, Object>>>
|
||||
*/
|
||||
@GetMapping("json/array/{code}")
|
||||
public RestResponse<List<Map<String, Object>>> getJsonArray(@PathVariable String code) {
|
||||
return new RestResponse<>(parameterService.getJson(code, new TypeReference<List<Map<String, Object>>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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="org.itkk.udf.api.common.repository.IDataHisRepository">
|
||||
|
||||
</mapper>
|
||||
@@ -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="org.itkk.udf.api.common.repository.IParameterRepository">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?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="org.itkk.udf.api.common.repository.ITraceInfoRepository">
|
||||
<delete id="clearTraceInfo">
|
||||
DELETE
|
||||
FROM TF_TRACE_INFO A
|
||||
WHERE A.CREATE_DATE <![CDATA[ <= ]]> (SYSDATE - #{traceLogKeepDays})
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- maven坐标 -->
|
||||
<artifactId>udf-api-general</artifactId>
|
||||
<name>udf-api-general</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>https://www.itkk.org/</url>
|
||||
<!-- 父依赖 -->
|
||||
<parent>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-api</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- udf-api-common -->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-api-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package org.itkk.udf.api.general;
|
||||
|
||||
|
||||
import org.itkk.udf.api.common.CommonConstant;
|
||||
import org.itkk.udf.api.common.CommonProperties;
|
||||
import org.itkk.udf.starter.queue.db.DbQueue;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class GeneralConfiguration {
|
||||
|
||||
/**
|
||||
* commonProperties
|
||||
*/
|
||||
@Autowired
|
||||
private CommonProperties commonProperties;
|
||||
|
||||
/**
|
||||
* 发送邮件队列
|
||||
*
|
||||
* @return DbQueue
|
||||
*/
|
||||
@Bean(name = CommonConstant.SEND_EMAIL_QUEUE, destroyMethod = "shutdown")
|
||||
public DbQueue sendEmailQueue() {
|
||||
return new DbQueue(CommonConstant.SEND_EMAIL_QUEUE, commonProperties.getSendEmailQueueMaxConcurrency());
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package org.itkk.udf.api.general.dbqueue;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.itkk.udf.api.common.CommonConstant;
|
||||
import org.itkk.udf.starter.core.exception.handle.IExceptionAlert;
|
||||
import org.itkk.udf.starter.queue.db.IDbQueueHandle;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component(CommonConstant.SEND_EMAIL_QUEUE_HANDLE)
|
||||
@Slf4j
|
||||
public class SendMailQueueHandle implements IDbQueueHandle {
|
||||
|
||||
/**
|
||||
* internalObjectMapper
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier("internalObjectMapper")
|
||||
private ObjectMapper internalObjectMapper;
|
||||
|
||||
/**
|
||||
* iExceptionAlert
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
private IExceptionAlert iExceptionAlert;
|
||||
|
||||
@Override
|
||||
public void handle(String id, String body) {
|
||||
log.warn("邮件发送服务暂未实现");
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package org.itkk.udf.api.general.job;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.itkk.udf.api.common.service.TraceInfoService;
|
||||
import org.itkk.udf.starter.cache.db.service.DbCacheService;
|
||||
import org.itkk.udf.starter.core.CoreUtil;
|
||||
import org.itkk.udf.starter.core.job.IJobHandle;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ClearTraceInfoJob implements IJobHandle {
|
||||
|
||||
/**
|
||||
* dbCacheService
|
||||
*/
|
||||
@Autowired
|
||||
private DbCacheService dbCacheService;
|
||||
|
||||
/**
|
||||
* traceInfoService
|
||||
*/
|
||||
@Autowired
|
||||
private TraceInfoService traceInfoService;
|
||||
|
||||
@Override
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
public void execution() {
|
||||
//开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
//定义key
|
||||
final String key = "job:clearTraceInfo";
|
||||
//定义过期时间(10分钟)
|
||||
final long expire = 10 * 60 * 1000L;
|
||||
//定义job的traceId
|
||||
final String traceId = CoreUtil.getTraceId();
|
||||
//悲观锁-锁定任务
|
||||
if (dbCacheService.setNx(key, Long.valueOf(System.currentTimeMillis()).toString(), expire)) {
|
||||
//日志输出
|
||||
log.info("{} 清理追踪日志(lock success)", traceId);
|
||||
//开始处理
|
||||
try {
|
||||
traceInfoService.clearTraceInfo();
|
||||
} finally {
|
||||
//删除key
|
||||
dbCacheService.delete(key);
|
||||
//日志输出
|
||||
log.info("{} 清理追踪日志(unlock success)(耗时:{}毫秒)", traceId, (System.currentTimeMillis() - startTime));
|
||||
}
|
||||
} else {
|
||||
//日志输出
|
||||
log.info("{} 清理追踪日志(lock fail)", traceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package org.itkk.udf.api.general.web;
|
||||
|
||||
import org.itkk.udf.api.common.CommonConstant;
|
||||
import org.itkk.udf.api.common.web.ParameterBaseController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = CommonConstant.URL_ROOT_WEB_PRIVATE + "parameter/")
|
||||
public class ParameterController extends ParameterBaseController {
|
||||
|
||||
}
|
||||
@@ -20,10 +20,10 @@
|
||||
</properties>
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- udf-api-common -->
|
||||
<!--udf-api-general-->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-api-common</artifactId>
|
||||
<artifactId>udf-api-general</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- 构建 -->
|
||||
|
||||
@@ -19,7 +19,7 @@ org.itkk.udf.starter.datasource.dynamic.properties.map.udf.enable=true
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.url=jdbc:mysql://itkk.org:3306/dev_udf?useUnicode=true&useSSL=false&autoReconnect=true
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.username=dev_udf
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.password=123456
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.driverClassName=com.mysql.jdbc.Driver
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.driverClassName=com.mysql.cj.jdbc.Driver
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.initialSize=1
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.minIdle=1
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.maxActive=2
|
||||
|
||||
@@ -19,7 +19,7 @@ org.itkk.udf.starter.datasource.dynamic.properties.map.udf.enable=true
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.url=jdbc:mysql://itkk.org:3306/dev_prod?useUnicode=true&useSSL=false&autoReconnect=true
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.username=dev_prod
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.password=5ds2c6de54t1fd36e5f
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.driverClassName=com.mysql.jdbc.Driver
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.driverClassName=com.mysql.cj.jdbc.Driver
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.initialSize=1
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.minIdle=1
|
||||
org.itkk.udf.starter.datasource.dynamic.properties.map.udf.maxActive=2
|
||||
|
||||
Reference in New Issue
Block a user