package com.zbf.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbf.common.utils.DateUtils;
import com.zbf.system.domain.TMiStock;
import com.zbf.system.domain.TPanDetail;
import com.zbf.system.mapper.TMiStockMapper;
import com.zbf.system.mapper.TPanDetailMapper;
import com.zbf.system.service.ITPanDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 盘点明细Service业务层处理
 *
 * @author wgs
 * @date 2024-11-01
 */
@Service
public class TPanDetailServiceImpl extends ServiceImpl<TPanDetailMapper, TPanDetail> implements ITPanDetailService //修改
{
    @Autowired
    private TPanDetailMapper tPanDetailMapper;

    @Autowired
    private TMiStockMapper mapper;

    /**
     * 查询盘点明细
     *
     * @param id 盘点明细主键
     * @return 盘点明细
     */
    @Override
    public TPanDetail selectTPanDetailById(Long id)
    {
        return tPanDetailMapper.selectTPanDetailById(id);
    }

    /**
     * 查询盘点明细列表
     *
     * @param tPanDetail 盘点明细
     * @return 盘点明细
     */
    @Override
    public List<TPanDetail> selectTPanDetailList(TPanDetail tPanDetail)
    {
        return tPanDetailMapper.selectTPanDetailList(tPanDetail);
    }

    /**
     * 新增盘点明细
     *
     * @param tPanDetail 盘点明细
     * @return 结果
     */
    @Override
    public int insertTPanDetail(TPanDetail tPanDetail)
    {
        tPanDetail.setCreateTime(DateUtils.getNowDate());
        return tPanDetailMapper.insertTPanDetail(tPanDetail);
    }

    /**
     * 修改盘点明细
     *
     * @param tPanDetail 盘点明细
     * @return 结果
     */
    @Override
    public int updateTPanDetail(TPanDetail tPanDetail)
    {
        LambdaQueryWrapper<TMiStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TMiStock::getId, tPanDetail.getStockId());
        TMiStock tMiStock = mapper.selectOne(queryWrapper);
        TPanDetail panDetail=  tPanDetailMapper.getList(tPanDetail.getStockId());

        tMiStock.setShelvesNum(panDetail.getCheckNum());
        int i = mapper.updateShelvesNum(tMiStock);
        if (i>0){
            tPanDetailMapper.deleteTPanDetailById(panDetail.getId());
        }
        return  0;

    }

    /**
     * 批量删除盘点明细
     *
     * @param ids 需要删除的盘点明细主键
     * @return 结果
     */
    @Override
    public int deleteTPanDetailByIds(Long[] ids)
    {
        return tPanDetailMapper.deleteTPanDetailByIds(ids);
    }

    /**
     * 删除盘点明细信息
     *
     * @param id 盘点明细主键
     * @return 结果
     */
    @Override
    public int deleteTPanDetailById(String id)
    {
        return tPanDetailMapper.deleteTPanDetailById(id);
    }


    /**
     * 批量禁用
     *
     * @param id 盘点明细主键
     * @return 结果
     */
    @Override
    public int disabledTPanDetailByIds(Long[] ids) {
        return tPanDetailMapper.disabledTPanDetailByIds(ids);
    }

    /**
     * 批量启用
     *
     * @param id 盘点明细主键
     * @return 结果
     */
    @Override
    public int enableTPanDetailByIds(Long[] ids) {
        return tPanDetailMapper.enableTPanDetailByIds(ids);
    }

    /**
     * 修改状态
     *
     * @param tPanDetail 工序管理主键
     * @return 结果
     */
    @Override
    public int updateStatus(TPanDetail tPanDetail) {
        return tPanDetailMapper.updateTPanDetail(tPanDetail);
    }

}
