package com.huimv.eartag.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.config.IFileCreate;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.huimv.common.utils.Result;
import com.huimv.eartag.entity.FeedBuild;
import com.huimv.eartag.entity.FeedBuildCount;
import com.huimv.eartag.entity.FeedFowlRecord;
import com.huimv.eartag.mapper.FeedBuildCountMapper;
import com.huimv.eartag.mapper.FeedBuildMapper;
import com.huimv.eartag.mapper.FeedFowlRecordMapper;
import com.huimv.eartag.service.IFeedFowlRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 牛只档案 服务实现类
 * </p>
 *
 * @author author
 * @since 2022-06-01
 */
@Service
public class FeedFowlRecordServiceImpl extends ServiceImpl<FeedFowlRecordMapper, FeedFowlRecord> implements IFeedFowlRecordService {
    @Autowired
    private FeedBuildCountMapper feedBuildCountMapper;

    @Override
    public Map listAll(String bulidCode) {
        Map<String,Object> endMap = new HashedMap();

        QueryWrapper<FeedFowlRecord> wrapper = new QueryWrapper<>();
        if (StringUtils.isBlank(bulidCode)){
            bulidCode="D001";
        }
        wrapper.eq("build_code",bulidCode);
        endMap.put("list",this.list(wrapper));
        QueryWrapper<FeedBuildCount> countQueryWrapper = new QueryWrapper<>();
        countQueryWrapper.orderByDesc("update_date").eq("build_code",bulidCode).last("limit 1");
        FeedBuildCount feedBuildCount = feedBuildCountMapper.selectOne(countQueryWrapper);
        endMap.put("bulidCount",feedBuildCount);
        return endMap;
    }




}
