package com.kxs.daemon.quartz.task;

import com.kxs.common.core.constant.SecurityConstants;
import com.kxs.daemon.quartz.constants.SkyQuartzEnum;
import com.kxs.user.api.feign.RemoteKxsUserService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 用户模块 Bean 任务
 *
 * @author 没秃顶的码农
 * @date 2024-03-21
 */
@Slf4j
@Component("userjob")
@RequiredArgsConstructor
public class UserBeanTask {


    private final RemoteKxsUserService remoteKxsUserService;

    /**
     *  自动表创建收支明细表任务
     */
    @SneakyThrows
    public String automaticTableCreationTasks() {
        try {
            log.info("自动表创建任务:{}", LocalDateTime.now());
            remoteKxsUserService.automaticTableCreationTasks(SecurityConstants.FROM_IN);
            return SkyQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();

        }catch (Exception e){
            log.error(e.getLocalizedMessage());
        }
        return SkyQuartzEnum.JOB_LOG_STATUS_FAIL.getType();
    }

    /**
     *  用户欠款扣除定时任务
     * 1.扫创客合伙人可提现额度，若有合伙人可提现额度，则扣除可提现额度，最大扣除金额=欠款总金额，扣除后减少欠款总金额，同时在前端增加扣除记录，备注为「预借款项还款」
     * 2.扫创客盟主可提现余额，若有盟主可提现余额，则扣除可提现余额，最大扣除金额=欠款总金额，扣除后减少欠款总金额，同时在前端增加扣除记录，备注为「预借款项还款」
     */
    @SneakyThrows
    public String userTotalDebtSub(String para) {
        remoteKxsUserService.userTotalDebtSub(SecurityConstants.FROM_IN);
        log.info("用户欠款扣除定时任务:{}，输入参数{}", LocalDateTime.now(), para);
        return SkyQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
    }
}
