package com.sw.mes.yb.scheduled;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.sw.mes.yb.report.entity.ZhxxProgressStatistics;
import com.sw.mes.yb.report.service.ZhxxProgressStatisticsService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

@Slf4j
@Component
public class ProgressStatistics {

    @Autowired
    private ZhxxProgressStatisticsService zhxxProgressStatisticsService;

    @XxlJob("progressStatistics")
    public void wipProgressStatistics() {
        CompletableFuture.runAsync(()->{
        //一检未截断毛棒
        List<Map<String,Object>> woolStickList=zhxxProgressStatisticsService.getWoolStick();
        List<ZhxxProgressStatistics> accOutCaseHelpExamList= JSON.parseObject(JSON.toJSONString(woolStickList), new TypeReference<List<ZhxxProgressStatistics>>() {});
        if(CollectionUtils.isNotEmpty(accOutCaseHelpExamList)){
            zhxxProgressStatisticsService.saveAll(accOutCaseHelpExamList);
        }
        //圆棒
        List<Map<String,Object>> ybList=zhxxProgressStatisticsService.getYbList();
        List<ZhxxProgressStatistics> yBExamList= JSON.parseObject(JSON.toJSONString(ybList), new TypeReference<List<ZhxxProgressStatistics>>() {});
        if(CollectionUtils.isNotEmpty(yBExamList)){
            zhxxProgressStatisticsService.saveAll(yBExamList);
        }
        //方棒
        List<Map<String,Object>> fbList=zhxxProgressStatisticsService.getFbList();
        List<ZhxxProgressStatistics> fBExamList= JSON.parseObject(JSON.toJSONString(fbList), new TypeReference<List<ZhxxProgressStatistics>>() {});
        if(CollectionUtils.isNotEmpty(fBExamList)){
            zhxxProgressStatisticsService.saveAll(fBExamList);
        }
        });
    }
}
