package com.hzs.member.account.provider;

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

import java.util.Date;

/**
 * 会员模块定时任务服务提供
 *
 * @Description:
 * @Author: ljc
 * @Time: 2023/4/12 10:40
 * @Classname: IMemberJobServiceProvider
 * @Package_name: com.hzs.member.account.provider
 */

@Slf4j
@DubboService
public class IMemberJobServiceProvider implements IMemberJobServiceApi {

    @Autowired
    private ICuMemberAccountDetailService memberAccountDetailService;

    @Autowired
    private ICuMemberWithdrawService memberWithdrawService;

    @Autowired
    private ICuMemberRechargeService memberRechargeService;

    @Autowired
    private DeleteGarbageDataMapper deleteGarbageDataMapper;


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


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


    @Override
    public R<CuMemberRecharge> selectRechargeTotalAmount(Date startDate, Date endDate) {
       return R.ok(memberRechargeService.selectRechargeTotalAmount(startDate, endDate));
    }

    @Override
    public R autoDeleteGarbageData() {
        deleteGarbageDataMapper.deleteMemberAwards(30);
        deleteGarbageDataMapper.deleteMemberLevel(30);
        deleteGarbageDataMapper.deleteMemberGrade(30);
        return R.ok();
    }

}
