package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.common.core.utils.DateUtils;
import cn.cecep.talroad.domain.STaskYieldTrend;
import cn.cecep.talroad.enums.TimeTypeEnum;
import cn.cecep.talroad.mapper.STaskYieldTrendMapper;
import cn.cecep.talroad.service.STaskYieldTrendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class STaskYieldTrendServiceImpl extends ServiceImpl<STaskYieldTrendMapper, STaskYieldTrend> implements STaskYieldTrendService {

    @Resource
    private STaskYieldTrendMapper sTaskYieldTrendMapper;

    @Override
    public void triggerYieldTrendSynchro(String factoryId) {

    }

    @Override
    public void analyseDayTaskYieldTrendData() {
        Date curr = new Date();
        Date lastDay = DateUtils.addDateDays(curr,-1);
        String dayTime = DateUtils.parseDateToStr("yyyy-MM-dd",lastDay);
        List<STaskYieldTrend> list = sTaskYieldTrendMapper.analyseDayTaskYieldTrendData(dayTime);
        list.forEach(t ->{
            t.setTimeType(TimeTypeEnum.DAY.getCode());
            t.setDataTime(DateUtils.dateTime("yyyy-MM-dd",dayTime));
            sTaskYieldTrendMapper.insert(t);
        });
    }

}
