package vip.xiaonuo.Timer;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import vip.xiaonuo.common.timer.CommonTimerTaskRunner;
import vip.xiaonuo.modular.feed.feedingenv.entity.FeedingEnv;
import vip.xiaonuo.modular.feed.feedingenv.mapper.FeedingEnvMapper;
import vip.xiaonuo.modular.feed.feedingfat.entity.FeedingFat;
import vip.xiaonuo.modular.feed.feedingfat.mapper.FeedingFatMapper;
import vip.xiaonuo.modular.feed.feedinglist.entity.FeedingList;
import vip.xiaonuo.modular.feed.feedinglist.mapper.FeedingListMapper;

import java.util.Date;
import java.util.List;


@Slf4j
@Component
public class ProFeedingData implements CommonTimerTaskRunner {

    @Autowired
    private FeedingListMapper listMapper;
    @Autowired
    private FeedingFatMapper fatMapper;
    @Autowired
    private FeedingEnvMapper envMapper;

    @Override
    public void action() {
        QueryWrapper<FeedingEnv> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("org_id", "1543842934270394370").eq("device_status", 1);
        List<FeedingEnv> feedingEnvs = envMapper.selectList(queryWrapper);
        for (FeedingEnv feedingEnv : feedingEnvs) {
            String water = NumberUtils.getNumFloat(5.0, 20.0);
            String feeding = NumberUtils.getNumFloat(5.0, 15.0);
            String weight = NumberUtils.getNumFloat(60.0, 65.0);
            String tem = NumberUtils.getNumFloat(36.0, 38.0);
            String act = NumberUtils.getNum(8, 10, 0);


            FeedingFat fat = new FeedingFat();
            fat.setUnitId(feedingEnv.getUnitId());
            fat.setUnitName(feedingEnv.getUnitName());
            fat.setEartagNum(feedingEnv.getEartagNum());
            fat.setCreateTime(new Date());
            fat.setUploadTime(new Date());
            fat.setDeviceCode(feedingEnv.getDeviceCode());
            fat.setOrgId(feedingEnv.getOrgId());
            fat.setDeviceType(feedingEnv.getType());
            fat.setWaterValue(water);
            fat.setWeigthValue(weight);
            fat.setFeedAct(act);
            fat.setFeedValue(feeding);
            fat.setTemp(tem);
            fat.setDayNum("100");
            if ("1".equals(feedingEnv.getType())) {
                fat.setRank(NumberUtils.getNumFloat(0.1, 1.0));
            }
            fatMapper.insert(fat);
            FeedingList list = new FeedingList();
            list.setUnitId(feedingEnv.getUnitId());
            list.setUnitName(feedingEnv.getUnitName());
            list.setCreateTime(new Date());
            list.setUploadTime(new Date());
            list.setOrgId(feedingEnv.getOrgId());
            list.setType(feedingEnv.getType());
            list.setPigNum(feedingEnv.getPigNum());
            String feedValue = NumberUtils.getNumFloat(30.0, 40.0);
            list.setFeedValue(feeding);
            list.setMarginValue(feedValue);
            listMapper.insert(list);
        }
    }
}
