package com.zbf.system.service.impl;

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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zbf.common.annotation.DataScope;
import com.zbf.common.annotation.DataSource;
import com.zbf.common.enums.DataSourceType;
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.TCkPickingwavegoodsBakMapper;
import com.zbf.system.domain.TCkPickingwavegoodsBak;
import com.zbf.system.service.ITCkPickingwavegoodsBakService;

/**
 * 出库任务历史Service业务层处理
 *
 * @author tony
 * @date 2024-06-14
 */
@Service
public class TCkPickingwavegoodsBakServiceImpl extends ServiceImpl<TCkPickingwavegoodsBakMapper, TCkPickingwavegoodsBak> implements ITCkPickingwavegoodsBakService //修改
{
    @Autowired
    private TCkPickingwavegoodsBakMapper tCkPickingwavegoodsBakMapper;
    @Autowired
    private ITBaseStorageService baseStorageService;

    /**
     * 查询出库任务历史
     *
     * @param id 出库任务历史主键
     * @return 出库任务历史
     */
    @Override
    public TCkPickingwavegoodsBak selectTCkPickingwavegoodsBakById(String id)
    {
        return tCkPickingwavegoodsBakMapper.selectTCkPickingwavegoodsBakById(id);
    }

    /**
     * 查询出库任务历史列表
     *
     * @param tCkPickingwavegoodsBak 出库任务历史
     * @return 出库任务历史
     */
    @Override
    @DataSource(value = DataSourceType.MASTER)
    public List<TCkPickingwavegoodsBak> selectTCkPickingwavegoodsBakList(TCkPickingwavegoodsBak tCkPickingwavegoodsBak)
    {
//         List<TBaseStorage> storageList = getStorageList(tCkPickingwavegoodsBak.getDeptId());
//        if(storageList.size() > 0){
//            tCkPickingwavegoodsBak.setStorageList(storageList.stream().map(TBaseStorage::getStorageId).collect(Collectors.toList()));
//        }
        return tCkPickingwavegoodsBakMapper.selectTCkPickingwavegoodsBakList(tCkPickingwavegoodsBak);
    }

    /**
     * 新增出库任务历史
     *
     * @param tCkPickingwavegoodsBak 出库任务历史
     * @return 结果
     */
    @Override
    public int insertTCkPickingwavegoodsBak(TCkPickingwavegoodsBak tCkPickingwavegoodsBak)
    {
        tCkPickingwavegoodsBak.setCreateTime(DateUtils.getNowDate());
        return tCkPickingwavegoodsBakMapper.insertTCkPickingwavegoodsBak(tCkPickingwavegoodsBak);
    }

    /**
     * 修改出库任务历史
     *
     * @param tCkPickingwavegoodsBak 出库任务历史
     * @return 结果
     */
    @Override
    public int updateTCkPickingwavegoodsBak(TCkPickingwavegoodsBak tCkPickingwavegoodsBak)
    {
                tCkPickingwavegoodsBak.setUpdateTime(DateUtils.getNowDate());
        return tCkPickingwavegoodsBakMapper.updateTCkPickingwavegoodsBak(tCkPickingwavegoodsBak);
    }

    /**
     * 批量删除出库任务历史
     *
     * @param ids 需要删除的出库任务历史主键
     * @return 结果
     */
    @Override
    public int deleteTCkPickingwavegoodsBakByIds(String[] ids)
    {
        return tCkPickingwavegoodsBakMapper.deleteTCkPickingwavegoodsBakByIds(ids);
    }

    /**
     * 删除出库任务历史信息
     *
     * @param id 出库任务历史主键
     * @return 结果
     */
    @Override
    public int deleteTCkPickingwavegoodsBakById(String id)
    {
        return tCkPickingwavegoodsBakMapper.deleteTCkPickingwavegoodsBakById(id);
    }


    /**
     * 批量禁用
     *
     * @param id 出库任务历史主键
     * @return 结果
     */
    @Override
    public int disabledTCkPickingwavegoodsBakByIds(String[] ids) {
        return tCkPickingwavegoodsBakMapper.disabledTCkPickingwavegoodsBakByIds(ids);
    }

    /**
     * 批量启用
     *
     * @param id 出库任务历史主键
     * @return 结果
     */
    @Override
    public int enableTCkPickingwavegoodsBakByIds(String[] ids) {
        return tCkPickingwavegoodsBakMapper.enableTCkPickingwavegoodsBakByIds(ids);
    }

    /**
     * 修改状态
     *
     * @param tCkPickingwavegoodsBak 工序管理主键
     * @return 结果
     */
    @Override
    public int updateStatus(TCkPickingwavegoodsBak tCkPickingwavegoodsBak) {
        return tCkPickingwavegoodsBakMapper.updateTCkPickingwavegoodsBak(tCkPickingwavegoodsBak);
    }
    private List<TBaseStorage> getStorageList(Long deptId){
        TBaseStorage baseStorage = new TBaseStorage();
        baseStorage.setDeptId(deptId);
        return baseStorageService.selectTBaseStorageList(baseStorage);

    }
    @Override
    public List<TCkPickingwavegoodsBak> list(LambdaQueryWrapper<TCkPickingwavegoodsBak> tCkPickingwavegoodsBakLambdaQueryWrapper) {
        return tCkPickingwavegoodsBakMapper.selectList(tCkPickingwavegoodsBakLambdaQueryWrapper);
    }


}
