@ -1,5 +1,16 @@
package cokr.xit.ens.modules.common.ctgy.intgrnnoti.service ;
import java.time.LocalDateTime ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.List ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Propagation ;
import org.springframework.transaction.annotation.Transactional ;
import cokr.xit.ens.core.aop.EnsResponseVO ;
import cokr.xit.ens.core.exception.EnsException ;
import cokr.xit.ens.core.exception.code.EnsErrCd ;
@ -9,18 +20,16 @@ import cokr.xit.ens.modules.common.ctgy.intgrnnoti.domain.IntgrnSendMast;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.domain.repository.IntgrnSendDetailRepository ;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.domain.repository.IntgrnSendMastRepository ;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.model.IntgrnNotiAcceptReqDTO ;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.support.* ;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.support.IntgrnNotiAcceptor ;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.support.IntgrnNotiMaker ;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.support.IntgrnNotiRsltFetcher ;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.support.IntgrnNotiRsltProvider ;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.support.IntgrnNotiSender ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Propagation ;
import org.springframework.transaction.annotation.Transactional ;
import java.time.LocalDateTime ;
import java.util.Arrays ;
import java.util.List ;
import java.util.stream.Collectors ;
import lombok.val ;
// TODO: 전자고지 서비스
@Slf4j
@Service
@RequiredArgsConstructor
@ -44,8 +53,8 @@ public class IntgrnNotiService {
* @return
* /
@Transactional ( propagation = Propagation . SUPPORTS )
public EnsResponseVO accept( IntgrnNotiAcceptReqDTO reqDTO ) {
EnsResponseVO responseVO = null ;
public EnsResponseVO < ? > accept( IntgrnNotiAcceptReqDTO reqDTO ) {
EnsResponseVO < ? > responseVO = null ;
try {
responseVO = intgrnSendAcceptor . statBegin ( reqDTO ) ;
if ( ! EnsErrCd . OK . equals ( responseVO . getErrCode ( ) ) )
@ -70,7 +79,7 @@ public class IntgrnNotiService {
* @return
* /
@Transactional ( propagation = Propagation . SUPPORTS )
public EnsResponseVO remake( Long intSendMastId ) {
public EnsResponseVO < ? > remake( Long intSendMastId ) {
try {
IntgrnSendMast sendMast = intgrnSendMastRepository . findById ( intSendMastId )
. orElseThrow ( ( ) - > new EnsException ( EnsErrCd . MAKE404 , "일치하는 자료가 없습니다." ) ) ;
@ -84,7 +93,7 @@ public class IntgrnNotiService {
. build ( ) ;
}
intgrnNotiMaker . statReady ( Arrays. as List( intSendMastId ) ) ;
intgrnNotiMaker . statReady ( Collections. singleton List( intSendMastId ) ) ;
return this . make ( intSendMastId ) ;
@ -96,12 +105,12 @@ public class IntgrnNotiService {
* @return
* /
@Transactional ( propagation = Propagation . SUPPORTS )
public EnsResponseVO makeAll( ) {
public EnsResponseVO < ? > makeAll( ) {
List < Long > sendMastIds = intgrnSendMastRepository . findAllByStatCdIn ( Arrays . asList ( StatCd . accept ) )
. stream ( )
. map ( row - > row . getIntSendMastId ( ) )
. collect ( Collectors . toList ( ) ) ;
if ( sendMastIds . size( ) < 1 )
if ( sendMastIds . isEmpty( ) )
return EnsResponseVO . errBuilder ( )
. errCode ( EnsErrCd . MAKE404 )
. errMsg ( "\"접수(accept)\" 상태인 자료가 없습니다" )
@ -109,15 +118,15 @@ public class IntgrnNotiService {
intgrnNotiMaker . statReady ( sendMastIds ) ;
List< EnsResponseVO > resultInfo = sendMastIds . stream ( )
. map ( intSendMastId - > this . make ( intSendMastId ) )
. collect ( Collectors . toList ( ) ) ;
val resultInfo = sendMastIds . stream ( )
. map ( this : : make )
. collect ( Collectors . toList ( ) ) ;
return EnsResponseVO . okBuilder ( ) . resultInfo ( resultInfo ) . build ( ) ;
}
private EnsResponseVO make( Long intSendMastId ) {
EnsResponseVO responseVO = intgrnNotiMaker . statBegin ( intSendMastId ) ;
private EnsResponseVO < ? > make( Long intSendMastId ) {
EnsResponseVO < ? > responseVO = intgrnNotiMaker . statBegin ( intSendMastId ) ;
if ( ! EnsErrCd . OK . equals ( responseVO . getErrCode ( ) ) )
return responseVO ;
@ -159,10 +168,10 @@ public class IntgrnNotiService {
* @return
* /
@Transactional ( propagation = Propagation . SUPPORTS )
public EnsResponseVO sendBulk( Long intSendMastId ) {
public EnsResponseVO < ? > sendBulk( Long intSendMastId ) {
try {
if ( intgrnSendDetailRepository . findAllBySendTargetAndSendMast ( IntgrnSendMast . builder ( ) . intSendMastId ( intSendMastId ) . build ( ) ) . size( ) < 1 )
if ( intgrnSendDetailRepository . findAllBySendTargetAndSendMast ( IntgrnSendMast . builder ( ) . intSendMastId ( intSendMastId ) . build ( ) ) . isEmpty( ) )
throw new EnsException ( EnsErrCd . SEND404 , "일치하는 자료가 없거나 전송 가능한 상태의 자료가 없습니다. (1회차:상태=makeok&try상태=stby&dtl상태=MAKING, 2~3회차:try상태:ok/fail&발송일시=기한경과&dtl상태=실패(ACPT_FAIL/FAIL/...)" ) ;
} catch ( EnsException e ) {
return EnsResponseVO . errBuilder ( )
@ -171,7 +180,7 @@ public class IntgrnNotiService {
. build ( ) ;
}
List < Long > sendMastIds = Arrays. as List( intSendMastId ) ;
List < Long > sendMastIds = Collections. singleton List( intSendMastId ) ;
return this . send ( sendMastIds ) ;
@ -181,10 +190,10 @@ public class IntgrnNotiService {
* ( 대 량 ) 전 송 서 비 스 - 일 괄
* /
@Transactional ( propagation = Propagation . SUPPORTS )
public EnsResponseVO sendBulkAll( ) {
public EnsResponseVO < ? > sendBulkAll( ) {
List < Long > intSendMastIds = intgrnSendDetailRepository . findIntSendMastIdsBySendTarget ( ) ;
if ( intSendMastIds . size( ) < 1 )
if ( intSendMastIds . isEmpty( ) )
return EnsResponseVO . errBuilder ( )
. errCode ( EnsErrCd . SEND404 )
. errMsg ( "전송 타깃 데이터가 없습니다." )
@ -193,14 +202,11 @@ public class IntgrnNotiService {
return this . send ( intSendMastIds ) ;
}
private EnsResponseVO send ( List < Long > intSendMastIds ) {
List < EnsResponseVO > resultInfo = intSendMastIds . stream ( )
. map ( intSendMastId - > {
intgrnNotiSender . statBegin ( intSendMastId ) ;
return intSendMastId ;
} )
. map ( intSendMastId - > intgrnNotiSender . execute ( intSendMastId ) )
. collect ( Collectors . toList ( ) ) ;
private EnsResponseVO < ? > send ( List < Long > intSendMastIds ) {
val resultInfo = intSendMastIds . stream ( )
. peek ( intgrnNotiSender : : statBegin )
. map ( intgrnNotiSender : : execute )
. collect ( Collectors . toList ( ) ) ;
return EnsResponseVO . okBuilder ( ) . resultInfo ( resultInfo ) . build ( ) ;
@ -211,18 +217,18 @@ public class IntgrnNotiService {
* 전 송 ( 성 공 / 실 패 ) 결 과 가 져 오 기
* /
@Transactional ( propagation = Propagation . SUPPORTS )
public EnsResponseVO statBulk( Long intSendMastId ) {
public EnsResponseVO < ? > statBulk( Long intSendMastId ) {
IntgrnSendMast intgrnSendMast = null ;
try {
intgrnSendMast = intgrnSendMastRepository . findById ( intSendMastId )
. orElseThrow ( ( ) - > new EnsException ( EnsErrCd . ERR404 , String . format ( "[ intSendMastId %s ]와 일치하는 자료가 없습니다." , intSendMastId ) ) ) ;
int validCnt = 0 ;
IntgrnSendMast finalIntgrnSendMast = intgrnSendMast ;
if ( ! Arrays . asList ( StatCd . sendok , StatCd . sendcmplt , StatCd . open ) . stream ( )
. any Match( statCd - > statCd . equals ( finalIntgrnSendMast . getStatCd ( ) ) ) )
if ( Stream . of ( StatCd . sendok , StatCd . sendcmplt , StatCd . open )
. none Match( statCd - > statCd . equals ( finalIntgrnSendMast . getStatCd ( ) ) ) )
validCnt + + ;
if ( ! Arrays . asList ( TryStatCd . sndRsrv , TryStatCd . sndRtme ) . stream ( )
. any Match( statCd - > statCd . equals ( finalIntgrnSendMast . getTryStatCd ( ) ) ) )
if ( Stream . of ( TryStatCd . sndRsrv , TryStatCd . sndRtme )
. none Match( statCd - > statCd . equals ( finalIntgrnSendMast . getTryStatCd ( ) ) ) )
validCnt + + ;
if ( validCnt = = 2 )
throw new EnsException ( EnsErrCd . RSLT404 , "\"진행상태\"가 전송성공/전송완료/열람중(sendok/sendcmplt/open) 또는 \"현재 회차상태\"가 예약전송/실시간전송(sndRsrv/sndRtme) 상태가 아닙니다." ) ;
@ -233,17 +239,17 @@ public class IntgrnNotiService {
. build ( ) ;
}
return this . stat ( Arrays. as List( intgrnSendMast ) ) ;
return this . stat ( Collections. singleton List( intgrnSendMast ) ) ;
}
/ * *
* 전 송 ( 성 공 / 실 패 ) 결 과 모 두 가 져 오 기
* /
@Transactional ( propagation = Propagation . SUPPORTS )
public EnsResponseVO statBulkAll( ) {
public EnsResponseVO < ? > statBulkAll( ) {
// List<IntgrnSendMast> intgrnSendMasts = intgrnSendMastRepository.findAllByStatCdIn(Arrays.asList(StatCd.sendok, StatCd.sendcmplt, StatCd.open));
List < IntgrnSendMast > intgrnSendMasts = intgrnSendMastRepository . findAllByStatCdInOrTryStatCdIn ( Arrays . asList ( StatCd . sendok , StatCd . sendcmplt , StatCd . open ) , Arrays . asList ( TryStatCd . sndRsrv , TryStatCd . sndRtme ) ) ;
if ( intgrnSendMasts . size( ) < 1 )
if ( intgrnSendMasts . isEmpty( ) )
return EnsResponseVO . errBuilder ( )
. errCode ( EnsErrCd . RSLT404 )
// .errMsg("\"전송성공/전송완료/열람중(sendok/sendcmplt/open)\" 상태인 자료가 없습니다")
@ -253,10 +259,10 @@ public class IntgrnNotiService {
return this . stat ( intgrnSendMasts ) ;
}
private EnsResponseVO stat( List < IntgrnSendMast > intgrnSendMasts ) {
List< EnsResponseVO > resultInfo = intgrnSendMasts . stream ( )
. map ( data - > intgrnNotiRsltFetcher . execute ( data . getIntSendMastId ( ) ) )
. collect ( Collectors . toList ( ) ) ;
private EnsResponseVO < ? > stat( List < IntgrnSendMast > intgrnSendMasts ) {
val resultInfo = intgrnSendMasts . stream ( )
. map ( data - > intgrnNotiRsltFetcher . execute ( data . getIntSendMastId ( ) ) )
. collect ( Collectors . toList ( ) ) ;
return EnsResponseVO . okBuilder ( ) . resultInfo ( resultInfo ) . build ( ) ;
}
@ -268,7 +274,7 @@ public class IntgrnNotiService {
* @return
* /
@Transactional ( propagation = Propagation . SUPPORTS )
public EnsResponseVO sendResultProvide( Long intSendMastId ) {
public EnsResponseVO < ? > sendResultProvide( Long intSendMastId ) {
return intgrnNotiRsltProvider . execute ( intSendMastId ) ;
}