package com.mortals.xhx.common.thread;


import cn.hutool.core.date.DateTime;
import cn.hutool.extra.spring.SpringUtil;
import com.mortals.framework.model.Context;
import com.mortals.xhx.common.code.StatTypeEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.module.ph.service.PhQueueStatService;
import com.mortals.xhx.module.pj.service.PjEvaluateStatService;
import com.mortals.xhx.module.stat.service.StatService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;

import java.util.List;

/**
 * 站点统计数据线程
 *
 * @author: zxfei
 * @date: 2024/8/2 14:13
 */
@Slf4j
@AllArgsConstructor
public class StatThread implements Runnable {

    private DateTime attendStart;

    private Long compare;

    private SitePdu site;

    private Context context;

    private List<Integer> typeStatList;


    @Override
    public void run() {
            if (ObjectUtils.isEmpty(site.getId())) return;

            StopWatch stopWatch = new StopWatch();
            PhQueueStatService phQueueStatService = SpringUtil.getBean(PhQueueStatService.class);
            PjEvaluateStatService pjEvaluateStatService = SpringUtil.getBean(PjEvaluateStatService.class);
            StatService statService = SpringUtil.getBean(StatService.class);

            if (typeStatList.contains(StatTypeEnum.STAT_PH.getValue())) {
                phQueueStatService.updateSitePhStatLog(attendStart, compare, stopWatch, site, context);
            }

            if (typeStatList.contains(StatTypeEnum.STAT_PJ.getValue())) {
                pjEvaluateStatService.updateSitePjStatLog(attendStart, compare, stopWatch, site, context);
            }

            if (typeStatList.contains(StatTypeEnum.STAT_ALL.getValue())) {
                statService.updateSiteStatLog(attendStart, compare, stopWatch, site, context);
            }


    }

}
