保誠-保戶業務員媒合平台
[update] 移除login_record欄位,改統一放之後 將新開的稽核欄位"audit_logging",並在顧問欄位加開最後上線時間

刪除3個檔案
修改5個檔案
新增1個檔案
244 ■■■■ 已變更過的檔案
pamapi/src/doc/sql/20220221_w.sql 21 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/domain/Consultant.java 11 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/domain/LoginRecord.java 96 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/repository/LoginRecordRepository.java 13 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java 18 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java 10 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/LoginRecordService.java 66 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/OtpUtilService.java 5 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java 4 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/sql/20220221_w.sql
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,21 @@
CREATE TABLE public.audit_logging (
      id bigserial NOT NULL,
      functional_type varchar NULL,
      "content" varchar NULL,
      created_by varchar NULL,
      created_date timestamp NULL,
      CONSTRAINT audit_logging_pk PRIMARY KEY (id)
);
ALTER TABLE public.consultant ADD latest_login_time timestamp NULL;
update consultant set latest_login_time = (select login_date from login_record where account = 'A183619275' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'A183619275';
update consultant set latest_login_time = (select login_date from login_record where account = 'AGAM11249699' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'AGAM11249699';
update consultant set latest_login_time = (select login_date from login_record where account = 'Z152717443' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'Z152717443';
update consultant set latest_login_time = (select login_date from login_record where account = 'D265260662' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'D265260662';
update consultant set latest_login_time = (select login_date from login_record where account = 'AG0109051204' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'AG0109051204';
update consultant set latest_login_time = (select login_date from login_record where account = 'B282677963' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'B282677963';
update consultant set latest_login_time = (select login_date from login_record where account = 'AG0101234567' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'AG0101234567';
update consultant set latest_login_time = (select login_date from login_record where account = 'X147309614' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'X147309614';
update consultant set latest_login_time = (select login_date from login_record where account = 'J149388015' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'J149388015';
update consultant set latest_login_time = (select login_date from login_record where account = 'R221444250' and login_method = 'E_SERVICE' and result = 'SUCCESS' order by login_date desc limit 1) where agent_no = 'R221444250';
pamapi/src/main/java/com/pollex/pam/domain/Consultant.java
@@ -5,6 +5,7 @@
import javax.persistence.*;
import java.io.Serializable;
import java.time.Instant;
@Entity
@Table(name = "consultant")
@@ -79,6 +80,8 @@
    @Column(name = "status")
    private ConsultantStatusEnum status;
    @Column(name = "latest_login_time")
    private Instant latestLoginTime;
    public Long getId() {
        return id;
@@ -255,6 +258,14 @@
        this.status = status;
    }
    public Instant getLatestLoginTime() {
        return latestLoginTime;
    }
    public void setLatestLoginTime(Instant latestLoginTime) {
        this.latestLoginTime = latestLoginTime;
    }
    @Override
    public String toString() {
        return "Consultant{" +
pamapi/src/main/java/com/pollex/pam/domain/LoginRecord.java
Àɮפw§R°£
pamapi/src/main/java/com/pollex/pam/repository/LoginRecordRepository.java
Àɮפw§R°£
pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java
@@ -4,10 +4,8 @@
import com.pollex.pam.config.ApplicationProperties;
import com.pollex.pam.domain.Consultant;
import com.pollex.pam.enums.ConsultantDetailEnum;
import com.pollex.pam.enums.ConsultantStatusEnum;
import com.pollex.pam.repository.ConsultantRepository;
import com.pollex.pam.security.token.EServiceAuthenticationToken;
import com.pollex.pam.service.LoginRecordService;
import com.pollex.pam.service.dto.EServiceResponse;
import com.pollex.pam.web.rest.errors.ConsultantDisableException;
import com.pollex.pam.web.rest.errors.EServiceErrorException;
@@ -39,6 +37,7 @@
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.time.Instant;
import java.util.*;
import static com.pollex.pam.enums.ConsultantStatusEnum.DISABLE;
@@ -55,16 +54,12 @@
    @Autowired
    ConsultantRepository consultantRepository;
    @Autowired
    LoginRecordService loginRecordService;
    public Authentication authenticate(EServiceAuthenticationToken authenticationToken) throws AuthenticationException {
        String account = authenticationToken.getPrincipal();
        String credentials = authenticationToken.getCredentials();
        if(applicationProperty.isMockLogin()){
            loginRecordService.saveEServiceLoginSuccessRecord(account);
            return getConsultantToken(account, credentials);
            return getConsultantTokenAndRecordLoginTime(account, credentials);
        }
        try {
@@ -74,11 +69,9 @@
                log.debug("eService response = {}", eServiceResponse);
                if(E_SERVICE_LOGIN_SUCCESS_CODE.equals(eServiceResponse.getIssuccess())){
                    loginRecordService.saveEServiceLoginSuccessRecord(account);
                    return getConsultantToken(account, credentials);
                    return getConsultantTokenAndRecordLoginTime(account, credentials);
                }
                else {
                    loginRecordService.saveEServiceLoginFailRecord(account, eServiceResponse.getMsg());
                    throw new EServiceErrorException(eServiceResponse.getMsg());
                }
            }
@@ -91,13 +84,16 @@
        }
    }
    private UsernamePasswordAuthenticationToken getConsultantToken(String account, String credential) throws ConsultantDisableException {
    private UsernamePasswordAuthenticationToken getConsultantTokenAndRecordLoginTime(String account, String credential) throws ConsultantDisableException {
        Consultant consultant = consultantRepository.findOneByAgentNo(account).orElseThrow(() -> new UsernameNotFoundException("該顧問資料並不存在於媒合平台系統中"));
        if(consultant.getStatus() == DISABLE) {
            throw new ConsultantDisableException("顧問帳號目前停用中");
        }
        consultant.setLatestLoginTime(Instant.now());
        consultantRepository.save(consultant);
        List<GrantedAuthority> grantedAuths = Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(account, credential, grantedAuths);
pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
@@ -61,9 +61,6 @@
    AppointmentService appointmentService;
    @Autowired
    LoginRecordService loginRecordService;
    @Autowired
    AppointmentCustomerViewMapper appointmentCustomerViewMapper;
    @Autowired
@@ -225,12 +222,7 @@
    public ConsultantDetailDTO getConsultantDetail(String agentNo) {
        Consultant consultant = consultantRepository.findOneByAgentNo(agentNo).orElseThrow(ConsultantNotFoundException::new);
        ConsultantDetailDTO consultantDetailDTO = consultantMapper.toDetailDto(consultant);
        loginRecordService.findLatestLoginRecord(agentNo, LoginResult.SUCCESS)
                .ifPresent(loginRecord -> consultantDetailDTO.setLatestLoginTime(loginRecord.getLoginDate()));
        return consultantDetailDTO;
        return consultantMapper.toDetailDto(consultant);
    }
    @Transactional
pamapi/src/main/java/com/pollex/pam/service/LoginRecordService.java
Àɮפw§R°£
pamapi/src/main/java/com/pollex/pam/service/OtpUtilService.java
@@ -28,9 +28,6 @@
    @Autowired
    OtpTmpService otpTmpService;
    @Autowired
    LoginRecordService loginRecordService;
    @Transactional
    public void verifyOtp(VerifyOtpVM verifyOtpParam) {
        verifyOtp(verifyOtpParam.getAccount(), verifyOtpParam.getIndexKey(), verifyOtpParam.getOtpCode());
@@ -47,11 +44,9 @@
            }
            else {
                log.info("otp login fail... , account = {}, error code = {}, failReason = {}", account, otpResponseDTO.getFailCode(), otpResponseDTO.getFailReason());
                loginRecordService.saveOTPLoginFailRecord(account, otpResponseDTO.getFailReason());
                throw new OtpLoginFailException(otpResponseDTO.getFailCode());
            }
        }
        loginRecordService.saveOTPLoginSuccessRecord(account);
        setVerrifiedOtpTmp(account, indexKey);
    }
pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java
@@ -2,7 +2,6 @@
import com.pollex.pam.config.ApplicationProperties;
import com.pollex.pam.security.jwt.TokenProvider;
import com.pollex.pam.service.LoginRecordService;
import com.pollex.pam.service.OtpWebService;
import com.pollex.pam.service.dto.EServiceResponse;
import com.pollex.pam.service.dto.OtpResponseDTO;
@@ -41,9 +40,6 @@
public class TestLoginResource {
    private final static Logger log = LoggerFactory.getLogger(TestLoginResource.class);
    @Autowired
    LoginRecordService loginRecordService;
    @Autowired
    ApplicationProperties applicationProperty;