package com.huimv.produce.produce.controller;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import com.huimv.produce.produce.entity.ProdStock;
import com.huimv.produce.produce.service.IProdStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-10-12
 */
@RestController
@RequestMapping("/prodStock")
public class ProdStockController {

    @Autowired
    private IProdStockService prodStockService;

    @GetMapping("/listERP")
    public Result listERP(@RequestParam(name = "farmId") Integer farmId){
        Date now = new Date();

        List<ProdStock> list = prodStockService.list(new QueryWrapper<ProdStock>().eq("farm_id", farmId).eq("year",DateUtil.year(now)).eq("month", DateUtil.month(now)+1));
//        List endList = new ArrayList();
        Map map = new HashMap();
        for (ProdStock prodStock : list) {
            String stockType = prodStock.getStockType();
            map.put(stockType,prodStock);

        }
        return new Result(ResultCode.SUCCESS,map);
    }

    @GetMapping("/listStorage")
    public Result listStorage(@RequestParam(name = "farmId") Integer farmId){

        Map map = prodStockService.listStorage(farmId);
        System.out.println(""+map.toString());
        return new Result(ResultCode.SUCCESS,map);
    }


}
