package com.bonus.sgzb.material.service.impl;

import java.util.List;

import com.bonus.sgzb.base.api.domain.TmTask;
import com.bonus.sgzb.material.domain.PurchaseCheckInfo;
import com.bonus.sgzb.material.mapper.PurchaseCheckInfoMapper;
import com.bonus.sgzb.material.mapper.TaskMapper;
import com.bonus.sgzb.material.service.IPurchaseCheckInfoService;
import com.bonus.sgzb.common.core.utils.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 新购验收任务Service业务层处理
 * 
 * @author bonus
 * @date 2023-12-10
 */
@Service
public class PurchaseCheckInfoServiceImpl implements IPurchaseCheckInfoService
{
    @Resource
    private PurchaseCheckInfoMapper purchaseCheckInfoMapper;

    @Resource
    private TaskMapper taskMapper;

    /**
     * 查询新购验收任务
     * 
     * @param taskId 新购验收任务主键
     * @return 新购验收任务
     */
    @Override
    public PurchaseCheckInfo selectPurchaseCheckInfoByTaskId(Long taskId)
    {
        return purchaseCheckInfoMapper.selectPurchaseCheckInfoByTaskId(taskId);
    }

    /**
     * 查询新购验收任务列表
     * 
     * @param purchaseCheckInfo 新购验收任务
     * @return 新购验收任务
     */
    @Override
    public List<PurchaseCheckInfo> selectPurchaseCheckInfoList(PurchaseCheckInfo purchaseCheckInfo)
    {
        List<PurchaseCheckInfo> purchaseCheckInfos = purchaseCheckInfoMapper.selectPurchaseCheckInfoList(purchaseCheckInfo);
        for (PurchaseCheckInfo checkInfo : purchaseCheckInfos) {
            String typeName = purchaseCheckInfoMapper.selectTypeNameByTaskId(checkInfo.getTaskId());
            checkInfo.setPurchasingTypeName(typeName);
        }
        return purchaseCheckInfos;
    }

    /**
     * 新增新购验收任务
     * 
     * @param purchaseCheckInfo 新购验收任务
     * @return 结果
     */
    @Override
    @Transactional
    public int insertPurchaseCheckInfo(PurchaseCheckInfo purchaseCheckInfo)
    {
        TmTask task = new TmTask();
        task.setTaskType(14);
        task.setTaskStatus(24);
        task.setCode(purchaseCheckInfo.getCode());
        task.setCompanyId(purchaseCheckInfo.getCompanyId());
        taskMapper.insertTmTask(task);
        purchaseCheckInfo.setTaskId(task.getTaskId());
        purchaseCheckInfo.setCreateTime(DateUtils.getNowDate());
        return purchaseCheckInfoMapper.insertPurchaseCheckInfo(purchaseCheckInfo);
    }

    /**
     * 修改新购验收任务
     * 
     * @param purchaseCheckInfo 新购验收任务
     * @return 结果
     */
    @Override
    public int updatePurchaseCheckInfo(PurchaseCheckInfo purchaseCheckInfo)
    {
        purchaseCheckInfo.setUpdateTime(DateUtils.getNowDate());
        return purchaseCheckInfoMapper.updatePurchaseCheckInfo(purchaseCheckInfo);
    }

    /**
     * 批量删除新购验收任务
     * 
     * @param taskIds 需要删除的新购验收任务主键
     * @return 结果
     */
    @Override
    public int deletePurchaseCheckInfoByTaskIds(Long[] taskIds)
    {
        return purchaseCheckInfoMapper.deletePurchaseCheckInfoByTaskIds(taskIds);
    }

    /**
     * 删除新购验收任务信息
     * 
     * @param taskId 新购验收任务主键
     * @return 结果
     */
    @Override
    public int deletePurchaseCheckInfoByTaskId(Long taskId)
    {
        return purchaseCheckInfoMapper.deletePurchaseCheckInfoByTaskId(taskId);
    }
}
