OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-03-02 20d2fc7868921587e7a0aafd0dc00690507bb6e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package kr.wisestone.owl.service.impl;
 
import kr.wisestone.owl.constant.MsgConstants;
import kr.wisestone.owl.domain.PaymentHistory;
import kr.wisestone.owl.domain.Workspace;
import kr.wisestone.owl.exception.OwlRuntimeException;
import kr.wisestone.owl.repository.PaymentHistoryRepository;
import kr.wisestone.owl.service.PaymentHistoryService;
import kr.wisestone.owl.web.form.PaymentForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
public class PaymentHistoryServiceImpl extends AbstractServiceImpl<PaymentHistory, Long, JpaRepository<PaymentHistory, Long>> implements PaymentHistoryService {
 
    private static final Logger log = LoggerFactory.getLogger(PaymentHistoryServiceImpl.class);
 
    @Autowired
    private PaymentHistoryRepository paymentHistoryRepository;
 
    @Override
    protected JpaRepository<PaymentHistory, Long> getRepository() {
        return this.paymentHistoryRepository;
    }
 
    @Override
    @Transactional
    public PaymentHistory addPaymentHistory(PaymentServiceImpl.RestClientResultObject resultObject, PaymentForm paymentForm, Workspace workspace) {
        PaymentHistory paymentHistory = new PaymentHistory();
        paymentHistory.bindPaymentResult(resultObject);
        paymentHistory.setPrice(paymentForm.getPaymentAmount());
        paymentHistory.setBuyUser(paymentForm.getBuyUser());
        paymentHistory.setType(paymentForm.getType());
        paymentHistory.setCustomerUid(paymentForm.getCustomerUid());
        paymentHistory.setMerchantUid(paymentForm.getMerchantUid());
        paymentHistory.setWorkspace(workspace);
 
        return this.paymentHistoryRepository.saveAndFlush(paymentHistory);
    }
 
    //  결제 시 오류가 발생했을 때 취소 정보를 저장한다.
    @Override
    @Transactional
    public PaymentHistory cancelPaymentHistory(PaymentForm paymentForm, Workspace workspace, String reason) {
        PaymentHistory paymentHistory = new PaymentHistory();
        paymentHistory.setPrice(paymentForm.getPaymentAmount());
        paymentHistory.setBuyUser(paymentForm.getBuyUser());
        paymentHistory.setType(paymentForm.getType());
        paymentHistory.setCustomerUid(paymentForm.getCustomerUid());
        paymentHistory.setMerchantUid(paymentForm.getMerchantUid());
        paymentHistory.setWorkspace(workspace);
        paymentHistory.setPaymentResult(PaymentHistory.PAYMENT_RESULT_FAILED);
        paymentHistory.setPaymentResponse(reason);
 
        return this.paymentHistoryRepository.saveAndFlush(paymentHistory);
    }
 
    //  해당 업무 공간에서 마지막으로 결제한 정보를 가져온다.
    @Override
    @Transactional(readOnly = true)
    public PaymentHistory findByWorkspaceLastPaymentHistory(Workspace workspace) {
        List<PaymentHistory> paymentHistoryList = this.paymentHistoryRepository.findByWorkspaceId(workspace.getId());
 
        if (paymentHistoryList.size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.PAYMENT_NOT_EXIST));
        }
 
        return paymentHistoryList.get(paymentHistoryList.size() - 1);
    }
 
}