package com.zg.project.Inventory.Task.service.impl;

import java.util.List;

import com.zg.common.utils.DateUtils;
import com.zg.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zg.project.Inventory.Task.mapper.InventoryTaskMapper;
import com.zg.project.Inventory.domain.entity.InventoryTask;
import com.zg.project.Inventory.Task.service.IInventoryTaskService;

/**
 * 盘点任务Service业务层处理
 * 
 * @author zg
 * @date 2025-06-16
 */
@Service
public class InventoryTaskServiceImpl implements IInventoryTaskService 
{
    @Autowired
    private InventoryTaskMapper inventoryTaskMapper;

    /**
     * 查询盘点任务
     * 
     * @param id 盘点任务主键
     * @return 盘点任务
     */
    @Override
    public InventoryTask selectInventoryTaskById(Long id)
    {
        return inventoryTaskMapper.selectInventoryTaskById(id);
    }

    /**
     * 查询盘点任务列表
     * 
     * @param inventoryTask 盘点任务
     * @return 盘点任务
     */
    @Override
    public List<InventoryTask> selectInventoryTaskList(InventoryTask inventoryTask)
    {
        return inventoryTaskMapper.selectInventoryTaskList(inventoryTask);
    }

    /**
     * 新增盘点任务
     * 
     * @param inventoryTask 盘点任务
     * @return 结果
     */
    @Override
    public int insertInventoryTask(InventoryTask inventoryTask) {
        inventoryTask.setCreatedBy(SecurityUtils.getUsername());
        inventoryTask.setCreatedAt(DateUtils.getTime());
        inventoryTask.setIsDelete("0");
        inventoryTask.setStatus("0");
        return inventoryTaskMapper.insertInventoryTask(inventoryTask);
    }

    /**
     * 修改盘点任务
     * 
     * @param inventoryTask 盘点任务
     * @return 结果
     */
    @Override
    public int updateInventoryTask(InventoryTask inventoryTask)
    {
        return inventoryTaskMapper.updateInventoryTask(inventoryTask);
    }

    /**
     * 批量删除盘点任务
     * 
     * @param ids 需要删除的盘点任务主键
     * @return 结果
     */
    @Override
    public int deleteInventoryTaskByIds(Long[] ids)
    {
        return inventoryTaskMapper.deleteInventoryTaskByIds(ids);
    }

    /**
     * 删除盘点任务信息
     * 
     * @param id 盘点任务主键
     * @return 结果
     */
    @Override
    public int deleteInventoryTaskById(Long id)
    {
        return inventoryTaskMapper.deleteInventoryTaskById(id);
    }

    @Override
    public int countPendingTaskByUserId(Long userId) {
        return inventoryTaskMapper.countPendingTaskByUserId(userId);
    }

    /**
     * 根据任务ID获取仓库
     * @param taskId
     * @return
     */
    @Override
    public String getWhByTaskId(String taskId) {
        return inventoryTaskMapper.getWhByTaskId(taskId);
    }
}
