package com.huimv.produce.produce.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huimv.produce.produce.entity.ProdStock;
import com.huimv.produce.produce.mapper.ProdStockMapper;
import com.huimv.produce.produce.service.IProdStockService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author astupidcoder
 * @since 2021-10-12
 */
@Service
public class ProdStockServiceImpl extends ServiceImpl<ProdStockMapper, ProdStock> implements IProdStockService {

    @Override
    public Map listStorage(Integer farmId) {
        Map map = new HashMap();
//        QueryWrapper<ProdStock> wrapper = new QueryWrapper<>();
//        wrapper.eq("farm_id", farmId);
//        wrapper.eq("stock_type","sow_stock");
//        List<ProdStock> sowStock = this.list(wrapper);
//        map.put("sowStock",sowStock);
//
//        QueryWrapper<ProdStock> wrapper1 = new QueryWrapper<>();
//        wrapper1.eq("farm_id", farmId);
//        wrapper1.eq("stock_type","boar_stock");
//        List<ProdStock> boarStock = this.list(wrapper);
//        map.put("boarStock",boarStock);
//
//
//        QueryWrapper<ProdStock> wrapper2 = new QueryWrapper<>();
//        wrapper2.eq("farm_id", farmId);
//        wrapper2.eq("stock_type","grice_stock");
//        List<ProdStock> griceStock = this.list(wrapper);
//        map.put("griceStock",griceStock);
//
//
//        QueryWrapper<ProdStock> wrapper3 = new QueryWrapper<>();
//        wrapper3.eq("farm_id", farmId);
//        wrapper3.eq("stock_type","piglet_stock");
//        List<ProdStock> pigletStock = this.list(wrapper);
//        map.put("pigletStock",pigletStock);
//
//
//        QueryWrapper<ProdStock> wrapper4 = new QueryWrapper<>();
//        wrapper4.eq("farm_id", farmId);
//        wrapper4.eq("stock_type","fatpig_stock");
//        List<ProdStock> fatpigStock = this.list(wrapper);
//        map.put("fatpigStock",fatpigStock);
        Date now = new Date();

        List list = new ArrayList();
        list.add("sow_stock");
        list.add("boar_stock");
        list.add("grice_stock");
        list.add("piglet_stock");
        list.add("fatpig_stock");
        list.add("sow_stock_5");
        QueryWrapper<ProdStock> wrapper = new QueryWrapper<>();
        wrapper.in("stock_type",list);
        wrapper.eq("farm_id",farmId);
        List<ProdStock> prodStockList = this.list(wrapper);

        Set month = new HashSet();
        List month1 = new ArrayList();
        List sowStock = new ArrayList();
        List boarStock = new ArrayList();
        List griceStock = new ArrayList();
        List pigletStock = new ArrayList();
        List fatpigStock = new ArrayList();
        List backPigStock = new ArrayList();
        for (ProdStock prodStock : prodStockList) {
            if ( month.add(prodStock.getMonth())){
                month1.add(prodStock.getMonth());
            }
            String stockType = prodStock.getStockType();
            Integer stockQuantity = prodStock.getStockQuantity();
            switch (stockType){
                case "sow_stock":
                    sowStock.add(stockQuantity);
                    break;
                case "boar_stock":
                    boarStock.add(stockQuantity);
                    break;
                case "grice_stock":
                    griceStock.add(stockQuantity);
                    break;
                case "piglet_stock":
                    pigletStock.add(stockQuantity);
                    break;
                case "fatpig_stock":
                    fatpigStock.add(stockQuantity);
                    break;
                case "sow_stock_5":
                    backPigStock.add(stockQuantity);
                    break;
                default:
                    break;

            }
        }

        map.put("sowStock",sowStock);
        map.put("boarStock",boarStock);
        map.put("griceStock",griceStock);
        map.put("pigletStock",pigletStock);
        map.put("fatpigStock",fatpigStock);
        // 后备
        map.put("backPigStock",backPigStock);
        map.put("month",month1);
        return map;
    }


}
