chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
e396568cc3
commit
5ee51d1913
2918 files changed
+302373
-3
No files matched your search
+13
@@ -0,0 +1,13 @@
|
||||
package com.solvway.services.log;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = {"com.solvway"})
|
||||
public class SolvwayServicesLogApplication{
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SolvwayServicesLogApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.solvway.services.log.configuration;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class Config {
|
||||
|
||||
@Bean
|
||||
public ModelMapper modelMapper() {
|
||||
return new ModelMapper();
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package com.solvway.services.log.configuration;
|
||||
|
||||
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
|
||||
import com.google.cloud.spring.pubsub.PubSubAdmin;
|
||||
import com.google.cloud.spring.pubsub.core.PubSubTemplate;
|
||||
import com.google.cloud.spring.pubsub.integration.AckMode;
|
||||
import com.google.cloud.spring.pubsub.integration.inbound.PubSubInboundChannelAdapter;
|
||||
import com.google.pubsub.v1.ExpirationPolicy;
|
||||
import com.google.pubsub.v1.Subscription;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class PubSubConfig {
|
||||
|
||||
private static final String PROJECTS_PREFIX = "projects/";
|
||||
private static final String TOPICS_PREFIX = "/topics/";
|
||||
private static final String SUBSCRIPTIONS_PREFIX = "/subscriptions/";
|
||||
|
||||
@Value("${spring.cloud.gcp.project-id}")
|
||||
public String projectId;
|
||||
|
||||
@Value("${pubsub.backoffice.topic}")
|
||||
public String backofficeTopic;
|
||||
|
||||
@Value("${pubsub.backoffice.subscription}")
|
||||
public String backofficeSubscription;
|
||||
@Value("${pubsub.response-time-log.topic}")
|
||||
public String responseTimeLogTopic;
|
||||
|
||||
@Value("${pubsub.response-time-log.subscription}")
|
||||
public String responseTimeLogSubscription;
|
||||
@Value("${pubsub.error-log.topic}")
|
||||
public String errorLogTopic;
|
||||
|
||||
@Value("${pubsub.error-log.subscription}")
|
||||
public String errorLogSubscription;
|
||||
|
||||
private final PubSubAdmin pubSubAdmin;
|
||||
|
||||
private final SubscriptionAdminClient subscriptionAdminClient;
|
||||
|
||||
@PostConstruct
|
||||
public void newTopic() {
|
||||
if(pubSubAdmin.getTopic(backofficeTopic)==null) {
|
||||
pubSubAdmin.createTopic(backofficeTopic);
|
||||
}
|
||||
if (pubSubAdmin.getTopic(responseTimeLogTopic) == null) {
|
||||
pubSubAdmin.createTopic(responseTimeLogTopic);
|
||||
}
|
||||
if (pubSubAdmin.getTopic(errorLogTopic) == null) {
|
||||
pubSubAdmin.createTopic(errorLogTopic);
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void newSubscription() {
|
||||
if(pubSubAdmin.getSubscription(backofficeSubscription)==null) {
|
||||
Subscription request = Subscription.newBuilder()
|
||||
.setTopic(PROJECTS_PREFIX+projectId+TOPICS_PREFIX+backofficeTopic)
|
||||
.setName(PROJECTS_PREFIX+projectId+SUBSCRIPTIONS_PREFIX+backofficeSubscription)
|
||||
.setRetainAckedMessages(true)
|
||||
.setExpirationPolicy(ExpirationPolicy.newBuilder().setTtl(com.google.protobuf.Duration.newBuilder().setSeconds(31536000)).build())
|
||||
.build();
|
||||
subscriptionAdminClient.createSubscription(request);
|
||||
|
||||
}
|
||||
if (pubSubAdmin.getSubscription(responseTimeLogSubscription) == null) {
|
||||
Subscription request = Subscription.newBuilder()
|
||||
.setTopic(PROJECTS_PREFIX + projectId + TOPICS_PREFIX + responseTimeLogTopic)
|
||||
.setName(PROJECTS_PREFIX + projectId + SUBSCRIPTIONS_PREFIX + responseTimeLogSubscription)
|
||||
.setRetainAckedMessages(true)
|
||||
.setExpirationPolicy(ExpirationPolicy.newBuilder().setTtl(com.google.protobuf.Duration.newBuilder().setSeconds(31536000)).build())
|
||||
.build();
|
||||
subscriptionAdminClient.createSubscription(request);
|
||||
}
|
||||
if (pubSubAdmin.getSubscription(errorLogSubscription) == null) {
|
||||
Subscription request = Subscription.newBuilder()
|
||||
.setTopic(PROJECTS_PREFIX + projectId + TOPICS_PREFIX + errorLogTopic)
|
||||
.setName(PROJECTS_PREFIX + projectId + SUBSCRIPTIONS_PREFIX + errorLogSubscription)
|
||||
.setRetainAckedMessages(true)
|
||||
.setExpirationPolicy(ExpirationPolicy.newBuilder().setTtl(com.google.protobuf.Duration.newBuilder().setSeconds(31536000)).build())
|
||||
.build();
|
||||
subscriptionAdminClient.createSubscription(request);
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PubSubInboundChannelAdapter backofficeSubscriptionChannelAdapter(
|
||||
@Qualifier("backofficeSubscriptionChannel") MessageChannel inputChannel, PubSubTemplate pubSubTemplate) {
|
||||
PubSubInboundChannelAdapter adapter = new PubSubInboundChannelAdapter(pubSubTemplate, backofficeSubscription);
|
||||
adapter.setOutputChannel(inputChannel);
|
||||
adapter.setAckMode(AckMode.MANUAL);
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PubSubInboundChannelAdapter reponseTimeLogSubscriptionChannelAdapter(
|
||||
@Qualifier("reponseTimeLogSubscriptionChannel") MessageChannel inputChannel, PubSubTemplate pubSubTemplate) {
|
||||
PubSubInboundChannelAdapter adapter = new PubSubInboundChannelAdapter(pubSubTemplate, responseTimeLogSubscription);
|
||||
adapter.setOutputChannel(inputChannel);
|
||||
adapter.setAckMode(AckMode.MANUAL);
|
||||
return adapter;
|
||||
}
|
||||
// @Bean
|
||||
// public PubSubInboundChannelAdapter errorLogSubscriptionChannelAdapter(
|
||||
// @Qualifier("errorLogSubscriptionChannel") MessageChannel inputChannel, PubSubTemplate pubSubTemplate) {
|
||||
// PubSubInboundChannelAdapter adapter = new PubSubInboundChannelAdapter(pubSubTemplate, errorLogSubscription);
|
||||
// adapter.setOutputChannel(inputChannel);
|
||||
// adapter.setAckMode(AckMode.MANUAL);
|
||||
// return adapter;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public MessageChannel backofficeSubscriptionChannel() {
|
||||
return new DirectChannel();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageChannel reponseTimeLogSubscriptionChannel() {
|
||||
return new DirectChannel();
|
||||
}
|
||||
// @Bean
|
||||
// public MessageChannel errorLogSubscriptionChannel() {
|
||||
// return new DirectChannel();
|
||||
// }
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.solvway.services.log.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Value("#{${cache.time-to-live}}")
|
||||
private int defaultTtl;
|
||||
|
||||
@Value("${spring.data.redis.host}")
|
||||
public String hostname;
|
||||
|
||||
@Value("${spring.data.redis.port}")
|
||||
public int port;
|
||||
|
||||
@Bean
|
||||
JedisConnectionFactory jedisConnectionFactory() {
|
||||
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(hostname, port);
|
||||
return new JedisConnectionFactory(redisStandaloneConfiguration);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String,Object> redisTemplate() {
|
||||
final RedisTemplate<String,Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new GenericToStringSerializer<>(Object.class));
|
||||
redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
|
||||
redisTemplate.setConnectionFactory(jedisConnectionFactory());
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisCacheConfiguration cacheConfiguration() {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
JdkSerializationRedisSerializer jdkSerializer = new JdkSerializationRedisSerializer(loader);
|
||||
SerializationPair<Object> pair = SerializationPair.fromSerializer(jdkSerializer);
|
||||
|
||||
return RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofSeconds(defaultTtl))
|
||||
.disableCachingNullValues().serializeValuesWith(pair);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisCacheManager cacheManager() {
|
||||
return RedisCacheManager.builder(jedisConnectionFactory())
|
||||
.cacheDefaults(cacheConfiguration())
|
||||
.transactionAware()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.solvway.services.log.configuration;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Converter
|
||||
public class StringListConverter implements AttributeConverter<List<String>, String> {
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(List<String> list) {
|
||||
if(list!=null && !list.isEmpty()) {
|
||||
return String.join(",", list);
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> convertToEntityAttribute(String joined) {
|
||||
if(joined!=null && !joined.isEmpty()) {
|
||||
return new ArrayList<>(Arrays.asList(joined.split(",")));
|
||||
}else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.solvway.services.log.controller;
|
||||
|
||||
import com.solvway.services.log.model.BoardConnectionStatus;
|
||||
import com.solvway.services.log.model.BoardConnectionStatusMain;
|
||||
import com.solvway.services.log.service.BoardConnectionStatusMainService;
|
||||
import com.solvway.services.log.service.BoardConnectionStatusService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequestMapping("/log/boardConnectionStatus")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class BoardConnectionStatusController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BoardConnectionStatusController.class);
|
||||
|
||||
private final BoardConnectionStatusService boardConnectionStatusService;
|
||||
|
||||
private final BoardConnectionStatusMainService boardConnectionStatusMainService;
|
||||
@RequestMapping("/save")
|
||||
public boolean save(@RequestBody BoardConnectionStatus status) {
|
||||
try {
|
||||
status.setCreateDateTime(LocalDateTime.now());
|
||||
boardConnectionStatusService.save(status);
|
||||
return true;
|
||||
} catch (Exception ignore) {
|
||||
log.error(ignore.getLocalizedMessage(),ignore);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@RequestMapping("/main/findByBranchCode/{branchCode}")
|
||||
public Optional<BoardConnectionStatusMain> findByBranchCode(@PathVariable("branchCode") String branchCode) {
|
||||
return boardConnectionStatusMainService.findByBranchCode(branchCode);
|
||||
}
|
||||
|
||||
@RequestMapping("/main/findAll")
|
||||
public List<BoardConnectionStatusMain> findByAll() {
|
||||
return boardConnectionStatusMainService.findAll();
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package com.solvway.services.log.controller;
|
||||
|
||||
import com.solvway.core.utils.StackTraceUtil;
|
||||
import com.solvway.services.log.model.BackOfficeAccessLog;
|
||||
import com.solvway.services.log.model.MemberAccessLog;
|
||||
import com.solvway.services.log.model.ResponseTime;
|
||||
import com.solvway.services.log.service.BackOfficeAccessLogService;
|
||||
import com.solvway.services.log.service.MemberAccessLogService;
|
||||
import com.solvway.services.log.service.ResponseTimeService;
|
||||
import com.solvway.services.log.util.paging.PageableRest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.TypeToken;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequestMapping("/log")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class LogController {
|
||||
private static final Logger log = LoggerFactory.getLogger(LogController.class);
|
||||
|
||||
private static final String PAGEABLE_REST = "pageableRest";
|
||||
private static final String PROPERTY = "property";
|
||||
|
||||
private final BackOfficeAccessLogService backOfficeAccessLogService;
|
||||
|
||||
private final MemberAccessLogService memberAccessLogService;
|
||||
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
private final ResponseTimeService responseTimeService;
|
||||
|
||||
@RequestMapping("/findAllPageable")
|
||||
public Page<BackOfficeAccessLog> findAllPageable(@RequestBody PageableRest pageable) {
|
||||
return backOfficeAccessLogService.findAllPageable(pageable);
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
public void save(@RequestBody BackOfficeAccessLog backOfficeAccessLog) {
|
||||
try {
|
||||
backOfficeAccessLogService.save(backOfficeAccessLog);
|
||||
} catch (Exception ignore) {
|
||||
log.info("Error From : {}", backOfficeAccessLog.getFunctionName());
|
||||
log.info("Data : {}", backOfficeAccessLog.getParameter());
|
||||
log.error(ignore.getMessage(), ignore);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/saveMemberLog")
|
||||
public void save(@RequestBody MemberAccessLog memberAccessLog) {
|
||||
try {
|
||||
memberAccessLogService.save(memberAccessLog);
|
||||
} catch (Exception ignore) {
|
||||
log.error(ignore.getMessage(), ignore);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/findByPropertyAndPageable")
|
||||
public Page<BackOfficeAccessLog> findByPropertyAndPageable(@RequestBody Map<String, Object> param){
|
||||
Page<BackOfficeAccessLog> page = Page.empty();
|
||||
try {
|
||||
PageableRest pageable = modelMapper.map(param.get(PAGEABLE_REST), PageableRest.class);
|
||||
Type listType = new TypeToken<HashMap<String, String>>() {}.getType();
|
||||
Map<String, String> property = modelMapper.map(param.get(PROPERTY), listType);
|
||||
page = backOfficeAccessLogService.findByPropertyAndPageable(property, pageable);
|
||||
}catch(Exception e) {
|
||||
StackTraceUtil.printStackTrace(log, e);
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
@RequestMapping("/member/findByPropertyAndPageable")
|
||||
public Page<MemberAccessLog> findMemberAccessLogByPropertyAndPageable(@RequestBody Map<String, Object> param){
|
||||
Page<MemberAccessLog> page = Page.empty();
|
||||
try {
|
||||
PageableRest pageable = modelMapper.map(param.get(PAGEABLE_REST), PageableRest.class);
|
||||
Type listType = new TypeToken<HashMap<String, String>>() {}.getType();
|
||||
Map<String, String> property = modelMapper.map(param.get(PROPERTY), listType);
|
||||
page = memberAccessLogService.findByPropertyAndPageable(property, pageable);
|
||||
}catch(Exception e) {
|
||||
StackTraceUtil.printStackTrace(log, e);
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
@RequestMapping("/findById/{id}")
|
||||
public Optional<BackOfficeAccessLog> findById(@PathVariable("id") Long id) {
|
||||
return backOfficeAccessLogService.findById(id);
|
||||
}
|
||||
|
||||
@RequestMapping("/responseTime/requestCountChart")
|
||||
public List<String[]> requestCountChart() throws ParseException {
|
||||
return responseTimeService.getRequestChart();
|
||||
}
|
||||
|
||||
@RequestMapping("/responseTime/findByPropertyAndPageable")
|
||||
public Page<ResponseTime> findResponseTimeByPropertyAndPageable(@RequestBody Map<String, Object> param){
|
||||
Page<ResponseTime> page = Page.empty();
|
||||
try {
|
||||
PageableRest pageable = modelMapper.map(param.get(PAGEABLE_REST), PageableRest.class);
|
||||
Type listType = new TypeToken<HashMap<String, String>>() {}.getType();
|
||||
Map<String, String> property = modelMapper.map(param.get(PROPERTY), listType);
|
||||
page = responseTimeService.findByPropertyAndPageable(property, pageable);
|
||||
}catch(Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return page;
|
||||
}
|
||||
@RequestMapping("/responseTime/findById/{id}")
|
||||
public Optional<ResponseTime> findResponseTimeById(@PathVariable("id") Long id){
|
||||
return responseTimeService.findById(id);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.solvway.services.log.model;
|
||||
|
||||
import com.solvway.services.log.configuration.StringListConverter;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Entity
|
||||
public class BackOfficeAccessLog{
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String userName;
|
||||
|
||||
private LocalDateTime dateTime = LocalDateTime.now();
|
||||
|
||||
private String module;
|
||||
|
||||
private String functionName;
|
||||
|
||||
private String parameter;
|
||||
|
||||
@Column
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> dataBefore;
|
||||
|
||||
@Column
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> dataAfter;
|
||||
|
||||
@Column
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> dataBeforeToDisplay;
|
||||
|
||||
@Column
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> dataAfterToDisplay;
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.solvway.services.log.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Entity
|
||||
public class BoardConnectionStatus {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String boardModel;
|
||||
private String branchCode;
|
||||
private Integer temperature;
|
||||
private String randomLogConnectionDateTime;
|
||||
private Integer outGoodStatus;
|
||||
private LocalDateTime createDateTime;
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.solvway.services.log.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Entity
|
||||
public class BoardConnectionStatusMain {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String boardModel;
|
||||
private String branchCode;
|
||||
private Integer temperature;
|
||||
private String randomLogConnectionDateTime;
|
||||
private Integer outGoodStatus;
|
||||
private LocalDateTime createDateTime;
|
||||
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.solvway.services.log.model;
|
||||
|
||||
import com.solvway.services.log.configuration.StringListConverter;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Entity
|
||||
public class MemberAccessLog {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String userName;
|
||||
|
||||
private LocalDateTime dateTime = LocalDateTime.now();
|
||||
|
||||
private String module;
|
||||
|
||||
private String functionName;
|
||||
|
||||
private String parameter;
|
||||
|
||||
@Column
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> dataBefore;
|
||||
|
||||
@Column
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> dataAfter;
|
||||
|
||||
@Column
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> dataBeforeToDisplay;
|
||||
|
||||
@Column
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> dataAfterToDisplay;
|
||||
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.solvway.services.log.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class MongoConnection {
|
||||
@Id
|
||||
private String id;
|
||||
private LocalDateTime transactionDateTime;
|
||||
|
||||
public MongoConnection() {
|
||||
this.transactionDateTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.solvway.services.log.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class RabbitLog {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
private Date dateTime;
|
||||
|
||||
private String data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.solvway.services.log.model;
|
||||
|
||||
import com.solvway.core.enums.GeneralEnum.CmsPlatform;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
public class ResponseTime {
|
||||
@Id
|
||||
private Long id;
|
||||
private LocalDateTime requestTime;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private CmsPlatform sourcePlatform = CmsPlatform.BO;
|
||||
private long timeUsedMs;
|
||||
private String method;
|
||||
private String url;
|
||||
private String functionCalled;
|
||||
private String username;
|
||||
private String httpHeaders;
|
||||
private String userAgent;
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.solvway.services.log.pubsub;
|
||||
|
||||
import com.google.cloud.spring.pubsub.support.BasicAcknowledgeablePubsubMessage;
|
||||
import com.google.cloud.spring.pubsub.support.GcpPubSubHeaders;
|
||||
import com.solvway.core.enums.GeneralEnum;
|
||||
import com.solvway.core.utils.PubSubUtil;
|
||||
import com.solvway.services.log.model.BackOfficeAccessLog;
|
||||
import com.solvway.services.log.model.ResponseTime;
|
||||
import com.solvway.services.log.repo.BackOfficeAccessLogRepository;
|
||||
import com.solvway.services.log.service.ResponseTimeService;
|
||||
import com.solvway.services.log.util.RedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class PubSubListener {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PubSubListener.class);
|
||||
|
||||
private final RedisUtil<String> redisUtil;
|
||||
|
||||
private final PubSubUtil pubSubUtil;
|
||||
|
||||
@Bean
|
||||
@ServiceActivator(inputChannel = "backofficeSubscriptionChannel")
|
||||
public MessageHandler messageReceiver(BackOfficeAccessLogRepository backOfficeAccessLogRepository) {
|
||||
return message -> {
|
||||
try {
|
||||
pubSubUtil.checkMessageId(redisUtil.getRedisTemplate(), message.getHeaders());
|
||||
backOfficeAccessLogRepository.save(pubSubUtil.convertToOriginalObject(message.getPayload(), BackOfficeAccessLog.class));
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getLocalizedMessage(), ex);
|
||||
}finally {
|
||||
BasicAcknowledgeablePubsubMessage originalMessage = message.getHeaders()
|
||||
.get(GcpPubSubHeaders.ORIGINAL_MESSAGE, BasicAcknowledgeablePubsubMessage.class);
|
||||
if (originalMessage != null) {
|
||||
originalMessage.ack();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ServiceActivator(inputChannel = "reponseTimeLogSubscriptionChannel")
|
||||
public MessageHandler messageReceiver2(ResponseTimeService responseTimeService) {
|
||||
return message -> {
|
||||
try {
|
||||
pubSubUtil.checkMessageId(redisUtil.getRedisTemplate(), message.getHeaders());
|
||||
ResponseTime bean = pubSubUtil.convertToOriginalObject(message.getPayload(), ResponseTime.class);
|
||||
bean = responseTimeService.save(bean);
|
||||
updateAppSession(bean);
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getLocalizedMessage(), ex);
|
||||
} finally {
|
||||
BasicAcknowledgeablePubsubMessage originalMessage = message.getHeaders()
|
||||
.get(GcpPubSubHeaders.ORIGINAL_MESSAGE, BasicAcknowledgeablePubsubMessage.class);
|
||||
if (originalMessage != null) {
|
||||
originalMessage.ack();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void updateAppSession(ResponseTime bean) {
|
||||
try {
|
||||
if (bean.getSourcePlatform().equals(GeneralEnum.CmsPlatform.APP)
|
||||
&& StringUtils.hasLength(bean.getUsername())
|
||||
&& !"ANONYMOUS".equalsIgnoreCase(bean.getUsername())) {
|
||||
redisUtil.putValueWithExpireTime("APP.SESSION." + bean.getUsername(), bean.getRequestTime().toString(), 30, TimeUnit.MINUTES);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.solvway.services.log.repo;
|
||||
|
||||
import com.solvway.services.log.model.BackOfficeAccessLog;
|
||||
import com.solvway.services.log.repo.custom.JpaRepositoryCustom;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface BackOfficeAccessLogRepository extends JpaRepository<BackOfficeAccessLog, Long>, JpaRepositoryCustom<BackOfficeAccessLog>{
|
||||
List<BackOfficeAccessLog> findByFunctionName(String functionName);
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.solvway.services.log.repo;
|
||||
|
||||
import com.solvway.core.utils.DateTimeFormatterUtil;
|
||||
import com.solvway.core.utils.StackTraceUtil;
|
||||
import com.solvway.services.log.model.BackOfficeAccessLog;
|
||||
import com.solvway.services.log.repo.custom.JpaRepositoryCustom;
|
||||
import com.solvway.services.log.util.paging.PageableRest;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.criteria.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class BackOfficeAccessLogRepositoryImpl implements JpaRepositoryCustom<BackOfficeAccessLog>{
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BackOfficeAccessLogRepositoryImpl.class);
|
||||
|
||||
private final EntityManager em;
|
||||
|
||||
private final DateTimeFormatterUtil dateTimeFormatterUtil;
|
||||
|
||||
@Override
|
||||
public Page<BackOfficeAccessLog> findByPropertyAndPageable(Map<String, String> property,
|
||||
PageableRest pageableRest) {
|
||||
Pageable pageable = PageRequest.of(pageableRest.getNumber(), pageableRest.getSize(), pageableRest.getSort());
|
||||
Sort sort = pageableRest.getSort();
|
||||
CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
CriteriaQuery<BackOfficeAccessLog> cq = cb.createQuery(BackOfficeAccessLog.class);
|
||||
Root<BackOfficeAccessLog> root = cq.from(BackOfficeAccessLog.class);
|
||||
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
|
||||
Root<BackOfficeAccessLog> rootCount = countQuery.from(BackOfficeAccessLog.class);
|
||||
List<BackOfficeAccessLog> resultList = new ArrayList<>();
|
||||
Long count = 0l;
|
||||
try {
|
||||
//[START] Criteria Searching
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
List<Predicate> predicatesCount = new ArrayList<>();
|
||||
|
||||
property.forEach((k, value) -> {
|
||||
if(null!=value && !value.isEmpty()) {
|
||||
switch (k) {
|
||||
case "id" -> {
|
||||
predicates.add(cb.equal(root.get(k), Long.parseLong(value)));
|
||||
predicatesCount.add(cb.equal(rootCount.get(k), Long.parseLong(value)));
|
||||
}
|
||||
case "userName", "functionName", "module" -> {
|
||||
predicates.add(cb.equal(root.get(k), value));
|
||||
predicatesCount.add(cb.equal(rootCount.get(k), value));
|
||||
}
|
||||
default -> {
|
||||
// Property not handled
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//[END] Criteria Searching
|
||||
|
||||
//Generate Query with criteria
|
||||
cq.where(predicates.toArray(new Predicate[0]));
|
||||
|
||||
//[START] Order by
|
||||
List<Order> orderList = new ArrayList<>();
|
||||
sort.forEach(o->{
|
||||
if(o.isAscending()) {
|
||||
orderList.add(cb.asc(root.get(o.getProperty())));
|
||||
}else {
|
||||
orderList.add(cb.desc(root.get(o.getProperty())));
|
||||
}
|
||||
});
|
||||
cq.orderBy(orderList);
|
||||
//[END] Order by
|
||||
|
||||
//Execute Generated Query
|
||||
resultList = em.createQuery(cq).setFirstResult((int) pageable.getOffset()).setMaxResults(pageable.getPageSize()).getResultList();
|
||||
|
||||
// Create Count Query
|
||||
countQuery.select(cb.count(rootCount)).where(predicatesCount.toArray(new Predicate[0]));
|
||||
|
||||
// Fetches the count of all Books as per given criteria
|
||||
count = em.createQuery(countQuery).getSingleResult();
|
||||
}catch(Exception e) {
|
||||
StackTraceUtil.printStackTrace(log, e);
|
||||
}
|
||||
return new PageImpl<>(resultList, pageable, count);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.solvway.services.log.repo;
|
||||
|
||||
import com.solvway.services.log.model.BoardConnectionStatusMain;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface BoardConnectionStatusMainRepository extends JpaRepository<BoardConnectionStatusMain, Long>{
|
||||
Optional<BoardConnectionStatusMain> findByBranchCode(String branchCode);
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.solvway.services.log.repo;
|
||||
|
||||
import com.solvway.services.log.model.BoardConnectionStatus;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface BoardConnectionStatusRepository extends JpaRepository<BoardConnectionStatus, Long>{
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.solvway.services.log.repo;
|
||||
|
||||
import com.solvway.services.log.model.MemberAccessLog;
|
||||
import com.solvway.services.log.repo.custom.JpaRepositoryCustom;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface MemberAccessLogRepository extends JpaRepository<MemberAccessLog, String>, JpaRepositoryCustom<MemberAccessLog>{
|
||||
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package com.solvway.services.log.repo;
|
||||
|
||||
import com.solvway.core.utils.DateTimeFormatterUtil;
|
||||
import com.solvway.core.utils.StackTraceUtil;
|
||||
import com.solvway.services.log.model.MemberAccessLog;
|
||||
import com.solvway.services.log.repo.custom.JpaRepositoryCustom;
|
||||
import com.solvway.services.log.util.paging.PageableRest;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.criteria.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class MemberAccessLogRepositoryImpl implements JpaRepositoryCustom<MemberAccessLog> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MemberAccessLogRepositoryImpl.class);
|
||||
|
||||
private final EntityManager em;
|
||||
|
||||
private final DateTimeFormatterUtil dateTimeFormatterUtil;
|
||||
|
||||
@Override
|
||||
public Page<MemberAccessLog> findByPropertyAndPageable(Map<String, String> property, PageableRest pageableRest) {
|
||||
Pageable pageable = PageRequest.of(pageableRest.getNumber(), pageableRest.getSize(), pageableRest.getSort());
|
||||
Sort sort = pageableRest.getSort();
|
||||
CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
CriteriaQuery<MemberAccessLog> cq = cb.createQuery(MemberAccessLog.class);
|
||||
Root<MemberAccessLog> root = cq.from(MemberAccessLog.class);
|
||||
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
|
||||
Root<MemberAccessLog> rootCount = countQuery.from(MemberAccessLog.class);
|
||||
List<MemberAccessLog> resultList = new ArrayList<>();
|
||||
Long count = 0l;
|
||||
try {
|
||||
//[START] Criteria Searching
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
List<Predicate> predicatesCount = new ArrayList<>();
|
||||
|
||||
property.forEach((k, value) -> {
|
||||
if(null!=value && !value.isEmpty()) {
|
||||
switch (k) {
|
||||
case "id" -> {
|
||||
predicates.add(cb.equal(root.get(k), Long.parseLong(value)));
|
||||
predicatesCount.add(cb.equal(rootCount.get(k), Long.parseLong(value)));
|
||||
}
|
||||
case "userName", "functionName", "module" -> {
|
||||
predicates.add(cb.equal(root.get(k), value));
|
||||
predicatesCount.add(cb.equal(rootCount.get(k), value));
|
||||
}
|
||||
default -> {
|
||||
// Property not handled
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//[END] Criteria Searching
|
||||
|
||||
//Generate Query with criteria
|
||||
cq.where(predicates.toArray(new Predicate[0]));
|
||||
|
||||
//[START] Order by
|
||||
List<Order> orderList = new ArrayList<>();
|
||||
sort.forEach(o->{
|
||||
if(o.isAscending()) {
|
||||
orderList.add(cb.asc(root.get(o.getProperty())));
|
||||
}else {
|
||||
orderList.add(cb.desc(root.get(o.getProperty())));
|
||||
}
|
||||
});
|
||||
cq.orderBy(orderList);
|
||||
//[END] Order by
|
||||
|
||||
//Execute Generated Query
|
||||
resultList = em.createQuery(cq).setFirstResult((int) pageable.getOffset()).setMaxResults(pageable.getPageSize()).getResultList();
|
||||
|
||||
// Create Count Query
|
||||
countQuery.select(cb.count(rootCount)).where(predicatesCount.toArray(new Predicate[0]));
|
||||
|
||||
// Fetches the count of all Books as per given criteria
|
||||
count = em.createQuery(countQuery).getSingleResult();
|
||||
}catch(Exception e) {
|
||||
StackTraceUtil.printStackTrace(log, e);
|
||||
}
|
||||
return new PageImpl<>(resultList, pageable, count);
|
||||
}
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.solvway.services.log.repo;
|
||||
|
||||
import com.solvway.services.log.model.ResponseTime;
|
||||
import com.solvway.services.log.repo.custom.JpaRepositoryCustom;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ResponseTimeRepository extends JpaRepository<ResponseTime, Long>, JpaRepositoryCustom<ResponseTime> {
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package com.solvway.services.log.repo;
|
||||
|
||||
import com.solvway.core.utils.DateTimeFormatterUtil;
|
||||
import com.solvway.services.log.model.ResponseTime;
|
||||
import com.solvway.services.log.repo.custom.JpaRepositoryCustom;
|
||||
import com.solvway.services.log.util.paging.PageableRest;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.criteria.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class ResponseTimeRepositoryImpl implements JpaRepositoryCustom<ResponseTime> {
|
||||
private static final Logger log = LoggerFactory.getLogger(ResponseTimeRepositoryImpl.class);
|
||||
private static final String REQUEST_TIME = "requestTime";
|
||||
|
||||
private final EntityManager em;
|
||||
private final DateTimeFormatterUtil dateTimeFormatterUtil;
|
||||
|
||||
/*
|
||||
* Use JPA Criteria to search
|
||||
* */
|
||||
@Override
|
||||
public Page<ResponseTime> findByPropertyAndPageable(Map<String, String> property, PageableRest pageableRest) {
|
||||
Pageable pageable = PageRequest.of(pageableRest.getNumber(), pageableRest.getSize(), pageableRest.getSort());
|
||||
Sort sort = pageableRest.getSort();
|
||||
CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
|
||||
CriteriaQuery<ResponseTime> cq = cb.createQuery(ResponseTime.class);
|
||||
Root<ResponseTime> root = cq.from(ResponseTime.class);
|
||||
|
||||
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
|
||||
Root<ResponseTime> rootCount = countQuery.from(ResponseTime.class);
|
||||
|
||||
List<Predicate> predicates = buildPredicates(property, cb, root);
|
||||
List<Predicate> predicatesCount = buildPredicates(property, cb, rootCount);
|
||||
|
||||
cq.where(predicates.toArray(new Predicate[0]));
|
||||
cq.orderBy(buildOrders(sort, cb, root));
|
||||
|
||||
List<ResponseTime> resultList = em.createQuery(cq)
|
||||
.setFirstResult((int) pageable.getOffset())
|
||||
.setMaxResults(pageable.getPageSize())
|
||||
.getResultList();
|
||||
|
||||
countQuery.select(cb.count(rootCount)).where(predicatesCount.toArray(new Predicate[0]));
|
||||
Long count = em.createQuery(countQuery).getSingleResult();
|
||||
|
||||
return new PageImpl<>(resultList, pageable, count);
|
||||
}
|
||||
|
||||
private List<Predicate> buildPredicates(Map<String, String> property, CriteriaBuilder cb, Root<ResponseTime> root) {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
property.forEach((k, value) -> {
|
||||
if (StringUtils.hasLength(value)) {
|
||||
addPredicate(predicates, k, value, cb, root);
|
||||
}
|
||||
});
|
||||
return predicates;
|
||||
}
|
||||
|
||||
private void addPredicate(List<Predicate> predicates, String key, String value, CriteriaBuilder cb, Root<ResponseTime> root) {
|
||||
switch (key) {
|
||||
case "id":
|
||||
predicates.add(cb.equal(root.get(key), Long.parseLong(value)));
|
||||
break;
|
||||
case "sourcePlatform":
|
||||
predicates.add(cb.like(root.get(key), "%" + value + "%"));
|
||||
break;
|
||||
case "username":
|
||||
predicates.add(cb.equal(root.get(key), value));
|
||||
break;
|
||||
case "dateFrom":
|
||||
parseAndAddDatePredicate(predicates, value, cb, root, true);
|
||||
break;
|
||||
case "dateTo":
|
||||
parseAndAddDatePredicate(predicates, value, cb, root, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void parseAndAddDatePredicate(List<Predicate> predicates, String value, CriteriaBuilder cb, Root<ResponseTime> root, boolean isFrom) {
|
||||
try {
|
||||
LocalDate date = dateTimeFormatterUtil.parseDate(value);
|
||||
if (isFrom) {
|
||||
predicates.add(cb.greaterThanOrEqualTo(root.get(REQUEST_TIME), date.atStartOfDay()));
|
||||
} else {
|
||||
predicates.add(cb.lessThanOrEqualTo(root.get(REQUEST_TIME), date.atTime(23, 59, 59)));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
log.error("Error parsing date: {}", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Order> buildOrders(Sort sort, CriteriaBuilder cb, Root<ResponseTime> root) {
|
||||
List<Order> orderList = new ArrayList<>();
|
||||
sort.forEach(o -> {
|
||||
if (o.isAscending()) {
|
||||
orderList.add(cb.asc(root.get(o.getProperty())));
|
||||
} else {
|
||||
orderList.add(cb.desc(root.get(o.getProperty())));
|
||||
}
|
||||
});
|
||||
return orderList;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.solvway.services.log.repo.custom;
|
||||
|
||||
import com.solvway.services.log.util.paging.PageableRest;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public interface JpaRepositoryCustom<T> {
|
||||
Page<T> findByPropertyAndPageable(Map<String, String> property, PageableRest pageableRest);
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.solvway.services.log.scheduler;
|
||||
|
||||
import com.solvway.core.utils.DateTimeFormatterUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Service
|
||||
@EnableScheduling
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ResponseTimeLogArchiveScheduler {
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private DateTimeFormatterUtil dateTimeFormatterUtil;
|
||||
|
||||
@Scheduled(cron = "0 0 4 * * ?")
|
||||
public void processResponseTimeLogArchive() throws ParseException {
|
||||
LocalDate d = LocalDate.now().minusDays(1);
|
||||
long executeTime = System.currentTimeMillis();
|
||||
log.info("Processing ResponseTimeLog: {}", d);
|
||||
String tableName = getTableName(d);
|
||||
insertRecords(tableName, d);
|
||||
deleteRecords(tableName, d);
|
||||
log.info("Processed ResponseTimeLog: {}; {}ms", d, System.currentTimeMillis() - executeTime);
|
||||
}
|
||||
|
||||
public String getTableName(LocalDate date) throws ParseException {
|
||||
String dateStr= dateTimeFormatterUtil.format(date, "yyyyMM");
|
||||
String tableName = "response_time_archived_"+dateStr;
|
||||
String SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS "+tableName+" LIKE `response_time`;";
|
||||
log.info("Generating Table : {}", SQL_CREATE_TABLE);
|
||||
jdbcTemplate.execute(SQL_CREATE_TABLE);
|
||||
return tableName;
|
||||
}
|
||||
public void insertRecords(String tableName, LocalDate d) throws ParseException {
|
||||
long executeTime = System.currentTimeMillis();
|
||||
String SQL = "INSERT IGNORE INTO "+tableName + " SELECT * FROM response_time "
|
||||
+ " WHERE request_time between '"+dateTimeFormatterUtil.format(d.atStartOfDay(), "yyyy-MM-dd HH:mm:ss")+"' "
|
||||
+ " and '" + dateTimeFormatterUtil.format(d.atTime(23, 59, 59), "yyyy-MM-dd HH:mm:ss")+"' ;";
|
||||
log.info("Executing insert: {}", SQL);
|
||||
jdbcTemplate.update(SQL);
|
||||
log.info("Time used executing insert: {}; {}ms", d, System.currentTimeMillis() - executeTime);
|
||||
}
|
||||
public void deleteRecords(String tableName, LocalDate d) {
|
||||
long executeTime = System.currentTimeMillis();
|
||||
String SQL=" DELETE `response_time` FROM `response_time` INNER JOIN " + tableName + " WHERE response_time.id = "+tableName+".id;";
|
||||
log.info("Executing delete: {}", SQL);
|
||||
jdbcTemplate.update(SQL);
|
||||
log.info("Time used executing delete: {}; {}ms", d.toString(), System.currentTimeMillis() - executeTime);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.solvway.services.log.service;
|
||||
|
||||
import com.solvway.services.log.model.BackOfficeAccessLog;
|
||||
import com.solvway.services.log.repo.BackOfficeAccessLogRepository;
|
||||
import com.solvway.services.log.util.paging.PageableRest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BackOfficeAccessLogService {
|
||||
|
||||
private final BackOfficeAccessLogRepository backOfficeAccessLogRepository;
|
||||
|
||||
public Page<BackOfficeAccessLog> findAllPageable(PageableRest pageable) {
|
||||
return backOfficeAccessLogRepository.findAll(PageRequest.of(pageable.getNumber(), pageable.getSize(), pageable.getSort()));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public BackOfficeAccessLog save(BackOfficeAccessLog log) {
|
||||
return backOfficeAccessLogRepository.save(log);
|
||||
}
|
||||
|
||||
public Page<BackOfficeAccessLog> findByPropertyAndPageable(Map<String, String> property ,PageableRest pageable){
|
||||
return backOfficeAccessLogRepository.findByPropertyAndPageable(property, pageable);
|
||||
}
|
||||
|
||||
public Optional<BackOfficeAccessLog> findById(Long id){
|
||||
return backOfficeAccessLogRepository.findById(id);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.solvway.services.log.service;
|
||||
|
||||
import com.solvway.services.log.model.BoardConnectionStatusMain;
|
||||
import com.solvway.services.log.repo.BoardConnectionStatusMainRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BoardConnectionStatusMainService {
|
||||
|
||||
private final BoardConnectionStatusMainRepository boardConnectionStatusMainRepository;
|
||||
|
||||
public List<BoardConnectionStatusMain> findAll(){
|
||||
return boardConnectionStatusMainRepository.findAll();
|
||||
}
|
||||
|
||||
public Optional<BoardConnectionStatusMain> findByBranchCode(String branchCode){
|
||||
return boardConnectionStatusMainRepository.findByBranchCode(branchCode);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.solvway.services.log.service;
|
||||
|
||||
import com.solvway.services.log.model.BoardConnectionStatus;
|
||||
import com.solvway.services.log.repo.BoardConnectionStatusRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BoardConnectionStatusService {
|
||||
|
||||
private final BoardConnectionStatusRepository boardConnectionStatusRepository;
|
||||
|
||||
@Transactional
|
||||
public BoardConnectionStatus save(BoardConnectionStatus log) {
|
||||
return boardConnectionStatusRepository.save(log);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.solvway.services.log.service;
|
||||
|
||||
import com.solvway.services.log.model.MemberAccessLog;
|
||||
import com.solvway.services.log.repo.MemberAccessLogRepository;
|
||||
import com.solvway.services.log.util.paging.PageableRest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MemberAccessLogService {
|
||||
|
||||
private final MemberAccessLogRepository memberAccessLogRepository;
|
||||
|
||||
@Transactional
|
||||
public MemberAccessLog save(MemberAccessLog log) {
|
||||
return memberAccessLogRepository.save(log);
|
||||
}
|
||||
|
||||
public Page<MemberAccessLog> findByPropertyAndPageable(Map<String, String> property ,PageableRest pageable){
|
||||
return memberAccessLogRepository.findByPropertyAndPageable(property, pageable);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.solvway.services.log.service;
|
||||
|
||||
import com.solvway.core.utils.DateTimeFormatterUtil;
|
||||
import com.solvway.services.log.model.ResponseTime;
|
||||
import com.solvway.services.log.repo.ResponseTimeRepository;
|
||||
import com.solvway.services.log.util.paging.PageableRest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.PreparedStatementCreator;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ResponseTimeService {
|
||||
private final ResponseTimeRepository repository;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final DateTimeFormatterUtil dateTimeFormatterUtil;
|
||||
|
||||
@Transactional
|
||||
public ResponseTime save(ResponseTime entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
public List<String[]> getRequestChart() throws ParseException {
|
||||
List<String[]> list = new ArrayList<>();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime from = LocalDateTime.now().minusMinutes(30);
|
||||
String query = "SELECT "
|
||||
+ "FROM_UNIXTIME(UNIX_TIMESTAMP(request_time)- UNIX_TIMESTAMP(request_time)%(60)) AS timekey,"
|
||||
+ "count(CASE WHEN source_platform='BO' THEN 1 END) \"BO\","
|
||||
+ "count(CASE WHEN source_platform='APP' THEN 1 END) \"APP\","
|
||||
+ "count(CASE WHEN source_platform='MB' THEN 1 END) \"MB\","
|
||||
+ "count(CASE WHEN source_platform='SK' THEN 1 END) \"SK\","
|
||||
+ "count(CASE WHEN source_platform='RS' THEN 1 END) \"RS\","
|
||||
+ "count(CASE WHEN source_platform='SS' THEN 1 END) \"SS\","
|
||||
+ "count(CASE WHEN source_platform='ES' THEN 1 END) \"ES\""
|
||||
+ "from `response_time` "
|
||||
+ "where request_time between '" + dateTimeFormatterUtil.format(from, "yyyy-MM-dd HH:mm:ss") + "' and '" + dateTimeFormatterUtil.format(now, "yyyy-MM-dd HH:mm:ss") + "' "
|
||||
+ "group by timekey "
|
||||
+ "order by timekey; ";
|
||||
jdbcTemplate.query((PreparedStatementCreator) con -> {
|
||||
final java.sql.PreparedStatement ret = con.prepareStatement(query,
|
||||
ResultSet.TYPE_FORWARD_ONLY,
|
||||
ResultSet.CONCUR_READ_ONLY);
|
||||
ret.setFetchSize(Integer.MIN_VALUE);
|
||||
ret.setFetchDirection(ResultSet.FETCH_FORWARD);
|
||||
return ret;
|
||||
}, rs -> {
|
||||
String[] string = new String[8];
|
||||
string[0] = rs.getString("timeKey");
|
||||
string[1] = rs.getString("BO");
|
||||
string[2] = rs.getString("APP");
|
||||
string[3] = rs.getString("MB");
|
||||
string[4] = rs.getString("SK");
|
||||
string[5] = rs.getString("RS");
|
||||
string[6] = rs.getString("SS");
|
||||
string[7] = rs.getString("ES");
|
||||
list.add(string);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public Page<ResponseTime> findByPropertyAndPageable(Map<String, String> property, PageableRest pageable) {
|
||||
return repository.findByPropertyAndPageable(property, pageable);
|
||||
}
|
||||
|
||||
public Optional<ResponseTime> findById(Long id) {
|
||||
return repository.findById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.solvway.services.log.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class RedisUtil<T> {
|
||||
|
||||
@Getter
|
||||
private final RedisTemplate<String, T> redisTemplate;
|
||||
|
||||
private final HashOperations<String, Object, T> hashOperation;
|
||||
|
||||
private final ValueOperations<String, T> valueOperations;
|
||||
|
||||
public RedisUtil(RedisTemplate<String,T> redisTemplate){
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.hashOperation = redisTemplate.opsForHash();
|
||||
this.valueOperations = redisTemplate.opsForValue();
|
||||
}
|
||||
|
||||
public void putMap(String redisKey, Object key, T data) {
|
||||
hashOperation.put(redisKey, key, data);
|
||||
}
|
||||
|
||||
public T getMapAsSingleEntry(String redisKey, Object key) {
|
||||
return hashOperation.get(redisKey, key);
|
||||
}
|
||||
|
||||
public Map<Object, T> getMapAsAll(String redisKey) {
|
||||
return hashOperation.entries(redisKey);
|
||||
}
|
||||
|
||||
public void putValue(String key, T value) {
|
||||
valueOperations.set(key, value);
|
||||
}
|
||||
|
||||
public void putValueWithExpireTime(String key, T value, long timeout, TimeUnit unit) {
|
||||
valueOperations.set(key, value, timeout, unit);
|
||||
}
|
||||
|
||||
public T getValue(String key) {
|
||||
return valueOperations.get(key);
|
||||
}
|
||||
|
||||
public void setExpire(String key, long timeout, TimeUnit unit) {
|
||||
redisTemplate.expire(key, timeout, unit);
|
||||
}
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.solvway.services.log.util.paging;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PageableRest {
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public static class SortRest {
|
||||
private String direction;
|
||||
private String property;
|
||||
|
||||
}
|
||||
|
||||
private int number;
|
||||
private int size;
|
||||
private List<SortRest> sorts;
|
||||
|
||||
public void setSorts(List<SortRest> sorts) {
|
||||
if (this.sorts == null) {
|
||||
this.sorts = new ArrayList<>();
|
||||
}
|
||||
this.sorts = sorts;
|
||||
}
|
||||
|
||||
public Sort getSort() {
|
||||
Iterator<SortRest> it = this.sorts.iterator();
|
||||
Sort sort = null;
|
||||
while (it.hasNext()) {
|
||||
SortRest sr = it.next();
|
||||
if(sort == null) {
|
||||
sort = Sort.by(new Order(Direction.valueOf(sr.getDirection()), sr.getProperty()));
|
||||
}else {
|
||||
sort = sort.and(Sort.by(new Order(Direction.valueOf(sr.getDirection()), sr.getProperty())));
|
||||
}
|
||||
}
|
||||
|
||||
return sort;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user