package com.yd.csf.api.async;

import com.yd.common.result.Result;
import com.yd.csf.api.service.ApiExpectedFortuneService;
import com.yd.csf.feign.request.expectedfortune.ApiGenerateExpectedFortuneRequest;
import com.yd.csf.feign.response.expectedfortune.ApiGenerateExpectedFortuneResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Slf4j
@Component
public class ApiExpectedFortuneAsyncService {

    @Resource
    private ApiExpectedFortuneService apiExpectedFortuneService;

    /**
     * 异步处理
     *
     * @return
     */
    @Async("commonAsyncExecutor")
    public Result execute(String policyNo) {
        // 调用 ApiExpectedFortuneService 的 generateSyncWithLogAndRedis（同步版本，包含日志和Redis处理）
        ApiGenerateExpectedFortuneRequest generateExpectedFortuneRequest = new ApiGenerateExpectedFortuneRequest();
        generateExpectedFortuneRequest.setPolicyNo(policyNo);
        log.info("生成预计发佣generateSyncWithLogAndRedis——>PolicyNo：{}", policyNo);
        Result<ApiGenerateExpectedFortuneResponse> result = apiExpectedFortuneService.generateSyncWithLogAndRedis(generateExpectedFortuneRequest);
        if (result != null && result.getCode() == 200) {
            log.info("新单跟进-同步生成预计出账记录成功:保单号={}", policyNo);
        }
        return Result.success();
    }

}
