package com.xinelu.manage.service.patientvisitoperation.impl;

import com.xinelu.manage.domain.patientvisitoperation.PatientVisitOperation;
import com.xinelu.manage.mapper.patientvisitoperation.PatientVisitOperationMapper;
import com.xinelu.manage.service.patientvisitoperation.IPatientVisitOperationService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 患者就诊手术记录信息Service业务层处理
 *
 * @author xinelu
 * @date 2024-02-26
 */
@Service
public class PatientVisitOperationServiceImpl implements IPatientVisitOperationService {
    @Resource
    private PatientVisitOperationMapper patientVisitOperationMapper;

    /**
     * 查询患者就诊手术记录信息
     *
     * @param id 患者就诊手术记录信息主键
     * @return 患者就诊手术记录信息
     */
    @Override
    public PatientVisitOperation selectPatientVisitOperationById(Long id) {
        return patientVisitOperationMapper.selectPatientVisitOperationById(id);
    }

    /**
     * 查询患者就诊手术记录信息列表
     *
     * @param patientVisitOperation 患者就诊手术记录信息
     * @return 患者就诊手术记录信息
     */
    @Override
    public List<PatientVisitOperation> selectPatientVisitOperationList(PatientVisitOperation patientVisitOperation) {
        return patientVisitOperationMapper.selectPatientVisitOperationList(patientVisitOperation);
    }

    @Override
    public PatientVisitOperation getByVisitRecord(Long patientVisitRecordId) {
        PatientVisitOperation patientVisitOperation = new PatientVisitOperation();
        patientVisitOperation.setPatientVisitRecordId(patientVisitRecordId);
        List<PatientVisitOperation> operations = patientVisitOperationMapper.selectPatientVisitOperationList(patientVisitOperation);
        if (CollectionUtils.isEmpty(operations)) {
            return null;
        }
        return operations.get(0);
    }

    /**
     * 新增患者就诊手术记录信息
     *
     * @param patientVisitOperation 患者就诊手术记录信息
     * @return 结果
     */
    @Override
    public int insertPatientVisitOperation(PatientVisitOperation patientVisitOperation) {
        patientVisitOperation.setCreateTime(LocalDateTime.now());
        return patientVisitOperationMapper.insertPatientVisitOperation(patientVisitOperation);
    }

    /**
     * 修改患者就诊手术记录信息
     *
     * @param patientVisitOperation 患者就诊手术记录信息
     * @return 结果
     */
    @Override
    public int updatePatientVisitOperation(PatientVisitOperation patientVisitOperation) {
        patientVisitOperation.setUpdateTime(LocalDateTime.now());
        return patientVisitOperationMapper.updatePatientVisitOperation(patientVisitOperation);
    }

    /**
     * 批量删除患者就诊手术记录信息
     *
     * @param ids 需要删除的患者就诊手术记录信息主键
     * @return 结果
     */
    @Override
    public int deletePatientVisitOperationByIds(Long[] ids) {
        return patientVisitOperationMapper.deletePatientVisitOperationByIds(ids);
    }

    /**
     * 删除患者就诊手术记录信息信息
     *
     * @param id 患者就诊手术记录信息主键
     * @return 结果
     */
    @Override
    public int deletePatientVisitOperationById(Long id) {
        return patientVisitOperationMapper.deletePatientVisitOperationById(id);
    }
}
