package com.yh.saas.plugin.yiliangyiyun.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yh.saas.plugin.yiliangyiyun.entity.InventoryCostInfo;
import com.yh.saas.plugin.yiliangyiyun.entity.WeightedDetails;
import com.yh.saas.plugin.yiliangyiyun.mapper.WeightedDetailsMapper;
import com.yh.saas.plugin.yiliangyiyun.service.IWeightedDetailsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 加权明细 服务实现类
 * </p>
 *
 * @author Gdc
 * @since 2021-10-08
 */
@Service
public class WeightedDetailsServiceImpl extends ServiceImpl<WeightedDetailsMapper, WeightedDetails> implements IWeightedDetailsService {


    /**
     * 列表
     *
     * @param weightedDetails
     * @return
     */
    @Override
    public Page<WeightedDetails> selectInventoryCostInfo(WeightedDetails weightedDetails) throws ParseException {
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy");
        Date start=simpleDateFormat.parse(weightedDetails.getYear());
        Date end=simpleDateFormat.parse(weightedDetails.getYear()+1);
        Page<WeightedDetails> weightedDetailsPage = this.selectPage(weightedDetails.getQueryPage(), new EntityWrapper<WeightedDetails>()
                .eq("warehouse_id", weightedDetails.getWarehouseId())
                .gt("update_date",start)
                .lt("update_date",end)
                .eq("goods_name_key", weightedDetails.getGoodsNameKey())
                .orderBy("update_date",false));
        int count = this.selectCount(new EntityWrapper<WeightedDetails>()
                .eq("warehouse_id", weightedDetails.getWarehouseId())
                .gt("update_date",start)
                .lt("update_date",end)
                .eq("goods_name_key", weightedDetails.getGoodsNameKey())
                .orderBy("update_date",false));
        weightedDetailsPage.setSize(count);
        return weightedDetailsPage;
    }
}
