package com.friday.custody.quartz;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.friday.custody.api.dto.gjdf.GjdfAppSecretDto;
import com.friday.custody.service.basicService.TenantEscrowAuthorizationInfoService;
import com.friday.custody.service.trustService.guojindaofu.service.GuoJinDaoFuService;
import com.friday.custody.dto.TenantEscrowAuthorizationInfoDto;
import com.friday.custody.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@DisallowConcurrentExecution
@Component
public class UpdateGJDFJob extends QuartzJobBean {
    @Value("${custody.quartz.updateGJDFByScheduled.switch}")
    private Boolean updateGJDFByScheduledSwitch;
    @Autowired
    private TenantEscrowAuthorizationInfoService authorizationInfoService;
    @Autowired
    private GuoJinDaoFuService guoJinDaoFuService;
    @Override
    protected void executeInternal(JobExecutionContext context)  {
        //获取国金道富管理人
        ObjectMapper objectMapper = new ObjectMapper();
        R<List<TenantEscrowAuthorizationInfoDto>> list = authorizationInfoService.queryAuthorizations();
        List<TenantEscrowAuthorizationInfoDto> data = list.getData();
        List<TenantEscrowAuthorizationInfoDto> result = data.stream().filter(t -> t.getTrustNo().equals("98") && t.getVersion().equals("api") ).collect(Collectors.toList());
        for (TenantEscrowAuthorizationInfoDto dto : result) {
            guoJinDaoFuService.updatesEveryDay(dto, null);
        }
    }
}
