package com.jeequan.jeepay.service.impl;

import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.db.entity.CashoutRecord;
import com.jeequan.jeepay.db.entity.MchApplyment;
import com.jeequan.jeepay.db.entity.SysEntitlement;
import com.jeequan.jeepay.db.entity.ToDoListModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class MainChartService {


    @Autowired
    private PackageOrderService packageOrderService;

    @Autowired
    private SysEntitlementService sysEntitlementService;

    @Autowired
    private MchAppService mchAppService;

    @Autowired
    private MchModifyApplymentService modifyApplymentService;

    @Autowired
    private CashoutRecordService cashoutRecordService;

    @Autowired
    private AccountChangeInfoService accountChangeInfoService;

    @Autowired
    private MchApplymentService mchApplymentService;

    /**
     *
     *  @describe （待办事项）汇总待审核或者待操作的事件数量
     *
     * @return
     */
    public List<ToDoListModel> getWaitOperationNumber(){
        ToDoListModel toDoListModel=new ToDoListModel();
        List<ToDoListModel> toDoListModelList=new ArrayList<>();


        //通过权限表id获取名字，防止改名出现不匹配的情况
        //1.产品管理，产品审核,应用审核
        //产品审核
        long productAppCheckNumber = packageOrderService.getProductAppCheckNumber(null);
        SysEntitlement eentMchProductCheck = sysEntitlementService.getSysEntitlement("EENT_MCH_PRODUCT_CHECK", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel.setName(eentMchProductCheck.getEntName());
        toDoListModel.setCount(productAppCheckNumber);
        toDoListModelList.add(toDoListModel);
        //应用审核
        long mchAppCheckNumber = mchAppService.getMchAppCheckNumber(null);
        SysEntitlement entMchApp = sysEntitlementService.getSysEntitlement("ENT_MCH_APP", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entMchApp.getEntName());
        toDoListModel.setCount(mchAppCheckNumber);
        toDoListModelList.add(toDoListModel);
        //产品管理总数
        SysEntitlement entMchProduct = sysEntitlementService.getSysEntitlement("ENT_MCH_PRODUCT", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entMchProduct.getEntName());
        toDoListModel.setCount(productAppCheckNumber+mchAppCheckNumber);
        toDoListModelList.add(toDoListModel);


        //2.商户管理，商户变更审核
        //商户变更审核 ，进件管理-待预审
        long modifyApplyMentChecknNumber = modifyApplymentService.getModifyApplyMentChecknNumber(null);
        SysEntitlement entMchModify = sysEntitlementService.getSysEntitlement("ENT_MCH_APP_MODIFY_LIST", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entMchModify.getEntName());
        toDoListModel.setCount(modifyApplyMentChecknNumber);
        toDoListModelList.add(toDoListModel);
        //进件管理
        long count = mchApplymentService.count(MchApplyment.gw().eq(MchApplyment::getState, 7));
        SysEntitlement entitlement = sysEntitlementService.getSysEntitlement("ENT_MCH_APPLYMENT", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entitlement.getEntName());
        toDoListModel.setCount(count);
        toDoListModelList.add(toDoListModel);
        //商户管理总数
        SysEntitlement entMch = sysEntitlementService.getSysEntitlement("ENT_MCH", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entMch.getEntName());
        toDoListModel.setCount(modifyApplyMentChecknNumber+count);
        toDoListModelList.add(toDoListModel);

        //3.佣金管理，提现申请管理
        //提现申请管理
        long cashoutNumber = cashoutRecordService.count(CashoutRecord.gw().eq(CashoutRecord::getState, CashoutRecord.CASHOUT_STATE_AUDIT_ING));
        SysEntitlement entProfitCashoutRecord = sysEntitlementService.getSysEntitlement("ENT_PROFIT_CASHOUT_RECORD", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entProfitCashoutRecord.getEntName());
        toDoListModel.setCount(cashoutNumber);
        toDoListModelList.add(toDoListModel);
        //佣金管理总数
        SysEntitlement entProfit = sysEntitlementService.getSysEntitlement("ENT_PROFIT", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entProfit.getEntName());
        toDoListModel.setCount(cashoutNumber);
        toDoListModelList.add(toDoListModel);


        //4.订单管理，资金明细列表 类型为退款 状态为处理中需要
        //资金明细列表
        //todo 暂时先不做
        /*int accountChangeNumber = accountChangeInfoService.count(AccountChangeInfo.gw().eq(AccountChangeInfo::getChangeType, AccountChangeInfo.REFUND)
                .eq(AccountChangeInfo::getState, AccountChangeInfo.PROCESSING));
        SysEntitlement entAccountChange = sysEntitlementService.getSysEntitlement("ENT_ACCOUNT_CHANGE_LIST", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entAccountChange.getEntName());
        toDoListModel.setCount(accountChangeNumber);
        toDoListModelList.add(toDoListModel);
        //订单管理总数
        SysEntitlement entOrder = sysEntitlementService.getSysEntitlement("ENT_ORDER", CS.SYS_ROLE_TYPE.PLATFORM);
        toDoListModel=new ToDoListModel();
        toDoListModel.setName(entOrder.getEntName());
        toDoListModel.setCount(accountChangeNumber);
        toDoListModelList.add(toDoListModel);*/
        //5.对账管理，对账批次,差异账单 暂时不做
        // TODO: 2024/3/20  对账管理，对账批次,差异账单 暂时不做

        return toDoListModelList;
    }
}
