package com.hzs.member.account.provider;

import com.hzs.common.core.domain.R;
import com.hzs.member.account.IMemberJobServiceApi;
import com.hzs.member.account.service.ICuMemberAccountDetailService;
import com.hzs.member.account.service.ICuMemberWithdrawService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 会员模块定时任务服务提供
 */
@Slf4j
@DubboService
public class IMemberJobServiceProvider implements IMemberJobServiceApi {

    @Autowired
    private ICuMemberAccountDetailService iCuMemberAccountDetailService;
    @Autowired
    private ICuMemberWithdrawService iCuMemberWithdrawService;

    @Override
    public R<?> insertAccountDetail() {
        try {
            iCuMemberAccountDetailService.insertAccountDetail();
        } catch (Exception e) {
            log.info("定时插入账户详情数据失败：", e);
            return R.fail(e.getMessage());
        }
        return R.ok();
    }

    @Override
    public R<?> deleteAccountDetailByMonth() {
        try {
            iCuMemberAccountDetailService.deleteAccountDetailByMonth();
        } catch (Exception e) {
            log.info("定时删除账户详情数据失败：", e);
            return R.fail(e.getMessage());
        }
        return R.ok();
    }

    @Override
    public R<?> automaticWithdrawal() {
        try {
            iCuMemberWithdrawService.autoWithdraw();
        } catch (Exception e) {
            log.info("自动提现报错：", e);
            return R.fail(e.getMessage());
        }
        return R.ok();
    }

}
