package com.yunfeiyun.agmp.fms.service.impl;


import com.yunfeiyun.agmp.fms.domain.WmsAssetgoods;
import com.yunfeiyun.agmp.fms.mapper.WmsAssetgoodsMapper;
import com.yunfeiyun.agmp.fms.domain.vo.WmsAssetgoodsVo;
import com.yunfeiyun.agmp.fms.domain.resvo.WmsGoodsAppMapResVo;
import com.yunfeiyun.agmp.fms.service.IWmsAssetgoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 货物Service业务层处理
 * 
 * @author 杨晓辉
 * @date 2023-05-25
 */
@Service
public class WmsAssetgoodsServiceImpl implements IWmsAssetgoodsService
{
    @Autowired
    private WmsAssetgoodsMapper wmsAssetgoodsMapper;



    /**
     * 查询货物
     * 
     * @param goodsId 货物主键
     * @return 货物
     */
    @Override
    public WmsAssetgoodsVo selectWmsAssetgoodsVoByGoodsId(String goodsId)
    {
        return wmsAssetgoodsMapper.selectWmsAssetgoodsVoByGoodsId(goodsId);
    }

    @Override
    public List<WmsAssetgoodsVo> selectWmsAssetgoodsVoList(WmsAssetgoodsVo wmsAssetgoodsVo) {
        return wmsAssetgoodsMapper.selectWmsAssetgoodsVoList(wmsAssetgoodsVo);
    }


    @Override
    public List<WmsGoodsAppMapResVo> selectWmsGoodsAppMapResVo() {
        List<WmsAssetgoodsVo> wmsAssetGoodsVoList = wmsAssetgoodsMapper.selectWmsAssetgoodsVoList(null);
        Map<String,WmsGoodsAppMapResVo> map = new HashMap<>();
        for(WmsAssetgoodsVo item : wmsAssetGoodsVoList){
            WmsGoodsAppMapResVo vo = map.get(item.getGoodsType());
            if(null == vo){
                vo = new WmsGoodsAppMapResVo();
                vo.setId(item.getGoodsType());
                map.put(vo.getId(),vo);
            }
            vo.getContents().add(item);
        }
        return new ArrayList<>(map.values());
    }

    /**
     * 新增货物
     * 
     * @param wmsAssetgoods 货物
     * @return 结果
     */
    @Override
    public int insertWmsAssetgoodsVo(WmsAssetgoods wmsAssetgoods)
    {

        return wmsAssetgoodsMapper.insertWmsAssetgoods(wmsAssetgoods);
    }

    /**
     * 修改货物
     * 
     * @param wmsAssetgoods 货物
     * @return 结果
     */
    @Override
    public int updateWmsAssetgoodsVo(WmsAssetgoods wmsAssetgoods)
    {
        return wmsAssetgoodsMapper.updateWmsAssetgoods(wmsAssetgoods);
    }

    /**
     * 批量删除货物
     * 
     * @param goodsIds 需要删除的货物主键
     * @return 结果
     */
    @Override
    public int deleteWmsAssetgoodsVoByGoodsIds(String[] goodsIds)
    {
        return wmsAssetgoodsMapper.deleteWmsAssetgoodsByGoodsIds(goodsIds);
    }

    /**
     * 删除货物信息
     * 
     * @param goodsId 货物主键
     * @return 结果
     */
    @Override
    public int deleteWmsAssetgoodsVoByGoodsId(String goodsId)
    {
        return wmsAssetgoodsMapper.deleteWmsAssetgoodsByGoodsId(goodsId);
    }
}
