package com.zbf.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.zbf.common.annotation.DataScope;
import com.zbf.common.utils.DateUtils;
import com.zbf.system.domain.TBaseStorage;
import com.zbf.system.service.ITBaseStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //添加
import com.zbf.system.mapper.TMiStockBakMapper;
import com.zbf.system.domain.TMiStockBak;
import com.zbf.system.service.ITMiStockBakService;

/**
 * 库存备份Service业务层处理
 *
 * @author tony
 * @date 2024-06-14
 */
@Service
public class TMiStockBakServiceImpl extends ServiceImpl<TMiStockBakMapper, TMiStockBak> implements ITMiStockBakService //修改
{
    @Autowired
    private TMiStockBakMapper tMiStockBakMapper;
    @Autowired
    private ITBaseStorageService baseStorageService;

    /**
     * 查询库存备份
     *
     * @param id 库存备份主键
     * @return 库存备份
     */
    @Override
    public TMiStockBak selectTMiStockBakById(Long id)
    {
        return tMiStockBakMapper.selectTMiStockBakById(id);
    }

    /**
     * 查询库存备份列表
     *
     * @param tMiStockBak 库存备份
     * @return 库存备份
     */
    @Override
    public List<TMiStockBak> selectTMiStockBakList(TMiStockBak tMiStockBak)
    {
        List<TBaseStorage> storageList = getStorageList(tMiStockBak.getDeptId());
        if(storageList.size() > 0){
            tMiStockBak.setStorageList(storageList.stream().map(TBaseStorage::getStorageId).collect(Collectors.toList()));
        }
        return tMiStockBakMapper.selectTMiStockBakList(tMiStockBak);
    }
    private List<TBaseStorage> getStorageList(Long deptId){
        TBaseStorage baseStorage = new TBaseStorage();
        baseStorage.setDeptId(deptId);
        return baseStorageService.selectTBaseStorageList(baseStorage);

    }

    /**
     * 新增库存备份
     *
     * @param tMiStockBak 库存备份
     * @return 结果
     */
    @Override
    public int insertTMiStockBak(TMiStockBak tMiStockBak)
    {
        tMiStockBak.setCreateTime(DateUtils.getNowDate());
        return tMiStockBakMapper.insertTMiStockBak(tMiStockBak);
    }

    /**
     * 修改库存备份
     *
     * @param tMiStockBak 库存备份
     * @return 结果
     */
    @Override
    public int updateTMiStockBak(TMiStockBak tMiStockBak)
    {
                tMiStockBak.setUpdateTime(DateUtils.getNowDate());
        return tMiStockBakMapper.updateTMiStockBak(tMiStockBak);
    }

    /**
     * 批量删除库存备份
     *
     * @param ids 需要删除的库存备份主键
     * @return 结果
     */
    @Override
    public int deleteTMiStockBakByIds(Long[] ids)
    {
        return tMiStockBakMapper.deleteTMiStockBakByIds(ids);
    }

    /**
     * 删除库存备份信息
     *
     * @param id 库存备份主键
     * @return 结果
     */
    @Override
    public int deleteTMiStockBakById(Long id)
    {
        return tMiStockBakMapper.deleteTMiStockBakById(id);
    }


    /**
     * 批量禁用
     *
     * @param id 库存备份主键
     * @return 结果
     */
    @Override
    public int disabledTMiStockBakByIds(Long[] ids) {
        return tMiStockBakMapper.disabledTMiStockBakByIds(ids);
    }

    /**
     * 批量启用
     *
     * @param id 库存备份主键
     * @return 结果
     */
    @Override
    public int enableTMiStockBakByIds(Long[] ids) {
        return tMiStockBakMapper.enableTMiStockBakByIds(ids);
    }

    /**
     * 修改状态
     *
     * @param tMiStockBak 工序管理主键
     * @return 结果
     */
    @Override
    public int updateStatus(TMiStockBak tMiStockBak) {
        return tMiStockBakMapper.updateTMiStockBak(tMiStockBak);
    }

}
