保誠-保戶業務員媒合平台
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
package com.pollex.pam.aop.logging.audit.strategy;
 
import com.google.gson.Gson;
import com.pollex.pam.aop.logging.audit.AuditLoggingType;
import com.pollex.pam.domain.AuditLogging;
import com.pollex.pam.repository.AppointmentRepository;
import com.pollex.pam.repository.AuditLoggingRepository;
import com.pollex.pam.security.SecurityUtils;
import com.pollex.pam.service.dto.AppointmentDTO;
import com.pollex.pam.service.mapper.AppointmentMapper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import static com.pollex.pam.aop.logging.audit.AuditLoggingType.CHECK_APPOINTMENT;
 
@Component
@Transactional
public class LoggingCheckAppointmentStrategy implements AuditLoggingStrategy{
 
    @Autowired
    AuditLoggingRepository auditLoggingRepository;
 
    @Autowired
    AppointmentRepository appointmentRepository;
 
    @Autowired
    AppointmentMapper appointmentMapper;
 
    @Override
    public AuditLoggingType getType() {
        return CHECK_APPOINTMENT;
    }
 
    @Override
    public void auditLogging(ProceedingJoinPoint joinPoint) {
        Long appointmentId = (Long) joinPoint.getArgs()[0];
 
        appointmentRepository.findById(appointmentId).ifPresent(appointment -> {
            AppointmentDTO dto = appointmentMapper.toAppointmentDTO(appointment);
 
            AuditLogging auditLogging = new AuditLogging();
            auditLogging.setContent(new Gson().toJson(dto));
            auditLogging.setFunctionalType(getType());
            auditLogging.setCreatedBy(SecurityUtils.getCurrentUserLogin().orElse(null));
 
            auditLoggingRepository.save(auditLogging);
        });
    }
}