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

import java.util.List;

import com.yunfeiyun.agmp.common.enums.DictTypeEnums;
import com.yunfeiyun.agmp.common.utils.DictUtils;
import com.yunfeiyun.agmp.common.utils.StringUtils;
import com.yunfeiyun.agmp.fms.domain.WmsFinishgoods;
import com.yunfeiyun.agmp.fms.domain.WmsGoods;
import com.yunfeiyun.agmp.fms.mapper.WmsFinishgoodsMapper;
import com.yunfeiyun.agmp.fms.mapper.WmsGoodsMapper;
import com.yunfeiyun.agmp.fms.domain.reqvo.WmsFinishgoodsReqVo;
import com.yunfeiyun.agmp.fms.domain.resvo.WmsFinishGoodsStockSumInfoResVo;
import com.yunfeiyun.agmp.fms.domain.resvo.WmsFinishgoodsInfoResVo;
import com.yunfeiyun.agmp.fms.service.IWmsFinishgoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * 农产品货物Service业务层处理
 * 
 * @author 杨晓辉
 * @date 2023-06-30
 */
@Service
public class WmsFinishgoodsServiceImpl implements IWmsFinishgoodsService
{
    @Autowired
    private WmsFinishgoodsMapper wmsFinishgoodsMapper;
    @Resource
    private WmsGoodsMapper wmsGoodsMapper;

    /**
     * 查询农产品货物
     * 
     * @param finishgoodsId 农产品货物主键
     * @return 农产品货物
     */
    @Override
    public WmsFinishgoodsInfoResVo selectWmsFinishgoodsByFinishgoodsId(String finishgoodsId)
    {
        return wmsFinishgoodsMapper.selectWmsFinishgoodsByFinishgoodsId(finishgoodsId);
    }

    /**
     * 查询农产品货物列表
     * 
     * @param wmsFinishgoods 农产品货物
     * @return 农产品货物
     */
    @Override
    public List<WmsFinishgoods> selectWmsFinishgoodsList(WmsFinishgoods wmsFinishgoods)
    {
        return wmsFinishgoodsMapper.selectWmsFinishgoodsList(wmsFinishgoods);
    }

    @Override
    public List<WmsFinishGoodsStockSumInfoResVo> selectWmsFinishGoodsStockSumInfo(WmsFinishgoodsReqVo reqVo) {
        return wmsFinishgoodsMapper.selectWmsFinishGoodsStockSumInfo(reqVo);
    }

    /**
     * 新增农产品货物
     * 
     * @param wmsFinishgoods 农产品货物
     * @return 结果
     */
    @Override
    public int insertWmsFinishgoods(WmsFinishgoods wmsFinishgoods)
    {
        return wmsFinishgoodsMapper.insertWmsFinishgoods(wmsFinishgoods);
    }

    /**
     * 修改农产品货物
     * 
     * @param wmsFinishgoods 农产品货物
     * @return 结果
     */
    @Transactional
    @Override
    public int updateWmsFinishgoods(WmsFinishgoods wmsFinishgoods)
    {
        wmsFinishgoodsMapper.updateWmsFinishgoods(wmsFinishgoods);
        if (!StringUtils.isEmpty(wmsFinishgoods.getFinishgoodscode()) && !StringUtils.isEmpty(wmsFinishgoods.getGoodsId())) {
            WmsGoods wmsGoods = new WmsGoods();
            wmsGoods.setGoodsId(wmsFinishgoods.getGoodsId());
            wmsGoods.setGoodsName(DictUtils.getDictLabel(DictTypeEnums.AGM_MPP_PRODUCT.getCode(), wmsFinishgoods.getFinishgoodscode()));
            wmsGoodsMapper.updateWmsGoods(wmsGoods);
        }
        return 1;
    }

    /**
     * 批量删除农产品货物
     * 
     * @param finishgoodsIds 需要删除的农产品货物主键
     * @return 结果
     */
    @Override
    public int deleteWmsFinishgoodsByFinishgoodsIds(String[] finishgoodsIds)
    {
        return wmsFinishgoodsMapper.deleteWmsFinishgoodsByFinishgoodsIds(finishgoodsIds);
    }

    /**
     * 删除农产品货物信息
     * 
     * @param finishgoodsId 农产品货物主键
     * @return 结果
     */
    @Override
    public int deleteWmsFinishgoodsByFinishgoodsId(String finishgoodsId)
    {
        return wmsFinishgoodsMapper.deleteWmsFinishgoodsByFinishgoodsId(finishgoodsId);
    }

    @Override
    public int selectCount(String sourceinfoId) {
        return wmsFinishgoodsMapper.selectCount(sourceinfoId);
    }
}
