package vip.xiaonuo.warehouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import vip.xiaonuo.warehouse.entity.WarehouseAge;
import vip.xiaonuo.warehouse.mapper.WarehouseAgeMapper;
import vip.xiaonuo.warehouse.param.WarehouseAgeParam;
import vip.xiaonuo.warehouse.param.WarehouseStockDetailParam;
import vip.xiaonuo.warehouse.param.WarehouseStockSecondParam;
import vip.xiaonuo.warehouse.service.IWarehouseAgeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 仓库物料库龄 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-04
 */
@Service
public class WarehouseAgeServiceImpl extends ServiceImpl<WarehouseAgeMapper, WarehouseAge> implements IWarehouseAgeService {

    @Autowired
    private WarehouseAgeMapper ageMapper;


    @Override
    public WarehouseAge listAge(WarehouseAgeParam detailParam) {
        String orgId = detailParam.getOrgId();
        Integer materialType = detailParam.getMaterialType();
        QueryWrapper<WarehouseAge> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(orgId),"org_id", orgId).eq( "material", materialType);
        queryWrapper.select(" IFNULL(sum(one_three),'0') oneThree,IFNULL(sum(four_six),'0') fourSix,IFNULL(sum(seven_year),'0') sevenYear," +
                "IFNULL(sum(year_one),'0') yearOne,IFNULL(sum(year_two),'0') yearTwo,IFNULL(sum(year_three),'0') yearThree");
        return ageMapper.selectOne(queryWrapper);
    }

}
