package com.zehong.system.service.impl;

import com.zehong.common.utils.DateUtils;
import com.zehong.system.domain.TInsSpotHazardRef;
import com.zehong.system.domain.TWorkSupervision;
import com.zehong.system.mapper.TInsSpotHazardRefMapper;
import com.zehong.system.mapper.TWorkSupervisionMapper;
import com.zehong.system.service.ITWorkSupervisionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 工作督导Service业务层处理
 * 
 * @author zehong
 * @date 2025-08-15
 */
@Service
public class TWorkSupervisionServiceImpl implements ITWorkSupervisionService
{
    @Autowired
    private TWorkSupervisionMapper tWorkSupervisionMapper;
    @Autowired
    private TInsSpotHazardRefMapper tInsSpotHazardRefMapper;

    /**
     * 查询工作督导
     * 
     * @param supervisionId 工作督导ID
     * @return 工作督导
     */
    @Override
    public TWorkSupervision selectTWorkSupervisionById(Long supervisionId)
    {
        return tWorkSupervisionMapper.selectTWorkSupervisionById(supervisionId);
    }

    /**
     * 查询工作督导列表
     * 
     * @param tWorkSupervision 工作督导
     * @return 工作督导
     */
    @Override
    public List<TWorkSupervision> selectTWorkSupervisionList(TWorkSupervision tWorkSupervision)
    {
        return tWorkSupervisionMapper.selectTWorkSupervisionList(tWorkSupervision);
    }

    /**
     * 新增工作督导
     * 
     * @param tWorkSupervision 工作督导
     * @return 结果
     */
    @Override
    public int insertTWorkSupervision(TWorkSupervision tWorkSupervision)
    {
        tWorkSupervision.setCreateTime(DateUtils.getNowDate());
        int a = tWorkSupervisionMapper.insertTWorkSupervision(tWorkSupervision);
        if(tWorkSupervision.getHiddenId()!=null){
            TInsSpotHazardRef hidden = new TInsSpotHazardRef();
            hidden.setfInsSpotHazardRefId(tWorkSupervision.getHiddenId());
            hidden.setfSupervisionId(tWorkSupervision.getSupervisionId());
            tInsSpotHazardRefMapper.updateTInsSpotHazardRef(hidden);
        }
        return a;
    }

    /**
     * 修改工作督导
     * 
     * @param tWorkSupervision 工作督导
     * @return 结果
     */
    @Override
    public int updateTWorkSupervision(TWorkSupervision tWorkSupervision)
    {
        return tWorkSupervisionMapper.updateTWorkSupervision(tWorkSupervision);
    }

    /**
     * 批量删除工作督导
     * 
     * @param supervisionIds 需要删除的工作督导ID
     * @return 结果
     */
    @Override
    public int deleteTWorkSupervisionByIds(Long[] supervisionIds)
    {
        return tWorkSupervisionMapper.deleteTWorkSupervisionByIds(supervisionIds);
    }

    /**
     * 删除工作督导信息
     * 
     * @param supervisionId 工作督导ID
     * @return 结果
     */
    @Override
    public int deleteTWorkSupervisionById(Long supervisionId)
    {
        return tWorkSupervisionMapper.deleteTWorkSupervisionById(supervisionId);
    }
}
