package cn.iocoder.yudao.module.member.job;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO;
import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO;
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
import cn.iocoder.yudao.module.member.dal.dataobject.orderdetail.OrderDetailDO;
import cn.iocoder.yudao.module.member.dal.dataobject.storebusiness.StoreBusinessDO;
import cn.iocoder.yudao.module.member.dal.mysql.business.BusinessMapper;
import cn.iocoder.yudao.module.member.dal.mysql.card.CardMapper;
import cn.iocoder.yudao.module.member.dal.mysql.order.DishOrderMapper;
import cn.iocoder.yudao.module.member.dal.mysql.orderdetail.OrderDetailMapper;
import cn.iocoder.yudao.module.member.dal.mysql.storebusiness.StoreBusinessMapper;
import cn.iocoder.yudao.module.member.enums.CostTypeEnum;
import cn.iocoder.yudao.module.member.enums.TimePeriodEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author:qjq
 * @Date:2024/4/3 14:50
 */
@Slf4j
@Component
public class BusinessNewJob implements JobHandler {
    @Resource
    private BusinessMapper businessMapper;

    @Resource
    private StoreBusinessMapper storeBusinessMapper;

    /**
     * 执行任务
     *
     * @param param 参数
     * @return 结果
     * @throws Exception 异常
     */
    @Override
    @TenantIgnore
    public String execute(String param){
        List<Long> allStoreId = businessMapper.getAllStoreId();
        for (Long storeId : allStoreId) {
            BusinessDO businessDO = new BusinessDO();
            businessDO.setCarteenId(storeId);
            businessMapper.insert(businessDO);

            StoreBusinessDO storeBusinessDO = new StoreBusinessDO();
            storeBusinessDO.setCarteenId(storeId);
            storeBusinessMapper.insert(storeBusinessDO);
        }
        log.info("[execute][生成当天统计营业数据 {}条]", allStoreId.size());
        return String.format("生成当天统计营业数据 %s 条   ", allStoreId.size());
    }
}
