SendAutoSms Connection TEST
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
package app.module.admin.config.application.bean;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
import org.mybatis.spring.SqlSessionTemplate;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
@MapperScan(
|
||||||
|
basePackages = { "app.module.admin", "app.module.core" },
|
||||||
|
annotationClass = org.apache.ibatis.annotations.Mapper.class,
|
||||||
|
sqlSessionFactoryRef = "kriSqlSessionFactory")
|
||||||
|
@EnableTransactionManagement
|
||||||
|
public class KRIConfig {
|
||||||
|
|
||||||
|
@Value("${mybatis.mapper-locations.kri}")
|
||||||
|
private String mybatisMapper;
|
||||||
|
|
||||||
|
@Primary
|
||||||
|
@Bean(name = "kriDataSource")
|
||||||
|
@ConfigurationProperties(prefix = "spring.datasource.kri")
|
||||||
|
public DataSource kriDataSource() {
|
||||||
|
return DataSourceBuilder.create().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Primary
|
||||||
|
@Bean(name = "kriSqlSessionFactory")
|
||||||
|
public SqlSessionFactory kriSqlSessionFactory(@Qualifier("kriDataSource") DataSource dataSource) throws Exception {
|
||||||
|
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
|
||||||
|
sessionFactoryBean.setVfs(SpringBootVFS.class);
|
||||||
|
configureSqlSessionFactory(sessionFactoryBean, dataSource);
|
||||||
|
return sessionFactoryBean.getObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void configureSqlSessionFactory(SqlSessionFactoryBean sessionFactoryBean, DataSource dataSource) throws IOException {
|
||||||
|
sessionFactoryBean.setDataSource(dataSource);
|
||||||
|
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||||
|
sessionFactoryBean.setMapperLocations(resolver.getResources(mybatisMapper));
|
||||||
|
|
||||||
|
// org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
|
||||||
|
// configuration.setMapUnderscoreToCamelCase(true);
|
||||||
|
// configuration.setJdbcTypeForNull(null);
|
||||||
|
// sessionFactoryBean.setConfiguration(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Primary
|
||||||
|
@Bean(name = "kriSqlSessionTemplate")
|
||||||
|
public SqlSessionTemplate kriSqlSessionTemplate(@Qualifier("kriSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
|
||||||
|
SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
|
||||||
|
return sqlSessionTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package app.module.admin.config.application.bean;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
import org.mybatis.spring.SqlSessionTemplate;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
@MapperScan(
|
||||||
|
basePackages = "app.module.mms",
|
||||||
|
annotationClass = org.apache.ibatis.annotations.Mapper.class,
|
||||||
|
sqlSessionFactoryRef = "mmsSqlSessionFactory")
|
||||||
|
@EnableTransactionManagement
|
||||||
|
public class MMSDBConfig {
|
||||||
|
|
||||||
|
@Value("${mybatis.mapper-locations.mms}")
|
||||||
|
private String mybatisMapper;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties(prefix = "spring.datasource.mms")
|
||||||
|
public DataSource mmsDataSource() {
|
||||||
|
return DataSourceBuilder.create().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "mmsSqlSessionFactory")
|
||||||
|
public SqlSessionFactory mmsSqlSessionFactory(@Qualifier("mmsDataSource") DataSource dataSource) throws Exception {
|
||||||
|
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
|
||||||
|
sessionFactoryBean.setVfs(SpringBootVFS.class);
|
||||||
|
configureSqlSessionFactory(sessionFactoryBean, dataSource);
|
||||||
|
return sessionFactoryBean.getObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void configureSqlSessionFactory(SqlSessionFactoryBean sessionFactoryBean, DataSource dataSource) throws IOException {
|
||||||
|
sessionFactoryBean.setDataSource(dataSource);
|
||||||
|
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||||
|
sessionFactoryBean.setMapperLocations(resolver.getResources(mybatisMapper));
|
||||||
|
|
||||||
|
// org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
|
||||||
|
// configuration.setMapUnderscoreToCamelCase(true);
|
||||||
|
// configuration.setJdbcTypeForNull(null);
|
||||||
|
// sessionFactoryBean.setConfiguration(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "mmsSqlSessionTemplate")
|
||||||
|
public SqlSessionTemplate mmsSqlSessionTemplate(@Qualifier("mmsSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
|
||||||
|
SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
|
||||||
|
return sqlSessionTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,8 +28,10 @@ public class AutoSchedulesController {
|
|||||||
public void fetchSmsAutoSend() {
|
public void fetchSmsAutoSend() {
|
||||||
portIn.sendAutoSms();
|
portIn.sendAutoSms();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 매일 오후 5시 마다 실행되는 스케줄러
|
||||||
* TODO 스케쥴 있다면.. 추가.
|
@Scheduled(cron = "5 * * * * ?")
|
||||||
*/
|
public void fetchSmsAutoSenTest() {
|
||||||
|
portIn.sendAutoSmsTest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ public interface AutoSchedulesPortIn {
|
|||||||
|
|
||||||
Optional<Boolean> operate();
|
Optional<Boolean> operate();
|
||||||
Optional<Boolean> sendAutoSms();
|
Optional<Boolean> sendAutoSms();
|
||||||
|
Optional<Boolean> sendAutoSmsTest();
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,9 @@ import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.GetIncomp
|
|||||||
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholds;
|
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholds;
|
||||||
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholdsCmd;
|
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholdsCmd;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
import app.module.mms.ports.MMSPortIn;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -27,6 +26,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
class AutoSchedulesService implements AutoSchedulesPortIn {
|
class AutoSchedulesService implements AutoSchedulesPortIn {
|
||||||
|
|
||||||
private final AutoSchedulesPortOut portOut;
|
private final AutoSchedulesPortOut portOut;
|
||||||
|
private final MMSPortIn mmsPortIn;
|
||||||
private final GetSmsAutoStatusPortIn getSmsAutoStatusPortIn;
|
private final GetSmsAutoStatusPortIn getSmsAutoStatusPortIn;
|
||||||
private final GetIncompleteHouseholdsPortIn getIncompleteHouseholdsPortIn;
|
private final GetIncompleteHouseholdsPortIn getIncompleteHouseholdsPortIn;
|
||||||
|
|
||||||
@@ -76,4 +76,29 @@ class AutoSchedulesService implements AutoSchedulesPortIn {
|
|||||||
|
|
||||||
return Optional.of(true);
|
return Optional.of(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Boolean> sendAutoSmsTest() {
|
||||||
|
String targetMonth = "202507";
|
||||||
|
DayRange dayRange = new DayRange(1, 7);
|
||||||
|
GetSmsAutoStatus getSmsAutoStatus = new GetSmsAutoStatus(true, "테스트", "01012345678", null, null);
|
||||||
|
|
||||||
|
// dayRange 날짜 범위의 일계부 미등록한 임가 목록 조회
|
||||||
|
List<GetIncompleteHouseholds> incompleteHouseholds = getIncompleteHouseholdsPortIn.operate(
|
||||||
|
new GetIncompleteHouseholdsCmd(targetMonth, dayRange.getFromDay(), dayRange.getToDay())
|
||||||
|
);
|
||||||
|
|
||||||
|
System.out.println(incompleteHouseholds);
|
||||||
|
|
||||||
|
// 미등록 임가가 있을 경우에만 실행
|
||||||
|
if(!CollectionUtils.isEmpty(incompleteHouseholds)) {
|
||||||
|
mmsPortIn.sendAutoSms(new app.module.mms.ports.application.domain.CreateSmsAutoSendCmd(
|
||||||
|
incompleteHouseholds,
|
||||||
|
getSmsAutoStatus.getSendPhone(),
|
||||||
|
getSmsAutoStatus.getMessage()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain;
|
package app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
|
@ToString
|
||||||
public class GetIncompleteHouseholds {
|
public class GetIncompleteHouseholds {
|
||||||
private Long seq;
|
private Long seq;
|
||||||
private String householdNum;
|
private String householdNum;
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package app.module.mms.adapters.persistence;
|
||||||
|
|
||||||
|
import app.module.mms.ports.application.domain.CreateSmsAutoSendCmd;
|
||||||
|
import app.module.mms.ports.MMSPortOut;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MMSDao implements MMSPortOut {
|
||||||
|
|
||||||
|
private final MMSMapper mapper;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Optional<Boolean> sendAutoSms(CreateSmsAutoSendCmd cmd) {
|
||||||
|
try {
|
||||||
|
log.debug("@@@ sendAutoSmsTest");
|
||||||
|
|
||||||
|
mapper.createSmsAutoSend(cmd);
|
||||||
|
|
||||||
|
return Optional.of(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info(e.getMessage());
|
||||||
|
|
||||||
|
// 예외 발생 시 false 반환
|
||||||
|
return Optional.of(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package app.module.mms.adapters.persistence;
|
||||||
|
|
||||||
|
import app.module.mms.ports.application.domain.CreateSmsAutoSendCmd;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface MMSMapper {
|
||||||
|
void createSmsAutoSend(CreateSmsAutoSendCmd cmd);
|
||||||
|
}
|
||||||
10
admin/src/main/java/app/module/mms/ports/MMSPortIn.java
Normal file
10
admin/src/main/java/app/module/mms/ports/MMSPortIn.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package app.module.mms.ports;
|
||||||
|
|
||||||
|
import app.module.mms.ports.application.domain.CreateSmsAutoSendCmd;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface MMSPortIn {
|
||||||
|
|
||||||
|
Optional<Boolean> sendAutoSms(CreateSmsAutoSendCmd cmd);
|
||||||
|
}
|
||||||
10
admin/src/main/java/app/module/mms/ports/MMSPortOut.java
Normal file
10
admin/src/main/java/app/module/mms/ports/MMSPortOut.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package app.module.mms.ports;
|
||||||
|
|
||||||
|
import app.module.mms.ports.application.domain.CreateSmsAutoSendCmd;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface MMSPortOut {
|
||||||
|
|
||||||
|
Optional<Boolean> sendAutoSms(CreateSmsAutoSendCmd cmd);
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package app.module.mms.ports.application;
|
||||||
|
|
||||||
|
import app.module.mms.ports.application.domain.CreateSmsAutoSendCmd;
|
||||||
|
import app.module.mms.ports.MMSPortIn;
|
||||||
|
import app.module.mms.ports.MMSPortOut;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
class MMSService implements MMSPortIn {
|
||||||
|
|
||||||
|
private final MMSPortOut portOut;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Optional<Boolean> sendAutoSms(CreateSmsAutoSendCmd command) {
|
||||||
|
portOut.sendAutoSms(command);
|
||||||
|
|
||||||
|
return Optional.of(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package app.module.mms.ports.application.domain;
|
||||||
|
|
||||||
|
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholds;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class CreateSmsAutoSendCmd {
|
||||||
|
private List<GetIncompleteHouseholds> sendHouseholds;
|
||||||
|
private String sendPhone;
|
||||||
|
private String message;
|
||||||
|
}
|
||||||
@@ -23,4 +23,25 @@ spring:
|
|||||||
cache-duration: 10s
|
cache-duration: 10s
|
||||||
thymeleaf:
|
thymeleaf:
|
||||||
# 타임리프 템플릿 캐시 비활성화 (개발 환경에서는 false 로 설정 권장)
|
# 타임리프 템플릿 캐시 비활성화 (개발 환경에서는 false 로 설정 권장)
|
||||||
cache: false
|
cache: false
|
||||||
|
|
||||||
|
datasource:
|
||||||
|
kri:
|
||||||
|
driver-class-name: org.postgresql.Driver
|
||||||
|
jdbc-url: jdbc:postgresql://15.165.180.203:5432/korea_research
|
||||||
|
username: ko_research
|
||||||
|
password: koresearch1@#4
|
||||||
|
mms:
|
||||||
|
driver-class-name: org.postgresql.Driver
|
||||||
|
jdbc-url: jdbc:postgresql://15.165.180.203:5432/ko_research_hyunjoo
|
||||||
|
username: hyunjoo
|
||||||
|
password: hyunjoo1@#4
|
||||||
|
maximum-pool-size: 2
|
||||||
|
minimum-idle: 1
|
||||||
|
hikari:
|
||||||
|
maximum-pool-size: 10
|
||||||
|
minimum-idle: 5
|
||||||
|
idle-timeout: 120000
|
||||||
|
max-lifetime: 900000
|
||||||
|
connection-timeout: 5000
|
||||||
|
leak-detection-threshold: 30000
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ logging:
|
|||||||
# MyBatis 설정
|
# MyBatis 설정
|
||||||
# ==============================================
|
# ==============================================
|
||||||
mybatis:
|
mybatis:
|
||||||
mapper-locations: classpath*:mappers/**/*Mapper.xml # 매퍼 파일 위치
|
mapper-locations:
|
||||||
|
kri: classpath*:mappers/**/*Mapper.xml # 매퍼 파일 위치
|
||||||
|
mms: classpath*:mappers/mms/*Mapper.xml # 매퍼 파일 위치
|
||||||
configuration:
|
configuration:
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # SQL 로깅 구현체
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # SQL 로깅 구현체
|
||||||
|
|||||||
32
admin/src/main/resources/mappers/mms/MMSMapper.xml
Normal file
32
admin/src/main/resources/mappers/mms/MMSMapper.xml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?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="app.module.mms.adapters.persistence.MMSMapper">
|
||||||
|
|
||||||
|
<insert id="createSmsAutoSend">
|
||||||
|
/* createSmsAutoSend : 문자 발송 insert */
|
||||||
|
INSERT INTO biz_msg
|
||||||
|
(
|
||||||
|
MSG_TYPE,
|
||||||
|
CMID,
|
||||||
|
REQUEST_TIME,
|
||||||
|
SEND_TIME,
|
||||||
|
DEST_PHONE,
|
||||||
|
SEND_PHONE,
|
||||||
|
MSG_BODY
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
<foreach collection="sendHouseholds" item="item" separator=",">
|
||||||
|
(
|
||||||
|
5,
|
||||||
|
TO_CHAR(NOW(), 'YYYYMMDDHH24MISS') || '_' || #{item.householdNum},
|
||||||
|
NOW(),
|
||||||
|
NOW(),
|
||||||
|
#{item.phone},
|
||||||
|
#{sendPhone},
|
||||||
|
#{message}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user