package com.huimv.receive.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huimv.receive.common.utils.Result;
import com.huimv.receive.common.utils.ResultCode;
import com.huimv.receive.entity.BillGoodsInventory;
import com.huimv.receive.entity.vo.BillGoodsInventoryVo;
import com.huimv.receive.mapper.BillGoodsInventoryMapper;
import com.huimv.receive.service.IBillGoodsInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-08-22
 */
@Service
public class BillGoodsInventoryServiceImpl extends ServiceImpl<BillGoodsInventoryMapper, BillGoodsInventory> implements IBillGoodsInventoryService {

    @Autowired
    private BillGoodsInventoryMapper inventoryMapper;

    @Override
    public Result listAll(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        QueryWrapper<BillGoodsInventory> queryWrapper = new QueryWrapper<>();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
        queryWrapper.ge("create_date", calendar.getTime()).eq("farm_id", farmId);
//        queryWrapper.groupBy("create_date");
//        queryWrapper.orderByAsc("create_date");
        List<BillGoodsInventoryVo> billGoodsInventoryVos = inventoryMapper.listAll(queryWrapper);
//        List<BillGoodsInventory> billGoodsInventories = inventoryMapper.selectList(queryWrapper);

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